From 007cef0eb0b2b60a62bc10df6166a7684736d31e Mon Sep 17 00:00:00 2001 From: tqchen Date: Thu, 9 Oct 2025 11:10:07 -0400 Subject: [PATCH 1/4] Enforce strides to be not null when ndim is nonzero This PR updates the spec to enforce the strides to be not null when the ndim is nonzero. This is going to help consumers to handle cases more uniformly. --- include/dlpack/dlpack.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/dlpack/dlpack.h b/include/dlpack/dlpack.h index 6ce3f60..662818b 100644 --- a/include/dlpack/dlpack.h +++ b/include/dlpack/dlpack.h @@ -257,8 +257,9 @@ typedef struct { /*! \brief The shape of the tensor */ int64_t* shape; /*! - * \brief strides of the tensor (in number of elements, not bytes) - * can be NULL, indicating tensor is compact and row-majored. + * \brief strides of the tensor (in number of elements, not bytes), + * can not be NULL if ndim != 0, must points to + * an array of ndim elements that specifies the strides. */ int64_t* strides; /*! \brief The offset in bytes to the beginning pointer to data */ From ec99b3744ca701998c653c3bbeeaf356ed7ddb01 Mon Sep 17 00:00:00 2001 From: tqchen Date: Thu, 9 Oct 2025 13:48:45 -0400 Subject: [PATCH 2/4] Add more comments on the null rationale --- include/dlpack/dlpack.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/include/dlpack/dlpack.h b/include/dlpack/dlpack.h index 662818b..420fc40 100644 --- a/include/dlpack/dlpack.h +++ b/include/dlpack/dlpack.h @@ -254,12 +254,23 @@ typedef struct { int32_t ndim; /*! \brief The data type of the pointer*/ DLDataType dtype; - /*! \brief The shape of the tensor */ + /*! + * \brief The shape of the tensor + * + * When ndim == 0, we suggest to set the shape to NULL. + */ int64_t* shape; /*! * \brief strides of the tensor (in number of elements, not bytes), * can not be NULL if ndim != 0, must points to * an array of ndim elements that specifies the strides. + * + * When ndim == 0, we suggest to set the strides to NULL. + * + * \note Before DLPack v1.2, strides can be NULL to indicate contiguous data. + * This is not allowed in DLPack v1.2 and later. The rationale + * is to simplify the consumer hanlding, and most frameworks already + * always returns the strides when ndim != 0. */ int64_t* strides; /*! \brief The offset in bytes to the beginning pointer to data */ From 63a9a328f2551984cfd7ca254432e90181dfbed7 Mon Sep 17 00:00:00 2001 From: tqchen Date: Thu, 9 Oct 2025 14:44:01 -0400 Subject: [PATCH 3/4] Remove mention of framework handling --- include/dlpack/dlpack.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/dlpack/dlpack.h b/include/dlpack/dlpack.h index 420fc40..5ba4e6a 100644 --- a/include/dlpack/dlpack.h +++ b/include/dlpack/dlpack.h @@ -269,8 +269,7 @@ typedef struct { * * \note Before DLPack v1.2, strides can be NULL to indicate contiguous data. * This is not allowed in DLPack v1.2 and later. The rationale - * is to simplify the consumer hanlding, and most frameworks already - * always returns the strides when ndim != 0. + * is to simplify the consumer handling. */ int64_t* strides; /*! \brief The offset in bytes to the beginning pointer to data */ From aa2c2cf1a8656ada4fcc5e4450b7771c55df493d Mon Sep 17 00:00:00 2001 From: tqchen Date: Fri, 10 Oct 2025 08:43:23 -0400 Subject: [PATCH 4/4] Update NULL note, bump minor --- include/dlpack/dlpack.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/include/dlpack/dlpack.h b/include/dlpack/dlpack.h index 5ba4e6a..9a710eb 100644 --- a/include/dlpack/dlpack.h +++ b/include/dlpack/dlpack.h @@ -19,7 +19,7 @@ #define DLPACK_MAJOR_VERSION 1 /*! \brief The current minor version of dlpack */ -#define DLPACK_MINOR_VERSION 1 +#define DLPACK_MINOR_VERSION 2 /*! \brief DLPACK_DLL prefix for windows */ #ifdef _WIN32 @@ -257,15 +257,16 @@ typedef struct { /*! * \brief The shape of the tensor * - * When ndim == 0, we suggest to set the shape to NULL. + * When ndim == 0, shape can be set to NULL. */ int64_t* shape; /*! * \brief strides of the tensor (in number of elements, not bytes), * can not be NULL if ndim != 0, must points to - * an array of ndim elements that specifies the strides. + * an array of ndim elements that specifies the strides, + * so consumer can always rely on strides[dim] being valid for 0 <= dim < ndim. * - * When ndim == 0, we suggest to set the strides to NULL. + * When ndim == 0, strides can be set to NULL. * * \note Before DLPack v1.2, strides can be NULL to indicate contiguous data. * This is not allowed in DLPack v1.2 and later. The rationale