tvm
|
Managed NDArray. The array is backed by reference counted blocks. More...
#include <ndarray.h>
Classes | |
class | Container |
Object container class that backs NDArray. More... | |
class | ContainerBase |
The container base structure contains all the fields except for the Object header. More... | |
Public Types | |
using | ContainerType = Container |
Container type for Object system. More... | |
Public Types inherited from tvm::runtime::ObjectRef | |
using | ContainerType = Object |
type indicate the container type. More... | |
Public Member Functions | |
NDArray () | |
default constructor More... | |
NDArray (ObjectPtr< Object > data) | |
constructor. More... | |
void | reset () |
reset the content of NDArray to be nullptr More... | |
int | use_count () const |
const DLTensor * | operator-> () const |
bool | IsContiguous () const |
void | CopyFrom (const DLTensor *other) |
Copy data content from another array. More... | |
void | CopyFrom (const NDArray &other) |
void | CopyFromBytes (const void *data, size_t nbytes) |
Copy data content from a byte buffer. More... | |
void | CopyTo (DLTensor *other) const |
Copy data content into another array. More... | |
void | CopyTo (const NDArray &other) const |
void | CopyToBytes (void *data, size_t nbytes) const |
Copy data content into another array. More... | |
NDArray | CopyTo (const Device &dev, Optional< String > mem_scope=NullOpt) const |
Copy the data to another device. More... | |
bool | Load (dmlc::Stream *stream) |
Load NDArray from stream. More... | |
void | Save (dmlc::Stream *stream) const |
Save NDArray to stream. More... | |
NDArray | CreateView (ShapeTuple shape, DLDataType dtype, uint64_t relative_byte_offset=0) |
Create a NDArray that shares the data memory with the current one. More... | |
DLManagedTensor * | ToDLPack () const |
Create a reference view of NDArray that represents as DLManagedTensor. More... | |
ShapeTuple | Shape () const |
runtime::DataType | DataType () const |
Public Member Functions inherited from tvm::runtime::ObjectRef | |
ObjectRef ()=default | |
default constructor More... | |
ObjectRef (ObjectPtr< Object > data) | |
Constructor from existing object ptr. More... | |
bool | same_as (const ObjectRef &other) const |
Comparator. More... | |
bool | operator== (const ObjectRef &other) const |
Comparator. More... | |
bool | operator!= (const ObjectRef &other) const |
Comparator. More... | |
bool | operator< (const ObjectRef &other) const |
Comparator. More... | |
bool | defined () const |
const Object * | get () const |
const Object * | operator-> () const |
bool | unique () const |
int | use_count () const |
template<typename ObjectType , typename = std::enable_if_t<std::is_base_of_v<Object, ObjectType>>> | |
const ObjectType * | as () const |
Try to downcast the internal Object to a raw pointer of a corresponding type. More... | |
template<typename ObjectRefType , typename = std::enable_if_t<std::is_base_of_v<ObjectRef, ObjectRefType>>> | |
Optional< ObjectRefType > | as () const |
Try to downcast the ObjectRef to a Optional<T> of the requested type. More... | |
Static Public Member Functions | |
static NDArray | Empty (ShapeTuple shape, DLDataType dtype, Device dev, Optional< String > mem_scope=NullOpt) |
Create an empty NDArray. More... | |
static NDArray | FromExternalDLTensor (const DLTensor &dl_tensor) |
Create a NDArray backed by an external DLTensor without memory copying. More... | |
static NDArray | NewFromDLTensor (DLTensor *dl_tensor, const Device &dev) |
Create new NDArray, data is copied from DLTensor. More... | |
static NDArray | FromDLPack (DLManagedTensor *tensor) |
Create a NDArray backed by a dlpack tensor. More... | |
static void | CopyFromTo (const DLTensor *from, DLTensor *to, TVMStreamHandle stream=nullptr) |
Function to copy data from one array to another. More... | |
static bool | AbilityOfZeroCopyForDLTensor (DLTensor *tensor, const Device &dev) |
Check conditions for construction NDArray over DLTensor without copying. There are three conditions to check: More... | |
Protected Member Functions | |
Container * | get_mutable () const |
Get mutable internal container pointer. More... | |
Protected Member Functions inherited from tvm::runtime::ObjectRef | |
Object * | get_mutable () const |
Static Protected Member Functions | |
static ObjectPtr< Object > | FFIDataFromHandle (TVMArrayHandle handle) |
Construct NDArray's Data field from array handle in FFI. More... | |
static void | FFIDecRef (TVMArrayHandle handle) |
DecRef resource managed by an FFI array handle. More... | |
static TVMArrayHandle | FFIGetHandle (const ObjectRef &nd) |
Get FFI Array handle from ndarray. More... | |
Static Protected Member Functions inherited from tvm::runtime::ObjectRef | |
template<typename T > | |
static T | DowncastNoCheck (ObjectRef ref) |
Internal helper function downcast a ref without check. More... | |
static void | FFIClearAfterMove (ObjectRef *ref) |
Clear the object ref data field without DecRef after we successfully moved the field. More... | |
template<typename ObjectType > | |
static ObjectPtr< ObjectType > | GetDataPtr (const ObjectRef &ref) |
Internal helper function get data_ as ObjectPtr of ObjectType. More... | |
Friends | |
class | TVMPODValue_ |
template<typename Derived > | |
class | TVMPODValue_CRTP_ |
class | TVMRetValue |
class | TVMArgsSetter |
Additional Inherited Members | |
Static Public Attributes inherited from tvm::runtime::ObjectRef | |
static constexpr bool | _type_is_nullable = true |
Protected Attributes inherited from tvm::runtime::ObjectRef | |
ObjectPtr< Object > | data_ |
Internal pointer that backs the reference. More... | |
Managed NDArray. The array is backed by reference counted blocks.
|
inline |
default constructor
constructor.
data | ObjectPtr to the data container. |
|
static |
Check conditions for construction NDArray over DLTensor without copying. There are three conditions to check:
tensor | the DLTensor. |
dev | destination device. |
|
inline |
Copy data content from another array.
other | The source array to be copied from. |
|
inline |
void tvm::runtime::NDArray::CopyFromBytes | ( | const void * | data, |
size_t | nbytes | ||
) |
Copy data content from a byte buffer.
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. |
|
static |
Function to copy data from one array to another.
from | The source array. |
to | The target array. |
stream | The stream used in copy. |
NDArray tvm::runtime::NDArray::CopyTo | ( | const Device & | dev, |
Optional< String > | mem_scope = NullOpt |
||
) | const |
Copy the data to another device.
dev | The target device. |
mem_scope | The memory scope of the target array. |
|
inline |
|
inline |
Copy data content into another array.
other | The source array to be copied from. |
void tvm::runtime::NDArray::CopyToBytes | ( | void * | data, |
size_t | nbytes | ||
) | const |
Copy data content into another array.
data | The source bytes to be copied from. |
nbytes | The size of the data buffer. Must be equal to the size of the NDArray. |
NDArray tvm::runtime::NDArray::CreateView | ( | ShapeTuple | shape, |
DLDataType | dtype, | ||
uint64_t | relative_byte_offset = 0 |
||
) |
Create a NDArray that shares the data memory with the current one.
shape | The shape of the new array. |
dtype | The data type of the new array. |
relative_byte_offset | The offset of the output NDArray, relative to the current byte offset. |
By default, the offset of the view is the same as the offset of the current array.
relative_byte_offset
would place the end of the new array outside the bounds of the current array, this function will raise an exception. runtime::DataType tvm::runtime::NDArray::DataType | ( | ) | const |
|
inlinestaticprotected |
Construct NDArray's Data field from array handle in FFI.
handle | The array handle. |
|
inlinestaticprotected |
DecRef resource managed by an FFI array handle.
handle | The array handle. |
|
inlinestaticprotected |
Get FFI Array handle from ndarray.
nd | The object with ndarray type. |
|
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.
tensor | The DLPack tensor to copy from. |
|
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.
dl_tensor | The DLTensor for NDArray base. |
|
inlineprotected |
Get mutable internal container pointer.
|
inline |
|
inline |
|
inline |
|
inline |
reset the content of NDArray to be nullptr
|
inline |
Save NDArray to stream.
stream | The output data stream |
ShapeTuple tvm::runtime::NDArray::Shape | ( | ) | const |
DLManagedTensor* tvm::runtime::NDArray::ToDLPack | ( | ) | const |
Create a reference view of NDArray that represents as DLManagedTensor.
|
inline |
|
friend |
|
friend |
|
friend |
|
friend |