tvm_ffi.Tensor#

class tvm_ffi.Tensor#

Bases: Object

Managed n-dimensional array compatible with DLPack.

Tensor provides zero-copy interoperability with array libraries through the DLPack protocol. Instances are typically created with from_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.

__dlpack_device__()

Implement the standard __dlpack_device__ protocol.

__ffi_init__(*args)

Defined in Object as method __ffi_init__().

same_as(other)

Defined in Object as method same_as().

Attributes

device

The Device on which the tensor is placed.

dtype

Data type as tvm_ffi.dtype (str subclass).

shape

Tensor shape as a tuple of integers.

strides

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. When None, 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) – If True, produce a copy rather than exporting in-place.

Raises:

BufferError – If the requested behavior cannot be satisfied.

Return type:

object

__dlpack_device__()#

Implement the standard __dlpack_device__ protocol.

Return type:

tuple[int, int]

device#

The Device on which the tensor is placed.

dtype#

Data type as tvm_ffi.dtype (str subclass).

shape#

Tensor shape as a tuple of integers.

strides#

Tensor strides as a tuple of integers.