| 82 | class ModuleTest : public MNNTestCase { |
| 83 | public: |
| 84 | virtual bool run(int precision) { |
| 85 | auto y = _mobileNetV1Expr(); |
| 86 | std::unique_ptr<MNN::NetT> net(new NetT); |
| 87 | Variable::save({y}, net.get()); |
| 88 | y = nullptr; |
| 89 | flatbuffers::FlatBufferBuilder builderOutput(1024); |
| 90 | auto len = MNN::Net::Pack(builderOutput, net.get()); |
| 91 | builderOutput.Finish(len); |
| 92 | int sizeOutput = builderOutput.GetSize(); |
| 93 | auto bufferOutput = builderOutput.GetBufferPointer(); |
| 94 | // Force use CPU Runtime |
| 95 | BackendConfig bnConfig; |
| 96 | auto exe = Executor::newExecutor(MNN_FORWARD_CPU, bnConfig, 1); |
| 97 | ExecutorScope scope(exe); |
| 98 | auto rtInfo = Express::ExecutorScope::Current()->getRuntime(); |
| 99 | auto rt = rtInfo.first.begin()->second; |
| 100 | auto mem0 = rt->onGetMemoryInMB(); |
| 101 | Module::Config config; |
| 102 | config.shapeMutable = false; |
| 103 | config.rearrange = true; |
| 104 | std::shared_ptr<Module> interp0(Module::load({"Input"}, {"Prob"}, bufferOutput, sizeOutput, &config), Module::destroy); |
| 105 | auto mem1 = rt->onGetMemoryInMB(); |
| 106 | MNN_PRINT("Increase: %f in rt\n", mem1 - mem0); |
| 107 | std::shared_ptr<Module> interp1(Module::clone(interp0.get(), true), Module::destroy); |
| 108 | auto mem2 = rt->onGetMemoryInMB(); |
| 109 | MNN_PRINT("Increase: %f in rt\n", mem2 - mem1); |
| 110 | if (mem2 - mem1 > mem1 - mem0) { |
| 111 | return false; |
| 112 | } |
| 113 | config.rearrange = false; |
| 114 | std::shared_ptr<Module> interp2(Module::load({"Input"}, {"Prob"}, bufferOutput, sizeOutput, &config), Module::destroy); |
| 115 | std::shared_ptr<Module> interp3(Module::clone(interp2.get()), Module::destroy); |
| 116 | auto x = _Input({1, 3, 224, 224}, NC4HW4, halide_type_of<float>()); |
| 117 | auto xPtr = x->writeMap<float>(); |
| 118 | ::memset(xPtr, 0, 1*3*224*224*sizeof(float)); |
| 119 | x->unMap(); |
| 120 | auto y0 = interp0->onForward({x}); |
| 121 | auto y1 = interp1->onForward({x}); |
| 122 | if (y0.size() != 1) { |
| 123 | return false; |
| 124 | } |
| 125 | { |
| 126 | auto info = y0[0]->getInfo(); |
| 127 | if (info->size != 1001) { |
| 128 | return false; |
| 129 | } |
| 130 | if (y0[0]->readMap<float>() == nullptr) { |
| 131 | return false; |
| 132 | } |
| 133 | } |
| 134 | if (y1.size() != 1) { |
| 135 | return false; |
| 136 | } |
| 137 | { |
| 138 | auto info = y1[0]->getInfo(); |
| 139 | if (info->size != 1001) { |
| 140 | return false; |
| 141 | } |
nothing calls this directly
no test coverage detected