diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-02-12 20:57:17 +0100 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-02-12 20:57:17 +0100 |
| commit | b333b06772c89d96aacb5490d6a219fba7c09cc6 (patch) | |
| tree | 211df60083a5946baa2ed61d33d8121b7e251b06 /llama.cpp/ggml/src/ggml-metal/ggml-metal-common.h | |
| download | llmnpc-b333b06772c89d96aacb5490d6a219fba7c09cc6.tar.gz | |
Engage!
Diffstat (limited to 'llama.cpp/ggml/src/ggml-metal/ggml-metal-common.h')
| -rw-r--r-- | llama.cpp/ggml/src/ggml-metal/ggml-metal-common.h | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/llama.cpp/ggml/src/ggml-metal/ggml-metal-common.h b/llama.cpp/ggml/src/ggml-metal/ggml-metal-common.h new file mode 100644 index 0000000..3acbc6a --- /dev/null +++ b/llama.cpp/ggml/src/ggml-metal/ggml-metal-common.h | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | // helper functions for ggml-metal that are too difficult to implement in Objective-C | ||
| 2 | |||
| 3 | #pragma once | ||
| 4 | |||
| 5 | #include <stdbool.h> | ||
| 6 | |||
| 7 | #ifdef __cplusplus | ||
| 8 | extern "C" { | ||
| 9 | #endif | ||
| 10 | |||
| 11 | struct ggml_tensor; | ||
| 12 | struct ggml_cgraph; | ||
| 13 | |||
| 14 | enum ggml_mem_range_type { | ||
| 15 | MEM_RANGE_TYPE_SRC = 0, | ||
| 16 | MEM_RANGE_TYPE_DST = 1, | ||
| 17 | }; | ||
| 18 | |||
| 19 | // a helper object that can be used for reordering operations to improve concurrency | ||
| 20 | // | ||
| 21 | // the fundamental idea is that a set of tasks (either ggml ops, or something else) can run concurrently if they | ||
| 22 | // don't write to a memory that is being read by another task or written to by another task in the set | ||
| 23 | // | ||
| 24 | // with this structure, we can add tasks to the set, setting memory constraints. we can also check if a new task | ||
| 25 | // can be added to the set without violating the constraints (i.e. if it can be executed concurrently with the | ||
| 26 | // tasks already in the set) | ||
| 27 | // | ||
| 28 | typedef struct ggml_mem_ranges * ggml_mem_ranges_t; | ||
| 29 | |||
| 30 | ggml_mem_ranges_t ggml_mem_ranges_init(int debug); | ||
| 31 | void ggml_mem_ranges_free(ggml_mem_ranges_t mrs); | ||
| 32 | |||
| 33 | // remove all ranges from the set | ||
| 34 | void ggml_mem_ranges_reset(ggml_mem_ranges_t mrs); | ||
| 35 | |||
| 36 | // add src or dst ranges to track | ||
| 37 | bool ggml_mem_ranges_add(ggml_mem_ranges_t mrs, const struct ggml_tensor * tensor); | ||
| 38 | |||
| 39 | // return false if: | ||
| 40 | // - new src range overlaps with any existing dst range | ||
| 41 | // - new dst range overlaps with any existing range (src or dst) | ||
| 42 | bool ggml_mem_ranges_check(ggml_mem_ranges_t mrs, const struct ggml_tensor * tensor); | ||
| 43 | |||
| 44 | // reorder the nodes in the graph to improve concurrency, while respecting fusion | ||
| 45 | // | ||
| 46 | // note: this implementation is generic and not specific to metal | ||
| 47 | // if it proves to work well, we can start using it for other backends in the future | ||
| 48 | void ggml_graph_optimize(struct ggml_cgraph * gf); | ||
| 49 | |||
| 50 | #ifdef __cplusplus | ||
| 51 | } | ||
| 52 | #endif | ||
