@@ -2923,6 +2923,15 @@ inline bool ggml_sycl_supports_mmq(enum ggml_type type) {
29232923 return false ;
29242924}
29252925
2926+ inline bool ggml_sycl_supports_reorder_mmvq (enum ggml_type type) {
2927+ switch (type) {
2928+ case GGML_TYPE_Q4_0:
2929+ return true ;
2930+ default :
2931+ return false ;
2932+ }
2933+ }
2934+
29262935static bool ggml_sycl_supports_dmmv (enum ggml_type type) {
29272936 switch (type) {
29282937 case GGML_TYPE_Q4_0:
@@ -2942,13 +2951,14 @@ static bool ggml_sycl_supports_dmmv(enum ggml_type type) {
29422951 }
29432952}
29442953
2945- static void ggml_sycl_mul_mat (ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
2946-
2947- const bool split = ggml_backend_buffer_is_sycl_split (src0->buffer );
2948- int64_t min_compute_capability = INT_MAX;
2954+ static void ggml_sycl_mul_mat (ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1,
2955+ ggml_tensor * dst) {
2956+ const bool split = ggml_backend_buffer_is_sycl_split (src0->buffer );
2957+ int64_t min_compute_capability = INT_MAX;
29492958
29502959 if (split) {
2951- ggml_backend_sycl_split_buffer_type_context * buft_ctx = (ggml_backend_sycl_split_buffer_type_context *) src0->buffer ->buft ->context ;
2960+ ggml_backend_sycl_split_buffer_type_context * buft_ctx =
2961+ (ggml_backend_sycl_split_buffer_type_context *) src0->buffer ->buft ->context ;
29522962 auto & tensor_split = buft_ctx->tensor_split ;
29532963 for (int id = 0 ; id < ggml_sycl_info ().device_count ; ++id) {
29542964 // skip devices that are not going to do any work:
@@ -2961,7 +2971,7 @@ static void ggml_sycl_mul_mat(ggml_backend_sycl_context & ctx, const ggml_tensor
29612971 }
29622972 }
29632973 } else {
2964- min_compute_capability = ggml_sycl_info ().devices [ctx.device ].cc ;
2974+ min_compute_capability = ggml_sycl_info ().devices [ctx.device ].cc ;
29652975 }
29662976
29672977 // check data types and tensor shapes for custom matrix multiplication kernels:
@@ -2984,8 +2994,13 @@ static void ggml_sycl_mul_mat(ggml_backend_sycl_context & ctx, const ggml_tensor
29842994#endif // SYCL_USE_XMX
29852995
29862996 // mmvq path is faster in the CUDA backend.
2987- if (ctx.stream ()->get_backend () == sycl::backend::ext_oneapi_cuda)
2997+ if (ctx.stream ()->get_backend () == sycl::backend::ext_oneapi_cuda
2998+ // Dispatch becomes obscure with the reorder, MMVQ when the reorder optimization
2999+ // is enabled takes precedence over DMMV, the current if-else implementation
3000+ // requires disabling DMMV if both conditions are met
3001+ || (ctx.opt_feature .reorder && ggml_sycl_supports_reorder_mmvq (src0->type ))) {
29883002 use_dequantize_mul_mat_vec = use_dequantize_mul_mat_vec && !use_mul_mat_vec_q;
3003+ }
29893004
29903005 if (!split && src0->type == GGML_TYPE_F16 && ggml_is_permuted (src0) && ggml_is_permuted (src1) && src1->ne [1 ] == 1 ) {
29913006 // TODO: Refactor and cleanup of mul mat dispatching.
@@ -3004,14 +3019,17 @@ static void ggml_sycl_mul_mat(ggml_backend_sycl_context & ctx, const ggml_tensor
30043019 // KQ + KQV multi-batch
30053020 ggml_sycl_mul_mat_batched_sycl (ctx, src0, src1, dst);
30063021 } else if (use_dequantize_mul_mat_vec) {
3007- ggml_sycl_op_mul_mat (ctx, src0, src1, dst, ggml_sycl_op_dequantize_mul_mat_vec, false ) ;
3008- // save_tensor_txt("1/dst_1.txt", (float*) dst->data, src0->ne[1], sizeof(float), ctx.stream() );
3022+ constexpr bool convert_src1_to_q8_1 = false ;
3023+ ggml_sycl_op_mul_mat (ctx, src0, src1, dst, ggml_sycl_op_dequantize_mul_mat_vec, convert_src1_to_q8_1 );
30093024 } else if (use_mul_mat_vec_q) {
3010- ggml_sycl_op_mul_mat (ctx, src0, src1, dst, ggml_sycl_op_mul_mat_vec_q, true );
3025+ constexpr bool convert_src1_to_q8_1 = true ;
3026+ ggml_sycl_op_mul_mat (ctx, src0, src1, dst, ggml_sycl_op_mul_mat_vec_q, convert_src1_to_q8_1);
30113027 } else if (use_mul_mat_q) {
3012- ggml_sycl_op_mul_mat (ctx, src0, src1, dst, ggml_sycl_op_mul_mat_q, true );
3028+ constexpr bool convert_src1_to_q8_1 = true ;
3029+ ggml_sycl_op_mul_mat (ctx, src0, src1, dst, ggml_sycl_op_mul_mat_q, convert_src1_to_q8_1);
30133030 } else {
3014- ggml_sycl_op_mul_mat (ctx, src0, src1, dst, ggml_sycl_op_mul_mat_sycl, false );
3031+ constexpr bool convert_src1_to_q8_1 = false ;
3032+ ggml_sycl_op_mul_mat (ctx, src0, src1, dst, ggml_sycl_op_mul_mat_sycl, convert_src1_to_q8_1);
30153033 }
30163034}
30173035
0 commit comments