ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
container::TensorBuffer Class Reference

Interface to access the raw ref-counted data buffer. More...

#include <tensor_buffer.h>

Inheritance diagram for container::TensorBuffer:
Collaboration diagram for container::TensorBuffer:

Public Member Functions

 TensorBuffer (base::core::Allocator *alloc, void *data_ptr)
 Construct a new TensorBuffer object.
 
 TensorBuffer (base::core::Allocator *alloc, size_t size)
 
 TensorBuffer (void *data_ptr)
 Construct a new TensorBuffer object.
 
 TensorBuffer (TensorBuffer &&other) noexcept
 Move constructor for the TensorBuffer class.
 
 ~TensorBuffer ()
 Destroy the TensorBuffer object.
 
void * data () const
 Get the raw data pointer.
 
void resize (size_t size)
 resize the tensor buffer
 
size_t GetAllocatedBytes () const
 Get the size of the buffer.
 
TensorBufferroot_buffer ()
 Get the root TensorBuffer object.
 
base::core::Allocatorallocator () const
 Get the Allocator object used in this class.
 
template<typename T >
Tbase () const
 Reinterpret the buffer as an array of type T.
 
virtual bool OwnsMemory () const
 Check whether this TensorBuffer owns the underlying memory.
 
DeviceType GetDeviceType () const
 Get the type of device used by the TensorBuffer.
 
TensorBufferoperator= (const TensorBuffer &other)
 Assignment operator overload for the TensorBuffer class.
 
TensorBufferoperator= (TensorBuffer &&other) noexcept
 Move assignment operator overload for the TensorBuffer class.
 
- Public Member Functions inherited from base::core::counted_base
 counted_base ()
 Default constructor. Initializes the reference count to one.
 
void ref () const
 Increases the reference count by one.
 
bool unref () const
 Decreases the reference count by one.
 
int_fast32_t ref_count () const
 Gets the current reference count.
 
bool ref_count_is_one () const
 Checks if the reference count is one.
 

Private Attributes

base::core::Allocatoralloc_ = nullptr
 Pointer to the allocator used for memory allocation.
 
void * data_ = nullptr
 Pointer to the underlying data buffer.
 
bool owns_memory_ = false
 Bool to indicate whether this tensor owns it's memory.
 
int64_t allocated_bytes_ = 0
 The number of bytes allocated for this buffer.
 

Additional Inherited Members

- Protected Member Functions inherited from base::core::counted_base
virtual ~counted_base ()
 Virtual destructor.
 

Detailed Description

Interface to access the raw ref-counted data buffer.

Constructor & Destructor Documentation

◆ TensorBuffer() [1/4]

container::TensorBuffer::TensorBuffer ( base::core::Allocator alloc,
void *  data_ptr 
)

Construct a new TensorBuffer object.

Parameters
allocPointer to the allocator to use for memory allocation.
data_ptrPointer to the underlying data buffer.

◆ TensorBuffer() [2/4]

container::TensorBuffer::TensorBuffer ( base::core::Allocator alloc,
size_t  size 
)
Here is the call graph for this function:

◆ TensorBuffer() [3/4]

container::TensorBuffer::TensorBuffer ( void *  data_ptr)
explicit

Construct a new TensorBuffer object.

This is a reference TensorBuffer, does not owns memory itself.

Parameters
data_ptrPointer to the given data buffer.

◆ TensorBuffer() [4/4]

container::TensorBuffer::TensorBuffer ( TensorBuffer &&  other)
noexcept

Move constructor for the TensorBuffer class.

This constructor is used to move the contents and ownership of another TensorBuffer object into the newly created object using move semantics. The source TensorBuffer's resources will be taken over, and the source object will be left in a valid but unspecified state.

Parameters
otherThe rvalue reference to the source TensorBuffer object to be moved.
Note
This function is declared as noexcept, indicating that it does not throw exceptions.

◆ ~TensorBuffer()

container::TensorBuffer::~TensorBuffer ( )

Destroy the TensorBuffer object.

Here is the call graph for this function:

Member Function Documentation

◆ allocator()

base::core::Allocator * container::TensorBuffer::allocator ( ) const

Get the Allocator object used in this class.

Returns
Allocator* Pointer to the Allocator object.
Here is the caller graph for this function:

◆ base()

template<typename T >
T * container::TensorBuffer::base ( ) const
inline

Reinterpret the buffer as an array of type T.

Template Parameters
TThe type to reinterpret the buffer as.
Returns
T* Pointer to the underlying buffer reinterpreted as type T.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ data()

void * container::TensorBuffer::data ( ) const

Get the raw data pointer.

Returns
void* Pointer to the underlying data buffer.
Here is the caller graph for this function:

◆ GetAllocatedBytes()

size_t container::TensorBuffer::GetAllocatedBytes ( ) const

Get the size of the buffer.

Returns
size_t The size of the buffer in bytes.
Here is the caller graph for this function:

◆ GetDeviceType()

DeviceType container::TensorBuffer::GetDeviceType ( ) const

Get the type of device used by the TensorBuffer.

Returns
MemoryType The type of memory used by the TensorBuffer.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=() [1/2]

TensorBuffer & container::TensorBuffer::operator= ( const TensorBuffer other)

Assignment operator overload for the TensorBuffer class.

This operator is used to assign the values of another TensorBuffer object to the current object. It performs a deep copy of the data from the source TensorBuffer to the destination TensorBuffer.

Parameters
otherThe source TensorBuffer object whose values will be assigned.
Returns
A reference to the current TensorBuffer object after the assignment.
Here is the call graph for this function:

◆ operator=() [2/2]

TensorBuffer & container::TensorBuffer::operator= ( TensorBuffer &&  other)
noexcept

Move assignment operator overload for the TensorBuffer class.

This operator is used to move the contents and ownership of another TensorBuffer object into the current object using move semantics. The source TensorBuffer's resources will be taken over, and the source object will be left in a valid but unspecified state.

Parameters
otherThe rvalue reference to the source TensorBuffer object to be moved.
Returns
A reference to the current TensorBuffer object after the move assignment.
Note
This function is declared as noexcept, indicating that it does not throw exceptions.

◆ OwnsMemory()

bool container::TensorBuffer::OwnsMemory ( ) const
virtual

Check whether this TensorBuffer owns the underlying memory.

Returns
true If the TensorBuffer owns the underlying memory.
false If the TensorBuffer does not own the underlying memory.
Here is the caller graph for this function:

◆ resize()

void container::TensorBuffer::resize ( size_t  size)

resize the tensor buffer

Here is the call graph for this function:
Here is the caller graph for this function:

◆ root_buffer()

TensorBuffer * container::TensorBuffer::root_buffer ( )

Get the root TensorBuffer object.

If this TensorBuffer is a sub-buffer of another TensorBuffer, returns that TensorBuffer. Otherwise, returns this.

Returns
TensorBuffer* Pointer to the root TensorBuffer object.
Here is the caller graph for this function:

Member Data Documentation

◆ alloc_

base::core::Allocator* container::TensorBuffer::alloc_ = nullptr
private

Pointer to the allocator used for memory allocation.

◆ allocated_bytes_

int64_t container::TensorBuffer::allocated_bytes_ = 0
private

The number of bytes allocated for this buffer.

◆ data_

void* container::TensorBuffer::data_ = nullptr
private

Pointer to the underlying data buffer.

◆ owns_memory_

bool container::TensorBuffer::owns_memory_ = false
private

Bool to indicate whether this tensor owns it's memory.


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