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-hexagon/htp/im2col-ops.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-hexagon / htp / im2col-ops.h` 81 lines ยท 2362 bytes Raw Blame History 1 #ifndef HTP_IM2COL_OPS_H 2 #define HTP_IM2COL_OPS_H 3 4 #include "hex-common.h" 5 #include "hex-fastdiv.h" 6 #include "htp-vtcm.h" 7 #include 8 9 enum htp_im2col_kernel_type { 10 HTP_IM2COL_KERNEL_UNSUPPORTED = 0, 11 HTP_IM2COL_KERNEL_PATCHEMBED_DMA = 1, 12 HTP_IM2COL_KERNEL_BLOCKED_DMA = 2, 13 }; 14 15 struct htp_im2col_vtcm_layout { 16 size_t total_bytes; 17 size_t off_src; 18 size_t off_dst; 19 uint32_t src_bytes_per_thread; 20 uint32_t dst_bytes_per_thread; 21 }; 22 23 // scratch_bytes: per-thread VTCM after the two src buffers (at least 256) 24 static inline void htp_im2col_vtcm_layout_build( 25 struct htp_im2col_vtcm_layout * L, 26 uint32_t src_row_bytes, 27 uint32_t dst_row_bytes, 28 uint32_t n_threads, 29 uint32_t scratch_bytes) { 30 31 L->src_bytes_per_thread = 2 * src_row_bytes + (scratch_bytes > 256 ? scratch_bytes : 256); 32 L->dst_bytes_per_thread = 2 * dst_row_bytes; 33 34 size_t off = 0; 35 VTCM_LAYOUT_ALLOC(off, off_src, (size_t) L->src_bytes_per_thread * n_threads); 36 VTCM_LAYOUT_ALLOC(off, off_dst, (size_t) L->dst_bytes_per_thread * n_threads); 37 L->total_bytes = off; 38 } 39 40 // per-thread scratch: the KH == 1 blocked path keeps its offset table and one gathered row there, 41 // both padded to whole vectors 42 static inline uint32_t htp_im2col_scratch_bytes(uint32_t kernel_type, uint32_t KH, uint32_t patch_stride) { 43 if (kernel_type == HTP_IM2COL_KERNEL_BLOCKED_DMA && KH == 1) { 44 return 2 * hex_round_up(patch_stride, 32) * (uint32_t) sizeof(float); 45 } 46 return 256; 47 } 48 49 struct htp_im2col_kernel_params { 50 uint8_t kernel_type; 51 uint8_t n_threads; 52 53 uint32_t vtcm_size; 54 uint32_t src_row_bytes; 55 uint32_t dst_row_bytes; 56 57 uint32_t owb; 58 uint32_t wb; 59 uint32_t nbpr; 60 61 uint32_t N; 62 uint32_t IC; 63 uint32_t ID, IH, IW; 64 uint32_t KD, KH, KW; 65 uint32_t OD, OH, OW; 66 uint32_t patch_stride; 67 uint32_t total_rows; 68 uint32_t rows_per_chunk; 69 70 struct fastdiv_values div_OH; 71 struct fastdiv_values div_OD; 72 struct fastdiv_values div_nbpr; 73 }; 74 75 #if defined(__cplusplus) 76 static_assert(sizeof(struct htp_im2col_kernel_params) <= 128, "htp_im2col_kernel_params is too large for kernel_params blob"); 77 #else 78 _Static_assert(sizeof(struct htp_im2col_kernel_params) <= 128, "htp_im2col_kernel_params is too large for kernel_params blob"); 79 #endif 80 81 #endif // HTP_IM2COL_OPS_H