|
|
|
@ -1,8 +1,9 @@
|
|
|
|
|
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
|
|
|
|
|
__constant sampler_t smp_zero = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST;
|
|
|
|
|
__kernel void DepthwiseConv2d_IMG_NC4HW4(__read_only image2d_t src_data, __global FLT4 *filter, __global FLT4 *bias,
|
|
|
|
|
float relu_clip, __write_only image2d_t dst_data, int2 kernel_size,
|
|
|
|
|
int2 stride, int2 padding, int2 dilation, int4 src_size, int4 dst_size) {
|
|
|
|
|
__write_only image2d_t dst_data, int2 kernel_size,
|
|
|
|
|
int2 stride, int2 padding, int2 dilation, int4 src_size, int4 dst_size,
|
|
|
|
|
float relu_clip_min, float relu_clip_max) {
|
|
|
|
|
int X = get_global_id(0);
|
|
|
|
|
int Y = get_global_id(1);
|
|
|
|
|
int Z = get_global_id(2);
|
|
|
|
@ -27,13 +28,14 @@ __kernel void DepthwiseConv2d_IMG_NC4HW4(__read_only image2d_t src_data, __globa
|
|
|
|
|
}
|
|
|
|
|
FLT4 bias_p = bias[Z];
|
|
|
|
|
FLT4 res = TO_FLT4(r) + bias_p;
|
|
|
|
|
res = clamp(res, (FLT)(0.0f), (FLT)(relu_clip));
|
|
|
|
|
res = clamp(res, (FLT)(relu_clip_min), (FLT)(relu_clip_max));
|
|
|
|
|
WRITE_IMAGE(dst_data, (int2)(X, (Z * dst_size.y + Y)), res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__kernel void DepthwiseConv2d_IMG_NHWC4(__read_only image2d_t src_data, __global FLT4 *filter, __global FLT4 *bias,
|
|
|
|
|
float relu_clip, __write_only image2d_t dst_data, int2 kernel_size,
|
|
|
|
|
int2 stride, int2 padding, int2 dilation, int4 src_size, int4 dst_size) {
|
|
|
|
|
__write_only image2d_t dst_data, int2 kernel_size,
|
|
|
|
|
int2 stride, int2 padding, int2 dilation, int4 src_size, int4 dst_size,
|
|
|
|
|
float relu_clip_min, float relu_clip_max) {
|
|
|
|
|
int X = get_global_id(0);
|
|
|
|
|
int Y = get_global_id(1);
|
|
|
|
|
int Z = get_global_id(2);
|
|
|
|
@ -58,13 +60,14 @@ __kernel void DepthwiseConv2d_IMG_NHWC4(__read_only image2d_t src_data, __global
|
|
|
|
|
}
|
|
|
|
|
FLT4 bias_p = bias[Z];
|
|
|
|
|
FLT4 res = TO_FLT4(r) + bias_p;
|
|
|
|
|
res = clamp(res, (FLT)(0.0f), (FLT)(relu_clip));
|
|
|
|
|
res = clamp(res, (FLT)(relu_clip_min), (FLT)(relu_clip_max));
|
|
|
|
|
WRITE_IMAGE(dst_data, (int2)(X * dst_size.z + Z, Y), res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__kernel void DepthwiseConv2d_IMG_NHWC4_1x1(__read_only image2d_t src_data, __global FLT4 *filter, __global FLT4 *bias,
|
|
|
|
|
float relu_clip, __write_only image2d_t dst_data, int2 kernel_size,
|
|
|
|
|
int2 stride, int2 padding, int2 dilation, int4 src_size, int4 dst_size) {
|
|
|
|
|
__write_only image2d_t dst_data, int2 kernel_size, int2 stride,
|
|
|
|
|
int2 padding, int2 dilation, int4 src_size, int4 dst_size,
|
|
|
|
|
float relu_clip_min, float relu_clip_max) {
|
|
|
|
|
int X = get_global_id(0);
|
|
|
|
|
int Y = get_global_id(1);
|
|
|
|
|
int Z = get_global_id(2);
|
|
|
|
@ -81,7 +84,6 @@ __kernel void DepthwiseConv2d_IMG_NHWC4_1x1(__read_only image2d_t src_data, __gl
|
|
|
|
|
bool outside_x = x_c < 0 || x_c >= src_size.x;
|
|
|
|
|
if (!outside_x && !outside_y) {
|
|
|
|
|
FLT4 flt_p = filter[fx_c];
|
|
|
|
|
// FLT4 src_p =src_data[((y_c * src_size.x + x_c) * src_size.z + Z)];
|
|
|
|
|
FLT4 src_p = READ_IMAGE(src_data, smp_zero, (int2)(Z, (y_c * src_size.x + x_c) * src_size.z));
|
|
|
|
|
r += TO_FLT4(src_p * flt_p);
|
|
|
|
|
}
|
|
|
|
@ -89,13 +91,13 @@ __kernel void DepthwiseConv2d_IMG_NHWC4_1x1(__read_only image2d_t src_data, __gl
|
|
|
|
|
}
|
|
|
|
|
FLT4 bias_p = bias[Z];
|
|
|
|
|
FLT4 res = TO_FLT4(r) + bias_p;
|
|
|
|
|
res = clamp(res, (FLT)(0.0f), (FLT)(relu_clip));
|
|
|
|
|
// dst_data[((Y * dst_size.x + X) * dst_size.z + Z)] = res;
|
|
|
|
|
res = clamp(res, (FLT)(relu_clip_min), (FLT)(relu_clip_max));
|
|
|
|
|
WRITE_IMAGE(dst_data, (int2)(Z, (Y * dst_size.x + X) * dst_size.z), res);
|
|
|
|
|
}
|
|
|
|
|
__kernel void DepthwiseConv2d_BUF_NC4HW4(__global FLT4 *src_data, __global FLT4 *filter, __global FLT4 *bias,
|
|
|
|
|
float relu_clip, __global FLT4 *dst_data, int2 kernel_size, int2 stride,
|
|
|
|
|
int2 padding, int2 dilation, int4 src_size, int4 dst_size) {
|
|
|
|
|
__global FLT4 *dst_data, int2 kernel_size, int2 stride,
|
|
|
|
|
int2 padding, int2 dilation, int4 src_size, int4 dst_size,
|
|
|
|
|
float relu_clip_min, float relu_clip_max) {
|
|
|
|
|
int X = get_global_id(0);
|
|
|
|
|
int Y = get_global_id(1);
|
|
|
|
|
int Z = get_global_id(2);
|
|
|
|
@ -120,13 +122,14 @@ __kernel void DepthwiseConv2d_BUF_NC4HW4(__global FLT4 *src_data, __global FLT4
|
|
|
|
|
}
|
|
|
|
|
FLT4 bias_p = bias[Z];
|
|
|
|
|
FLT4 res = TO_FLT4(r) + bias_p;
|
|
|
|
|
res = clamp(res, (FLT)(0.0f), (FLT)(relu_clip));
|
|
|
|
|
res = clamp(res, (FLT)(relu_clip_min), (FLT)(relu_clip_max));
|
|
|
|
|
dst_data[(((Z)*dst_size.y + (Y)) * dst_size.x + (X))] = res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__kernel void DepthwiseConv2d_BUF_NHWC4(__global FLT4 *src_data, __global FLT4 *filter, __global FLT4 *bias,
|
|
|
|
|
float relu_clip, __global FLT4 *dst_data, int2 kernel_size, int2 stride,
|
|
|
|
|
int2 padding, int2 dilation, int4 src_size, int4 dst_size) {
|
|
|
|
|
__global FLT4 *dst_data, int2 kernel_size, int2 stride,
|
|
|
|
|
int2 padding, int2 dilation, int4 src_size, int4 dst_size,
|
|
|
|
|
float relu_clip_min, float relu_clip_max) {
|
|
|
|
|
int X = get_global_id(0);
|
|
|
|
|
int Y = get_global_id(1);
|
|
|
|
|
int Z = get_global_id(2);
|
|
|
|
@ -151,13 +154,14 @@ __kernel void DepthwiseConv2d_BUF_NHWC4(__global FLT4 *src_data, __global FLT4 *
|
|
|
|
|
}
|
|
|
|
|
FLT4 bias_p = bias[Z];
|
|
|
|
|
FLT4 res = TO_FLT4(r) + bias_p;
|
|
|
|
|
res = clamp(res, (FLT)(0.0f), (FLT)(relu_clip));
|
|
|
|
|
res = clamp(res, (FLT)(relu_clip_min), (FLT)(relu_clip_max));
|
|
|
|
|
dst_data[((Y * dst_size.x + X) * dst_size.z + Z)] = res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__kernel void DepthwiseConv2d_BUF_NHWC4_1x1(__global FLT4 *src_data, __global FLT4 *filter, __global FLT4 *bias,
|
|
|
|
|
float relu_clip, __global FLT4 *dst_data, int2 kernel_size, int2 stride,
|
|
|
|
|
int2 padding, int2 dilation, int4 src_size, int4 dst_size) {
|
|
|
|
|
__global FLT4 *dst_data, int2 kernel_size, int2 stride,
|
|
|
|
|
int2 padding, int2 dilation, int4 src_size, int4 dst_size,
|
|
|
|
|
float relu_clip_min, float relu_clip_max) {
|
|
|
|
|
int X = get_global_id(0);
|
|
|
|
|
int Y = get_global_id(1);
|
|
|
|
|
int Z = get_global_id(2);
|
|
|
|
@ -181,6 +185,6 @@ __kernel void DepthwiseConv2d_BUF_NHWC4_1x1(__global FLT4 *src_data, __global FL
|
|
|
|
|
}
|
|
|
|
|
FLT4 bias_p = bias[Z];
|
|
|
|
|
FLT4 res = TO_FLT4(r) + bias_p;
|
|
|
|
|
res = clamp(res, (FLT)(0.0f), (FLT)(relu_clip));
|
|
|
|
|
res = clamp(res, (FLT)(relu_clip_min), (FLT)(relu_clip_max));
|
|
|
|
|
dst_data[((Y * dst_size.x + X) * dst_size.z + Z)] = res;
|
|
|
|
|
}
|
|
|
|
|