tvm.runtime.ndarray#

Runtime NDArray API

class tvm.runtime.ndarray.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.

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.

numpy()[源代码]#

Convert this array to numpy array

返回:

np_arr -- The corresponding numpy array.

返回类型:

numpy.ndarray

tvm.runtime.ndarray.array(arr, device=None, 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.empty(shape, dtype='float32', device=None, 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.from_dlpack(ext_tensor)[源代码]#

Convert an external tensor to an NDArray.

参数:
  • ext_tensor (object) -- The external tensor to convert.

  • required_alignment (int) -- The minimum required alignment to check for the tensor.

  • required_contiguous (bool) -- Whether to check for contiguous memory.