ggml
[Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685)
Brought by drakestapleton
ggml / src / ggml-hexagon / htp / get-rows-ops.h
| 1 | #ifndef HTP_GET_ROWS_OPS_H |
| 2 | #define HTP_GET_ROWS_OPS_H |
| 3 | |
| 4 | #include <stdbool.h> |
| 5 | #include <string.h> |
| 6 | |
| 7 | #include "hex-fastdiv.h" |
| 8 | #include "htp-tensor.h" |
| 9 | #include "htp-vtcm.h" |
| 10 | |
| 11 | enum htp_get_rows_kernel_type { |
| 12 | HTP_GET_ROWS_KERNEL_SAMETYPE = 0, |
| 13 | HTP_GET_ROWS_KERNEL_TILED, |
| 14 | HTP_GET_ROWS_KERNEL_FLAT, |
| 15 | }; |
| 16 | |
| 17 | struct htp_get_rows_kernel_params { |
| 18 | uint8_t kernel_type; |
| 19 | uint32_t n_threads; |
| 20 | uint32_t total_tasks; |
| 21 | uint32_t vtcm_size; |
| 22 | |
| 23 | // Fastdiv helpers |
| 24 | struct fastdiv_values div_ne10; |
| 25 | struct fastdiv_values div_ne10_ne11; |
| 26 | struct fastdiv_values div_ne02; |
| 27 | struct fastdiv_values div_ne03; |
| 28 | }; |
| 29 | |
| 30 | struct htp_get_rows_vtcm_layout { |
| 31 | size_t total_bytes; |
| 32 | size_t off_src1; |
| 33 | size_t src1_bytes; |
| 34 | size_t off_src0; |
| 35 | size_t off_dst; |
| 36 | |
| 37 | size_t src0_bytes_per_thread; |
| 38 | size_t dst_bytes_per_thread; |
| 39 | |
| 40 | size_t src0_spad_half_size; |
| 41 | size_t dst_spad_half_size; |
| 42 | }; |
| 43 | |
| 44 | static inline void htp_get_rows_vtcm_layout_build( |
| 45 | struct htp_get_rows_vtcm_layout * L, |
| 46 | int kernel_type, |
| 47 | int type, |
| 48 | uint32_t ne00, |
| 49 | uint32_t total_tasks, |
| 50 | int idx_type, |
| 51 | uint32_t n_threads) { |
| 52 | |
| 53 | memset(L, 0, sizeof(*L)); |
| 54 | |
| 55 | const size_t elem_size = (idx_type == HTP_TYPE_I64) ? sizeof(int64_t) : sizeof(int32_t); |
| 56 | const size_t src1_raw_bytes = total_tasks * elem_size; |
| 57 | const size_t src1_bytes = ((src1_raw_bytes + 127) & ~127) + 128; |
| 58 | |
| 59 | L->src1_bytes = src1_bytes; |
| 60 | const size_t src1_alloc_bytes = (src1_bytes + 255) & ~255; |
| 61 | |
| 62 | if (kernel_type != HTP_GET_ROWS_KERNEL_SAMETYPE) { |
| 63 | size_t src0_row_size = 0; |
| 64 | if (kernel_type == HTP_GET_ROWS_KERNEL_TILED) { |
| 65 | const size_t tile_stride = htp_tensor_get_tile_padded_size(type); |
| 66 | const uint32_t n_k_tiles = ne00 / htp_tensor_get_tile_k(type); |
| 67 | src0_row_size = n_k_tiles > 0 ? (n_k_tiles * tile_stride) : tile_stride; |
| 68 | } else { |
| 69 | src0_row_size = htp_tensor_get_row_size(type, ne00); |
| 70 | } |
| 71 | |
| 72 | L->src0_spad_half_size = (src0_row_size + 255) & ~255; |
| 73 | L->dst_spad_half_size = (ne00 * sizeof(float) + 255) & ~255; |
| 74 | L->src0_bytes_per_thread = 2 * L->src0_spad_half_size; |
| 75 | L->dst_bytes_per_thread = 2 * L->dst_spad_half_size; |
| 76 | } |
| 77 | |
| 78 | size_t off = 0; |
| 79 | VTCM_LAYOUT_ALLOC(off, off_src1, src1_alloc_bytes); |
| 80 | VTCM_LAYOUT_ALLOC(off, off_src0, L->src0_bytes_per_thread * n_threads); |
| 81 | VTCM_LAYOUT_ALLOC(off, off_dst, L->dst_bytes_per_thread * n_threads); |
| 82 | L->total_bytes = off; |
| 83 | } |
| 84 | |
| 85 | #if defined(__cplusplus) |
| 86 | static_assert(sizeof(struct htp_get_rows_kernel_params) <= 128, "htp_get_rows_kernel_params is too large for kernel_params blob"); |
| 87 | #else |
| 88 | _Static_assert(sizeof(struct htp_get_rows_kernel_params) <= 128, "htp_get_rows_kernel_params is too large for kernel_params blob"); |
| 89 | #endif |
| 90 | |
| 91 | #endif // HTP_GET_ROWS_OPS_H |