24 #ifndef TVM_RUNTIME_MEMORY_MEMORY_MANAGER_H_
25 #define TVM_RUNTIME_MEMORY_MEMORY_MANAGER_H_
35 #include <unordered_map>
81 DLDataType type_hint) = 0;
90 const std::string& mem_scope =
"") = 0;
135 std::unordered_map<Device, std::unordered_map<AllocatorType, std::unique_ptr<Allocator>>>
Managed NDArray. The array is backed by reference counted blocks.
Definition: ndarray.h:51
Base class of all object reference.
Definition: object.h:519
base class of all object containers.
Definition: object.h:171
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
Reference to shape tuple objects.
Definition: shape_tuple.h:85
Definition: memory_manager.h:58
NDArray Empty(ShapeTuple shape, DLDataType dtype, Device dev, Optional< String > mem_scope=NullOpt)
Allocate an empty NDArray using from the allocator.
virtual void Free(const Buffer &buffer)=0
Free a buffer allocated by the allocator.
virtual ~Allocator()=default
virtual size_t UsedMemory() const =0
The amount of memory currently allocated.
AllocatorType type() const
Return the allocator type.
Definition: memory_manager.h:72
virtual bool AllowMemoryScope(const std::string &mem_scope) const
Check if the given memory scope is allowed to allocate by the allocator.
Allocator(AllocatorType type)
Definition: memory_manager.h:60
virtual Buffer Alloc(Device dev, size_t nbytes, size_t alignment, DLDataType type_hint)=0
Allocate a buffer given a size, alignment and type.
virtual Buffer Alloc(Device dev, ShapeTuple shape, DLDataType type_hint, const std::string &mem_scope="")=0
Allocate a buffer given a shape and type.
virtual void Clear()
Clear the allocated memory.
Definition: memory_manager.h:110
static void Clear()
Clear the allocators.
static Allocator * GetOrCreateAllocator(Device dev, AllocatorType type)
Get or create an allocator given the context and allocator type.
std::mutex mu_
Definition: memory_manager.h:134
static Allocator * GetAllocator(Device dev, AllocatorType type)
Get an allocator given the context.
static MemoryManager * Global()
std::unordered_map< Device, std::unordered_map< AllocatorType, std::unique_ptr< Allocator > > > allocators_
Definition: memory_manager.h:136
An object representing a storage allocation.
Definition: memory_manager.h:140
Buffer buffer
The index into the VM function table.
Definition: memory_manager.h:143
Allocator * allocator
The allocator where the storage buffer is allocated from.
Definition: memory_manager.h:145
~StorageObj()
Definition: memory_manager.h:153
static constexpr const char * _type_key
Definition: memory_manager.h:160
TVM_DECLARE_FINAL_OBJECT_INFO(StorageObj, Object)
static constexpr const uint32_t _type_index
Definition: memory_manager.h:159
static void Deleter(Object *ptr)
The deleter for an NDArray when allocated from underlying storage.
NDArray AllocNDArray(int64_t offset, ShapeTuple shape, DLDataType dtype)
Allocate an NDArray from a given piece of storage.
reference to storage.
Definition: memory_manager.h:165
TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS(Storage, ObjectRef, StorageObj)
Storage(Buffer buffer, Allocator *allocator)
AllocatorType
Definition: memory_manager.h:42
@ kNaive
Definition: memory_manager.h:43
@ kPooled
Definition: memory_manager.h:44
Tensor shape(const Tensor &src, DataType dtype, const std::string name="T_shape", const std::string tag=kInjective)
Get the shape of input tensor.
Definition: transform.h:1913
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
DLDevice Device
Definition: ndarray.h:43
constexpr runtime::NullOptType NullOpt
Definition: optional.h:169
A device-independent managed NDArray abstraction.
A managed object in the TVM runtime.
@ kDynamic
Type index is allocated during runtime.
Definition: object.h:84
Definition: memory_manager.h:47
Device device
The context of the allocated buffers.
Definition: memory_manager.h:53
AllocatorType alloc_type
The allocator that created this buffer.
Definition: memory_manager.h:55
void * data
The pointer to the allocated block of memory.
Definition: memory_manager.h:49
size_t size
The size of the block.
Definition: memory_manager.h:51