| 1616 | class InputModuleTest : public MNNTestCase { |
| 1617 | public: |
| 1618 | virtual bool run(int precision) { |
| 1619 | auto executor = cloneCurrentExecutor(); |
| 1620 | ExecutorScope scope(executor); |
| 1621 | auto y = _mobileNetV1Expr(nullptr, false); |
| 1622 | std::unique_ptr<MNN::NetT> net(new NetT); |
| 1623 | Variable::save({y}, net.get()); |
| 1624 | y = nullptr; |
| 1625 | flatbuffers::FlatBufferBuilder builderOutput(1024); |
| 1626 | auto len = MNN::Net::Pack(builderOutput, net.get()); |
| 1627 | builderOutput.Finish(len); |
| 1628 | int sizeOutput = builderOutput.GetSize(); |
| 1629 | auto bufferOutput = builderOutput.GetBufferPointer(); |
| 1630 | auto test = [&](bool shapeMutable) { |
| 1631 | Module::Config config; |
| 1632 | config.shapeMutable = shapeMutable; |
| 1633 | config.rearrange = true; |
| 1634 | std::shared_ptr<Module> m0; |
| 1635 | std::shared_ptr<Module> m1; |
| 1636 | std::shared_ptr<Module> m2; |
| 1637 | { |
| 1638 | MNN::ScheduleConfig sconfig; |
| 1639 | sconfig.numThread = 1; |
| 1640 | MNN::BackendConfig bnconfig; |
| 1641 | bnconfig.precision = MNN::BackendConfig::Precision_Low; |
| 1642 | sconfig.backendConfig = &bnconfig; |
| 1643 | std::vector<MNN::ScheduleConfig> sconfigs = {sconfig}; |
| 1644 | std::shared_ptr<Executor::RuntimeManager> rtMgr(Executor::RuntimeManager::createRuntimeManager(sconfigs)); |
| 1645 | m0.reset(Module::load({"Input"}, {"Prob"}, bufferOutput, sizeOutput, rtMgr, &config), Module::destroy); |
| 1646 | bnconfig.precision = MNN::BackendConfig::Precision_Normal; |
| 1647 | std::shared_ptr<Executor::RuntimeManager> rtMgr2(Executor::RuntimeManager::createRuntimeManager(sconfigs)); |
| 1648 | m1.reset(Module::load({"Input"}, {"Prob"}, bufferOutput, sizeOutput, rtMgr2, &config), Module::destroy); |
| 1649 | m2.reset(Module::load({"Input"}, {"Prob"}, bufferOutput, sizeOutput), Module::destroy); |
| 1650 | } |
| 1651 | auto x = _Input({1, 3, 32, 32}, NCHW, halide_type_of<float>()); |
| 1652 | auto ptr = x->writeMap<float>(); |
| 1653 | for (int i=0; i<x->getInfo()->size; ++i) { |
| 1654 | ptr[i] = 1.0f * i; |
| 1655 | } |
| 1656 | x = x + x; |
| 1657 | auto prob = m0->onForward({x})[0]; |
| 1658 | auto pptr = prob->readMap<float>(); |
| 1659 | |
| 1660 | float s0 = _ReduceSum(m0->onForward({x})[0])->readMap<float>()[0]; |
| 1661 | float s1 = _ReduceSum(m1->onForward({x})[0])->readMap<float>()[0]; |
| 1662 | float s2 = _ReduceSum(m2->onForward({x})[0])->readMap<float>()[0]; |
| 1663 | // Normally s2 is correct, compare to s2 |
| 1664 | if (fabsf(s0-s2) / s2 > 0.2f) { |
| 1665 | FUNC_PRINT_ALL(s0, f); |
| 1666 | FUNC_PRINT_ALL(s2, f); |
| 1667 | return false; |
| 1668 | } |
| 1669 | if (fabsf(s1-s2) / s2 > 0.2f) { |
| 1670 | FUNC_PRINT_ALL(s1, f); |
| 1671 | FUNC_PRINT_ALL(s2, f); |
| 1672 | return false; |
| 1673 | } |
| 1674 | return true; |
| 1675 | }; |
nothing calls this directly
no test coverage detected