From d60a6b9d7977c6bd63ff7c523bed84d42363898b Mon Sep 17 00:00:00 2001 From: Gian Marco Iodice Date: Thu, 10 Aug 2017 10:43:40 +0100 Subject: COMPMID-477 - Optimized CLNormalizationLayer CLPixelWiseMultiplication has been removed within the function Change-Id: Ibe7edd7921d5cef6ff68fdeeca89771129a8eaea Reviewed-on: http://mpd-gerrit.cambridge.arm.com/84459 Reviewed-by: Anthony Barbier Tested-by: Kaizen Reviewed-by: Georgios Pinitas --- src/core/CL/cl_kernels/normalization_layer.cl | 120 +++++++++++--------------- 1 file changed, 51 insertions(+), 69 deletions(-) (limited to 'src/core/CL/cl_kernels/normalization_layer.cl') diff --git a/src/core/CL/cl_kernels/normalization_layer.cl b/src/core/CL/cl_kernels/normalization_layer.cl index e2a5c4079a..4e65560b95 100644 --- a/src/core/CL/cl_kernels/normalization_layer.cl +++ b/src/core/CL/cl_kernels/normalization_layer.cl @@ -54,43 +54,33 @@ * * @note Datatype should be given as a preprocessor argument using -DDATA_TYPE=type. e.g. -DDATA_TYPE=short * @note Vector size should be given as a preprocessor argument using -DVEC_SIZE=size, e.g. -DVEC_SIZE=16 + * @note The radius should be given as a preprocessor argument using -DRADIUS=size. e.g. -DRADIUS=5 + * @note The number of slices should be given as a preprocessor argument using -DNUM_SLICES=size. e.g. -DNUM_SLICES=192 * @note In case of fixed-point operation -DFIXED_POINT_POSITION=fixed_point_position must be provided: e.g. -DFIXED_POINT_POSITION=3 * @note Scaling coefficient (= alpha/norm_size), beta and kappa need to be passed at compile time using -DCOEFF, -DALPHA and -DKAPPA * - * @param[in] input_ptr Pointer to the first source tensor. Supported data types: QS8/QS16/F16/F32 - * @param[in] input_stride_x Stride of the first source tensor in X dimension (in bytes) - * @param[in] input_step_x input_stride_x * number of elements along X processed per workitem(in bytes) - * @param[in] input_stride_y Stride of the first source tensor in Y dimension (in bytes) - * @param[in] input_step_y input_stride_y * number of elements along Y processed per workitem(in bytes) - * @param[in] input_stride_z Stride of the first source tensor in Z dimension (in bytes) - * @param[in] input_step_z input_stride_z * number of elements along Z processed per workitem(in bytes) - * @param[in] input_offset_first_element_in_bytes The offset of the first element in the first source tensor - * @param[in] squared_input_ptr Pointer to the second source tensor. Supported data types: same as @p input_ptr - * @param[in] squared_input_stride_x Stride of the second source tensor in X dimension (in bytes) - * @param[in] squared_input_step_x input_stride_x * number of elements along X processed per workitem(in bytes) - * @param[in] squared_input_stride_y Stride of the second source tensor in Y dimension (in bytes) - * @param[in] squared_input_step_y input_stride_y * number of elements along Y processed per workitem(in bytes) - * @param[in] squared_input_stride_z Stride of the second source tensor in Z dimension (in bytes) - * @param[in] squared_input_step_z input_stride_z * number of elements along Z processed per workitem(in bytes) - * @param[in] squared_input_offset_first_element_in_bytes The offset of the second element in the second source tensor - * @param[out] output_ptr Pointer to the destination tensor. Supported data types: same as @p input_ptr - * @param[in] output_stride_x Stride of the destination tensor in X dimension (in bytes) - * @param[in] output_step_x output_stride_x * number of elements along X processed per workitem(in bytes) - * @param[in] output_stride_y Stride of the destination tensor in Y dimension (in bytes) - * @param[in] output_step_y output_stride_y * number of elements along Y processed per workitem(in bytes) - * @param[in] output_stride_z Stride of the destination tensor in Z dimension (in bytes) - * @param[in] output_step_z output_stride_z * number of elements along Z processed per workitem(in bytes) - * @param[in] output_offset_first_element_in_bytes The offset of the first element in the destination tensor - * @param[in] radius Number of elements on the right or left side to normalize across + * @param[in] input_ptr Pointer to the first source tensor. Supported data types: QS8/QS16/F16/F32 + * @param[in] input_stride_x Stride of the first source tensor in X dimension (in bytes) + * @param[in] input_step_x input_stride_x * number of elements along X processed per workitem(in bytes) + * @param[in] input_stride_y Stride of the first source tensor in Y dimension (in bytes) + * @param[in] input_step_y input_stride_y * number of elements along Y processed per workitem(in bytes) + * @param[in] input_stride_z Stride of the first source tensor in Z dimension (in bytes) + * @param[in] input_step_z input_stride_z * number of elements along Z processed per workitem(in bytes) + * @param[in] input_offset_first_element_in_bytes The offset of the first element in the first source tensor + * @param[out] output_ptr Pointer to the destination tensor. Supported data types: same as @p input_ptr + * @param[in] output_stride_x Stride of the destination tensor in X dimension (in bytes) + * @param[in] output_step_x output_stride_x * number of elements along X processed per workitem(in bytes) + * @param[in] output_stride_y Stride of the destination tensor in Y dimension (in bytes) + * @param[in] output_step_y output_stride_y * number of elements along Y processed per workitem(in bytes) + * @param[in] output_stride_z Stride of the destination tensor in Z dimension (in bytes) + * @param[in] output_step_z output_stride_z * number of elements along Z processed per workitem(in bytes) + * @param[in] output_offset_first_element_in_bytes The offset of the first element in the destination tensor */ __kernel void normalization_layer_cross_map(TENSOR3D_DECLARATION(input), - TENSOR3D_DECLARATION(squared_input), - TENSOR3D_DECLARATION(output), - uint radius) + TENSOR3D_DECLARATION(output)) { - Tensor3D in = CONVERT_TO_TENSOR3D_STRUCT(input); - Tensor3D squared_in = CONVERT_TO_TENSOR3D_STRUCT(squared_input); - Tensor3D out = CONVERT_TO_TENSOR3D_STRUCT(output); + Tensor3D in = CONVERT_TO_TENSOR3D_STRUCT(input); + Tensor3D out = CONVERT_TO_TENSOR3D_STRUCT(output); VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE) acc = (VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE))0; @@ -101,15 +91,16 @@ __kernel void normalization_layer_cross_map(TENSOR3D_DECLARATION(input), const VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE) kappa_v = (VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE))SQCVT_SAT(KAPPA); - const int num_of_slices = get_global_size(2); const int current_slice = get_global_id(2); - const int left_slice = max(current_slice - (int)radius, (int)0); - const int right_slice = min(current_slice + (int)radius, (int)(num_of_slices - 1)); + const int left_slice = max(current_slice - (int)RADIUS, (int)0); + const int right_slice = min(current_slice + (int)RADIUS, (int)(NUM_SLICES - 1)); for(int i = left_slice; i <= right_slice; i++) { - acc = ADD_OP(acc, LOAD_OP(0, (__global DATA_TYPE *)tensor3D_offset(&squared_in, 0, 0, i - current_slice))); + VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE) + values = LOAD_OP(0, (__global DATA_TYPE *)tensor3D_offset(&in, 0, 0, i - current_slice)); + acc = ADD_OP(acc, MUL_OP(values, values)); } acc = ADD_OP(MUL_OP(acc, coeff_v), kappa_v); @@ -125,43 +116,32 @@ __kernel void normalization_layer_cross_map(TENSOR3D_DECLARATION(input), * * @note Datatype should be given as a preprocessor argument using -DDATA_TYPE=type. e.g. -DDATA_TYPE=short * @note Vector size should be given as a preprocessor argument using -DVEC_SIZE=size, e.g. -DVEC_SIZE=16 + * @note The radius should be given as a preprocessor argument using -DRADIUS=size. e.g. -DRADIUS=5 * @note In case of fixed-point operation -DFIXED_POINT_POSITION=fixed_point_position must be provided: e.g. -DFIXED_POINT_POSITION=3 * @note Scaling coefficient (= alpha/norm_size), beta and kappa need to be passed at compile time using -DCOEFF, -DALPHA and -DKAPPA * - * @param[in] input_ptr Pointer to the first source tensor. Supported data types: QS8/F16/F32 - * @param[in] input_stride_x Stride of the first source tensor in X dimension (in bytes) - * @param[in] input_step_x input_stride_x * number of elements along X processed per workitem(in bytes) - * @param[in] input_stride_y Stride of the first source tensor in Y dimension (in bytes) - * @param[in] input_step_y input_stride_y * number of elements along Y processed per workitem(in bytes) - * @param[in] input_stride_z Stride of the first source tensor in Z dimension (in bytes) - * @param[in] input_step_z input_stride_z * number of elements along Z processed per workitem(in bytes) - * @param[in] input_offset_first_element_in_bytes The offset of the first element in the first source tensor - * @param[in] squared_input_ptr Pointer to the second source tensor. Supported data types: same as @p input_ptr - * @param[in] squared_input_stride_x Stride of the second source tensor in X dimension (in bytes) - * @param[in] squared_input_step_x input_stride_x * number of elements along X processed per workitem(in bytes) - * @param[in] squared_input_stride_y Stride of the second source tensor in Y dimension (in bytes) - * @param[in] squared_input_step_y input_stride_y * number of elements along Y processed per workitem(in bytes) - * @param[in] squared_input_stride_z Stride of the second source tensor in Z dimension (in bytes) - * @param[in] squared_input_step_z input_stride_z * number of elements along Z processed per workitem(in bytes) - * @param[in] squared_input_offset_first_element_in_bytes The offset of the second element in the second source tensor - * @param[out] output_ptr Pointer to the destination tensor. Supported data types: same as @p input_ptr - * @param[in] output_stride_x Stride of the destination tensor in X dimension (in bytes) - * @param[in] output_step_x output_stride_x * number of elements along X processed per workitem(in bytes) - * @param[in] output_stride_y Stride of the first destination tensor in Y dimension (in bytes) - * @param[in] output_step_y output_stride_y * number of elements along Y processed per workitem(in bytes) - * @param[in] output_stride_z Stride of the first source tensor in Z dimension (in bytes) - * @param[in] output_step_z output_stride_z * number of elements along Z processed per workitem(in bytes) - * @param[in] output_offset_first_element_in_bytes The offset of the first element in the destination tensor - * @param[in] radius Number of elements on the right or left side to normalize across + * @param[in] input_ptr Pointer to the first source tensor. Supported data types: QS8/F16/F32 + * @param[in] input_stride_x Stride of the first source tensor in X dimension (in bytes) + * @param[in] input_step_x input_stride_x * number of elements along X processed per workitem(in bytes) + * @param[in] input_stride_y Stride of the first source tensor in Y dimension (in bytes) + * @param[in] input_step_y input_stride_y * number of elements along Y processed per workitem(in bytes) + * @param[in] input_stride_z Stride of the first source tensor in Z dimension (in bytes) + * @param[in] input_step_z input_stride_z * number of elements along Z processed per workitem(in bytes) + * @param[in] input_offset_first_element_in_bytes The offset of the first element in the first source tensor + * @param[out] output_ptr Pointer to the destination tensor. Supported data types: same as @p input_ptr + * @param[in] output_stride_x Stride of the destination tensor in X dimension (in bytes) + * @param[in] output_step_x output_stride_x * number of elements along X processed per workitem(in bytes) + * @param[in] output_stride_y Stride of the first destination tensor in Y dimension (in bytes) + * @param[in] output_step_y output_stride_y * number of elements along Y processed per workitem(in bytes) + * @param[in] output_stride_z Stride of the first source tensor in Z dimension (in bytes) + * @param[in] output_step_z output_stride_z * number of elements along Z processed per workitem(in bytes) + * @param[in] output_offset_first_element_in_bytes The offset of the first element in the destination tensor */ __kernel void normalization_layer_in_map_1D(TENSOR3D_DECLARATION(input), - TENSOR3D_DECLARATION(squared_input), - TENSOR3D_DECLARATION(output), - uint radius) + TENSOR3D_DECLARATION(output)) { - Tensor3D in = CONVERT_TO_TENSOR3D_STRUCT(input); - Tensor3D squared_in = CONVERT_TO_TENSOR3D_STRUCT(squared_input); - Tensor3D out = CONVERT_TO_TENSOR3D_STRUCT(output); + Tensor3D in = CONVERT_TO_TENSOR3D_STRUCT(input); + Tensor3D out = CONVERT_TO_TENSOR3D_STRUCT(output); VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE) acc = (VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE))0; @@ -174,12 +154,14 @@ __kernel void normalization_layer_in_map_1D(TENSOR3D_DECLARATION(input), const int current_pos = get_global_id(0) << 2; - const int left_pos = max(current_pos - (int)radius, -3); - const int right_pos = min(current_pos + (int)radius, (int)((get_global_size(0) << 2) + 3 - 1)); + const int left_pos = max(current_pos - (int)RADIUS, -3); + const int right_pos = min(current_pos + (int)RADIUS, (int)((get_global_size(0) << 2) + 3 - 1)); for(int i = left_pos; i <= right_pos; i += 1) { - acc = ADD_OP(acc, LOAD_OP(0, (__global DATA_TYPE *)tensor3D_offset(&squared_in, i - current_pos, 0, 0))); + VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE) + values = LOAD_OP(0, (__global DATA_TYPE *)tensor3D_offset(&in, i - current_pos, 0, 0)); + acc = ADD_OP(acc, MUL_OP(values, values)); } acc = ADD_OP(MUL_OP(acc, coeff_v), kappa_v); -- cgit v1.2.1