|
FEAT 3
Finite Element Analysis Toolbox
|
#include <memory_arbiter.hpp>
Public Member Functions | |
| Arbiter () | |
| standard constructor More... | |
| Arbiter (Arbiter &&other) | |
| move constructor More... | |
| Arbiter (const Arbiter &other)=delete | |
| deleted copy constructor | |
| Arbiter (std::size_t bytes, Location mem_loc=Location::none, Init mem_ini=Init::dont_care) | |
| Creates a new memory arbiter block of a given size. More... | |
| ~Arbiter () | |
| destructor More... | |
| void | alloc (Location mem_loc, Init mem_ini=Init::dont_care) |
| Allocates memory for a given memory block. More... | |
| void | attach (const Arbiter &other, std::size_t offset=0u, std::size_t size=full_size) |
| Attaches this arbiter to another arbiter's memory block. More... | |
| Arbiter | attach (std::size_t offset=0u, std::size_t size=full_size) const |
| Creates a new arbiter that is attached to the same memory block as this arbiter. More... | |
| std::size_t | block_bytes () const |
| Returns the size of the entire attached memory block in bytes. More... | |
| std::size_t | bytes () const |
| Returns the size of the arbiter's range in the attached memory block in bytes. More... | |
| void | clone (const Arbiter &source, std::size_t offset=0u, std::size_t size=full_size, bool clone_block=false) |
| Sets this arbiter to a deep copy of (a sub-region of) another arbiter's memory block. More... | |
| Arbiter | clone (std::size_t offset=0u, std::size_t size=full_size, bool clone_block=false) const |
| Creates a new arbiter that contains a deep copy to (a sub-region of) this arbiters memory block. More... | |
| template<typename Tdst_ , typename Tsrc_ > | |
| void | convert (const Arbiter &source) |
| Converts the contents of one memory block into another one by casting the underlying data types. More... | |
| template<typename Tdst_ , typename Tsrc_ > | |
| void | convert (const Arbiter &source, Location mem_loc) |
| Converts the contents of one memory block into another one by casting the underlying data types. More... | |
| void | copy (const Arbiter &source, Location mem_loc=Location::none) |
| Copies of the contents of one memory block into another one. More... | |
| void | copy (const void *src_ptr, Location src_loc, Location mem_loc=Location::none) |
| Copies of the contents of a raw memory region into this memory block. More... | |
| void | copy_to (void *dst_ptr, Location dst_loc) const |
| Copies the contents of this memory block into a raw memory region. More... | |
| template<typename T_ > | |
| void | format (const T_ &value, Location mem_loc) |
| Formats the memory block to a given value. More... | |
| void | format (Location mem_loc=Location::none) |
| Formats the memory block to zero. More... | |
| void | format_random (Location mem_loc=Location::none) |
| Formats the memory block to random values. More... | |
| void | free (Location mem_loc) |
| Frees memory for a given memory block. More... | |
| Location | location () const |
| Returns a combination of all up-to-date memory locations. More... | |
| operator bool () const | |
| Checks whether this arbiter is not the null arbiter. More... | |
| bool | operator!= (const Arbiter &other) const |
| Checks whether two arbiters refer to the different memory regions. More... | |
| Arbiter & | operator= (Arbiter &&other) |
| move-assign operator More... | |
| Arbiter & | operator= (const Arbiter &other)=delete |
| deleted copy-assign operator | |
| bool | operator== (const Arbiter &other) const |
| Checks whether two arbiters refer to the same memory region. More... | |
| void | release () |
| Releases this arbiter from its associated memory block and frees it if necessary. More... | |
| bool | same_block (const Arbiter &other) const |
| Checks whether two arbiters refer to the same memory block ignoring offset and size. More... | |
| template<typename T_ > | |
| TypedView< T_ > | typed_view (Location mem_loc, Access access) |
| Maps a typed view to a memory block. More... | |
| template<typename T_ > | |
| TypedView< T_ > | typed_view (Location mem_loc, Access access=Access::read) const |
| Maps a read-only typed view to a memory block. More... | |
| View | view (Location mem_loc, Access access) |
| Maps a raw view to a memory block. More... | |
| View | view (Location mem_loc, Access access=Memory::Access::read) const |
| Maps a raw read-only view to the arbiters memory block. More... | |
Static Public Attributes | |
| static constexpr std::size_t | full_size = ~std::size_t(0) |
| full size constant for size parameters More... | |
Private Member Functions | |
| Arbiter (Block *block, std::size_t offset, std::size_t size) | |
| private constructor More... | |
| void | _move (Arbiter &&other) |
| moves another arbiter into this one More... | |
Private Attributes | |
| Block * | _block |
| a pointer to the memory block associated with this arbiter More... | |
| std::size_t | _offset |
| the offset of this arbiter's memory region within the block More... | |
| std::size_t | _size |
| size of this arbiter's memory region within the block More... | |
Memory arbiter class.
This class implements a memory-location-aware reference-counted smart pointer, which is capable of automatically transferring memory between host and device memory when needed without explicit synchronization by the user.
See The Memory Arbiter and its View classes for more information.
Definition at line 636 of file memory_arbiter.hpp.
|
explicitprivate |
private constructor
Definition at line 1153 of file memory_arbiter.cpp.
References FEAT::Memory::Block::bytes, full_size, and XASSERT.
|
inline |
standard constructor
Definition at line 660 of file memory_arbiter.hpp.
|
explicit |
Creates a new memory arbiter block of a given size.
| [in] | bytes | The size of the memory block to be created in bytes. |
| [in] | mem_loc | A combination of memory locations on which the memory block has to be allocated at time of creation, i.e. during this function call. If set to Location::none, then no memory is allocated initially and the allocation is performed when the first view to this memory block is mapped. |
| [in] | mem_ini | Specifies how the memory of this block is to be initialized if memory is to be allocated during this function call, i.e. if mem_loc != Location::none. |
Definition at line 1175 of file memory_arbiter.cpp.
| FEAT::Memory::Arbiter::Arbiter | ( | Arbiter && | other | ) |
| FEAT::Memory::Arbiter::~Arbiter | ( | ) |
|
private |
moves another arbiter into this one
Definition at line 1205 of file memory_arbiter.cpp.
References _block, _offset, _size, and XASSERT.
Referenced by Arbiter(), attach(), clone(), and operator=().
| void FEAT::Memory::Arbiter::alloc | ( | Location | mem_loc, |
| Init | mem_ini = Init::dont_care |
||
| ) |
Allocates memory for a given memory block.
| [in] | mem_loc | A combination of memory locations on which the memory block has to be allocated |
| [in] | mem_ini | Specifies how the memory of this block is to be initialized if memory is to be allocated |
Definition at line 1394 of file memory_arbiter.cpp.
References _block.
| void FEAT::Memory::Arbiter::attach | ( | const Arbiter & | other, |
| std::size_t | offset = 0u, |
||
| std::size_t | size = full_size |
||
| ) |
Attaches this arbiter to another arbiter's memory block.
This function is effectively equivalent to
other as well as this arbiter will point to the same memory block. If you indent to perform a deep copy instead, use the clone() function instead.| [in] | other | A transient reference to another arbiter to whose block this arbiter should attach to. |
Definition at line 1249 of file memory_arbiter.cpp.
References _block, _move(), _offset, _size, attach(), FEAT::Memory::Block::bytes, and full_size.
| Arbiter FEAT::Memory::Arbiter::attach | ( | std::size_t | offset = 0u, |
| std::size_t | size = full_size |
||
| ) | const |
Creates a new arbiter that is attached to the same memory block as this arbiter.
Definition at line 1216 of file memory_arbiter.cpp.
References Arbiter(), _block, _offset, _size, FEAT::Memory::Block::bytes, and full_size.
Referenced by FEAT::LAFEM::MatrixMirrorBuffer< DT_, IT_ >::MatrixMirrorBuffer(), FEAT::LAFEM::SparseMatrixBanded< DT_, IT_ >::SparseMatrixBanded(), FEAT::LAFEM::SparseMatrixBCSR< DT_, IT_, block_height_, block_width_ >::SparseMatrixBCSR(), FEAT::LAFEM::SparseMatrixCSCR< DT_, IT_ >::SparseMatrixCSCR(), FEAT::LAFEM::SparseMatrixCSR< DT_, IT_ >::SparseMatrixCSR(), FEAT::LAFEM::SparseVector< DT_, IT_ >::SparseVector(), FEAT::LAFEM::SparseVectorBlocked< DT_, IT_, block_size_ >::SparseVectorBlocked(), and attach().
| std::size_t FEAT::Memory::Arbiter::block_bytes | ( | ) | const |
Returns the size of the entire attached memory block in bytes.
Definition at line 1384 of file memory_arbiter.cpp.
References _block, and FEAT::Memory::Block::bytes.
| std::size_t FEAT::Memory::Arbiter::bytes | ( | ) | const |
Returns the size of the arbiter's range in the attached memory block in bytes.
Definition at line 1374 of file memory_arbiter.cpp.
References _block, _offset, _size, and FEAT::Memory::Block::bytes.
Referenced by Arbiter().
| void FEAT::Memory::Arbiter::clone | ( | const Arbiter & | source, |
| std::size_t | offset = 0u, |
||
| std::size_t | size = full_size, |
||
| bool | clone_block = false |
||
| ) |
Sets this arbiter to a deep copy of (a sub-region of) another arbiter's memory block.
This function is effectively equivalent to
other and this arbiter will point to independent memory blocks. If you indent to perform a shallow copy instead, use the attach() function instead.| [in] | source | A transient reference to another arbiter to whose block this arbiter should clone from. |
| [in] | offset | Specifies the offset of the memory sub-region in bytes that is to be copied. |
| [in] | size | Specifies the size of the memory sub-region in bytes that is to be copied. Set to Arbiter::full_size if the memory sub-region should extend to the end of the input memory block (sub-region). |
| [in] | clone_block | Specifies if the entire memory block is to be cloned or only the sub-region of the block that is defined by the range [offset, offset+size). |
Definition at line 1329 of file memory_arbiter.cpp.
References _block, _move(), _offset, _size, FEAT::Memory::Block::bytes, clone(), and full_size.
| Arbiter FEAT::Memory::Arbiter::clone | ( | std::size_t | offset = 0u, |
| std::size_t | size = full_size, |
||
| bool | clone_block = false |
||
| ) | const |
Creates a new arbiter that contains a deep copy to (a sub-region of) this arbiters memory block.
| [in] | offset | Specifies the offset of the memory sub-region in bytes that is to be copied. |
| [in] | size | Specifies the size of the memory sub-region in bytes that is to be copied. Set to Arbiter::full_size if the memory sub-region should extend to the end of the input memory block (sub-region). |
| [in] | clone_block | Specifies if the entire memory block is to be cloned or only the sub-region of the block that is defined by the range [offset, offset+size). |
Definition at line 1287 of file memory_arbiter.cpp.
References Arbiter(), _block, _offset, _size, FEAT::Memory::Block::bytes, full_size, FEAT::Memory::none, and XASSERTM.
Referenced by clone().
|
inline |
Converts the contents of one memory block into another one by casting the underlying data types.
This function interprets the contents of the destination memory block as an array of elements of type Tdst_ and the contents of the source memory block as an array of elements of type Tsrc_ and it converts each element of the source array into its corresponding element of the destination array by performing a static cast to the destination data type.
| Tdst_ | Specifies the underlying type of the destination. |
| Tsrc_ | Specifies the underlying type of the source array; must be convertible to Tdst_. |
| [in] | source | The arbiter of the source memory block that is to be converted. |
Definition at line 987 of file memory_arbiter.hpp.
References FEAT::Memory::TypedView< T_ >::convert_from(), FEAT::Memory::cuda, location(), FEAT::Memory::main, FEAT::Memory::read, FEAT::Memory::View::release(), and FEAT::Memory::write.
|
inline |
Converts the contents of one memory block into another one by casting the underlying data types.
This function interprets the contents of the destination memory block as an array of elements of type Tdst_ and the contents of the source memory block as an array of elements of type Tsrc_ and it converts each element of the source array into its corresponding element of the destination array by performing a static cast to the destination data type.
| Tdst_ | Specifies the underlying type of the destination array. |
| Tsrc_ | Specifies the underlying type of the source array; must be convertible to Tdst_. |
| [in] | source | The arbiter of the source memory block that is to be converted. |
| [in] | mem_loc | Specifies which memory location of the destination memory block should receive the copy. Must be a single memory location and must not be Location::none. |
Definition at line 962 of file memory_arbiter.hpp.
References FEAT::Memory::TypedView< T_ >::convert_from(), FEAT::Memory::read, and FEAT::Memory::write.
| void FEAT::Memory::Arbiter::copy | ( | const Arbiter & | source, |
| Location | mem_loc = Location::none |
||
| ) |
Copies of the contents of one memory block into another one.
This function performs a deep copy of the currently up-to-date memory location(s) of the source memory block into the memory locations of the destination memory block that are specified by mem_loc.
| [in] | source | The handle of the source memory block that is to be copied. |
| [in] | mem_loc | Specifies which memory location of the destination memory block should receive the copy. If set to Location::none, then all up-to-date locations of the source memory block are copied into the destination memory block. |
Definition at line 1406 of file memory_arbiter.cpp.
References _block, _offset, _size, FEAT::Memory::Block::bytes, full_size, XASSERT, and XASSERTM.
Referenced by FEAT::LAFEM::SparseMatrixBanded< DT_, IT_ >::extract_diag(), and FEAT::VoxelAssembly::DeviceCubature< DT_, PointType_ >::update().
| void FEAT::Memory::Arbiter::copy | ( | const void * | src_ptr, |
| Location | src_loc, | ||
| Location | mem_loc = Location::none |
||
| ) |
Copies of the contents of a raw memory region into this memory block.
This function performs a deep copy of the given source memory region into the memory locations of the destination memory block that are specified by mem_loc.
| [in] | src_ptr | A transient pointer to the source memory region that is to be deep copied. |
| [in] | src_loc | The memory location of the source memory region. Must be a single memory location and must not be Location::none. |
| [in] | mem_loc | Specifies which memory location of the destination memory block should receive the copy. If set to Location::none, then the destination memory location will be equal to the source memory location src_loc |
Definition at line 1421 of file memory_arbiter.cpp.
| void FEAT::Memory::Arbiter::copy_to | ( | void * | dst_ptr, |
| Location | dst_loc | ||
| ) | const |
Copies the contents of this memory block into a raw memory region.
This function performs a deep copy of this memory block's contents into the given memory region. This function automatically chooses a valid source memory location in this block.
| [out] | dst_ptr | A transient pointer to the destination memory region that is to be deep copied to. |
| [in] | dst_loc | The memory location of the source memory region. Must be a single memory location and must not be Location::none. |
Definition at line 1427 of file memory_arbiter.cpp.
|
inline |
Formats the memory block to a given value.
This function interprets the memory block as an array of elements of type T_ and sets all elements of the array to the given value
| T_ | Specifies the type of the array elements that the memory block's contents are to be interpreted as |
| [in] | value_ | The value that all array elements are to be set to. |
| [in] | mem_loc | A combination of memory locations which have to be formatted. If set to Location::none, then all memory locations that are currently allocated will be formatted. |
Definition at line 868 of file memory_arbiter.hpp.
References FEAT::Memory::cuda, location(), FEAT::Memory::main, FEAT::Memory::none, FEAT::value, and FEAT::Memory::write.
| void FEAT::Memory::Arbiter::format | ( | Location | mem_loc = Location::none | ) |
Formats the memory block to zero.
| [in] | mem_loc | A combination of memory locations which have to be formatted. If set to Location::none, then all memory locations that are currently allocated will be formatted. |
Definition at line 1433 of file memory_arbiter.cpp.
References _block, _offset, and _size.
Referenced by FEAT::Solver::AmaVankaGMRES< Global::Matrix< LocalMatrix_, MirrorRow_, MirrorCol_ >, Global::Filter< LocalFilter_, MirrorRow_ > >::_calc_dots_s(), FEAT::Solver::AmaVankaGMRES< Global::Matrix< LocalMatrix_, MirrorRow_, MirrorCol_ >, Global::Filter< LocalFilter_, MirrorRow_ > >::_calc_triple_dots_s(), FEAT::Solver::ClassicGramSchmidtOrthogonalizer< Vector_ >::_compute_dots(), and FEAT::Solver::AmaVankaGMRES< Global::Matrix< LocalMatrix_, MirrorRow_, MirrorCol_ >, Global::Filter< LocalFilter_, MirrorRow_ > >::init_numeric().
| void FEAT::Memory::Arbiter::format_random | ( | Location | mem_loc = Location::none | ) |
Formats the memory block to random values.
| [in] | mem_loc | A combination of memory locations which have to be formatted. If set to Location::none, then all memory locations that are currently allocated will be formatted. |
Definition at line 1439 of file memory_arbiter.cpp.
| void FEAT::Memory::Arbiter::free | ( | Location | mem_loc | ) |
Frees memory for a given memory block.
| [in] | mem_loc | A combination of memory locations on which the memory block has to be freed |
Definition at line 1400 of file memory_arbiter.cpp.
References _block.
| Location FEAT::Memory::Arbiter::location | ( | ) | const |
Returns a combination of all up-to-date memory locations.
Definition at line 1389 of file memory_arbiter.cpp.
References _block, FEAT::Memory::none, and FEAT::Memory::Block::valid_locations.
|
inline |
Checks whether this arbiter is not the null arbiter.
Definition at line 1094 of file memory_arbiter.hpp.
|
inline |
Checks whether two arbiters refer to the different memory regions.
Definition at line 1106 of file memory_arbiter.hpp.
move-assign operator
Definition at line 1189 of file memory_arbiter.cpp.
|
inline |
Checks whether two arbiters refer to the same memory region.
Definition at line 1100 of file memory_arbiter.hpp.
| void FEAT::Memory::Arbiter::release | ( | ) |
Releases this arbiter from its associated memory block and frees it if necessary.
This function decrements the reference counter of this arbiters memory block by one and, if the reference counter reaches zero, frees all memory allocated within the memory block as well as the block itself.
This function has no effect if the arbiter is not attached to a memory block.
Definition at line 1368 of file memory_arbiter.cpp.
References _block.
Referenced by FEAT::Solver::VoxelAmaVanka< Matrix_, Filter_, pol_threading_, macro_type_ >::_free_device().
|
inline |
Checks whether two arbiters refer to the same memory block ignoring offset and size.
Definition at line 1112 of file memory_arbiter.hpp.
|
inline |
Maps a typed view to a memory block.
| T_ | The type that is to be used for the typed view. |
| [in] | mem_loc | The memory location that the view is to be mapped for. Must be a single location and must not be Location::none. |
| [in] | access | The access rights that are to be granted for the view. |
Definition at line 1063 of file memory_arbiter.hpp.
References view().
|
inline |
Maps a read-only typed view to a memory block.
| T_ | The type that is to be used for the typed view. |
| [in] | mem_loc | The memory location that the view is to be mapped for. Must be a single location and must not be Location::none. |
| [in] | access | The access rights that are to be granted for the view. Must be equal to Memory::Access:read for this overload. |
Definition at line 1086 of file memory_arbiter.hpp.
References view().
Maps a raw view to a memory block.
| [in] | mem_loc | The memory location that the view is to be mapped for. Must be a single location and must not be Location::none. |
| [in] | access | The access rights that are to be granted for the view. |
Definition at line 1445 of file memory_arbiter.cpp.
References _block, _offset, _size, and XASSERT.
Referenced by FEAT::Solver::AmaVankaGMRES< Global::Matrix< LocalMatrix_, MirrorRow_, MirrorCol_ >, Global::Filter< LocalFilter_, MirrorRow_ > >::_calc_dots_s(), FEAT::Solver::AmaVankaGMRES< Global::Matrix< LocalMatrix_, MirrorRow_, MirrorCol_ >, Global::Filter< LocalFilter_, MirrorRow_ > >::_calc_triple_dots_s(), FEAT::Solver::ClassicGramSchmidtOrthogonalizer< Vector_ >::_compute_dots(), FEAT::VoxelAssembly::Arch::assemble_burgers_csr_host(), FEAT::VoxelAssembly::Arch::assemble_burgers_defect_host(), FEAT::VoxelAssembly::Arch::assemble_burgers_velo_material_csr_host(), FEAT::VoxelAssembly::Arch::assemble_burgers_velo_material_defect_host(), FEAT::Adjacency::ColoringDataHandler::fill_color(), and typed_view().
| View FEAT::Memory::Arbiter::view | ( | Location | mem_loc, |
| Access | access = Memory::Access::read |
||
| ) | const |
Maps a raw read-only view to the arbiters memory block.
| [in] | mem_loc | The memory location that the view is to be mapped for. Must be a single location and must not be Location::none. |
| [in] | access | The access rights that are to be granted for the view. Must be equal to Memory::Access:read for this overload. |
Definition at line 1451 of file memory_arbiter.cpp.
References _block, _offset, _size, FEAT::Memory::write, XASSERT, and XASSERTM.
|
mutableprivate |
a pointer to the memory block associated with this arbiter
Definition at line 644 of file memory_arbiter.hpp.
Referenced by Arbiter(), ~Arbiter(), _move(), alloc(), attach(), block_bytes(), bytes(), clone(), copy(), copy_to(), format(), format_random(), free(), location(), operator=(), release(), and view().
|
private |
|
private |
|
staticconstexpr |