tvm_ffi.Tensor#
- class tvm_ffi.Tensor#
Bases:
ObjectManaged n-dimensional array compatible with DLPack.
Tensorprovides zero-copy interoperability with array libraries through the DLPack protocol. Instances are typically created withfrom_dlpack()or returned from FFI functions.Examples
import numpy as np x = tvm_ffi.from_dlpack(np.arange(6, dtype="int32")) assert x.shape == (6,) assert x.dtype == tvm_ffi.dtype("int32") # Round-trip through NumPy using DLPack np.testing.assert_equal(np.from_dlpack(x), np.arange(6, dtype="int32"))
- __init__()#
Methods
__dlpack__(*[, stream, max_version, ...])Implement the standard
__dlpack__protocol.Implement the standard
__dlpack_device__protocol.__ffi_init__(*args)Defined in
Objectas method__ffi_init__().same_as(other)Attributes
The
Deviceon which the tensor is placed.Data type as
tvm_ffi.dtype(strsubclass).Tensor shape as a tuple of integers.
Tensor strides as a tuple of integers.
- __dlpack__(*, stream=None, max_version=None, dl_device=None, copy=None)#
Implement the standard
__dlpack__protocol.- Parameters:
stream (
Any|None, default:None) – Framework-specific stream/context object.max_version (
tuple[int,int] |None, default:None) – Upper bound on the supported DLPack version of the consumer. WhenNone, use the built-in protocol version.dl_device (
tuple[int,int] |None, default:None) – Override the device reported by__dlpack_device__().copy (
bool|None, default:None) – IfTrue, produce a copy rather than exporting in-place.
- Raises:
BufferError – If the requested behavior cannot be satisfied.
- Return type:
- __dlpack_device__()#
Implement the standard
__dlpack_device__protocol.
- dtype#
Data type as
tvm_ffi.dtype(strsubclass).
- shape#
Tensor shape as a tuple of integers.
- strides#
Tensor strides as a tuple of integers.