(git:9ccafda)
Loading...
Searching...
No Matches
offload_mempool.c File Reference
#include "offload_mempool.h"
#include "../mpiwrap/cp_mpi.h"
#include "offload_library.h"
#include "offload_runtime.h"
#include <assert.h>
#include <inttypes.h>
#include <omp.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Data Structures

struct  offload_memchunk
 Private struct for storing a chunk of memory. More...
struct  offload_mempool
 Private struct for storing a memory pool. More...

Macros

#define OFFLOAD_MEMPOOL_PRINT(FN, MSG, OUTPUT_UNIT)
#define OFFLOAD_MEMPOOL_OMPALLOC   1

Typedefs

typedef struct offload_memchunk offload_memchunk_t
 Private struct for storing a chunk of memory.
typedef struct offload_mempool offload_mempool_t
 Private struct for storing a memory pool.

Functions

static uint64_t imax (uint64_t x, uint64_t y)
 Returns the larger of two given integer (missing from the C standard).
static void * actual_malloc (const size_t size, const bool on_device)
 Private routine for actually allocating system memory.
static void actual_free (void *memory, const bool on_device)
 Private routine for actually freeing system memory.
static void * internal_mempool_malloc (offload_mempool_t *pool, const size_t size, const bool on_device)
 Private routine for allocating host or device memory from the pool.
void * offload_mempool_host_malloc (const size_t size)
 Internal routine for allocating host memory from the pool.
void * offload_mempool_device_malloc (const size_t size)
 Internal routine for allocating device memory from the pool.
static void internal_mempool_free (offload_mempool_t *pool, const void *mem)
 Private routine for releasing memory back to the pool.
void offload_mempool_host_free (const void *memory)
 Internal routine for releasing memory back to the pool.
void offload_mempool_device_free (const void *memory)
 Internal routine for releasing memory back to the pool.
static void internal_mempool_clear (offload_mempool_t *pool, const bool on_device)
 Private routine for freeing all memory in the pool.
void offload_mempool_clear (void)
 Internal routine for freeing all memory in the pool.
static uint64_t sum_chunks_size (const offload_memchunk_t *head)
 Private routine for summing alloc sizes of all chunks in given list.
static uint64_t sum_chunks_used (const offload_memchunk_t *head)
 Private routine for summing used sizes of all chunks in given list.
void offload_mempool_stats_get (offload_mempool_stats_t *memstats)
 Internal routine to query statistics.
void offload_mempool_stats_print (int fortran_comm, void(*print_func)(const char *, int, int), int output_unit)
 Print allocation statistics..

Variables

static offload_mempool_t mempool_host = {0}
 Private pools for host and device memory.
static offload_mempool_t mempool_device = {0}
static uint64_t host_malloc_counter = 0
 Private counters for statistics.
static uint64_t device_malloc_counter = 0

Macro Definition Documentation

◆ OFFLOAD_MEMPOOL_PRINT

#define OFFLOAD_MEMPOOL_PRINT ( FN,
MSG,
OUTPUT_UNIT )
Value:
((FN)(MSG, (int)strlen(MSG), OUTPUT_UNIT))

Definition at line 24 of file offload_mempool.c.

◆ OFFLOAD_MEMPOOL_OMPALLOC

#define OFFLOAD_MEMPOOL_OMPALLOC   1

Definition at line 26 of file offload_mempool.c.

Typedef Documentation

◆ offload_memchunk_t

Private struct for storing a chunk of memory.

Author
Ole Schuett

◆ offload_mempool_t

Private struct for storing a memory pool.

Author
Ole Schuett

Function Documentation

◆ imax()

uint64_t imax ( uint64_t x,
uint64_t y )
inlinestatic

Returns the larger of two given integer (missing from the C standard).

Author
Ole Schuett

Definition at line 63 of file offload_mempool.c.

Here is the caller graph for this function:

◆ actual_malloc()

void * actual_malloc ( const size_t size,
const bool on_device )
static

Private routine for actually allocating system memory.

Author
Ole Schuett

Definition at line 69 of file offload_mempool.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ actual_free()

void actual_free ( void * memory,
const bool on_device )
static

Private routine for actually freeing system memory.

Author
Ole Schuett

Definition at line 113 of file offload_mempool.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ internal_mempool_malloc()

void * internal_mempool_malloc ( offload_mempool_t * pool,
const size_t size,
const bool on_device )
static

Private routine for allocating host or device memory from the pool.

Author
Ole Schuett and Hans Pabst

Definition at line 146 of file offload_mempool.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ offload_mempool_host_malloc()

void * offload_mempool_host_malloc ( const size_t size)

Internal routine for allocating host memory from the pool.

Author
Ole Schuett

Definition at line 212 of file offload_mempool.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ offload_mempool_device_malloc()

void * offload_mempool_device_malloc ( const size_t size)

Internal routine for allocating device memory from the pool.

Author
Ole Schuett

Definition at line 220 of file offload_mempool.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ internal_mempool_free()

void internal_mempool_free ( offload_mempool_t * pool,
const void * mem )
static

Private routine for releasing memory back to the pool.

Author
Ole Schuett

Definition at line 228 of file offload_mempool.c.

Here is the caller graph for this function:

◆ offload_mempool_host_free()

void offload_mempool_host_free ( const void * memory)

Internal routine for releasing memory back to the pool.

Author
Ole Schuett

Definition at line 256 of file offload_mempool.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ offload_mempool_device_free()

void offload_mempool_device_free ( const void * memory)

Internal routine for releasing memory back to the pool.

Author
Ole Schuett

Definition at line 264 of file offload_mempool.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ internal_mempool_clear()

void internal_mempool_clear ( offload_mempool_t * pool,
const bool on_device )
static

Private routine for freeing all memory in the pool.

Author
Ole Schuett

Definition at line 272 of file offload_mempool.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ offload_mempool_clear()

void offload_mempool_clear ( void )

Internal routine for freeing all memory in the pool.

Author
Ole Schuett and Hans Pabst

Definition at line 300 of file offload_mempool.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sum_chunks_size()

uint64_t sum_chunks_size ( const offload_memchunk_t * head)
static

Private routine for summing alloc sizes of all chunks in given list.

Author
Ole Schuett

Definition at line 309 of file offload_mempool.c.

Here is the caller graph for this function:

◆ sum_chunks_used()

uint64_t sum_chunks_used ( const offload_memchunk_t * head)
static

Private routine for summing used sizes of all chunks in given list.

Author
Ole Schuett

Definition at line 322 of file offload_mempool.c.

Here is the caller graph for this function:

◆ offload_mempool_stats_get()

void offload_mempool_stats_get ( offload_mempool_stats_t * memstats)

Internal routine to query statistics.

Author
Hans Pabst

Definition at line 335 of file offload_mempool.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ offload_mempool_stats_print()

void offload_mempool_stats_print ( int fortran_comm,
void(* print_func )(const char *, int, int),
int output_unit )

Print allocation statistics..

Print allocation statistics.

Author
Hans Pabst

Definition at line 360 of file offload_mempool.c.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ mempool_host

offload_mempool_t mempool_host = {0}
static

Private pools for host and device memory.

Author
Ole Schuett

Definition at line 51 of file offload_mempool.c.

◆ mempool_device

offload_mempool_t mempool_device = {0}
static

Definition at line 51 of file offload_mempool.c.

◆ host_malloc_counter

uint64_t host_malloc_counter = 0
static

Private counters for statistics.

Author
Hans Pabst

Definition at line 57 of file offload_mempool.c.

◆ device_malloc_counter

uint64_t device_malloc_counter = 0
static

Definition at line 57 of file offload_mempool.c.