From 750641dd6aab1e5e62d1875b97b230312bb87959 Mon Sep 17 00:00:00 2001 From: Gian Marco Iodice Date: Tue, 8 May 2018 12:01:57 +0100 Subject: COMPMID-1052 - Rework validate method in CLGEMM Change-Id: Iece5bd6478b5fac5164abff30c1e63e8a77291a9 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/130374 Reviewed-by: Anthony Barbier Tested-by: Jenkins --- src/core/CL/kernels/CLGEMMInterleave4x4Kernel.cpp | 18 +++++++++--------- src/core/CL/kernels/CLGEMMMatrixAdditionKernel.cpp | 14 ++++++-------- src/core/CL/kernels/CLGEMMMatrixMultiplyKernel.cpp | 15 ++++++--------- src/core/CL/kernels/CLGEMMTranspose1xWKernel.cpp | 16 ++++++---------- 4 files changed, 27 insertions(+), 36 deletions(-) (limited to 'src/core/CL') diff --git a/src/core/CL/kernels/CLGEMMInterleave4x4Kernel.cpp b/src/core/CL/kernels/CLGEMMInterleave4x4Kernel.cpp index d12255ff24..8f669a9298 100644 --- a/src/core/CL/kernels/CLGEMMInterleave4x4Kernel.cpp +++ b/src/core/CL/kernels/CLGEMMInterleave4x4Kernel.cpp @@ -69,16 +69,16 @@ std::pair validate_and_configure_window(ITensorInfo *input, ITen AccessWindowRectangle input_access(input, 0, 0, num_elems_processed_per_iteration_x, num_elems_processed_per_iteration_y); window_changed = window_changed || update_window_and_padding(win, input_access); - // Configure window in case of configured output - if(output->total_size() != 0) - { - const float scale_x = 4.0f * static_cast(mult_interleave4x4_height); - const float scale_y = 1.0f / (scale_x); + // Output auto inizialitation if not yet initialized + auto_init_if_empty(*output, input->clone()->set_tensor_shape(compute_interleaved_shape(*input, mult_interleave4x4_height))); - AccessWindowRectangle output_access(output, 0, 0, num_elems_written_per_iteration, 1, scale_x, scale_y); - window_changed = window_changed || update_window_and_padding(win, output_access); - output_access.set_valid_region(win, input->valid_region()); - } + // Configure window + const float scale_x = 4.0f * static_cast(mult_interleave4x4_height); + const float scale_y = 1.0f / (scale_x); + + AccessWindowRectangle output_access(output, 0, 0, num_elems_written_per_iteration, 1, scale_x, scale_y); + window_changed = window_changed || update_window_and_padding(win, output_access); + output_access.set_valid_region(win, input->valid_region()); // Collapse along the Z direction // This collapse needs to be here in order to tune the Z dimension of LWS diff --git a/src/core/CL/kernels/CLGEMMMatrixAdditionKernel.cpp b/src/core/CL/kernels/CLGEMMMatrixAdditionKernel.cpp index 4b4814f15d..4538812baa 100644 --- a/src/core/CL/kernels/CLGEMMMatrixAdditionKernel.cpp +++ b/src/core/CL/kernels/CLGEMMMatrixAdditionKernel.cpp @@ -58,16 +58,15 @@ std::pair validate_and_configure_window(ITensorInfo *input, ITen namespace { -Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output, const float beta) +Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output, float beta) { ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, output); + ARM_COMPUTE_UNUSED(input, output, beta); ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QS8, DataType::QS16, DataType::F16, DataType::F32); ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); - ARM_COMPUTE_RETURN_ERROR_ON(input->dimension(0) != output->dimension(0)); - ARM_COMPUTE_RETURN_ERROR_ON(input->dimension(1) != output->dimension(1)); + ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(input, output); - ARM_COMPUTE_UNUSED(beta); return Status{}; } } // namespace @@ -114,11 +113,10 @@ void CLGEMMMatrixAdditionKernel::configure(const ICLTensor *input, ICLTensor *ou ICLKernel::configure(win_config.second); } -Status CLGEMMMatrixAdditionKernel::validate(const ITensorInfo *input, const ITensorInfo *output, const float beta) +Status CLGEMMMatrixAdditionKernel::validate(const ITensorInfo *input, const ITensorInfo *output, float beta) { - ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); - ARM_COMPUTE_RETURN_ERROR_ON(validate_arguments(input, output, beta)); - ARM_COMPUTE_RETURN_ERROR_ON(validate_and_configure_window(input->clone().get(), output->clone().get()).first); + ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, beta)); + ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), output->clone().get()).first); return Status{}; } diff --git a/src/core/CL/kernels/CLGEMMMatrixMultiplyKernel.cpp b/src/core/CL/kernels/CLGEMMMatrixMultiplyKernel.cpp index 674937eff0..cc9ae27bed 100644 --- a/src/core/CL/kernels/CLGEMMMatrixMultiplyKernel.cpp +++ b/src/core/CL/kernels/CLGEMMMatrixMultiplyKernel.cpp @@ -107,7 +107,7 @@ inline Status validate_arguments(const ITensorInfo *input0, const ITensorInfo *i } inline std::pair validate_and_configure_window(ITensorInfo *input0, ITensorInfo *input1, ITensorInfo *output, - bool is_interleaved_transposed, GPUTarget gpu_target, + bool is_interleaved_transposed, const GEMMReshapeInfo &reshape_info, GPUTarget gpu_target, ElementsProcessed &num_elements_processed) { bool window_changed = false; @@ -117,6 +117,9 @@ inline std::pair validate_and_configure_window(ITensorInfo *inpu unsigned int &num_elems_processed_per_iteration_x = num_elements_processed[0]; unsigned int &num_elems_processed_per_iteration_y = num_elements_processed[1]; + // Output tensor auto inizialitation if not yet initialized + auto_init_if_empty(*output, input0->clone()->set_tensor_shape(compute_mm_shape(*input0, *input1, is_interleaved_transposed, reshape_info))); + if(is_interleaved_transposed) { // Configure kernel window @@ -182,13 +185,6 @@ void CLGEMMMatrixMultiplyKernel::configure(const ICLTensor *input0, const ICLTen { ARM_COMPUTE_ERROR_ON_NULLPTR(input0, input1, output); - // Output tensor auto inizialitation if not yet initialized - TensorShape tensor_shape{ input0->info()->tensor_shape() }; - tensor_shape.set(0, is_interleaved_transposed ? reshape_info.n() : input1->info()->dimension(0)); - tensor_shape.set(1, is_interleaved_transposed ? reshape_info.m() : input0->info()->dimension(1)); - - auto_init_if_empty(*output->info(), input0->info()->clone()->set_tensor_shape(tensor_shape)); - // Perform validate step ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input0->info(), input1->info(), output->info(), is_interleaved_transposed, reshape_info)); @@ -246,7 +242,7 @@ void CLGEMMMatrixMultiplyKernel::configure(const ICLTensor *input0, const ICLTen ElementsProcessed num_elements_processed{}; // Configure kernel window - auto win_config = validate_and_configure_window(input0->info(), input1->info(), output->info(), is_interleaved_transposed, gpu_target, num_elements_processed); + auto win_config = validate_and_configure_window(input0->info(), input1->info(), output->info(), is_interleaved_transposed, reshape_info, gpu_target, num_elements_processed); ARM_COMPUTE_ERROR_THROW_ON(win_config.first); ICLKernel::configure(win_config.second); @@ -354,6 +350,7 @@ Status CLGEMMMatrixMultiplyKernel::validate(const ITensorInfo *input0, const ITe input1->clone().get(), output->clone().get(), is_interleaved_transposed, + reshape_info, gpu_target, num_elements_processed) .first); diff --git a/src/core/CL/kernels/CLGEMMTranspose1xWKernel.cpp b/src/core/CL/kernels/CLGEMMTranspose1xWKernel.cpp index 54abb1cde0..a9618609e6 100644 --- a/src/core/CL/kernels/CLGEMMTranspose1xWKernel.cpp +++ b/src/core/CL/kernels/CLGEMMTranspose1xWKernel.cpp @@ -78,17 +78,13 @@ std::pair validate_and_configure_window(ITensorInfo *input, ITen AccessWindowHorizontal input_access(input, 0, num_elems_processed_per_iteration); + // Output tensor auto inizialitation if not yet initialized + auto_init_if_empty(*output, input->clone()->set_tensor_shape(compute_transpose1xW_with_element_size_shape(*input, mult_transpose1xW_width))); + // Configure window in case of configured output - if(output->total_size() != 0) - { - AccessWindowStatic output_access(output, 0, 0, ceil_to_multiple(output->dimension(0), scale_x), output->dimension(1)); - window_changed = window_changed || update_window_and_padding(win, input_access, output_access); - output_access.set_valid_region(win, ValidRegion(Coordinates(0, 0), input->tensor_shape())); - } - else - { - window_changed = window_changed || update_window_and_padding(win, input_access); - } + AccessWindowStatic output_access(output, 0, 0, ceil_to_multiple(output->dimension(0), scale_x), output->dimension(1)); + window_changed = window_changed || update_window_and_padding(win, input_access, output_access); + output_access.set_valid_region(win, ValidRegion(Coordinates(0, 0), input->tensor_shape())); // Collapse along the Z direction Window collapsed = win.collapse(win, Window::DimZ); -- cgit v1.2.1