char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

QuintinShawmetal : fix null-pipeline crash for F16 src1 mul_mat/mul_mat_id (#25648)d882575cc

char/aliceai-t5-moe
2.0 KiB56 linesraw
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
8extern "C" {
9#endif
10
11struct ggml_tensor;
12struct ggml_cgraph;
13
14enum 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//
28typedef struct ggml_mem_ranges * ggml_mem_ranges_t;
29
30ggml_mem_ranges_t ggml_mem_ranges_init(int debug);
31void ggml_mem_ranges_free(ggml_mem_ranges_t mrs);
32
33// remove all ranges from the set
34void ggml_mem_ranges_reset(ggml_mem_ranges_t mrs);
35
36// add src or dst ranges to track
37bool 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)
42bool 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
48void ggml_graph_optimize(struct ggml_cgraph * gf);
49
50// mat-mat vs mat-vec dispatch; used by both supports_op and ggml_metal_op_mul_mat*
51bool ggml_metal_op_mul_mat_use_mm   (const struct ggml_tensor * op, bool has_simdgroup_mm);
52bool ggml_metal_op_mul_mat_id_use_mm(const struct ggml_tensor * op, bool has_simdgroup_mm);
53
54#ifdef __cplusplus
55}
56#endif