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

Method run

test/expr/ModuleTest.cpp:1000–1041  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

998class ConstMemoryReplaceTest : public MNNTestCase {
999public:
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};
1043MNNTestSuiteRegister(ConstMemoryReplaceTest, "expr/ConstMemoryReplaceTest");
1044

Callers

nothing calls this directly

Calls 15

_InputFunction · 0.85
_ConstFunction · 0.85
_RoundFunction · 0.85
_ReduceSumFunction · 0.85
_ConvertFunction · 0.85
_UnsqueezeFunction · 0.85
_StackFunction · 0.85
_FillFunction · 0.85
getSessionInfoMethod · 0.80
runSessionMethod · 0.80
resizeTensorMethod · 0.80
getSessionInputMethod · 0.80

Tested by

no test coverage detected