From afd38f0c617d6f89b2b4532c6c44f116617e2b6f Mon Sep 17 00:00:00 2001 From: Felix Thomasmathibalan Date: Wed, 27 Sep 2023 17:46:17 +0100 Subject: Apply clang-format on repository Code is formatted as per a revised clang format configuration file(not part of this delivery). Version 14.0.6 is used. Exclusion List: - files with .cl extension - files that are not strictly C/C++ (e.g. Android.bp, Sconscript ...) And the following directories - compute_kernel_writer/validation/ - tests/ - include/ - src/core/NEON/kernels/convolution/ - src/core/NEON/kernels/arm_gemm/ - src/core/NEON/kernels/arm_conv/ - data/ There will be a follow up for formatting of .cl files and the files under tests/ and compute_kernel_writer/validation/. Signed-off-by: Felix Thomasmathibalan Change-Id: Ib7eb1fcf4e7537b9feaefcfc15098a804a3fde0a Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/10391 Benchmark: Arm Jenkins Tested-by: Arm Jenkins Reviewed-by: Gunes Bayir --- src/core/IAccessWindow.cpp | 79 +++++++++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 32 deletions(-) (limited to 'src/core/IAccessWindow.cpp') diff --git a/src/core/IAccessWindow.cpp b/src/core/IAccessWindow.cpp index 832801255f..923c5f8a85 100644 --- a/src/core/IAccessWindow.cpp +++ b/src/core/IAccessWindow.cpp @@ -29,14 +29,18 @@ using namespace arm_compute; -ValidRegion AccessWindowRectangle::compute_valid_region(const Window &window, const ValidRegion &input_valid_region) const +ValidRegion AccessWindowRectangle::compute_valid_region(const Window &window, + const ValidRegion &input_valid_region) const { return compute_valid_region(window, input_valid_region, false, BorderSize(0)); } -ValidRegion AccessWindowRectangle::compute_valid_region(const Window &window, ValidRegion input_valid_region, bool border_undefined, BorderSize border_size) const +ValidRegion AccessWindowRectangle::compute_valid_region(const Window &window, + ValidRegion input_valid_region, + bool border_undefined, + BorderSize border_size) const { - if(_info == nullptr) + if (_info == nullptr) { return input_valid_region; } @@ -45,7 +49,7 @@ ValidRegion AccessWindowRectangle::compute_valid_region(const Window &window, Va Coordinates old_anchor(anchor); TensorShape &shape = input_valid_region.shape; - if(!border_undefined) + if (!border_undefined) { border_size = BorderSize(0); } @@ -56,7 +60,7 @@ ValidRegion AccessWindowRectangle::compute_valid_region(const Window &window, Va // Additionally the valid region is shifted by the offset that is used by // the kernel to write back output values. anchor.set(0, std::max(window.x().start() * _scale_x, anchor[0] + border_size.left) + _x); - if(_info->num_dimensions() > 1) + if (_info->num_dimensions() > 1) { anchor.set(1, std::max(window.y().start() * _scale_y, anchor[1] + border_size.top) + _y); } @@ -69,15 +73,19 @@ ValidRegion AccessWindowRectangle::compute_valid_region(const Window &window, Va // old size is first converted into end points to compared against the // execution window. Afterwards the new end points are converted back into // a size of the region. - shape.set(0, std::min(old_anchor[0] + shape[0] - border_size.right, (window.x().end() - window.x().step()) * _scale_x + _width) - anchor[0]); - if(_info->num_dimensions() > 1) + shape.set(0, std::min(old_anchor[0] + shape[0] - border_size.right, + (window.x().end() - window.x().step()) * _scale_x + _width) - + anchor[0]); + if (_info->num_dimensions() > 1) { - shape.set(1, std::min(old_anchor[1] + shape[1] - border_size.bottom, (window.y().end() - window.y().step()) * _scale_y + _height) - anchor[1]); + shape.set(1, std::min(old_anchor[1] + shape[1] - border_size.bottom, + (window.y().end() - window.y().step()) * _scale_y + _height) - + anchor[1]); } // For higher dimensions use the intersection of the window size and the // valid region of the input - for(size_t d = 2; d < _info->num_dimensions(); ++d) + for (size_t d = 2; d < _info->num_dimensions(); ++d) { anchor.set(d, std::max(window[d].start(), input_valid_region.anchor[d])); shape.set(d, std::min(window[d].end(), input_valid_region.shape[d]) - anchor[d]); @@ -86,9 +94,12 @@ ValidRegion AccessWindowRectangle::compute_valid_region(const Window &window, Va return input_valid_region; } -void AccessWindowRectangle::set_valid_region(const Window &window, const ValidRegion &input_valid_region, bool border_undefined, const BorderSize &border_size) +void AccessWindowRectangle::set_valid_region(const Window &window, + const ValidRegion &input_valid_region, + bool border_undefined, + const BorderSize &border_size) { - if(_info != nullptr) + if (_info != nullptr) { _info->set_valid_region(compute_valid_region(window, input_valid_region, border_undefined, border_size)); } @@ -97,17 +108,16 @@ void AccessWindowRectangle::set_valid_region(const Window &window, const ValidRe bool AccessWindowRectangle::update_window_if_needed(Window &window) const { // Only update the window size if we can't use padding - if(_info == nullptr || _info->is_resizable()) + if (_info == nullptr || _info->is_resizable()) { return false; } - PaddingSize needed = get_needed_padding(window); + PaddingSize needed = get_needed_padding(window); PaddingSize available = _info->padding(); - if(needed.top <= available.top && needed.right <= available.right - && needed.bottom <= available.bottom - && needed.left <= available.left) + if (needed.top <= available.top && needed.right <= available.right && needed.bottom <= available.bottom && + needed.left <= available.left) { return false; } @@ -124,12 +134,12 @@ bool AccessWindowRectangle::update_window_if_needed(Window &window) const const int max_y = (window.y().end() - window.y().step()) * _scale_y + _y + _height; // Adjust window start for Y dimension - if(min_y < 0) + if (min_y < 0) { // Calculate rows available above the tensor const int front_pad_y_available = -static_cast(offset_first_element / strides[1]); - if(min_y < front_pad_y_available) + if (min_y < front_pad_y_available) { // Not enough padding available, need to shrink the window int start = adjust_up(min_y, front_pad_y_available, window.y().step() * _scale_y) - _y; @@ -144,18 +154,19 @@ bool AccessWindowRectangle::update_window_if_needed(Window &window) const } // Adjust window end for Y dimension - if(max_y > static_cast(shape[1])) + if (max_y > static_cast(shape[1])) { const int stride_z = _info->num_dimensions() > 2 ? strides[2] : _info->total_size(); // Calculate rows available below the tensor const int tail_pad_y_available = (stride_z / strides[1]) - shape[1] - front_pad_y; - if(static_cast(shape[1]) + tail_pad_y_available < max_y) + if (static_cast(shape[1]) + tail_pad_y_available < max_y) { // Not enough padding available, need to shrink the window - int end = adjust_down(max_y, shape[1] + tail_pad_y_available, window.y().step() * _scale_y) + window.y().step() * _scale_y - _y - _height; - end = std::max(window.y().start(), end / _scale_y); + int end = adjust_down(max_y, shape[1] + tail_pad_y_available, window.y().step() * _scale_y) + + window.y().step() * _scale_y - _y - _height; + end = std::max(window.y().start(), end / _scale_y); window.set(1, Window::Dimension(window.y().start(), end, window.y().step())); window_modified = true; @@ -170,11 +181,14 @@ bool AccessWindowRectangle::update_window_if_needed(Window &window) const const int stride_y = _info->num_dimensions() > 1 ? strides[1] : _info->total_size(); // Adjust window start for X dimension - if(min_x < 0) + if (min_x < 0) { - const int front_pad_x_available = -std::min(static_cast(offset_first_element) - front_pad_y * strides[1], stride_y - shape[0] * strides[0]) / static_cast(strides[0]); + const int front_pad_x_available = + -std::min(static_cast(offset_first_element) - front_pad_y * strides[1], + stride_y - shape[0] * strides[0]) / + static_cast(strides[0]); - if(min_x < front_pad_x_available) + if (min_x < front_pad_x_available) { // Not enough padding available, need to shrink the window int start = adjust_up(min_x, front_pad_x_available, window.x().step() * _scale_x) - _x; @@ -189,15 +203,16 @@ bool AccessWindowRectangle::update_window_if_needed(Window &window) const } // Adjust window end for X dimension - if(max_x > static_cast(shape[0])) + if (max_x > static_cast(shape[0])) { const int tail_pad_x_available = (stride_y / strides[0]) - shape[0] - front_pad_x; - if(static_cast(shape[0]) + tail_pad_x_available < max_x) + if (static_cast(shape[0]) + tail_pad_x_available < max_x) { // Not enough padding available, need to shrink the window - int end = adjust_down(max_x, shape[0] + tail_pad_x_available, window.x().step() * _scale_x) + window.x().step() * _scale_x - _x - _width; - end = std::max(window.x().start(), end / _scale_x); + int end = adjust_down(max_x, shape[0] + tail_pad_x_available, window.x().step() * _scale_x) + + window.x().step() * _scale_x - _x - _width; + end = std::max(window.x().start(), end / _scale_x); window.set(0, Window::Dimension(window.x().start(), end, window.x().step())); window_modified = true; @@ -212,15 +227,15 @@ bool AccessWindowRectangle::update_window_if_needed(Window &window) const bool AccessWindowRectangle::update_padding_if_needed(const Window &window) { // Only update the padding if the tensor allows it - if(_info == nullptr || !_info->is_resizable()) + if (_info == nullptr || !_info->is_resizable()) { return false; } // Update strides in tensor info - return _info->extend_padding( get_needed_padding(window)); + return _info->extend_padding(get_needed_padding(window)); } -PaddingSize AccessWindowRectangle::get_needed_padding(const Window &window)const +PaddingSize AccessWindowRectangle::get_needed_padding(const Window &window) const { ARM_COMPUTE_ERROR_ON(_scale_x == 0); ARM_COMPUTE_ERROR_ON(_scale_y == 0); -- cgit v1.2.1