ONE - On-device Neural Engine
Loading...
Searching...
No Matches
onert::compiler::pass::PermutationIOPass Class Reference

Pass to insert permutation operations for input and output for layout and/or data type conversions. More...

#include <PermutationIOPass.h>

Collaboration diagram for onert::compiler::pass::PermutationIOPass:

Public Member Functions

 PermutationIOPass (ir::Graph &graph, const CompilerOptions &options, const ir::ModelIndex &model_index, const ir::SubgraphIndex &subg_index)
 
std::string id () override
 
void run () override
 
- Public Member Functions inherited from onert::compiler::pass::Pass
 Pass (ir::Graph &graph)
 
virtual ~Pass ()=default
 
- Public Member Functions inherited from onert::compiler::pass::IPass
virtual ~IPass ()=default
 

Additional Inherited Members

- Protected Attributes inherited from onert::compiler::pass::Pass
ir::Graph_graph
 

Detailed Description

Pass to insert permutation operations for input and output for layout and/or data type conversions.

If actual layout or data type of input/output by user request is different with model's layout or data type, this pass will insert permutation operations for input/output nodes.

If actual layout and data type of input/output by user request is same with model's layout and data type, this pass does nothing.

Definition at line 42 of file PermutationIOPass.h.

Constructor & Destructor Documentation

◆ PermutationIOPass()

onert::compiler::pass::PermutationIOPass::PermutationIOPass ( ir::Graph graph,
const CompilerOptions options,
const ir::ModelIndex model_index,
const ir::SubgraphIndex subg_index 
)
inline

Definition at line 46 of file PermutationIOPass.h.

48 : Pass(graph), _options(options), _model_index(model_index), _subg_index(subg_index)
49 {
50 }
Pass(ir::Graph &graph)
Definition Pass.h:35

Member Function Documentation

◆ id()

std::string onert::compiler::pass::PermutationIOPass::id ( )
inlineoverridevirtual

Implements onert::compiler::pass::Pass.

Definition at line 53 of file PermutationIOPass.h.

53{ return "PermutationIOPass"; }

◆ run()

void onert::compiler::pass::PermutationIOPass::run ( )
overridevirtual

Implements onert::compiler::pass::Pass.

Definition at line 29 of file PermutationIOPass.cc.

30{
31 if (_options.input_layout.size() == 0 && _options.output_layout.size() == 0 &&
32 _options.input_type.size() == 0 && _options.output_type.size() == 0)
33 return;
34
35 for (auto i = ir::IOIndex{0}; i < ir::IOIndex{_graph.getInputs().size()}; i++)
36 {
37 const auto &iodesc = ir::IODesc{_model_index, _subg_index, i};
38 if (_options.input_layout.count(iodesc) == 0 && _options.input_type.count(iodesc) == 0)
39 continue;
40
41 const auto index = _graph.getInputs().at(i);
42 const auto &type = _options.input_type.count(iodesc) > 0
43 ? _options.input_type.at(iodesc)
44 : _graph.operands().at(index).typeInfo();
45 const auto layout =
46 _options.input_layout.count(iodesc) > 0 ? _options.input_layout.at(iodesc) : ir::Layout::NHWC;
47
48 insertInputPermute(index, type, layout);
49 }
50
51 for (auto i = ir::IOIndex{0}; i < ir::IOIndex{_graph.getOutputs().size()}; i++)
52 {
53 const auto &iodesc = ir::IODesc{_model_index, _subg_index, i};
54 if (_options.output_layout.count(iodesc) == 0 && _options.output_type.count(iodesc) == 0)
55 continue;
56
57 const auto index = _graph.getOutputs().at(i);
58 const auto &type = _options.output_type.count(iodesc) > 0
59 ? _options.output_type.at(iodesc)
60 : _graph.operands().at(index).typeInfo();
61 const auto layout = _options.output_layout.count(iodesc) > 0 ? _options.output_layout.at(iodesc)
63
64 insertOutputPermute(index, type, layout);
65 }
66}
int32_t type
const Operands & operands() const override
Definition Graph.h:103
const OperandIndexSequence & getInputs() const override
Definition Graph.h:97
const OperandIndexSequence & getOutputs() const override
Definition Graph.h:99
const OperandIndex & at(IOIndex set_index) const
const Object & at(const Index &index) const
Get the object that is associated with the given index.
loco::GraphInputIndex index(const TFPlaceholder *node)
Definition TFNode.cpp:54
std::tuple< ModelIndex, SubgraphIndex, IOIndex > IODesc
Definition NNPkg.h:30
::onert::util::Index< uint32_t, IOIndexTag > IOIndex
Definition Index.h:36
int32_t size[5]
Definition Slice.cpp:35
std::unordered_map< ir::IODesc, ir::TypeInfo > output_type
std::unordered_map< ir::IODesc, ir::Layout > output_layout
std::unordered_map< ir::IODesc, ir::TypeInfo > input_type
std::unordered_map< ir::IODesc, ir::Layout > input_layout

References onert::compiler::pass::Pass::_graph, onert::util::ObjectManager< Index, Object >::at(), onert::ir::OperandIndexSequence::at(), onert::ir::Graph::getInputs(), onert::ir::Graph::getOutputs(), onert::compiler::CompilerOptions::input_layout, onert::compiler::CompilerOptions::input_type, onert::ir::NHWC, onert::ir::Graph::operands(), onert::compiler::CompilerOptions::output_layout, onert::compiler::CompilerOptions::output_type, size, and type.


The documentation for this class was generated from the following files: