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)
 
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 
)
inline

Definition at line 46 of file PermutationIOPass.h.

47 : Pass(graph), _options(options)
48 {
49 }
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 52 of file PermutationIOPass.h.

52{ 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 if (_options.input_layout.count(i) == 0 && _options.input_type.count(i) == 0)
38 continue;
39
40 const auto index = _graph.getInputs().at(i);
41 const auto &type = _options.input_type.count(i) > 0 ? _options.input_type.at(i)
42 : _graph.operands().at(index).typeInfo();
43 const auto layout =
44 _options.input_layout.count(i) > 0 ? _options.input_layout.at(i) : ir::Layout::NHWC;
45
46 insertInputPermute(index, type, layout);
47 }
48
49 for (auto i = ir::IOIndex{0}; i < ir::IOIndex{_graph.getOutputs().size()}; i++)
50 {
51 if (_options.output_layout.count(i) == 0 && _options.output_type.count(i) == 0)
52 continue;
53
54 const auto index = _graph.getOutputs().at(i);
55 const auto &type = _options.output_type.count(i) > 0 ? _options.output_type.at(i)
56 : _graph.operands().at(index).typeInfo();
57 const auto layout =
58 _options.output_layout.count(i) > 0 ? _options.output_layout.at(i) : ir::Layout::NHWC;
59
60 insertOutputPermute(index, type, layout);
61 }
62}
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.
type
Definition infer.py:18
loco::GraphInputIndex index(const TFPlaceholder *node)
Definition TFNode.cpp:54
::onert::util::Index< uint32_t, IOIndexTag > IOIndex
Definition Index.h:36
int32_t size[5]
Definition Slice.cpp:35
std::unordered_map< ir::IOIndex, ir::TypeInfo > output_type
std::unordered_map< ir::IOIndex, ir::Layout > input_layout
std::unordered_map< ir::IOIndex, ir::Layout > output_layout
std::unordered_map< ir::IOIndex, ir::TypeInfo > input_type

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, and size.


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