Skip to content

Commit bcc24c7

Browse files
committed
vulkan : support conv_2d_dw with f16 weights
1 parent 21c17b5 commit bcc24c7

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

ggml/src/ggml-vulkan/ggml-vulkan.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,8 @@ struct vk_device_struct {
529529
vk_pipeline pipeline_opt_step_sgd_f32;
530530
vk_pipeline pipeline_conv2d_f32[CONV_SHAPE_COUNT];
531531
vk_pipeline pipeline_conv2d_f16_f32[CONV_SHAPE_COUNT];
532-
vk_pipeline pipeline_conv2d_dw_whcn_f32;
533-
vk_pipeline pipeline_conv2d_dw_cwhn_f32;
532+
vk_pipeline pipeline_conv2d_dw_whcn_f32, pipeline_conv2d_dw_whcn_f16_f32;
533+
vk_pipeline pipeline_conv2d_dw_cwhn_f32, pipeline_conv2d_dw_cwhn_f16_f32;
534534

535535
// [2][2][2] is for {f16acc,f32acc}x{large,small_rows}x{unaligned, aligned}
536536
vk_pipeline pipeline_flash_attn_f32_f16_cm2[GGML_TYPE_COUNT][FA_HEAD_SIZE_COUNT][2][2][2];
@@ -3251,6 +3251,8 @@ static void ggml_vk_load_shaders(vk_device& device) {
32513251

32523252
ggml_vk_create_pipeline(device, device->pipeline_conv2d_dw_whcn_f32, "conv2d_dw_whcn_f32", conv2d_dw_whcn_f32_len, conv2d_dw_whcn_f32_data, "main", 3, sizeof(vk_op_conv2d_dw_push_constants), {512, 1, 1}, {}, 1);
32533253
ggml_vk_create_pipeline(device, device->pipeline_conv2d_dw_cwhn_f32, "conv2d_dw_cwhn_f32", conv2d_dw_cwhn_f32_len, conv2d_dw_cwhn_f32_data, "main", 3, sizeof(vk_op_conv2d_dw_push_constants), {512, 1, 1}, {}, 1);
3254+
ggml_vk_create_pipeline(device, device->pipeline_conv2d_dw_whcn_f16_f32, "conv2d_dw_whcn_f16_f32", conv2d_dw_whcn_f16_f32_len, conv2d_dw_whcn_f16_f32_data, "main", 3, sizeof(vk_op_conv2d_dw_push_constants), {512, 1, 1}, {}, 1);
3255+
ggml_vk_create_pipeline(device, device->pipeline_conv2d_dw_cwhn_f16_f32, "conv2d_dw_cwhn_f16_f32", conv2d_dw_cwhn_f16_f32_len, conv2d_dw_cwhn_f16_f32_data, "main", 3, sizeof(vk_op_conv2d_dw_push_constants), {512, 1, 1}, {}, 1);
32543256

32553257
for (auto &c : compiles) {
32563258
c.wait();
@@ -7306,6 +7308,12 @@ static vk_pipeline ggml_vk_op_get_pipeline(ggml_backend_vk_context * ctx, const
73067308
} else if (ggml_is_contiguous_channels(src1)) {
73077309
return ctx->device->pipeline_conv2d_dw_cwhn_f32;
73087310
}
7311+
} else if (src0->type == GGML_TYPE_F16 && dst->type == GGML_TYPE_F32) {
7312+
if (ggml_is_contiguous(src1)) {
7313+
return ctx->device->pipeline_conv2d_dw_whcn_f16_f32;
7314+
} else if (ggml_is_contiguous_channels(src1)) {
7315+
return ctx->device->pipeline_conv2d_dw_cwhn_f16_f32;
7316+
}
73097317
}
73107318
return nullptr;
73117319
default:

ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,8 @@ void process_shaders() {
677677

678678
string_to_spv("conv2d_dw_whcn_f32", "conv2d_dw.comp", merge_maps(base_dict, {{"A_TYPE", "float"}, {"B_TYPE", "float"}, {"D_TYPE", "float"}, {"WHCN", "1"}}));
679679
string_to_spv("conv2d_dw_cwhn_f32", "conv2d_dw.comp", merge_maps(base_dict, {{"A_TYPE", "float"}, {"B_TYPE", "float"}, {"D_TYPE", "float"}, {"CWHN", "1"}}));
680+
string_to_spv("conv2d_dw_whcn_f16_f32", "conv2d_dw.comp", merge_maps(base_dict, {{"A_TYPE", "float16_t"}, {"B_TYPE", "float"}, {"D_TYPE", "float"}, {"WHCN", "1"}}));
681+
string_to_spv("conv2d_dw_cwhn_f16_f32", "conv2d_dw.comp", merge_maps(base_dict, {{"A_TYPE", "float16_t"}, {"B_TYPE", "float"}, {"D_TYPE", "float"}, {"CWHN", "1"}}));
680682

681683
string_to_spv("roll_f32", "roll.comp", merge_maps(base_dict, {{"A_TYPE", "float"}, {"D_TYPE", "float"}}));
682684

0 commit comments

Comments
 (0)