Skip to content

Commit 180dfcd

Browse files
committed
Move exchange api to common header
1 parent df77508 commit 180dfcd

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

include/dlpack/dlpack.h

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,28 @@ typedef int (*DLPackManagedTensorToPyObjectNoSync)( //
493493
void** out_py_object //
494494
);
495495

496+
/*!
497+
* \brief DLPackExchangeAPI stable header.
498+
* \sa DLPackExchangeAPI
499+
*/
500+
typedef struct DLPackExchangeAPIHeader {
501+
/*!
502+
* \brief The provided DLPack version the consumer must check major version
503+
* compatibility before using this struct.
504+
*/
505+
DLPackVersion version;
506+
/*!
507+
* \brief Optional pointer to an older DLPackExchangeAPI in the chain.
508+
*
509+
* It must be NULL if the framework does not support older versions.
510+
* If the current major version is larger than the one supported by the
511+
* consumer, the consumer may walk this to find an earlier supported version.
512+
*
513+
* \sa DLPackExchangeAPI
514+
*/
515+
struct DLPackExchangeAPIHeader* prev_version_api;
516+
} DLPackExchangeAPIHeader;
517+
496518
/*!
497519
* \brief Framework-specific function pointers table for DLPack exchange.
498520
*
@@ -518,14 +540,15 @@ typedef int (*DLPackManagedTensorToPyObjectNoSync)( //
518540
* \code
519541
* struct MyDLPackExchangeAPI : public DLPackExchangeAPI {
520542
* MyDLPackExchangeAPI() {
521-
* version.major = DLPACK_MAJOR_VERSION;
522-
* version.minor = DLPACK_MINOR_VERSION;
543+
* header.version.major = DLPACK_MAJOR_VERSION;
544+
* header.version.minor = DLPACK_MINOR_VERSION;
545+
* header.prev_version_api = nullptr;
546+
*
523547
* managed_tensor_allocator = MyDLPackManagedTensorAllocator;
524548
* managed_tensor_from_py_object_no_sync = MyDLPackManagedTensorFromPyObjectNoSync;
525549
* managed_tensor_to_py_object_no_sync = MyDLPackManagedTensorToPyObjectNoSync;
526550
* dltensor_from_py_object_no_sync = MyDLPackDLTensorFromPyObjectNoSync;
527551
* current_work_stream = MyDLPackCurrentWorkStream;
528-
* prev_version_api = nullptr;
529552
* }
530553
*
531554
* static const DLPackExchangeAPI* Global() {
@@ -561,22 +584,11 @@ typedef int (*DLPackManagedTensorToPyObjectNoSync)( //
561584
* shows an example to do so in C++. It should also be reasonably easy
562585
* to do so in other languages.
563586
*/
564-
struct DLPackExchangeAPI {
565-
/*!
566-
* \brief The provided DLPack version the consumer must check major version
567-
* compatibility before using this struct.
568-
*/
569-
DLPackVersion version;
587+
typedef struct DLPackExchangeAPI {
570588
/*!
571-
* \brief Optional pointer to an older DLPackExchangeAPI in the chain.
572-
*
573-
* It must be NULL if the framework does not support older versions.
574-
* If the current major version is larger than the one supported by the
575-
* consumer, the consumer may walk this to find an earlier supported version.
576-
*
577-
* \sa DLPackExchangeAPI
589+
* \brief The header that remains stable across versions.
578590
*/
579-
struct DLPackExchangeAPI* prev_version_api;
591+
DLPackExchangeAPIHeader header;
580592
/*!
581593
* \brief Producer function pointer for DLPackManagedTensorAllocator
582594
* This function must not be NULL.
@@ -607,7 +619,7 @@ struct DLPackExchangeAPI {
607619
* \sa DLPackCurrentWorkStream
608620
*/
609621
DLPackCurrentWorkStream current_work_stream;
610-
};
622+
} DLPackExchangeAPI;
611623

612624
#ifdef __cplusplus
613625
} // DLPACK_EXTERN_C

0 commit comments

Comments
 (0)