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 / htp-ops.h
| 1 | #ifndef HTP_OPS_H |
| 2 | #define HTP_OPS_H |
| 3 | |
| 4 | #include <assert.h> |
| 5 | |
| 6 | // ggml-common.h must be included prio to this header |
| 7 | |
| 8 | enum htp_status { |
| 9 | HTP_STATUS_OK = 1, |
| 10 | HTP_STATUS_INTERNAL_ERR = 2, |
| 11 | HTP_STATUS_NO_SUPPORT = 3, |
| 12 | HTP_STATUS_INVAL_PARAMS = 4, |
| 13 | HTP_STATUS_VTCM_TOO_SMALL = 5, |
| 14 | }; |
| 15 | |
| 16 | // First set of values must match the ggml_type. |
| 17 | // Duplicated here because we can't include full ggml.h in the htp build. |
| 18 | // We have some static_asserts in the cpp code to ensure things are in sync. |
| 19 | enum htp_data_type { |
| 20 | HTP_TYPE_F32 = 0, |
| 21 | HTP_TYPE_F16 = 1, |
| 22 | HTP_TYPE_Q4_0 = 2, |
| 23 | HTP_TYPE_Q4_1 = 3, |
| 24 | HTP_TYPE_Q8_0 = 8, |
| 25 | HTP_TYPE_Q2_K = 10, |
| 26 | HTP_TYPE_Q3_K = 11, |
| 27 | HTP_TYPE_Q4_K = 12, |
| 28 | HTP_TYPE_Q5_K = 13, |
| 29 | HTP_TYPE_Q6_K = 14, |
| 30 | HTP_TYPE_IQ4_NL = 20, |
| 31 | HTP_TYPE_I32 = 26, |
| 32 | HTP_TYPE_I64 = 27, |
| 33 | HTP_TYPE_BF16 = 30, |
| 34 | HTP_TYPE_MXFP4 = 39, |
| 35 | HTP_TYPE_Q1_0 = 41, |
| 36 | HTP_TYPE_Q2_0 = 42, |
| 37 | |
| 38 | HTP_TYPE_INVALID |
| 39 | }; |
| 40 | |
| 41 | // Do not reorder first 4 (used as an index) |
| 42 | enum htp_op_code { |
| 43 | HTP_OP_MUL = 0, |
| 44 | HTP_OP_ADD = 1, |
| 45 | HTP_OP_SUB = 2, |
| 46 | HTP_OP_DIV = 3, |
| 47 | HTP_OP_MUL_MAT, |
| 48 | HTP_OP_MUL_MAT_ID, |
| 49 | HTP_OP_MUL_MAT_NX, |
| 50 | HTP_OP_MUL_MAT_ID_NX, |
| 51 | HTP_OP_MUL_MAT_ADD, |
| 52 | HTP_OP_RMS_NORM, |
| 53 | HTP_OP_RMS_NORM_MUL, |
| 54 | HTP_OP_UNARY_SILU, |
| 55 | HTP_OP_UNARY_GELU, |
| 56 | HTP_OP_UNARY_SIGMOID, |
| 57 | HTP_OP_UNARY_EXP, |
| 58 | HTP_OP_UNARY_NEG, |
| 59 | HTP_OP_UNARY_SOFTPLUS, |
| 60 | HTP_OP_UNARY_TANH, |
| 61 | HTP_OP_UNARY_ABS, |
| 62 | HTP_OP_UNARY_LOG, |
| 63 | HTP_OP_UNARY_RELU, |
| 64 | HTP_OP_UNARY_STEP, |
| 65 | HTP_OP_GLU_SWIGLU, |
| 66 | HTP_OP_GLU_SWIGLU_OAI, |
| 67 | HTP_OP_GLU_GEGLU, |
| 68 | HTP_OP_GLU_GEGLU_QUICK, |
| 69 | HTP_OP_SOFTMAX, |
| 70 | HTP_OP_ADD_ID, |
| 71 | HTP_OP_ROPE, |
| 72 | HTP_OP_FLASH_ATTN_EXT, |
| 73 | HTP_OP_SET_ROWS, |
| 74 | HTP_OP_GET_ROWS, |
| 75 | HTP_OP_SCALE, |
| 76 | HTP_OP_CPY, |
| 77 | HTP_OP_CPY_FENCE, |
| 78 | HTP_OP_ARGSORT, |
| 79 | HTP_OP_TOP_K, |
| 80 | HTP_OP_SQR, |
| 81 | HTP_OP_SQRT, |
| 82 | HTP_OP_SUM, |
| 83 | HTP_OP_SUM_ROWS, |
| 84 | HTP_OP_SSM_CONV, |
| 85 | HTP_OP_REPEAT, |
| 86 | HTP_OP_CUMSUM, |
| 87 | HTP_OP_FILL, |
| 88 | HTP_OP_DIAG, |
| 89 | HTP_OP_SOLVE_TRI, |
| 90 | HTP_OP_L2_NORM, |
| 91 | HTP_OP_GATED_DELTA_NET, |
| 92 | HTP_OP_TRI, |
| 93 | HTP_OP_PAD, |
| 94 | HTP_OP_NORM, |
| 95 | HTP_OP_CONCAT, |
| 96 | HTP_OP_CLAMP, |
| 97 | HTP_OP_LEAKY_RELU, |
| 98 | HTP_OP_IM2COL, |
| 99 | HTP_OP_CONV_2D, |
| 100 | HTP_OP_CONV_2D_DW, |
| 101 | HTP_OP_FENCE, |
| 102 | HTP_OP_ALLREDUCE, |
| 103 | HTP_OP_ALLREDUCE_ADD, |
| 104 | HTP_OP_GLU_SWIGLU_CLAMP, |
| 105 | HTP_OP_MDEV_GROUP, |
| 106 | HTP_OP_ROLL, |
| 107 | HTP_OP_ARGMAX, |
| 108 | HTP_OP_UNARY_GELU_ERF, |
| 109 | HTP_OP_GLU_GEGLU_ERF, |
| 110 | HTP_OP_POOL_2D, |
| 111 | HTP_OP_POOL_1D, |
| 112 | HTP_OP_UNARY_GELU_QUICK, |
| 113 | HTP_OP_IM2COL_3D, |
| 114 | HTP_OP_HADAMARD, |
| 115 | HTP_OP_GLU_REGLU, |
| 116 | HTP_OP_GLU_SIGMOID, |
| 117 | HTP_OP_UNARY_CEIL, |
| 118 | HTP_OP_UNARY_SGN, |
| 119 | HTP_OP_UPSCALE, |
| 120 | HTP_OP_DSV4_HC_PRE, |
| 121 | HTP_OP_DSV4_HC_POST, |
| 122 | HTP_OP_TOP_K_MASK, |
| 123 | HTP_OP_LIGHTNING_INDEXER, |
| 124 | |
| 125 | HTP_OP_INVALID |
| 126 | }; |
| 127 | |
| 128 | #define HTP_OP_MAX_DIMS 4 // aka GGML_MAX_DIMS |
| 129 | #define HTP_OP_MAX_INPUTS 10 // aka GGML_MAX_SRCS |
| 130 | #define HTP_OP_MAX_OUTPUTS 4 |
| 131 | #define HTP_OP_MAX_PARAMS 16 // aka GGML_MAX_OP_PARAMS |
| 132 | #define HTP_OP_MAX_KERN_PARAMS 32 |
| 133 | |
| 134 | #define HTP_OP_MAX_BUFS 64 |
| 135 | #define HTP_OP_MAX_TENSORS 65534 // must stay under 64K (uint16) |
| 136 | |
| 137 | #define HTP_FENCE_TIMEOUT (1000000000ULL) |
| 138 | #define HTP_FENCE_SLOT_SIZE 128 |
| 139 | |
| 140 | #define HTP_OP_MAX_VMEM_DEFAULT (3355443200u) |
| 141 | |
| 142 | #define HTP_MMAP_MAX_VMEM (2147483648u) |
| 143 | |
| 144 | #define HTP_DDR_SPAD_SIZE (512 * 1024) |
| 145 | |
| 146 | enum htp_tensor_flags { |
| 147 | HTP_TENSOR_WEIGHT = (1U << 0), // Tensor buffer model weight data (not compute) |
| 148 | HTP_TENSOR_TILED = (1U << 1), // Tensor is in tiled format |
| 149 | HTP_TENSOR_FENCE = (1U << 2), // Tensor is synchronization fence (explicitly managed) |
| 150 | HTP_TENSOR_FUSEABLE = (1U << 3), // Tensor can be fused (host-only) |
| 151 | }; |
| 152 | |
| 153 | enum htp_buf_flags { |
| 154 | HTP_BUF_EXTENDED = (1U << 0), |
| 155 | }; |
| 156 | |
| 157 | // Tensor descriptor |
| 158 | struct htp_tensor { |
| 159 | uint64_t data; // Buffer offset in the messages, and data pointer on the NPU |
| 160 | uint32_t size; // Data size in bytes |
| 161 | uint32_t flags; // Buffer / tensor flags |
| 162 | uint32_t type; // Data type |
| 163 | uint16_t bi; // Buffer index |
| 164 | uint16_t ti; // Tensor index |
| 165 | uint32_t ne[HTP_OP_MAX_DIMS]; // Number of elements |
| 166 | uint32_t nb[HTP_OP_MAX_DIMS]; // Stride in bytes (see ggml.h ggml_tensor) |
| 167 | }; |
| 168 | |
| 169 | // Buffer descriptor |
| 170 | struct htp_buf_desc { |
| 171 | uint64_t base; // base address |
| 172 | uint64_t size; // total size |
| 173 | uint32_t flags; // HTP_BUF_* |
| 174 | uint32_t fd; // file descriptor |
| 175 | }; |
| 176 | |
| 177 | enum htp_op_flags { |
| 178 | HTP_OPFLAGS_STUB = (1U << 0), |
| 179 | }; |
| 180 | |
| 181 | // Op descriptor |
| 182 | struct htp_op_desc { |
| 183 | uint32_t opcode; // GGML/HTP Op |
| 184 | uint32_t flags; // Op flags |
| 185 | int32_t params[HTP_OP_MAX_PARAMS]; // Params for the op, e.g. epsilon of RMS norm |
| 186 | int32_t kernel_params[HTP_OP_MAX_KERN_PARAMS]; // generic blob for host-precomputed parameters |
| 187 | uint16_t src[HTP_OP_MAX_INPUTS]; // Input tensors indices |
| 188 | uint16_t dst[HTP_OP_MAX_OUTPUTS]; // Output tensor indices |
| 189 | uint16_t pad[2]; // padding to align to 64 bits |
| 190 | }; |
| 191 | |
| 192 | #ifndef HTP_MAX_NTHREADS |
| 193 | #define HTP_MAX_NTHREADS 10 |
| 194 | #endif |
| 195 | |
| 196 | #define HTP_TRACE_MAX_EVENTS 256 |
| 197 | |
| 198 | enum htp_profiler_mode { |
| 199 | HTP_PROF_DISABLED = 0, |
| 200 | HTP_PROF_BASIC = 1, |
| 201 | HTP_PROF_PMU = 2, |
| 202 | HTP_PROF_TRACE = 3, |
| 203 | }; |
| 204 | |
| 205 | // DCVS/HMX power profile requested for the session. |
| 206 | enum htp_power_mode { |
| 207 | HTP_POWER_MODE_LOW_POWER_SAVER = 0, |
| 208 | HTP_POWER_MODE_POWER_SAVER = 1, |
| 209 | HTP_POWER_MODE_HIGH_POWER_SAVER = 2, |
| 210 | HTP_POWER_MODE_LOW_BALANCED = 3, |
| 211 | HTP_POWER_MODE_BALANCED = 4, |
| 212 | HTP_POWER_MODE_HIGH_PERFORMANCE = 5, |
| 213 | HTP_POWER_MODE_SUSTAINED_HIGH_PERFORMANCE = 6, |
| 214 | HTP_POWER_MODE_BURST = 7, |
| 215 | |
| 216 | HTP_POWER_MODE_COUNT |
| 217 | }; |
| 218 | |
| 219 | enum htp_trace_event_id { |
| 220 | HTP_TRACE_EVT_DMA = 0, |
| 221 | HTP_TRACE_EVT_L2FLUSH = 1, |
| 222 | HTP_TRACE_EVT_INIT = 2, |
| 223 | HTP_TRACE_EVT_BUFF = 3, |
| 224 | HTP_TRACE_EVT_FENCE = 4, |
| 225 | |
| 226 | HTP_TRACE_EVT_HVX_COMP = 20, |
| 227 | HTP_TRACE_EVT_HVX_A_QUANT = 21, |
| 228 | HTP_TRACE_EVT_HVX_A_PREP = 22, |
| 229 | HTP_TRACE_EVT_HVX_W_DEQUANT = 23, |
| 230 | HTP_TRACE_EVT_HVX_W_PREP = 24, |
| 231 | HTP_TRACE_EVT_HVX_O_PROC = 25, |
| 232 | HTP_TRACE_EVT_HVX_FA_QK = 26, |
| 233 | HTP_TRACE_EVT_HVX_FA_SFM = 27, |
| 234 | HTP_TRACE_EVT_HVX_FA_Q_PREP = 28, |
| 235 | HTP_TRACE_EVT_HVX_FA_K_PREP = 29, |
| 236 | HTP_TRACE_EVT_HVX_FA_V_PREP = 30, |
| 237 | |
| 238 | HTP_TRACE_EVT_HVX_GDN_PREP = 31, |
| 239 | HTP_TRACE_EVT_HVX_GDN_SOLVE = 32, |
| 240 | HTP_TRACE_EVT_HVX_GDN_V_PREP = 33, |
| 241 | HTP_TRACE_EVT_HVX_GDN_D_PREP = 34, |
| 242 | HTP_TRACE_EVT_HVX_GDN_OUT = 35, |
| 243 | HTP_TRACE_EVT_HVX_GDN_STATE = 36, |
| 244 | HTP_TRACE_EVT_HVX_GDN_REM = 37, |
| 245 | |
| 246 | HTP_TRACE_EVT_HMX_COMP = 40, |
| 247 | }; |
| 248 | |
| 249 | struct htp_trace_desc { |
| 250 | uint32_t cycles; // lower 32-bits of cycle counter |
| 251 | uint16_t id; // Event ID |
| 252 | uint16_t info; // bit 15: is_stop. bits 14-0: tile/chunk index or other metadata. |
| 253 | }; |
| 254 | |
| 255 | #define HTP_PROF_PMU_NCNT 8 |
| 256 | |
| 257 | // Profile descriptor |
| 258 | struct htp_prof_desc { |
| 259 | uint32_t opcode; // GGML/HTP Op |
| 260 | uint32_t usecs; // Number of usec |
| 261 | uint32_t cycles_start; // Start cycle counter |
| 262 | uint32_t cycles_stop; // Stop cycle counter |
| 263 | uint32_t pmu[HTP_PROF_PMU_NCNT]; // PMU counters |
| 264 | }; |
| 265 | |
| 266 | struct htp_opbatch_req { |
| 267 | uint64_t seq; // Sequence number |
| 268 | uint32_t n_bufs; // Number of buffers |
| 269 | uint32_t n_tensors; // Number of tensors |
| 270 | uint32_t n_ops; // Number of ops |
| 271 | uint32_t n_traces; // Number of trace descriptors per thread |
| 272 | // struct htp_buf_desc bufs[]; -- dspqueue buf 0 |
| 273 | // struct htp_tensor tensors[]; -- dspqueue buf 0 |
| 274 | // struct htp_op_desc ops[]; -- dspqueue buf 0 |
| 275 | }; |
| 276 | |
| 277 | struct htp_opbatch_rsp { |
| 278 | uint64_t seq; // Sequence number |
| 279 | uint64_t cycles_start; // Start cycle counter |
| 280 | uint64_t cycles_stop; // Stop cycle counter |
| 281 | uint32_t status; // HTP_STATUS_... |
| 282 | uint32_t n_bufs; // Number of buffers |
| 283 | uint32_t n_tensors; // Number of tensors |
| 284 | uint32_t n_ops; // Number of op profile descriptors |
| 285 | uint32_t usecs; // Number of usec |
| 286 | uint32_t n_traces[HTP_MAX_NTHREADS + 1]; |
| 287 | // struct htp_prof_desc profs[]; -- dspqueue buf 0 |
| 288 | }; |
| 289 | |
| 290 | #endif /* HTP_OPS_H */ |