MNN/test/expr/MultiThreadLoad.cpp

57 lines
1.8 KiB
C++
Raw Normal View History

//
2020-11-05 16:41:56 +08:00
// MultiThreadLoad.cpp
// MNNTests
//
// Created by MNN on 2019/09/26.
// Copyright © 2018, Alibaba Group Holding Limited
//
2020-11-05 16:41:56 +08:00
#include <MNN/Interpreter.hpp>
2019-12-27 22:16:57 +08:00
#include <MNN/expr/ExprCreator.hpp>
2020-11-05 16:41:56 +08:00
#include <thread>
#include "MNNTestSuite.h"
2024-12-31 15:34:08 +08:00
#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<float>());
auto x0 = _Input({4}, NCHW, halide_type_of<float>());
2020-11-05 16:41:56 +08:00
auto y = _Add(x1, x0);
y = _Abs(y);
y = _Sign(y);
y = _Square(y);
y = _Cos(y);
y = _Exp(y);
std::unique_ptr<MNN::NetT> net(new NetT);
- build: - unify schema building in core and converter; - add more build script for android; - add linux build script for python; - ops impl: - add floor mod support in binary; - use eltwise impl in add/max/sub/mul binary for optimization; - remove fake double support in cast; - fix 5d support for concat; - add adjX and adjY support for batch matmul; - optimize conv2d back prop filter; - add pad mode support for conv3d; - fix bug in conv2d & conv depthwise with very small feature map; - optimize binary without broacast; - add data types support for gather; - add gather ND support; - use uint8 data type in gather v2; - add transpose support for matmul; - add matrix band part; - add dim != 4 support for padding, reshape & tensor convert; - add pad type support for pool3d; - make ops based on TensorFlow Lite quantization optional; - add all & any support for reduction; - use type in parameter as output type in reduction; - add int support for unary; - add variable weight support for conv2d; - fix conv2d depthwise weights initialization; - fix type support for transpose; - fix grad outputs count for reduce grad and reshape grad; - fix priorbox & detection output; - fix metal softmax error; - python: - add runSessionWithCallBackInfo interface; - add max nodes limit (1400) for visualization tool; - fix save error in python3; - align default dim; - convert: - add extra design for optimization; - add more post converting optimizers; - add caffe v1 weights blob support; - add cast, unary, conv transpose support for onnx model; - optimize batchnorm, conv with variable weights, prelu, reshape, slice, upsample for onnx model; - add cos/sin/atan/tan support for unary for tensorflow model; - add any/all support for reduction for tensorflow model; - add elu, conv3d, pool3d support for tensorflow model; - optimize argmax, batchnorm, concat, batch to space, conv with variable weights, prelu, slice for tensorflow model; - others: - fix size computer lock; - fix thread pool deadlock; - add express & parameters in express; - rewrite blitter chooser without static map; - add tests for expr;
2019-10-29 13:37:26 +08:00
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();
2019-12-27 22:16:57 +08:00
2024-12-31 15:34:08 +08:00
auto forwardType = getCurrentType();
2025-07-23 14:10:58 +08:00
for(int n = 0; n < 100; ++n){
std::vector<std::thread> threads;
for (int i = 0; i < 4; ++i) {
threads.emplace_back([&]() {
std::shared_ptr<Interpreter> 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");