16#include "../offload/offload_library.h"
17#include "../offload/offload_runtime.h"
63#if defined(__OFFLOAD) && !defined(__NO_OFFLOAD_DBM)
65 offload_activate_chosen_device();
66 offloadMalloc(&memory, size);
68 offload_activate_chosen_device();
69 offloadMallocHost(&memory, size);
84 assert(memory != NULL);
97#if defined(__OFFLOAD) && !defined(__NO_OFFLOAD_DBM)
99 offload_activate_chosen_device();
102 offload_activate_chosen_device();
103 offloadFreeHost(memory);
116 const bool on_device) {
123#pragma omp critical(dbm_mempool_modify)
128 while (*indirect != NULL) {
129 const size_t s = (*indirect)->
size;
130 if (size <= s && (reuse == NULL || s < (*reuse)->
size)) {
135 }
else if (reclaim == NULL || (*reclaim)->size < s) {
138 indirect = &(*indirect)->
next;
145 *reuse = chunk->
next;
146 }
else if (reclaim != NULL) {
149 *reclaim = chunk->
next;
153 assert(chunk != NULL);
158 if (chunk->
size < size) {
167#pragma omp critical(dbm_mempool_modify)
201#pragma omp critical(dbm_mempool_modify)
205 while (*indirect != NULL && (*indirect)->
mem != mem) {
206 indirect = &(*indirect)->
next;
209 assert(chunk != NULL && chunk->
mem == mem);
212 *indirect = chunk->
next;
241#pragma omp critical(dbm_mempool_modify)
270 uint64_t size_sum = 0;
272 size_sum += chunk->size;
282 uint64_t used_sum = 0;
284 used_sum += chunk->used;
294 assert(NULL != memstats);
295#pragma omp critical(dbm_mempool_modify)
static dbm_mempool_t mempool_host
Private pools for host and device memory.
static uint64_t sum_chunks_used(const dbm_memchunk_t *head)
Private routine for summing used sizes of all chunks in given list.
void dbm_mempool_device_free(const void *memory)
Internal routine for releasing memory back to the pool.
static dbm_mempool_t mempool_device
static void actual_free(void *memory, const bool on_device)
Private routine for actually freeing system memory.
void dbm_mempool_statistics(dbm_memstats_t *memstats)
Internal routine to query statistics.
void * dbm_mempool_host_malloc(const size_t size)
Internal routine for allocating host memory from the pool.
void dbm_mempool_host_free(const void *memory)
Internal routine for releasing memory back to the pool.
void dbm_mempool_clear(void)
Internal routine for freeing all memory in the pool.
struct dbm_memchunk dbm_memchunk_t
Private struct for storing a chunk of memory.
static uint64_t sum_chunks_size(const dbm_memchunk_t *head)
Private routine for summing alloc sizes of all chunks in given list.
static uint64_t host_malloc_counter
Private some counters for statistics.
static void internal_mempool_clear(dbm_mempool_t *pool, const bool on_device)
Private routine for freeing all memory in the pool.
static void * internal_mempool_malloc(dbm_mempool_t *pool, const size_t size, const bool on_device)
Private routine for allocating host or device memory from the pool.
static void * actual_malloc(const size_t size, const bool on_device)
Private routine for actually allocating system memory.
void * dbm_mempool_device_malloc(const size_t size)
Internal routine for allocating device memory from the pool.
static void internal_mempool_free(dbm_mempool_t *pool, const void *mem)
Private routine for releasing memory back to the pool.
static uint64_t device_malloc_counter
struct dbm_mempool dbm_mempool_t
Private struct for storing a memory pool.
void dbm_mpi_free_mem(void *mem)
Wrapper around MPI_Free_mem.
void * dbm_mpi_alloc_mem(size_t size)
Wrapper around MPI_Alloc_mem.
Private struct for storing a chunk of memory.
struct dbm_memchunk * next
Private struct for storing a memory pool.
dbm_memchunk_t * allocated_head
dbm_memchunk_t * available_head
Internal struct for pool statistics.