Do compilation with the options.
47{
48
49
50
51 {
52 if (!_options)
53 throw std::runtime_error{"Empty compile option"};
54
55
56
58 throw std::runtime_error("NYI: Profiling mode for multiple model is not supported yet");
59
62 }
63
64
65 auto const model_count = _nnpkg->model_count();
66 for (uint16_t i = 0; i < model_count; i++)
67 {
69 throw std::runtime_error("MultiModelCompiler can only compile models for inference.");
70 }
71
72 for (uint16_t i = 0; i < model_count; i++)
73 {
75 auto &subg = nnfw::misc::polymorphic_downcast<ir::Graph &>(graph);
76
77
78 pass::PassRunner{}
79 .append(std::make_unique<pass::ConstantOutputPass>(subg))
80 .append(std::make_unique<pass::OddOutputPass>(subg))
81 .run();
82
83
84 pass::PassRunner{}.append(std::make_unique<pass::UnusedOperandEliminationPass>(subg)).run();
85 });
86 }
87
88
89
90
91
94
95
96
97 std::unique_ptr<util::TracingCtx> tracing_ctx = nullptr;
98
99
100 auto model_edges = std::make_unique<ir::ModelEdges>(_nnpkg->model_edges());
101
102
103 std::unordered_map<ir::ModelIndex, std::shared_ptr<backend::custom::IKernelBuilder>>
104 custom_kernel_builders;
105 for (uint16_t i = 0; i < model_count; i++)
106 {
108 custom_kernel_builders[model_index] = _nnpkg->model(model_index)->getKernelBuilder();
109 }
110
111
113 std::unordered_map<ir::SubgraphIndex, std::unique_ptr<compiler::LoweredGraph>>>
114 lowered_subgs;
115
116 for (uint16_t i = 0; i < model_count; i++)
117 {
119 auto model = _nnpkg->model(model_index);
120
122 auto &subg = nnfw::misc::polymorphic_downcast<ir::Graph &>(graph);
123
124 dot_dumper.dump(subg,
125 nnfw::misc::str(
"before_lower_model-", i,
"-subg-", subg_index.value()));
126
127 lowered_subgs[model_index][subg_index] =
128 std::make_unique<compiler::LoweredGraph>(subg, *_options);
129
130 if (tracing_ctx != nullptr)
131 tracing_ctx->setSubgraphIndex(&(lowered_subgs[model_index][subg_index]->
graph()),
132 subg_index.value());
133 });
134 }
135
136 _nnpkg.reset();
137
138 for (const auto &[model_index, model_lsubg] : lowered_subgs)
139 {
140 for (const auto &[subg_index, lowered_subg] : model_lsubg)
141 {
142 dot_dumper.dump(*lowered_subg,
nnfw::misc::str(
"after_lower_model-", model_index.value(),
143 "-subg-", subg_index.value()));
144 }
145 }
146
147
148 for (auto &&pair : lowered_subgs)
149 {
150 auto &model_lsubgs = pair.second;
151
152
153 std::unordered_map<ir::SubgraphIndex, std::unique_ptr<StaticShapeInferer>> inferers =
154 createStaticShapeInferers(model_lsubgs);
155
157 inferers.at(primary_subg_idx)->infer();
158
159 for (const auto &pair_inferer : inferers)
160 {
161 const auto inferer = pair_inferer.second.get();
162 inferer->dump();
163 }
164 }
165
166
167
168
169
170
171
172
173 for (const auto &pair : lowered_subgs)
174 {
175 const auto &model_lsubgs = pair.second;
176
177 for (const auto &pair_inner : model_lsubgs)
178 {
179 const auto &lowered_subg = pair_inner.second;
180 compiler::ShapeValidator{lowered_subg->graph()}();
181 }
182 }
183
184
185
186
187 auto executors = std::make_shared<exec::MultiModelExecutors>(std::move(model_edges));
188 for (auto &&pair : lowered_subgs)
189 {
190 auto const &model_index = pair.first;
191 auto &model_lsubgs = pair.second;
192
193 for (auto &&pair_inner : model_lsubgs)
194 {
195 auto const subg_index = pair_inner.first;
196 auto &lowered_subg = pair_inner.second;
197 auto const indexed_ranks = lowered_subg->indexed_ranks();
198
199 ir::OperationDumper dumper("Executor generation of Subgraph " +
200 std::to_string(subg_index.value()));
201 lowered_subg->graph().operations().iterate(
203
204 ExecutorFactoryArgs
args;
205 args.tracing_ctx = tracing_ctx.get();
206 args.options = _options;
207 args.model_index = model_index;
208 args.custom_kernel_builder = custom_kernel_builders[model_index];
209 auto executor = std::unique_ptr<exec::IExecutor>{
212 executors->emplace(model_index, subg_index, std::move(executor));
213 }
214 }
215
216
217
218
219 return std::make_shared<CompilerArtifact>(executors, std::move(tracing_ctx));
220}
exec::IExecutor * create(std::unique_ptr< compiler::LoweredGraph > lowered_graph, const std::shared_ptr< exec::IExecutors > &executors, const ExecutorFactoryArgs &args)
static ExecutorFactory & get()
IndexIterator iterate(const Shape &shape)
Create an object of IndexIterator for kernel.
std::string str(Args &&...args)
::onert::util::Index< uint32_t, OperationIndexTag > OperationIndex
::onert::util::Index< uint16_t, ModelIndexTag > ModelIndex
::onert::util::Index< uint16_t, SubgraphIndexTag > SubgraphIndex
void forceInternalOptions()
Force default values of CompilerOptions for correct compilations.
void verboseOptions()
Print option value.
virtual void setIndexedRanks(std::shared_ptr< ir::OperationIndexMap< int64_t > >)=0
Set an ordering on operations.