![]() |
ryujin 2.1.1 revision ee5cbcbf2346c1299c942d0e1f13b46449973c18
|
#include <source/gpu.h>

Public Member Functions | |
Memory space access and synchronization | |
| template<typename MemorySpace > | |
| bool | is_resident () const |
| template<typename MemorySpace > | |
| bool | is_pinned () const |
| template<typename MemorySpace > | |
| void | copy_to_memory_space () const |
| template<typename MemorySpace > | |
| void | move_to_memory_space () |
| TransferPolicy | transfer_policy () const |
| void | set_transfer_policy (const TransferPolicy transfer_policy) |
Protected Member Functions | |
Internal methods used by derived classes | |
| MirroredStorage ()=default | |
| template<typename MemorySpace > | |
| void | prepare_read_access () const |
| template<typename MemorySpace > | |
| void | prepare_write_access () |
| void | reset_residency (const bool host_resident, const bool default_resident) |
A CRTP base class that manages the residency state of data mirrored between the host and default (device) memory spaces. It provides a unified interface for querying residency (is_resident()) and for transferring data between memory spaces (copy_to_memory_space() and move_to_memory_space()) that is used by the SparsityPattern, SparseMatrix, and MultiComponentVector classes.
Data can be resident on either memory space, or on both (after a copy_to_memory_space() operation).
The Derived class must provide the following (private) primitives and declare friend class MirroredStorage<Derived>;:
allocate_storage() and deep_copy_storage() must be const and may only modify mutable members: they are reachable from a const view() under an implicit transfer policy.
Derived class thus has to initialize an object in the following order: first put the data in place, then call reset_residency(), and only then select the transfer policy with set_transfer_policy().
|
protecteddefault |
| bool ryujin::MirroredStorage< Derived >::is_resident | ( | ) | const |
Returns true if data is available on the selected memory space, i.e., if view<MemorySpace>() may be called. Both memory spaces can be resident simultaneously. If the host and default memory spaces coincide the function returns true for both memory spaces (once the object has been initialized).
| bool ryujin::MirroredStorage< Derived >::is_pinned | ( | ) | const |
Returns true if the selected memory space is "pinned" by the current transfer policy, i.e., if the data has to remain resident on it and all operations that would deallocate its storage - a move_to_memory_space() to the other memory space and a writable view on the other memory space - are disallowed.
The function always returns false if the host and default memory spaces coincide.
| void ryujin::MirroredStorage< Derived >::copy_to_memory_space | ( | ) | const |
Make a deep copy of the data to the selected memory space. Both memory spaces remain valid/resident.
| void ryujin::MirroredStorage< Derived >::move_to_memory_space | ( | ) |
Move the data to the selected memory space, then deallocate the storage of the other memory space and mark it non-resident.
| TransferPolicy ryujin::MirroredStorage< Derived >::transfer_policy | ( | ) | const |
Return the currently selected transfer policy.
| void ryujin::MirroredStorage< Derived >::set_transfer_policy | ( | const TransferPolicy | transfer_policy | ) |
Select a transfer policy, see the documentation of TransferPolicy.
|
protected |
Prepare read access on the selected memory space.
This function is called by the derived class at the beginning of every (const) view() method returning a read-only view: Under an implicit transfer policy the function performs an implicit copy_to_memory_space(), otherwise it asserts that the selected memory space is resident.
|
protected |
Prepare write access on the selected memory space.
This function is called by the derived class at the beginning of every view() method returning a writable view: Under an implicit transfer policy the function performs an implicit move_to_memory_space() (invalidating a stale mirror on the other memory space), otherwise it asserts that the selected memory space is resident. The operation is disallowed if the other memory space is pinned by the current transfer policy, see is_pinned().
|
protected |
Reset the residency flags. This function is called by the derived class at the end of reinit(), prior to selecting the transfer policy with set_transfer_policy().