ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
base::core::Allocator Class Referenceabstract

An abstract base class for memory allocators. More...

#include <allocator.h>

Inheritance diagram for base::core::Allocator:
Collaboration diagram for base::core::Allocator:

Public Member Functions

virtual void * allocate (size_t size)=0
 Allocate a block of memory with the given size and default alignment.
 
virtual void * allocate (size_t size, size_t alignment)=0
 Allocate a block of memory with the given size and alignment.
 
virtual void free (void *ptr)=0
 Free a block of memory that was previously allocated by this allocator.
 
virtual size_t AllocatedSize (void *ptr)
 Get the allocated size of a given pointer.
 
virtual container::DeviceType GetDeviceType ()=0
 Get the type of memory used by the TensorBuffer.
 
virtual ~Allocator ()=default
 

Protected Attributes

size_t allocated_size_ = 0
 The total number of bytes allocated by this allocator.
 

Detailed Description

An abstract base class for memory allocators.

This class defines an interface for memory allocators. Subclasses of this class can provide different implementations of memory allocation/deallocation strategies.

All memory allocated by an Allocator must be freed using the same allocator that allocated it.

Constructor & Destructor Documentation

◆ ~Allocator()

virtual base::core::Allocator::~Allocator ( )
virtualdefault

Member Function Documentation

◆ allocate() [1/2]

virtual void * base::core::Allocator::allocate ( size_t  size)
pure virtual

Allocate a block of memory with the given size and default alignment.

Parameters
sizeThe size of the memory block to allocate.
Returns
A pointer to the allocated memory block, or nullptr if the allocation fails.

Implemented in base::core::BFCAllocator, base::core::CPUAllocator, and base::core::GPUAllocator.

Here is the caller graph for this function:

◆ allocate() [2/2]

virtual void * base::core::Allocator::allocate ( size_t  size,
size_t  alignment 
)
pure virtual

Allocate a block of memory with the given size and alignment.

Parameters
sizeThe size of the memory block to allocate.
alignmentThe alignment of the memory block to allocate.
Returns
A pointer to the allocated memory block, or nullptr if the allocation fails.

Implemented in base::core::BFCAllocator, base::core::CPUAllocator, and base::core::GPUAllocator.

◆ AllocatedSize()

virtual size_t base::core::Allocator::AllocatedSize ( void *  ptr)
inlinevirtual

Get the allocated size of a given pointer.

Parameters
ptrThe pointer to get the allocated size of.
Returns
size_t The size of the allocated block of memory, in bytes.

◆ free()

virtual void base::core::Allocator::free ( void *  ptr)
pure virtual

Free a block of memory that was previously allocated by this allocator.

Parameters
ptrA pointer to the memory block to free.

Implemented in base::core::BFCAllocator, base::core::CPUAllocator, and base::core::GPUAllocator.

Here is the caller graph for this function:

◆ GetDeviceType()

virtual container::DeviceType base::core::Allocator::GetDeviceType ( )
pure virtual

Get the type of memory used by the TensorBuffer.

Returns
MemoryType The type of memory used by the TensorBuffer.

Implemented in base::core::BFCAllocator, base::core::CPUAllocator, and base::core::GPUAllocator.

Here is the caller graph for this function:

Member Data Documentation

◆ allocated_size_

size_t base::core::Allocator::allocated_size_ = 0
protected

The total number of bytes allocated by this allocator.


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