ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
tensor_buffer.h
Go to the documentation of this file.
1#ifndef ATEN_CORE_TENSOR_BUFFER_H_
2#define ATEN_CORE_TENSOR_BUFFER_H_
3
7
8namespace container {
9
14 public:
21 TensorBuffer(base::core::Allocator* alloc, void* data_ptr);
22
23 TensorBuffer(base::core::Allocator* alloc, size_t size);
24
32 explicit TensorBuffer(void* data_ptr);
33
44 TensorBuffer(TensorBuffer&& other) noexcept;
45
50
56 void* data() const;
57
61 void resize(size_t size);
62
68 size_t GetAllocatedBytes() const;
69
79
86
93 template <typename T>
94 T* base() const {
95 return reinterpret_cast<T*>(data());
96 }
97
104 virtual bool OwnsMemory() const;
105
112
122 TensorBuffer& operator=(const TensorBuffer& other);
123
135 TensorBuffer& operator=(TensorBuffer&& other) noexcept;
136
137
138 private:
140 void *data_ = nullptr;
141 bool owns_memory_ = false;
142 int64_t allocated_bytes_ = 0;
143};
144
145} // namespace container
146
147#endif // ATEN_CORE_TENSOR_BUFFER_H_
An abstract base class for memory allocators.
Definition allocator.h:17
The base class for reference-counted objects.
Definition refcount.h:14
Interface to access the raw ref-counted data buffer.
Definition tensor_buffer.h:13
DeviceType GetDeviceType() const
Get the type of device used by the TensorBuffer.
Definition tensor_buffer.cpp:77
~TensorBuffer()
Destroy the TensorBuffer object.
Definition tensor_buffer.cpp:44
TensorBuffer & operator=(const TensorBuffer &other)
Assignment operator overload for the TensorBuffer class.
Definition tensor_buffer.cpp:98
int64_t allocated_bytes_
The number of bytes allocated for this buffer.
Definition tensor_buffer.h:142
TensorBuffer * root_buffer()
Get the root TensorBuffer object.
Definition tensor_buffer.cpp:66
void * data() const
Get the raw data pointer.
Definition tensor_buffer.cpp:54
void * data_
Pointer to the underlying data buffer.
Definition tensor_buffer.h:140
bool owns_memory_
Bool to indicate whether this tensor owns it's memory.
Definition tensor_buffer.h:141
void resize(size_t size)
resize the tensor buffer
Definition tensor_buffer.cpp:84
T * base() const
Reinterpret the buffer as an array of type T.
Definition tensor_buffer.h:94
base::core::Allocator * allocator() const
Get the Allocator object used in this class.
Definition tensor_buffer.cpp:69
base::core::Allocator * alloc_
Pointer to the allocator used for memory allocation.
Definition tensor_buffer.h:139
size_t GetAllocatedBytes() const
Get the size of the buffer.
Definition tensor_buffer.cpp:59
virtual bool OwnsMemory() const
Check whether this TensorBuffer owns the underlying memory.
Definition tensor_buffer.cpp:74
#define T
Definition exp.cpp:237
Definition tensor.cpp:8
DeviceType
The type of memory used by an allocator.
Definition tensor_types.h:73
This file contains the definition of the DataType enum class.