Skip to content

Commit 327b088

Browse files
committed
Update naming and specification according to feedbacks
1 parent 0330ad9 commit 327b088

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

include/dlpack/dlpack.h

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ typedef struct DLManagedTensorVersioned {
385385
*
386386
* \sa DLPackExchangeAPI
387387
*/
388-
typedef int (*DLPackTensorAllocator)( //
388+
typedef int (*DLPackManagedTensorAllocator)( //
389389
DLTensor* prototype, DLManagedTensorVersioned** out, void* error_ctx, //
390390
void (*SetError)(void* error_ctx, const char* kind, const char* message) //
391391
);
@@ -410,13 +410,15 @@ typedef int (*DLPackTensorAllocator)( //
410410
* \param out The output DLManagedTensorVersioned.
411411
* \param optional_out_env_stream Outputs the current context stream of the device provided
412412
* by the tensor; it can be NULL, in which case the stream will not be queried.
413+
* optional_out_env_stream should points to cudaStream_t in the case of CUDA.
414+
*
413415
* \return 0 on success, -1 on failure. PyError should be set if -1 is returned.
414416
* \note We use void* to avoid dependency on Python.h, so this specific type is
415417
* not dependent on Python.h and can be copied to dlpack.h.
416418
*
417419
* \sa DLPackExchangeAPI
418420
*/
419-
typedef int (*DLPackFromPyObject)( //
421+
typedef int (*DLPackManagedTensorFromPyObject)( //
420422
void* py_object, //
421423
DLManagedTensorVersioned** out, //
422424
void** optional_out_env_stream //
@@ -438,7 +440,7 @@ typedef int (*DLPackFromPyObject)( //
438440
*
439441
* \sa DLPackExchangeAPI
440442
*/
441-
typedef int (*DLPackToPyObject)(DLManagedTensorVersioned* tensor, void** out_py_object);
443+
typedef int (*DLPackManagedTensorToPyObject)(DLManagedTensorVersioned* tensor, void** out_py_object);
442444

443445
/*!
444446
* \brief Framework-specific function pointers table for DLPack exchange.
@@ -457,40 +459,49 @@ typedef int (*DLPackToPyObject)(DLManagedTensorVersioned* tensor, void** out_py_
457459
* MyDLPackExchangeAPI() {
458460
* version.major = DLPACK_MAJOR_VERSION;
459461
* version.minor = DLPACK_MINOR_VERSION;
460-
* tensor_allocator = MyDLPackTensorAllocator;
461-
* dlpack_from_py_object = MyDLPackFromPyObject;
462-
* dlpack_to_py_object = MyDLPackToPyObject
462+
* managed_tensor_allocator = MyDLPackManagedTensorAllocator;
463+
* managed_tensor_from_py_object = MyDLPackManagedTensorFromPyObject;
464+
* managed_tensor_to_py_object = MyDLPackManagedTensorToPyObject
463465
* }
464466
*
465-
* const DLPackExchangeAPI* Global() {
467+
* static const DLPackExchangeAPI* Global() {
466468
* static MyDLPackExchangeAPI inst;
467469
* return &inst;
468470
* }
469471
* };
470472
* \endcode
471473
*
474+
* Each framework should attach a dunder `__c_dlpack_exchange_api__` integer
475+
* to point to the pointer of the DLPackExchangeAPI*
476+
*
477+
* Importantly the attributed should be attached to the class of the Tensor, not the instance.
478+
*
472479
* mypackage.Tensor.__c_dlpack_exchange_api__ = MyPackageDLPackExchangeAPI
480+
*
481+
* or equivalently:
482+
*
483+
* type(tensor_obj).__c_dlpack_exchange_api__ = MyPackageDLPackExchangeAPI
473484
*/
474485
struct DLPackExchangeAPI {
475486
/*!
476487
* \brief The current DLPack version.
477488
*/
478489
DLPackVersion version;
479490
/*!
480-
* \brief Framework-specific function pointer for DLPackTensorAllocator
481-
* \sa DLPackTensorAllocator
491+
* \brief Framework-specific function pointer for DLPackManagedTensorAllocator
492+
* \sa DLPackManagedTensorAllocator
482493
*/
483-
DLPackTensorAllocator tensor_allocator;
494+
DLPackManagedTensorAllocator managed_tensor_allocator;
484495
/*!
485-
* \brief Framework-specific function pointer for DLPackFromPyObject
486-
* \sa DLPackFromPyObject
496+
* \brief Framework-specific function pointer for DLPackManagedTensorFromPyObject
497+
* \sa DLPackManagedTensorFromPyObject
487498
*/
488-
DLPackFromPyObject dlpack_from_py_object;
499+
DLPackManagedTensorFromPyObject managed_tensor_from_py_object;
489500
/*!
490-
* \brief Framework-specific function pointer for DLPackToPyObject
491-
* \sa DLPackToPyObject
501+
* \brief Framework-specific function pointer for DLPackManagedTensorToPyObject
502+
* \sa DLPackManagedTensorToPyObject
492503
*/
493-
DLPackToPyObject dlpack_to_py_object;
504+
DLPackManagedTensorToPyObject managed_tensor_to_py_object;
494505
};
495506

496507
#ifdef __cplusplus

0 commit comments

Comments
 (0)