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

An Allocator subclass for CPU memory. More...

#include <cpu_allocator.h>

Inheritance diagram for base::core::CPUAllocator:
Collaboration diagram for base::core::CPUAllocator:

Public Member Functions

void * allocate (size_t size) override
 Allocate a block of CPU memory with the given size and default alignment.
 
void * allocate (size_t size, size_t alignment) override
 Allocate a block of CPU memory with the given size and alignment.
 
void free (void *ptr) override
 Free a block of CPU memory that was previously allocated by this allocator.
 
container::DeviceType GetDeviceType () override
 Get the type of device used by the TensorBuffer.
 
- Public Member Functions inherited from base::core::Allocator
virtual size_t AllocatedSize (void *ptr)
 Get the allocated size of a given pointer.
 
virtual ~Allocator ()=default
 

Additional Inherited Members

- Protected Attributes inherited from base::core::Allocator
size_t allocated_size_ = 0
 The total number of bytes allocated by this allocator.
 

Detailed Description

An Allocator subclass for CPU memory.

This class provides an implementation of the Allocator interface for CPU memory. It uses the standard library functions std::malloc, std::free, and std::aligned_alloc to allocate and deallocate memory blocks.

Member Function Documentation

◆ allocate() [1/2]

void * base::core::CPUAllocator::allocate ( size_t  size)
overridevirtual

Allocate a block of CPU 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.

Implements base::core::Allocator.

Here is the caller graph for this function:

◆ allocate() [2/2]

void * base::core::CPUAllocator::allocate ( size_t  size,
size_t  alignment 
)
overridevirtual

Allocate a block of CPU 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.

Implements base::core::Allocator.

◆ free()

void base::core::CPUAllocator::free ( void *  ptr)
overridevirtual

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

Parameters
ptrA pointer to the memory block to free.

Implements base::core::Allocator.

Here is the caller graph for this function:

◆ GetDeviceType()

container::DeviceType base::core::CPUAllocator::GetDeviceType ( )
overridevirtual

Get the type of device used by the TensorBuffer.

Returns
MemoryType The type of memory used by the TensorBuffer.

Implements base::core::Allocator.

Here is the caller graph for this function:

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