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/spacemit/rvv_kernels.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 / spacemit / rvv_kernels.h` 95 lines ยท 4380 bytes Raw Blame History 1 #pragma once 2 3 #include "ggml-cpu-impl.h" 4 5 #include 6 #include 7 #include 8 #include 9 10 namespace spacemit_kernels { 11 12 constexpr auto div_round_up(auto up, auto down) { 13 return (up + down - 1) / down; 14 } 15 16 // Q8 Blk [f32] [s16] [int8 * blk_len] 17 // Q8 Blk N [f32 * N] [s16 * N] [int8 * blk_len * N] 18 constexpr size_t q8_blk_size(size_t blk_len, bool with_blk_sum = false) { 19 const size_t blk_size = sizeof(float) + blk_len * sizeof(int8_t) + (with_blk_sum ? sizeof(int16_t) : 0); 20 return blk_size; 21 } 22 23 // Q8 HP row block: K is split into K32 subblocks. 24 // Each subblock stores [f32 scale] [int8 * 32], with an optional fp16 sum trailer per subblock. 25 constexpr size_t q8_hp_blk_size(size_t blk_len, bool with_blk_sum = false, bool with_blk_scale = false) { 26 const size_t subblk_count = div_round_up(blk_len, size_t(32)); 27 const size_t blk_size = blk_len * sizeof(int8_t) + subblk_count * sizeof(_Float16) + 28 (with_blk_sum ? subblk_count * sizeof(_Float16) : 0) + 29 (with_blk_scale ? sizeof(_Float16) : 0); 30 return blk_size; 31 } 32 33 // Q8K Blk [f32] [s16 * (blk_len / 16)] [int8 * blk_len] 34 // Q8K Blk N [f32 * N] [s16 * (blk_len / 16) * N] [int8 * blk_len * N] 35 constexpr size_t q8k_blk_size(size_t blk_len) { 36 const size_t blk_size = sizeof(float) + blk_len * sizeof(int8_t) + sizeof(int16_t) * blk_len / 16; 37 return blk_size; 38 } 39 40 using quantize_a_row_def = std::function; 41 42 namespace rvv { 43 void memcpy1d(void * dst, const void * src, int64_t size); 44 45 void memcpy2d(void * dst, int64_t dst_stride, const void * src, int64_t src_stride, int64_t tile_rows, int64_t size); 46 47 void forward_flash_attn_ext_f16_one_chunk_vlen1024_vf16(const ggml_compute_params * params, 48 ggml_tensor * dst, 49 int ir0, 50 int ir1, 51 void * tcm_buffer, 52 size_t tcm_buffer_size); 53 54 void forward_flash_attn_ext_f16_tiled_vlen1024_vf16(const ggml_compute_params * params, 55 ggml_tensor * dst, 56 int ir0, 57 int ir1, 58 void * tcm_buffer, 59 size_t tcm_buffer_size); 60 61 void forward_rms_norm_f32(ggml_compute_params * params, ggml_tensor * op); 62 63 void forward_norm_f32(ggml_compute_params * params, ggml_tensor * op); 64 65 void forward_cont_with_permute(ggml_compute_params * params, ggml_tensor * op); 66 67 void forward_cpy_with_permute(ggml_compute_params * params, ggml_tensor * op); 68 69 template void forward_get_rows(ggml_compute_params * params, ggml_tensor * op); 70 71 template void forward_concat(ggml_compute_params * params, ggml_tensor * op); 72 73 template void forward_binary(ggml_compute_params * params, ggml_tensor * op); 74 75 template void forward_sum_rows(const ggml_compute_params * params, ggml_tensor * op); 76 77 template void forward_repeat_nrows(ggml_compute_params * params, ggml_tensor * op); 78 79 template void forward_repeat_dim1(ggml_compute_params * params, ggml_tensor * op); 80 81 void quantize_a_row_i8(size_t blk_len, const float * a_ptr, size_t count_k, uint8_t * quant_a_ptr); 82 83 void quantize_a_4row_i8(size_t blk_len, const float * a_ptr, size_t count_k, uint8_t * quant_a_ptr); 84 85 void quantize_a_row_i8_hp(size_t blk_len, const float * a_ptr, size_t count_k, uint8_t * quant_a_ptr); 86 87 void quantize_a_4row_i8_hp(size_t blk_len, const float * a_ptr, size_t count_k, uint8_t * quant_a_ptr); 88 89 void quantize_a_row_i8k(size_t blk_len, const float * a_ptr, size_t count_k, uint8_t * quant_a_ptr); 90 91 void quantize_a_4row_i8k(size_t blk_len, const float * a_ptr, size_t count_k, uint8_t * quant_a_ptr); 92 93 } // namespace rvv 94 95 } // namespace spacemit_kernels