Go to the documentation of this file.
23 std::function<
void *( size_t ,
char const *)> alloc_device_func;
25 std::function<void (
void * ,
char const *)> free_device_func;
27 std::function<void ()> timer_init;
29 std::function<void ()> timer_finalize;
31 std::function<void (
char const *)> timer_start;
33 std::function<void (
char const *)> timer_stop;
37 size_t pool_initial_mb;
41 size_t pool_block_bytes;
48 size_t mem_total, mem_free;
49 #if defined(YAKL_ARCH_CUDA)
50 cudaMemGetInfo(&mem_free, &mem_total);
51 mem_free /= 1024*1024;
52 mem_total /= 1024*1024;
53 #elif defined(YAKL_ARCH_HIP)
54 hipMemGetInfo(&mem_free, &mem_total);
55 mem_free /= 1024*1024;
56 mem_total /= 1024*1024;
57 #elif defined(YAKL_ARCH_SYCL)
58 mem_total = sycl_default_stream().get_device().get_info<sycl::info::device::global_mem_size>();
59 mem_free = sycl_default_stream().get_device().get_info<sycl::ext::intel::info::device::free_memory>();
60 mem_free /= 1024*1024;
61 mem_total /= 1024*1024;
63 long pages = sysconf(_SC_PHYS_PAGES);
64 long page_size = sysconf(_SC_PAGE_SIZE);
65 mem_total = (size_t)pages*(
size_t)page_size;
67 mem_free /= 1024*1024;
68 mem_total /= 1024*1024;
71 pool_initial_mb = mem_total / 8;
72 if (mem_free < pool_initial_mb) pool_initial_mb = 0.5*mem_free;
73 pool_grow_mb = pool_initial_mb;
74 pool_block_bytes = 16*
sizeof(size_t);
76 char * env = std::getenv(
"GATOR_DISABLE");
77 if ( env !=
nullptr ) {
78 std::string resp(env);
79 if (resp ==
"yes" || resp ==
"YES" || resp ==
"1" || resp ==
"true" || resp ==
"TRUE" || resp ==
"T") {
85 env = std::getenv(
"GATOR_INITIAL_MB");
86 if ( env !=
nullptr ) {
87 long int initial_mb = atol(env);
88 if (initial_mb != 0) {
89 pool_initial_mb = initial_mb;
90 pool_grow_mb = pool_initial_mb;
92 if (
yakl_mainproc()) std::cout <<
"WARNING: Invalid GATOR_INITIAL_MB. Defaulting to 1GB\n";
96 env = std::getenv(
"GATOR_GROW_MB");
97 if ( env !=
nullptr ) {
98 long int grow_mb = atol(env);
100 pool_grow_mb = grow_mb;
102 if (
yakl_mainproc()) std::cout <<
"WARNING: Invalid GATOR_GROW_MB. Defaulting to 1GB\n";
107 env = std::getenv(
"GATOR_BLOCK_BYTES");
108 if ( env !=
nullptr ) {
109 long int block_bytes = atol(env);
110 if (block_bytes != 0 && block_bytes%(2*
sizeof(
size_t)) == 0) {
111 pool_block_bytes = block_bytes;
113 if (
yakl_mainproc()) std::cout <<
"WARNING: Invalid GATOR_BLOCK_BYTES. Defaulting to 16*sizeof(size_t)\n";
114 if (
yakl_mainproc()) std::cout <<
" GATOR_BLOCK_BYTES must be > 0 and a multiple of 2*sizeof(size_t)\n";
120 alloc_device_func = [=] (
size_t bytes ,
char const *label) ->
void * {
return func(bytes); };
125 free_device_func = [=] (
void *ptr ,
char const *label) { func(ptr); };
An object of this class can optionally be passed to yakl::init() to configure the initialization....
Definition: YAKL_InitConfig.h:20
void timer_stop(char const *lab)
Stop a timer with the given string label. NOTE: Timers must be perfectly nested.
Definition: YAKL_timers.h:26
InitConfig set_timer_start(std::function< void(char const *)> func)
Pass the timer start function you wish to use to override YAKL's default.
Definition: YAKL_InitConfig.h:137
std::function< void *(size_t, char const *)> get_device_allocator() const
Get the device allocator function. Returns an empty std::function if the user has not set one.
Definition: YAKL_InitConfig.h:149
InitConfig set_pool_grow_mb(size_t grow_mb)
Tell YAKL how big each additional pool should be in MB.
Definition: YAKL_InitConfig.h:145
InitConfig set_timer_init(std::function< void()> func)
Pass the timer init function you wish to use to override YAKL's default.
Definition: YAKL_InitConfig.h:133
void timer_finalize()
Finalize the YAKL timers.
Definition: YAKL_timers.h:20
std::function< void(char const *)> get_timer_start() const
Get the timer start function. Returns an empty std::function if the user has not set one.
Definition: YAKL_InitConfig.h:157
InitConfig()
Creating an InitConfig() controls the memory pool parameters, timer function overrides,...
Definition: YAKL_InitConfig.h:47
#define __YAKL_NAMESPACE_WRAPPER_END__
Definition: YAKL.h:20
InitConfig set_device_deallocator(std::function< void(void *, char const *)> func)
Pass the device deallocator function you wish to use to override YAKL's default (LABEL)
Definition: YAKL_InitConfig.h:131
InitConfig set_timer_finalize(std::function< void()> func)
Pass the timer finalize function you wish to use to override YAKL's default.
Definition: YAKL_InitConfig.h:135
#define __YAKL_NAMESPACE_WRAPPER_BEGIN__
Definition: YAKL.h:19
InitConfig set_device_allocator(std::function< void *(size_t, char const *)> func)
Pass the device allocator function you wish to use to override YAKL's default (LABEL)
Definition: YAKL_InitConfig.h:129
std::function< void(char const *)> get_timer_stop() const
Get the timer stop function. Returns an empty std::function if the user has not set one.
Definition: YAKL_InitConfig.h:159
InitConfig set_pool_block_bytes(size_t block_bytes)
Tell YAKL how big each additional pool should be in MB.
Definition: YAKL_InitConfig.h:147
InitConfig set_pool_initial_mb(size_t initial_mb)
Tell YAKL how big the initial pool should be in MB.
Definition: YAKL_InitConfig.h:143
InitConfig set_pool_enabled(bool enabled)
Tell YAKL whether to enable the pool or not.
Definition: YAKL_InitConfig.h:141
std::function< void()> get_timer_finalize() const
Get the timer finalize function. Returns an empty std::function if the user has not set one.
Definition: YAKL_InitConfig.h:155
bool yakl_mainproc()
If true, this is the main MPI process (task number == 0)
Definition: YAKL_error.h:64
InitConfig set_device_deallocator(std::function< void(void *)> func)
Pass the device deallocator function you wish to use to override YAKL's default (NO LABEL)
Definition: YAKL_InitConfig.h:124
std::function< void()> get_timer_init() const
Get the timer init function. Returns an empty std::function if the user has not set one.
Definition: YAKL_InitConfig.h:153
bool get_pool_enabled() const
Determine whether this config object will enable the device memory pool.
Definition: YAKL_InitConfig.h:161
size_t get_pool_grow_mb() const
Determine how many MB this config will request the pool to use for additional pools.
Definition: YAKL_InitConfig.h:165
InitConfig set_device_allocator(std::function< void *(size_t)> func)
Pass the device allocator function you wish to use to override YAKL's default (NO LABEL)
Definition: YAKL_InitConfig.h:119
void timer_start(char const *lab)
Start a timer with the given string label. NOTE: Timers must be perfectly nested.
Definition: YAKL_timers.h:23
size_t get_pool_initial_mb() const
Determine how many MB this config will request the pool to use for the initial device memory pool.
Definition: YAKL_InitConfig.h:163
InitConfig set_timer_stop(std::function< void(char const *)> func)
Pass the timer stop function you wish to use to override YAKL's default.
Definition: YAKL_InitConfig.h:139
void timer_init()
Initialize the YAKL timers.
Definition: YAKL_timers.h:17
std::function< void(void *, char const *)> get_device_deallocator() const
Get the device deallocator function. Returns an empty std::function if the user has not set one.
Definition: YAKL_InitConfig.h:151
size_t get_pool_block_bytes() const
Determine how many bytes this config will request the pool to use for block size.
Definition: YAKL_InitConfig.h:167