diff options
Diffstat (limited to 'src/graph')
-rw-r--r-- | src/graph/Utils.cpp | 1 | ||||
-rw-r--r-- | src/graph/mutators/MutatorUtils.cpp | 52 | ||||
-rw-r--r-- | src/graph/mutators/MutatorUtils.h | 42 | ||||
-rw-r--r-- | src/graph/mutators/NodeFusionMutator.cpp | 38 |
4 files changed, 104 insertions, 29 deletions
diff --git a/src/graph/Utils.cpp b/src/graph/Utils.cpp index 7db06b9c70..dcab177a3b 100644 --- a/src/graph/Utils.cpp +++ b/src/graph/Utils.cpp @@ -225,5 +225,6 @@ void configure_tensor(Tensor *tensor) tensor->set_handle(std::move(handle)); } } + } // namespace graph } // namespace arm_compute diff --git a/src/graph/mutators/MutatorUtils.cpp b/src/graph/mutators/MutatorUtils.cpp new file mode 100644 index 0000000000..c8f38f34e7 --- /dev/null +++ b/src/graph/mutators/MutatorUtils.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2021 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "src/graph/mutators/MutatorUtils.h" + +namespace arm_compute +{ +namespace graph +{ +bool is_padding_in_height_or_width(const DataLayout &layout, const PaddingList &padding_list) +{ + if(layout == DataLayout::NCHW || layout == DataLayout::NHWC) + { + const unsigned int height_index = get_dimension_idx(layout, DataLayoutDimension::HEIGHT); + const unsigned int width_index = get_dimension_idx(layout, DataLayoutDimension::WIDTH); + + for(unsigned int i = 0; i < padding_list.size(); ++i) + { + if(i != height_index && i != width_index && padding_list[i] != PaddingInfo(0, 0)) + { + // if the index is not either height or width, don't fuse + return false; + } + } + + return true; + } + + return false; +} +} // namespace graph +} // namespace arm_compute
\ No newline at end of file diff --git a/src/graph/mutators/MutatorUtils.h b/src/graph/mutators/MutatorUtils.h new file mode 100644 index 0000000000..170d892c93 --- /dev/null +++ b/src/graph/mutators/MutatorUtils.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2021 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef ARM_COMPUTE_GRAPH_MUTATOR_UTILS_H +#define ARM_COMPUTE_GRAPH_MUTATOR_UTILS_H + +#include "arm_compute/graph/Utils.h" + +namespace arm_compute +{ +namespace graph +{ +/** Check if padding is in height and/or width dimensions + * + * @param[in] layout Data layout of the tensor + * @param[in] padding_list List of padding pairs + */ +bool is_padding_in_height_or_width(const DataLayout &layout, const PaddingList &padding_list); +} // namespace graph +} // namespace arm_compute + +#endif /* ARM_COMPUTE_GRAPH_MUTATOR_UTILS_H */
\ No newline at end of file diff --git a/src/graph/mutators/NodeFusionMutator.cpp b/src/graph/mutators/NodeFusionMutator.cpp index b530fb0c00..e37164c60c 100644 --- a/src/graph/mutators/NodeFusionMutator.cpp +++ b/src/graph/mutators/NodeFusionMutator.cpp @@ -30,6 +30,8 @@ #include "arm_compute/graph/nodes/FusedConvolutionBatchNormalizationNode.h" #include "arm_compute/graph/nodes/Nodes.h" +#include "src/graph/mutators/MutatorUtils.h" + #include "support/Cast.h" #include <set> @@ -265,33 +267,6 @@ void fuse_node_with_activation(Graph &g, const Edge *output_edge, const std::set } } -bool check_padding_info(const DataLayout &layout, const PaddingList &padding_list, PaddingInfo &pad_w, PaddingInfo &pad_h) -{ - if(layout == DataLayout::NCHW || layout == DataLayout::NHWC) - { - const PaddingInfo zero_padding(0, 0); - - const unsigned int height_index = get_dimension_idx(layout, DataLayoutDimension::HEIGHT); - const unsigned int width_index = get_dimension_idx(layout, DataLayoutDimension::WIDTH); - - pad_w = width_index < padding_list.size() ? padding_list[width_index] : zero_padding; - pad_h = height_index < padding_list.size() ? padding_list[height_index] : zero_padding; - - for(unsigned int i = 0; i < padding_list.size(); i++) - { - if(i != height_index && i != width_index && padding_list[i] != zero_padding) - { - // if the index is not either height or width, don't fuse - return false; - } - } - - return true; - } - - return false; -} - template <typename N> void fuse_pad_with_convolution(Graph &g, const Edge *output_edge) { @@ -304,9 +279,14 @@ void fuse_pad_with_convolution(Graph &g, const Edge *output_edge) { const DataLayout layout = input_edge->tensor()->desc().layout; const PaddingList padding_list = pad_node->padding(); - PaddingInfo pad_w, pad_h; - if(check_padding_info(layout, padding_list, pad_w, pad_h)) + const unsigned int height_index = get_dimension_idx(layout, DataLayoutDimension::HEIGHT); + const unsigned int width_index = get_dimension_idx(layout, DataLayoutDimension::WIDTH); + + const PaddingInfo pad_w = width_index < padding_list.size() ? padding_list[width_index] : PaddingInfo(0, 0); + const PaddingInfo pad_h = height_index < padding_list.size() ? padding_list[height_index] : PaddingInfo(0, 0); + + if(is_padding_in_height_or_width(layout, padding_list)) { // Add paddings to the convolution node const PadStrideInfo conv_info = conv_node->convolution_info(); |