Skip to content

Commit 4d58c1a

Browse files
authored
Validate DLPack tensor imports (#1204)
* Validate DLPack tensor imports
1 parent 767dbff commit 4d58c1a

3 files changed

Lines changed: 381 additions & 110 deletions

File tree

docs_input/external.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ example, to convert a libtorch tensor to a MatX tensor:
134134
MatX will invoke the producer-provided DLPack deleter when the last MatX
135135
reference to the imported storage is released.
136136

137+
MatX validates imported DLPack rank, dtype, shape, stride, and byte-offset
138+
metadata before creating the tensor view. Shape dimensions must be positive,
139+
strides must be positive, and the declared logical size and strided address
140+
span must fit in MatX index and host size ranges. DLPack does not include the
141+
actual backing allocation length, so the producer must still accurately describe
142+
the allocation it exports.
143+
137144
.. important::
138145

139146
A `DLManagedTensorVersioned` or `DLManagedTensor` should only be consumed once.
@@ -214,4 +221,3 @@ can only be used on tensors and not other operators.
214221
The above example shows an existing function `foo` taking in a pointer from the MatX tensor `t1`. Since only a pointer is available, all
215222
metadata available in the operator (shape, strides, etc) is not available inside of the function, and the user must ensure the correctness
216223
of usage with the pointer.
217-

0 commit comments

Comments
 (0)