-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ABI] ABI Update For adding Version to DLPack #113
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,11 +15,11 @@ | |
#define DLPACK_EXTERN_C | ||
#endif | ||
|
||
/*! \brief The current version of dlpack */ | ||
#define DLPACK_VERSION 80 | ||
/*! \brief The current major version of dlpack */ | ||
#define DLPACK_MAJOR_VERSION 1 | ||
|
||
/*! \brief The current ABI version of dlpack */ | ||
#define DLPACK_ABI_VERSION 1 | ||
/*! \brief The current minor version of dlpack */ | ||
#define DLPACK_MINOR_VERSION 0 | ||
|
||
/*! \brief DLPACK_DLL prefix for windows */ | ||
#ifdef _WIN32 | ||
|
@@ -38,6 +38,33 @@ | |
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/*! | ||
* \brief The DLPack version. | ||
* | ||
* A change in major version indicates that we have changed the | ||
* data layout of the ABI - DLManagedTensorVersioned. | ||
* | ||
* A change in minor version indicates that we have added new | ||
* code, such as a new device type, but the ABI is kept the same. | ||
* | ||
* If an obtained DLPack tensor has a major version that disagrees | ||
* with the version number specified in this header file | ||
* (i.e. major != DLPACK_MAJOR_VERSION), the consumer must call the deleter | ||
* (and it is safe to do so). It is not safe to access any other fields | ||
* as the memory layout will have changed. | ||
* | ||
* In the case of a minor version mismatch, the tensor can be safely used as | ||
* long as the consumer knows how to interpret all fields. Minor version | ||
* updates indicate the addition of enumeration values. | ||
*/ | ||
typedef struct { | ||
/*! \brief DLPack major version. */ | ||
uint32_t major; | ||
/*! \brief DLPack minor version. */ | ||
uint32_t minor; | ||
} DLPackVersion; | ||
|
||
/*! | ||
* \brief The device type in DLDevice. | ||
*/ | ||
|
@@ -211,6 +238,13 @@ typedef struct { | |
* not meant to transfer the tensor. When the borrowing framework doesn't need | ||
* the tensor, it should call the deleter to notify the host that the resource | ||
* is no longer needed. | ||
* | ||
* \note This data structure is used as Legacy DLManagedTensor | ||
* in DLPack exchange and is deprecated after DLPack v0.8 | ||
tqchen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* Use DLManagedTensorVersioned instead. | ||
* This data structure may get renamed or deleted in future versions. | ||
* | ||
* \sa DLManagedTensorVersioned | ||
*/ | ||
typedef struct DLManagedTensor { | ||
/*! \brief DLTensor which is being memory managed */ | ||
|
@@ -219,13 +253,65 @@ typedef struct DLManagedTensor { | |
* which DLManagedTensor is used in the framework. It can also be NULL. | ||
*/ | ||
void * manager_ctx; | ||
/*! \brief Destructor signature void (*)(void*) - this should be called | ||
* to destruct manager_ctx which holds the DLManagedTensor. It can be NULL | ||
* if there is no way for the caller to provide a reasonable destructor. | ||
* The destructors deletes the argument self as well. | ||
/*! | ||
* \brief Destructor - this should be called | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit picking: formatting is a little messed up (double spaces, rows of different length). Edit: That also applies to a few of the other newly added comments, but I will just mention it once here to avoid spamming the PR. Also: I think the idea of the doxygen \brief tag is that the description is actually brief (1 sentence) followed by a newline to separate it from a more thorough comment. The \brief part is used as a preview. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great point, fixed for this particular case. we can do further cleanups |
||
* to destruct the manager_ctx which backs the DLManagedTensor. It can be | ||
* NULL if there is no way for the caller to provide a reasonable destructor. | ||
* The destructors deletes the argument self as well. | ||
*/ | ||
void (*deleter)(struct DLManagedTensor * self); | ||
} DLManagedTensor; | ||
|
||
// bit masks used in in the DLManagedTensorVersioned | ||
|
||
/*! \brief bit mask to indicate that the tensor is read only. */ | ||
#define DLPACK_FLAG_BITMASK_READ_ONLY (1UL << 0UL) | ||
|
||
/*! | ||
* \brief A versioned and managed C Tensor object, manage memory of DLTensor. | ||
* | ||
* This data structure is intended to facilitate the borrowing of DLTensor by | ||
* another framework. It is not meant to transfer the tensor. When the borrowing | ||
* framework doesn't need the tensor, it should call the deleter to notify the | ||
* host that the resource is no longer needed. | ||
* | ||
* \note This is the current standard DLPack exchange data structure. | ||
*/ | ||
struct DLManagedTensorVersioned { | ||
/*! | ||
* \brief The API and ABI version of the current managed Tensor | ||
*/ | ||
DLPackVersion version; | ||
tqchen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/*! | ||
* \brief the context of the original host framework. | ||
* | ||
* Stores DLManagedTensorVersioned is used in the | ||
* framework. It can also be NULL. | ||
*/ | ||
void *manager_ctx; | ||
/*! | ||
* \brief Destructor. | ||
* | ||
* This should be called to destruct manager_ctx which holds the DLManagedTensorVersioned. | ||
* It can be NULL if there is no way for the caller to provide a reasonable | ||
* destructor. The destructors deletes the argument self as well. | ||
*/ | ||
void (*deleter)(struct DLManagedTensorVersioned *self); | ||
/*! | ||
* \brief Additional bitmask flags information about the tensor. | ||
* | ||
* By default the flags should be set to 0. | ||
* | ||
* \note Future ABI changes should keep everything until this field | ||
* stable, to ensure that deleter can be correctly called. | ||
* | ||
* \sa DLPACK_FLAG_BITMASK_READ_ONLY | ||
*/ | ||
uint64_t flags; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to note somewhere that we guarantee the fields remain ABI stable until here (I guess including the flags). But after this, everything may be version dependent (it may make sense to specify whether growing the struct at the end is considered valid without bumping ABI in theory). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is the key part, and it would be useful to summarize the high-level idea in this header since it's the most important file of the entire repository. If we implement DLPack version There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are also two version numbers: the DLpack version, and the ABI version. Is the first one completely irrelevant in deciding what is valid/disallowed, or does it also play a potential role? If yes, how is it different from the ABI version? If no, why does it need to be part of the ABI via a field stored in data structures? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It could be a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added some clarification of the current scheme |
||
/*! \brief DLTensor which is being memory managed */ | ||
DLTensor dl_tensor; | ||
}; | ||
|
||
#ifdef __cplusplus | ||
} // DLPACK_EXTERN_C | ||
#endif | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add something of the following sort just to spell it out clearly somewhere:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the great suggestion, just add the comment per suggestion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great suggestion +1