2019-04-17 10:49:11 +08:00
|
|
|
//
|
|
|
|
// CPUBackend.hpp
|
|
|
|
// MNN
|
|
|
|
//
|
|
|
|
// Created by MNN on 2018/07/06.
|
|
|
|
// Copyright © 2018, Alibaba Group Holding Limited
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef CPUBackend_hpp
|
|
|
|
#define CPUBackend_hpp
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
2019-12-27 22:16:57 +08:00
|
|
|
#include "core/Backend.hpp"
|
|
|
|
#include "core/Execution.hpp"
|
2019-04-17 10:49:11 +08:00
|
|
|
#include "MNN_generated.h"
|
|
|
|
|
|
|
|
namespace MNN {
|
|
|
|
class BufferAllocator;
|
|
|
|
|
|
|
|
class CPUBackend final : public Backend {
|
|
|
|
public:
|
|
|
|
CPUBackend(int numberThread = 4, BackendConfig::MemoryMode memory = BackendConfig::Memory_Normal,
|
2019-08-22 20:13:46 +08:00
|
|
|
BackendConfig::PowerMode = BackendConfig::Power_Normal, size_t flags = 0);
|
2019-04-17 10:49:11 +08:00
|
|
|
virtual ~CPUBackend();
|
|
|
|
|
2020-02-26 09:57:17 +08:00
|
|
|
// Return sizeDivide, scheduleNumber aligned memory
|
|
|
|
std::pair<int, int> multiThreadDivide(int size) const;
|
2019-04-17 10:49:11 +08:00
|
|
|
public:
|
|
|
|
virtual bool onAcquireBuffer(const Tensor* nativeTensor, StorageType storageType) override;
|
|
|
|
virtual bool onReleaseBuffer(const Tensor* nativeTensor, StorageType storageType) override;
|
|
|
|
virtual bool onAllocateBuffer() override;
|
|
|
|
virtual bool onClearBuffer() override;
|
|
|
|
virtual void onCopyBuffer(const Tensor* srcTensor, const Tensor* dstTensor) const override;
|
- 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
|
|
|
virtual std::pair<float, bool> onMeasure(const std::vector<Tensor*>& inputs, const std::vector<Tensor*>& outputs,
|
|
|
|
const MNN::Op* op) override;
|
2019-04-17 10:49:11 +08:00
|
|
|
|
|
|
|
virtual Execution* onCreate(const std::vector<Tensor*>& inputs, const std::vector<Tensor*>& outputs,
|
|
|
|
const MNN::Op* op) override;
|
|
|
|
virtual void onExecuteBegin() const override;
|
2019-07-19 17:09:09 +08:00
|
|
|
virtual void onExecuteEnd() const override;
|
2020-03-22 20:16:29 +08:00
|
|
|
|
|
|
|
virtual void* getAllocator(StorageType type = DYNAMIC) const override{
|
|
|
|
if(type == STATIC){
|
|
|
|
return (void*)mStaticAllocator.get();
|
|
|
|
}
|
|
|
|
return (void*)mDynamicAllocator.get();
|
|
|
|
}
|
2019-04-17 10:49:11 +08:00
|
|
|
public:
|
|
|
|
class Creator {
|
|
|
|
public:
|
|
|
|
virtual Execution* onCreate(const std::vector<Tensor*>& inputs, const std::vector<Tensor*>& outputs,
|
|
|
|
const MNN::Op* op, Backend* backend) const = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool addCreator(OpType t, Creator* c);
|
|
|
|
|
|
|
|
int threadNumber() const {
|
|
|
|
return mThreadNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
BufferAllocator* getBufferAllocator() const {
|
2020-03-22 20:16:29 +08:00
|
|
|
return static_cast<BufferAllocator*>(this->getAllocator());
|
2019-04-17 10:49:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
BackendConfig::MemoryMode memoryMode() const {
|
|
|
|
return mMemory;
|
|
|
|
}
|
|
|
|
BackendConfig::PowerMode powerMode() const {
|
|
|
|
return mPower;
|
|
|
|
}
|
2019-07-19 17:09:09 +08:00
|
|
|
#ifdef MNN_USE_THREAD_POOL
|
|
|
|
inline int taskIndex() const {return mTaskIndex;}
|
|
|
|
#endif
|
2019-04-17 10:49:11 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::unique_ptr<BufferAllocator> mStaticAllocator;
|
|
|
|
std::unique_ptr<BufferAllocator> mDynamicAllocator;
|
|
|
|
int mThreadNumber;
|
2019-07-19 17:09:09 +08:00
|
|
|
#ifdef MNN_USE_THREAD_POOL
|
|
|
|
int mTaskIndex;
|
|
|
|
#endif
|
2019-04-17 10:49:11 +08:00
|
|
|
const BackendConfig::MemoryMode mMemory;
|
|
|
|
const BackendConfig::PowerMode mPower;
|
2019-08-22 20:13:46 +08:00
|
|
|
bool mCheckNAN = false;
|
- 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 = 0.0f;
|
2019-04-17 10:49:11 +08:00
|
|
|
};
|
2019-05-09 19:39:33 +08:00
|
|
|
|
|
|
|
#ifdef MNN_CODEGEN_REGISTER
|
|
|
|
#define REGISTER_CPU_OP_CREATOR(name, opType) \
|
|
|
|
void ___##name##__##opType##__() { \
|
|
|
|
CPUBackend::addCreator(opType, new name); \
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
class CPUCreatorRegister {
|
|
|
|
public:
|
|
|
|
CPUCreatorRegister(OpType type) {
|
|
|
|
CPUBackend::addCreator(type, new T);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#define REGISTER_CPU_OP_CREATOR(name, opType) static CPUCreatorRegister<name> _Create##opType(opType)
|
|
|
|
#endif
|
|
|
|
|
2019-04-17 10:49:11 +08:00
|
|
|
} // namespace MNN
|
|
|
|
|
|
|
|
#endif /* CPUBackend_hpp */
|