2019-09-01 19:25:26 +08:00
|
|
|
//
|
|
|
|
// FunctionDispatcher.cpp
|
|
|
|
// MNN
|
|
|
|
//
|
- dynamic computation graph (beta)
- add supports (/express)
- add tests
- add benchmarks with it (/benchmark/exprModels)
- Python
- MNN engine and tools were submitted to pip
- available on Windows/macOS/Linux
- Engine/Converter
- add supports for each op benchmarking
- refactor optimizer by separating steps
- CPU
- add supports for Conv3D, Pool3D, ELU, ReverseSequence
- fix ArgMax, Permute, Scale, BinaryOp, Slice, SliceTf
- OpenCL
- add half transform in CPU
- add broadcast supports for binary
- optimize Conv2D, Reshape, Eltwise, Gemm, etc.
- OpenGL
- add sub, real div supports for binary
- add supports for unary
- optimize Conv2D, Reshape
- Vulkan
- add max supports for eltwise
- Metal
- fix metallib missing problem
- Train/Quantization
- use express to refactor training codes
2019-09-26 21:02:07 +08:00
|
|
|
// Created by MNN on 2019/08/25.
|
2019-09-01 19:25:26 +08:00
|
|
|
// Copyright © 2018, Alibaba Group Holding Limited
|
|
|
|
//
|
2020-11-05 16:41:56 +08:00
|
|
|
|
|
|
|
#include <limits>
|
2021-01-05 15:30:28 +08:00
|
|
|
#include "avx512/FunctionSummary.hpp"
|
2020-11-05 16:41:56 +08:00
|
|
|
#include "avx/FunctionSummary.hpp"
|
2021-06-11 17:17:13 +08:00
|
|
|
#include "AVX2Functions.hpp"
|
2021-04-08 15:34:23 +08:00
|
|
|
#include "avxfma/FunctionSummary.hpp"
|
2019-12-27 22:16:57 +08:00
|
|
|
#include "backend/cpu/compute/CommonOptFunction.h"
|
|
|
|
#include "backend/cpu/compute/ConvOpt.h"
|
2020-02-26 09:57:17 +08:00
|
|
|
#include "backend/cpu/compute/Int8FunctionsOpt.h"
|
2020-07-04 01:21:30 +08:00
|
|
|
#include "cpu_id.h"
|
2020-11-05 16:41:56 +08:00
|
|
|
#include "sse/FunctionSummary.hpp"
|
2020-04-14 22:52:24 +08:00
|
|
|
// https://stackoverflow.com/a/11230437
|
|
|
|
#if defined(_MSC_VER)
|
|
|
|
#include <intrin.h>
|
|
|
|
#else
|
2020-04-10 14:44:01 +08:00
|
|
|
#include <x86intrin.h>
|
2020-04-14 22:52:24 +08:00
|
|
|
#endif
|
2020-07-04 01:21:30 +08:00
|
|
|
|
2020-04-10 14:44:01 +08:00
|
|
|
bool MNNReorder4x4ByPlatform(float* dst, size_t number) {
|
2020-12-15 14:12:35 +08:00
|
|
|
return _SSE_MNNReorder4x4ByPlatform(dst, number);
|
2020-04-10 14:44:01 +08:00
|
|
|
}
|
|
|
|
|
2020-07-04 01:21:30 +08:00
|
|
|
struct FunctionGroup {
|
2020-11-05 16:41:56 +08:00
|
|
|
int tileNumber = 8;
|
|
|
|
int eP = 12;
|
|
|
|
int lP = 1;
|
|
|
|
int hP = 4;
|
|
|
|
void (*MNNExpC8)(float* dest, const float* source, const float* parameters, size_t countC8) = _SSE_MNNExpC8;
|
2020-12-10 11:28:55 +08:00
|
|
|
void (*MNNFloat2Int8)(const float* src, int8_t* dst, size_t sizeQuad, const float* scalep, ssize_t minValue,
|
2021-01-06 16:29:37 +08:00
|
|
|
ssize_t maxValue, ssize_t zeroPoint) = _SSE_MNNFloat2Int8;
|
|
|
|
void (*MNNInt8ScaleToFloat)(float* dst, const int8_t* src, const float* scale, size_t size, ssize_t zeroPoint) = _SSE_MNNInt8ScaleToFloat;
|
|
|
|
void (*MNNComputeMatMulForE_1)(const float* A, const float* B, float* C, const float* biasPtr, const MatMulParam* param, size_t tId) = _SSE_MNNComputeMatMulForE_1;
|
2021-04-08 15:34:23 +08:00
|
|
|
void (*MNNReluWithSlopeChannel)(float* dst, const float* src, const float* slope, size_t sizeQuad, size_t depthQuad) = _SSE_MNNReluWithSlopeChannel;
|
|
|
|
void (*MNNReluInt8)(int8_t* dst, const int8_t* src, size_t size) = _SSE_MNNReluInt8;
|
|
|
|
void (*MNNHardSwish)(float* dst, const float* src, size_t size) = _SSE_MNNHardSwish;
|
2021-06-11 17:17:13 +08:00
|
|
|
void (*MNNGelu)(float* dst, const float* src, size_t size) = _SSE_MNNGelu;
|
2020-07-04 01:21:30 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static FunctionGroup gFunc;
|
2021-04-08 15:34:23 +08:00
|
|
|
|
|
|
|
void _SSEMNNGetMatMulPackMode(int* eP, int *lP, int* hP) {
|
|
|
|
*eP = gFunc.eP;
|
|
|
|
*lP = gFunc.lP;
|
|
|
|
*hP = gFunc.hP;
|
|
|
|
}
|
2020-07-04 01:21:30 +08:00
|
|
|
void MNNFunctionInit() {
|
|
|
|
auto cpuFlags = libyuv::InitCpuFlags();
|
2021-04-08 15:34:23 +08:00
|
|
|
auto coreFunction = MNN::MNNGetCoreFunctions();
|
|
|
|
if (cpuFlags & libyuv::kCpuHasSSSE3) {
|
|
|
|
coreFunction->MNNGetMatMulPackMode = _SSEMNNGetMatMulPackMode;
|
|
|
|
coreFunction->MNNMatrixAdd = _SSE_MNNMatrixAdd;
|
|
|
|
coreFunction->MNNMatrixSub = _SSE_MNNMatrixSub;
|
|
|
|
coreFunction->MNNPackedMatMul = _SSE_MNNPackedMatMul;
|
|
|
|
coreFunction->MNNPackedMatMulRemain = _SSE_MNNPackedMatMulRemain;
|
|
|
|
coreFunction->MNNPackC4ForMatMul_A = _SSE_MNNPackC4ForMatMul_A;
|
|
|
|
coreFunction->MNNPackForMatMul_B = _SSE_MNNPackForMatMul_B;
|
|
|
|
coreFunction->MNNConvRunForLineDepthwise = _SSE_MNNConvRunForLineDepthwise;
|
|
|
|
coreFunction->MNNAxByClampBroadcastUnit = _SSE_MNNAxByClampBroadcastUnit;
|
2021-06-11 17:17:13 +08:00
|
|
|
coreFunction->MNNComputeMatMulForE_1 = _SSE_MNNComputeMatMulForE_1;
|
2021-04-08 15:34:23 +08:00
|
|
|
}
|
2021-01-06 16:29:37 +08:00
|
|
|
if (cpuFlags & libyuv::kCpuHasAVX2) {
|
2021-06-11 17:17:13 +08:00
|
|
|
MNN::AVX2Functions::init(cpuFlags);
|
2020-11-10 16:53:52 +08:00
|
|
|
gFunc.MNNExpC8 = _AVX_MNNExpC8;
|
2021-06-11 17:17:13 +08:00
|
|
|
gFunc.MNNGelu = _AVX_MNNGelu;
|
2020-07-04 01:21:30 +08:00
|
|
|
}
|
2021-06-11 17:17:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MNNInt8FunctionInit() {
|
|
|
|
auto cpuFlags = libyuv::InitCpuFlags();
|
|
|
|
auto core = MNN::MNNGetInt8CoreFunctions();
|
|
|
|
if (cpuFlags & libyuv::kCpuHasSSSE3) {
|
|
|
|
core->Int8GemmKernel = _SSE_MNNGemmInt8AddBiasScale_16x4_Unit;
|
|
|
|
core->Int8GemmKernelFast = _SSE_MNNGemmInt8AddBiasScale_16x4_Unit;
|
|
|
|
core->ConvDepthwiseLineInt8 = _SSE_MNNLineDepthWiseInt8AddBiasScaleUnit;
|
|
|
|
}
|
|
|
|
if (cpuFlags & libyuv::kCpuHasAVX2) {
|
|
|
|
core->Int8GemmKernel = _AVX_MNNGemmInt8AddBiasScale_16x4_Unit;
|
|
|
|
core->Int8GemmKernelFast = _AVX_MNNGemmInt8AddBiasScale_16x4_Unit_Fast;
|
|
|
|
core->ConvDepthwiseLineInt8 = _AVX_MNNLineDepthWiseInt8AddBiasScaleUnit;
|
|
|
|
}
|
|
|
|
#ifdef MNN_AVX512_VNNI
|
2021-02-07 10:45:07 +08:00
|
|
|
if (cpuFlags & libyuv::kCpuHasAVX512VNNI) {
|
2021-06-11 17:17:13 +08:00
|
|
|
core->Int8GemmKernel = _AVX512_MNNGemmInt8AddBiasScale_16x4_Unit;
|
|
|
|
core->Int8GemmKernelFast = _AVX512_MNNGemmInt8AddBiasScale_16x4_Unit;
|
2021-01-06 16:29:37 +08:00
|
|
|
}
|
|
|
|
#endif
|
2020-07-04 01:21:30 +08:00
|
|
|
}
|
|
|
|
|
2019-09-01 19:25:26 +08:00
|
|
|
// ========= CommonOptFunction.cpp ===========
|
|
|
|
|
|
|
|
void MNNCopyC4WithStride(const float* source, float* dest, size_t srcStride, size_t dstStride, size_t count) {
|
|
|
|
_SSE_MNNCopyC4WithStride(source, dest, srcStride, dstStride, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MNNAddC4WithStride(const float* source, float* dest, size_t srcStride, size_t dstStride, size_t count) {
|
|
|
|
_SSE_MNNAddC4WithStride(source, dest, srcStride, dstStride, count);
|
|
|
|
}
|
|
|
|
|
2020-11-05 16:41:56 +08:00
|
|
|
void MNNReluWithSlopeChannel(float* dst, const float* src, const float* slope, size_t sizeQuad, size_t depthQuad) {
|
2021-04-08 15:34:23 +08:00
|
|
|
return gFunc.MNNReluWithSlopeChannel(dst, src, slope, sizeQuad, depthQuad);
|
2020-02-26 09:57:17 +08:00
|
|
|
}
|
|
|
|
|
2021-04-08 15:34:23 +08:00
|
|
|
void MNNReluInt8(int8_t* dst, const int8_t* src, size_t size) {
|
|
|
|
return gFunc.MNNReluInt8(dst, src, size);
|
2020-11-05 16:41:56 +08:00
|
|
|
}
|
|
|
|
|
2021-04-08 15:34:23 +08:00
|
|
|
void MNNHardSwish(float* dst, const float* src, size_t size) {
|
|
|
|
return gFunc.MNNHardSwish(dst, src, size);
|
2020-05-15 19:08:36 +08:00
|
|
|
}
|
|
|
|
|
2021-06-11 17:17:13 +08:00
|
|
|
void MNNGelu(float* dst, const float* src, size_t size) {
|
|
|
|
return gFunc.MNNGelu(dst, src, size);
|
|
|
|
}
|
|
|
|
|
2020-12-10 11:28:55 +08:00
|
|
|
void MNNFloat2Int8(const float* src, int8_t* dst, size_t sizeQuad, const float* scalep, ssize_t minValue,
|
2021-01-06 16:29:37 +08:00
|
|
|
ssize_t maxValue, ssize_t zeroPoint) {
|
|
|
|
return gFunc.MNNFloat2Int8(src, dst, sizeQuad, scalep, minValue, maxValue, zeroPoint);
|
2020-12-10 17:53:24 +08:00
|
|
|
}
|
2021-01-06 16:29:37 +08:00
|
|
|
void MNNInt8ScaleToFloat(float* dst, const int8_t* src, const float* scale, size_t size, ssize_t zeroPoint) {
|
|
|
|
return gFunc.MNNInt8ScaleToFloat(dst, src, scale, size, zeroPoint);
|
2020-12-10 11:28:55 +08:00
|
|
|
}
|
|
|
|
|
2020-11-05 16:41:56 +08:00
|
|
|
void MNNExpC8(float* dest, const float* source, const float* parameters, size_t countC8) {
|
|
|
|
gFunc.MNNExpC8(dest, source, parameters, countC8);
|
|
|
|
}
|
2021-01-06 16:29:37 +08:00
|
|
|
|
|
|
|
void MNNInt8ToInt16(int16_t* dest, const int8_t* source, size_t count) {
|
|
|
|
_SSE_MNNInt8ToInt16(dest, source, count);
|
|
|
|
}
|