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

Method detect_replace

src/tensorrt/impl/opr_replace.cpp:1343–1424  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1341}
1342
1343void TensorRTReplacePass::Impl::detect_replace() {
1344 auto cb = [this](OperatorNodeBase* opr) { m_const_var_propogate->add_opr(opr); };
1345 m_opt_state.graph().iter(cb);
1346
1347 auto on_opr = [this](OperatorNodeBase* opr) {
1348 ++m_opr_num;
1349 Maybe<std::string> irreplaceable_msg = has_fail_msg(opr);
1350 TensorRTGraphFeatureBits feature_bits =
1351 is_quantized_int8_operator(opr) ? TensorRTGraphFeatureBits::NCHW4_QINT8
1352 : TensorRTGraphFeatureBits::NCHW_FLOAT;
1353 if (!irreplaceable_msg.valid()) {
1354 size_t max = 1;
1355 for (auto i : opr->input()) {
1356 if (!has_fail_msg(i->owner_opr()).valid())
1357 update_max(max, m_graph_map[i->owner_opr()]);
1358 else
1359 update_max(max, m_graph_map[i->owner_opr()] + 1);
1360 }
1361
1362 size_t max_update = max;
1363 for (; max_update <= m_tensorrt_graphs.size(); max_update++) {
1364 TensorRTGraphFeatureBits trt_graph_feature_bits =
1365 m_tensorrt_graphs[max_update - 1]->feature_bits;
1366 if (trt_graph_feature_bits == feature_bits)
1367 break;
1368 }
1369 max = max_update;
1370
1371 m_graph_map[opr] = max;
1372 if (max > m_tensorrt_graphs.size()) {
1373 opr->output(0)->comp_node().activate();
1374 m_tensorrt_graphs.push_back(
1375 std::make_shared<TensorRTGraph>(feature_bits));
1376 }
1377 for (auto i : opr->input()) {
1378 if (m_graph_map[i->owner_opr()] != max) {
1379 m_tensorrt_graphs[max - 1]->inputs.insert(i);
1380 if (!has_fail_msg(i->owner_opr()).valid()) {
1381 //! TODO: check
1382 m_tensorrt_graphs[m_graph_map[i->owner_opr()] - 1]
1383 ->outputs.insert(i);
1384 }
1385 }
1386 }
1387 } else {
1388 static const ThinHashSet<Typeinfo*> ignore_types{
1389 opr::SharedDeviceTensor::typeinfo(),
1390 opr::ImmutableTensor::typeinfo(), opr::Host2DeviceCopy::typeinfo(),
1391 opr::MultipleDeviceTensorHolder::typeinfo()};
1392 if (!ignore_types.count(opr->dyn_typeinfo())) {
1393 ++m_opr_fail_num;
1394 if (m_opr_fail.size() < OPR_FAIL_LOG_NUM) {
1395 FailInfo fail_info;
1396 fail_info.opr = opr;
1397 fail_info.fail_msg = irreplaceable_msg.val();
1398 m_opr_fail.push_back(fail_info);
1399 }
1400 }

Callers

nothing calls this directly

Calls 15

update_maxFunction · 0.85
add_oprMethod · 0.45
iterMethod · 0.45
graphMethod · 0.45
validMethod · 0.45
inputMethod · 0.45
owner_oprMethod · 0.45
sizeMethod · 0.45
activateMethod · 0.45
comp_nodeMethod · 0.45
outputMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected