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

Method run

test/expr/ModuleTest.cpp:324–401  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

322 }
323 }
324 virtual bool run(int precision) {
325 auto executor = cloneCurrentExecutor();
326 ExecutorScope scope(executor);
327 std::vector<int8_t> buffer;
328#ifdef MNN_REDUCE_SIZE
329 return true;
330#endif
331
332 // construct
333 {
334 auto x = _Input({1, 3, 5, 7}, NCHW, halide_type_of<int>());
335 x->setName("data");
336 auto x1 = _Input({1, 3, 5, 7}, NCHW, halide_type_of<int>());
337 x1->setName("data1");
338 auto y = x + x1;
339 y->setName("o0");
340 auto y1 = x - x1;
341 y1->setName("o1");
342 auto limit = _Input({}, NCHW, halide_type_of<int>());
343 limit->setName("limit");
344 auto cond = _Input({}, NCHW, halide_type_of<int>());
345 cond->setName("cond");
346 auto resCond = _Scalar<int>(1);
347 resCond->setName("condresult");
348 ExecutorScope::Current()->registerSubGraph("body", {resCond, y, y1}, {limit, cond, x, x1});
349 auto u = _Loop({limit, resCond, x, x1}, "body");
350 u[0]->setName("o0");
351 u[1]->setName("o1");
352 buffer = Variable::save(u);
353 }
354 // Execute
355 std::shared_ptr<Module> loopModule(Module::load({"limit", "data", "data1"}, {"o0", "o1"}, (const uint8_t*)buffer.data(), buffer.size()), Module::destroy);
356 auto limit = _Input({}, NCHW, halide_type_of<int>());
357 auto x = _Input({1, 3, 5, 7}, NCHW, halide_type_of<int>());
358 auto x1 = _Input({1, 3, 5, 7}, NCHW, halide_type_of<int>());
359 auto size = x->getInfo()->size;
360 std::vector<int> inputPtr(size);
361 std::vector<int> inputPtr2(size);
362 for (int i=0; i<size; ++i) {
363 inputPtr[i] = i;
364 inputPtr2[i] = i / 2;
365 }
366 std::vector<int> outputPtr(size);
367 std::vector<int> outputPtr2(size);
368 {
369 auto xPtr = x->writeMap<int>();
370 ::memcpy(xPtr, inputPtr.data(), inputPtr.size() * sizeof(int));
371 auto x1Ptr = x1->writeMap<int>();
372 ::memcpy(x1Ptr, inputPtr2.data(), inputPtr2.size() * sizeof(int));
373 }
374 auto testFunc = [&](int limitIndex) {
375 limit->writeMap<int>()[0] = limitIndex;
376 auto y = loopModule->onForward({limit, x, x1});
377 auto yPtr = y[0]->readMap<int>();
378 auto yPtr1 = y[1]->readMap<int>();
379 _computeLoop(size, outputPtr.data(), outputPtr2.data(), inputPtr.data(), inputPtr2.data(), limitIndex);
380 for (int i=0; i<size; ++i) {
381 if (yPtr[i] != outputPtr[i]) {

Callers

nothing calls this directly

Calls 12

cloneCurrentExecutorFunction · 0.85
_InputFunction · 0.85
_LoopFunction · 0.85
registerSubGraphMethod · 0.80
saveFunction · 0.50
loadFunction · 0.50
setNameMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
getInfoMethod · 0.45
onForwardMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected