@@ -1418,15 +1418,17 @@ static void ggml_webgpu_quantize_q8_dispatch(webgpu_context &
14181418 const size_t dst_offset = ggml_webgpu_tensor_offset (dst);
14191419 const size_t q8_src1_align_offset = ROUNDUP_POW2 (
14201420 dst_offset + ggml_nbytes (dst), ctx->global_ctx ->capabilities .limits .minStorageBufferOffsetAlignment );
1421- const size_t q8_src1_binding_size =
1422- ROUNDUP_POW2 ( src1->ne [3 ] * src1->ne [2 ] * (36 /* sizeof(q8_1) */ * (src1->ne [0 ] / /* block_size */ 32 )),
1423- WEBGPU_STORAGE_BUF_BINDING_MULT );
1421+ const size_t q8_src1_binding_size = ROUNDUP_POW2 (
1422+ src1->ne [3 ] * src1->ne [2 ] * src1-> ne [ 1 ] * (36 /* sizeof(q8_1) */ * (src1->ne [0 ] / /* block_size */ 32 )),
1423+ WEBGPU_STORAGE_BUF_BINDING_MULT );
14241424
14251425 std::vector<uint32_t > q8_params = {
14261426 (uint32_t ) (ggml_webgpu_tensor_misalignment (ctx, src1) / ggml_type_size (src1->type )),
1427+ (uint32_t ) (src1->nb [1 ] / ggml_type_size (src1->type )),
14271428 (uint32_t ) (src1->nb [2 ] / ggml_type_size (src1->type )),
14281429 (uint32_t ) (src1->nb [3 ] / ggml_type_size (src1->type )),
14291430 (uint32_t ) src1->ne [0 ],
1431+ (uint32_t ) src1->ne [1 ],
14301432 (uint32_t ) src1->ne [2 ],
14311433 (uint32_t ) src1->ne [3 ],
14321434 };
@@ -1442,7 +1444,7 @@ static void ggml_webgpu_quantize_q8_dispatch(webgpu_context &
14421444 uint32_t q8_wg_x = 1 ;
14431445 uint32_t q8_wg_y = 1 ;
14441446 const uint32_t wg_per_vec = (src0->ne [0 ] / 4 + (q8_wg_size - 1 )) / q8_wg_size;
1445- const uint32_t q8_total_wg = src1->ne [2 ] * src1->ne [3 ] * wg_per_vec;
1447+ const uint32_t q8_total_wg = src1->ne [1 ] * src1-> ne [ 2 ] * src1->ne [3 ] * wg_per_vec;
14461448 const uint32_t max_wg_per_dim = ctx->global_ctx ->capabilities .limits .maxComputeWorkgroupsPerDimension ;
14471449 compute_2d_workgroups (q8_total_wg, max_wg_per_dim, q8_wg_x, q8_wg_y);
14481450
@@ -1456,7 +1458,7 @@ static webgpu_encoded_op ggml_webgpu_mul_mat(webgpu_context & ctx,
14561458 ggml_tensor * src1,
14571459 ggml_tensor * dst) {
14581460 // Determine if this is a mat-vec operation
1459- bool is_vec = (dst->ne [1 ] == 1 );
1461+ bool use_mat_vec = (dst->ne [1 ] <= 4 );
14601462
14611463 // use MMVQ path for mat-vec
14621464 bool use_mmvq = ggml_webgpu_can_use_mmvq (src0, src1, ctx->global_ctx ->capabilities .supports_dot_product ,
@@ -1482,7 +1484,7 @@ static webgpu_encoded_op ggml_webgpu_mul_mat(webgpu_context & ctx,
14821484 webgpu_pipeline pipeline;
14831485 std::vector<webgpu_dispatch_desc> dispatches;
14841486
1485- if (is_vec ) {
1487+ if (use_mat_vec ) {
14861488 if (use_mmvq) {
14871489 ggml_webgpu_quantize_q8_dispatch (ctx, src0, src1, dst, dispatches);
14881490 }
@@ -1529,7 +1531,7 @@ static webgpu_encoded_op ggml_webgpu_mul_mat(webgpu_context & ctx,
15291531 uint32_t wg_y = 1 ;
15301532 const uint32_t max_wg_per_dim = ctx->global_ctx ->capabilities .limits .maxComputeWorkgroupsPerDimension ;
15311533
1532- if (is_vec ) {
1534+ if (use_mat_vec ) {
15331535 auto * decisions = static_cast <ggml_webgpu_mul_mat_vec_shader_decisions *>(pipeline.context .get ());
15341536
15351537 uint32_t batches = dst->ne [2 ] * dst->ne [3 ];
@@ -3691,8 +3693,8 @@ static size_t ggml_backend_webgpu_buffer_type_get_alloc_size(ggml_backend_buffer
36913693 ggml_webgpu_can_use_mmvq (src0, src1, ctx->webgpu_global_ctx ->capabilities .supports_dot_product ,
36923694 ctx->webgpu_global_ctx ->vendor );
36933695 if (use_mmvq) {
3694- const size_t q8_src1_size =
3695- src1-> ne [ 3 ] * src1-> ne [ 2 ] * (36 /* sizeof(q8_1) */ * (src1->ne [0 ] / /* block_size */ 32 ));
3696+ const size_t q8_src1_size = src1-> ne [ 3 ] * src1-> ne [ 2 ] * src1-> ne [ 1 ] *
3697+ (36 /* sizeof(q8_1) */ * (src1->ne [0 ] / /* block_size */ 32 ));
36963698 res = ROUNDUP_POW2 (res + q8_src1_size +
36973699 ctx->webgpu_global_ctx ->capabilities .limits .minStorageBufferOffsetAlignment ,
36983700 WEBGPU_STORAGE_BUF_BINDING_MULT );
0 commit comments