#include "ckernel_alloc.h"#include <errno.h>#include <fcntl.h>#include <pthread.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <strings.h>#include <sys/mman.h>#include <sys/stat.h>#include <sys/types.h>#include <unistd.h>Go to the source code of this file.
Macros | |
| #define | _GNU_SOURCE |
| #define | HUGE_PAGE_SIZE (2UL * 1024UL * 1024UL) |
Functions | |
| static size_t | align_up_bytes (size_t n, size_t align) |
| void | ck_bump_alloc_free (ck_bump_alloc_t *alloc) |
| int | ck_bump_alloc_init (ck_bump_alloc_t *alloc, const char *weights_path, size_t total_size, size_t weights_base, size_t activations_base) |
| int | ck_bump_alloc_needs_weight_materialization (const ck_bump_alloc_t *alloc) |
| static void | ck_bump_alloc_reset (ck_bump_alloc_t *alloc) |
| void * | ck_huge_alloc (size_t bytes) |
| void | ck_huge_free (void *ptr, size_t bytes) |
| static ck_huge_alloc_entry_t * | detach_allocation (void *ptr) |
| static int | env_flag_enabled (const char *name) |
| static int | record_allocation (void *ptr, size_t len, int was_mmap) |
Variables | |
| static ck_huge_alloc_entry_t * | g_alloc_list = NULL |
| static pthread_mutex_t | g_alloc_mutex = PTHREAD_MUTEX_INITIALIZER |
| #define _GNU_SOURCE |
Definition at line 1 of file ckernel_alloc.c.
| #define HUGE_PAGE_SIZE (2UL * 1024UL * 1024UL) |
Definition at line 18 of file ckernel_alloc.c.
|
static |
Definition at line 31 of file ckernel_alloc.c.
Referenced by ck_bump_alloc_init(), and ck_huge_alloc().
| void ck_bump_alloc_free | ( | ck_bump_alloc_t * | alloc | ) |
Definition at line 313 of file ckernel_alloc.c.
References ck_bump_alloc_t::base, ck_bump_alloc_reset(), CK_BUMP_MODE_ANON, CK_BUMP_MODE_MIXED_FILE_BACKED, ck_huge_free(), ck_bump_alloc_t::mapped_len, ck_bump_alloc_t::mode, and ck_bump_alloc_t::total_size.
| int ck_bump_alloc_init | ( | ck_bump_alloc_t * | alloc, |
| const char * | weights_path, | ||
| size_t | total_size, | ||
| size_t | weights_base, | ||
| size_t | activations_base | ||
| ) |
Definition at line 257 of file ckernel_alloc.c.
References ck_bump_alloc_t::activations_base, align_up_bytes(), ck_bump_alloc_t::base, ck_bump_alloc_reset(), CK_BUMP_MODE_ANON, ck_huge_alloc(), env_flag_enabled(), HUGE_PAGE_SIZE, ck_bump_alloc_t::mapped_len, ck_bump_alloc_t::mode, ck_bump_alloc_t::total_size, and ck_bump_alloc_t::weights_base.
| int ck_bump_alloc_needs_weight_materialization | ( | const ck_bump_alloc_t * | alloc | ) |
Definition at line 331 of file ckernel_alloc.c.
References CK_BUMP_MODE_MIXED_FILE_BACKED, and ck_bump_alloc_t::mode.
|
static |
Definition at line 138 of file ckernel_alloc.c.
References ck_bump_alloc_t::activations_base, ck_bump_alloc_t::base, CK_BUMP_MODE_UNINITIALIZED, ck_bump_alloc_t::mapped_len, ck_bump_alloc_t::mode, ck_bump_alloc_t::total_size, ck_bump_alloc_t::weights_base, and ck_bump_alloc_t::weights_file_size.
Referenced by ck_bump_alloc_free(), and ck_bump_alloc_init().
| void * ck_huge_alloc | ( | size_t | bytes | ) |
Allocate a large, contiguous memory region for model weights/activations.
Implementation strategy:
Returns NULL on failure.
Definition at line 70 of file ckernel_alloc.c.
Referenced by ck_bump_alloc_init().
| void ck_huge_free | ( | void * | ptr, |
| size_t | bytes | ||
| ) |
Free memory allocated by ck_huge_alloc.
The bytes parameter should be the same size passed to ck_huge_alloc.
Definition at line 104 of file ckernel_alloc.c.
Referenced by ck_bump_alloc_free().
|
static |
Definition at line 53 of file ckernel_alloc.c.
References g_alloc_list, and g_alloc_mutex.
Referenced by ck_huge_free().
|
static |
Definition at line 126 of file ckernel_alloc.c.
Referenced by ck_bump_alloc_init().
|
static |
Definition at line 37 of file ckernel_alloc.c.
References g_alloc_list, and g_alloc_mutex.
Referenced by ck_huge_alloc().
|
static |
Definition at line 29 of file ckernel_alloc.c.
Referenced by detach_allocation(), and record_allocation().
|
static |
Definition at line 28 of file ckernel_alloc.c.
Referenced by detach_allocation(), and record_allocation().