← 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 read-only from weights.bump and the runtime region is anonymous
48 * writable memory, while preserving one contiguous virtual address space.
49 * Mixed mode is for inference only: callers that update weights must request
50 * an anonymous writable allocation instead.
51 */
53 const char *weights_path,
54 size_t total_size,
55 size_t weights_base,
56 size_t activations_base);
57
58/*
59 * Release a logical bump arena previously initialized by ck_bump_alloc_init().
60 */
62
63/*
64 * Return non-zero when weights still need to be copied into RAM.
65 */
67
68#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