SIRIUS 7.5.0
Electronic structure library and applications
Classes | Namespaces | Macros | Typedefs | Enumerations | Functions
memory.hpp File Reference

Memory management functions and classes. More...

Go to the source code of this file.

Classes

struct  sirius::sddk::is_complex< T >
 Check is the type is a complex number; by default it is not. More...
 
struct  sirius::sddk::is_complex< std::complex< T > >
 Check is the type is a complex number: for std::complex<T> it is true. More...
 
class  sirius::sddk::memory_t_deleter_base
 Base class for smart pointer deleters. More...
 
class  sirius::sddk::memory_t_deleter_base::memory_t_deleter_base_impl
 
class  sirius::sddk::memory_t_deleter
 Deleter for the allocated memory pointer of a given type. More...
 
class  sirius::sddk::memory_t_deleter::memory_t_deleter_impl
 
class  sirius::sddk::memory_pool_deleter
 Deleter for the allocated memory pointer from a given memory pool. More...
 
class  sirius::sddk::memory_pool_deleter::memory_pool_deleter_impl
 
class  sirius::sddk::memory_pool
 
class  sirius::sddk::mdarray_index_descriptor
 Index descriptor of mdarray. More...
 
class  sirius::sddk::mdarray< T, N >
 Multidimensional array with the column-major (Fortran) order. More...
 

Namespaces

module  sirius
 Namespace of the SIRIUS library.
 

Macros

#define mdarray_assert(condition__)
 

Typedefs

template<typename T >
using sirius::sddk::matrix = mdarray< T, 2 >
 

Enumerations

enum class  sirius::sddk::memory_t : unsigned int {
  none = 0b0000 , host = 0b0001 , host_pinned = 0b0011 , device = 0b1000 ,
  managed = 0b1101
}
 Memory types where the code can store data. More...
 
enum class  sirius::sddk::device_t { CPU = 0 , GPU = 1 }
 Type of the main processing unit. More...
 

Functions

bool sirius::sddk::is_host_memory (memory_t mem__)
 Check if this is a valid host memory (memory, accessible by the host). More...
 
bool sirius::sddk::is_device_memory (memory_t mem__)
 Check if this is a valid device memory (memory, accessible by the device). More...
 
memory_t sirius::sddk::get_memory_t (std::string name__)
 Get a memory type from a string. More...
 
device_t sirius::sddk::get_device_t (memory_t mem__)
 Get type of device by memory type. More...
 
device_t sirius::sddk::get_device_t (std::string name__)
 Get device type from the string. More...
 
template<typename T >
T * sirius::sddk::allocate (size_t n__, memory_t M__)
 Allocate n elements in a specified memory. More...
 
void sirius::sddk::deallocate (void *ptr__, memory_t M__)
 Deallocate pointer of a given memory type. More...
 
template<typename T , typename F >
void sirius::sddk::copy (memory_t from_mem__, T const *from_ptr__, memory_t to_mem__, F *to_ptr__, size_t n__)
 Copy between different memory types. More...
 
template<typename T >
void sirius::sddk::copy (memory_t from_mem__, T const *from_ptr__, memory_t to_mem__, T *to_ptr__, size_t n__)
 
template<typename T >
std::unique_ptr< T, memory_t_deleter_base > sirius::sddk::get_unique_ptr (size_t n__, memory_t M__)
 Allocate n elements and return a unique pointer. More...
 
sddk::memory_pool & sirius::sddk::get_memory_pool (sddk::memory_t M__)
 Return a memory pool. More...
 
template<typename T , int N>
std::ostream & sirius::sddk::operator<< (std::ostream &out, mdarray< T, N > const &v)
 Serialize to std::ostream. More...
 
template<typename T , typename F , int N>
void sirius::sddk::copy (mdarray< F, N > const &src__, mdarray< T, N > &dest__)
 Copy content of the array to another array of identical size but different precision. More...
 
template<typename T , int N>
void sirius::sddk::copy (mdarray< T, N > const &src__, mdarray< T, N > &dest__)
 Copy content of the array to another array of identical size. More...
 
template<typename T , int N>
void sirius::sddk::auto_copy (mdarray< T, N > &dst, const mdarray< T, N > &src)
 Copy all memory present on destination. More...
 
template<typename T , int N>
void sirius::sddk::auto_copy (mdarray< T, N > &dst, const mdarray< T, N > &src, device_t device)
 Copy memory specified by device from src to dst. More...
 
template<class numeric_t , std::size_t... Ts>
auto sirius::sddk::_empty_like_inner (std::index_sequence< Ts... > &seq, std::size_t(&dims)[sizeof...(Ts)], memory_pool *mempool)
 
template<typename T , int N>
auto sirius::sddk::empty_like (const mdarray< T, N > &src)
 
template<typename T , int N>
auto sirius::sddk::empty_like (const mdarray< T, N > &src, memory_pool &mempool)
 

Detailed Description

Memory management functions and classes.

Definition in file memory.hpp.

Macro Definition Documentation

◆ mdarray_assert

#define mdarray_assert (   condition__)
Value:
{ \
if (!(condition__)) { \
std::stringstream _s; \
_s << "Assertion (" << #condition__ << ") failed " \
<< "at line " << __LINE__ << " of file " << __FILE__ << std::endl \
<< "array label: " << label_ << std::endl; \
for (int i = 0; i < N; i++) { \
_s << "dims[" << i << "].size = " << dims_[i].size() << std::endl; \
} \
throw std::runtime_error(_s.str()); \
raise(SIGABRT); \
} \
}

Definition at line 536 of file memory.hpp.

Typedef Documentation

◆ matrix

template<typename T >
using sirius::sddk::matrix = typedef mdarray<T, 2>

Definition at line 1434 of file memory.hpp.

Enumeration Type Documentation

◆ memory_t

enum class sirius::sddk::memory_t : unsigned int
strong

Memory types where the code can store data.

All memory types can be divided into two (possibly overlapping) groups: accessible by the CPU and accessible by the device.

Enumerator
none 

Nothing.

host 

Host memory.

host_pinned 

Pinned host memory. This is host memory + extra bit flag.

device 

Device memory.

managed 

Managed memory (accessible from both host and device).

Definition at line 70 of file memory.hpp.

◆ device_t

enum class sirius::sddk::device_t
strong

Type of the main processing unit.

List the processing units on which the code can run.

Enumerator
CPU 

CPU device.

GPU 

GPU device (with CUDA programming model).

Definition at line 119 of file memory.hpp.

Function Documentation

◆ is_host_memory()

bool sirius::sddk::is_host_memory ( memory_t  mem__)
inline

Check if this is a valid host memory (memory, accessible by the host).

Definition at line 86 of file memory.hpp.

◆ is_device_memory()

bool sirius::sddk::is_device_memory ( memory_t  mem__)
inline

Check if this is a valid device memory (memory, accessible by the device).

Definition at line 93 of file memory.hpp.

◆ get_memory_t()

memory_t sirius::sddk::get_memory_t ( std::string  name__)
inline

Get a memory type from a string.

Definition at line 100 of file memory.hpp.

◆ get_device_t() [1/2]

device_t sirius::sddk::get_device_t ( memory_t  mem__)
inline

Get type of device by memory type.

Definition at line 130 of file memory.hpp.

◆ get_device_t() [2/2]

device_t sirius::sddk::get_device_t ( std::string  name__)
inline

Get device type from the string.

Definition at line 149 of file memory.hpp.

◆ allocate()

template<typename T >
T * sirius::sddk::allocate ( size_t  n__,
memory_t  M__ 
)
inline

Allocate n elements in a specified memory.

Allocate a memory block of the memory_t type. Return a nullptr if this memory is not available, otherwise return a pointer to an allocated block.

Definition at line 167 of file memory.hpp.

◆ deallocate()

void sirius::sddk::deallocate ( void *  ptr__,
memory_t  M__ 
)
inline

Deallocate pointer of a given memory type.

Definition at line 198 of file memory.hpp.

◆ copy() [1/4]

template<typename T , typename F >
void sirius::sddk::copy ( memory_t  from_mem__,
T const *  from_ptr__,
memory_t  to_mem__,
F *  to_ptr__,
size_t  n__ 
)
inline

Copy between different memory types.

Definition at line 229 of file memory.hpp.

◆ copy() [2/4]

template<typename T >
void sirius::sddk::copy ( memory_t  from_mem__,
T const *  from_ptr__,
memory_t  to_mem__,
T *  to_ptr__,
size_t  n__ 
)
inline

Definition at line 243 of file memory.hpp.

◆ get_unique_ptr()

template<typename T >
std::unique_ptr< T, memory_t_deleter_base > sirius::sddk::get_unique_ptr ( size_t  n__,
memory_t  M__ 
)
inline

Allocate n elements and return a unique pointer.

Definition at line 345 of file memory.hpp.

◆ get_memory_pool()

sddk::memory_pool & sirius::sddk::get_memory_pool ( sddk::memory_t  M__)

Return a memory pool.

A memory pool is created when this function called for the first time.

Definition at line 10 of file memory.cpp.

◆ operator<<()

template<typename T , int N>
std::ostream & sirius::sddk::operator<< ( std::ostream &  out,
mdarray< T, N > const &  v 
)

Serialize to std::ostream.

Definition at line 1438 of file memory.hpp.

◆ copy() [3/4]

template<typename T , typename F , int N>
void sirius::sddk::copy ( mdarray< F, N > const &  src__,
mdarray< T, N > &  dest__ 
)
inline

Copy content of the array to another array of identical size but different precision.

Definition at line 1453 of file memory.hpp.

◆ copy() [4/4]

template<typename T , int N>
void sirius::sddk::copy ( mdarray< T, N > const &  src__,
mdarray< T, N > &  dest__ 
)
inline

Copy content of the array to another array of identical size.

For example:

mdarray<double, 2> src(10, 20);
mdarray<double, 2> dest(10, 20);
copy(src, dest);
void copy(T *target__, T const *source__, size_t n__)
Copy memory inside a device.
Definition: acc.hpp:320

Definition at line 1480 of file memory.hpp.

◆ auto_copy() [1/2]

template<typename T , int N>
void sirius::sddk::auto_copy ( mdarray< T, N > &  dst,
const mdarray< T, N > &  src 
)

Copy all memory present on destination.

Definition at line 1498 of file memory.hpp.

◆ auto_copy() [2/2]

template<typename T , int N>
void sirius::sddk::auto_copy ( mdarray< T, N > &  dst,
const mdarray< T, N > &  src,
device_t  device 
)

Copy memory specified by device from src to dst.

Definition at line 1516 of file memory.hpp.

◆ _empty_like_inner()

template<class numeric_t , std::size_t... Ts>
auto sirius::sddk::_empty_like_inner ( std::index_sequence< Ts... > &  seq,
std::size_t(&)  dims[sizeof...(Ts)],
memory_pool mempool 
)

Definition at line 1536 of file memory.hpp.

◆ empty_like() [1/2]

template<typename T , int N>
auto sirius::sddk::empty_like ( const mdarray< T, N > &  src)

Definition at line 1550 of file memory.hpp.

◆ empty_like() [2/2]

template<typename T , int N>
auto sirius::sddk::empty_like ( const mdarray< T, N > &  src,
memory_pool mempool 
)

Definition at line 1562 of file memory.hpp.