| 915 | class MemeoryUsageTest : public MNNTestCase { |
| 916 | public: |
| 917 | bool _run(int precision, bool lazy) { |
| 918 | auto func = [precision](VARP y, float limit) { |
| 919 | flatbuffers::FlatBufferBuilder builderOutput(1024); |
| 920 | { |
| 921 | std::unique_ptr<MNN::NetT> net(new NetT); |
| 922 | Variable::save({y}, net.get()); |
| 923 | auto len = MNN::Net::Pack(builderOutput, net.get()); |
| 924 | builderOutput.Finish(len); |
| 925 | } |
| 926 | int sizeOutput = builderOutput.GetSize(); |
| 927 | auto bufferOutput = builderOutput.GetBufferPointer(); |
| 928 | std::shared_ptr<Interpreter> net(Interpreter::createFromBuffer((void*)bufferOutput, sizeOutput), Interpreter::destroy); |
| 929 | ScheduleConfig config; |
| 930 | BackendConfig bnConfig; |
| 931 | bnConfig.precision = (MNN::BackendConfig::PrecisionMode)precision; |
| 932 | config.numThread = 1; |
| 933 | config.type = ExecutorScope::Current()->getAttr()->firstType; |
| 934 | config.backendConfig = &bnConfig; |
| 935 | auto s1 = net->createSession(config); |
| 936 | float memory = 0.0f; |
| 937 | net->getSessionInfo(s1, MNN::Interpreter::MEMORY, &memory); |
| 938 | if (memory < 0.01f) { |
| 939 | FUNC_PRINT(precision); |
| 940 | return false; |
| 941 | } |
| 942 | if (memory > limit) { |
| 943 | MNN_ERROR("memory %f larger than limit: %f, precision=%d\n", memory, limit, precision); |
| 944 | return false; |
| 945 | } |
| 946 | FUNC_PRINT_ALL(memory, f); |
| 947 | return true; |
| 948 | }; |
| 949 | auto y = _mobileNetV1Expr(); |
| 950 | bool res = func(y, 62.0f); |
| 951 | if (!res) { |
| 952 | return false; |
| 953 | } |
| 954 | auto x = _Input({1, 3, 1024, 1024}, NCHW); |
| 955 | y = _Sigmoid(x); |
| 956 | res = func(y, 35.0f); |
| 957 | if (!res) { |
| 958 | return false; |
| 959 | } |
| 960 | auto weightVar = MNN::Express::_Const(0.0f, {100, 10000}, NCHW); |
| 961 | x = MNN::Express::_Input({1, 100}, NCHW); |
| 962 | auto x2 = MNN::Express::_Input({1, 10000}, NCHW); |
| 963 | y = MNN::Express::_MatMul(x, weightVar); |
| 964 | auto weightVar2 = MNN::Express::_Const(0.0f, {10000, 100}, NCHW); |
| 965 | y = MNN::Express::_MatMul(y, weightVar2); |
| 966 | res = func(y, 8.0f); |
| 967 | if (!res) { |
| 968 | return false; |
| 969 | } |
| 970 | weightVar = MNN::Express::_Const(0.0f, {100, 10000, 1, 1}, NC4HW4); |
| 971 | x = MNN::Express::_Input({100, 10000, 1, 1}, NC4HW4); |
| 972 | y = MNN::Express::_Add(x, weightVar); |
| 973 | res = func(y, 12.0f); |
| 974 | if (!res) { |
nothing calls this directly
no test coverage detected