okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-own-1a (451f3e8a6): own-stack phase 1A and cleanup 5.4; the ggml/MMQ sources the engines build are vendored in third_party/strata-ggml (frozen at the pin, manifest and check), default engine builds need no llama.cpp download, the TQ overlay is plain files, CMakeLists.txt is split into cmake/backends/*; every engine unchanged (CUDA/HIP gfx1201/gfx1151/SYCL device code identical, SYCL 22/22 checksums, Metal 104/105 objects with only __TIME__ differing, CUDA tokens 26/26); release scripts still pass -DSTRATA_GGML_DIR (owner go 11-08)508e6999a

main
2.0 KiB55 linesraw
1#ifdef GGML_USE_CPU_HBM
2
3#include "ggml-backend.h"
4#include "ggml-backend-impl.h"
5#include "ggml-cpu.h"
6#include "ggml-impl.h"
7
8#include "hbm.h"
9
10// buffer type HBM
11
12#include <hbwmalloc.h>
13
14static const char * ggml_backend_cpu_hbm_buffer_type_get_name(ggml_backend_buffer_type_t buft) {
15    return "CPU_HBM";
16
17    GGML_UNUSED(buft);
18}
19
20static void ggml_backend_cpu_hbm_buffer_free_buffer(ggml_backend_buffer_t buffer) {
21    hbw_free(buffer->context);
22}
23
24static ggml_backend_buffer_t ggml_backend_cpu_hbm_buffer_type_alloc_buffer(ggml_backend_buffer_type_t buft,
25                                                                           size_t                     size) {
26    void * ptr;
27    int    result = hbw_posix_memalign(&ptr, ggml_backend_cpu_buffer_type_get_alignment(buft), size);
28    if (result != 0) {
29        GGML_LOG_ERROR("failed to allocate HBM buffer of size %zu\n", size);
30        return NULL;
31    }
32
33    ggml_backend_buffer_t buffer = ggml_backend_cpu_buffer_from_ptr(ptr, size);
34    buffer->buft                 = buft;
35    buffer->iface.free_buffer    = ggml_backend_cpu_hbm_buffer_free_buffer;
36
37    return buffer;
38}
39
40ggml_backend_buffer_type_t ggml_backend_cpu_hbm_buffer_type(void) {
41    static struct ggml_backend_buffer_type ggml_backend_cpu_buffer_type_hbm = {
42        /* .iface    = */ {
43                           /* .get_name         = */ ggml_backend_cpu_hbm_buffer_type_get_name,
44                           /* .alloc_buffer     = */ ggml_backend_cpu_hbm_buffer_type_alloc_buffer,
45                           /* .get_alignment    = */ ggml_backend_cpu_buffer_type_get_alignment,
46                           /* .get_max_size     = */ nullptr,  // defaults to SIZE_MAX
47                           /* .get_alloc_size   = */ nullptr,  // defaults to ggml_nbytes
48                           /* .is_host          = */ ggml_backend_cpu_buffer_type_is_host,
49                           },
50        /* .context  = */ nullptr,
51    };
52
53    return &ggml_backend_cpu_buffer_type_hbm;
54}
55#endif