| 1407 | class PrearrangeTest : public MNNTestCase { |
| 1408 | public: |
| 1409 | virtual bool run(int precision) { |
| 1410 | // Make Model include convolution in shape compute and content compute |
| 1411 | auto x = _Input({1, 3, 24, 24}, NCHW, halide_type_of<float>()); |
| 1412 | x->setName("x"); |
| 1413 | auto xs = _Convert(_Reshape(_Cast<float>(_Shape(x, NCHW)), {1, 1, 2, 2}), NC4HW4); |
| 1414 | xs = _Convert(_Conv(1.0f, 0.0f, xs, {1, 1}, {2, 2}), NCHW); |
| 1415 | auto y = _Conv(0.1f, 0.0f, _Convert(x, NC4HW4), {3, 1}, {3, 3}); |
| 1416 | y = _Convert(y, NCHW); |
| 1417 | y = _ReduceMean(y); |
| 1418 | y = y * _Reciprocal(xs); |
| 1419 | auto info = y->getInfo(); |
| 1420 | y->setName("y"); |
| 1421 | auto buffer = Variable::save({y}); |
| 1422 | MNN::ScheduleConfig sconfig; |
| 1423 | BackendConfig bnConfig; |
| 1424 | bnConfig.precision = MNN::BackendConfig::Precision_Low; |
| 1425 | sconfig.backendConfig = &bnConfig; |
| 1426 | auto exe = Executor::newExecutor(MNN_FORWARD_CPU, bnConfig, 4); |
| 1427 | ExecutorScope scope(exe); |
| 1428 | std::vector<MNN::ScheduleConfig> sconfigs = {sconfig}; |
| 1429 | std::shared_ptr<Executor::RuntimeManager> rtMgr(Executor::RuntimeManager::createRuntimeManager(sconfigs)); |
| 1430 | rtMgr->setMode(Interpreter::Session_Memory_Collect); |
| 1431 | Module::Config config; |
| 1432 | config.rearrange = false; |
| 1433 | std::shared_ptr<MNN::Express::Module> m0(Module::load({"x"}, {"y"}, (const unsigned char*)buffer.data(), buffer.size(), rtMgr, &config), Module::destroy); |
| 1434 | config.rearrange = true; |
| 1435 | std::shared_ptr<MNN::Express::Module> m1(Module::load({"x"}, {"y"}, (const unsigned char*)buffer.data(), buffer.size(), rtMgr, &config), Module::destroy); |
| 1436 | auto size = x->getInfo()->size; |
| 1437 | auto xPtr = x->writeMap<float>(); |
| 1438 | for (int v=0; v<size; ++v) { |
| 1439 | xPtr[v] = 0.01f; |
| 1440 | } |
| 1441 | auto y0 = m0->onForward({x})[0]->readMap<float>()[0]; |
| 1442 | auto y1 = m1->onForward({x})[0]->readMap<float>()[0]; |
| 1443 | if (fabsf(y0 - y1) > 0.000001f) { |
| 1444 | return false; |
| 1445 | } |
| 1446 | rtMgr->setExternalPath(".", Interpreter::EXTERNAL_FEATUREMAP_DIR); |
| 1447 | std::shared_ptr<MNN::Express::Module> m2(Module::load({"x"}, {"y"}, (const unsigned char*)buffer.data(), buffer.size(), rtMgr, &config), Module::destroy); |
| 1448 | auto y2 = m2->onForward({x})[0]->readMap<float>()[0]; |
| 1449 | if (fabsf(y0 - y2) > 0.000001f) { |
| 1450 | return false; |
| 1451 | } |
| 1452 | return true; |
| 1453 | } |
| 1454 | }; |
| 1455 | MNNTestSuiteRegister(PrearrangeTest, "expr/PrearrangeTest"); |
| 1456 |
nothing calls this directly
no test coverage detected