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

Method run

test/expr/ModuleShapeInfer.cpp:18–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16 return summer;
17 }
18 virtual bool run(int precision) {
19 auto executor = cloneCurrentExecutor();
20 ExecutorScope scope(executor);
21 std::vector<VARP> empty;
22 // Make Net
23 auto x = _Input({1, 3, 2, 2}, NCHW, halide_type_of<float>());
24 x->setName("x");
25 auto y = x * x;
26 VARP starts;
27 VARP sizes;
28 {
29 std::vector<int> sta = {0, 0, 1, 1};
30 std::vector<int> siz = {1, 1, 1, 1};
31 starts = _Const(sta.data(), {4}, NCHW, halide_type_of<int>());
32 sizes = _Const(siz.data(), {4}, NCHW, halide_type_of<int>());
33 }
34 auto z = _Slice(y, starts, sizes);
35 z->setName("z");
36 auto buffer = Variable::save({z});
37 ScheduleConfig config;
38 BackendConfig bnConfig;
39 bnConfig.precision = MNN::BackendConfig::Precision_Low;
40 config.backendConfig = &bnConfig;
41 std::shared_ptr<Executor::RuntimeManager> rt(Executor::RuntimeManager::createRuntimeManager(config), Executor::RuntimeManager::destroy);
42 std::shared_ptr<Module> net0(Module::load({"x"}, {"z"}, (const uint8_t*)buffer.data(), buffer.size(), rt), Module::destroy);
43 std::shared_ptr<Module> net1(Module::load({"x"}, {"z"}, (const uint8_t*)buffer.data(), buffer.size(), rt), Module::destroy);
44 x = _Input({1, 3, 2, 2}, NCHW, halide_type_of<float>());
45 // Run Init Value
46 auto inputPtr = x->writeMap<float>();
47 for (int i=0; i<x->getInfo()->size; ++i) {
48 inputPtr[i] = i;
49 }
50 y = net0->onForward({x})[0];
51 auto yPtr = y->readMap<float>();
52 auto ySize = y->getInfo()->size;
53 auto valueFirst = _reduceSum(yPtr, ySize);
54 for (int i=0; i<x->getInfo()->size; ++i) {
55 inputPtr[i] = x->getInfo()->size - i;
56 }
57 y = net0->onForward({x})[0];
58 yPtr = y->readMap<float>();
59 auto valueSecond = _reduceSum(yPtr, ySize);
60
61 // Shape Infer mode
62 auto code = net1->traceOrOptimize(Interpreter::Module_Forward_Separate);
63 if (0 != code) {
64 FUNC_PRINT(1);
65 return false;
66 }
67 for (int i=0; i<x->getInfo()->size; ++i) {
68 inputPtr[i] = i;
69 }
70 y = net1->onForward({x})[0];
71 yPtr = y->readMap<float>();
72 auto tmp = net1->onForward(empty);
73 if (tmp.size() > 0) {
74 FUNC_PRINT(1);
75 return false;

Callers

nothing calls this directly

Calls 12

cloneCurrentExecutorFunction · 0.85
_InputFunction · 0.85
_ConstFunction · 0.85
_SliceFunction · 0.85
traceOrOptimizeMethod · 0.80
saveFunction · 0.50
loadFunction · 0.50
setNameMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
getInfoMethod · 0.45
onForwardMethod · 0.45

Tested by

no test coverage detected