metal : add concat support for quantized types (#28116)

Assisted-by: pi:llama.cpp/DeepSeek-V4-Flash-0731
This commit is contained in:
Georgi Gerganov
2026-08-31 23:16:04 +03:00
committed by GitHub
parent 85c55223ca
commit ab0b3bd3c8
3 changed files with 71 additions and 4 deletions
+20 -4
View File
@@ -552,8 +552,24 @@ int ggml_metal_op_concat(ggml_metal_op_t ctx, int idx) {
const int32_t dim = ((const int32_t *) op->op_params)[0];
const bool is_q = ggml_is_quantized(op->type);
// for quantized types, concat is done at the block level (nb0 == type_size == block size)
int32_t ne00_arg = ne00;
int32_t ne10_arg = ne10;
int32_t ne0_arg = ne0;
if (is_q) {
const int32_t blck = ggml_blck_size(op->type);
GGML_ASSERT(ne00 % blck == 0);
GGML_ASSERT(ne10 % blck == 0);
GGML_ASSERT(ne0 % blck == 0);
ne00_arg = ne00/blck;
ne10_arg = ne10/blck;
ne0_arg = ne0/blck;
}
ggml_metal_kargs_concat args = {
/*.ne00 =*/ ne00,
/*.ne00 =*/ ne00_arg,
/*.ne01 =*/ ne01,
/*.ne02 =*/ ne02,
/*.ne03 =*/ ne03,
@@ -561,7 +577,7 @@ int ggml_metal_op_concat(ggml_metal_op_t ctx, int idx) {
/*.nb01 =*/ nb01,
/*.nb02 =*/ nb02,
/*.nb03 =*/ nb03,
/*.ne10 =*/ ne10,
/*.ne10 =*/ ne10_arg,
/*.ne11 =*/ ne11,
/*.ne12 =*/ ne12,
/*.ne13 =*/ ne13,
@@ -569,7 +585,7 @@ int ggml_metal_op_concat(ggml_metal_op_t ctx, int idx) {
/*.nb11 =*/ nb11,
/*.nb12 =*/ nb12,
/*.nb13 =*/ nb13,
/*.ne0 =*/ ne0,
/*.ne0 =*/ ne0_arg,
/*.ne1 =*/ ne1,
/*.ne2 =*/ ne2,
/*.ne3 =*/ ne3,
@@ -588,7 +604,7 @@ int ggml_metal_op_concat(ggml_metal_op_t ctx, int idx) {
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[1]), 2);
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), 3);
int nth = std::min(256, ne0);
int nth = std::min(256, ne0_arg);
// when rows are small, we can batch them together in a single threadgroup
int nrptg = 1;