MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / update_io

Method update_io

lite/load_and_run/src/models/model_mdl.cpp:183–218  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

181}
182
183void ModelMdl::update_io() {
184 //! update output varlist when input shape maybe change(some pass excution
185 //! time depends on the shape of init input)
186 mgb::thin_hash_table::ThinHashMap<mgb::cg::SymbolVar, mgb::cg::SymbolVar> varmap;
187 auto&& network = m_load_result;
188 std::unordered_map<void*, std::string> tensor_name_map;
189 for (auto& input : network.tensor_map) {
190 tensor_name_map.insert({input.second->raw_ptr(), input.first});
191 }
192 mgb::cg::DepOprIter dep([&](mgb::cg::OperatorNodeBase* opr) {
193 if (auto h2d = opr->try_cast_final<mgb::opr::Host2DeviceCopy>()) {
194 if (tensor_name_map.find(h2d->host_data()->raw_ptr()) !=
195 tensor_name_map.end()) {
196 //! make new h2d opr with new host tensor shape
197 std::string name = tensor_name_map[h2d->host_data()->raw_ptr()];
198 std::shared_ptr<mgb::HostTensorND> new_tensor =
199 std::make_shared<mgb::HostTensorND>();
200 new_tensor->copy_from(*h2d->host_data());
201
202 auto h2d_opr = mgb::opr::Host2DeviceCopy::make(
203 *h2d->owner_graph(), new_tensor, h2d->param(), h2d->config());
204 //! rename new h2d with given name
205 h2d_opr.node()->owner_opr()->name(name);
206 varmap[h2d->output(0)] = h2d_opr;
207 }
208 }
209 });
210 //! get replace var map
211 for (auto&& i : network.output_var_list)
212 dep.add(i);
213 //! replace new h2d and update related var shape
214 if (!varmap.empty()) {
215 auto output_vars = mgb::cg::replace_vars(network.output_var_list, varmap);
216 network.output_var_list = output_vars;
217 }
218}

Callers 1

config_modelMethod · 0.45

Calls 15

replace_varsFunction · 0.85
makeFunction · 0.50
insertMethod · 0.45
raw_ptrMethod · 0.45
findMethod · 0.45
endMethod · 0.45
copy_fromMethod · 0.45
owner_graphMethod · 0.45
paramMethod · 0.45
nameMethod · 0.45
owner_oprMethod · 0.45
nodeMethod · 0.45

Tested by

no test coverage detected