Skip to content

Commit

Permalink
[onert] Remove PermuteFactor (Samsung#13716)
Browse files Browse the repository at this point in the history
This commit removes PermuteFactor class and usage.
Layout between backends is always same.

ONE-DCO-1.0-Signed-off-by: Hyeongseok Oh <[email protected]>
  • Loading branch information
hseok-oh authored Aug 20, 2024
1 parent aa9ebd2 commit dec3d68
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 203 deletions.
130 changes: 0 additions & 130 deletions runtime/onert/core/include/compiler/PermuteFactor.h

This file was deleted.

28 changes: 0 additions & 28 deletions runtime/onert/core/src/compiler/PermuteFactor.cc

This file was deleted.

21 changes: 9 additions & 12 deletions runtime/onert/core/src/compiler/pass/ConstantInsertionPass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#include "ConstantInsertionPass.h"

#include "backend/Backend.h"
#include "ir/Graph.h"
#include "util/Utils.h"
#include "util/logging.h"
Expand All @@ -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)
{
Expand All @@ -42,42 +40,41 @@ 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
auto &replaced_object = _graph.operands().at(replaced_input);
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());
Expand Down
33 changes: 5 additions & 28 deletions runtime/onert/core/src/compiler/pass/ConstantInsertionPass.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
#ifndef __ONERT_COMPILER_PASS_CONSTANT_INSERTION_PASS_H__
#define __ONERT_COMPILER_PASS_CONSTANT_INSERTION_PASS_H__

#include <compiler/PermuteFactor.h>
#include <ir/Index.h>
#include "LoweredOperationPass.h"
#include "backend/Backend.h"
#include "ir/Index.h"

#include <unordered_map>
#include <utility>

namespace onert
{
Expand All @@ -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<ir::OperandIndex>()(key.index) ^ (hash<PermuteFactor>()(key.factor) << 1);
}
};

std::unordered_map<ReplaceKey, ir::OperandIndex, KeyHasher> _replace_operands_map;
std::unordered_map<ir::OperandIndex, PermuteFactor> _keep_operands_map;
std::unordered_map<const backend::Backend *, ir::OperandIndex> _replace_operands_map;
std::unordered_map<ir::OperandIndex, const backend::Backend *> _keep_operands_map;
};

} // namespace pass
Expand Down
7 changes: 3 additions & 4 deletions runtime/onert/core/src/compiler/pass/ConstantLoweringPass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
#include "ConstantLoweringPass.h"

#include "backend/Backend.h"
#include <ir/Graph.h>
#include <compiler/PermuteFactor.h>
#include <util/Utils.h>
#include "ir/Graph.h"
#include "util/logging.h"
#include "util/Utils.h"

namespace onert
{
Expand All @@ -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<compiler::OperandLowerInfo>();
operand_li->addDefBackend(backend);
operand_li->addUseBackend(backend);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "LoweredOperandPass.h"
#include "compiler/BackendManager.h"
#include "ir/Operand.h"
#include "compiler/PermuteFactor.h"

namespace onert
{
Expand Down

0 comments on commit dec3d68

Please sign in to comment.