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

Method run

test/expr/MemoryIncrease.cpp:103–162  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

101class MemoryIncreaseInterpTest : public MNNTestCase {
102public:
103 virtual bool run(int precision) {
104 auto x = _Input({1, 3, 224, 224}, NCHW, halide_type_of<float>());
105 auto y = _Interp({x}, 0.25, 0.25, 56, 56, 2, true);
106 y = _Convert(y, NCHW);
107 auto size = y->getInfo()->size;
108 int e = 14;
109 y = _Reshape(y, {e, -1});
110 int l = size / e;
111 VARP res;
112 {
113 std::unique_ptr<OpT> mat(new OpT);
114 mat->type = OpType_MatMul;
115 mat->main.type = OpParameter_MatMul;
116 mat->main.value = new MatMulT;
117 mat->main.AsMatMul()->transposeA = false;
118 mat->main.AsMatMul()->transposeB = false;
119
120 std::vector<float> bias(e, 0.0f);
121 auto biasVar = _Const(bias.data(), {e}, NCHW, halide_type_of<float>());
122 auto weightVar = _Input({l, 50}, NCHW, halide_type_of<float>());
123 res = Variable::create(Expr::create(mat.get(), {y, weightVar, biasVar}));
124 }
125 std::unique_ptr<MNN::NetT> net(new NetT);
126 Variable::save({res}, net.get());
127 flatbuffers::FlatBufferBuilder builderOutput(1024);
128 auto len = MNN::Net::Pack(builderOutput, net.get());
129 builderOutput.Finish(len);
130 int sizeOutput = builderOutput.GetSize();
131 auto bufferOutput = builderOutput.GetBufferPointer();
132 std::shared_ptr<Interpreter> interp(Interpreter::createFromBuffer(bufferOutput, sizeOutput));
133 ScheduleConfig config;
134 config.type = MNN_FORWARD_CPU;
135 auto session = interp->createSession(config);
136 auto input = interp->getSessionInput(session, nullptr);
137
138 {
139 interp->resizeTensor(input, {1, 3, 112, 112});
140 interp->resizeSession(session);
141 interp->resizeTensor(input, {1, 3, 224, 224});
142 interp->resizeSession(session);
143 }
144 float initMemory = 0.0f;
145 interp->getSessionInfo(session, MNN::Interpreter::MEMORY, &initMemory);
146
147 for (int i = 0; i < 100; ++i) {
148 if (i % 2 == 0) {
149 interp->resizeTensor(input, {1, 3, 112, 112});
150 } else {
151 interp->resizeTensor(input, {1, 3, 224, 224});
152 }
153 interp->resizeSession(session);
154 }
155 float lastMemory = 0.0f;
156 interp->getSessionInfo(session, MNN::Interpreter::MEMORY, &lastMemory);
157 MNN_PRINT("From init %f mb to %f mb\n", initMemory, lastMemory);
158 if (lastMemory > initMemory) {
159 return false;
160 }

Callers

nothing calls this directly

Calls 15

_InputFunction · 0.85
_InterpFunction · 0.85
_ConvertFunction · 0.85
_ReshapeFunction · 0.85
_ConstFunction · 0.85
AsMatMulMethod · 0.80
getSessionInputMethod · 0.80
resizeTensorMethod · 0.80
resizeSessionMethod · 0.80
getSessionInfoMethod · 0.80
createFunction · 0.50
saveFunction · 0.50

Tested by

no test coverage detected