|
| | TensorBuffer (const TensorBuffer &)=delete |
| | Copy operations explicitly deleted for performance safety.
|
| | TensorBuffer (int device_id, size_t logical_size) |
| | Constructs buffer with owned memory.
|
| | TensorBuffer (TensorBuffer &&other) noexcept |
| | Move constructor for efficient ownership transfer.
|
| | ~TensorBuffer () |
| | Destructor with automatic memory cleanup via RAII.
|
| size_t | alignedSize () const noexcept |
| | Returns the aligned memory allocation size in bytes.
|
| const void * | data () const noexcept |
| | Returns const raw pointer to buffer data.
|
| void * | data () noexcept |
| | Returns raw pointer to buffer data.
|
| bool | empty () const noexcept |
| | Checks if the buffer is empty.
|
| Compute::MemoryResource * | getMemoryResource () const noexcept |
| | Returns pointer to the memory resource managing this buffer's storage.
|
| bool | isAligned () const noexcept |
| | Checks if buffer memory is properly aligned.
|
|
TensorBuffer & | operator= (const TensorBuffer &)=delete |
| TensorBuffer & | operator= (TensorBuffer &&other) noexcept |
| | Move assignment operator for efficient ownership transfer.
|
| void | resize (size_t new_logical_size) |
| | Resizes buffer WITHOUT preserving existing data.
|
| size_t | size () const noexcept |
| | Returns the number of logical elements in the buffer.
|
| size_t | storageBytes () const noexcept |
| | Returns the storage size in bytes.
|
|
|
static constexpr size_t | alignment = Detail::get_alignment<TDataType, TMemoryResource>() |
| | Optimal memory alignment.
|
|
static constexpr TensorDataType | data_type = TDataType |
| | Compile-time data type constant.
|
|
static constexpr size_t | element_size = DataTypeTraits::size_in_bytes |
| | Storage size per element.
|
|
static constexpr bool | is_device_only = DataTypeTraits::is_device_only |
| | Device-only type restriction.
|
|
static constexpr bool | is_float_type = DataTypeTraits::is_float_type |
| | Floating-point type classification.
|
|
static constexpr bool | is_integer_type = DataTypeTraits::is_integer_type |
| | Integer type classification.
|
template<
TensorDataType TDataType, typename TMemoryResource, bool TrackMemory = false>
requires isValidTensor<TDataType, TMemoryResource>
class Mila::Dnn::TensorBuffer< TDataType, TMemoryResource, TrackMemory >
Device-agnostic buffer for storing tensor data with abstract type system.
Advanced memory management container providing efficient storage for tensor data across heterogeneous compute environments using abstract TensorDataType enumeration. Supports device-specific alignment optimization and automatic compatibility validation.
Core architectural principles:
- Abstract data types prevent device-specific compilation issues
- Automatic memory alignment optimization for target hardware
- Support for precision formats including FP32, FP16, BF16, FP8, and integer types
- Device-agnostic memory operations with compile-time dispatch optimization
- Optional allocation tracking for memory profiling and debugging
- Exception-safe design with strong safety guarantees
The buffer supports both owned memory management and external memory wrapping, enabling integration with existing memory pools and external libraries while maintaining optimal performance characteristics.
- Template Parameters
-
| TDataType | Abstract tensor data type from TensorDataType enumeration |
| TMemoryResource | Memory resource type determining allocation strategy and device targeting |
| TrackMemory | When true, enables detailed memory allocation tracking and profiling |
- Note
- Thread Safety: Buffer operations are not thread-safe; external synchronization required
-
Exception Safety: Strong guarantee for most operations; basic guarantee for constructors
-
Memory Layout: Automatic optimization for device-specific alignment
-
Memory Transfers: Transfer operations belong at the Tensor level where device contexts are meaningful
- See also
- TensorDataType for supported abstract data type enumeration
-
TensorDataTypeTraits for compile-time data type characteristics
-
MemoryResource for device memory abstraction layer
Example usage:
TensorBuffer(int device_id, size_t logical_size)
Constructs buffer with owned memory.
Definition TensorBuffer.ixx:212