TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
Memory utilities

Detailed Description

Generic versions (w.r.t. the different address spaces) of memory managing functions as well as other tools related to memory management.

Concepts

concept  nda::mem::Allocator
 Check if a given type satisfies the allocator concept.
 
concept  nda::mem::Handle
 Check if a given type satisfies the memory handle concept.
 
concept  nda::mem::OwningHandle
 Check if a given type satisfies the owning memory handle concept.
 

Classes

struct  nda::mem::aligner< T, Al >
 Wraps an arbitrary type to have a specified alignment. More...
 
struct  nda::mem::do_not_initialize_t
 Tag used in constructors to indicate that the memory should not be initialized. More...
 
struct  nda::mem::init_zero_t
 Tag used in constructors to indicate that the memory should be initialized to zero. More...
 

Macros

#define device_error_check(ARG1, ARG2)   compile_error_no_gpu()
 Trigger a compilation error every time the nda::device_error_check function is called.
 

Functions

template<bool flag = false>
void nda::compile_error_no_gpu ()
 Trigger a compilation error in case GPU specific functionality is used without configuring the project with GPU support.
 
template<AddressSpace AdrSp>
void nda::mem::free (void *p)
 Call the correct free function based on the given address space.
 
template<AddressSpace AdrSp>
void * nda::mem::malloc (size_t size)
 Call the correct malloc function based on the given address space.
 
template<AddressSpace DestAdrSp, AddressSpace SrcAdrSp>
void nda::mem::memcpy (void *dest, void const *src, size_t count)
 Call the correct memcpy function based on the given address spaces.
 
template<AddressSpace DestAdrSp, AddressSpace SrcAdrSp>
void nda::mem::memcpy2D (void *dest, size_t dpitch, const void *src, size_t spitch, size_t width, size_t height)
 Call CUDA's cudaMemcpy2D function or simulate its behavior on the Host based on the given address spaces.
 
template<AddressSpace AdrSp>
void nda::mem::memset (void *p, int value, size_t count)
 Call the correct memset function based on the given address space.
 
template<AddressSpace AdrSp>
void nda::mem::memset2D (void *ptr, size_t pitch, int value, size_t width, size_t height)
 Call CUDA's cudaMemset2D function or simulate its behavior on the Host based on the given address space.
 

Variables

static constexpr do_not_initialize_t nda::mem::do_not_initialize {}
 Instance of nda::mem::do_not_initialize_t.
 
static constexpr bool nda::have_cuda = false
 Constexpr variable that is true if the project is configured with CUDA support.
 
static constexpr bool nda::have_device = false
 Constexpr variable that is true if the project is configured with GPU support.
 
static constexpr bool nda::mem::init_dcmplx = true
 Should we initialize memory for complex double types to zero.
 
static constexpr init_zero_t nda::mem::init_zero {}
 Instance of nda::mem::init_zero_t.
 

Function Documentation

◆ free()

template<AddressSpace AdrSp>
void nda::mem::free ( void * p)

#include <nda/mem/malloc.hpp>

Call the correct free function based on the given address space.

It makes the following function calls depending on the address space:

  • std::free for Host.
  • cudaFree for Device and Unified.
Template Parameters
AdrSpnda::mem::AddressSpace.
Parameters
pPointer to the memory to be freed.

Definition at line 75 of file malloc.hpp.

◆ malloc()

template<AddressSpace AdrSp>
void * nda::mem::malloc ( size_t size)

#include <nda/mem/malloc.hpp>

Call the correct malloc function based on the given address space.

It makes the following function calls depending on the address space:

  • std::malloc for Host.
  • cudaMalloc for Device.
  • cudaMallocManaged for Unified.
Template Parameters
AdrSpnda::mem::AddressSpace.
Parameters
sizeSize in bytes to be allocated.
Returns
Pointer to the allocated memory.

Definition at line 49 of file malloc.hpp.

◆ memcpy()

template<AddressSpace DestAdrSp, AddressSpace SrcAdrSp>
void nda::mem::memcpy ( void * dest,
void const * src,
size_t count )

#include <nda/mem/memcpy.hpp>

Call the correct memcpy function based on the given address spaces.

It makes the following function calls depending on the address spaces:

  • std::memcpy if both address spaces are Host.
  • cudaMemcpy for all other combinations.
Template Parameters
DestAdrSpnda::mem::AddressSpace of the destination.
SrcAdrSpnda::mem::AddressSpace of the source.
Parameters
destPointer to the destination memory.
srcPointer to the source memory.
countSize in bytes to copy.

Definition at line 51 of file memcpy.hpp.

◆ memcpy2D()

template<AddressSpace DestAdrSp, AddressSpace SrcAdrSp>
void nda::mem::memcpy2D ( void * dest,
size_t dpitch,
const void * src,
size_t spitch,
size_t width,
size_t height )

#include <nda/mem/memcpy.hpp>

Call CUDA's cudaMemcpy2D function or simulate its behavior on the Host based on the given address spaces.

Copies a matrix (height rows of width bytes each) from the memory area pointed to by src to the memory area pointed to by dest. dpitch and spitch are the widths in memory in bytes of the 2D arrays pointed to by dest and src, including any padding added to the end of each row. The memory areas may not overlap. width must not exceed either dpitch or spitch.

If both address spaces are Host, it simulates the behavior of CUDA's cudaMemcpy2D function by making multiple calls to std::memcpy.

Template Parameters
DestAdrSpnda::mem::AddressSpace of the destination.
SrcAdrSpnda::mem::AddressSpace of the source.
Parameters
destPointer to the destination memory.
dpitchPitch of destination memory
srcPointer to the source memory.
spitchPitch of source memory.
widthWidth of matrix transfer (columns in bytes).
heightHeight of matrix transfer (rows).

Definition at line 84 of file memcpy.hpp.

◆ memset()

template<AddressSpace AdrSp>
void nda::mem::memset ( void * p,
int value,
size_t count )

#include <nda/mem/memset.hpp>

Call the correct memset function based on the given address space.

It makes the following function calls depending on the address spaces:

  • std::memset for Host.
  • cudaMemset for Device and Unified.
Template Parameters
AdrSpnda::mem::AddressSpace.
Parameters
pPointer to the memory to be set.
valueValue to set for each byte of specified memory.
countSize in bytes to be set.

Definition at line 49 of file memset.hpp.

◆ memset2D()

template<AddressSpace AdrSp>
void nda::mem::memset2D ( void * ptr,
size_t pitch,
int value,
size_t width,
size_t height )

#include <nda/mem/memset.hpp>

Call CUDA's cudaMemset2D function or simulate its behavior on the Host based on the given address space.

Sets each byte of a matrix (height rows of width bytes each) pointed to by dest to a specified value. pitch is the width in memory in bytes of the 2D array pointed to by dest, including any padding added to the end of each row.

If the address space is Host, it simulates the behavior of CUDA's cudaMemset2D function by making multiple calls to std::memset.

Template Parameters
AdrSpnda::mem::AddressSpace.
Parameters
ptrPointer to the memory to be set.
pitchPitch in bytes of the memory (unused if height is 1).
valueValue to set for each byte of specified memory
widthWidth of matrix to set (columns in bytes).
heightHeight of matrix to set (rows).

Definition at line 78 of file memset.hpp.