diff --git a/runtime/onert/core/include/compiler/PermuteFactor.h b/runtime/onert/core/include/compiler/PermuteFactor.h deleted file mode 100644 index 67ce957bb08..00000000000 --- a/runtime/onert/core/include/compiler/PermuteFactor.h +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @file PermuteFactor.h - * @brief This file contains PermuteFactor class - * @ingroup COM_AI_RUNTIME - */ - -#ifndef __ONERT_COMPILER_OPERAND_PERMUTE_FACTOR_H__ -#define __ONERT_COMPILER_OPERAND_PERMUTE_FACTOR_H__ - -#include - -#include "ir/Layout.h" - -namespace onert -{ -namespace backend -{ -class Backend; -} // namespace backend -} // namespace onert - -namespace onert -{ -namespace compiler -{ - -/** - * @brief Class that has factors of permutation - */ -class PermuteFactor -{ -public: - /** - * @brief Construct PermuteFactor object. - * @param backend The backend factor - * @param layout The layout factor - */ - PermuteFactor(const backend::Backend *backend, ir::Layout layout) - : _backend{backend}, _layout{layout} - { - // DO NOTHING - } - /** - * @brief Construct PermuteFactor object by copy semantics. - */ - PermuteFactor(const PermuteFactor &f) : _backend{f._backend}, _layout{f._layout} - { - // DO NOTHING - } - /** - * @brief Construct PermuteFactor object by move semantics. - */ - PermuteFactor(PermuteFactor &&) = default; - -public: - /** - * @brief Get backend - * - * @return Backend factor - */ - const backend::Backend *backend() const { return _backend; } - /** - * @brief Get layout - * - * @return Layout factor - */ - ir::Layout layout() const { return _layout; } - -public: - /** - * @brief operator overloading function for `==` - * - * @return Whether two PermuteFactor are the same - */ - bool operator==(const PermuteFactor &other) const - { - return _backend == other.backend() && _layout == other.layout(); - } - /** - * @brief operator overloading function for `!=` - * - * @return Whether two PermuteFactor are differenct - */ - bool operator!=(const PermuteFactor &other) const { return !(*this == other); } - -private: - const backend::Backend *_backend{nullptr}; - ir::Layout _layout{ir::Layout::UNKNOWN}; -}; - -} // namespace compiler -} // namespace onert - -namespace std -{ - -/** - * @brief Structure that provides hash value of PermuteFactor - */ -template <> struct hash -{ - size_t operator()(const onert::compiler::PermuteFactor &factor) const noexcept - { - hash b_hash{}; - hash l_hash{}; - return b_hash(factor.backend()) ^ (l_hash(factor.layout()) << 1); - } -}; - -} // namespace std - -std::ostream &operator<<(std::ostream &os, const onert::compiler::PermuteFactor &obj); - -#endif // __ONERT_COMPILER_OPERAND_PERMUTE_FACTOR_H__ diff --git a/runtime/onert/core/src/compiler/PermuteFactor.cc b/runtime/onert/core/src/compiler/PermuteFactor.cc deleted file mode 100644 index f0081a2a46f..00000000000 --- a/runtime/onert/core/src/compiler/PermuteFactor.cc +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "compiler/PermuteFactor.h" - -#include -#include - -#include "backend/Backend.h" - -std::ostream &operator<<(std::ostream &os, const onert::compiler::PermuteFactor &obj) -{ - assert(obj.backend() && obj.backend()->config()); - return os << "(" << obj.backend()->config()->id() << "/" << to_string(obj.layout()) << ")"; -} diff --git a/runtime/onert/core/src/compiler/pass/ConstantInsertionPass.cc b/runtime/onert/core/src/compiler/pass/ConstantInsertionPass.cc index e2224eaf3fc..b9fa3d79aca 100644 --- a/runtime/onert/core/src/compiler/pass/ConstantInsertionPass.cc +++ b/runtime/onert/core/src/compiler/pass/ConstantInsertionPass.cc @@ -16,7 +16,6 @@ #include "ConstantInsertionPass.h" -#include "backend/Backend.h" #include "ir/Graph.h" #include "util/Utils.h" #include "util/logging.h" @@ -31,7 +30,6 @@ namespace pass void ConstantInsertionPass::callback(const ir::OperationIndex &node_index, ir::IOperation &node) { const auto backend = _lowered_graph.lower_info().operation.at(node_index); - const auto factor = PermuteFactor{backend, ir::Layout::NHWC}; for (const auto &input : node.getInputs() | ir::Remove::DUPLICATED | ir::Remove::UNDEFINED) { @@ -42,34 +40,33 @@ void ConstantInsertionPass::callback(const ir::OperationIndex &node_index, ir::I continue; // 1st use of shared constant operand. Keep using original operand without insertion of new one - // Register original operand into keep_operand map for later reuse on same PermuteFactor + // Register original operand into keep_operand map for later reuse on same backend if (_keep_operands_map.find(input) == _keep_operands_map.end()) { - _keep_operands_map.emplace(input, factor); + _keep_operands_map.emplace(input, backend); continue; } // Same PermuteFactor with original operand usage. Keep using original operand - if (_keep_operands_map.at(input) == factor) + if (_keep_operands_map.at(input) == backend) continue; - // Different PermuteFactor with original operand + // Different backend with original operand // Check operand is already created for current input's PermuteFactor // If not, create new operand and register to _replace_operands_map - const auto key = ReplaceKey{input, factor}; - if (_replace_operands_map.count(key) == 0) + if (_replace_operands_map.count(backend) == 0) { ir::Operand new_object(object); new_object.clearDefUse(); const auto new_index = _graph.operands().emplace(new_object); - _replace_operands_map[key] = new_index; + _replace_operands_map[backend] = new_index; } - const auto replaced_input = _replace_operands_map[key]; + const auto replaced_input = _replace_operands_map[backend]; // Update the same inputs of a node at once because inputs of an operation have the same - // PermuteFactor + // backend node.replaceInputs(input, replaced_input); // Update operand @@ -77,7 +74,7 @@ void ConstantInsertionPass::callback(const ir::OperationIndex &node_index, ir::I replaced_object.insertUse(node_index); VERBOSE(ConstInsertPass) << "New operand " << replaced_input << " added(copy of " << input - << ") for " << factor << std::endl; + << ") for " << backend->config()->id() << std::endl; // Remove this node from uses of origin operand // Constant operand has no def. assert(!object.getDef().valid()); diff --git a/runtime/onert/core/src/compiler/pass/ConstantInsertionPass.h b/runtime/onert/core/src/compiler/pass/ConstantInsertionPass.h index d816240c6c5..0606511e902 100644 --- a/runtime/onert/core/src/compiler/pass/ConstantInsertionPass.h +++ b/runtime/onert/core/src/compiler/pass/ConstantInsertionPass.h @@ -17,11 +17,11 @@ #ifndef __ONERT_COMPILER_PASS_CONSTANT_INSERTION_PASS_H__ #define __ONERT_COMPILER_PASS_CONSTANT_INSERTION_PASS_H__ -#include -#include #include "LoweredOperationPass.h" +#include "backend/Backend.h" +#include "ir/Index.h" + #include -#include namespace onert { @@ -42,31 +42,8 @@ class ConstantInsertionPass : public LoweredOperationPass void callback(const ir::OperationIndex &index, ir::IOperation &node) final; private: - struct ReplaceKey - { - ir::OperandIndex index; - PermuteFactor factor; - - bool operator==(const ReplaceKey &other) const - { - return index == other.index && factor == other.factor; - } - }; - - /** - * @brief Structure that provides hash function of ReplaceKey - */ - struct KeyHasher - { - std::size_t operator()(const ReplaceKey &key) const noexcept - { - using std::hash; - return hash()(key.index) ^ (hash()(key.factor) << 1); - } - }; - - std::unordered_map _replace_operands_map; - std::unordered_map _keep_operands_map; + std::unordered_map _replace_operands_map; + std::unordered_map _keep_operands_map; }; } // namespace pass diff --git a/runtime/onert/core/src/compiler/pass/ConstantLoweringPass.cc b/runtime/onert/core/src/compiler/pass/ConstantLoweringPass.cc index 86bacf15a24..108e607ac1b 100644 --- a/runtime/onert/core/src/compiler/pass/ConstantLoweringPass.cc +++ b/runtime/onert/core/src/compiler/pass/ConstantLoweringPass.cc @@ -17,10 +17,9 @@ #include "ConstantLoweringPass.h" #include "backend/Backend.h" -#include -#include -#include +#include "ir/Graph.h" #include "util/logging.h" +#include "util/Utils.h" namespace onert { @@ -40,7 +39,7 @@ void ConstantLoweringPass::callback(const ir::OperationIndex &node_index, ir::IO if (object.isConstant()) { // All constant operand are already assinged at each backend by ContantInsertionPass. So a - // constant has `def` and `use` as the same PermuteFactor + // constant has `def` and `use` as the same backend auto operand_li = std::make_unique(); operand_li->addDefBackend(backend); operand_li->addUseBackend(backend); diff --git a/runtime/onert/core/src/compiler/pass/PermutationInsertionPass.h b/runtime/onert/core/src/compiler/pass/PermutationInsertionPass.h index 250cfb4480d..ed3515b07a3 100644 --- a/runtime/onert/core/src/compiler/pass/PermutationInsertionPass.h +++ b/runtime/onert/core/src/compiler/pass/PermutationInsertionPass.h @@ -20,7 +20,6 @@ #include "LoweredOperandPass.h" #include "compiler/BackendManager.h" #include "ir/Operand.h" -#include "compiler/PermuteFactor.h" namespace onert {