|
Tensorium
|
Aligned memory allocator for high-performance computing. More...
#include <Allocator.hpp>
Classes | |
| struct | rebind |
| Rebinding structure for allocator traits. More... | |
Public Types | |
| using | value_type = T |
| using | pointer = T* |
| using | const_pointer = const T* |
| using | reference = T& |
| using | const_reference = const T& |
| using | size_type = std::size_t |
| using | difference_type = std::ptrdiff_t |
Public Member Functions | |
| AlignedAllocator () noexcept=default | |
| Conversion constructor from another allocator of different type. | |
| template<typename U > | |
| AlignedAllocator (const AlignedAllocator< U, Alignment > &) noexcept | |
| Default constructor. | |
| T * | allocate (std::size_t n) |
| Allocates aligned memory for n elements of type T. | |
| void | deallocate (T *p, std::size_t) noexcept |
| Deallocates memory previously allocated with allocate(). | |
Aligned memory allocator for high-performance computing.
This allocator provides memory aligned to a specified boundary, ensuring compatibility with SIMD instructions and optimal cache usage. On Intel KNL (Knights Landing) architectures, this allocator automatically uses the high-bandwidth MCDRAM via hbw_posix_memalign if the macro USE_KNL is defined. Otherwise, standard posix_memalign is used.
This is particularly useful for vectorized numerical libraries, where memory alignment is essential for instruction-level parallelism (e.g., AVX, SSE, AVX-512).
| T | Type of the objects being allocated. |
| Alignment | Memory alignment in bytes. Must be a power of two and compatible with the ISA in use (e.g., 32 for AVX256). |
| using AlignedAllocator< T, Alignment >::const_pointer = const T* |
| using AlignedAllocator< T, Alignment >::const_reference = const T& |
| using AlignedAllocator< T, Alignment >::difference_type = std::ptrdiff_t |
| using AlignedAllocator< T, Alignment >::pointer = T* |
| using AlignedAllocator< T, Alignment >::reference = T& |
| using AlignedAllocator< T, Alignment >::size_type = std::size_t |
| using AlignedAllocator< T, Alignment >::value_type = T |
|
defaultnoexcept |
Conversion constructor from another allocator of different type.
Required by the STL allocator model. Does nothing as this allocator is stateless.
| U | Other type. |
| other | The other allocator. |
|
inlinenoexcept |
Default constructor.
Stateless and noexcept.
|
inline |
Allocates aligned memory for n elements of type T.
The alignment is guaranteed to be at least Alignment bytes. On KNL platforms, high-bandwidth memory (HBM) will be used via libhbw.
| n | Number of elements to allocate. |
| std::bad_alloc | If memory allocation fails. |
|
inlinenoexcept |
Deallocates memory previously allocated with allocate().
On KNL platforms, this calls hbw_free. Otherwise, standard free is used.
| p | Pointer to memory to deallocate. |
| size | Number of elements (not used). |