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

Method run

test/expr/ModuleTest.cpp:407–489  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

405class ModuleCloneTest : public MNNTestCase {
406public:
407 virtual bool run(int precision) {
408 auto y = _mobileNetV1Expr();
409 std::unique_ptr<MNN::NetT> net(new NetT);
410 Variable::save({y}, net.get());
411 y = nullptr;
412 flatbuffers::FlatBufferBuilder builderOutput(1024);
413 auto len = MNN::Net::Pack(builderOutput, net.get());
414 builderOutput.Finish(len);
415 int sizeOutput = builderOutput.GetSize();
416 auto bufferOutput = builderOutput.GetBufferPointer();
417 // Force use CPU Runtime
418 BackendConfig bnConfig;
419 auto exe = Executor::newExecutor(MNN_FORWARD_CPU, bnConfig, 1);
420 ExecutorScope scope(exe);
421 Module::Config config;
422 config.shapeMutable = false;
423 config.rearrange = true;
424 std::shared_ptr<Module> moduleBasic;
425 {
426 MNN::ScheduleConfig sconfig;
427 sconfig.numThread = 1;
428 std::vector<MNN::ScheduleConfig> sconfigs = {sconfig};
429 std::shared_ptr<Executor::RuntimeManager> rtMgr(Executor::RuntimeManager::createRuntimeManager(sconfigs));
430 moduleBasic.reset(Module::load({"Input"}, {"Prob"}, bufferOutput, sizeOutput, rtMgr, &config), Module::destroy);
431 }
432 auto makeInput = []() {
433 auto varp = _Input({1, 3, 224, 224}, NC4HW4, halide_type_of<float>());
434 auto ptr = varp->writeMap<float>();
435 int size = varp->getInfo()->size;
436 for (int i=0; i < size; ++i) {
437 ptr[i] = (float) i / 1000.0f;
438 }
439 return varp;
440 };
441 auto basicResult = moduleBasic->onForward({makeInput()});
442 float targetAvage = _ReduceMean(basicResult[0])->readMap<float>()[0];
443
444 /* Clone Module Begin */
445 int cloneNumber = 4;
446 std::vector<std::shared_ptr<Executor>> cloneExecutors(cloneNumber);
447 std::vector<std::shared_ptr<Module>> cloneModules(cloneNumber);
448 for (int i=0; i<cloneNumber; ++i) {
449 cloneExecutors[i] = Executor::newExecutor(MNN_FORWARD_CPU, bnConfig, 1);
450 ExecutorScope current(cloneExecutors[i]);
451 cloneModules[i].reset(Module::clone(moduleBasic.get()));
452 }
453 /* Clone Module End */
454
455 /* Execute Module with Multi-Thread Begin*/
456 std::vector<bool> result(cloneNumber);
457 {
458 std::vector<std::thread> threads;
459 for (int i=0; i<cloneNumber; ++i) {
460 auto curExe = cloneExecutors[i];
461 auto curMod = cloneModules[i];
462 threads.emplace_back(([curExe, curMod, i, &result, &makeInput, targetAvage] {
463 result[i] = true;
464 ExecutorScope current(curExe);

Callers

nothing calls this directly

Calls 14

_InputFunction · 0.85
makeInputFunction · 0.85
_ReduceMeanFunction · 0.85
joinMethod · 0.80
_mobileNetV1ExprFunction · 0.70
saveFunction · 0.50
loadFunction · 0.50
cloneFunction · 0.50
getMethod · 0.45
FinishMethod · 0.45
GetSizeMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected