24 #ifndef TVM_RUNTIME_MEMORY_MEMORY_MANAGER_H_
25 #define TVM_RUNTIME_MEMORY_MEMORY_MANAGER_H_
34 #include <unordered_map>
69 ffi::Optional<ffi::String> mem_scope = std::nullopt);
80 DLDataType type_hint) = 0;
89 const std::string& mem_scope =
"");
100 const std::string& mem_scope =
"global") {
154 std::unordered_map<Device, std::unordered_map<AllocatorType, std::unique_ptr<Allocator>>>
171 ffi::String scope =
"global");
Managed Tensor. The array is backed by reference counted blocks.
Definition: tensor.h:49
Definition: memory_manager.h:57
virtual ~Allocator()=default
virtual TVM_RUNTIME_DLL Buffer Alloc(Device dev, size_t nbytes, size_t alignment, DLDataType type_hint)=0
Allocate a buffer given a size, alignment and type.
AllocatorType type() const
Return the allocator type.
Definition: memory_manager.h:71
TVM_RUNTIME_DLL Tensor Empty(ffi::Shape shape, DLDataType dtype, Device dev, ffi::Optional< ffi::String > mem_scope=std::nullopt)
Allocate an empty Tensor using from the allocator.
virtual TVM_RUNTIME_DLL bool AllowMemoryScope(const std::string &mem_scope) const
Check if the given memory scope is allowed to allocate by the allocator.
virtual TVM_RUNTIME_DLL void * CreateView(const Buffer &buffer, ffi::Shape shape, DLDataType type_hint, const std::string &mem_scope="global")
Create a view for the buffer given a shape, type and scope.
Definition: memory_manager.h:98
Allocator(AllocatorType type)
Definition: memory_manager.h:59
virtual TVM_RUNTIME_DLL void Clear()
Clear the allocated memory.
virtual TVM_RUNTIME_DLL size_t UsedMemory() const =0
The amount of memory currently allocated.
virtual TVM_RUNTIME_DLL void Free(const Buffer &buffer)=0
Free a buffer allocated by the allocator.
virtual TVM_RUNTIME_DLL void FreeView(Device dev, void *data)
Release the view .
Definition: memory_manager.h:108
virtual TVM_RUNTIME_DLL Buffer Alloc(Device dev, ffi::Shape shape, DLDataType type_hint, const std::string &mem_scope="")
Allocate a buffer given a shape and type.
Definition: memory_manager.h:129
static void Clear()
Clear the allocators.
std::mutex mu_
Definition: memory_manager.h:153
static TVM_RUNTIME_DLL MemoryManager * Global()
static TVM_RUNTIME_DLL Allocator * GetOrCreateAllocator(Device dev, AllocatorType type)
Get or create an allocator given the context and allocator type.
static TVM_RUNTIME_DLL Allocator * GetAllocator(Device dev, AllocatorType type)
Get an allocator given the context.
std::unordered_map< Device, std::unordered_map< AllocatorType, std::unique_ptr< Allocator > > > allocators_
Definition: memory_manager.h:155
An object representing a storage allocation.
Definition: memory_manager.h:159
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("vm.Storage", StorageObj, ffi::Object)
Buffer buffer
The index into the VM function table.
Definition: memory_manager.h:162
Allocator * allocator
The allocator where the storage buffer is allocated from.
Definition: memory_manager.h:164
~StorageObj()
Definition: memory_manager.h:173
static constexpr const bool _type_mutable
Definition: memory_manager.h:179
TVM_RUNTIME_DLL Tensor AllocTensorScoped(int64_t offset, ffi::Shape shape, DLDataType dtype, ffi::String scope="global")
Allocate an Tensor with memory scope from a given piece of storage.
TVM_RUNTIME_DLL Tensor AllocTensor(int64_t offset, ffi::Shape shape, DLDataType dtype)
Allocate an Tensor from a given piece of storage.
reference to storage.
Definition: memory_manager.h:184
TVM_RUNTIME_DLL Storage(Buffer buffer, Allocator *allocator)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Storage, ffi::ObjectRef, StorageObj)
AllocatorType
Definition: memory_manager.h:41
@ kNaive
Definition: memory_manager.h:42
@ kPooled
Definition: memory_manager.h:43
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:1981
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition: analyzer.h:37
DLDevice Device
Definition: device_api.h:43
#define TVM_RUNTIME_DLL
Definition: base.h:88
A device-independent managed Tensor abstraction.
Definition: memory_manager.h:46
Device device
The context of the allocated buffers.
Definition: memory_manager.h:52
AllocatorType alloc_type
The allocator that created this buffer.
Definition: memory_manager.h:54
void * data
The pointer to the allocated block of memory.
Definition: memory_manager.h:48
size_t size
The size of the block.
Definition: memory_manager.h:50