| 1045 | class MutlThreadConstReplaceTest : public MNNTestCase { |
| 1046 | public: |
| 1047 | virtual bool run(int precision) { |
| 1048 | auto executor = cloneCurrentExecutor(); |
| 1049 | ExecutorScope scope(executor); |
| 1050 | auto func = [precision](VARP y, int thread) { |
| 1051 | flatbuffers::FlatBufferBuilder builderOutput(1024); |
| 1052 | { |
| 1053 | std::unique_ptr<MNN::NetT> net(new NetT); |
| 1054 | Variable::save({y}, net.get()); |
| 1055 | auto len = MNN::Net::Pack(builderOutput, net.get()); |
| 1056 | builderOutput.Finish(len); |
| 1057 | } |
| 1058 | int sizeOutput = builderOutput.GetSize(); |
| 1059 | auto bufferOutput = builderOutput.GetBufferPointer(); |
| 1060 | MNN::Express::Module::Config modConfig; |
| 1061 | modConfig.rearrange = true; |
| 1062 | std::shared_ptr<MNN::Express::Module> net(MNN::Express::Module::load(std::vector<std::string>{}, std::vector<std::string>{}, bufferOutput, sizeOutput, &modConfig), MNN::Express::Module::destroy); |
| 1063 | |
| 1064 | ScheduleConfig config; |
| 1065 | BackendConfig bnConfig; |
| 1066 | bnConfig.precision = (MNN::BackendConfig::PrecisionMode)precision; |
| 1067 | config.numThread = 1; |
| 1068 | config.type = ExecutorScope::Current()->getAttr()->firstType; |
| 1069 | config.backendConfig = &bnConfig; |
| 1070 | |
| 1071 | std::vector<std::thread> threads; |
| 1072 | std::vector<float> summer(thread); |
| 1073 | std::mutex moduleMutex; |
| 1074 | |
| 1075 | for (int t = 0; t<thread; ++t) { |
| 1076 | threads.emplace_back([&, t]() { |
| 1077 | auto newExe = Executor::newExecutor(config.type, bnConfig, 1); |
| 1078 | ExecutorScope scope(newExe); |
| 1079 | std::shared_ptr<Module> tempModule; |
| 1080 | { |
| 1081 | std::unique_lock<std::mutex> _l(moduleMutex); |
| 1082 | tempModule.reset(Module::clone(net.get()), Module::destroy); |
| 1083 | } |
| 1084 | // Create Input |
| 1085 | auto x = MNN::Express::_Input({1, 100}, NCHW); |
| 1086 | auto xPtr = x->writeMap<float>(); |
| 1087 | for (int j=0; j<100; ++j) { |
| 1088 | xPtr[j] = j / 100.0f; |
| 1089 | } |
| 1090 | x->unMap(); |
| 1091 | auto y = tempModule->onForward({x}); |
| 1092 | auto yPtr = y[0]->readMap<float>(); |
| 1093 | auto ySize = y[0]->getInfo()->size; |
| 1094 | float sum = 0.0f; |
| 1095 | for (int j=0; j<ySize; ++j) { |
| 1096 | sum += yPtr[j]; |
| 1097 | } |
| 1098 | y[0]->unMap(); |
| 1099 | { |
| 1100 | std::unique_lock<std::mutex> _l(moduleMutex); |
| 1101 | summer[t] = sum; |
| 1102 | } |
| 1103 | }); |
| 1104 | } |
nothing calls this directly
no test coverage detected