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-metal/ggml-metal-common.h # 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-metal / ggml-metal-common.h` 73 lines ยท 3054 bytes Raw Blame History 1 // helper functions for ggml-metal that are too difficult to implement in Objective-C 2 3 #pragma once 4 5 #include "ggml.h" 6 7 #include 8 #include 9 10 #ifdef __cplusplus 11 extern "C" { 12 #endif 13 14 struct ggml_tensor; 15 struct ggml_cgraph; 16 17 enum ggml_mem_range_type { 18 MEM_RANGE_TYPE_SRC = 0, 19 MEM_RANGE_TYPE_DST = 1, 20 }; 21 22 // a helper object that can be used for reordering operations to improve concurrency 23 // 24 // the fundamental idea is that a set of tasks (either ggml ops, or something else) can run concurrently if they 25 // don't write to a memory that is being read by another task or written to by another task in the set 26 // 27 // with this structure, we can add tasks to the set, setting memory constraints. we can also check if a new task 28 // can be added to the set without violating the constraints (i.e. if it can be executed concurrently with the 29 // tasks already in the set) 30 // 31 typedef struct ggml_mem_ranges * ggml_mem_ranges_t; 32 33 ggml_mem_ranges_t ggml_mem_ranges_init(int debug); 34 void ggml_mem_ranges_free(ggml_mem_ranges_t mrs); 35 36 // remove all ranges from the set 37 void ggml_mem_ranges_reset(ggml_mem_ranges_t mrs); 38 39 // add src or dst ranges to track 40 bool ggml_mem_ranges_add(ggml_mem_ranges_t mrs, const struct ggml_tensor * tensor); 41 42 // return false if: 43 // - new src range overlaps with any existing dst range 44 // - new dst range overlaps with any existing range (src or dst) 45 bool ggml_mem_ranges_check(ggml_mem_ranges_t mrs, const struct ggml_tensor * tensor); 46 47 // reorder the nodes in the graph to improve concurrency, while respecting the fusions of a device with props 48 // 49 // note: this implementation is generic and not specific to metal 50 // if it proves to work well, we can start using it for other backends in the future 51 void ggml_graph_optimize(struct ggml_cgraph * gf); 52 53 // mat-mat vs mat-vec dispatch; used by both supports_op and ggml_metal_op_mul_mat* 54 bool ggml_metal_op_mul_mat_use_fwht (const struct ggml_tensor * op, size_t max_tg_mem); 55 bool ggml_metal_op_mul_mat_use_mm (const struct ggml_tensor * op, bool has_simdgroup_mm); 56 bool ggml_metal_op_mul_mat_id_use_mm(const struct ggml_tensor * op, bool has_simdgroup_mm); 57 58 bool ggml_metal_op_mul_mat_use_mma (const struct ggml_tensor * op); 59 bool ggml_metal_op_mul_mat_may_use_mma(const struct ggml_tensor * op); // graph structure only 60 61 // the few-row MMA kernel for a src0 type and rt src1 tiles: per 32-weight block (q4_0, q8_0 with one tile), q5_K, or the generic 64-weight chunk kernel 62 enum ggml_metal_mma_kind { GGML_METAL_MMA_KIND_BLK, GGML_METAL_MMA_KIND_Q5_K, GGML_METAL_MMA_KIND_GEN }; 63 enum ggml_metal_mma_kind ggml_metal_mul_mv_mma_kind(enum ggml_type type, int rt); 64 65 // the src1 tiles of the few-row MMA kernels for mat-mul op: one 8-row tile, or two above 8 rows 66 int ggml_metal_mul_mv_mma_rt(const struct ggml_tensor * op); 67 68 // the weights of K per simdgroup step of the few-row MMA kernel for a src0 type and rt src1 tiles, 0 if none takes the type 69 int64_t ggml_metal_mul_mv_mma_k_step(enum ggml_type type, int rt); 70 71 #ifdef __cplusplus 72 } 73 #endif