16#include "../offload/offload_library.h"
17#include "../offload/offload_runtime.h"
60#if defined(__OFFLOAD) && !defined(__NO_OFFLOAD_DBM)
62 offload_activate_chosen_device();
63 offloadMalloc(&memory,
size);
66 offloadMallocHost(&memory,
size);
75 assert(memory != NULL);
96 void *
mem = (
void *)(uintptr_t)memory;
97#if defined(__OFFLOAD) && !defined(__NO_OFFLOAD_DBM)
99 offload_activate_chosen_device();
103 offloadFreeHost(
mem);
119#if DBM_MEMPOOL_DEVICE || DBM_MEMPOOL_HOST
132#pragma omp critical(dbm_mempool_modify)
136 for (; NULL != *available_head; available_head = &(*available_head)->
next) {
137 const size_t s = (*available_head)->
size;
138 if (
size <= s && (NULL == reuse || s < (*reuse)->
size)) {
139 reuse = available_head;
140 if (
size == (*reuse)->size) {
143 }
else if (NULL != reclaim) {
144 if (s > (*reclaim)->size) {
145 reclaim = available_head;
148 reclaim = available_head;
158 *reuse = chunk->
next;
161 assert(chunk != NULL);
165 chunk->
next = *allocated_head;
166 *allocated_head = chunk;
171 void *memory = chunk->
mem;
201#if DBM_MEMPOOL_DEVICE
202#if defined(__OFFLOAD) && !defined(__NO_OFFLOAD_DBM)
217#if DBM_MEMPOOL_DEVICE || DBM_MEMPOOL_HOST
222#pragma omp critical(dbm_mempool_modify)
225 while (NULL != *allocated_head && (*allocated_head)->
mem !=
mem) {
226 allocated_head = &(*allocated_head)->
next;
229 assert(NULL != chunk && chunk->
mem ==
mem);
232 *allocated_head = chunk->
next;
235 chunk->
next = *available_head;
236 *available_head = chunk;
260#if DBM_MEMPOOL_DEVICE
261#if defined(__OFFLOAD) && !defined(__NO_OFFLOAD_DBM)
281 while (NULL != *available_head) {
283 *available_head = chunk->
next;
298#pragma omp critical(dbm_mempool_modify)
310 assert(NULL != memstats);
312#pragma omp critical(dbm_mempool_modify)
316 chunk = chunk->
next) {
321 chunk = chunk->
next) {
326 chunk = chunk->
next) {
331 chunk = chunk->
next) {
static void * actual_malloc(size_t size, bool on_device)
Private routine for actually allocating system memory.
void dbm_mempool_device_free(const void *memory)
Internal routine for releasing memory back to the pool.
void dbm_mempool_statistics(dbm_memstats_t *memstats)
Internal routine to query statistics.
static dbm_memchunk_t * mempool_device_available_head
Private linked list of memory chunks that are available.
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 dbm_memstats_t mempool_stats
Private statistics.
static void internal_mempool_clear(dbm_memchunk_t **available_head)
Private routine for freeing all memory in the pool.
void * dbm_mempool_host_malloc(size_t size)
Internal routine for allocating host memory from the pool.
static dbm_memchunk_t * mempool_host_available_head
static void * internal_mempool_malloc(dbm_memchunk_t **available_head, dbm_memchunk_t **allocated_head, size_t size)
Private routine for allocating host or device memory from the pool.
static void actual_free(const void *memory, bool on_device)
Private routine for actually freeing system memory.
static void internal_mempool_free(dbm_memchunk_t **available_head, dbm_memchunk_t **allocated_head, const void *mem)
Private routine for releasing memory back to the pool.
static dbm_memchunk_t * mempool_host_allocated_head
static dbm_memchunk_t * mempool_device_allocated_head
Private linked list of memory chunks that are in use.
void * dbm_mempool_device_malloc(size_t size)
Internal routine for allocating device memory from the 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
Internal struct for pool statistics.