| 998 | class ConstMemoryReplaceTest : public MNNTestCase { |
| 999 | public: |
| 1000 | virtual bool run(int precision) { |
| 1001 | auto x = _Input({1, 4, 1, 1}, NC4HW4); |
| 1002 | auto y = _Const(0.3f, {1, 1, 4, 1}, NC4HW4); |
| 1003 | auto z = x * y; |
| 1004 | auto w0 = _Round(_ReduceSum(_Convert(y, NHWC))); |
| 1005 | z = z + _Unsqueeze(w0, {0}); |
| 1006 | auto w1 = _Scalar<int>(1); |
| 1007 | auto shape = _Stack({w1, _Cast<int>(w0), w1, w1}, -1); |
| 1008 | auto ones = _Fill(shape, _Scalar<float>(0.3f)); |
| 1009 | auto res = z + ones; |
| 1010 | x->writeMap<float>(); |
| 1011 | auto ptr = res->readMap<float>(); |
| 1012 | if (nullptr == ptr) { |
| 1013 | FUNC_PRINT(1); |
| 1014 | return false; |
| 1015 | } |
| 1016 | flatbuffers::FlatBufferBuilder builderOutput(1024); |
| 1017 | { |
| 1018 | std::shared_ptr<MNN::NetT> net(new NetT); |
| 1019 | Variable::save({res}, net.get()); |
| 1020 | y = nullptr; |
| 1021 | auto len = MNN::Net::Pack(builderOutput, net.get()); |
| 1022 | builderOutput.Finish(len); |
| 1023 | } |
| 1024 | int sizeOutput = builderOutput.GetSize(); |
| 1025 | auto bufferOutput = builderOutput.GetBufferPointer(); |
| 1026 | std::shared_ptr<Interpreter> net(Interpreter::createFromBuffer((void*)bufferOutput, sizeOutput), Interpreter::destroy); |
| 1027 | ScheduleConfig config; |
| 1028 | config.numThread = 4; |
| 1029 | config.type = ExecutorScope::Current()->getAttr()->firstType; |
| 1030 | auto s1 = net->createSession(config); |
| 1031 | int resizeCode; |
| 1032 | net->getSessionInfo(s1, Interpreter::RESIZE_STATUS, &resizeCode); |
| 1033 | if (resizeCode != 0) { |
| 1034 | FUNC_PRINT(1); |
| 1035 | return false; |
| 1036 | } |
| 1037 | net->runSession(s1); |
| 1038 | net->resizeTensor(net->getSessionInput(s1, nullptr), {1, 1, 1, 1}); |
| 1039 | net->resizeSession(s1); |
| 1040 | return resizeCode == 0; |
| 1041 | } |
| 1042 | }; |
| 1043 | MNNTestSuiteRegister(ConstMemoryReplaceTest, "expr/ConstMemoryReplaceTest"); |
| 1044 |
nothing calls this directly
no test coverage detected