(git:e966546)
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)    ((FN)(MSG, (int)strlen(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 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 some counters for statistics.
 
static uint64_t device_malloc_counter = 0
 

Macro Definition Documentation

◆ OFFLOAD_MEMPOOL_PRINT

#define OFFLOAD_MEMPOOL_PRINT (   FN,
  MSG,
  OUTPUT_UNIT 
)     ((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

◆ actual_malloc()

static 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 62 of file offload_mempool.c.

Here is the caller graph for this function:

◆ actual_free()

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

Private routine for actually freeing system memory.

Author
Ole Schuett

Definition at line 106 of file offload_mempool.c.

Here is the caller graph for this function:

◆ internal_mempool_malloc()

static 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 139 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 205 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 213 of file offload_mempool.c.

Here is the call graph for this function:

◆ internal_mempool_free()

static 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 221 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 249 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 257 of file offload_mempool.c.

Here is the call graph for this function:

◆ internal_mempool_clear()

static 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 265 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

Definition at line 286 of file offload_mempool.c.

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

◆ sum_chunks_size()

static 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 295 of file offload_mempool.c.

Here is the caller graph for this function:

◆ sum_chunks_used()

static 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 308 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 321 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(*)(const char *, int, int)  print_func,
int  output_unit 
)

Print allocation statistics..

Print allocation statistics.

Author
Hans Pabst

Definition at line 343 of file offload_mempool.c.

Here is the call 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 50 of file offload_mempool.c.

◆ mempool_device

offload_mempool_t mempool_device = {0}
static

Definition at line 50 of file offload_mempool.c.

◆ host_malloc_counter

uint64_t host_malloc_counter = 0
static

Private some counters for statistics.

Author
Hans Pabst

Definition at line 56 of file offload_mempool.c.

◆ device_malloc_counter

uint64_t device_malloc_counter = 0
static

Definition at line 56 of file offload_mempool.c.