tvm.runtime.ndarray#

Runtime NDArray API

class tvm.runtime.ndarray.NDArray(handle, is_view=False)[源代码]#

Lightweight NDArray class of TVM runtime.

Strictly this is only an Array Container (a buffer object) No arthimetic operations are defined. All operations are performed by TVM functions.

The goal is not to re-build yet another array library. Instead, this is a minimal data structure to demonstrate how can we use TVM in existing project which might have their own array containers.

asnumpy()[源代码]#

Convert this array to numpy array. This API will be deprecated in TVM v0.8 release. Please use numpy instead.

copyfrom(source_array)[源代码]#

Perform a synchronous copy from the array.

参数:

source_array (array_like) -- The data source we should like to copy from.

返回:

arr -- Reference to self.

返回类型:

NDArray

copyto(target, mem_scope=None)[源代码]#

Copy array to target

参数:
  • target (NDArray) -- The target array to be copied, must have same shape as this array.

  • mem_scope (Optional[str]) -- The memory scope of the array.

property device#

Device of this array

property dtype#

Type of this array

numpy()[源代码]#

Convert this array to numpy array

返回:

np_arr -- The corresponding numpy array.

返回类型:

numpy.ndarray

same_as(other)[源代码]#

Check object identity equality

参数:

other (object) -- The other object to compare to

返回:

same -- Whether other is same as self.

返回类型:

bool

tvm.runtime.ndarray.array(arr, device=cpu(0), mem_scope=None)[源代码]#

Create an array from source arr.

参数:
  • arr (numpy.ndarray) -- The array to be copied from

  • device (Device, optional) -- The device to create the array

  • mem_scope (Optional[str]) -- The memory scope of the array

返回:

ret -- The created array

返回类型:

NDArray

tvm.runtime.ndarray.cl(dev_id=0)#

Construct a OpenCL device

参数:

dev_id (int, optional) -- The integer device id

返回:

dev -- The created device

返回类型:

Device

tvm.runtime.ndarray.cpu(dev_id=0)[源代码]#

Construct a CPU device

参数:

dev_id (int, optional) -- The integer device id

返回:

dev -- The created device

返回类型:

Device

tvm.runtime.ndarray.cuda(dev_id=0)[源代码]#

Construct a CUDA GPU device

参数:

dev_id (int, optional) -- The integer device id

返回:

dev -- The created device

返回类型:

Device

tvm.runtime.ndarray.device(dev_type, dev_id=0)[源代码]#

Construct a TVM device with given device type and id.

参数:
  • dev_type (int or str) -- The device type mask or name of the device.

  • dev_id (int, optional) -- The integer device id

返回:

dev -- The corresponding device.

返回类型:

tvm.runtime.Device

示例

Device can be used to create reflection of device by string representation of the device type.

assert tvm.device("cpu", 1) == tvm.cpu(1)
assert tvm.device("cuda", 0) == tvm.cuda(0)
tvm.runtime.ndarray.empty(shape, dtype='float32', device=cpu(0), mem_scope=None)[源代码]#

Create an empty array given shape and device

参数:
  • shape (Union[tvm.runtime.ShapeTuple, Sequence[SupportsInt]]) -- The shape of the array.

  • dtype (type or str) -- The data type of the array.

  • device (Device) -- The device of the array.

  • mem_scope (Optional[str]) -- The memory scope of the array.

返回:

arr -- The array tvm supported.

返回类型:

tvm.nd.NDArray

tvm.runtime.ndarray.ext_dev(dev_id=0)[源代码]#

Construct a extension device

参数:

dev_id (int, optional) -- The integer device id

返回:

dev -- The created device

返回类型:

Device

备注

This API is reserved for quick testing of new device by plugin device API as ext_dev.

tvm.runtime.ndarray.from_dlpack(dltensor)[源代码]#

Produces an array from an object with __dlpack__ method or a DLPack tensor w/o memory copy. Retreives the underlying DLPack tensor's pointer to create an array from the data. Removes the original DLPack tensor's destructor as now the array is responsible for destruction.

参数:

dltensor (object with __dlpack__ attribute or a DLPack capsule)

返回:

arr -- The array view of the tensor data.

返回类型:

tvm.nd.NDArray

tvm.runtime.ndarray.gpu(dev_id=0)[源代码]#

Construct a CUDA GPU device

deprecated:: 0.9.0 Use tvm.cuda() instead.

参数:

dev_id (int, optional) -- The integer device id

返回:

dev -- The created device

返回类型:

Device

tvm.runtime.ndarray.hexagon(dev_id=0)[源代码]#

Construct a Hexagon device

参数:

dev_id (int, optional) -- The integer device id

返回:

dev -- The created device

返回类型:

Device

tvm.runtime.ndarray.metal(dev_id=0)[源代码]#

Construct a metal device

参数:

dev_id (int, optional) -- The integer device id

返回:

dev -- The created device

返回类型:

Device

tvm.runtime.ndarray.mtl(dev_id=0)#

Construct a metal device

参数:

dev_id (int, optional) -- The integer device id

返回:

dev -- The created device

返回类型:

Device

tvm.runtime.ndarray.numpyasarray(np_data)[源代码]#

Return a TVMArray representation of a numpy array.

tvm.runtime.ndarray.opencl(dev_id=0)[源代码]#

Construct a OpenCL device

参数:

dev_id (int, optional) -- The integer device id

返回:

dev -- The created device

返回类型:

Device

tvm.runtime.ndarray.rocm(dev_id=0)[源代码]#

Construct a ROCM device

参数:

dev_id (int, optional) -- The integer device id

返回:

dev -- The created device

返回类型:

Device

tvm.runtime.ndarray.vpi(dev_id=0)[源代码]#

Construct a VPI simulated device

参数:

dev_id (int, optional) -- The integer device id

返回:

dev -- The created device

返回类型:

Device

tvm.runtime.ndarray.vulkan(dev_id=0)[源代码]#

Construct a Vulkan device

参数:

dev_id (int, optional) -- The integer device id

返回:

dev -- The created device

返回类型:

Device

tvm.runtime.ndarray.webgpu(dev_id=0)[源代码]#

Construct a webgpu device.

参数:

dev_id (int, optional) -- The integer device id

返回:

dev -- The created device

返回类型:

Device