@@ -145,8 +145,15 @@ static void ggml_vk_destroy_pipeline(vk::Device& device, vk_pipeline& pipeline);
145145struct vk_matmul_pipeline_struct {
146146    vk_pipeline l, m, s;
147147    vk_pipeline a_l, a_m, a_s;
148+     // Returns true when all member pipelines are null
149+     bool is_empty() const;
148150};
149151
152+ bool vk_matmul_pipeline_struct::is_empty() const {
153+     return l == nullptr && m == nullptr && s == nullptr &&
154+         a_l == nullptr && a_m == nullptr && a_s == nullptr;
155+ }
156+ 
150157typedef std::shared_ptr<vk_matmul_pipeline_struct> vk_matmul_pipeline;
151158
152159struct vk_matmul_pipeline2 {
@@ -4930,7 +4937,7 @@ static vk_matmul_pipeline ggml_vk_get_mul_mat_mat_pipeline(ggml_backend_vk_conte
49304937    if (src1_type == GGML_TYPE_Q8_1) {
49314938        vk_matmul_pipeline pipelines = (ctx->device->fp16 && prec == GGML_PREC_DEFAULT) ? ctx->device->pipeline_dequant_mul_mat_mat_q8_1[src0_type].f16acc : ctx->device->pipeline_dequant_mul_mat_mat_q8_1[src0_type].f32acc;
49324939
4933-         if (pipelines->s == nullptr && pipelines->m == nullptr && pipelines->l == nullptr ) {
4940+         if (pipelines->is_empty() ) {
49344941            return nullptr;
49354942        }
49364943
@@ -5103,24 +5110,18 @@ static vk_matmul_pipeline ggml_vk_get_mul_mat_mat_id_pipeline(ggml_backend_vk_co
51035110            return nullptr;
51045111    }
51055112
5113+     vk_matmul_pipeline2& mmp = ctx->device->pipeline_dequant_mul_mat_mat_id[src0_type];
51065114    // XXX TODO 'prec' is not actually allowed in mul_mat_id.
51075115    bool prefer_fp16acc = ctx->device->fp16 /*&& prec == GGML_PREC_DEFAULT*/;
5108-     auto& mmp = ctx->device->pipeline_dequant_mul_mat_mat_id[src0_type];
5109-     if (ctx->device->coopmat_support) {
5110-         // coopmat may or may not have f16acc and f32acc. It may also lack some child pipelines
5111-         if (ctx->device->coopmat_acc_f16_support && prefer_fp16acc) {
5112-             return mmp.f16acc;
5113-         } else if (ctx->device->coopmat_acc_f32_support) {
5114-             return mmp.f32acc;
5115-         } else {
5116-             // f16acc nor f32acc is supported so we just abort
5117-             GGML_ASSERT(false);
5118-         }
5116+     bool support_fp16acc = !mmp.f16acc->is_empty();
5117+     bool support_fp32acc = !mmp.f32acc->is_empty();
5118+ 
5119+     if (support_fp16acc && (prefer_fp16acc || !support_fp32acc)) {
5120+         return mmp.f16acc;
5121+     } else {
5122+         GGML_ASSERT(support_fp32acc);
5123+         return mmp.f32acc;
51195124    }
5120-     // coopmat2 or no coopmat comes here.
5121-     // coopmat2 should support both f16acc and f32acc by default with all child pipelines.
5122-     // No coopmat should support both f16acc and f32acc when FP16 is preferred, but only f32acc when FP16 is not preferred.
5123-     return prefer_fp16acc ? mmp.f16acc : mmp.f32acc;
51245125}
51255126
51265127static vk_pipeline ggml_vk_get_dequantize_mul_mat_vec_id(ggml_backend_vk_context * ctx, ggml_type a_type, ggml_type b_type) {
0 commit comments