2019-04-17 10:49:11 +08:00
|
|
|
//
|
|
|
|
// OpenCLRuntime.hpp
|
|
|
|
// MNN
|
|
|
|
//
|
|
|
|
// Created by MNN on 2019/01/31.
|
|
|
|
// Copyright © 2018, Alibaba Group Holding Limited
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef OpenCLRuntime_hpp
|
|
|
|
#define OpenCLRuntime_hpp
|
|
|
|
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
|
|
|
#include <mutex>
|
|
|
|
#include <set>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2019-12-27 22:16:57 +08:00
|
|
|
#include "core/Macro.h"
|
2019-04-17 10:49:11 +08:00
|
|
|
#include "Type_generated.h"
|
2019-12-27 22:16:57 +08:00
|
|
|
#include "backend/opencl/core/runtime/OpenCLWrapper.hpp"
|
2021-03-12 18:41:50 +08:00
|
|
|
#include "MNN/MNNForwardType.h"
|
2019-04-17 10:49:11 +08:00
|
|
|
|
|
|
|
namespace 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
|
|
|
#define CL_CONTEXT_PERF_HINT_QCOM 0x40C2
|
|
|
|
#define CL_PERF_HINT_HIGH_QCOM 0x40C3
|
|
|
|
#define CL_PERF_HINT_NORMAL_QCOM 0x40C4
|
|
|
|
#define CL_PERF_HINT_LOW_QCOM 0x40C5
|
|
|
|
#define CL_CONTEXT_PRIORITY_HINT_QCOM 0x40C9
|
|
|
|
#define CL_PRIORITY_HINT_HIGH_QCOM 0x40CA
|
|
|
|
#define CL_PRIORITY_HINT_NORMAL_QCOM 0x40CB
|
|
|
|
#define CL_PRIORITY_HINT_LOW_QCOM 0x40CC
|
|
|
|
|
|
|
|
#define CL_KERNEL_WAVE_SIZE_QCOM 0xAA02
|
|
|
|
|
2019-09-01 19:25:26 +08:00
|
|
|
enum GpuType { MALI = 0, ADRENO = 1, RADEON = 2, OTHER = 3 };
|
2021-03-12 18:41:50 +08:00
|
|
|
enum GpuMemObject { AUTO = 0, BUFFER = 1, IMAGE = 2};
|
|
|
|
enum CLTuneLevel { None = 0, Heavy = 1, Wide = 2, Normal = 3, Fast = 4};
|
2019-04-17 10:49:11 +08:00
|
|
|
|
|
|
|
class OpenCLRuntime {
|
|
|
|
public:
|
2021-03-12 18:41:50 +08:00
|
|
|
OpenCLRuntime(const BackendConfig::PrecisionMode precision, const int cl_mode);
|
2019-04-17 10:49:11 +08:00
|
|
|
~OpenCLRuntime();
|
|
|
|
OpenCLRuntime(const OpenCLRuntime &) = delete;
|
|
|
|
OpenCLRuntime &operator=(const OpenCLRuntime &) = delete;
|
|
|
|
|
|
|
|
bool isSupportedFP16() const;
|
2020-11-05 16:41:56 +08:00
|
|
|
bool isWeightCpuTransHalf() const;
|
|
|
|
bool isDeviceSupportedFP16() const;
|
2019-11-15 14:22:45 +08:00
|
|
|
bool isSupportedDotInt8() const;
|
|
|
|
bool isSupportedDotAccInt8() const;
|
2019-04-17 10:49:11 +08:00
|
|
|
::cl::Context &context();
|
|
|
|
::cl::CommandQueue &commandQueue();
|
|
|
|
uint64_t deviceGlobalMemeryCacheSize() const;
|
|
|
|
uint32_t deviceComputeUnits() const;
|
|
|
|
uint32_t maxFreq() const;
|
|
|
|
uint64_t getMaxWorkGroupSize(const ::cl::Kernel &kernel);
|
2019-12-27 22:16:57 +08:00
|
|
|
uint64_t GetKernelWaveSize(const cl::Kernel &kernel);
|
2020-11-05 16:41:56 +08:00
|
|
|
std::vector<uint32_t> getMaxWorkItemSizes();
|
- 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
|
|
|
uint64_t getMaxLocalMem() const;
|
2021-03-12 18:41:50 +08:00
|
|
|
GpuType getGpuType() {
|
|
|
|
return mGpuType;
|
|
|
|
}
|
|
|
|
GpuMemObject getGpuMemType() {
|
|
|
|
return mMemType;
|
|
|
|
}
|
|
|
|
CLTuneLevel getCLTuneLevel() {
|
|
|
|
return mTuneLevel;
|
|
|
|
}
|
|
|
|
std::string getDeviceName() {
|
|
|
|
return mDeviceName;
|
|
|
|
}
|
2019-04-17 10:49:11 +08:00
|
|
|
uint64_t maxAllocSize() const;
|
2020-06-22 11:23:12 +08:00
|
|
|
void setCommandQueueProfileEnable();
|
|
|
|
void setCommandQueueProfileDisable();
|
2021-03-12 18:41:50 +08:00
|
|
|
|
2020-06-23 19:00:04 +08:00
|
|
|
unsigned int mQueueCount = 0;
|
2020-06-23 17:50:24 +08:00
|
|
|
unsigned int getQueueNum();
|
2020-07-06 17:48:55 +08:00
|
|
|
|
2020-11-05 16:41:56 +08:00
|
|
|
unsigned int mKernelTime = 0;
|
|
|
|
|
2021-03-12 18:41:50 +08:00
|
|
|
std::map<std::pair<std::string, std::vector<uint32_t>>, std::pair<std::vector<uint32_t>, uint32_t>>& tunedLwsMap();
|
2020-07-06 17:48:55 +08:00
|
|
|
|
2019-04-17 10:49:11 +08:00
|
|
|
::cl::Kernel buildKernel(const std::string &programName, const std::string &kernelName,
|
|
|
|
const std::set<std::string> &buildOptions);
|
|
|
|
|
|
|
|
std::vector<size_t> getMaxImage2DSize();
|
2021-03-12 18:41:50 +08:00
|
|
|
bool isCreateError() const {
|
|
|
|
return mIsCreateError;
|
|
|
|
}
|
2019-04-17 10:49:11 +08:00
|
|
|
|
- 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
|
|
|
float flops() const {
|
|
|
|
return mFlops;
|
|
|
|
}
|
2019-12-27 22:16:57 +08:00
|
|
|
|
|
|
|
double getCostTime(const cl::Event *event);
|
|
|
|
double getQueuedTime(const cl::Event *event);
|
|
|
|
double getSubmitTime(const cl::Event *event);
|
|
|
|
|
2020-11-05 16:41:56 +08:00
|
|
|
std::pair<const void*, size_t> makeCache();
|
2021-06-11 17:17:13 +08:00
|
|
|
bool setCache(std::pair<const void*, size_t> cache);
|
2019-04-17 10:49:11 +08:00
|
|
|
private:
|
|
|
|
bool loadProgram(const std::string &programName, cl::Program *program);
|
|
|
|
bool buildProgram(const std::string &buildOptionsStr, cl::Program *program);
|
|
|
|
bool getDeviceSupportsExtension(const cl::Device &device, const char *extensionName);
|
2021-03-12 18:41:50 +08:00
|
|
|
void setGpuMode(const int cl_mode_num);
|
2019-04-17 10:49:11 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::shared_ptr<::cl::Context> mContext;
|
|
|
|
std::shared_ptr<::cl::Device> mFirstGPUDevicePtr;
|
|
|
|
std::shared_ptr<::cl::CommandQueue> mCommandQueuePtr;
|
2021-06-11 17:17:13 +08:00
|
|
|
std::map<std::tuple<std::string, std::string, std::string>, ::cl::Program> mBuildProgramMap;
|
2019-04-17 10:49:11 +08:00
|
|
|
uint64_t mGPUGlobalMemeryCacheSize;
|
|
|
|
uint32_t mGPUComputeUnits;
|
|
|
|
uint32_t mMaxFreq;
|
|
|
|
uint32_t mMaxMemAllocSize;
|
- 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
|
|
|
uint64_t mMaxLocalMemSize;
|
2019-04-17 10:49:11 +08:00
|
|
|
bool mIsSupportedFP16 = false;
|
2020-11-05 16:41:56 +08:00
|
|
|
bool mIsDeviceSupportedFP16 = false;
|
2019-11-15 14:22:45 +08:00
|
|
|
bool mSupportDotInt8 = false;
|
|
|
|
bool mSupportDotAccInt8 = false;
|
2019-04-17 10:49:11 +08:00
|
|
|
GpuType mGpuType;
|
2021-03-12 18:41:50 +08:00
|
|
|
GpuMemObject mMemType = AUTO;
|
|
|
|
CLTuneLevel mTuneLevel = Wide;
|
|
|
|
std::string mDeviceName;
|
|
|
|
bool isSetWorkGroupAttribute = false;
|
2019-04-17 10:49:11 +08:00
|
|
|
std::string mDefaultBuildParams;
|
- 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
|
|
|
float mFlops = 4.0f;
|
2019-12-27 22:16:57 +08:00
|
|
|
bool mIsCreateError{false};
|
2020-07-04 01:21:30 +08:00
|
|
|
|
2019-12-27 22:16:57 +08:00
|
|
|
double mStartNanos;
|
|
|
|
double mStopNanos;
|
|
|
|
|
2021-03-12 18:41:50 +08:00
|
|
|
std::map<std::pair<std::string, std::vector<uint32_t>>, std::pair<std::vector<uint32_t>, uint32_t>> mTunedLws;
|
2020-11-05 16:41:56 +08:00
|
|
|
std::vector<uint8_t> mBuffer;
|
|
|
|
const void* mCacheOutside = nullptr;
|
|
|
|
size_t mCacheOutsideSize = 0;
|
2019-04-17 10:49:11 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace MNN
|
|
|
|
#endif /* OpenCLRuntime_hpp */
|