DFT-FE 1.1.0-pre
Density Functional Theory With Finite-Elements
|
#include <MemoryStorage.h>
Public Types | |
typedef ValueType | value_type |
A class template to provide an interface that can act similar to STL vectors but with different MemorySpace— HOST (cpu) , DEVICE (gpu), etc,. | |
typedef ValueType * | pointer |
typedef ValueType & | reference |
typedef const ValueType & | const_reference |
typedef ValueType * | iterator |
typedef const ValueType * | const_iterator |
Public Member Functions | |
MemoryStorage ()=default | |
MemoryStorage (const MemoryStorage &u) | |
Copy constructor for a MemoryStorage. | |
MemoryStorage (MemoryStorage &&u) noexcept | |
Move constructor for a Vector. | |
MemoryStorage (std::size_t size, ValueType initVal=0) | |
Constructor for Vector with size and initial value arguments. | |
~MemoryStorage () | |
Destructor. | |
void | clear () |
clear and set to d_data to nullptr | |
void | setValue (const ValueType val) |
Set all the entries to a given value. | |
iterator | begin () |
Return iterator pointing to the beginning of point data. | |
const_iterator | begin () const |
Return iterator pointing to the beginning of Vector data. | |
iterator | end () |
Return iterator pointing to the end of Vector data. | |
const_iterator | end () const |
Return iterator pointing to the end of Vector data. | |
MemoryStorage & | operator= (const MemoryStorage &rhs) |
Copy assignment operator. | |
MemoryStorage & | operator= (MemoryStorage &&rhs) noexcept |
Move assignment constructor. | |
reference | operator[] (std::size_t i) |
Operator to get a reference to a element of the Vector. | |
const_reference | operator[] (std::size_t i) const |
Operator to get a const reference to a element of the Vector. | |
void | swap (MemoryStorage &rhs) |
void | resize (std::size_t size, ValueType initVal=ValueType()) |
Deallocates and then resizes Vector with new size and initial value arguments. | |
std::size_t | size () const |
Returns the dimension of the Vector. | |
ValueType * | data () noexcept |
Return the raw pointer to the Vector. | |
const ValueType * | data () const noexcept |
Return the raw pointer to the Vector without modifying the values. | |
template<dftfe::utils::MemorySpace memorySpaceDst> | |
void | copyTo (MemoryStorage< ValueType, memorySpaceDst > &dstMemoryStorage) const |
Copies the data to a MemoryStorage object in a different memory space. This provides a seamless interface to copy back and forth between memory spaces , including between the same memory spaces. | |
template<dftfe::utils::MemorySpace memorySpaceDst> | |
void | copyTo (MemoryStorage< ValueType, memorySpaceDst > &dstMemoryStorage, const std::size_t N, const std::size_t srcOffset, const std::size_t dstOffset) const |
Copies the data to a MemoryStorage object in a different memory space. This provides a seamless interface to copy back and forth between memory spaces , including between the same memory spaces. This is a more granular version of the above copyTo function as it provides transfer from a specific portion of the source MemoryStorage to a specific portion of the destination MemoryStorage. | |
template<dftfe::utils::MemorySpace memorySpaceSrc> | |
void | copyFrom (const MemoryStorage< ValueType, memorySpaceSrc > &srcMemoryStorage) |
Copies data from a MemoryStorage object in a different memory space. This provides a seamless interface to copy back and forth between memory spaces, including between the same memory spaces. | |
template<dftfe::utils::MemorySpace memorySpaceSrc> | |
void | copyFrom (const MemoryStorage< ValueType, memorySpaceSrc > &srcMemoryStorage, const std::size_t N, const std::size_t srcOffset, const std::size_t dstOffset) |
Copies data from a MemoryStorage object in a different memory space. This provides a seamless interface to copy back and forth between memory spaces, including between the same memory spaces. This is a more granular version of the above copyFrom function as it provides transfer from a specific portion of the source MemoryStorage to a specific portion of the destination MemoryStorage. | |
template<dftfe::utils::MemorySpace memorySpaceDst> | |
void | copyTo (ValueType *dst) const |
Copies the data to a memory pointed by a raw pointer This provides a seamless interface to copy back and forth between memory spaces, including between the same memory spaces. | |
template<dftfe::utils::MemorySpace memorySpaceDst> | |
void | copyTo (ValueType *dst, const std::size_t N, const std::size_t srcOffset, const std::size_t dstOffset) const |
Copies the data to a memory pointer by a raw pointer. This provides a seamless interface to copy back and forth between memory spaces , including between the same memory spaces. This is a more granular version of the above copyTo function as it provides transfer from a specific portion of the source MemoryStorage to a specific portion of the destination pointer. | |
template<dftfe::utils::MemorySpace memorySpaceSrc> | |
void | copyFrom (const ValueType *src) |
Copies data from a memory pointed by a raw pointer into the MemoryStorage object. This provides a seamless interface to copy back and forth between memory spaces, including between the same memory spaces. | |
template<dftfe::utils::MemorySpace memorySpaceSrc> | |
void | copyFrom (const ValueType *src, const std::size_t N, const std::size_t srcOffset, const std::size_t dstOffset) |
Copies data from a memory pointer by a raw pointer into the MemoryStorage object. This provides a seamless interface to copy back and forth between memory spaces, including between the same memory spaces. This is a more granular version of the above copyFrom function as it provides transfer from a specific portion of the source memory to a specific portion of the destination MemoryStorage. | |
void | copyTo (std::vector< ValueType > &dst) const |
Copies the data to a C++ STL vector, which always resides in the CPU. This provides a seamless interface to copy from any memory space to a C++ STL vector, including the case where source memory space is HOST (i.e., it resides on the CPU) | |
void | copyTo (std::vector< ValueType > &dst, const std::size_t N, const std::size_t srcOffset, const std::size_t dstOffset) const |
Copies the data to a C++ STL vector, which always resides in the CPU. This provides a seamless interface to copy from any memory space to a C++ STL vector, including the case where source memory space is HOST (i.e., it resides on the CPU). This is a more granular version of the above copyToSTL function as it provides transfer from a specific portion of the MemoryStorage to a specific portion of the destination STL vector. | |
void | copyFrom (const std::vector< ValueType > &src) |
Copies data from a C++ STL vector to the MemoryStorage object, which always resides on a CPU. This provides a seamless interface to copy from any memory space, including the case where the same memory spaces is HOST(i.e., the MemoryStorage is on CPU). | |
void | copyFrom (const std::vector< ValueType > &src, const std::size_t N, const std::size_t srcOffset, const std::size_t dstOffset) |
Copies data from a C++ STL vector to the MemoryStorage object, which always resides on a CPU. This provides a seamless interface to copy from any memory space, including the case where the same memory spaces is HOST(i.e., the MemoryStorage is on CPU). This is a more granular version of the above copyFromSTL function as it provides transfer from a specific portion of the source STL vector to to a specific portion of the destination MemoryStorage. | |
Private Attributes | |
ValueType * | d_data = nullptr |
std::size_t | d_size = 0 |
typedef const ValueType* dftfe::utils::MemoryStorage< ValueType, memorySpace >::const_iterator |
typedef const ValueType& dftfe::utils::MemoryStorage< ValueType, memorySpace >::const_reference |
typedef ValueType* dftfe::utils::MemoryStorage< ValueType, memorySpace >::iterator |
typedef ValueType* dftfe::utils::MemoryStorage< ValueType, memorySpace >::pointer |
typedef ValueType& dftfe::utils::MemoryStorage< ValueType, memorySpace >::reference |
typedef ValueType dftfe::utils::MemoryStorage< ValueType, memorySpace >::value_type |
A class template to provide an interface that can act similar to STL vectors but with different MemorySpace— HOST (cpu) , DEVICE (gpu), etc,.
ValueType | The underlying value type for the MemoryStorage (e.g., int, double, complex<double>, etc.) |
memorySpace | The memory space in which the MemoryStorage needs to reside |
|
default |
dftfe::utils::MemoryStorage< ValueType, memorySpace >::MemoryStorage | ( | const MemoryStorage< ValueType, memorySpace > & | u | ) |
Copy constructor for a MemoryStorage.
[in] | u | MemoryStorage object to copy from |
|
noexcept |
Move constructor for a Vector.
[in] | u | Vector object to move from |
|
explicit |
Constructor for Vector with size and initial value arguments.
[in] | size | size of the Vector |
[in] | initVal | initial value of elements of the Vector |
dftfe::utils::MemoryStorage< ValueType, memorySpace >::~MemoryStorage | ( | ) |
Destructor.
MemoryStorage< ValueType, memorySpace >::iterator dftfe::utils::MemoryStorage< ValueType, memorySpace >::begin | ( | ) |
Return iterator pointing to the beginning of point data.
MemoryStorage< ValueType, memorySpace >::const_iterator dftfe::utils::MemoryStorage< ValueType, memorySpace >::begin | ( | ) | const |
Return iterator pointing to the beginning of Vector data.
void dftfe::utils::MemoryStorage< ValueType, memorySpace >::clear | ( | ) |
clear and set to d_data to nullptr
void dftfe::utils::MemoryStorage< ValueType, memorySpace >::copyFrom | ( | const MemoryStorage< ValueType, memorySpaceSrc > & | srcMemoryStorage | ) |
Copies data from a MemoryStorage object in a different memory space. This provides a seamless interface to copy back and forth between memory spaces, including between the same memory spaces.
memorySpaceSrc | memory space of the source MemoryStorage from which to copy |
[in] | srcMemoryStorage | reference to the source MemoryStorage |
utils::LengthError | exception if the size of underlying MemoryStorage is less than size of srcMemoryStorage |
void dftfe::utils::MemoryStorage< ValueType, memorySpace >::copyFrom | ( | const MemoryStorage< ValueType, memorySpaceSrc > & | srcMemoryStorage, |
const std::size_t | N, | ||
const std::size_t | srcOffset, | ||
const std::size_t | dstOffset ) |
Copies data from a MemoryStorage object in a different memory space. This provides a seamless interface to copy back and forth between memory spaces, including between the same memory spaces. This is a more granular version of the above copyFrom function as it provides transfer from a specific portion of the source MemoryStorage to a specific portion of the destination MemoryStorage.
memorySpaceSrc | memory space of the source MemoryStorage from which to copy |
[in] | srcMemoryStorage | reference to the source MemoryStorage |
[in] | N | number of entries of the source MemoryStorage that needs to be copied to the destination MemoryStorage |
[in] | srcOffset | offset relative to the start of the source MemoryStorage from which we need to copy data |
[in] | dstOffset | offset relative to the start of the destination MemoryStorage to which we need to copy data |
utils::LengthError | exception if the size of srcMemoryStorage is less than N + srcOffset |
utils::LengthError | exception if the size of underlying MemoryStorage is less than N + dstOffset |
void dftfe::utils::MemoryStorage< ValueType, memorySpace >::copyFrom | ( | const std::vector< ValueType > & | src | ) |
Copies data from a C++ STL vector to the MemoryStorage object, which always resides on a CPU. This provides a seamless interface to copy from any memory space, including the case where the same memory spaces is HOST(i.e., the MemoryStorage is on CPU).
[in] | src | const reference to the source C++ STL vector from which the data needs to be copied. |
utils::LengthError | exception if the size of the MemoryStorage is less than the size of the src |
void dftfe::utils::MemoryStorage< ValueType, memorySpace >::copyFrom | ( | const std::vector< ValueType > & | src, |
const std::size_t | N, | ||
const std::size_t | srcOffset, | ||
const std::size_t | dstOffset ) |
Copies data from a C++ STL vector to the MemoryStorage object, which always resides on a CPU. This provides a seamless interface to copy from any memory space, including the case where the same memory spaces is HOST(i.e., the MemoryStorage is on CPU). This is a more granular version of the above copyFromSTL function as it provides transfer from a specific portion of the source STL vector to to a specific portion of the destination MemoryStorage.
[in] | src | const reference to the source C++ STL vector from which the data needs to be copied. |
[in] | N | number of entries of the source pointer that needs to be copied to the destination MemoryStorage |
[in] | srcOffset | offset relative to the start of the source STL vector from which we need to copy data |
[in] | dstOffset | offset relative to the start of the destination MemoryStorage to which we need to copy data |
utils::LengthError | exception if the size of src is less than N + srcOffset |
utils::LengthError | exception if the size of the MemoryStorage is less thant N + dstOffset |
void dftfe::utils::MemoryStorage< ValueType, memorySpace >::copyFrom | ( | const ValueType * | src | ) |
Copies data from a memory pointed by a raw pointer into the MemoryStorage object. This provides a seamless interface to copy back and forth between memory spaces, including between the same memory spaces.
memorySpaceSrc | memory space of the source pointer from which to copy |
[in] | src | pointer to the source memory |
void dftfe::utils::MemoryStorage< ValueType, memorySpace >::copyFrom | ( | const ValueType * | src, |
const std::size_t | N, | ||
const std::size_t | srcOffset, | ||
const std::size_t | dstOffset ) |
Copies data from a memory pointer by a raw pointer into the MemoryStorage object. This provides a seamless interface to copy back and forth between memory spaces, including between the same memory spaces. This is a more granular version of the above copyFrom function as it provides transfer from a specific portion of the source memory to a specific portion of the destination MemoryStorage.
memorySpaceSrc | memory space of the source pointer from which to copy |
[in] | src | pointer to the source memory |
[in] | N | number of entries of the source pointer that needs to be copied to the destination MemoryStorage |
[in] | srcOffset | offset relative to the start of the source pointer from which we need to copy data |
[in] | dstOffset | offset relative to the start of the destination MemoryStorage to which we need to copy data |
utils::LengthError | exception if the size of the MemoryStorage is less than N + dstOffset |
void dftfe::utils::MemoryStorage< ValueType, memorySpace >::copyTo | ( | MemoryStorage< ValueType, memorySpaceDst > & | dstMemoryStorage | ) | const |
Copies the data to a MemoryStorage object in a different memory space. This provides a seamless interface to copy back and forth between memory spaces , including between the same memory spaces.
memorySpaceDst | memory space of the destination MemoryStorage |
[in] | dstMemoryStorage | reference to the destination MemoryStorage. It must be pre-allocated appropriately |
[out] | dstMemoryStorage | reference to the destination MemoryStorage with the data copied into it |
utils::LengthError | exception if the size of dstMemoryStorage is less than underlying MemoryStorage |
void dftfe::utils::MemoryStorage< ValueType, memorySpace >::copyTo | ( | MemoryStorage< ValueType, memorySpaceDst > & | dstMemoryStorage, |
const std::size_t | N, | ||
const std::size_t | srcOffset, | ||
const std::size_t | dstOffset ) const |
Copies the data to a MemoryStorage object in a different memory space. This provides a seamless interface to copy back and forth between memory spaces , including between the same memory spaces. This is a more granular version of the above copyTo function as it provides transfer from a specific portion of the source MemoryStorage to a specific portion of the destination MemoryStorage.
memorySpaceDst | memory space of the destination MemoryStorage |
[in] | dstMemoryStorage | reference to the destination MemoryStorage. It must be pre-allocated appropriately |
[in] | N | number of entries of the source MemoryStorage that needs to be copied to the destination MemoryStorage |
[in] | srcOffset | offset relative to the start of the source MemoryStorage from which we need to copy data |
[in] | dstOffset | offset relative to the start of the destination MemoryStorage to which we need to copy data |
[out] | dstMemoryStorage | reference to the destination MemoryStorage with the data copied into it |
utils::LengthError | exception if the size of dstMemoryStorage is less than N + dstOffset |
utils::LengthError | exception if the size of underlying MemoryStorage is less than N + srcOffset |
void dftfe::utils::MemoryStorage< ValueType, memorySpace >::copyTo | ( | std::vector< ValueType > & | dst | ) | const |
Copies the data to a C++ STL vector, which always resides in the CPU. This provides a seamless interface to copy from any memory space to a C++ STL vector, including the case where source memory space is HOST (i.e., it resides on the CPU)
[in] | dst | reference to the destination C++ STL vector to which the data needs to be copied. |
[out] | dst | reference to the destination C++ STL vector with the data copied into it |
void dftfe::utils::MemoryStorage< ValueType, memorySpace >::copyTo | ( | std::vector< ValueType > & | dst, |
const std::size_t | N, | ||
const std::size_t | srcOffset, | ||
const std::size_t | dstOffset ) const |
Copies the data to a C++ STL vector, which always resides in the CPU. This provides a seamless interface to copy from any memory space to a C++ STL vector, including the case where source memory space is HOST (i.e., it resides on the CPU). This is a more granular version of the above copyToSTL function as it provides transfer from a specific portion of the MemoryStorage to a specific portion of the destination STL vector.
[in] | dst | reference to the destination C++ STL vector to which the data needs to be copied. |
[in] | N | number of entries of the source MemoryStorage that needs to be copied to the destination pointer |
[in] | srcOffset | offset relative to the start of the source MemoryStorage from which we need to copy data |
[in] | dstOffset | offset relative to the start of the STL vector to which we need to copy data |
[out] | dst | reference to the destination C++ STL vector with the data copied into it |
utils::LengthError | exception if the size of the MemoryStorage is less than N + srcOffset |
void dftfe::utils::MemoryStorage< ValueType, memorySpace >::copyTo | ( | ValueType * | dst | ) | const |
Copies the data to a memory pointed by a raw pointer This provides a seamless interface to copy back and forth between memory spaces, including between the same memory spaces.
memorySpaceDst | memory space of the destination pointer |
[in] | dst | pointer to the destination. It must be pre-allocated appropriately |
[out] | dst | pointer to the destination with the data copied into it |
void dftfe::utils::MemoryStorage< ValueType, memorySpace >::copyTo | ( | ValueType * | dst, |
const std::size_t | N, | ||
const std::size_t | srcOffset, | ||
const std::size_t | dstOffset ) const |
Copies the data to a memory pointer by a raw pointer. This provides a seamless interface to copy back and forth between memory spaces , including between the same memory spaces. This is a more granular version of the above copyTo function as it provides transfer from a specific portion of the source MemoryStorage to a specific portion of the destination pointer.
memorySpaceDst | memory space of the destination pointer |
[in] | dst | pointer to the destination. It must be pre-allocated appropriately |
[in] | N | number of entries of the source MemoryStorage that needs to be copied to the destination pointer |
[in] | srcOffset | offset relative to the start of the source MemoryStorage from which we need to copy data |
[in] | dstOffset | offset relative to the start of the destination pointer to which we need to copy data |
[out] | dst | pointer to the destination with the data copied into it |
utils::LengthError | exception if the size of the MemoryStorage is less than N + srcOffset |
|
noexcept |
Return the raw pointer to the Vector without modifying the values.
|
noexcept |
Return the raw pointer to the Vector.
MemoryStorage< ValueType, memorySpace >::iterator dftfe::utils::MemoryStorage< ValueType, memorySpace >::end | ( | ) |
Return iterator pointing to the end of Vector data.
MemoryStorage< ValueType, memorySpace >::const_iterator dftfe::utils::MemoryStorage< ValueType, memorySpace >::end | ( | ) | const |
Return iterator pointing to the end of Vector data.
MemoryStorage< ValueType, memorySpace > & dftfe::utils::MemoryStorage< ValueType, memorySpace >::operator= | ( | const MemoryStorage< ValueType, memorySpace > & | rhs | ) |
Copy assignment operator.
[in] | rhs | the rhs Vector from which to copy |
|
noexcept |
Move assignment constructor.
[in] | rhs | the rhs Vector from which to move |
MemoryStorage< ValueType, memorySpace >::reference dftfe::utils::MemoryStorage< ValueType, memorySpace >::operator[] | ( | std::size_t | i | ) |
Operator to get a reference to a element of the Vector.
[in] | i | is the index to the element of the Vector |
exception | if i >= size of the Vector |
MemoryStorage< ValueType, memorySpace >::const_reference dftfe::utils::MemoryStorage< ValueType, memorySpace >::operator[] | ( | std::size_t | i | ) | const |
Operator to get a const reference to a element of the Vector.
[in] | i | is the index to the element of the Vector |
exception | if i >= size of the Vector |
void dftfe::utils::MemoryStorage< ValueType, memorySpace >::resize | ( | std::size_t | size, |
ValueType | initVal = ValueType() ) |
Deallocates and then resizes Vector with new size and initial value arguments.
[in] | size | size of the Vector |
[in] | initVal | initial value of elements of the Vector |
void dftfe::utils::MemoryStorage< ValueType, memorySpace >::setValue | ( | const ValueType | val | ) |
Set all the entries to a given value.
[in] | val | The value to which the entries are to be set |
std::size_t dftfe::utils::MemoryStorage< ValueType, memorySpace >::size | ( | ) | const |
Returns the dimension of the Vector.
void dftfe::utils::MemoryStorage< ValueType, memorySpace >::swap | ( | MemoryStorage< ValueType, memorySpace > & | rhs | ) |
|
private |
|
private |