8.3
general documentation
cs_mem.h
Go to the documentation of this file.
1#ifndef CS_MEM_H
2#define CS_MEM_H
3
4/*============================================================================
5 * Base memory allocation wrappers with optional tracing
6 *============================================================================*/
7
8/*
9 This file is part of code_saturne, a general-purpose CFD tool.
10
11 Copyright (C) 1998-2024 EDF S.A.
12
13 This program is free software; you can redistribute it and/or modify it under
14 the terms of the GNU General Public License as published by the Free Software
15 Foundation; either version 2 of the License, or (at your option) any later
16 version.
17
18 This program is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 details.
22
23 You should have received a copy of the GNU General Public License along with
24 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
25 Street, Fifth Floor, Boston, MA 02110-1301, USA.
26*/
27
28/*----------------------------------------------------------------------------*/
29
30#include "cs_defs.h"
31
32/*----------------------------------------------------------------------------*/
33
34/* BFT headers */
35
36#include "bft_error.h"
37
38/*-----------------------------------------------------------------------------*/
39
41
42/*============================================================================
43 * Public types
44 *============================================================================*/
45
50typedef enum {
51
62
63/*============================================================================
64 * Public macros
65 *============================================================================*/
66
67/*
68 * Allocate memory for _ni items of type _type.
69 *
70 * This macro calls cs_mem_malloc(), automatically setting the
71 * allocated variable name and source file name and line arguments.
72 *
73 * parameters:
74 * _ptr --> pointer to allocated memory.
75 * _ni <-- number of items.
76 * _type <-- element type.
77 */
78
79#define CS_MALLOC(_ptr, _ni, _type) \
80_ptr = (_type *) cs_mem_malloc(_ni, sizeof(_type), \
81 #_ptr, __FILE__, __LINE__)
82
83/*
84 * Allocate memory for _ni items of type _type.
85 *
86 * This macro calls cs_mem_malloc_hd(), automatically setting the
87 * allocated variable name and source file name and line arguments.
88 *
89 * If separate allocations are used on the host and device
90 * (mode == CS_ALLOC_HOST_DEVICE), the host pointer is returned.
91 *
92 * parameters:
93 * _ptr --> pointer to allocated memory.
94 * _ni <-- number of items.
95 * _type <-- element type.
96 * _mode <-- allocation mode.
97 */
98
99#define CS_MALLOC_HD(_ptr, _ni, _type, _mode) \
100_ptr = (_type *) cs_mem_malloc_hd(_mode, _ni, sizeof(_type), \
101 #_ptr, __FILE__, __LINE__)
102
103/*
104 * Reallocate memory for _ni items of type _type.
105 *
106 * This macro calls cs_mem_realloc(), automatically setting the
107 * allocated variable name and source file name and line arguments.
108 *
109 * parameters:
110 * _ptr <-> pointer to allocated memory.
111 * _ni <-- number of items.
112 * _type <-- element type.
113 */
114
115#define CS_REALLOC(_ptr, _ni, _type) \
116_ptr = (_type *) cs_mem_realloc(_ptr, _ni, sizeof(_type), \
117 #_ptr, __FILE__, __LINE__)
118
119/*
120 * Reallocate memory for _ni items of type _type.
121 *
122 * This macro calls cs_mem_realloc_hd(), automatically setting the
123 * allocated variable name and source file name and line arguments.
124 *
125 * If the allocation parameters are unchanged, no actual reallocation
126 * occurs.
127 *
128 * parameters:
129 * _ptr <-> pointer to allocated memory.
130 * _ni <-- number of items.
131 * _type <-- element type.
132 * _mode <-- allocation mode.
133 */
134
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__)
138
139/*
140 * Free allocated memory.
141 *
142 * This macro calls cs_mem_free(), automatically setting the
143 * allocated variable name and source file name and line arguments.
144 *
145 * The freed pointer is set to NULL to avoid accidental reuse.
146 *
147 * If separate allocations are used on the host and device
148 * (mode == CS_ALLOC_HOST_DEVICE), the host pointer should be used with this
149 * function.
150 *
151 * parameters:
152 * _ptr <-> pointer to allocated memory.
153 */
154
155#define CS_FREE(_ptr) \
156cs_mem_free(_ptr, #_ptr, __FILE__, __LINE__), _ptr = NULL
157
158/*
159 * Allocate aligned memory for _ni items of type _type.
160 *
161 * This macro calls cs_mem_memalign(), automatically setting the
162 * allocated variable name and source file name and line arguments.
163 *
164 * parameters:
165 * _ptr --> pointer to allocated memory.
166 * _align <-- alignment.
167 * _ni <-- number of items.
168 * _type <-- element type.
169 */
170
171#define CS_MEMALIGN(_ptr, _align, _ni, _type) \
172_ptr = (_type *) cs_mem_memalign(_align, _ni, sizeof(_type), \
173 #_ptr, __FILE__, __LINE__)
174
175/*=============================================================================
176 * Global variable definitions
177 *============================================================================*/
178
179#if defined(HAVE_ACCEL)
180
183
184#else
185
186#define cs_alloc_mode CS_ALLOC_HOST
187#define cs_alloc_mode_read_mostly CS_ALLOC_HOST
188
189#endif
190
191/*============================================================================
192 * Semi-private function prototypes
193 *============================================================================*/
194
197/*----------------------------------------------------------------------------
198 * Initialize memory handling.
199 *
200 * This function should be called before any other cs_mem_...()
201 * function. To activate memory allocation logging, a logfile
202 * name should be given as an argument. The resulting file will
203 * be a regular, local file. If this file cannot be opened for
204 * some reason, logging is silently de-activated.
205 *
206 * If the log file name argument is non-null but is an empty string,
207 * memory management be tracked, but not logged in detail, so only
208 * statistics will be available.
209 *
210 * parameter:
211 * log_file_name <-- name of optional log_file (if NULL, no log).
212 *----------------------------------------------------------------------------*/
213
214void
215cs_mem_init(const char *log_file_name);
216
217/*----------------------------------------------------------------------------
218 * End memory handling.
219 *
220 * This function should be called after all other cs_mem_...()
221 * functions. In case of memory allocation logging, it
222 * writes final information to the log file and closes is.
223 *----------------------------------------------------------------------------*/
224
225void
226cs_mem_end(void);
227
228/*----------------------------------------------------------------------------
229 * Indicates if cs_mem_...() functions are initialized.
230 *
231 * returns:
232 * 1 if cs_mem_init has been called, 0 otherwise.
233 *----------------------------------------------------------------------------*/
234
235int
236cs_mem_initialized(void);
237
238/*----------------------------------------------------------------------------
239 * Allocate memory for ni items of size bytes.
240 *
241 * This function calls malloc(), but adds tracing capabilities, and
242 * automatically calls the cs_error() errorhandler if it fails to
243 * allocate the required memory.
244 *
245 * Allocation couting and logging to trace file will be done if
246 * both required by the cs_mem_init options and if file_name != nullptr.
247 * If required but file_name == nullptr, it must be handled by the caller,
248 * using `cs_mem_log_mem_op`.
249 *
250 * parameters:
251 * ni <-- number of items.
252 * size <-- element size.
253 * var_name <-- allocated variable name string.
254 * file_name <-- name of calling source file.
255 * line_num <-- line number in calling source file.
256 *
257 * returns:
258 * pointer to allocated memory.
259 *----------------------------------------------------------------------------*/
260
261void *
262cs_mem_malloc(size_t ni,
263 size_t size,
264 const char *var_name,
265 const char *file_name,
266 int line_num);
267
268#if defined(HAVE_ACCEL)
269
270/*----------------------------------------------------------------------------*/
271/*
272 * \brief Allocate memory on host and device for ni elements of size bytes.
273 *
274 * This function calls the appropriate allocation function based on
275 * the requested mode, and allows introspection of the allocated memory.
276 *
277 * If separate pointers are used on the host and device,
278 * the host pointer is returned.
279 *
280 * \param [in] mode allocation mode
281 * \param [in] ni number of elements
282 * \param [in] size element size
283 * \param [in] var_name allocated variable name string
284 * \param [in] file_name name of calling source file
285 * \param [in] line_num line number in calling source file
286 *
287 * \returns pointer to allocated memory.
288 */
289/*----------------------------------------------------------------------------*/
290
291void *
292cs_mem_malloc_hd(cs_alloc_mode_t mode,
293 size_t ni,
294 size_t size,
295 const char *var_name,
296 const char *file_name,
297 int line_num);
298
299#else
300
301inline static void *
302cs_mem_malloc_hd(cs_alloc_mode_t mode,
303 size_t ni,
304 size_t size,
305 const char *var_name,
306 const char *file_name,
307 int line_num)
308{
309 CS_UNUSED(mode);
310 return cs_mem_malloc(ni, size, var_name, file_name, line_num);
311}
312
313#endif
314
315/*----------------------------------------------------------------------------
316 * Reallocate memory for ni items of size bytes.
317 *
318 * This function calls realloc(), but adds tracing capabilities, and
319 * automatically calls the cs_error() errorhandler if it fails to
320 * allocate the required memory.
321 *
322 * parameters:
323 * ptr <-> pointer to previous memory location
324 * (if NULL, cs_alloc() called).
325 * ni <-- number of items.
326 * size <-- element size.
327 * var_name <-- allocated variable name string.
328 * file_name <-- name of calling source file.
329 * line_num -> line number in calling source file
330 *
331 * returns:
332 * pointer to allocated memory.
333 *----------------------------------------------------------------------------*/
334
335void *
336cs_mem_realloc(void *ptr,
337 size_t ni,
338 size_t size,
339 const char *var_name,
340 const char *file_name,
341 int line_num);
342
343/*----------------------------------------------------------------------------*/
344/*
345 * \brief Reallocate memory on host and device for ni elements of size bytes.
346 *
347 * This function calls the appropriate reallocation function based on
348 * the requested mode, and allows introspection of the allocated memory.
349 *
350 * If separate pointers are used on the host and device,
351 * the host pointer should be used with this function.
352 *
353 * If the allocation parameters are unchanged, no actual reallocation
354 * occurs on the host.
355 *
356 * If the device uses a separate allocation, it is freed, and a new
357 * allocation is delayed (as per initial allocation) so as to invalidate copies
358 * which will not be up to date anymore after the associated values
359 * modification.
360 *
361 * \param [in] ptr pointer to previously allocated memory
362 * \param [in] mode allocation mode
363 * \param [in] ni number of elements
364 * \param [in] size element size
365 * \param [in] var_name allocated variable name string
366 * \param [in] file_name name of calling source file
367 * \param [in] line_num line number in calling source file
368 *
369 * \returns pointer to allocated memory.
370 */
371/*----------------------------------------------------------------------------*/
372
373#if defined(HAVE_ACCEL)
374
375void *
376cs_mem_realloc_hd(void *ptr,
377 cs_alloc_mode_t mode,
378 size_t ni,
379 size_t size,
380 const char *var_name,
381 const char *file_name,
382 int line_num);
383
384#else
385
386inline static void *
387cs_mem_realloc_hd(void *ptr,
388 cs_alloc_mode_t mode,
389 size_t ni,
390 size_t size,
391 const char *var_name,
392 const char *file_name,
393 int line_num)
394{
395 CS_UNUSED(mode);
396 return cs_mem_realloc(ptr, ni, size, var_name, file_name, line_num);
397}
398
399#endif
400
401/*----------------------------------------------------------------------------
402 * Free allocated memory.
403 *
404 * This function calls free(), but adds tracing capabilities, and
405 * automatically calls the cs_error() errorhandler if it fails to
406 * free the corresponding memory. In case of a null pointer argument,
407 * the function simply returns.
408 *
409 * parameters:
410 * ptr <-> pointer to previous memory location
411 * (if NULL, cs_alloc() called).
412 * var_name <-- allocated variable name string.
413 * file_name <-- name of calling source file.
414 * line_num <-- line number in calling source file.
415 *
416 * returns:
417 * null pointer.
418 *----------------------------------------------------------------------------*/
419
420void *
421cs_mem_free(void *ptr,
422 const char *var_name,
423 const char *file_name,
424 int line_num);
425
426/*----------------------------------------------------------------------------
427 * Allocate aligned memory for ni elements of size bytes.
428 *
429 * This function calls posix_memalign() if available, but adds tracing
430 * capabilities, and automatically calls the cs_error() errorhandler if
431 * it fails to allocate the required memory.
432 *
433 * The associated function cs_mem_have_memalign() indicates if this
434 * type of allocation may be used on this system.
435 *
436 * parameters:
437 * alignment <-- alignent.
438 * ni <-- number of items.
439 * size <-- element size.
440 * var_name <-- allocated variable name string.
441 * file_name <-- name of calling source file.
442 * line_num <-- line number in calling source file.
443 *
444 * returns:
445 * pointer to allocated memory.
446 *----------------------------------------------------------------------------*/
447
448void *
449cs_mem_memalign(size_t alignment,
450 size_t ni,
451 size_t size,
452 const char *var_name,
453 const char *file_name,
454 int line_num);
455
456/*----------------------------------------------------------------------------*/
457/*
458 * \brief Return current theoretical dynamic memory allocated.
459 *
460 * \return current memory handled through cs_mem_...() (in kB).
461 *----------------------------------------------------------------------------*/
462
463size_t
464cs_mem_size_current(void);
465
466/*----------------------------------------------------------------------------*/
467/*
468 * \brief Return maximum theoretical dynamic memory allocated.
469 *
470 * \return maximum memory handled through cs_mem_...() (in kB).
471 *----------------------------------------------------------------------------*/
472
473size_t
474cs_mem_size_max(void);
475
476/*----------------------------------------------------------------------------
477 * Indicate if a memory aligned allocation variant is available.
478 *
479 * If no such function is available, cs_mem_memalign() will always fail.
480 *
481 * returns:
482 * 1 if memory aligned allocation is possible, 0 otherwise.
483 *----------------------------------------------------------------------------*/
484
485int
486cs_mem_have_memalign(void);
487
488/*----------------------------------------------------------------------------*/
489/* Returns the error handler associated with the cs_mem_...() functions.
490 *
491 * returns:
492 * pointer to the error handler function.
493 *----------------------------------------------------------------------------*/
494
496cs_mem_error_handler_get(void);
497
498/*----------------------------------------------------------------------------
499 * Associates an error handler with the cs_mem_...() functions.
500 *
501 * With the default error handler, an error message is output to stderr,
502 * (after cs_print_flush() is called), and the general error handler used
503 * by cs_error() is then called (which results in the termination of the
504 * current process or process group).
505 *
506 * parameter:
507 * handler <-- pointer to the error handler function.
508 *----------------------------------------------------------------------------*/
509
510void
511cs_mem_error_handler_set(bft_error_handler_t *handler);
512
513/*============================================================================
514 * Semi-private function definitions
515 *============================================================================*/
516
517#if defined(HAVE_OPENMP_TARGET)
518
519/*----------------------------------------------------------------------------*/
520/*
521 * \brief Set OpenMp target device id
522 *
523 * \param [in] device_id device id to use for OpenMP device memory handling.
524 */
525/*----------------------------------------------------------------------------*/
526
527void
528cs_mem_set_omp_target_device_id(int device_id);
529
530#endif
531
534/*============================================================================
535 * Public function prototypes
536 *============================================================================*/
537
538/*----------------------------------------------------------------------------*/
554int
555cs_mem_stats(uint64_t *alloc_cur,
556 uint64_t *alloc_max,
557 uint64_t *n_allocs,
558 uint64_t *n_reallocs,
559 uint64_t *n_frees,
560 uint64_t *n_current);
561
562#if defined(HAVE_ACCEL)
563
564/*----------------------------------------------------------------------------*/
575/*----------------------------------------------------------------------------*/
576
577void
578cs_copy_h2d(void *dest,
579 const void *src,
580 size_t size);
581
582/*----------------------------------------------------------------------------*/
593/*----------------------------------------------------------------------------*/
594
595void
596cs_copy_d2h(void *dest,
597 const void *src,
598 size_t size);
599
600/*----------------------------------------------------------------------------*/
611/*----------------------------------------------------------------------------*/
612
613void
614cs_copy_d2d(void *dest,
615 const void *src,
616 size_t size);
617
618#endif // defined(HAVE_ACCEL)
619
620/*----------------------------------------------------------------------------*/
634/*----------------------------------------------------------------------------*/
635
636#if defined(HAVE_ACCEL)
637
638void *
639cs_get_device_ptr(void *ptr);
640
641#else
642
643inline static void *
645{
646 return ptr;
647}
648
649#endif
650
652
653#if defined(__cplusplus) && defined(HAVE_ACCEL)
654
655template <class T>
656inline const T *
658{
659 const void *ptr_v
660 = cs_get_device_ptr_const(reinterpret_cast<void *>(ptr));
661
662 return (const T *)ptr_v;
663}
664
665#endif // __cplusplus && HAVE_ACCEL
666
668
669/*----------------------------------------------------------------------------*/
683/*----------------------------------------------------------------------------*/
684
685#if defined(HAVE_ACCEL)
686
687const void *
688cs_get_device_ptr_const(const void *ptr);
689
690#else
691
692inline static const void *
694{
695 return ptr;
696}
697
698#endif
699
701
702#if defined(__cplusplus) && defined(HAVE_ACCEL)
703
704template <class T>
705inline const T *
706cs_get_device_ptr_const(const T *ptr)
707{
708 const void *ptr_v
709 = cs_get_device_ptr_const(reinterpret_cast<const void *>(ptr));
710
711 return (const T *)ptr_v;
712}
713
714#endif // __cplusplus && HAVE_ACCEL
715
717
718/*----------------------------------------------------------------------------*/
733/*----------------------------------------------------------------------------*/
734
735#if defined(HAVE_ACCEL)
736
737const void *
738cs_get_device_ptr_const_pf(const void *ptr);
739
740#else
741
742inline static const void *
744{
745 return ptr;
746}
747
748#endif
749
751
752#if defined(__cplusplus) && defined(HAVE_ACCEL)
753
754template <class T>
755inline const T *
756cs_get_device_ptr_const_pf(const T *ptr)
757{
758 const void *ptr_v
759 = cs_get_device_ptr_const_pf(reinterpret_cast<const void *>(ptr));
760
761 return (const T *)ptr_v;
762}
763
764#endif // __cplusplus && HAVE_ACCEL
765
767
768/*----------------------------------------------------------------------------*/
777/*----------------------------------------------------------------------------*/
778
779#if defined(HAVE_ACCEL)
780
782cs_check_device_ptr(const void *ptr);
783
784#else
785
786inline static cs_alloc_mode_t
787cs_check_device_ptr(const void *ptr)
788{
789 CS_UNUSED(ptr);
790 return CS_ALLOC_HOST;
791}
792
793#endif
794
795/*----------------------------------------------------------------------------*/
804/*----------------------------------------------------------------------------*/
805
806#if defined(HAVE_ACCEL)
807
808bool
809cs_mem_is_device_ptr(const void *ptr);
810
811#else
812
813inline static bool
814cs_mem_is_device_ptr(const void *ptr)
815{
816 CS_UNUSED(ptr);
817 return false;
818}
819
820#endif
821
822/*----------------------------------------------------------------------------*/
836/*----------------------------------------------------------------------------*/
837
838#if defined(HAVE_ACCEL)
839
840void *
841cs_associate_device_ptr(void *host_ptr,
842 size_t ni,
843 size_t size);
844
845#else
846
847#define cs_associate_device_ptr(_host_ptr, _ni, _size);
848
849#endif
850
851/*----------------------------------------------------------------------------*/
860/*----------------------------------------------------------------------------*/
861
862#if defined(HAVE_ACCEL)
863
864void
865cs_disassociate_device_ptr(void *host_ptr);
866
867#else
868
869#define cs_disassociate_device_ptr(_host_ptr);
870
871#endif
872
873/*----------------------------------------------------------------------------*/
884/*----------------------------------------------------------------------------*/
885
886#if defined(HAVE_ACCEL)
887
888void
889cs_set_alloc_mode(void **host_ptr,
890 cs_alloc_mode_t mode);
891
892#else
893
894#define cs_set_alloc_mode(_host_ptr, mode);
895
896#endif
897
898/*----------------------------------------------------------------------------*/
909/*----------------------------------------------------------------------------*/
910
912
913#if defined(__cplusplus) && defined(HAVE_ACCEL)
914
915template<typename T>
916static inline void
917cs_set_alloc_mode_r(T* &host_ptr,
918 cs_alloc_mode_t mode)
919{
920 void *p = host_ptr;
921 cs_set_alloc_mode(&p, mode);
922 host_ptr = (T *)p;
923}
924
925#else
926
927#define cs_set_alloc_mode_r(_host_ptr, mode);
928
929#endif // __cplusplus && HAVE_ACCEL
930
932
933/*----------------------------------------------------------------------------*/
939/*----------------------------------------------------------------------------*/
940
941#if defined(HAVE_ACCEL)
942
943void
945
946#else
947
948#define cs_mem_advise_set_read_mostly(ptr);
949
950#endif
951
952/*----------------------------------------------------------------------------*/
958/*----------------------------------------------------------------------------*/
959
960#if defined(HAVE_ACCEL)
961
962void
964
965#else
966
967#define cs_mem_advise_unset_read_mostly(ptr);
968
969#endif
970
971/*----------------------------------------------------------------------------*/
987/*----------------------------------------------------------------------------*/
988
989#if defined(HAVE_ACCEL)
990
991void
992cs_sync_h2d(const void *ptr);
993
994#else
995
996static inline void
997cs_sync_h2d(const void *ptr)
998{
999 CS_UNUSED(ptr);
1000}
1001
1002#endif
1003
1004/*----------------------------------------------------------------------------*/
1021/*----------------------------------------------------------------------------*/
1022
1023#if defined(HAVE_ACCEL)
1024
1025void
1026cs_sync_d2h(void *ptr);
1027
1028#else
1029
1030static inline void
1031cs_sync_d2h(void *ptr)
1032{
1033 CS_UNUSED(ptr);
1034}
1035
1036#endif
1037
1038/*----------------------------------------------------------------------------*/
1055/*----------------------------------------------------------------------------*/
1056
1057#if defined(HAVE_ACCEL)
1058
1059void
1060cs_sync_d2h_if_needed(void *ptr);
1061
1062#else
1063
1064static inline void
1066{
1067 CS_UNUSED(ptr);
1068}
1069
1070#endif
1071
1072/*----------------------------------------------------------------------------*/
1083/*----------------------------------------------------------------------------*/
1084
1085#if defined(HAVE_ACCEL)
1086
1087void
1088cs_prefetch_h2d(void *ptr,
1089 size_t size);
1090
1091#else
1092
1093static inline void
1095 size_t size)
1096{
1097 CS_UNUSED(ptr);
1098 CS_UNUSED(size);
1099}
1100
1101#endif
1102
1103/*----------------------------------------------------------------------------*/
1114/*----------------------------------------------------------------------------*/
1115
1116#if defined(HAVE_ACCEL)
1117
1118void
1119cs_prefetch_d2h(void *ptr,
1120 size_t size);
1121
1122#else
1123
1124static inline void
1126 size_t size)
1127{
1128 CS_UNUSED(ptr);
1129 CS_UNUSED(size);
1130}
1131
1132#endif
1133
1134#if defined(HAVE_ACCEL)
1135
1136/*----------------------------------------------------------------------------*/
1137/*
1138 * \brief Activate device memory pool
1139 *
1140 * \param [in] status true to activate, false to deactivate
1141 */
1142/*----------------------------------------------------------------------------*/
1143
1144void
1145cs_mem_device_pool_set_active(bool status);
1146
1147/*----------------------------------------------------------------------------*/
1148/*
1149 * \brief Set maximum allocation size for free memory pool.
1150 *
1151 * When the memory pool is active, memory that should be freed is transferred
1152 * to the memory pool instead, so it can be reused.
1153 * If > 0, this size corresponds to the maximum total size the pool will
1154 * manage before evicting blocks.
1155 *
1156 * \param [in] size maximum total allocation size in pool, or 0
1157 */
1158/*----------------------------------------------------------------------------*/
1159
1160void
1161cs_mem_device_pool_set_max_capacity(size_t size);
1162
1163/*----------------------------------------------------------------------------*/
1164/*
1165 * \brief Set maximum number of tries before a block in memory pool is evicted
1166 *
1167 * \param [in] n_tries number of tries
1168 */
1169/*----------------------------------------------------------------------------*/
1170
1171void
1172cs_mem_device_pool_set_max_tries(short int n_tries);
1173
1174/*----------------------------------------------------------------------------*/
1175/*
1176 * \brief Clear device memory pool if present
1177 */
1178/*----------------------------------------------------------------------------*/
1179
1180void
1181cs_mem_device_pool_clear(void);
1182
1183#endif // defined(HAVE_ACCEL)
1184
1185/*----------------------------------------------------------------------------*/
1186
1188
1189#endif /* CS_MEM_H */
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
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.
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