Managed NDArray. The array is backed by reference counted blocks.
More...
#include <ndarray.h>
Managed NDArray. The array is backed by reference counted blocks.
◆ ContainerType
◆ NDArray() [1/2]
tvm::runtime::NDArray::NDArray |
( |
| ) |
|
|
inline |
◆ NDArray() [2/2]
◆ AbilityOfZeroCopyForDLTensor()
static bool tvm::runtime::NDArray::AbilityOfZeroCopyForDLTensor |
( |
DLTensor * |
tensor, |
|
|
const Device & |
dev |
|
) |
| |
|
static |
Check conditions for construction NDArray over DLTensor without copying. There are three conditions to check:
- Destination device is the same as DLTensor device
- Destination device id is the same as DLTensor device id
- Memory in DLTensor is aligned as expected for NDArray
- Parameters
-
tensor | the DLTensor. |
dev | destination device. |
- Returns
- true if all conditions are satisfied.
◆ CopyFrom() [1/2]
void tvm::runtime::NDArray::CopyFrom |
( |
const DLTensor * |
other | ) |
|
|
inline |
Copy data content from another array.
- Parameters
-
other | The source array to be copied from. |
- Note
- The copy may happen asynchronously if it involves a GPU context. TVMSynchronize is necessary.
◆ CopyFrom() [2/2]
void tvm::runtime::NDArray::CopyFrom |
( |
const NDArray & |
other | ) |
|
|
inline |
◆ CopyFromBytes()
void tvm::runtime::NDArray::CopyFromBytes |
( |
const void * |
data, |
|
|
size_t |
nbytes |
|
) |
| |
Copy data content from a byte buffer.
- Parameters
-
data | The source bytes to be copied from. |
nbytes | The size of the buffer in bytes Must be equal to the size of the NDArray. |
- Note
- The copy always triggers a TVMSynchronize.
◆ CopyFromTo()
static void tvm::runtime::NDArray::CopyFromTo |
( |
const DLTensor * |
from, |
|
|
DLTensor * |
to, |
|
|
TVMStreamHandle |
stream = nullptr |
|
) |
| |
|
static |
Function to copy data from one array to another.
- Parameters
-
from | The source array. |
to | The target array. |
stream | The stream used in copy. |
◆ CopyTo() [1/3]
void tvm::runtime::NDArray::CopyTo |
( |
DLTensor * |
other | ) |
const |
|
inline |
Copy data content into another array.
- Parameters
-
other | The source array to be copied from. |
- Note
- The copy may happen asynchronously if it involves a GPU context. TVMSynchronize is necessary.
◆ CopyTo() [2/3]
void tvm::runtime::NDArray::CopyTo |
( |
const NDArray & |
other | ) |
const |
|
inline |
◆ CopyTo() [3/3]
NDArray tvm::runtime::NDArray::CopyTo |
( |
const Device & |
dev | ) |
const |
|
inline |
Copy the data to another device.
- Parameters
-
- Returns
- The array under another device.
◆ CopyToBytes()
void tvm::runtime::NDArray::CopyToBytes |
( |
void * |
data, |
|
|
size_t |
nbytes |
|
) |
| const |
Copy data content into another array.
- Parameters
-
data | The source bytes to be copied from. |
nbytes | The size of the data buffer. Must be equal to the size of the NDArray. |
- Note
- The copy always triggers a TVMSynchronize.
◆ CreateView()
Create a NDArray that shares the data memory with the current one.
- Parameters
-
shape | The shape of the new array. |
dtype | The data type of the new array. |
- Note
- The memory size of new array must be smaller than the current one.
◆ DataType()
◆ Empty()
Create an empty NDArray.
- Parameters
-
shape | The shape of the new array. |
dtype | The data type of the new array. |
dev | The device of the array. |
mem_scope | The memory scope of the array. |
- Returns
- The created Array
◆ FFIDataFromHandle()
Construct NDArray's Data field from array handle in FFI.
- Parameters
-
- Returns
- The corresponding ObjectPtr to the constructed container object.
- Note
- We keep a special calling convention for NDArray by passing ContainerBase pointer in FFI. As a result, the argument is compatible to DLTensor*.
◆ FFIDecRef()
DecRef resource managed by an FFI array handle.
- Parameters
-
◆ FFIGetHandle()
Get FFI Array handle from ndarray.
- Parameters
-
nd | The object with ndarray type. |
- Returns
- The result array handle.
◆ FromDLPack()
static NDArray tvm::runtime::NDArray::FromDLPack |
( |
DLManagedTensor * |
tensor | ) |
|
|
static |
Create a NDArray backed by a dlpack tensor.
This allows us to create a NDArray using the memory allocated by an external deep learning framework that is DLPack compatible.
The memory is retained until the NDArray went out of scope.
- Parameters
-
tensor | The DLPack tensor to copy from. |
- Returns
- The created NDArray view.
◆ FromExternalDLTensor()
static NDArray tvm::runtime::NDArray::FromExternalDLTensor |
( |
const DLTensor & |
dl_tensor | ) |
|
|
static |
Create a NDArray backed by an external DLTensor without memory copying.
If DLTensor is not contiguous or has bad aligned data, It fails. This allows us to create a NDArray using the memory allocated by an external source. Responsibility for memory retaining lies with the external source.
- Parameters
-
dl_tensor | The DLTensor for NDArray base. |
- Returns
- The created NDArray view.
◆ get_mutable()
Get mutable internal container pointer.
- Returns
- a mutable container pointer.
◆ IsContiguous()
bool tvm::runtime::NDArray::IsContiguous |
( |
| ) |
const |
|
inline |
- Returns
- Whether the tensor is contiguous
◆ Load()
bool tvm::runtime::NDArray::Load |
( |
dmlc::Stream * |
stream | ) |
|
|
inline |
Load NDArray from stream.
- Parameters
-
stream | The input data stream |
- Returns
- Whether load is successful
◆ NewFromDLTensor()
static NDArray tvm::runtime::NDArray::NewFromDLTensor |
( |
DLTensor * |
dl_tensor, |
|
|
const Device & |
dev |
|
) |
| |
|
static |
Create new NDArray, data is copied from DLTensor.
- Parameters
-
dl_tensor | The DLTensor to copy from. |
dev | device location of the created NDArray. |
- Returns
- The created NDArray view.
◆ operator->()
const DLTensor * tvm::runtime::NDArray::operator-> |
( |
| ) |
const |
|
inline |
- Returns
- Pointer to content of DLTensor
◆ reset()
void tvm::runtime::NDArray::reset |
( |
| ) |
|
|
inline |
reset the content of NDArray to be nullptr
◆ Save()
void tvm::runtime::NDArray::Save |
( |
dmlc::Stream * |
stream | ) |
const |
|
inline |
Save NDArray to stream.
- Parameters
-
stream | The output data stream |
◆ Shape()
◆ ToDLPack()
DLManagedTensor* tvm::runtime::NDArray::ToDLPack |
( |
| ) |
const |
Create a reference view of NDArray that represents as DLManagedTensor.
- Returns
- A DLManagedTensor
◆ use_count()
int tvm::runtime::NDArray::use_count |
( |
| ) |
const |
|
inline |
- Returns
- the reference counter
- Note
- this number is approximate in multi-threaded setting.
◆ TVMArgsSetter
◆ TVMPODValue_
◆ TVMRetValue
The documentation for this class was generated from the following file: