← Back to C-Kernel-Engine Docs Doxygen Source Documentation
 
Loading...
Searching...
No Matches
ckernel_alloc.h
Go to the documentation of this file.
1#ifndef CKERNEL_ALLOC_H
2#define CKERNEL_ALLOC_H
3
4#include <stddef.h>
5#include <stdint.h>
6
7/**
8 * Allocate a large, contiguous memory region for model weights/activations.
9 *
10 * Implementation strategy:
11 * - Try to allocate 2MB-aligned memory backed by huge pages where possible.
12 * - Fall back to aligned_alloc + madvise(MADV_HUGEPAGE) when explicit
13 * huge pages are not available.
14 *
15 * Returns NULL on failure.
16 */
17void *ck_huge_alloc(size_t bytes);
18
19/**
20 * Free memory allocated by ck_huge_alloc.
21 *
22 * The bytes parameter should be the same size passed to ck_huge_alloc.
23 */
24void ck_huge_free(void *ptr, size_t bytes);
25
31
41
42/*
43 * Initialize a logical bump arena.
44 *
45 * The allocator first tries the existing anonymous DRAM path. On Linux, if that
46 * fails, it can fall back to a mixed-backed arena where the weights region is
47 * file-backed from weights.bump and the runtime region is anonymous memory,
48 * while preserving one contiguous virtual address space.
49 */
51 const char *weights_path,
52 size_t total_size,
53 size_t weights_base,
54 size_t activations_base);
55
56/*
57 * Release a logical bump arena previously initialized by ck_bump_alloc_init().
58 */
60
61/*
62 * Return non-zero when weights still need to be copied into RAM.
63 */
65
66#endif /* CKERNEL_ALLOC_H */
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)
ck_bump_mode_t
@ CK_BUMP_MODE_ANON
@ CK_BUMP_MODE_MIXED_FILE_BACKED
@ CK_BUMP_MODE_UNINITIALIZED
void * ck_huge_alloc(size_t bytes)
void ck_huge_free(void *ptr, size_t bytes)
int ck_bump_alloc_needs_weight_materialization(const ck_bump_alloc_t *alloc)
size_t activations_base
size_t weights_file_size
ck_bump_mode_t mode