MCPcopy Create free account
hub / github.com/alibaba/MNN / _run

Method _run

test/expr/ModuleTest.cpp:1326–1403  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1324 }
1325
1326 bool _run(int precision, bool shapeMultable) {
1327 BackendConfig bnConfig;
1328 auto exe = Executor::newExecutor(MNN_FORWARD_CPU, bnConfig, 1);
1329 ExecutorScope scope(exe);
1330 Module::Config config;
1331 config.shapeMutable = shapeMultable;
1332 config.rearrange = true;
1333 std::vector<int8_t> buffer;
1334 {
1335 // Make Buffer
1336 auto x0 = _Input({1, 3, -1, -1}, NCHW, halide_type_of<float>());
1337 x0->setName("x0");
1338 auto y0 = _mobileNetV1Expr(_Convert(x0, NC4HW4), false);
1339 y0->setName("y0");
1340 buffer = Variable::save({y0});
1341 }
1342 auto rtInfo = Express::ExecutorScope::Current()->getRuntime();
1343 auto rt = rtInfo.first.begin()->second;
1344 MNN::ScheduleConfig sconfig;
1345 std::vector<MNN::ScheduleConfig> sconfigs = {sconfig};
1346 std::shared_ptr<Executor::RuntimeManager> rtMgr(Executor::RuntimeManager::createRuntimeManager(sconfigs));
1347 rtMgr->setMode(Interpreter::Session_Memory_Collect);
1348 std::shared_ptr<MNN::Express::Module> m0(Module::load({"x0"}, {"y0"}, (const unsigned char*)buffer.data(), buffer.size(), rtMgr, &config), Module::destroy);
1349 std::shared_ptr<MNN::Express::Module> m1(Module::load({"x0"}, {"y0"}, (const unsigned char*)buffer.data(), buffer.size(), rtMgr, &config), Module::destroy);
1350 float memoryInit = 0.0f;
1351 rtMgr->getInfo(Interpreter::MEMORY, &memoryInit);
1352 FUNC_PRINT_ALL(memoryInit, f);
1353 auto x = _Input({1, 3, 96, 96}, NCHW, halide_type_of<float>());
1354 x->writeMap<float>();
1355 x->unMap();
1356 auto x1 = _Input({1, 3, 97, 97}, NCHW, halide_type_of<float>());
1357 x1->writeMap<float>();
1358 x1->unMap();
1359 auto x2 = _Input({1, 3, 95, 95}, NCHW, halide_type_of<float>());
1360 x2->writeMap<float>();
1361 x2->unMap();
1362 float memoryCurrent = 0.0f;
1363 auto compute = [&](){
1364 m0->onForward({x});
1365 rtMgr->getInfo(Interpreter::MEMORY, &memoryCurrent);
1366 auto dynamic0 = memoryCurrent - memoryInit;
1367 FUNC_PRINT_ALL(dynamic0, f);
1368 m1->onForward({x1});
1369 rtMgr->getInfo(Interpreter::MEMORY, &memoryCurrent);
1370 auto dynamic1 = memoryCurrent - memoryInit;
1371
1372 FUNC_PRINT_ALL(dynamic1, f);
1373 m1->onForward({x2});
1374 rtMgr->getInfo(Interpreter::MEMORY, &memoryCurrent);
1375 auto dynamic2 = memoryCurrent - memoryInit;
1376 FUNC_PRINT_ALL(dynamic2, f);
1377
1378 if (dynamic1 > dynamic0 * 1.1f || dynamic2 > dynamic1) {
1379 MNN_ERROR("Dynamic Memory reuse error\n");
1380 return false;
1381 }
1382 return true;
1383 };

Callers

nothing calls this directly

Calls 15

_InputFunction · 0.85
_ConvertFunction · 0.85
unMapMethod · 0.80
gcMethod · 0.80
_mobileNetV1ExprFunction · 0.70
saveFunction · 0.50
loadFunction · 0.50
setNameMethod · 0.45
getRuntimeMethod · 0.45
beginMethod · 0.45
setModeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected