Template Class Vector
Defined in File Vector.hpp
Class Documentation
-
template<typename ScalarT, typename IdxT>
class Vector This class implements vectors (dense arrays) and multivectors and some basic utilities (get size, allocate, set data, get data, etc).
What you need to know:
Multivectors are stored in one array, organized column-wise. A vector is a multivector of size 1.
There is a mirroring memory approach: the class has DEVICE and HOST data pointers. If needed, only one (or none) can be used or allocated. Unless triggered directly or by other function, the data is NOT automatically updated between HOST and DEVICE.
Constructor DOES NOT allocate memory. This has to be done separately.
You can get (and set) “raw” data easily, if needed.
There is memory ownership utility - vector can own memory (separate flags for HOST and DEVICE) or not, depending on how it is used.
- Author
Kasia Swirydowicz kasia.swirydowicz@pnnl.gov
- Author
Slaven Peles peless@ornl.gov
Public Functions
-
inline ScalarT *getData(memory::MemorySpace memspace = memory::HOST)
get a pointer to HOST or DEVICE vector data.
Note
This function gives you access to the pointer, not to a copy. If you change the values using the pointer, the vector values will change too. Make sure to use setDataUpdated function to set the update flags correctly after changing the values.
- Parameters:
memspace – [in] - Memory space of the pointer (HOST or DEVICE)
- Returns:
pointer to the vector data (HOST or DEVICE). In case of multivectors, vectors are stored column-wise.
-
inline ScalarT *getData(IdxT j, memory::MemorySpace memspace = memory::HOST)
Get a pointer to HOST or DEVICE data of a vector in a multivector.
Note
This function gives you access to the pointer, not to a copy. If you change the values using the pointer, the vector values will change too. Call setDataUpdated() to update the staleness flags.
- Parameters:
j – [in] - Index of a vector in multivector
memspace – [in] - Memory space of the pointer (HOST or DEVICE)
- Returns:
Pointer to the _j_th vector data (HOST or DEVICE).
- Pre:
j<k_, i.e.,jis smaller than the number of vectors.
-
inline const ScalarT *getData(memory::MemorySpace memspace = memory::HOST) const
get a pointer to HOST or DEVICE vector data.
- Parameters:
memspace – [in] - Memory space of the pointer (HOST or DEVICE)
- Returns:
pointer to the vector data (HOST or DEVICE). In case of multivectors, vectors are stored column-wise.
-
inline const ScalarT *getData(IdxT j, memory::MemorySpace memspace = memory::HOST) const
Get a const pointer to HOST or DEVICE data of a vector in a multivector.
- Parameters:
j – [in] - Index of a vector in multivector
memspace – [in] - Memory space of the pointer (HOST or DEVICE)
- Returns:
Const pointer to the _j_th vector data (HOST or DEVICE).
- Pre:
j<k_, i.e.,jis smaller than the number of vectors.
-
inline int setDataUpdated(memory::MemorySpace memspace = memory::HOST)
Set the flag to indicate that the data (HOST or DEVICE) has been updated.
Use this function if you update vector elements by accessing the raw data pointer.
Warning
This is an expert level method. Use only if you know what you are doing.
- Parameters:
memspace – [in] - Memory space (HOST or DEVICE)
-
inline int setDataUpdated(IdxT j, memory::MemorySpace memspace = memory::HOST)
Set the flag to indicate that the data (HOST or DEVICE) for vector
jin the multivector has been updated.Use this function if you update vector elements by accessing the raw data pointer.
Warning
This is an expert level method. Use only if you know what you are doing.
- Parameters:
j – [in] - Index of a vector in multivector
memspace – [in] - Memory space (HOST or DEVICE)
Public Members
-
bool *gpu_updated_ = {nullptr}
when k > 1, store the flags on the heap
-
bool gpu_updated_single_
when k == 1, store the flag in-place for locality
-
bool *cpu_updated_ = {nullptr}
when k > 1, store the flags on the heap
-
bool cpu_updated_single_
when k == 1, store the flag in-place for locality