tvm
Public Member Functions | Protected Member Functions | List of all members
tvm::runtime::memory::Allocator Class Referenceabstract

#include <memory_manager.h>

Collaboration diagram for tvm::runtime::memory::Allocator:

Public Member Functions

 Allocator (AllocatorType type)
 
virtual ~Allocator ()=default
 
NDArray Empty (ShapeTuple shape, DLDataType dtype, Device dev, Optional< String > mem_scope=NullOpt)
 Allocate an empty NDArray using from the allocator. More...
 
AllocatorType type () const
 Return the allocator type. More...
 
virtual Buffer Alloc (Device dev, size_t nbytes, size_t alignment, DLDataType type_hint)=0
 Allocate a buffer given a size, alignment and type. More...
 
virtual Buffer Alloc (Device dev, ShapeTuple shape, DLDataType type_hint, const std::string &mem_scope="")=0
 Allocate a buffer given a shape and type. More...
 
virtual void Free (const Buffer &buffer)=0
 Free a buffer allocated by the allocator. More...
 
virtual void Clear ()
 Clear the allocated memory. More...
 
virtual size_t UsedMemory () const =0
 The amount of memory currently allocated. More...
 

Protected Member Functions

virtual bool AllowMemoryScope (const std::string &mem_scope) const
 Check if the given memory scope is allowed to allocate by the allocator. More...
 

Constructor & Destructor Documentation

◆ Allocator()

tvm::runtime::memory::Allocator::Allocator ( AllocatorType  type)
inlineexplicit

◆ ~Allocator()

virtual tvm::runtime::memory::Allocator::~Allocator ( )
virtualdefault

Member Function Documentation

◆ Alloc() [1/2]

virtual Buffer tvm::runtime::memory::Allocator::Alloc ( Device  dev,
ShapeTuple  shape,
DLDataType  type_hint,
const std::string &  mem_scope = "" 
)
pure virtual

Allocate a buffer given a shape and type.

Parameters
devThe device where the array is allocated.
shapeThe shape of the tensor.
type_hintA type hint to the allocator.
mem_scopeA memory scope of the buffer.
Returns
A sized allocation in the form of a buffer.

◆ Alloc() [2/2]

virtual Buffer tvm::runtime::memory::Allocator::Alloc ( Device  dev,
size_t  nbytes,
size_t  alignment,
DLDataType  type_hint 
)
pure virtual

Allocate a buffer given a size, alignment and type.

Parameters
devThe device where the array is allocated.
nbytesThe size of the buffer.
alignmentThe alignment of the buffer.
type_hintA type hint to the allocator.
Returns
A sized allocation in the form of a buffer.

◆ AllowMemoryScope()

virtual bool tvm::runtime::memory::Allocator::AllowMemoryScope ( const std::string &  mem_scope) const
protectedvirtual

Check if the given memory scope is allowed to allocate by the allocator.

◆ Clear()

virtual void tvm::runtime::memory::Allocator::Clear ( )
virtual

Clear the allocated memory.

◆ Empty()

NDArray tvm::runtime::memory::Allocator::Empty ( ShapeTuple  shape,
DLDataType  dtype,
Device  dev,
Optional< String mem_scope = NullOpt 
)

Allocate an empty NDArray using from the allocator.

Parameters
shapeThe shape of the NDArray.
dtypeThe datatype of the NDArray.
devThe device where the array is allocated.
mem_scopeThe device memory scope hint.
Returns
The empty NDArray.

◆ Free()

virtual void tvm::runtime::memory::Allocator::Free ( const Buffer buffer)
pure virtual

Free a buffer allocated by the allocator.

Parameters
bufferThe buffer to free.

◆ type()

AllocatorType tvm::runtime::memory::Allocator::type ( ) const
inline

Return the allocator type.

◆ UsedMemory()

virtual size_t tvm::runtime::memory::Allocator::UsedMemory ( ) const
pure virtual

The amount of memory currently allocated.

Returns
The amount of memory currently allocated.

The documentation for this class was generated from the following file: