From 19ea419e7f14d02aeb208c2fbd5a4ac55f4cb101 Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Tue, 19 Jun 2018 13:09:53 +0100 Subject: COMPMID-809: Add NHWC data format on CLGEMMConvolutionLayer. Change-Id: I50e4f5e7d47e21c300f754bee2c216863075b5cf Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/136191 Tested-by: Jenkins Reviewed-by: Giorgio Arena Reviewed-by: Gian Marco Iodice --- src/core/CL/kernels/CLCol2ImKernel.cpp | 16 +++++++++------- src/core/CL/kernels/CLIm2ColKernel.cpp | 16 +++++++--------- src/core/CL/kernels/CLWeightsReshapeKernel.cpp | 6 ++++-- 3 files changed, 20 insertions(+), 18 deletions(-) (limited to 'src/core/CL/kernels') diff --git a/src/core/CL/kernels/CLCol2ImKernel.cpp b/src/core/CL/kernels/CLCol2ImKernel.cpp index 4e444206f1..64e6a0b7d8 100644 --- a/src/core/CL/kernels/CLCol2ImKernel.cpp +++ b/src/core/CL/kernels/CLCol2ImKernel.cpp @@ -140,23 +140,25 @@ void CLCol2ImKernel::run(const Window &window, cl::CommandQueue &queue) { ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); ARM_COMPUTE_ERROR_ON_MISMATCHING_WINDOWS(ICLKernel::window(), window); - // The collapse method rely on the assumption that the third dimension of input buffer is 1 - ARM_COMPUTE_ERROR_ON(window.z().end() != 1); + + Window out_window; + out_window.use_tensor_dimensions(_output->info()->tensor_shape()); Window collapsed_window = window.collapse_if_possible(ICLKernel::window(), Window::DimZ); - Window slice = collapsed_window.first_slice_window_3D(); + Window slice = collapsed_window.first_slice_window_2D(); + Window slice_out = out_window.first_slice_window_3D(); // Set static kernel arguments - unsigned int idx = 2 * num_arguments_per_3D_tensor(); + unsigned int idx = num_arguments_per_2D_tensor() + num_arguments_per_3D_tensor(); _kernel.setArg(idx++, _output->info()->strides_in_bytes()[3]); do { // Set inputs unsigned int idx = 0; - add_3D_tensor_argument(idx, _input, slice); - add_3D_tensor_argument(idx, _output, slice); + add_2D_tensor_argument(idx, _input, slice); + add_3D_tensor_argument(idx, _output, slice_out); enqueue(queue, *this, slice, _lws_hint); } - while(collapsed_window.slide_window_slice_3D(slice)); + while(collapsed_window.slide_window_slice_2D(slice) && out_window.slide_window_slice_3D(slice_out)); } diff --git a/src/core/CL/kernels/CLIm2ColKernel.cpp b/src/core/CL/kernels/CLIm2ColKernel.cpp index 328b39681b..21deb9217c 100644 --- a/src/core/CL/kernels/CLIm2ColKernel.cpp +++ b/src/core/CL/kernels/CLIm2ColKernel.cpp @@ -143,7 +143,7 @@ CLIm2ColKernel::configure_window(const ICLTensor *input, ICLTensor *output, cons { case 1: // Optimized im2col1x1 if stride_x = 1 and conv_info.has_padding() = false - if(conv_info.stride().first == 1 && !conv_info.has_padding()) + if(conv_info.stride().first == 1 && !conv_info.has_padding() && data_layout == DataLayout::NCHW) { // Set hint for LWS _lws_hint = cl::NDRange(1, 1, 8); @@ -350,11 +350,14 @@ void CLIm2ColKernel::run_generic(const Window &window, cl::CommandQueue &queue) // Change the Z dimension's step back to 1 window_collapsed.set_dimension_step(Window::DimZ, 1); + Window window_output; + window_output.use_tensor_dimensions(_output->info()->tensor_shape()); + const Window first_slice_3d = window_collapsed.first_slice_window_3D(); Window slice = first_slice_3d; Window slice_in = first_slice_3d; - Window slice_out = first_slice_3d; + Window slice_out = window_output.first_slice_window_2D(); const bool out_dim_not_same_input_dim = _convolved_dims.first != _input->info()->dimension(width_idx) || _convolved_dims.second != _input->info()->dimension(height_idx); @@ -386,21 +389,16 @@ void CLIm2ColKernel::run_generic(const Window &window, cl::CommandQueue &queue) slice_in.set(Window::DimY, Window::Dimension(0, 0, 0)); slice_in.set(Window::DimZ, Window::Dimension(0, 0, 0)); - // Setup output slice - slice_out.set(Window::DimX, Window::Dimension(0, _output->info()->dimension(0), _kernel_dims.area())); - slice_out.set(Window::DimY, Window::Dimension(0, _output->info()->dimension(1), _output->info()->dimension(1))); - slice_out.set(Window::DimZ, Window::Dimension(0, 1, 1)); - do { unsigned int idx = 0; add_3D_tensor_argument(idx, _input, slice_in); add_2D_tensor_argument(idx, _output, slice_out); _kernel.setArg(idx++, static_cast(_input->info()->strides_in_bytes()[3])); - _kernel.setArg(idx++, static_cast(_output->info()->strides_in_bytes()[3])); + _kernel.setArg(idx++, static_cast(_output->info()->strides_in_bytes()[2])); enqueue(queue, *this, slice, _lws_hint); } - while(window_collapsed.slide_window_slice_3D(slice) && window_collapsed.slide_window_slice_3D(slice_out) && window_collapsed.slide_window_slice_3D(slice_in)); + while(window_collapsed.slide_window_slice_3D(slice) && window_output.slide_window_slice_2D(slice_out) && window_collapsed.slide_window_slice_3D(slice_in)); } void CLIm2ColKernel::run_reduced(const Window &window, cl::CommandQueue &queue) diff --git a/src/core/CL/kernels/CLWeightsReshapeKernel.cpp b/src/core/CL/kernels/CLWeightsReshapeKernel.cpp index c0a4517ad3..b012d58d59 100644 --- a/src/core/CL/kernels/CLWeightsReshapeKernel.cpp +++ b/src/core/CL/kernels/CLWeightsReshapeKernel.cpp @@ -85,7 +85,8 @@ void CLWeightsReshapeKernel::configure(const ICLTensor *input, const ICLTensor * (biases != nullptr) ? biases->info() : nullptr, output->info())); - const DataType data_type = input->info()->data_type(); + const DataType data_type = input->info()->data_type(); + const DataLayout data_layout = input->info()->data_layout(); _biases = biases; _output = output; @@ -98,7 +99,8 @@ void CLWeightsReshapeKernel::configure(const ICLTensor *input, const ICLTensor * build_opts.add_option_if(is_data_type_fixed_point(data_type), "-DFIXED_POINT_POSITION=" + support::cpp11::to_string(input->info()->fixed_point_position())); // Create kernel - _kernel = static_cast(CLKernelLibrary::get().create_kernel("reshape_to_columns", build_opts.options())); + std::string kernel_name = std::string("reshape_to_columns_") + lower_string(string_from_data_layout(data_layout)); + _kernel = static_cast(CLKernelLibrary::get().create_kernel(kernel_name, build_opts.options())); // Set static arguments unsigned int idx = num_arguments_per_3D_tensor() + num_arguments_per_2D_tensor(); -- cgit v1.2.1