Do compilation with the options.
49{
50
51
52
53 {
54 if (!_options)
55 throw std::runtime_error{"Empty compile option"};
56
57
58
60 throw std::runtime_error("NYI: Profiling mode for multiple model is not supported yet");
61
64 }
65
66
67 auto const model_count = _nnpkg->model_count();
68 for (uint16_t i = 0; i < model_count; i++)
69 {
71 throw std::runtime_error("MultiModelCompiler can only compile models for inference.");
72 }
73
74 for (uint16_t i = 0; i < model_count; i++)
75 {
77 auto &subg = nnfw::misc::polymorphic_downcast<ir::Graph &>(graph);
78
79
80 pass::PassRunner{}
81 .append(std::make_unique<pass::ConstantOutputPass>(subg))
82 .append(std::make_unique<pass::OddOutputPass>(subg))
83 .run();
84
85
86 pass::PassRunner{}.append(std::make_unique<pass::UnusedOperandEliminationPass>(subg)).run();
87 });
88 }
89
90
91
92
93
96
97
98
99 std::unique_ptr<util::TracingCtx> tracing_ctx = nullptr;
100
101
102 auto model_edges = std::make_unique<ir::ModelEdges>(_nnpkg->model_edges());
103
104
105 std::unordered_map<ir::ModelIndex, std::shared_ptr<backend::custom::IKernelBuilder>>
106 custom_kernel_builders;
107 for (uint16_t i = 0; i < model_count; i++)
108 {
110 custom_kernel_builders[model_index] = _nnpkg->model(model_index)->getKernelBuilder();
111 }
112
113
115 std::unordered_map<ir::SubgraphIndex, std::unique_ptr<compiler::LoweredGraph>>>
116 lowered_subgs;
117
118 for (uint16_t i = 0; i < model_count; i++)
119 {
121 auto model = _nnpkg->model(model_index);
122
124 auto &subg = nnfw::misc::polymorphic_downcast<ir::Graph &>(graph);
125
126 dot_dumper.dump(subg,
127 nnfw::misc::str(
"before_lower_model-", i,
"-subg-", subg_index.value()));
128
129 lowered_subgs[model_index][subg_index] =
130 std::make_unique<compiler::LoweredGraph>(subg, *_options);
131
132 if (tracing_ctx != nullptr)
133 tracing_ctx->setSubgraphIndex(&(lowered_subgs[model_index][subg_index]->
graph()),
134 subg_index.value());
135 });
136 }
137
138 _nnpkg.reset();
139
140 for (const auto &pair : lowered_subgs)
141 {
142 const auto &model_index = pair.first;
143 const auto &model_lsubg = pair.second;
144
145 for (const auto &pair_inner : model_lsubg)
146 {
147 const auto &subg_index = pair_inner.first;
148 const auto &lowered_subg = pair_inner.second;
149 dot_dumper.dump(*lowered_subg,
nnfw::misc::str(
"after_lower_model-", model_index.value(),
150 "-subg-", subg_index.value()));
151 }
152 }
153
154
155 for (auto &&pair : lowered_subgs)
156 {
157 auto &model_lsubgs = pair.second;
158
159
160 std::unordered_map<ir::SubgraphIndex, std::unique_ptr<StaticShapeInferer>> inferers =
161 createStaticShapeInferers(model_lsubgs);
162
164 inferers.at(primary_subg_idx)->infer();
165
166 for (const auto &pair_inferer : inferers)
167 {
168 const auto inferer = pair_inferer.second.get();
169 inferer->dump();
170 }
171 }
172
173
174
175
176
177
178
179
180 for (const auto &pair : lowered_subgs)
181 {
182 const auto &model_lsubgs = pair.second;
183
184 for (const auto &pair_inner : model_lsubgs)
185 {
186 const auto &lowered_subg = pair_inner.second;
187 compiler::ShapeValidator{lowered_subg->graph()}();
188 }
189 }
190
191
192
193
194 auto executors = std::make_shared<exec::MultiModelExecutors>(std::move(model_edges));
195 for (auto &&pair : lowered_subgs)
196 {
197 auto const &model_index = pair.first;
198 auto &model_lsubgs = pair.second;
199
200 for (auto &&pair_inner : model_lsubgs)
201 {
202 auto const subg_index = pair_inner.first;
203 auto &lowered_subg = pair_inner.second;
204 auto const indexed_ranks = lowered_subg->indexed_ranks();
205
206 ir::OperationDumper dumper("Executor generation of Subgraph " +
207 std::to_string(subg_index.value()));
208 lowered_subg->graph().operations().iterate(
210
211 ExecutorFactoryArgs
args;
212 args.tracing_ctx = tracing_ctx.get();
213 args.options = _options;
214 args.model_index = model_index;
215 args.custom_kernel_builder = custom_kernel_builders[model_index];
216 auto executor = std::unique_ptr<exec::IExecutor>{
219 executors->emplace(model_index, subg_index, std::move(executor));
220 }
221 }
222
223
224
225
226 return std::make_shared<CompilerArtifact>(executors, std::move(tracing_ctx));
227}
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.