|
MTL5 -- Matrix Template Library C++ API
mtl:: -- C++20 header-only linear algebra for mixed-precision algorithm design
|
Contiguous memory block with compile-time stack/heap selection. More...
#include <contiguous_memory_block.hpp>
Public Types | |
| using | value_type = Value |
| using | size_type = std::size_t |
| using | memory_space = Space |
| using | handle_type = handle |
| How Space names the storage: Value* for host memory and for every space whose handle is a pointer (#1017). | |
| using | const_handle_type = const_handle |
Public Member Functions | |
| bool | assigns_in_place (std::size_t other_size) const noexcept |
| Whether assigning a block of other_size writes into this block's elements in place, rather than replacing its storage. | |
| contiguous_memory_block () | |
| contiguous_memory_block (std::size_t n) | |
| contiguous_memory_block (handle ptr, std::size_t n, bool is_view) | |
| contiguous_memory_block (const contiguous_memory_block &other) | |
| contiguous_memory_block (contiguous_memory_block &&other) noexcept(!fixed_heap) | |
| contiguous_memory_block & | operator= (const contiguous_memory_block &other) |
| contiguous_memory_block & | operator= (contiguous_memory_block &&other) noexcept |
| ~contiguous_memory_block () | |
| handle_type | data () |
| The handle of the storage: a pointer in every space whose handle is one. | |
| const_handle_type | data () const |
| Value * | host_data () |
| The host address of the elements, in a host-accessible space. | |
| const Value * | host_data () const |
| Value & | operator[] (std::size_t i) |
| const Value & | operator[] (std::size_t i) const |
| std::size_t | size () const |
| bool | empty () const |
| Value * | begin () |
| const Value * | begin () const |
| Value * | end () |
| const Value * | end () const |
| memory_category | category () const |
| void | realloc (std::size_t n) |
| void | swap (contiguous_memory_block &other) noexcept |
Static Public Attributes | |
| static constexpr bool | fixed_heap = !on_stack && StaticSize > 0 |
Contiguous memory block with compile-time stack/heap selection.
Stack path: StaticSize-element array with alignas. Heap path: new[]/delete[] with three ownership modes (own, external, view).
Assignment never re-points a non-owning (external or view) block (#829):
A fixed-size heap block (StaticSize > 0) always holds StaticSize elements: the default constructor allocates them, and a moved-from block gets fresh storage (move assignment swaps instead, so it does not allocate).
Space is the memory space the heap storage lives in (#223), by default memory_space::host: over-aligned new and delete, as before. An owning block allocates and frees through Space, so it needs an AllocatingMemorySpace; a non-owning block (external or view) only records where the caller's memory lives. Copying or moving elements, and element access, are host operations and need a host-accessible space; they fail to compile otherwise. Stack storage is host memory.
The heap storage is named by Space's handle (#1017): a Value* for every space whose handle is a pointer, which keeps the layout and code of host blocks unchanged, and an object with an offset for a space whose storage is not addressed by a pointer (a Metal buffer, an OpenCL cl_mem). data() returns the handle; element access goes through the space's host address for it (detail::handle_traits).
| using mtl::detail::contiguous_memory_block< Value, Storage, StaticSize, Space >::const_handle_type = const_handle |
| using mtl::detail::contiguous_memory_block< Value, Storage, StaticSize, Space >::handle_type = handle |
How Space names the storage: Value* for host memory and for every space whose handle is a pointer (#1017).
| using mtl::detail::contiguous_memory_block< Value, Storage, StaticSize, Space >::memory_space = Space |
| using mtl::detail::contiguous_memory_block< Value, Storage, StaticSize, Space >::size_type = std::size_t |
| using mtl::detail::contiguous_memory_block< Value, Storage, StaticSize, Space >::value_type = Value |
|
inline |
|
inlineexplicit |
|
inline |
|
inline |
|
inlinenoexcept |
|
inline |
|
inlinenoexcept |
Whether assigning a block of other_size writes into this block's elements in place, rather than replacing its storage.
|
inline |
|
inline |
|
inline |
|
inline |
The handle of the storage: a pointer in every space whose handle is one.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
The host address of the elements, in a host-accessible space.
An empty block's is nullptr: a handle that names no storage never reaches the space's address(), which need not accept one (review of issue 1017).
|
inline |
|
inline |
|
inlinenoexcept |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlinenoexcept |
|
staticconstexpr |