From 1b50bd4d74d479f80c48ee1cd7b223245162aac3 Mon Sep 17 00:00:00 2001 From: Sheri Zhang Date: Tue, 27 Oct 2020 00:24:07 +0000 Subject: COMPMID-3793: Remove OpenCL padding: CLWidthConcatenateLayerKernel Signed-off-by: Sheri Zhang Change-Id: I705044a9429bb9a08268368b09463c2af85616d5 Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/4253 Tested-by: Arm Jenkins Reviewed-by: Manuel Bottini Comments-Addressed: Arm Jenkins --- src/core/CL/cl_kernels/concatenate.cl | 25 ++++++++++------- .../CL/kernels/CLWidthConcatenateLayerKernel.cpp | 32 ++++++---------------- 2 files changed, 24 insertions(+), 33 deletions(-) (limited to 'src/core') diff --git a/src/core/CL/cl_kernels/concatenate.cl b/src/core/CL/cl_kernels/concatenate.cl index 0f4b5afe2c..7c6c8d211a 100644 --- a/src/core/CL/cl_kernels/concatenate.cl +++ b/src/core/CL/cl_kernels/concatenate.cl @@ -278,11 +278,12 @@ __kernel void concatenate_width_x4( #endif /* defined(INPUT1_WIDTH) */ #endif /* defined(DEPTH) && defined(ELEMENT_SIZE) */ -#if defined(WIDTH_OFFSET) && defined(DEPTH) +#if defined(WIDTH_OFFSET) && defined(DEPTH) && defined(VEC_SIZE) && defined(VEC_SIZE_LEFTOVER) /** This kernel concatenates the input tensor into the output tensor along the first dimension * * @note The data type has to be passed at compile time using -DDATA_TYPE. i.e. -DDATA_TYPE=float * @note Vector size has to be passed at compile time using -DVEC_SIZE. i.e. -DVEC_SIZE=16 + * @note Leftover vector size has to be passed at compile time using -DVEC_SIZE_LEFTOVER. e.g. -DVEC_SIZE_LEFTOVER=3. It is defined as the remainder between the input's first dimension and VEC_SIZE * @note The offset for the first spatial dimension has to be passed at compile time using -DWIDTH_OFFSET. i.e. -DWIDTH_OFFSET=128 * @note Tensor depth should be given as a preprocessor argument using -DDEPTH=size. e.g. -DDEPTH=16 * @@ -312,23 +313,27 @@ __kernel void concatenate_width( TENSOR4D_DECLARATION(src), TENSOR4D_DECLARATION(dst)) { - Tensor4D src = CONVERT_TO_TENSOR4D_STRUCT(src, DEPTH); - Tensor4D dst = CONVERT_TO_TENSOR4D_STRUCT(dst, DEPTH); + // Calculate input indices + const int x = max((int)(get_global_id(0) * VEC_SIZE - (VEC_SIZE - VEC_SIZE_LEFTOVER) % VEC_SIZE), 0); + const int y = get_global_id(1); + const int z = get_global_id(2) % (int)DEPTH; + const int w = get_global_id(2) / (int)DEPTH; + + __global uchar *src_addr = src_ptr + src_offset_first_element_in_bytes + x * sizeof(DATA_TYPE) + y * src_stride_y + z * src_stride_z + w * src_stride_w; + __global uchar *dst_addr = dst_ptr + dst_offset_first_element_in_bytes + x * sizeof(DATA_TYPE) + y * dst_stride_y + z * dst_stride_z + w * dst_stride_w; VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE) - source_values = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)src.ptr); + source_values0 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)src_addr); #if defined(OFFSET_IN1) && defined(OFFSET_OUT) && defined(SCALE_IN1) && defined(SCALE_OUT) - const VEC_QUANT out = requantize(source_values, OFFSET_IN1, OFFSET_OUT, SCALE_IN1, SCALE_OUT); - VSTORE(VEC_SIZE) - (out, 0, (__global DATA_TYPE *)(dst.ptr) + WIDTH_OFFSET); + const VEC_QUANT out0 = requantize(source_values0, OFFSET_IN1, OFFSET_OUT, SCALE_IN1, SCALE_OUT); + STORE_VECTOR_SELECT(out, DATA_TYPE, dst_addr + WIDTH_OFFSET * sizeof(DATA_TYPE), VEC_SIZE, VEC_SIZE_LEFTOVER, VEC_SIZE_LEFTOVER != 0 && get_global_id(0) == 0) #else /* defined(OFFSET_IN1) && defined(OFFSET_OUT) && defined(SCALE_IN1) && defined(SCALE_OUT) */ - VSTORE(VEC_SIZE) - (source_values, 0, (__global DATA_TYPE *)(dst.ptr) + WIDTH_OFFSET); + STORE_VECTOR_SELECT(source_values, DATA_TYPE, dst_addr + WIDTH_OFFSET * sizeof(DATA_TYPE), VEC_SIZE, VEC_SIZE_LEFTOVER, VEC_SIZE_LEFTOVER != 0 && get_global_id(0) == 0) #endif /* defined(OFFSET_IN1) && defined(OFFSET_OUT) && defined(SCALE_IN1) && defined(SCALE_OUT) */ } -#endif /* defined(WIDTH_OFFSET) && defined(DEPTH) */ +#endif /* defined(WIDTH_OFFSET) && defined(DEPTH) && defined(VEC_SIZE) && defined(VEC_SIZE_LEFTOVER)*/ #if defined(VEC_SIZE_LEFTOVER) diff --git a/src/core/CL/kernels/CLWidthConcatenateLayerKernel.cpp b/src/core/CL/kernels/CLWidthConcatenateLayerKernel.cpp index 8b0aaf3227..a9a601dc8e 100644 --- a/src/core/CL/kernels/CLWidthConcatenateLayerKernel.cpp +++ b/src/core/CL/kernels/CLWidthConcatenateLayerKernel.cpp @@ -38,21 +38,6 @@ namespace arm_compute { namespace { -constexpr unsigned int num_elems_processed_per_iteration = 16; - -std::pair validate_and_configure_window(ITensorInfo *input, unsigned int width_offset, ITensorInfo *output) -{ - // The window needs to be based on input as we copy all the widths of input - Window win = calculate_max_window(*input, Steps(num_elems_processed_per_iteration)); - AccessWindowHorizontal input_access(input, 0, num_elems_processed_per_iteration); - AccessWindowHorizontal output_access(output, width_offset, num_elems_processed_per_iteration); - bool window_changed = update_window_and_padding(win, input_access, output_access); - - Window win_collapsed = win.collapse(win, Window::DimZ); - - Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{}; - return std::make_pair(err, win_collapsed); -} Status validate_arguments(const ITensorInfo *input, unsigned int width_offset, const ITensorInfo *output) { ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, output); @@ -73,14 +58,12 @@ Status validate_arguments(const ITensorInfo *input, unsigned int width_offset, c } // namespace CLWidthConcatenateLayerKernel::CLWidthConcatenateLayerKernel() - : _width_offset(0) { } Status CLWidthConcatenateLayerKernel::validate(const ITensorInfo *input, unsigned int width_offset, const ITensorInfo *output) { ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, width_offset, output)); - ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), width_offset, output->clone().get()).first); return Status{}; } @@ -89,13 +72,16 @@ void CLWidthConcatenateLayerKernel::configure(const CLCompileContext &compile_co ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input, width_offset, output)); - _width_offset = width_offset; + auto padding_info = get_padding_info({ input, output }); + + const unsigned int num_elems_processed_per_iteration = adjust_vec_size(16, input->dimension(0)); // Add build options CLBuildOptions build_opts; build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(input->data_type())); build_opts.add_option("-DVEC_SIZE=" + support::cpp11::to_string(num_elems_processed_per_iteration)); - build_opts.add_option("-DWIDTH_OFFSET=" + support::cpp11::to_string(_width_offset)); + build_opts.add_option("-DVEC_SIZE_LEFTOVER=" + support::cpp11::to_string(input->dimension(0) % num_elems_processed_per_iteration)); + build_opts.add_option("-DWIDTH_OFFSET=" + support::cpp11::to_string(width_offset)); build_opts.add_option("-DDEPTH=" + support::cpp11::to_string(input->dimension(2))); if(is_data_type_quantized_asymmetric(input->data_type()) && input->quantization_info() != output->quantization_info()) @@ -112,13 +98,13 @@ void CLWidthConcatenateLayerKernel::configure(const CLCompileContext &compile_co // Create kernel _kernel = create_kernel(compile_context, "concatenate_width", build_opts.options()); // Configure kernel window - auto win_config = validate_and_configure_window(input, width_offset, output); - ARM_COMPUTE_ERROR_THROW_ON(std::get<0>(win_config)); - - ICLKernel::configure_internal(std::get<1>(win_config)); + Window win = calculate_max_window(*input, Steps(num_elems_processed_per_iteration)); + ICLKernel::configure_internal(win.collapse(win, Window::DimZ)); // Set output valid region output->set_valid_region(ValidRegion(Coordinates(), output->tensor_shape())); + + ARM_COMPUTE_ERROR_ON(has_padding_changed(padding_info)); } void CLWidthConcatenateLayerKernel::run_op(ITensorPack &tensors, const Window &window, cl::CommandQueue &queue) -- cgit v1.2.1