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

Method run

test/expr/ModuleTest.cpp:547–601  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

545class ModuleTestSpeed : public MNNTestCase {
546public:
547 virtual bool run(int precision) {
548 auto y = _mobileNetV1Expr();
549 std::unique_ptr<MNN::NetT> net(new NetT);
550 Variable::save({y}, net.get());
551 y = nullptr;
552 flatbuffers::FlatBufferBuilder builderOutput(1024);
553 auto len = MNN::Net::Pack(builderOutput, net.get());
554 builderOutput.Finish(len);
555 int sizeOutput = builderOutput.GetSize();
556 auto bufferOutput = builderOutput.GetBufferPointer();
557 // Force use CPU Runtime
558 BackendConfig bnConfig;
559 auto exe = Executor::newExecutor(MNN_FORWARD_CPU, bnConfig, 1);
560 ExecutorScope scope(exe);
561 Module::Config config;
562 config.shapeMutable = false;
563 config.rearrange = true;
564 auto x = _Input({1, 3, 224, 224}, NC4HW4, halide_type_of<float>());
565 auto xPtr = x->writeMap<float>();
566 ::memset(xPtr, 0, 1*3*224*224*sizeof(float));
567 x->unMap();
568 int runTime = 10;
569 std::shared_ptr<Module> interp0;
570 {
571 MNN::ScheduleConfig sconfig;
572 sconfig.numThread = 1;
573 std::vector<MNN::ScheduleConfig> sconfigs = {sconfig};
574 std::shared_ptr<Executor::RuntimeManager> rtMgr(Executor::RuntimeManager::createRuntimeManager(sconfigs));
575 interp0.reset(Module::load({"Input"}, {"Prob"}, bufferOutput, sizeOutput, rtMgr, &config), Module::destroy);
576 }
577 {
578 Timer _l;
579 for (int i=0; i<runTime; ++i) {
580 auto y0 = interp0->onForward({x});
581 }
582 MNN_PRINT("Thread 1 avg cost: %f ms\n", (float)_l.durationInUs() / 1000.0f / runTime);
583 }
584 std::shared_ptr<Module> interp1;
585 {
586 MNN::ScheduleConfig sconfig;
587 sconfig.numThread = 4;
588 std::vector<MNN::ScheduleConfig> sconfigs = {sconfig};
589 std::shared_ptr<Executor::RuntimeManager> rtMgr(Executor::RuntimeManager::createRuntimeManager(sconfigs));
590 rtMgr->setHint(Interpreter::STRICT_CHECK_MODEL, 0);
591 interp1.reset(Module::load({"Input"}, {"Prob"}, bufferOutput, sizeOutput, rtMgr, &config), Module::destroy);
592 }
593 {
594 Timer _l;
595 for (int i=0; i<runTime; ++i) {
596 auto y0 = interp1->onForward({x});
597 }
598 MNN_PRINT("Thread 4 avg cost: %f ms\n", (float)_l.durationInUs() / 1000.0f / runTime);
599 }
600 return true;
601 }
602};
603MNNTestSuiteRegister(ModuleTestSpeed, "expr/ModuleTestSpeed");
604

Callers

nothing calls this directly

Calls 12

_InputFunction · 0.85
unMapMethod · 0.80
durationInUsMethod · 0.80
_mobileNetV1ExprFunction · 0.70
saveFunction · 0.50
loadFunction · 0.50
getMethod · 0.45
FinishMethod · 0.45
GetSizeMethod · 0.45
resetMethod · 0.45
onForwardMethod · 0.45
setHintMethod · 0.45

Tested by

no test coverage detected