MCPcopy Create free account
hub / github.com/alibaba/MNN / _run

Method _run

test/expr/ModuleTest.cpp:782–863  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

780class SessionTest : public MNNTestCase {
781public:
782 bool _run(int precision, bool lazy) {
783 flatbuffers::FlatBufferBuilder builderOutput(1024);
784 {
785 auto y = _mobileNetV1Expr();
786 std::unique_ptr<MNN::NetT> net(new NetT);
787 Variable::save({y}, net.get());
788 y = nullptr;
789 auto len = MNN::Net::Pack(builderOutput, net.get());
790 builderOutput.Finish(len);
791 }
792 int sizeOutput = builderOutput.GetSize();
793 auto bufferOutput = builderOutput.GetBufferPointer();
794 std::shared_ptr<Interpreter> net(Interpreter::createFromBuffer((void*)bufferOutput, sizeOutput), Interpreter::destroy);
795 ScheduleConfig config;
796 config.numThread = 1;
797 int runTime = 5;
798 auto s0 = net->createSession(config);
799 {
800 AUTOTIME;
801 for (int t = 0; t < runTime; ++t) {
802 net->runSession(s0);
803 }
804 }
805 net->releaseSession(s0);
806 config.numThread = 4;
807 auto s1 = net->createSession(config);
808 {
809 AUTOTIME;
810 for (int t = 0; t < runTime; ++t) {
811 net->runSession(s1);
812 }
813 }
814 net->releaseSession(s1);
815 std::vector<std::thread> allThreads;
816 for (int i = 0; i < 4; ++i) {
817 allThreads.emplace_back(std::thread([runTime, i, bufferOutput, sizeOutput] {
818 {
819 std::shared_ptr<Interpreter> net(Interpreter::createFromBuffer((void*)bufferOutput, sizeOutput), Interpreter::destroy);
820 ScheduleConfig config;
821 config.numThread = 4 - i;
822 BackendConfig bnConfig;
823 bnConfig.power = MNN::BackendConfig::Power_Normal;
824 config.backendConfig = &bnConfig;
825 auto s = net->createSession(config);
826 AUTOTIME;
827 for (int t = 0; t < runTime; ++t) {
828 net->runSession(s);
829 }
830 net->releaseSession(s);
831 }
832 }));
833 }
834 for (auto& t : allThreads) {
835 t.join();
836 }
837 for (int i=0; i<3; ++i) {
838 auto rt = Interpreter::createRuntime({config});
839 auto s0 = net->createSession(config, rt);

Callers

nothing calls this directly

Calls 10

runSessionMethod · 0.80
joinMethod · 0.80
getSessionInfoMethod · 0.80
_mobileNetV1ExprFunction · 0.70
saveFunction · 0.50
getMethod · 0.45
FinishMethod · 0.45
GetSizeMethod · 0.45
createSessionMethod · 0.45
releaseSessionMethod · 0.45

Tested by

no test coverage detected