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

Method run

test/expr/ModuleTest.cpp:607–651  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

605class SpecialSessionTest : public MNNTestCase {
606public:
607 virtual bool run(int precision) {
608 {
609 int expect = 5;
610 auto x = _Input({10}, NHWC, halide_type_of<int>());
611 auto y = _Scalar<int>(expect);
612 auto z = x * x + y;
613 z->setName("test");
614 auto res = z + y;
615 auto buffer = Variable::save({res});
616 std::shared_ptr<Interpreter> net(Interpreter::createFromBuffer((void*)buffer.data(), buffer.size()), Interpreter::destroy);
617 ScheduleConfig config;
618 config.numThread = 1;
619 net->setSessionMode(Interpreter::Session_Debug);
620 auto session = net->createSession(config);
621
622 int directValue = -1;
623 int copyValue = -1;
624 MNN::TensorCallBack beforeCallBack = [&](const std::vector<MNN::Tensor*>& ntensors, const std::string& opName) {
625 auto origin = ntensors[1];
626 if (opName == "test") {
627 directValue = origin->host<int>()[0];
628 std::shared_ptr<MNN::Tensor> copyTensor(new MNN::Tensor(origin, MNN::Tensor::TENSORFLOW));
629 origin->copyToHostTensor(copyTensor.get());
630 copyValue = copyTensor->host<int>()[0];
631 }
632 return true;
633 };
634 MNN::TensorCallBack afterCallBack = [&](const std::vector<MNN::Tensor*>& ntensors, const std::string& opName) {
635 if (opName == "test") {
636 return false;
637 }
638 return true;
639 };
640 net->runSessionWithCallBack(session, beforeCallBack, afterCallBack);
641 if (expect != directValue) {
642 FUNC_PRINT(1);
643 return false;
644 }
645 if (expect != copyValue) {
646 FUNC_PRINT(1);
647 return false;
648 }
649 }
650 return true;
651 }
652
653};
654MNNTestSuiteRegister(SpecialSessionTest, "expr/SpecialSessionTest");

Callers

nothing calls this directly

Calls 10

_InputFunction · 0.85
setSessionModeMethod · 0.80
copyToHostTensorMethod · 0.80
saveFunction · 0.50
setNameMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
createSessionMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected