| 605 | class SpecialSessionTest : public MNNTestCase { |
| 606 | public: |
| 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 | }; |
| 654 | MNNTestSuiteRegister(SpecialSessionTest, "expr/SpecialSessionTest"); |
nothing calls this directly
no test coverage detected