tvm.runtime.ndarray

Runtime NDArray API

class tvm.nd.NDArray

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.

property dtype

Type of this array

property device

Device of this array

same_as(other)

Check object identity equality

Parameters

other (object) – The other object to compare to

Returns

same – Whether other is same as self.

Return type

bool

copyfrom(source_array)

Perform a synchronous copy from the array.

Parameters

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

Returns

arr – Reference to self.

Return type

NDArray

asnumpy()

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

numpy()

Convert this array to numpy array

Returns

np_arr – The corresponding numpy array.

Return type

numpy.ndarray

copyto(target, mem_scope=None)

Copy array to target

Parameters
  • 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.

shape

Shape of this array

to_dlpack()

Produce an array from a DLPack Tensor without copying memory

Returns

dlpack

Return type

DLPack tensor view of the array data

tvm.nd.array(arr, device=cpu(0), mem_scope=None)

Create an array from source arr.

Parameters
  • 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

Returns

ret – The created array

Return type

NDArray

tvm.nd.empty(shape, dtype='float32', device=cpu(0), mem_scope=None)

Create an empty array given shape and device

Parameters
Returns

arr – The array tvm supported.

Return type

tvm.nd.NDArray