ggml
[Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685)
Brought by drakestapleton
ggml / src / ggml-metal / ggml-metal-impl.h
| 1 | #ifndef GGML_METAL_IMPL |
| 2 | #define GGML_METAL_IMPL |
| 3 | |
| 4 | // kernel parameters for mat-mat threadgroups |
| 5 | // |
| 6 | // TODO: become function constants |
| 7 | |
| 8 | #define SZ_SIMDGROUP 16 |
| 9 | #define N_MM_NK 2 |
| 10 | #define N_MM_NK_TOTAL (SZ_SIMDGROUP * N_MM_NK) |
| 11 | |
| 12 | #define N_MM_BLOCK_X 4 |
| 13 | #define N_MM_BLOCK_Y 2 |
| 14 | #define N_MM_SIMD_GROUP_X 2 |
| 15 | #define N_MM_SIMD_GROUP_Y 2 |
| 16 | |
| 17 | #define N_ARGMAX_NPART_MAX 256 |
| 18 | #define N_ARGMAX_CHUNK 4096 |
| 19 | |
| 20 | // kernel parameters for mat-vec threadgroups |
| 21 | // |
| 22 | // N_R0: number of src0 rows to process per simdgroup |
| 23 | // N_SG: number of simdgroups per threadgroup |
| 24 | // |
| 25 | // TODO: for optimal performance, become function of the device and work size |
| 26 | |
| 27 | #define N_R0_Q1_0 8 |
| 28 | #define N_SG_Q1_0 2 |
| 29 | |
| 30 | #define N_R0_Q2_0 8 |
| 31 | #define N_SG_Q2_0 2 |
| 32 | |
| 33 | #define N_R0_Q4_0 4 |
| 34 | #define N_SG_Q4_0 2 |
| 35 | |
| 36 | #define N_R0_Q4_1 4 |
| 37 | #define N_SG_Q4_1 2 |
| 38 | |
| 39 | #define N_R0_Q5_0 4 |
| 40 | #define N_SG_Q5_0 2 |
| 41 | |
| 42 | #define N_R0_Q5_1 4 |
| 43 | #define N_SG_Q5_1 2 |
| 44 | |
| 45 | #define N_R0_Q8_0 2 |
| 46 | #define N_SG_Q8_0 4 |
| 47 | |
| 48 | #define N_R0_MXFP4 2 |
| 49 | #define N_SG_MXFP4 2 |
| 50 | |
| 51 | #define N_R0_Q2_K 4 |
| 52 | #define N_SG_Q2_K 2 |
| 53 | |
| 54 | #define N_R0_Q3_K 2 |
| 55 | #define N_SG_Q3_K 2 |
| 56 | |
| 57 | #define N_R0_Q4_K 2 |
| 58 | #define N_SG_Q4_K 2 |
| 59 | |
| 60 | #define N_R0_Q5_K 1 |
| 61 | #define N_SG_Q5_K 2 |
| 62 | |
| 63 | #define N_R0_Q6_K 2 |
| 64 | #define N_SG_Q6_K 2 |
| 65 | |
| 66 | #define N_R0_IQ1_S 4 |
| 67 | #define N_SG_IQ1_S 2 |
| 68 | #define N_R0_IQ1_S_SPLIT 8 |
| 69 | |
| 70 | #define N_R0_IQ1_M 4 |
| 71 | #define N_SG_IQ1_M 2 |
| 72 | #define N_R0_IQ1_M_SPLIT 8 |
| 73 | |
| 74 | #define N_R0_IQ2_XXS 4 |
| 75 | #define N_SG_IQ2_XXS 2 |
| 76 | #define N_R0_IQ2_XXS_SPLIT 8 |
| 77 | |
| 78 | #define N_R0_IQ2_XS 4 |
| 79 | #define N_SG_IQ2_XS 2 |
| 80 | #define N_R0_IQ2_XS_SPLIT 8 |
| 81 | |
| 82 | #define N_R0_IQ2_S 4 |
| 83 | #define N_SG_IQ2_S 2 |
| 84 | #define N_R0_IQ2_S_SPLIT 8 |
| 85 | |
| 86 | #define N_R0_IQ3_XXS 4 |
| 87 | #define N_SG_IQ3_XXS 2 |
| 88 | #define N_R0_IQ3_XXS_SPLIT 8 |
| 89 | |
| 90 | #define N_R0_IQ3_S 4 |
| 91 | #define N_SG_IQ3_S 2 |
| 92 | #define N_R0_IQ3_S_SPLIT 8 |
| 93 | |
| 94 | #define N_R0_IQ4_NL 2 |
| 95 | #define N_SG_IQ4_NL 2 |
| 96 | |
| 97 | #define N_R0_IQ4_XS 2 |
| 98 | #define N_SG_IQ4_XS 2 |
| 99 | |
| 100 | #define N_R0_TQ2_0 4 |
| 101 | #define N_SG_TQ2_0 2 |
| 102 | |
| 103 | // function constants offsets |
| 104 | #define FC_FLASH_ATTN_EXT_PAD 100 |
| 105 | #define FC_FLASH_ATTN_EXT_BLK 200 |
| 106 | #define FC_FLASH_ATTN_EXT 300 |
| 107 | #define FC_FLASH_ATTN_EXT_VEC 400 |
| 108 | #define FC_FLASH_ATTN_EXT_VEC_REDUCE 500 |
| 109 | #define FC_MUL_MV 600 |
| 110 | #define FC_MUL_MM 700 |
| 111 | #define FC_ROPE 800 |
| 112 | #define FC_SSM_CONV 900 |
| 113 | #define FC_SOLVE_TRI 1000 |
| 114 | #define FC_COUNT_EQUAL 1100 |
| 115 | #define FC_UNARY 1200 |
| 116 | #define FC_BIN 1300 |
| 117 | #define FC_SUM_ROWS 1400 |
| 118 | #define FC_UPSCALE 1500 |
| 119 | #define FC_GATED_DELTA_NET 1600 |
| 120 | #define FC_NORM 1700 |
| 121 | #define FC_TOPK_MOE 1800 |
| 122 | #define FC_MOE_REDUCE 1900 |
| 123 | #define FC_DSV4_HC 2000 |
| 124 | #define FC_PAD 2100 |
| 125 | #define FC_FLASH_ATTN_EXT_TENSOR 2200 |
| 126 | #define FC_LIGHTNING_INDEXER 2200 |
| 127 | #define FC_MUL_MV_MMA 2300 |
| 128 | #define FC_TOP_K_MASK 2400 |
| 129 | |
| 130 | // op-specific constants |
| 131 | #define OP_FLASH_ATTN_EXT_NQPSG 8 |
| 132 | #define OP_FLASH_ATTN_EXT_NCPSG 64 |
| 133 | |
| 134 | #define OP_FLASH_ATTN_EXT_TENSOR_NQPSG 32 |
| 135 | #define OP_FLASH_ATTN_EXT_TENSOR_NQPSG_LARGE 16 |
| 136 | #define OP_FLASH_ATTN_EXT_TENSOR_NCPSG 64 |
| 137 | #define OP_FLASH_ATTN_EXT_TENSOR_NSG 8 |
| 138 | |
| 139 | #define OP_FLASH_ATTN_EXT_VEC_NQPSG 1 |
| 140 | #define OP_FLASH_ATTN_EXT_VEC_NCPSG 32 |
| 141 | |
| 142 | #define OP_LIGHTNING_INDEXER_DK 128 |
| 143 | #define OP_LIGHTNING_INDEXER_NHPTG 8 |
| 144 | #define OP_LIGHTNING_INDEXER_NKPSG 8 |
| 145 | #define OP_LIGHTNING_INDEXER_NSG 8 |
| 146 | #define OP_LIGHTNING_INDEXER_NBPTG 8 |
| 147 | |
| 148 | #define OP_UNARY_NUM_SCALE 10 |
| 149 | #define OP_UNARY_NUM_FILL 11 |
| 150 | #define OP_UNARY_NUM_CLAMP 12 |
| 151 | #define OP_UNARY_NUM_SQR 13 |
| 152 | #define OP_UNARY_NUM_SQRT 14 |
| 153 | #define OP_UNARY_NUM_SIN 15 |
| 154 | #define OP_UNARY_NUM_COS 16 |
| 155 | #define OP_UNARY_NUM_LOG 17 |
| 156 | #define OP_UNARY_NUM_LEAKY_RELU 18 |
| 157 | |
| 158 | #define OP_UNARY_NUM_TANH 100 |
| 159 | #define OP_UNARY_NUM_RELU 101 |
| 160 | #define OP_UNARY_NUM_SIGMOID 102 |
| 161 | #define OP_UNARY_NUM_GELU 103 |
| 162 | #define OP_UNARY_NUM_GELU_ERF 104 |
| 163 | #define OP_UNARY_NUM_GELU_QUICK 105 |
| 164 | #define OP_UNARY_NUM_SILU 106 |
| 165 | #define OP_UNARY_NUM_ELU 107 |
| 166 | #define OP_UNARY_NUM_NEG 108 |
| 167 | #define OP_UNARY_NUM_ABS 109 |
| 168 | #define OP_UNARY_NUM_SGN 110 |
| 169 | #define OP_UNARY_NUM_STEP 111 |
| 170 | #define OP_UNARY_NUM_HARDSWISH 112 |
| 171 | #define OP_UNARY_NUM_HARDSIGMOID 113 |
| 172 | #define OP_UNARY_NUM_EXP 114 |
| 173 | #define OP_UNARY_NUM_SOFTPLUS 115 |
| 174 | #define OP_UNARY_NUM_EXPM1 116 |
| 175 | #define OP_UNARY_NUM_FLOOR 117 |
| 176 | #define OP_UNARY_NUM_CEIL 118 |
| 177 | #define OP_UNARY_NUM_ROUND 119 |
| 178 | #define OP_UNARY_NUM_TRUNC 120 |
| 179 | #define OP_UNARY_NUM_XIELU 121 |
| 180 | |
| 181 | #define OP_SUM_ROWS_NUM_SUM_ROWS 10 |
| 182 | #define OP_SUM_ROWS_NUM_MEAN 11 |
| 183 | |
| 184 | #define OP_SSM_SCAN_SSD_CS 64 // Metal-specific; Chunk Size; 64 is largest multiple of 8 (simdgroup tile) fitting into 32 KiB Metal threadgroup mem limit (~26.75 KiB shared mem; see smem layout comment in kernel_ssm_scan_ssd_mma_f32) |
| 185 | #define OP_SSM_SCAN_SSD_HD 64 // Metal-specific; Head Dim the MMA kernel is specialized for (Mamba-2); use_mma gates on d_inner == this |
| 186 | #define OP_SSM_SCAN_SSD_NSG 4 // Metal-specific; Number of SimdGroups per threadgroup; NSG*32 == threads dispatched per threadgroup |
| 187 | |
| 188 | // kernel argument structs |
| 189 | // |
| 190 | // - element counters (e.g. ne00) typically use int32_t to reduce register usage |
| 191 | // however, be careful from int overflows when using those in the kernel implementation |
| 192 | // |
| 193 | // - strides (e.g. nb00) use uint64_t |
| 194 | |
| 195 | typedef struct { |
| 196 | int32_t ne00; |
| 197 | int32_t ne01; |
| 198 | int32_t ne02; |
| 199 | int32_t ne03; |
| 200 | uint64_t nb00; |
| 201 | uint64_t nb01; |
| 202 | uint64_t nb02; |
| 203 | uint64_t nb03; |
| 204 | int32_t ne10; |
| 205 | int32_t ne11; |
| 206 | int32_t ne12; |
| 207 | int32_t ne13; |
| 208 | uint64_t nb10; |
| 209 | uint64_t nb11; |
| 210 | uint64_t nb12; |
| 211 | uint64_t nb13; |
| 212 | int32_t ne0; |
| 213 | int32_t ne1; |
| 214 | int32_t ne2; |
| 215 | int32_t ne3; |
| 216 | uint64_t nb0; |
| 217 | uint64_t nb1; |
| 218 | uint64_t nb2; |
| 219 | uint64_t nb3; |
| 220 | int32_t dim; |
| 221 | int32_t nc0; |
| 222 | } ggml_metal_kargs_concat; |
| 223 | |
| 224 | typedef struct { |
| 225 | int32_t ne00; |
| 226 | int32_t ne01; |
| 227 | int32_t ne02; |
| 228 | int32_t ne03; |
| 229 | uint64_t nb00; |
| 230 | uint64_t nb01; |
| 231 | uint64_t nb02; |
| 232 | uint64_t nb03; |
| 233 | int32_t ne0; |
| 234 | int32_t ne1; |
| 235 | int32_t ne2; |
| 236 | int32_t ne3; |
| 237 | uint64_t nb0; |
| 238 | uint64_t nb1; |
| 239 | uint64_t nb2; |
| 240 | uint64_t nb3; |
| 241 | float slope; |
| 242 | float scale; |
| 243 | float bias; |
| 244 | float val; |
| 245 | float min; |
| 246 | float max; |
| 247 | } ggml_metal_kargs_unary; |
| 248 | |
| 249 | typedef struct { |
| 250 | int32_t ne00; |
| 251 | int32_t ne01; |
| 252 | int32_t ne02; |
| 253 | int32_t ne03; |
| 254 | uint64_t nb00; |
| 255 | uint64_t nb01; |
| 256 | uint64_t nb02; |
| 257 | uint64_t nb03; |
| 258 | int32_t ne10; |
| 259 | int32_t ne11; |
| 260 | int32_t ne12; |
| 261 | int32_t ne13; |
| 262 | uint64_t nb10; |
| 263 | uint64_t nb11; |
| 264 | uint64_t nb12; |
| 265 | uint64_t nb13; |
| 266 | int32_t ne0; |
| 267 | int32_t ne1; |
| 268 | int32_t ne2; |
| 269 | int32_t ne3; |
| 270 | uint64_t nb0; |
| 271 | uint64_t nb1; |
| 272 | uint64_t nb2; |
| 273 | uint64_t nb3; |
| 274 | uint64_t offs; |
| 275 | uint64_t o1[8]; |
| 276 | } ggml_metal_kargs_bin; |
| 277 | |
| 278 | typedef struct { |
| 279 | int64_t ne0; |
| 280 | int64_t ne1; |
| 281 | size_t nb01; |
| 282 | size_t nb02; |
| 283 | size_t nb11; |
| 284 | size_t nb21; |
| 285 | } ggml_metal_kargs_add_id; |
| 286 | |
| 287 | typedef struct { |
| 288 | int32_t ne00; |
| 289 | int32_t ne01; |
| 290 | int32_t ne02; |
| 291 | int32_t ne03; |
| 292 | uint64_t nb00; |
| 293 | uint64_t nb01; |
| 294 | uint64_t nb02; |
| 295 | uint64_t nb03; |
| 296 | int32_t ne0; |
| 297 | int32_t ne1; |
| 298 | int32_t ne2; |
| 299 | int32_t ne3; |
| 300 | uint64_t nb0; |
| 301 | uint64_t nb1; |
| 302 | uint64_t nb2; |
| 303 | uint64_t nb3; |
| 304 | } ggml_metal_kargs_repeat; |
| 305 | |
| 306 | typedef struct { |
| 307 | int64_t nk0; |
| 308 | int64_t ne00; |
| 309 | int64_t ne01; |
| 310 | int64_t ne02; |
| 311 | int64_t ne03; |
| 312 | uint64_t nb00; |
| 313 | uint64_t nb01; |
| 314 | uint64_t nb02; |
| 315 | uint64_t nb03; |
| 316 | int64_t ne0; |
| 317 | int64_t ne1; |
| 318 | int64_t ne2; |
| 319 | int64_t ne3; |
| 320 | uint64_t nb0; |
| 321 | uint64_t nb1; |
| 322 | uint64_t nb2; |
| 323 | uint64_t nb3; |
| 324 | } ggml_metal_kargs_cpy; |
| 325 | |
| 326 | typedef struct { |
| 327 | int64_t ne10; |
| 328 | int64_t ne11; |
| 329 | int64_t ne12; |
| 330 | uint64_t nb10; |
| 331 | uint64_t nb11; |
| 332 | uint64_t nb12; |
| 333 | uint64_t nb13; |
| 334 | uint64_t nb1; |
| 335 | uint64_t nb2; |
| 336 | uint64_t nb3; |
| 337 | uint64_t offs; |
| 338 | bool inplace; |
| 339 | } ggml_metal_kargs_set; |
| 340 | |
| 341 | typedef struct { |
| 342 | int32_t ne00; |
| 343 | int32_t ne01; |
| 344 | int32_t ne02; |
| 345 | int32_t ne03; |
| 346 | uint64_t nb00; |
| 347 | uint64_t nb01; |
| 348 | uint64_t nb02; |
| 349 | uint64_t nb03; |
| 350 | int32_t ne0; |
| 351 | int32_t ne1; |
| 352 | int32_t ne2; |
| 353 | int32_t ne3; |
| 354 | uint64_t nb0; |
| 355 | uint64_t nb1; |
| 356 | uint64_t nb2; |
| 357 | uint64_t nb3; |
| 358 | int32_t n_past; |
| 359 | int32_t n_dims; |
| 360 | int32_t n_offs; |
| 361 | int32_t n_ctx_orig; |
| 362 | float freq_base; |
| 363 | float freq_scale; |
| 364 | float ext_factor; |
| 365 | float attn_factor; |
| 366 | float beta_fast; |
| 367 | float beta_slow; |
| 368 | int32_t sect_0; |
| 369 | int32_t sect_1; |
| 370 | int32_t sect_2; |
| 371 | int32_t sect_3; |
| 372 | bool src2; |
| 373 | bool inplace; |
| 374 | } ggml_metal_kargs_rope; |
| 375 | |
| 376 | typedef struct { |
| 377 | int32_t ne0; |
| 378 | int32_t ne1; |
| 379 | int32_t ne2; |
| 380 | int32_t ne3; |
| 381 | uint64_t nb0; |
| 382 | uint64_t nb1; |
| 383 | uint64_t nb2; |
| 384 | uint64_t nb3; |
| 385 | int32_t nblocks; |
| 386 | } ggml_metal_kargs_flash_attn_ext_kv_f16; |
| 387 | |
| 388 | // gather the K/V cache rows referenced by the kv_rows lists into contiguous F16 buffers |
| 389 | typedef struct { |
| 390 | int32_t ne11; // number of rows per list (n_kv_rows) |
| 391 | int32_t ne_12_2; // number of K/V heads |
| 392 | int32_t ne10; // DK |
| 393 | int32_t ne20; // DV, set to 0 to skip gathering V (V is a view of K) |
| 394 | uint64_t v_off; // byte offset of the gathered V region in dst |
| 395 | uint64_t nb11; // K source strides (ne13 = 1: the cache is shared by all streams) |
| 396 | uint64_t nb12; |
| 397 | uint64_t nb21; // V source strides (ne23 = 1) |
| 398 | uint64_t nb22; |
| 399 | } ggml_metal_kargs_flash_attn_ext_rows; |
| 400 | |
| 401 | typedef struct { |
| 402 | int32_t ne11; |
| 403 | int32_t ne_12_2; // assume K and V are same shape |
| 404 | int32_t ne_12_3; |
| 405 | uint64_t nb11; |
| 406 | uint64_t nb12; |
| 407 | uint64_t nb13; |
| 408 | uint64_t nb21; |
| 409 | uint64_t nb22; |
| 410 | uint64_t nb23; |
| 411 | int32_t ne31; |
| 412 | int32_t ne32; |
| 413 | int32_t ne33; |
| 414 | uint64_t nb31; |
| 415 | uint64_t nb32; |
| 416 | uint64_t nb33; |
| 417 | } ggml_metal_kargs_flash_attn_ext_pad; |
| 418 | |
| 419 | typedef struct { |
| 420 | int32_t ne01; |
| 421 | int32_t ne30; |
| 422 | int32_t ne31; |
| 423 | int32_t ne32; |
| 424 | int32_t ne33; |
| 425 | uint64_t nb31; |
| 426 | uint64_t nb32; |
| 427 | uint64_t nb33; |
| 428 | } ggml_metal_kargs_flash_attn_ext_blk; |
| 429 | |
| 430 | typedef struct { |
| 431 | int32_t ne01; |
| 432 | int32_t ne02; |
| 433 | int32_t ne03; |
| 434 | uint64_t nb01; |
| 435 | uint64_t nb02; |
| 436 | uint64_t nb03; |
| 437 | int32_t ne11; |
| 438 | int32_t ne_12_2; // assume K and V are same shape |
| 439 | int32_t ne_12_3; |
| 440 | int32_t ns10; |
| 441 | uint64_t nb11; |
| 442 | uint64_t nb12; |
| 443 | uint64_t nb13; |
| 444 | int32_t ns20; |
| 445 | uint64_t nb21; |
| 446 | uint64_t nb22; |
| 447 | uint64_t nb23; |
| 448 | int32_t ne31; |
| 449 | int32_t ne32; |
| 450 | int32_t ne33; |
| 451 | uint64_t nb31; |
| 452 | uint64_t nb32; |
| 453 | uint64_t nb33; |
| 454 | int32_t ne1; |
| 455 | int32_t ne2; |
| 456 | int32_t ne3; |
| 457 | float scale; |
| 458 | float max_bias; |
| 459 | float m0; |
| 460 | float m1; |
| 461 | int32_t n_head_log2; |
| 462 | float logit_softcap; |
| 463 | } ggml_metal_kargs_flash_attn_ext; |
| 464 | |
| 465 | typedef struct { |
| 466 | int32_t ne01; |
| 467 | int32_t ne02; |
| 468 | int32_t ne03; |
| 469 | uint64_t nb01; |
| 470 | uint64_t nb02; |
| 471 | uint64_t nb03; |
| 472 | int32_t ne11; |
| 473 | int32_t ne_12_2; // assume K and V are same shape |
| 474 | int32_t ne_12_3; |
| 475 | int32_t ns10; |
| 476 | uint64_t nb11; |
| 477 | uint64_t nb12; |
| 478 | uint64_t nb13; |
| 479 | int32_t ns20; |
| 480 | uint64_t nb21; |
| 481 | uint64_t nb22; |
| 482 | uint64_t nb23; |
| 483 | int32_t ne31; |
| 484 | int32_t ne32; |
| 485 | int32_t ne33; |
| 486 | uint64_t nb31; |
| 487 | uint64_t nb32; |
| 488 | uint64_t nb33; |
| 489 | int32_t ne1; |
| 490 | int32_t ne2; |
| 491 | int32_t ne3; |
| 492 | float scale; |
| 493 | float max_bias; |
| 494 | float m0; |
| 495 | float m1; |
| 496 | int32_t n_head_log2; |
| 497 | float logit_softcap; |
| 498 | int32_t n_kv_max_padded; |
| 499 | } ggml_metal_kargs_flash_attn_ext_vec; |
| 500 | |
| 501 | typedef struct { |
| 502 | int32_t ne30; |
| 503 | int32_t ne31; |
| 504 | int32_t ne32; |
| 505 | int32_t ne33; |
| 506 | uint64_t nb31; |
| 507 | uint64_t nb32; |
| 508 | uint64_t nb33; |
| 509 | int32_t n_kv_max; |
| 510 | int32_t n_kv_max_padded; |
| 511 | } ggml_metal_kargs_flash_attn_ext_vec_idx; |
| 512 | |
| 513 | typedef struct { |
| 514 | int32_t nrows; |
| 515 | } ggml_metal_kargs_flash_attn_ext_vec_reduce; |
| 516 | |
| 517 | typedef struct { |
| 518 | int32_t ne00; |
| 519 | int32_t ne02; |
| 520 | uint64_t nb01; |
| 521 | uint64_t nb02; |
| 522 | uint64_t nb03; |
| 523 | int32_t ne12; |
| 524 | uint64_t nb10; |
| 525 | uint64_t nb11; |
| 526 | uint64_t nb12; |
| 527 | uint64_t nb13; |
| 528 | int32_t ne0; |
| 529 | int32_t ne1; |
| 530 | int16_t r2; |
| 531 | int16_t r3; |
| 532 | } ggml_metal_kargs_mul_mm; |
| 533 | |
| 534 | typedef struct { |
| 535 | int32_t ne00; |
| 536 | int32_t ne01; |
| 537 | int32_t ne02; |
| 538 | uint64_t nb00; |
| 539 | uint64_t nb01; |
| 540 | uint64_t nb02; |
| 541 | uint64_t nb03; |
| 542 | int32_t ne10; |
| 543 | int32_t ne11; |
| 544 | int32_t ne12; |
| 545 | uint64_t nb10; |
| 546 | uint64_t nb11; |
| 547 | uint64_t nb12; |
| 548 | uint64_t nb13; |
| 549 | int32_t ne0; |
| 550 | int32_t ne1; |
| 551 | int32_t nr0; |
| 552 | int16_t r2; |
| 553 | int16_t r3; |
| 554 | } ggml_metal_kargs_mul_mv; |
| 555 | |
| 556 | typedef struct { |
| 557 | int32_t ne00; |
| 558 | int32_t ne01; |
| 559 | int32_t ne02; |
| 560 | uint64_t nb00; |
| 561 | uint64_t nb01; |
| 562 | uint64_t nb02; |
| 563 | uint64_t nb03; |
| 564 | int32_t ne10; |
| 565 | int32_t ne11; |
| 566 | int32_t ne12; |
| 567 | uint64_t nb10; |
| 568 | uint64_t nb11; |
| 569 | uint64_t nb12; |
| 570 | uint64_t nb13; |
| 571 | int32_t ne0; |
| 572 | int32_t ne1; |
| 573 | int16_t r2; |
| 574 | int16_t r3; |
| 575 | } ggml_metal_kargs_mul_mv_ext; |
| 576 | |
| 577 | typedef struct { |
| 578 | int32_t ne10; |
| 579 | int32_t ne11; // n_expert_used (bcast) |
| 580 | uint64_t nb11; |
| 581 | uint64_t nb12; |
| 582 | int32_t ne21; // n_tokens |
| 583 | int32_t ne20; // n_expert_used |
| 584 | uint64_t nb21; |
| 585 | } ggml_metal_kargs_mul_mm_id_map0; |
| 586 | |
| 587 | typedef struct { |
| 588 | int32_t ne0; |
| 589 | uint64_t nb1; |
| 590 | uint64_t nb2; |
| 591 | uint64_t nb21; |
| 592 | } ggml_metal_kargs_mul_mm_id_zero; |
| 593 | |
| 594 | typedef struct { |
| 595 | int32_t ne00; |
| 596 | int32_t ne02; |
| 597 | uint64_t nb01; |
| 598 | uint64_t nb02; |
| 599 | uint64_t nb03; |
| 600 | int32_t ne11; |
| 601 | uint64_t nb10; |
| 602 | uint64_t nb11; |
| 603 | uint64_t nb12; |
| 604 | uint64_t nb13; |
| 605 | int32_t ne20; |
| 606 | int32_t ne0; |
| 607 | int32_t ne1; |
| 608 | int16_t r2; |
| 609 | int16_t r3; |
| 610 | } ggml_metal_kargs_mul_mm_id; |
| 611 | |
| 612 | typedef struct { |
| 613 | int32_t nei0; |
| 614 | int32_t nei1; |
| 615 | uint64_t nbi1; |
| 616 | int32_t ne00; |
| 617 | int32_t ne01; |
| 618 | int32_t ne02; |
| 619 | uint64_t nb00; |
| 620 | uint64_t nb01; |
| 621 | uint64_t nb02; |
| 622 | int32_t ne10; |
| 623 | int32_t ne11; |
| 624 | int32_t ne12; |
| 625 | int32_t ne13; |
| 626 | uint64_t nb10; |
| 627 | uint64_t nb11; |
| 628 | uint64_t nb12; |
| 629 | int32_t ne0; |
| 630 | int32_t ne1; |
| 631 | uint64_t nb1; |
| 632 | int32_t nr0; |
| 633 | } ggml_metal_kargs_mul_mv_id; |
| 634 | |
| 635 | // NORM |
| 636 | // RMS_NORM |
| 637 | typedef struct { |
| 638 | int32_t ne00; |
| 639 | int32_t ne00_t; |
| 640 | uint64_t nb1; |
| 641 | uint64_t nb2; |
| 642 | uint64_t nb3; |
| 643 | float eps; |
| 644 | int32_t nef1[3]; |
| 645 | int32_t nef2[3]; |
| 646 | int32_t nef3[3]; |
| 647 | uint64_t nbf1[3]; |
| 648 | uint64_t nbf2[3]; |
| 649 | uint64_t nbf3[3]; |
| 650 | float scale; |
| 651 | } ggml_metal_kargs_norm; |
| 652 | |
| 653 | typedef struct { |
| 654 | int32_t ne00; |
| 655 | int32_t ne01; |
| 656 | int32_t ne02; |
| 657 | int32_t ne03; |
| 658 | uint64_t nb00; |
| 659 | uint64_t nb01; |
| 660 | uint64_t nb02; |
| 661 | uint64_t nb03; |
| 662 | int32_t ne0; |
| 663 | int32_t ne1; |
| 664 | int32_t ne2; |
| 665 | int32_t ne3; |
| 666 | uint64_t nb0; |
| 667 | uint64_t nb1; |
| 668 | uint64_t nb2; |
| 669 | uint64_t nb3; |
| 670 | float eps; |
| 671 | } ggml_metal_kargs_l2_norm; |
| 672 | |
| 673 | typedef struct { |
| 674 | int64_t ne00; |
| 675 | int64_t ne01; |
| 676 | int64_t ne02; |
| 677 | uint64_t nb00; |
| 678 | uint64_t nb01; |
| 679 | uint64_t nb02; |
| 680 | int32_t ngrp; |
| 681 | float eps; |
| 682 | } ggml_metal_kargs_group_norm; |
| 683 | |
| 684 | typedef struct { |
| 685 | int32_t IC; |
| 686 | int32_t IL; |
| 687 | int32_t K; |
| 688 | int32_t s0; |
| 689 | uint64_t nb0; |
| 690 | uint64_t nb1; |
| 691 | } ggml_metal_kargs_conv_transpose_1d; |
| 692 | |
| 693 | typedef struct { |
| 694 | int32_t T_in; |
| 695 | int32_t T_out; |
| 696 | int32_t OC; |
| 697 | int32_t K; |
| 698 | int32_t K_OC; |
| 699 | int32_t s0; |
| 700 | int32_t p0; |
| 701 | } ggml_metal_kargs_col2im_1d; |
| 702 | |
| 703 | typedef struct { |
| 704 | int32_t T; |
| 705 | int32_t C; |
| 706 | } ggml_metal_kargs_snake; |
| 707 | |
| 708 | typedef struct { |
| 709 | int32_t IC; |
| 710 | int32_t IH; |
| 711 | int32_t IW; |
| 712 | int32_t KH; |
| 713 | int32_t KW; |
| 714 | int32_t OC; |
| 715 | int32_t s0; |
| 716 | uint64_t nb0; |
| 717 | uint64_t nb1; |
| 718 | uint64_t nb2; |
| 719 | uint64_t nb3; |
| 720 | } ggml_metal_kargs_conv_transpose_2d; |
| 721 | |
| 722 | typedef struct { |
| 723 | uint64_t nb00; |
| 724 | uint64_t nb01; |
| 725 | uint64_t nb02; |
| 726 | uint64_t nb03; |
| 727 | uint64_t nb10; |
| 728 | uint64_t nb11; |
| 729 | uint64_t nb12; |
| 730 | uint64_t nb13; |
| 731 | uint64_t nb0; |
| 732 | uint64_t nb1; |
| 733 | uint64_t nb2; |
| 734 | uint64_t nb3; |
| 735 | int32_t IW; |
| 736 | int32_t IH; |
| 737 | int32_t KW; |
| 738 | int32_t KH; |
| 739 | int32_t IC; |
| 740 | int32_t OC; |
| 741 | int32_t OW; |
| 742 | int32_t OH; |
| 743 | int32_t N; |
| 744 | int32_t s0; |
| 745 | int32_t s1; |
| 746 | int32_t p0; |
| 747 | int32_t p1; |
| 748 | int32_t d0; |
| 749 | int32_t d1; |
| 750 | } ggml_metal_kargs_conv_2d; |
| 751 | |
| 752 | typedef struct { |
| 753 | uint64_t nb00; // kernel strides |
| 754 | uint64_t nb01; |
| 755 | uint64_t nb02; |
| 756 | uint64_t nb10; // input strides |
| 757 | uint64_t nb11; |
| 758 | uint64_t nb12; |
| 759 | uint64_t nb13; |
| 760 | uint64_t nb0; // output strides |
| 761 | uint64_t nb1; |
| 762 | uint64_t nb2; |
| 763 | uint64_t nb3; |
| 764 | int32_t IW; // input width |
| 765 | int32_t IH; // input height |
| 766 | int32_t KW; // kernel width |
| 767 | int32_t KH; // kernel height |
| 768 | int32_t C; // channels (IC == OC for depthwise) |
| 769 | int32_t OW; // output width |
| 770 | int32_t OH; // output height |
| 771 | int32_t N; // batch size |
| 772 | int32_t s0; // stride x |
| 773 | int32_t s1; // stride y |
| 774 | int32_t p0; // padding x |
| 775 | int32_t p1; // padding y |
| 776 | int32_t d0; // dilation x |
| 777 | int32_t d1; // dilation y |
| 778 | } ggml_metal_kargs_conv_2d_dw; |
| 779 | |
| 780 | typedef struct { |
| 781 | uint64_t ofs0; |
| 782 | uint64_t ofs1; |
| 783 | int32_t IW; |
| 784 | int32_t IH; |
| 785 | int32_t CHW; |
| 786 | int32_t s0; |
| 787 | int32_t s1; |
| 788 | int32_t p0; |
| 789 | int32_t p1; |
| 790 | int32_t d0; |
| 791 | int32_t d1; |
| 792 | int32_t N; |
| 793 | int32_t KH; |
| 794 | int32_t KW; |
| 795 | int32_t KHW; // KH * KW, pre-computed on CPU to save GPU resources |
| 796 | } ggml_metal_kargs_im2col; |
| 797 | |
| 798 | typedef struct { |
| 799 | int32_t IW; |
| 800 | int32_t IH; |
| 801 | int32_t ID; |
| 802 | int32_t OW; |
| 803 | int32_t OH; |
| 804 | int32_t OD; |
| 805 | int32_t KW; |
| 806 | int32_t KH; |
| 807 | int32_t KD; |
| 808 | int32_t s0; |
| 809 | int32_t s1; |
| 810 | int32_t s2; |
| 811 | int32_t p0; |
| 812 | int32_t p1; |
| 813 | int32_t p2; |
| 814 | int32_t d0; |
| 815 | int32_t d1; |
| 816 | int32_t d2; |
| 817 | int32_t IC; |
| 818 | int32_t N; |
| 819 | int32_t OC; |
| 820 | uint64_t nb00; |
| 821 | uint64_t nb01; |
| 822 | uint64_t nb02; |
| 823 | uint64_t nb03; |
| 824 | uint64_t nb10; |
| 825 | uint64_t nb11; |
| 826 | uint64_t nb12; |
| 827 | uint64_t nb13; |
| 828 | uint64_t nb0; |
| 829 | uint64_t nb1; |
| 830 | uint64_t nb2; |
| 831 | uint64_t nb3; |
| 832 | } ggml_metal_kargs_conv_3d; |
| 833 | |
| 834 | typedef struct{ |
| 835 | int32_t ne00; |
| 836 | uint64_t nb01; |
| 837 | int32_t ne10; |
| 838 | uint64_t nb11; |
| 839 | int32_t ne0; |
| 840 | uint64_t nb1; |
| 841 | int32_t i00; |
| 842 | int32_t i10; |
| 843 | float alpha; |
| 844 | float limit; |
| 845 | } ggml_metal_kargs_glu; |
| 846 | |
| 847 | typedef struct { |
| 848 | uint64_t np; |
| 849 | } ggml_metal_kargs_sum; |
| 850 | |
| 851 | typedef struct { |
| 852 | int64_t ne00; |
| 853 | int64_t ne01; |
| 854 | int64_t ne02; |
| 855 | int64_t ne03; |
| 856 | uint64_t nb00; |
| 857 | uint64_t nb01; |
| 858 | uint64_t nb02; |
| 859 | uint64_t nb03; |
| 860 | int64_t ne0; |
| 861 | int64_t ne1; |
| 862 | int64_t ne2; |
| 863 | int64_t ne3; |
| 864 | uint64_t nb0; |
| 865 | uint64_t nb1; |
| 866 | uint64_t nb2; |
| 867 | uint64_t nb3; |
| 868 | } ggml_metal_kargs_sum_rows; |
| 869 | |
| 870 | typedef struct { |
| 871 | int64_t ne00; |
| 872 | int64_t ne01; |
| 873 | int64_t ne02; |
| 874 | int64_t ne03; |
| 875 | uint64_t nb00; |
| 876 | uint64_t nb01; |
| 877 | uint64_t nb02; |
| 878 | uint64_t nb03; |
| 879 | int64_t net0; |
| 880 | int64_t net1; |
| 881 | int64_t net2; |
| 882 | int64_t net3; |
| 883 | uint64_t nbt0; |
| 884 | uint64_t nbt1; |
| 885 | uint64_t nbt2; |
| 886 | uint64_t nbt3; |
| 887 | bool outb; |
| 888 | } ggml_metal_kargs_cumsum_blk; |
| 889 | |
| 890 | typedef struct { |
| 891 | int64_t ne00; |
| 892 | int64_t ne01; |
| 893 | int64_t ne02; |
| 894 | int64_t ne03; |
| 895 | uint64_t nb00; |
| 896 | uint64_t nb01; |
| 897 | uint64_t nb02; |
| 898 | uint64_t nb03; |
| 899 | int64_t net0; |
| 900 | int64_t net1; |
| 901 | int64_t net2; |
| 902 | int64_t net3; |
| 903 | uint64_t nbt0; |
| 904 | uint64_t nbt1; |
| 905 | uint64_t nbt2; |
| 906 | uint64_t nbt3; |
| 907 | } ggml_metal_kargs_cumsum_add; |
| 908 | |
| 909 | typedef struct { |
| 910 | int32_t ne00; |
| 911 | int32_t ne01; |
| 912 | int32_t ne02; |
| 913 | uint64_t nb01; |
| 914 | uint64_t nb02; |
| 915 | uint64_t nb03; |
| 916 | int32_t ne11; |
| 917 | int32_t ne12; |
| 918 | int32_t ne13; |
| 919 | uint64_t nb11; |
| 920 | uint64_t nb12; |
| 921 | uint64_t nb13; |
| 922 | uint64_t nb1; |
| 923 | uint64_t nb2; |
| 924 | uint64_t nb3; |
| 925 | float scale; |
| 926 | float max_bias; |
| 927 | float m0; |
| 928 | float m1; |
| 929 | int32_t n_head_log2; |
| 930 | } ggml_metal_kargs_soft_max; |
| 931 | |
| 932 | typedef struct { |
| 933 | int64_t ne00; |
| 934 | int64_t ne01; |
| 935 | int64_t ne02; |
| 936 | uint64_t nb00; |
| 937 | uint64_t nb01; |
| 938 | uint64_t nb02; |
| 939 | int64_t ne11; |
| 940 | uint64_t nb10; |
| 941 | uint64_t nb11; |
| 942 | int64_t ne0; |
| 943 | int64_t ne1; |
| 944 | int64_t ne2; |
| 945 | uint64_t nb0; |
| 946 | uint64_t nb1; |
| 947 | uint64_t nb2; |
| 948 | } ggml_metal_kargs_ssm_conv; |
| 949 | |
| 950 | typedef struct { |
| 951 | int64_t d_state; |
| 952 | int64_t d_inner; |
| 953 | int64_t n_head; |
| 954 | int64_t n_group; |
| 955 | int64_t n_seq_tokens; |
| 956 | int64_t n_seq_tokens_total; |
| 957 | int64_t token_offset; |
| 958 | int64_t n_seqs; |
| 959 | int64_t K; |
| 960 | uint64_t s_off; |
| 961 | uint64_t nb00; |
| 962 | uint64_t nb01; |
| 963 | uint64_t nb02; |
| 964 | uint64_t nb03; |
| 965 | uint64_t nb10; |
| 966 | uint64_t nb11; |
| 967 | uint64_t nb12; |
| 968 | uint64_t ns12; |
| 969 | uint64_t nb13; |
| 970 | uint64_t nb20; |
| 971 | uint64_t nb21; |
| 972 | uint64_t ns21; |
| 973 | uint64_t nb22; |
| 974 | int64_t ne30; |
| 975 | uint64_t nb31; |
| 976 | uint64_t nb41; |
| 977 | uint64_t nb42; |
| 978 | uint64_t ns42; |
| 979 | uint64_t nb43; |
| 980 | uint64_t nb51; |
| 981 | uint64_t nb52; |
| 982 | uint64_t ns52; |
| 983 | uint64_t nb53; |
| 984 | uint64_t nb0; |
| 985 | } ggml_metal_kargs_ssm_scan; |
| 986 | |
| 987 | typedef struct { |
| 988 | int32_t ne00; |
| 989 | int32_t ne01; |
| 990 | int32_t ne02; |
| 991 | int32_t ne03; |
| 992 | uint64_t nb00; |
| 993 | uint64_t nb01; |
| 994 | uint64_t nb02; |
| 995 | uint64_t nb03; |
| 996 | int32_t ne10; |
| 997 | int32_t ne11; |
| 998 | int32_t ne12; |
| 999 | int32_t ne13; |
| 1000 | uint64_t nb10; |
| 1001 | uint64_t nb11; |
| 1002 | uint64_t nb12; |
| 1003 | uint64_t nb13; |
| 1004 | int32_t ne20; |
| 1005 | int32_t ne21; |
| 1006 | int32_t ne22; |
| 1007 | int32_t ne23; |
| 1008 | uint64_t nb20; |
| 1009 | uint64_t nb21; |
| 1010 | uint64_t nb22; |
| 1011 | uint64_t nb23; |
| 1012 | int32_t ns02; |
| 1013 | int32_t ns12; |
| 1014 | int32_t ns22; |
| 1015 | int32_t ne0; |
| 1016 | int32_t ne1; |
| 1017 | int32_t ne2; |
| 1018 | int32_t ne3; |
| 1019 | uint64_t nb0; |
| 1020 | uint64_t nb1; |
| 1021 | uint64_t nb2; |
| 1022 | uint64_t nb3; |
| 1023 | uint64_t nb_out; // 0 => snapshots are appended after the attn scores (unfused) |
| 1024 | } ggml_metal_kargs_gated_delta_net; |
| 1025 | |
| 1026 | typedef struct { |
| 1027 | int32_t ne00; |
| 1028 | int32_t ne01; |
| 1029 | int32_t ne02; |
| 1030 | int32_t ne03; |
| 1031 | uint64_t nb00; |
| 1032 | uint64_t nb01; |
| 1033 | uint64_t nb02; |
| 1034 | uint64_t nb03; |
| 1035 | int32_t ne10; |
| 1036 | int32_t ne11; |
| 1037 | int32_t ne12; |
| 1038 | int32_t ne13; |
| 1039 | uint64_t nb10; |
| 1040 | uint64_t nb11; |
| 1041 | uint64_t nb12; |
| 1042 | uint64_t nb13; |
| 1043 | int32_t ne0; |
| 1044 | int32_t ne1; |
| 1045 | int32_t ne2; |
| 1046 | int32_t ne3; |
| 1047 | uint64_t nb0; |
| 1048 | uint64_t nb1; |
| 1049 | uint64_t nb2; |
| 1050 | uint64_t nb3; |
| 1051 | } ggml_metal_kargs_solve_tri; |
| 1052 | |
| 1053 | typedef struct { |
| 1054 | int32_t ne00t; |
| 1055 | int32_t ne00; |
| 1056 | uint64_t nb01; |
| 1057 | uint64_t nb02; |
| 1058 | uint64_t nb03; |
| 1059 | int32_t ne10; |
| 1060 | uint64_t nb10; |
| 1061 | uint64_t nb11; |
| 1062 | uint64_t nb12; |
| 1063 | uint64_t nb1; |
| 1064 | uint64_t nb2; |
| 1065 | uint64_t nb3; |
| 1066 | } ggml_metal_kargs_get_rows; |
| 1067 | |
| 1068 | typedef struct { |
| 1069 | int32_t nk0; |
| 1070 | int32_t ne01; |
| 1071 | uint64_t nb01; |
| 1072 | uint64_t nb02; |
| 1073 | uint64_t nb03; |
| 1074 | int32_t ne11; |
| 1075 | int32_t ne12; |
| 1076 | uint64_t nb10; |
| 1077 | uint64_t nb11; |
| 1078 | uint64_t nb12; |
| 1079 | uint64_t nb1; |
| 1080 | uint64_t nb2; |
| 1081 | uint64_t nb3; |
| 1082 | } ggml_metal_kargs_set_rows; |
| 1083 | |
| 1084 | typedef struct { |
| 1085 | int32_t ne00; |
| 1086 | int32_t ne01; |
| 1087 | int32_t ne02; |
| 1088 | int32_t ne03; |
| 1089 | uint64_t nb00; |
| 1090 | uint64_t nb01; |
| 1091 | uint64_t nb02; |
| 1092 | uint64_t nb03; |
| 1093 | int32_t ne0; |
| 1094 | int32_t ne1; |
| 1095 | int32_t ne2; |
| 1096 | int32_t ne3; |
| 1097 | uint64_t nb0; |
| 1098 | uint64_t nb1; |
| 1099 | uint64_t nb2; |
| 1100 | uint64_t nb3; |
| 1101 | } ggml_metal_kargs_diag; |
| 1102 | |
| 1103 | typedef struct { |
| 1104 | int64_t ne00; |
| 1105 | int64_t ne01; |
| 1106 | int64_t ne02; |
| 1107 | int64_t ne03; |
| 1108 | uint64_t nb00; |
| 1109 | uint64_t nb01; |
| 1110 | uint64_t nb02; |
| 1111 | uint64_t nb03; |
| 1112 | int64_t ne0; |
| 1113 | int64_t ne1; |
| 1114 | int64_t ne2; |
| 1115 | int64_t ne3; |
| 1116 | uint64_t nb0; |
| 1117 | uint64_t nb1; |
| 1118 | uint64_t nb2; |
| 1119 | uint64_t nb3; |
| 1120 | float sf0; |
| 1121 | float sf1; |
| 1122 | float sf2; |
| 1123 | float sf3; |
| 1124 | float poffs; |
| 1125 | } ggml_metal_kargs_upscale; |
| 1126 | |
| 1127 | typedef struct { |
| 1128 | int64_t ne00; |
| 1129 | int64_t ne01; |
| 1130 | int64_t ne02; |
| 1131 | int64_t ne03; |
| 1132 | uint64_t nb00; |
| 1133 | uint64_t nb01; |
| 1134 | uint64_t nb02; |
| 1135 | uint64_t nb03; |
| 1136 | int64_t ne0; |
| 1137 | int64_t ne1; |
| 1138 | int64_t ne2; |
| 1139 | int64_t ne3; |
| 1140 | uint64_t nb0; |
| 1141 | uint64_t nb1; |
| 1142 | uint64_t nb2; |
| 1143 | uint64_t nb3; |
| 1144 | int32_t lp0; |
| 1145 | int32_t lp1; |
| 1146 | int32_t lp2; |
| 1147 | int32_t lp3; |
| 1148 | } ggml_metal_kargs_pad; |
| 1149 | |
| 1150 | typedef struct { |
| 1151 | int64_t ne00; |
| 1152 | int64_t ne01; |
| 1153 | int64_t ne02; |
| 1154 | int64_t ne03; |
| 1155 | uint64_t nb00; |
| 1156 | uint64_t nb01; |
| 1157 | uint64_t nb02; |
| 1158 | uint64_t nb03; |
| 1159 | int64_t ne0; |
| 1160 | int64_t ne1; |
| 1161 | int64_t ne2; |
| 1162 | int64_t ne3; |
| 1163 | uint64_t nb0; |
| 1164 | uint64_t nb1; |
| 1165 | uint64_t nb2; |
| 1166 | uint64_t nb3; |
| 1167 | int32_t p0; |
| 1168 | int32_t p1; |
| 1169 | } ggml_metal_kargs_pad_reflect_1d; |
| 1170 | |
| 1171 | typedef struct { |
| 1172 | int64_t ne00; |
| 1173 | int64_t ne01; |
| 1174 | int64_t ne02; |
| 1175 | int64_t ne03; |
| 1176 | uint64_t nb00; |
| 1177 | uint64_t nb01; |
| 1178 | uint64_t nb02; |
| 1179 | uint64_t nb03; |
| 1180 | int64_t ne0; |
| 1181 | int64_t ne1; |
| 1182 | int64_t ne2; |
| 1183 | int64_t ne3; |
| 1184 | uint64_t nb0; |
| 1185 | uint64_t nb1; |
| 1186 | uint64_t nb2; |
| 1187 | uint64_t nb3; |
| 1188 | int32_t s0; |
| 1189 | int32_t s1; |
| 1190 | int32_t s2; |
| 1191 | int32_t s3; |
| 1192 | } ggml_metal_kargs_roll; |
| 1193 | |
| 1194 | typedef struct { |
| 1195 | uint64_t nb1; |
| 1196 | int dim; |
| 1197 | int max_period; |
| 1198 | } ggml_metal_kargs_timestep_embedding; |
| 1199 | |
| 1200 | typedef struct { |
| 1201 | int32_t ne00; |
| 1202 | int32_t ne01; |
| 1203 | int32_t ne02; |
| 1204 | int32_t ne03; |
| 1205 | uint64_t nb00; |
| 1206 | uint64_t nb01; |
| 1207 | uint64_t nb02; |
| 1208 | uint64_t nb03; |
| 1209 | int32_t ne0; |
| 1210 | int32_t ne1; |
| 1211 | int32_t ne2; |
| 1212 | int32_t ne3; |
| 1213 | uint64_t nb0; |
| 1214 | uint64_t nb1; |
| 1215 | uint64_t nb2; |
| 1216 | uint64_t nb3; |
| 1217 | } ggml_metal_kargs_tri; |
| 1218 | |
| 1219 | typedef struct { |
| 1220 | int32_t ne00; |
| 1221 | int32_t ne01; |
| 1222 | int32_t ne02; |
| 1223 | int32_t ne03; |
| 1224 | uint64_t nb00; |
| 1225 | uint64_t nb01; |
| 1226 | uint64_t nb02; |
| 1227 | uint64_t nb03; |
| 1228 | int32_t ne0; |
| 1229 | int32_t ne1; |
| 1230 | int32_t ne2; |
| 1231 | int32_t ne3; |
| 1232 | int32_t top_k; |
| 1233 | } ggml_metal_kargs_argsort; |
| 1234 | |
| 1235 | typedef struct { |
| 1236 | int64_t ne00; |
| 1237 | int64_t ne01; |
| 1238 | int64_t ne02; |
| 1239 | int64_t ne03; |
| 1240 | uint64_t nb00; |
| 1241 | uint64_t nb01; |
| 1242 | uint64_t nb02; |
| 1243 | uint64_t nb03; |
| 1244 | int32_t ne0; |
| 1245 | int32_t ne1; |
| 1246 | int32_t ne2; |
| 1247 | int32_t ne3; |
| 1248 | int32_t top_k; |
| 1249 | int32_t len; |
| 1250 | } ggml_metal_kargs_argsort_merge; |
| 1251 | |
| 1252 | typedef struct { |
| 1253 | int32_t ne00; // number of columns (elements per row) |
| 1254 | int32_t ne01; // rows |
| 1255 | int32_t ne02; |
| 1256 | int32_t ne03; |
| 1257 | uint64_t nb01; // row stride in src0 |
| 1258 | uint64_t nb02; |
| 1259 | uint64_t nb03; |
| 1260 | int32_t top_k; // k |
| 1261 | } ggml_metal_kargs_top_k; |
| 1262 | |
| 1263 | // widths at or above this use the threadgroup FWHT kernel, one row per threadgroup |
| 1264 | // with GGML_METAL_FWHT_TG_NT threads, instead of one row per simdgroup |
| 1265 | #define GGML_METAL_FWHT_TG_MIN_N 512 |
| 1266 | #define GGML_METAL_FWHT_TG_NT 256 |
| 1267 | |
| 1268 | typedef struct { |
| 1269 | int32_t ne01; // n_tokens |
| 1270 | uint64_t nb01; // logits row stride |
| 1271 | uint64_t nb1_ids; // ids row stride |
| 1272 | float clamp; |
| 1273 | float scale; |
| 1274 | } ggml_metal_kargs_topk_moe; |
| 1275 | |
| 1276 | typedef struct { |
| 1277 | int32_t ne00; // n_embd |
| 1278 | int32_t ne02; // n_tokens |
| 1279 | } ggml_metal_kargs_moe_reduce; |
| 1280 | |
| 1281 | typedef struct { |
| 1282 | int32_t nrows; |
| 1283 | } ggml_metal_kargs_fwht; |
| 1284 | |
| 1285 | typedef struct { |
| 1286 | int64_t ne0; |
| 1287 | float start; |
| 1288 | float step; |
| 1289 | } ggml_metal_kargs_arange; |
| 1290 | |
| 1291 | typedef struct { |
| 1292 | int64_t val; |
| 1293 | } ggml_metal_kargs_memset; |
| 1294 | |
| 1295 | typedef struct { |
| 1296 | int32_t n_kv; |
| 1297 | int32_t n_batch; |
| 1298 | int32_t mask_ne3; |
| 1299 | uint64_t nb1; |
| 1300 | uint64_t nb3; |
| 1301 | uint64_t nbq1; |
| 1302 | uint64_t nbq2; |
| 1303 | uint64_t nbq3; |
| 1304 | uint64_t nbk2; |
| 1305 | uint64_t nbk3; |
| 1306 | uint64_t nbw1; |
| 1307 | uint64_t nbw3; |
| 1308 | uint64_t nbm1; |
| 1309 | uint64_t nbm3; |
| 1310 | } ggml_metal_kargs_lightning_indexer; |
| 1311 | |
| 1312 | typedef struct { |
| 1313 | int32_t n_kv; |
| 1314 | int32_t m1; |
| 1315 | int32_t m2; |
| 1316 | int32_t m3; |
| 1317 | int32_t n_top; |
| 1318 | int32_t n_pick; |
| 1319 | int32_t n_blk; |
| 1320 | int32_t n_extra; |
| 1321 | int64_t n_elems; |
| 1322 | uint64_t nb1; |
| 1323 | uint64_t nb2; |
| 1324 | uint64_t nb3; |
| 1325 | uint64_t nbm1; |
| 1326 | uint64_t nbm2; |
| 1327 | uint64_t nbm3; |
| 1328 | uint64_t nbk0; |
| 1329 | uint64_t nbk1; |
| 1330 | uint64_t nbk2; |
| 1331 | uint64_t nbk3; |
| 1332 | uint64_t nbs0; |
| 1333 | uint64_t nbs1; |
| 1334 | uint64_t nbs2; |
| 1335 | uint64_t nbs3; |
| 1336 | uint64_t nbb0; |
| 1337 | uint64_t nbb1; |
| 1338 | uint64_t nbe0; |
| 1339 | uint64_t nbe1; |
| 1340 | uint64_t nbe2; |
| 1341 | uint64_t nbe3; |
| 1342 | } ggml_metal_kargs_top_k_mask; |
| 1343 | |
| 1344 | typedef struct { |
| 1345 | int32_t n_tokens; |
| 1346 | int32_t n_iter; |
| 1347 | uint64_t nb_m0; |
| 1348 | uint64_t nb_m1; |
| 1349 | uint64_t nb_s0; |
| 1350 | uint64_t nb_b0; |
| 1351 | uint64_t nb_d0; |
| 1352 | uint64_t nb_d1; |
| 1353 | uint64_t nb_d2; |
| 1354 | float eps; |
| 1355 | } ggml_metal_kargs_dsv4_hc_comb; |
| 1356 | |
| 1357 | typedef struct { |
| 1358 | int32_t n_embd; |
| 1359 | int32_t n_tokens; |
| 1360 | uint64_t nb_x0; |
| 1361 | uint64_t nb_x1; |
| 1362 | uint64_t nb_x2; |
| 1363 | uint64_t nb_w0; |
| 1364 | uint64_t nb_w1; |
| 1365 | uint64_t nb_w2; |
| 1366 | uint64_t nb_d0; |
| 1367 | uint64_t nb_d1; |
| 1368 | float scale; |
| 1369 | } ggml_metal_kargs_dsv4_hc_pre; |
| 1370 | |
| 1371 | typedef struct { |
| 1372 | int32_t n_embd; |
| 1373 | int32_t n_tokens; |
| 1374 | uint64_t nb_x0; |
| 1375 | uint64_t nb_x1; |
| 1376 | uint64_t nb_r0; |
| 1377 | uint64_t nb_r1; |
| 1378 | uint64_t nb_r2; |
| 1379 | uint64_t nb_p0; |
| 1380 | uint64_t nb_p1; |
| 1381 | uint64_t nb_c0; |
| 1382 | uint64_t nb_c1; |
| 1383 | uint64_t nb_c2; |
| 1384 | uint64_t nb_d0; |
| 1385 | uint64_t nb_d1; |
| 1386 | uint64_t nb_d2; |
| 1387 | } ggml_metal_kargs_dsv4_hc_post; |
| 1388 | |
| 1389 | typedef struct { |
| 1390 | int32_t ne00; |
| 1391 | int32_t ne01; |
| 1392 | int32_t ne02; |
| 1393 | int32_t ne03; |
| 1394 | uint64_t nb00; |
| 1395 | uint64_t nb01; |
| 1396 | uint64_t nb02; |
| 1397 | uint64_t nb03; |
| 1398 | uint64_t nb10; |
| 1399 | uint64_t nb11; |
| 1400 | uint64_t nb12; |
| 1401 | uint64_t nb13; |
| 1402 | } ggml_metal_kargs_count_equal; |
| 1403 | |
| 1404 | typedef struct { |
| 1405 | int32_t k0; |
| 1406 | int32_t k1; |
| 1407 | int32_t s0; |
| 1408 | int32_t s1; |
| 1409 | int32_t p0; |
| 1410 | int32_t p1; |
| 1411 | int64_t IH; |
| 1412 | int64_t IW; |
| 1413 | int64_t OH; |
| 1414 | int64_t OW; |
| 1415 | int64_t np; |
| 1416 | } ggml_metal_kargs_pool_2d; |
| 1417 | |
| 1418 | typedef struct { |
| 1419 | int32_t k0; |
| 1420 | int32_t s0; |
| 1421 | int32_t p0; |
| 1422 | int64_t IW; |
| 1423 | int64_t OW; |
| 1424 | int64_t np; |
| 1425 | } ggml_metal_kargs_pool_1d; |
| 1426 | |
| 1427 | typedef struct { |
| 1428 | int64_t ne00; |
| 1429 | uint64_t nb01; |
| 1430 | int64_t npart; |
| 1431 | int64_t ne01; |
| 1432 | } ggml_metal_kargs_argmax; |
| 1433 | |
| 1434 | typedef struct { |
| 1435 | int64_t np; |
| 1436 | } ggml_metal_kargs_opt_step_adamw; |
| 1437 | |
| 1438 | typedef struct { |
| 1439 | int64_t np; |
| 1440 | } ggml_metal_kargs_opt_step_sgd; |
| 1441 | |
| 1442 | typedef struct { |
| 1443 | int64_t ne; |
| 1444 | } ggml_metal_kargs_silu_back; |
| 1445 | |
| 1446 | #endif // GGML_METAL_IMPL |