![]() |
(git:5a3db73)
|
#include "offload_mempool.h"#include "../mpiwrap/cp_mpi.h"#include "offload_library.h"#include "offload_runtime.h"#include "../base/cp_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 |
| #define | OFFLOAD_MEMPOOL_SLACK 4 /* 1/4 */ |
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. | |
Enumerations | |
| enum | { MEMPOOL_INITIAL_BUCKETS = 64 } |
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 size_t | mempool_bucket (const void *mem, size_t nbuckets) |
| Bucket for an aligned host or device address (power-of-two table). | |
| static void | mempool_grow_table (offload_mempool_t *pool) |
| Grow the address index. Chaining still works if resizing fails. | |
| static void | mempool_register (offload_mempool_t *pool, offload_memchunk_t *chunk, size_t requested) |
| Register a loan and account for the requested and actual chunk sizes. All index operations on the pool use offload_mempool_modify. | |
| static offload_memchunk_t * | mempool_splay (offload_memchunk_t *root, size_t size) |
| Bring an idle capacity (or the last node on its search path) to the root. Top-down splaying needs no parent pointers or recursion. | |
| static void | mempool_cache (offload_mempool_t *pool, offload_memchunk_t *chunk) |
| Insert a returned chunk by its actual capacity. Within a size, the most recently returned chunk is the first one reused or trimmed. | |
| static offload_memchunk_t * | mempool_take_root (offload_mempool_t *pool) |
| Take a chunk from the size currently at the root of the idle tree. | |
| static offload_memchunk_t * | mempool_take_fit (offload_mempool_t *pool, size_t size) |
| Take the smallest idle chunk within the existing reuse tolerance. | |
| static offload_memchunk_t * | internal_mempool_trim (offload_mempool_t *pool) |
| Trim the largest idle chunks after a backend allocation. A cache hit or return only transfers capacity between the idle and live sets. | |
| static void | internal_mempool_release (offload_memchunk_t *release, const bool on_device) |
| Private routine for freeing the chunks taken out of the pool. | |
| 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. | |
| 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 |
| Private pools for host and device memory. | |
| static offload_mempool_t | mempool_device |
| #define OFFLOAD_MEMPOOL_PRINT | ( | FN, | |
| MSG, | |||
| OUTPUT_UNIT ) |
Definition at line 24 of file offload_mempool.c.
| #define OFFLOAD_MEMPOOL_OMPALLOC 1 |
Definition at line 26 of file offload_mempool.c.
| #define OFFLOAD_MEMPOOL_SLACK 4 /* 1/4 */ |
Definition at line 31 of file offload_mempool.c.
| 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.
| anonymous enum |
| Enumerator | |
|---|---|
| MEMPOOL_INITIAL_BUCKETS | |
Definition at line 32 of file offload_mempool.c.
|
inlinestatic |
Returns the larger of two given integer (missing from the C standard).
Definition at line 79 of file offload_mempool.c.
|
static |
Private routine for actually allocating system memory.
Definition at line 85 of file offload_mempool.c.
|
static |
Private routine for actually freeing system memory.
Definition at line 131 of file offload_mempool.c.
|
static |
Bucket for an aligned host or device address (power-of-two table).
Definition at line 173 of file offload_mempool.c.
|
static |
Grow the address index. Chaining still works if resizing fails.
Definition at line 183 of file offload_mempool.c.
|
static |
Register a loan and account for the requested and actual chunk sizes. All index operations on the pool use offload_mempool_modify.
Definition at line 210 of file offload_mempool.c.
|
static |
Bring an idle capacity (or the last node on its search path) to the root. Top-down splaying needs no parent pointers or recursion.
Definition at line 229 of file offload_mempool.c.
|
static |
Insert a returned chunk by its actual capacity. Within a size, the most recently returned chunk is the first one reused or trimmed.
Definition at line 275 of file offload_mempool.c.
|
static |
Take a chunk from the size currently at the root of the idle tree.
Definition at line 305 of file offload_mempool.c.
|
static |
Take the smallest idle chunk within the existing reuse tolerance.
Definition at line 328 of file offload_mempool.c.
|
static |
Trim the largest idle chunks after a backend allocation. A cache hit or return only transfers capacity between the idle and live sets.
Definition at line 356 of file offload_mempool.c.
|
static |
Private routine for freeing the chunks taken out of the pool.
Definition at line 375 of file offload_mempool.c.
|
static |
Private routine for allocating host or device memory from the pool.
Definition at line 389 of file offload_mempool.c.
| void * offload_mempool_host_malloc | ( | const size_t | size | ) |
Internal routine for allocating host memory from the pool.
Definition at line 433 of file offload_mempool.c.
| void * offload_mempool_device_malloc | ( | const size_t | size | ) |
Internal routine for allocating device memory from the pool.
Definition at line 441 of file offload_mempool.c.
|
static |
Private routine for releasing memory back to the pool.
Definition at line 449 of file offload_mempool.c.
| void offload_mempool_host_free | ( | const void * | memory | ) |
Internal routine for releasing memory back to the pool.
Definition at line 475 of file offload_mempool.c.
| void offload_mempool_device_free | ( | const void * | memory | ) |
Internal routine for releasing memory back to the pool.
Definition at line 483 of file offload_mempool.c.
|
static |
Private routine for freeing all memory in the pool.
Definition at line 491 of file offload_mempool.c.
| void offload_mempool_clear | ( | void | ) |
Internal routine for freeing all memory in the pool.
Definition at line 523 of file offload_mempool.c.
| void offload_mempool_stats_get | ( | offload_mempool_stats_t * | memstats | ) |
Internal routine to query statistics.
Definition at line 532 of file offload_mempool.c.
| void offload_mempool_stats_print | ( | int | fortran_comm, |
| void(* | print_func )(const char *, int, int), | ||
| int | output_unit ) |
Print allocation statistics..
Print allocation statistics.
Definition at line 554 of file offload_mempool.c.
|
static |
Private pools for host and device memory.
Definition at line 68 of file offload_mempool.c.
|
static |
Definition at line 71 of file offload_mempool.c.