@@ -71,8 +71,8 @@ struct dw_cwhn_layout {
7171 }
7272};
7373
74- template <typename Layout>
75- static void conv2d_dw_kernel (const float * input, const float * kernel, float * output,
74+ template <typename KernelT, typename Layout>
75+ static void conv2d_dw_kernel (const float * input, const KernelT * kernel, float * output,
7676 const conv2d_dw_params p, const sycl::nd_item<3 > & item_ct1) {
7777 const int global_idx = item_ct1.get_local_id (2 ) +
7878 item_ct1.get_group (2 ) * item_ct1.get_local_range (2 );
@@ -93,23 +93,23 @@ static void conv2d_dw_kernel(const float * input, const float * kernel, float *
9393 for (int kx = bounds.x_min ; kx < bounds.x_max ; ++kx) {
9494 const int in_x = dw_calculate_input_coord (out_x, kx, p.stride_x , p.dilation_x , p.padding_x );
9595 acc += input[Layout::input_index (n, c, in_y, in_x, p)] *
96- kernel[Layout::kernel_index (c, ky, kx, p)];
96+ static_cast < float >( kernel[Layout::kernel_index (c, ky, kx, p)]) ;
9797 }
9898 }
9999
100100 output[Layout::output_index (n, c, out_y, out_x, p)] = acc;
101101}
102102
103- template <typename Layout>
104- static void conv2d_dw_sycl (const float * x_d, const float * w_d, float * y_d,
103+ template <typename KernelT, typename Layout>
104+ static void conv2d_dw_sycl (const float * x_d, const KernelT * w_d, float * y_d,
105105 const conv2d_dw_params p, const queue_ptr & stream) {
106106 const int total = p.batches * p.channels * p.out_h * p.out_w ;
107107 const int num_blocks = (total + SYCL_CONV2D_DW_BLOCK_SIZE - 1 ) / SYCL_CONV2D_DW_BLOCK_SIZE ;
108108 const sycl::range<3 > block_dims (1 , 1 , SYCL_CONV2D_DW_BLOCK_SIZE );
109109 const sycl::range<3 > block_nums (1 , 1 , num_blocks);
110110 stream->parallel_for (sycl::nd_range<3 >(block_nums * block_dims, block_dims),
111111 [=](sycl::nd_item<3 > item_ct1) {
112- conv2d_dw_kernel<Layout>(x_d, w_d, y_d, p, item_ct1);
112+ conv2d_dw_kernel<KernelT, Layout>(x_d, w_d, y_d, p, item_ct1);
113113 });
114114}
115115
@@ -119,9 +119,9 @@ void ggml_sycl_op_conv2d_dw(ggml_backend_sycl_context & ctx, ggml_tensor * dst)
119119 const ggml_tensor * kernel = dst->src [0 ];
120120 const ggml_tensor * input = dst->src [1 ];
121121
122- GGML_ASSERT (kernel->type == GGML_TYPE_F32 && input->type == GGML_TYPE_F32 && dst->type == GGML_TYPE_F32 );
122+ GGML_ASSERT ((kernel->type == GGML_TYPE_F32 || kernel->type == GGML_TYPE_F16 ) &&
123+ input->type == GGML_TYPE_F32 && dst->type == GGML_TYPE_F32 );
123124
124- const float * w_d = (const float *) kernel->data ;
125125 const float * x_d = (const float *) input->data ;
126126 float * y_d = (float *) dst->data ;
127127
@@ -148,11 +148,23 @@ void ggml_sycl_op_conv2d_dw(ggml_backend_sycl_context & ctx, ggml_tensor * dst)
148148
149149 const queue_ptr stream = ctx.stream ();
150150
151- if (ggml_is_contiguous (input)) {
152- conv2d_dw_sycl<dw_whcn_layout>(x_d, w_d, y_d, params, stream);
153- } else if (ggml_is_contiguous_channels (input)) {
154- conv2d_dw_sycl<dw_cwhn_layout>(x_d, w_d, y_d, params, stream);
151+ if (kernel->type == GGML_TYPE_F16 ) {
152+ const sycl::half * w_d = (const sycl::half *) kernel->data ;
153+ if (ggml_is_contiguous (input)) {
154+ conv2d_dw_sycl<sycl::half, dw_whcn_layout>(x_d, w_d, y_d, params, stream);
155+ } else if (ggml_is_contiguous_channels (input)) {
156+ conv2d_dw_sycl<sycl::half, dw_cwhn_layout>(x_d, w_d, y_d, params, stream);
157+ } else {
158+ GGML_ABORT (" Unsupported memory layout for conv2d_dw" );
159+ }
155160 } else {
156- GGML_ABORT (" Unsupported memory layout for conv2d_dw" );
161+ const float * w_d = (const float *) kernel->data ;
162+ if (ggml_is_contiguous (input)) {
163+ conv2d_dw_sycl<float , dw_whcn_layout>(x_d, w_d, y_d, params, stream);
164+ } else if (ggml_is_contiguous_channels (input)) {
165+ conv2d_dw_sycl<float , dw_cwhn_layout>(x_d, w_d, y_d, params, stream);
166+ } else {
167+ GGML_ABORT (" Unsupported memory layout for conv2d_dw" );
168+ }
157169 }
158170}
0 commit comments