79#define CS_MALLOC(_ptr, _ni, _type) \
80_ptr = (_type *) cs_mem_malloc(_ni, sizeof(_type), \
81 #_ptr, __FILE__, __LINE__)
99#define CS_MALLOC_HD(_ptr, _ni, _type, _mode) \
100_ptr = (_type *) cs_mem_malloc_hd(_mode, _ni, sizeof(_type), \
101 #_ptr, __FILE__, __LINE__)
115#define CS_REALLOC(_ptr, _ni, _type) \
116_ptr = (_type *) cs_mem_realloc(_ptr, _ni, sizeof(_type), \
117 #_ptr, __FILE__, __LINE__)
135#define CS_REALLOC_HD(_ptr, _ni, _type, _mode) \
136_ptr = (_type *) cs_mem_realloc_hd(_ptr, _mode, _ni, sizeof(_type), \
137 #_ptr, __FILE__, __LINE__)
155#define CS_FREE(_ptr) \
156cs_mem_free(_ptr, #_ptr, __FILE__, __LINE__), _ptr = NULL
171#define CS_MEMALIGN(_ptr, _align, _ni, _type) \
172_ptr = (_type *) cs_mem_memalign(_align, _ni, sizeof(_type), \
173 #_ptr, __FILE__, __LINE__)
179#if defined(HAVE_ACCEL)
186#define cs_alloc_mode CS_ALLOC_HOST
187#define cs_alloc_mode_read_mostly CS_ALLOC_HOST
264 const char *var_name,
265 const char *file_name,
268#if defined(HAVE_ACCEL)
295 const char *var_name,
296 const char *file_name,
305 const char *var_name,
306 const char *file_name,
310 return cs_mem_malloc(ni, size, var_name, file_name, line_num);
339 const char *var_name,
340 const char *file_name,
373#if defined(HAVE_ACCEL)
376cs_mem_realloc_hd(
void *ptr,
380 const char *var_name,
381 const char *file_name,
387cs_mem_realloc_hd(
void *ptr,
391 const char *var_name,
392 const char *file_name,
396 return cs_mem_realloc(ptr, ni, size, var_name, file_name, line_num);
422 const char *var_name,
423 const char *file_name,
452 const char *var_name,
453 const char *file_name,
517#if defined(HAVE_OPENMP_TARGET)
528cs_mem_set_omp_target_device_id(
int device_id);
558 uint64_t *n_reallocs,
560 uint64_t *n_current);
562#if defined(HAVE_ACCEL)
578cs_copy_h2d(
void *dest,
596cs_copy_d2h(
void *dest,
614cs_copy_d2d(
void *dest,
636#if defined(HAVE_ACCEL)
653#if defined(__cplusplus) && defined(HAVE_ACCEL)
662 return (
const T *)ptr_v;
685#if defined(HAVE_ACCEL)
692inline static const void *
702#if defined(__cplusplus) && defined(HAVE_ACCEL)
711 return (
const T *)ptr_v;
735#if defined(HAVE_ACCEL)
742inline static const void *
752#if defined(__cplusplus) && defined(HAVE_ACCEL)
761 return (
const T *)ptr_v;
779#if defined(HAVE_ACCEL)
806#if defined(HAVE_ACCEL)
838#if defined(HAVE_ACCEL)
847#define cs_associate_device_ptr(_host_ptr, _ni, _size);
862#if defined(HAVE_ACCEL)
869#define cs_disassociate_device_ptr(_host_ptr);
886#if defined(HAVE_ACCEL)
894#define cs_set_alloc_mode(_host_ptr, mode);
913#if defined(__cplusplus) && defined(HAVE_ACCEL)
927#define cs_set_alloc_mode_r(_host_ptr, mode);
941#if defined(HAVE_ACCEL)
948#define cs_mem_advise_set_read_mostly(ptr);
960#if defined(HAVE_ACCEL)
967#define cs_mem_advise_unset_read_mostly(ptr);
989#if defined(HAVE_ACCEL)
1023#if defined(HAVE_ACCEL)
1057#if defined(HAVE_ACCEL)
1085#if defined(HAVE_ACCEL)
1116#if defined(HAVE_ACCEL)
1134#if defined(HAVE_ACCEL)
1145cs_mem_device_pool_set_active(
bool status);
1161cs_mem_device_pool_set_max_capacity(
size_t size);
1172cs_mem_device_pool_set_max_tries(
short int n_tries);
1181cs_mem_device_pool_clear(
void);
void bft_error_handler_t(const char *const file_name, const int line_num, const int sys_error_code, const char *const format, va_list arg_ptr)
Function pointer to opaque error handler.
Definition bft_error.h:52
#define BEGIN_C_DECLS
Definition cs_defs.h:542
#define CS_UNUSED(x)
Definition cs_defs.h:528
#define END_C_DECLS
Definition cs_defs.h:543
@ p
Definition cs_field_pointer.h:67
int cs_mem_have_memalign(void)
Indicate if a memory aligned allocation variant is available.
Definition cs_mem.cpp:1974
void * cs_mem_memalign(size_t alignment, size_t ni, size_t size, const char *var_name, const char *file_name, int line_num)
Allocate aligned memory for ni elements of size bytes.
Definition cs_mem.cpp:1826
size_t cs_mem_size_max(void)
Return maximum theoretical dynamic memory allocated.
Definition cs_mem.cpp:1911
int cs_mem_initialized(void)
Indicates if cs_mem_...() functions are initialized.
Definition cs_mem.cpp:1578
void * cs_mem_malloc(size_t ni, size_t size, const char *var_name, const char *file_name, int line_num)
Allocate memory for ni elements of size bytes.
Definition cs_mem.cpp:1607
bft_error_handler_t * cs_mem_error_handler_get(void)
Returns the error handler associated with the cs_mem_...() functions.
Definition cs_mem.cpp:1992
void cs_mem_init(const char *log_file_name)
Initialize memory handling.
Definition cs_mem.cpp:1407
size_t cs_mem_size_current(void)
Return current theoretical dynamic memory allocated.
Definition cs_mem.cpp:1897
void cs_mem_end(void)
End memory handling.
Definition cs_mem.cpp:1501
void * cs_mem_realloc(void *ptr, size_t ni, size_t size, const char *var_name, const char *file_name, int line_num)
Reallocate memory for ni elements of size bytes.
Definition cs_mem.cpp:1666
void cs_mem_error_handler_set(bft_error_handler_t *handler)
Definition cs_mem.cpp:2011
void * cs_mem_free(void *ptr, const char *var_name, const char *file_name, int line_num)
Free allocated memory.
Definition cs_mem.cpp:1759
static const void * cs_get_device_ptr_const_pf(const void *ptr)
Return matching device pointer for a given constant pointer, prefetching if applicable.
Definition cs_mem.h:743
#define cs_mem_advise_set_read_mostly(ptr)
Advise memory system that a given allocation will be mostly read.
Definition cs_mem.h:948
#define cs_set_alloc_mode_r(_host_ptr, mode)
Set allocation mode for an already allocated pointer using pass by reference semantics for the pointe...
Definition cs_mem.h:927
#define cs_mem_advise_unset_read_mostly(ptr)
Advise memory system that a given allocation will be mostly read.
Definition cs_mem.h:967
static bool cs_mem_is_device_ptr(const void *ptr)
Check if a pointer is a device (or shared) pointer.
Definition cs_mem.h:814
static void cs_prefetch_d2h(void *ptr, size_t size)
Prefetch data from device to host.
Definition cs_mem.h:1125
static const void * cs_get_device_ptr_const(const void *ptr)
Return matching device pointer for a given constant pointer.
Definition cs_mem.h:693
#define cs_associate_device_ptr(_host_ptr, _ni, _size)
Associate device memory with a given host memory pointer.
Definition cs_mem.h:847
#define cs_set_alloc_mode(_host_ptr, mode)
Set allocation mode for an already allocated pointer.
Definition cs_mem.h:894
static void cs_sync_d2h(void *ptr)
Synchronize data from device to host.
Definition cs_mem.h:1031
#define cs_disassociate_device_ptr(_host_ptr)
Detach device memory from a given host memory pointer.
Definition cs_mem.h:869
#define cs_alloc_mode
Definition cs_mem.h:186
#define cs_alloc_mode_read_mostly
Definition cs_mem.h:187
static void cs_prefetch_h2d(void *ptr, size_t size)
Prefetch data from host to device.
Definition cs_mem.h:1094
int cs_mem_stats(uint64_t *alloc_cur, uint64_t *alloc_max, uint64_t *n_allocs, uint64_t *n_reallocs, uint64_t *n_frees, uint64_t *n_current)
Return memory allocation stats, if available.
Definition cs_mem.cpp:1934
static cs_alloc_mode_t cs_check_device_ptr(const void *ptr)
Check if a pointer is associated with a device.
Definition cs_mem.h:787
static void cs_sync_d2h_if_needed(void *ptr)
Synchronize data from device to host, only if needed.
Definition cs_mem.h:1065
static void cs_sync_h2d(const void *ptr)
Synchronize data from host to device.
Definition cs_mem.h:997
static void * cs_get_device_ptr(void *ptr)
Return matching device pointer for a given pointer.
Definition cs_mem.h:644
cs_alloc_mode_t
Definition cs_mem.h:50
@ CS_ALLOC_HOST
Definition cs_mem.h:52
@ CS_ALLOC_HOST_DEVICE_PINNED
Definition cs_mem.h:54
@ CS_ALLOC_HOST_DEVICE_SHARED
Definition cs_mem.h:57
@ CS_ALLOC_HOST_DEVICE
Definition cs_mem.h:53
@ CS_ALLOC_DEVICE
Definition cs_mem.h:59