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.
- 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.
- Parameters:
source_array (array_like) – The data source we should like to copy from.
- Returns:
arr – Reference to self.
- Return type:
- 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.
- property device¶
Device of this array
- property dtype¶
Type of this array
- numpy()¶
Convert this array to numpy array
- Returns:
np_arr – The corresponding numpy array.
- Return type:
numpy.ndarray
- 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
- tvm.runtime.ndarray.array(arr, device=cpu(0), mem_scope=None)¶
Create an array from source arr.
- tvm.runtime.ndarray.cl(dev_id=0)¶
Construct a OpenCL device
- Parameters:
dev_id (int, optional) – The integer device id
- Returns:
dev – The created device
- Return type:
- tvm.runtime.ndarray.cpu(dev_id=0)¶
Construct a CPU device
- Parameters:
dev_id (int, optional) – The integer device id
- Returns:
dev – The created device
- Return type:
- tvm.runtime.ndarray.cuda(dev_id=0)¶
Construct a CUDA GPU device
- Parameters:
dev_id (int, optional) – The integer device id
- Returns:
dev – The created device
- Return type:
- tvm.runtime.ndarray.device(dev_type, dev_id=0)¶
Construct a TVM device with given device type and id.
- Parameters:
dev_type (int or str) – The device type mask or name of the device.
dev_id (int, optional) – The integer device id
- Returns:
dev – The corresponding device.
- Return type:
Examples
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
- Parameters:
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.
- Returns:
arr – The array tvm supported.
- Return type:
tvm.nd.NDArray
- tvm.runtime.ndarray.ext_dev(dev_id=0)¶
Construct a extension device
- Parameters:
dev_id (int, optional) – The integer device id
- Returns:
dev – The created device
- Return type:
Note
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.
- Parameters:
dltensor (object with __dlpack__ attribute or a DLPack capsule) –
- Returns:
arr – The array view of the tensor data.
- Return type:
tvm.nd.NDArray
- tvm.runtime.ndarray.gpu(dev_id=0)¶
Construct a CUDA GPU device
deprecated:: 0.9.0 Use
tvm.cuda()
instead.- Parameters:
dev_id (int, optional) – The integer device id
- Returns:
dev – The created device
- Return type:
- tvm.runtime.ndarray.hexagon(dev_id=0)¶
Construct a Hexagon device
- Parameters:
dev_id (int, optional) – The integer device id
- Returns:
dev – The created device
- Return type:
- tvm.runtime.ndarray.metal(dev_id=0)¶
Construct a metal device
- Parameters:
dev_id (int, optional) – The integer device id
- Returns:
dev – The created device
- Return type:
- tvm.runtime.ndarray.mtl(dev_id=0)¶
Construct a metal device
- Parameters:
dev_id (int, optional) – The integer device id
- Returns:
dev – The created device
- Return type:
- 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
- Parameters:
dev_id (int, optional) – The integer device id
- Returns:
dev – The created device
- Return type:
- tvm.runtime.ndarray.rocm(dev_id=0)¶
Construct a ROCM device
- Parameters:
dev_id (int, optional) – The integer device id
- Returns:
dev – The created device
- Return type:
- tvm.runtime.ndarray.vpi(dev_id=0)¶
Construct a VPI simulated device
- Parameters:
dev_id (int, optional) – The integer device id
- Returns:
dev – The created device
- Return type:
- tvm.runtime.ndarray.vulkan(dev_id=0)¶
Construct a Vulkan device
- Parameters:
dev_id (int, optional) – The integer device id
- Returns:
dev – The created device
- Return type: