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

An allocator that allocates memory on a GPU device. More...

#include <bfc_allocator.h>

Inheritance diagram for base::core::BFCAllocator:
Collaboration diagram for base::core::BFCAllocator:

Classes

struct  bin
 
struct  chunk
 
struct  Options
 

Public Member Functions

 BFCAllocator (std::unique_ptr< Allocator > sub_alloc, const size_t &total_memory, const Options &options=Options())
 
 ~BFCAllocator ()
 
void * allocate (size_t size) override
 Allocate a block of memory with the given size and default alignment on GPU.
 
void * allocate (size_t size, size_t alignment) override
 Allocate a block of memory with the given size and alignment on GPU.
 
void free (void *ptr) override
 Free a block of GPU memory that was previously allocated by this allocator.
 
DeviceType GetDeviceType () override
 Get the type of memory 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
 

Private Types

typedef size_t chunk_handle_t
 
typedef int bin_index_t
 

Private Attributes

std::unique_ptr< Allocatorsub_alloc_
 
std::mutex mtx_
 

Static Private Attributes

static constexpr chunk_handle_t kInvalidChunkHandle = UINT64_MAX
 
static constexpr int kInvalidBinNum = -1
 
static constexpr int kNumBins = 21
 

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 that allocates memory on a GPU device.

This class provides an implementation of the Allocator interface that allocates memory on a GPU device using CUDA APIs.

Member Typedef Documentation

◆ bin_index_t

◆ chunk_handle_t

Constructor & Destructor Documentation

◆ BFCAllocator()

base::core::BFCAllocator::BFCAllocator ( std::unique_ptr< Allocator sub_alloc,
const size_t &  total_memory,
const Options options = Options() 
)

◆ ~BFCAllocator()

base::core::BFCAllocator::~BFCAllocator ( )

Member Function Documentation

◆ allocate() [1/2]

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

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

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.

◆ allocate() [2/2]

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

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

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::BFCAllocator::free ( void *  ptr)
overridevirtual

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

Parameters
ptrA pointer to the memory block to free.

Implements base::core::Allocator.

◆ GetDeviceType()

DeviceType base::core::BFCAllocator::GetDeviceType ( )
overridevirtual

Get the type of memory used by the TensorBuffer.

Returns
MemoryType The type of memory used by the TensorBuffer.

Implements base::core::Allocator.

Member Data Documentation

◆ kInvalidBinNum

constexpr int base::core::BFCAllocator::kInvalidBinNum = -1
staticconstexprprivate

◆ kInvalidChunkHandle

constexpr chunk_handle_t base::core::BFCAllocator::kInvalidChunkHandle = UINT64_MAX
staticconstexprprivate

◆ kNumBins

constexpr int base::core::BFCAllocator::kNumBins = 21
staticconstexprprivate

◆ mtx_

std::mutex base::core::BFCAllocator::mtx_
mutableprivate

◆ sub_alloc_

std::unique_ptr<Allocator> base::core::BFCAllocator::sub_alloc_
private

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