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/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-cpu / common.h` 109 lines ยท 2742 bytes Raw Blame History 1 #pragma once 2 3 #include "ggml.h" 4 #include "traits.h" 5 #include "ggml-cpu-impl.h" 6 #include "ggml-impl.h" 7 #include "simd-mappings.h" 8 9 #define GGML_FA_TILE_Q 64 10 #define GGML_FA_TILE_KV 64 11 12 #ifdef __cplusplus 13 14 #include 15 16 // convenience functions/macros for use in template calls 17 // note: these won't be required after the 'traits' lookup table is used. 18 static inline ggml_fp16_t f32_to_f16(float x) { 19 return GGML_CPU_FP32_TO_FP16(x); 20 } 21 22 static inline float f16_to_f32(ggml_fp16_t x) { 23 return GGML_CPU_FP16_TO_FP32(x); 24 } 25 26 static inline ggml_bf16_t f32_to_bf16(float x) { 27 return GGML_FP32_TO_BF16(x); 28 } 29 30 static inline float bf16_to_f32(ggml_bf16_t x) { 31 return GGML_BF16_TO_FP32(x); 32 } 33 34 static inline float i32_to_f32(int32_t x) { 35 return x; 36 } 37 38 static inline int32_t f32_to_i32(float x) { 39 return x; 40 } 41 42 static inline float f32_to_f32(float x) { 43 return x; 44 } 45 46 static inline float f8_e4m3_to_f32(ggml_fp8_e4m3_t x) { 47 return ggml_f8_e4m3_to_fp32(x.bits); 48 } 49 50 static inline ggml_fp8_e4m3_t f32_to_f8_e4m3(float x) { 51 return { ggml_fp32_to_f8_e4m3(x) }; 52 } 53 54 // TODO - merge this into the traits table, after using row-based conversions 55 template 56 struct type_conversion_table; 57 58 template <> 59 struct type_conversion_table { 60 static constexpr float (*to_f32)(ggml_fp16_t) = f16_to_f32; 61 static constexpr ggml_fp16_t (*from_f32)(float) = f32_to_f16; 62 }; 63 64 template <> 65 struct type_conversion_table { 66 static constexpr float (*to_f32)(float) = f32_to_f32; 67 static constexpr float (*from_f32)(float) = f32_to_f32; 68 }; 69 70 template <> 71 struct type_conversion_table { 72 static constexpr float (*to_f32)(ggml_bf16_t) = bf16_to_f32; 73 static constexpr ggml_bf16_t (*from_f32)(float) = f32_to_bf16; 74 }; 75 76 template <> 77 struct type_conversion_table { 78 static constexpr float (*to_f32)(ggml_fp8_e4m3_t) = f8_e4m3_to_f32; 79 static constexpr ggml_fp8_e4m3_t (*from_f32)(float) = f32_to_f8_e4m3; 80 }; 81 82 template <> 83 struct type_conversion_table { 84 static constexpr float (*to_f32)(int32_t) = i32_to_f32; 85 static constexpr int32_t (*from_f32)(float) = f32_to_i32; 86 }; 87 88 static std::pair get_thread_range(const struct ggml_compute_params * params, const struct ggml_tensor * src0) { 89 const int64_t ith = params->ith; 90 const int64_t nth = params->nth; 91 92 const int64_t nr = ggml_nrows(src0); 93 94 // rows per thread 95 const int64_t dr = (nr + nth - 1)/nth; 96 97 // row range for this thread 98 const int64_t ir0 = dr*ith; 99 const int64_t ir1 = MIN(ir0 + dr, nr); 100 101 return {ir0, ir1}; 102 } 103 104 struct ggml_fa_tile_config { 105 static constexpr size_t Q = GGML_FA_TILE_Q; 106 static constexpr size_t KV = GGML_FA_TILE_KV; 107 }; 108 109 #endif