// // MultiThreadLoad.cpp // MNNTests // // Created by MNN on 2019/09/26. // Copyright © 2018, Alibaba Group Holding Limited // #include #include #include #include "MNNTestSuite.h" #include "TestUtils.h" #include "MNN_generated.h" using namespace MNN::Express; using namespace MNN; class MultiThreadLoadTest : public MNNTestCase { public: virtual bool run(int precision) { auto x1 = _Input({4}, NHWC, halide_type_of()); auto x0 = _Input({4}, NCHW, halide_type_of()); auto y = _Add(x1, x0); y = _Abs(y); y = _Sign(y); y = _Square(y); y = _Cos(y); y = _Exp(y); std::unique_ptr net(new NetT); Variable::save({y}, net.get()); flatbuffers::FlatBufferBuilder builderOutput(1024); auto len = MNN::Net::Pack(builderOutput, net.get()); builderOutput.Finish(len); int sizeOutput = builderOutput.GetSize(); auto bufferOutput = builderOutput.GetBufferPointer(); auto forwardType = getCurrentType(); for(int n = 0; n < 100; ++n){ std::vector threads; for (int i = 0; i < 4; ++i) { threads.emplace_back([&]() { std::shared_ptr interp(Interpreter::createFromBuffer(bufferOutput, sizeOutput)); ScheduleConfig config; config.type = forwardType; auto session = interp->createSession(config); interp->runSession(session); }); } for (auto& t : threads) { t.join(); } } return true; } }; MNNTestSuiteRegister(MultiThreadLoadTest, "expr/MultiThreadLoad");