| 64 | class StaticModuleOutputReuseTest : public MNNTestCase { |
| 65 | public: |
| 66 | bool run(int precision) override { |
| 67 | auto executor = cloneCurrentExecutor(); |
| 68 | ExecutorScope scope(executor); |
| 69 | |
| 70 | std::vector<int8_t> buffer; |
| 71 | { |
| 72 | auto x = _Input({1, 4, 32, 32}, NCHW, halide_type_of<float>()); |
| 73 | x->setName("Input"); |
| 74 | auto outputs = makeComplexGraph(x); |
| 75 | buffer = Variable::save(outputs); |
| 76 | } |
| 77 | |
| 78 | Module::Config config; |
| 79 | config.shapeMutable = true; |
| 80 | |
| 81 | std::shared_ptr<Module> module( |
| 82 | Module::load({"Input"}, {"Aux", "Output", "Shape"}, (const uint8_t*)buffer.data(), buffer.size(), &config), |
| 83 | Module::destroy); |
| 84 | if (nullptr == module) { |
| 85 | return false; |
| 86 | } |
| 87 | { |
| 88 | auto x = _Input({1, 4, 320, 320}, NCHW, halide_type_of<float>()); |
| 89 | auto ptr = x->writeMap<float>(); |
| 90 | module->onForward({x}); |
| 91 | } |
| 92 | |
| 93 | auto input0 = makeInput(0.0f); |
| 94 | auto outputs0 = module->onForward({input0}); |
| 95 | if (outputs0.size() != 3) { |
| 96 | return false; |
| 97 | } |
| 98 | |
| 99 | auto aux0Info = outputs0[0]->getInfo(); |
| 100 | auto output0Info = outputs0[1]->getInfo(); |
| 101 | auto shape0Info = outputs0[2]->getInfo(); |
| 102 | if (nullptr == aux0Info || nullptr == output0Info || nullptr == shape0Info) { |
| 103 | return false; |
| 104 | } |
| 105 | if (aux0Info->dim != std::vector<int>({1, 16, 16, 16})) { |
| 106 | return false; |
| 107 | } |
| 108 | if (output0Info->dim != std::vector<int>({1, 4, 1, 16})) { |
| 109 | return false; |
| 110 | } |
| 111 | if (shape0Info->dim != std::vector<int>({4})) { |
| 112 | return false; |
| 113 | } |
| 114 | |
| 115 | int expectedShape[4] = {1, 4, 1, 16}; |
| 116 | auto shapeResult0 = outputs0[2]->readMap<int>(); |
| 117 | if (!checkVector(shapeResult0, expectedShape, 4, 0)) { |
| 118 | return false; |
| 119 | } |
| 120 | |
| 121 | // Snapshot first inference results. We'll verify they remain unchanged after |
| 122 | // the next inference (to catch output buffer reuse issues). |
| 123 | std::vector<float> aux0Snapshot(aux0Info->size); |
nothing calls this directly
no test coverage detected