Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/ggml/blob/master/src/ggml-cpu/hbm.cpp # ggml [Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685) Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `ggml / src / ggml-cpu / hbm.cpp` 57 lines ยท 2156 bytes Raw Blame History 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 13 14 static 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 20 static void ggml_backend_cpu_hbm_buffer_free_buffer(ggml_backend_buffer_t buffer) { 21 hbw_free(buffer->context); 22 } 23 24 static 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 40 ggml_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 /* .alloc_buffer_n = */ nullptr, 46 /* .get_alignment = */ ggml_backend_cpu_buffer_type_get_alignment, 47 /* .get_max_size = */ nullptr, // defaults to SIZE_MAX 48 /* .get_alloc_size = */ nullptr, // defaults to ggml_nbytes 49 /* .get_alloc_size_n = */ NULL, 50 /* .is_host = */ ggml_backend_cpu_buffer_type_is_host, 51 }, 52 /* .context = */ nullptr, 53 }; 54 55 return &ggml_backend_cpu_buffer_type_hbm; 56 } 57 #endif