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 / pool-ops.h
| 1 | #ifndef HTP_POOL_OPS_H |
| 2 | #define HTP_POOL_OPS_H |
| 3 | |
| 4 | #include <stdint.h> |
| 5 | #include <stddef.h> |
| 6 | #include <stdbool.h> |
| 7 | #include <string.h> |
| 8 | |
| 9 | #include "hex-common.h" |
| 10 | #include "htp-vtcm.h" |
| 11 | |
| 12 | enum htp_pool_kernel_type { |
| 13 | HTP_POOL_KERNEL_GENERAL = 0, |
| 14 | HTP_POOL_KERNEL_HVX, |
| 15 | HTP_POOL_KERNEL_HVX_NARROW, |
| 16 | HTP_POOL_KERNEL_GLOBAL, |
| 17 | HTP_POOL_KERNEL_BLOCK, |
| 18 | }; |
| 19 | |
| 20 | struct htp_pool_2d_kernel_params { |
| 21 | uint8_t kernel_type; |
| 22 | uint32_t src_x; |
| 23 | uint32_t src_y; |
| 24 | uint32_t dst_x; |
| 25 | uint32_t dst_y; |
| 26 | uint32_t kernel_x; |
| 27 | uint32_t kernel_y; |
| 28 | uint32_t stride_x; |
| 29 | uint32_t stride_y; |
| 30 | int32_t pad_x; |
| 31 | int32_t pad_y; |
| 32 | uint32_t n_threads; |
| 33 | uint32_t planes; |
| 34 | uint32_t planes_per_chunk; |
| 35 | uint32_t pool_op; |
| 36 | uint32_t avg_divide_count; |
| 37 | uint32_t ox_lo; |
| 38 | uint32_t ox_hi; |
| 39 | float inv_kernel_area; |
| 40 | }; |
| 41 | |
| 42 | #if defined(__cplusplus) |
| 43 | static_assert(sizeof(struct htp_pool_2d_kernel_params) <= 128, "htp_pool_2d_kernel_params is too large"); |
| 44 | #else |
| 45 | _Static_assert(sizeof(struct htp_pool_2d_kernel_params) <= 128, "htp_pool_2d_kernel_params is too large"); |
| 46 | #endif |
| 47 | |
| 48 | struct htp_pool_vtcm_layout { |
| 49 | size_t total_bytes; |
| 50 | size_t off_src; |
| 51 | size_t off_dst; |
| 52 | uint32_t src_plane_bytes; |
| 53 | uint32_t dst_plane_bytes; |
| 54 | size_t src_bytes_per_thread; |
| 55 | size_t dst_bytes_per_thread; |
| 56 | size_t src_spad_half_size; |
| 57 | size_t dst_spad_half_size; |
| 58 | }; |
| 59 | |
| 60 | static inline void htp_pool_vtcm_layout_build( |
| 61 | struct htp_pool_vtcm_layout * L, |
| 62 | uint32_t src_x, |
| 63 | uint32_t src_y, |
| 64 | uint32_t dst_x, |
| 65 | uint32_t dst_y, |
| 66 | uint32_t n_threads |
| 67 | ) { |
| 68 | // Full-plane double buffering (256 bytes guard space for vector loads) |
| 69 | L->src_plane_bytes = src_x * src_y * sizeof(float); |
| 70 | L->dst_plane_bytes = dst_x * dst_y * sizeof(float); |
| 71 | L->src_spad_half_size = hex_round_up(L->src_plane_bytes + 256, 128); |
| 72 | L->dst_spad_half_size = hex_round_up(L->dst_plane_bytes, 128); |
| 73 | L->src_bytes_per_thread = 2 * L->src_spad_half_size; |
| 74 | L->dst_bytes_per_thread = 2 * L->dst_spad_half_size; |
| 75 | |
| 76 | size_t off = 0; |
| 77 | VTCM_LAYOUT_ALLOC(off, off_src, L->src_bytes_per_thread * n_threads); |
| 78 | VTCM_LAYOUT_ALLOC(off, off_dst, L->dst_bytes_per_thread * n_threads); |
| 79 | L->total_bytes = off; |
| 80 | } |
| 81 | |
| 82 | static inline bool htp_pool_solve_layout( |
| 83 | struct htp_pool_vtcm_layout * layout, |
| 84 | uint32_t src_x, |
| 85 | uint32_t src_y, |
| 86 | uint32_t dst_x, |
| 87 | uint32_t dst_y, |
| 88 | uint32_t n_threads, |
| 89 | size_t vtcm_budget |
| 90 | ) { |
| 91 | htp_pool_vtcm_layout_build(layout, src_x, src_y, dst_x, dst_y, n_threads); |
| 92 | return layout->total_bytes <= vtcm_budget; |
| 93 | } |
| 94 | |
| 95 | #endif // HTP_POOL_OPS_H |