【新增】MNN依赖库
This commit is contained in:
72
3rd/win/mnn/include/MNN/expr/Executor.hpp
Normal file
72
3rd/win/mnn/include/MNN/expr/Executor.hpp
Normal file
@@ -0,0 +1,72 @@
|
||||
//
|
||||
// Executor.hpp
|
||||
// MNN
|
||||
//
|
||||
// Created by MNN on 2019/07/25.
|
||||
// Copyright © 2018, Alibaba Group Holding Limited
|
||||
//
|
||||
#ifndef Executor_hpp
|
||||
#define Executor_hpp
|
||||
#include <MNN/ErrorCode.hpp>
|
||||
#include <MNN/expr/Expr.hpp>
|
||||
#include <MNN/Tensor.hpp>
|
||||
#include <MNN/Interpreter.hpp>
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
#include <set>
|
||||
#include <MNN/MNNForwardType.h>
|
||||
namespace MNN {
|
||||
class Backend;
|
||||
class Execution;
|
||||
class Runtime;
|
||||
struct Op;
|
||||
namespace Express {
|
||||
class MNN_PUBLIC Executor {
|
||||
public:
|
||||
class ComputeCache;
|
||||
struct Unit;
|
||||
static void setShapeDirty(ComputeCache* cache);
|
||||
static void setContentDirty(ComputeCache* cache);
|
||||
static void* mapOutput(ComputeCache* cache, int offset, Tensor* dest);
|
||||
struct Requirement {
|
||||
std::vector<bool> contentNeedContent;
|
||||
std::vector<bool> shapeNeedContent;
|
||||
};
|
||||
~Executor();
|
||||
Requirement getRequirement(Expr* expr) const;
|
||||
ErrorCode computeInfo(Expr* expr);
|
||||
void makeCache(const std::vector<EXPRP>& expr, bool forceCPU = false);
|
||||
ErrorCode runCache(std::shared_ptr<ComputeCache> cache);
|
||||
void setGlobalExecutorConfig(MNNForwardType type, const BackendConfig& config, int numberThread);
|
||||
enum GCFlag {
|
||||
FULL,
|
||||
PART
|
||||
};
|
||||
void gc(GCFlag flag = FULL);
|
||||
static std::shared_ptr<Executor> getGlobalExecutor();
|
||||
|
||||
static std::shared_ptr<Executor> newExecutor(MNNForwardType type,
|
||||
const BackendConfig& config,
|
||||
int numberThread);
|
||||
void resetProfile();
|
||||
void dumpProfile();
|
||||
void addOpCostTime(int op, float costTime);
|
||||
void addOpCostTime(const std::string& type, float costTime);
|
||||
void addOpFlops(const std::string& type, float flops);
|
||||
class Profiler;
|
||||
static RuntimeInfo getRuntime();
|
||||
private:
|
||||
void _makeCache(const std::vector<EXPRP>& outputs, bool forceCPU);
|
||||
void _create(const std::vector<EXPRP>& outputs, std::set<std::shared_ptr<Executor::ComputeCache>>&& inputCaches, std::set<std::shared_ptr<Expr::Inside>>&& inputNode, bool forceCPU);
|
||||
|
||||
void _visit(EXPRP expr, std::set<std::shared_ptr<Executor::ComputeCache>>& inputCaches, std::set<std::shared_ptr<Expr::Inside>>& inputNode);
|
||||
|
||||
Executor(std::shared_ptr<Runtime> backend, MNNForwardType type);
|
||||
std::pair<std::shared_ptr<Runtime>, MNNForwardType> mRuntime;
|
||||
std::pair<std::shared_ptr<Runtime>, MNNForwardType> mBackupRuntime;
|
||||
std::mutex mMutex;
|
||||
std::shared_ptr<Profiler> mProfiler;
|
||||
};
|
||||
} // namespace Express
|
||||
} // namespace MNN
|
||||
#endif
|
||||
264
3rd/win/mnn/include/MNN/expr/Expr.hpp
Normal file
264
3rd/win/mnn/include/MNN/expr/Expr.hpp
Normal file
@@ -0,0 +1,264 @@
|
||||
//
|
||||
// Expr.hpp
|
||||
// MNN
|
||||
//
|
||||
// Created by MNN on 2019/06/10.
|
||||
// Copyright © 2018, Alibaba Group Holding Limited
|
||||
//
|
||||
|
||||
#ifndef Expr_hpp
|
||||
#define Expr_hpp
|
||||
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <MNN/HalideRuntime.h>
|
||||
#include <MNN/MNNDefine.h>
|
||||
|
||||
namespace MNN {
|
||||
struct OpT;
|
||||
struct Op;
|
||||
struct NetT;
|
||||
namespace Express {
|
||||
class Variable;
|
||||
class Expr;
|
||||
class Executor;
|
||||
typedef std::shared_ptr<Expr> EXPRP;
|
||||
typedef std::weak_ptr<Expr> WeakEXPRP;
|
||||
typedef std::vector<int> INTS;
|
||||
enum Dimensionformat { NHWC, NC4HW4, NCHW };
|
||||
class MNN_PUBLIC VARP {
|
||||
public:
|
||||
VARP() {
|
||||
// Do nothing
|
||||
}
|
||||
VARP(std::shared_ptr<Variable> c) {
|
||||
mContent = std::move(c);
|
||||
}
|
||||
VARP(Variable* c) {
|
||||
mContent.reset(c);
|
||||
}
|
||||
Variable* get() const {
|
||||
return mContent.get();
|
||||
}
|
||||
~ VARP() {
|
||||
// Do nothing
|
||||
}
|
||||
VARP(const VARP& var) {
|
||||
mContent = var.mContent;
|
||||
}
|
||||
VARP(VARP&& var) {
|
||||
mContent = std::move(var.mContent);
|
||||
}
|
||||
VARP operator+(VARP var) const;
|
||||
VARP operator-(VARP var) const;
|
||||
VARP operator*(VARP var) const;
|
||||
VARP operator/(VARP var) const;
|
||||
VARP mean(INTS dims) const;
|
||||
VARP sum(INTS dims) const;
|
||||
|
||||
bool operator==(const VARP& var) const {
|
||||
return var.mContent == mContent;
|
||||
}
|
||||
bool operator<(const VARP& var) const {
|
||||
return mContent < var.mContent;
|
||||
}
|
||||
bool operator<=(const VARP& var) const {
|
||||
return mContent <= var.mContent;
|
||||
}
|
||||
VARP& operator=(const VARP& var) {
|
||||
mContent = var.mContent;
|
||||
return *this;
|
||||
}
|
||||
VARP& operator=(Variable* var) {
|
||||
mContent.reset(var);
|
||||
return *this;
|
||||
}
|
||||
Variable* operator->() const {
|
||||
return mContent.get();
|
||||
}
|
||||
enum InputType {
|
||||
INPUT = 0,
|
||||
CONSTANT = 1,
|
||||
TRAINABLE = 2,
|
||||
};
|
||||
bool fix(InputType type) const;
|
||||
private:
|
||||
friend class Variable;
|
||||
std::shared_ptr<Variable> mContent;
|
||||
};
|
||||
inline bool operator==(Variable* src, VARP dst) {
|
||||
return src == dst.get();
|
||||
}
|
||||
inline bool operator!=(Variable* src, VARP dst) {
|
||||
return src != dst.get();
|
||||
}
|
||||
// inline bool operator<(VARP src, VARP dst) {
|
||||
// return src.get() < dst.get();
|
||||
// }
|
||||
typedef std::vector<VARP> VARPS;
|
||||
|
||||
class MNN_PUBLIC Variable {
|
||||
public:
|
||||
struct Info {
|
||||
Dimensionformat order = NHWC;
|
||||
INTS dim;
|
||||
halide_type_t type;
|
||||
int size;
|
||||
void syncSize();
|
||||
};
|
||||
const std::string& name() const;
|
||||
void setName(const std::string& name);
|
||||
std::pair<EXPRP, int> expr() const {
|
||||
return std::make_pair(mFrom, mFromIndex);
|
||||
}
|
||||
// If compute info error, return nullptr
|
||||
const Info* getInfo();
|
||||
bool resize(INTS dims);
|
||||
template <typename T>
|
||||
const T* readMap() {
|
||||
return (const T*)readInternal();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T* writeMap() {
|
||||
return (T*)writeInternal();
|
||||
}
|
||||
|
||||
//Depecerate
|
||||
void unMap();
|
||||
|
||||
bool input(VARP src);
|
||||
static void replace(VARP dst, VARP src);
|
||||
|
||||
static VARP create(EXPRP expr, int index = 0);
|
||||
|
||||
static std::vector<VARP> load(const char* fileName);
|
||||
static std::map<std::string, VARP> loadMap(const char* fileName);
|
||||
static std::vector<VARP> load(const uint8_t* buffer, size_t length);
|
||||
static std::map<std::string, VARP> loadMap(const uint8_t* buffer, size_t length);
|
||||
static std::pair<std::map<std::string, VARP>, std::map<std::string, VARP>> getInputAndOutput(const std::map<std::string, VARP>& allVariable);
|
||||
static std::vector<VARP> mapToSequence(const std::map<std::string, VARP>& source);
|
||||
static std::vector<EXPRP> getExecuteOrder(const std::vector<VARP>& output);
|
||||
static void save(const std::vector<VARP>& vars, const char* fileName);
|
||||
static void save(const std::vector<VARP>& vars, NetT* dest);
|
||||
|
||||
// Pack a few Variable to compute in one pipeline
|
||||
static void prepareCompute(const std::vector<VARP>& vars, bool forceCPU = false);
|
||||
|
||||
size_t linkNumber() const;
|
||||
const std::vector<WeakEXPRP>& toExprs() const;
|
||||
void setExpr(EXPRP expr, int index) {
|
||||
mFrom = expr;
|
||||
mFromIndex = index;
|
||||
}
|
||||
private:
|
||||
Variable(EXPRP expr, int index) {
|
||||
mFrom = expr;
|
||||
mFromIndex = index;
|
||||
}
|
||||
|
||||
void* readInternal(bool forShape = false);
|
||||
void* writeInternal(bool inform=true);
|
||||
void informDirty();
|
||||
|
||||
friend class Expr;
|
||||
EXPRP mFrom;
|
||||
int mFromIndex;
|
||||
};
|
||||
|
||||
class MNN_PUBLIC Expr {
|
||||
public:
|
||||
struct Inside;
|
||||
static EXPRP create(Variable::Info&& info, const void* ptr, VARP::InputType type, bool copy = true);
|
||||
static EXPRP create(const OpT* op, std::vector<VARP> inputs, int outputSize = 1);
|
||||
static EXPRP create(std::pair<std::shared_ptr<char>, int> extra, std::vector<VARP>&& inputs, int outputSize = 1);
|
||||
static EXPRP create(std::unique_ptr<OpT>&& op, std::vector<VARP> inputs, int outputSize = 1) {
|
||||
return create(op.get(), inputs, outputSize);
|
||||
}
|
||||
void setName(const std::string& name);
|
||||
|
||||
const Op* get() const {
|
||||
return mOp;
|
||||
}
|
||||
const std::vector<VARP>& inputs() const {
|
||||
return mInputs;
|
||||
}
|
||||
int outputSize() const {
|
||||
return (int)mOutputNames.size();
|
||||
}
|
||||
static void replace(EXPRP oldExpr, EXPRP newExpr);
|
||||
bool requireInfo();
|
||||
void visitOutputs(const std::function<bool(EXPRP, int)>& visit);
|
||||
static void visit(EXPRP expr, const std::function<bool(EXPRP)>& before, const std::function<bool(EXPRP)>& after);
|
||||
|
||||
const std::vector<WeakEXPRP>& outputs() const {
|
||||
return mTo;
|
||||
}
|
||||
~Expr();
|
||||
|
||||
bool visited() const {
|
||||
return mVisited;
|
||||
}
|
||||
void setVisited(bool visited) {
|
||||
mVisited = visited;
|
||||
}
|
||||
const std::string& name() const {
|
||||
return mName;
|
||||
}
|
||||
const std::string& outputName(int index) {
|
||||
return mOutputNames[index];
|
||||
}
|
||||
|
||||
VARP::InputType inputType() const {return mType;}
|
||||
Variable::Info* outputInfo(int index) const;
|
||||
std::pair<std::shared_ptr<char>, int> extra() const {
|
||||
return std::make_pair(mExtraBuffer, mOpBufferSize);
|
||||
}
|
||||
bool setInfoDirty();
|
||||
std::shared_ptr<Inside> inside() const {
|
||||
return mInside;
|
||||
}
|
||||
bool valid() const {
|
||||
return mValid;
|
||||
}
|
||||
|
||||
void setEntry(const std::vector<VARP>& entries) {
|
||||
mEntries = entries;
|
||||
}
|
||||
|
||||
const std::vector<VARP>& getEntry() const {
|
||||
return mEntries;
|
||||
}
|
||||
|
||||
private:
|
||||
static void _addLinkForInputs(EXPRP expr);
|
||||
|
||||
Expr(int outputSize);
|
||||
|
||||
friend class Variable;
|
||||
friend class VARP;
|
||||
VARP::InputType mType;
|
||||
const Op* mOp;
|
||||
std::vector<VARP> mInputs;
|
||||
std::vector<std::string> mOutputNames;
|
||||
|
||||
bool mValid = true;
|
||||
std::shared_ptr<char> mExtraBuffer;
|
||||
int mOpBufferSize = 0;
|
||||
std::string mName;
|
||||
std::shared_ptr<Inside> mInside = nullptr;
|
||||
bool mVisited = false;
|
||||
std::vector<WeakEXPRP> mTo;
|
||||
|
||||
// Only the enter input has entries, and it helps to get info for enter
|
||||
// input expression.
|
||||
std::vector<VARP> mEntries;
|
||||
};
|
||||
} // namespace Express
|
||||
} // namespace MNN
|
||||
|
||||
#endif /* Expr_hpp */
|
||||
16
3rd/win/mnn/include/MNN/expr/ExprCreator.hpp
Normal file
16
3rd/win/mnn/include/MNN/expr/ExprCreator.hpp
Normal file
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// ExprCreator.hpp
|
||||
// MNN
|
||||
//
|
||||
// Created by MNN on 2019/06/27.
|
||||
// Copyright © 2018, Alibaba Group Holding Limited
|
||||
//
|
||||
|
||||
#ifndef ExprCreator_hpp
|
||||
#define ExprCreator_hpp
|
||||
|
||||
#include <MNN/expr/Expr.hpp>
|
||||
#include <MNN/expr/MathOp.hpp>
|
||||
#include <MNN/expr/NeuralNetWorkOp.hpp>
|
||||
|
||||
#endif
|
||||
128
3rd/win/mnn/include/MNN/expr/MathOp.hpp
Normal file
128
3rd/win/mnn/include/MNN/expr/MathOp.hpp
Normal file
@@ -0,0 +1,128 @@
|
||||
//
|
||||
// MathOp.hpp
|
||||
// MNN
|
||||
//
|
||||
// Created by MNN on 2019/06/27.
|
||||
// Copyright © 2018, Alibaba Group Holding Limited
|
||||
//
|
||||
|
||||
#ifndef MathOp_HPP
|
||||
#define MathOp_HPP
|
||||
|
||||
namespace MNN {
|
||||
namespace Express {
|
||||
//BinaryOPs
|
||||
MNN_PUBLIC VARP _Add(VARP x, VARP y);
|
||||
MNN_PUBLIC VARP _Subtract(VARP x, VARP y);
|
||||
MNN_PUBLIC VARP _Multiply(VARP x, VARP y);
|
||||
MNN_PUBLIC VARP _Divide(VARP x, VARP y);
|
||||
MNN_PUBLIC VARP _Pow(VARP x, VARP y);
|
||||
MNN_PUBLIC VARP _Minimum(VARP x, VARP y);
|
||||
MNN_PUBLIC VARP _Maximum(VARP x, VARP y);
|
||||
MNN_PUBLIC VARP _BiasAdd(VARP value, VARP bias);
|
||||
MNN_PUBLIC VARP _Greater(VARP x, VARP y);
|
||||
MNN_PUBLIC VARP _GreaterEqual(VARP x, VARP y);
|
||||
MNN_PUBLIC VARP _Less(VARP x, VARP y);
|
||||
MNN_PUBLIC VARP _FloorDiv(VARP x, VARP y);
|
||||
MNN_PUBLIC VARP _SquaredDifference(VARP x, VARP y);
|
||||
MNN_PUBLIC VARP _Equal(VARP x, VARP y);
|
||||
MNN_PUBLIC VARP _LessEqual(VARP x, VARP y);
|
||||
MNN_PUBLIC VARP _FloorMod(VARP x, VARP y);
|
||||
MNN_PUBLIC VARP _Atan2(VARP x, VARP y);
|
||||
MNN_PUBLIC VARP _LogicalOr(VARP x, VARP y);
|
||||
MNN_PUBLIC VARP _NotEqual(VARP x, VARP y);
|
||||
|
||||
//UnaryOPs
|
||||
MNN_PUBLIC VARP _Sign(VARP a);
|
||||
MNN_PUBLIC VARP _Abs(VARP x);
|
||||
MNN_PUBLIC VARP _Negative(VARP x);
|
||||
MNN_PUBLIC VARP _Floor(VARP x);
|
||||
MNN_PUBLIC VARP _Round(VARP x);
|
||||
MNN_PUBLIC VARP _Ceil(VARP x);
|
||||
MNN_PUBLIC VARP _Square(VARP x);
|
||||
MNN_PUBLIC VARP _Sqrt(VARP x);
|
||||
MNN_PUBLIC VARP _Rsqrt(VARP x);
|
||||
MNN_PUBLIC VARP _Exp(VARP x);
|
||||
MNN_PUBLIC VARP _Log(VARP x);
|
||||
MNN_PUBLIC VARP _Sin(VARP x);
|
||||
MNN_PUBLIC VARP _Sinh(VARP x);
|
||||
MNN_PUBLIC VARP _Cos(VARP x);
|
||||
MNN_PUBLIC VARP _Cosh(VARP x);
|
||||
MNN_PUBLIC VARP _Tan(VARP x);
|
||||
MNN_PUBLIC VARP _Asin(VARP x);
|
||||
MNN_PUBLIC VARP _Asinh(VARP x);
|
||||
MNN_PUBLIC VARP _Acos(VARP x);
|
||||
MNN_PUBLIC VARP _Acosh(VARP x);
|
||||
MNN_PUBLIC VARP _Atan(VARP x);
|
||||
MNN_PUBLIC VARP _Atanh(VARP x);
|
||||
MNN_PUBLIC VARP _Reciprocal(VARP x);
|
||||
MNN_PUBLIC VARP _Log1p(VARP x);
|
||||
//Only one but not in UnaryOPs
|
||||
MNN_PUBLIC VARP _Tanh(VARP x);
|
||||
MNN_PUBLIC VARP _Sigmoid(VARP x);
|
||||
MNN_PUBLIC VARP _Erf(VARP x);
|
||||
MNN_PUBLIC VARP _Erfc(VARP x);
|
||||
MNN_PUBLIC VARP _Erfinv(VARP x);
|
||||
MNN_PUBLIC VARP _Expm1(VARP x);
|
||||
|
||||
|
||||
//ReduceOPs
|
||||
MNN_PUBLIC VARP _ReduceSum(VARP input_variable, INTS axis = {}, bool keepDims = false);
|
||||
MNN_PUBLIC VARP _ReduceMean(VARP input_variable, INTS axis = {}, bool keepDims = false);
|
||||
MNN_PUBLIC VARP _ReduceMax(VARP input_variable, INTS axis = {}, bool keepDims = false);
|
||||
MNN_PUBLIC VARP _ReduceMin(VARP input_variable, INTS axis = {}, bool keepDims = false);
|
||||
MNN_PUBLIC VARP _ReduceProd(VARP input_variable, INTS axis = {}, bool keepDims = false);
|
||||
MNN_PUBLIC VARP _ReduceAny(VARP input_variable, INTS axis = {}, bool keepDims = false);
|
||||
MNN_PUBLIC VARP _ReduceAll(VARP input_variable, INTS axis = {}, bool keepDims = false);
|
||||
|
||||
MNN_PUBLIC VARP _ReduceSumMutable(VARP input_variable, VARP axis, bool keepDims = false);
|
||||
MNN_PUBLIC VARP _ReduceMeanMutable(VARP input_variable, VARP axis, bool keepDims = false);
|
||||
MNN_PUBLIC VARP _ReduceMaxMutable(VARP input_variable, VARP axis, bool keepDims = false);
|
||||
MNN_PUBLIC VARP _ReduceMinMutable(VARP input_variable, VARP axis, bool keepDims = false);
|
||||
MNN_PUBLIC VARP _ReduceProdMutable(VARP input_variable, VARP axis, bool keepDims = false);
|
||||
MNN_PUBLIC VARP _ReduceAnyMutable(VARP input_variable, VARP axis, bool keepDims = false);
|
||||
MNN_PUBLIC VARP _ReduceAllMutable(VARP input_variable, VARP axis, bool keepDims = false);
|
||||
|
||||
//EltwiseOPs
|
||||
MNN_PUBLIC VARP _Prod(VARP a, VARP b, std::vector<float> coeff);
|
||||
MNN_PUBLIC VARP _Sum(VARP a, VARP b, std::vector<float> coeff);
|
||||
MNN_PUBLIC VARP _Max(VARP a, VARP b, std::vector<float> coeff);
|
||||
MNN_PUBLIC VARP _Sub(VARP a, VARP b, std::vector<float> coeff);
|
||||
MNN_PUBLIC VARP _EltwiseProdInt8(VARP x, VARP y,
|
||||
std::vector<int8_t> x_weight, std::vector<int32_t> x_bias, std::vector<float> x_scale, std::vector<float> x_tensorScale,
|
||||
std::vector<int8_t> y_weight, std::vector<int32_t> y_bias, std::vector<float> y_scale, std::vector<float> y_tensorScale,
|
||||
std::vector<int8_t> output_weight, std::vector<int32_t> output_bias, std::vector<float> output_scale, std::vector<float> output_tensorScale);
|
||||
MNN_PUBLIC VARP _EltwiseSumInt8(VARP x, VARP y,
|
||||
std::vector<int8_t> x_weight, std::vector<int32_t> x_bias, std::vector<float> x_scale, std::vector<float> x_tensorScale,
|
||||
std::vector<int8_t> y_weight, std::vector<int32_t> y_bias, std::vector<float> y_scale, std::vector<float> y_tensorScale,
|
||||
std::vector<int8_t> output_weight, std::vector<int32_t> output_bias, std::vector<float> output_scale, std::vector<float> output_tensorScale);
|
||||
MNN_PUBLIC VARP _EltwiseSubInt8(VARP x, VARP y,
|
||||
std::vector<int8_t> x_weight, std::vector<int32_t> x_bias, std::vector<float> x_scale, std::vector<float> x_tensorScale,
|
||||
std::vector<int8_t> y_weight, std::vector<int32_t> y_bias, std::vector<float> y_scale, std::vector<float> y_tensorScale,
|
||||
std::vector<int8_t> output_weight, std::vector<int32_t> output_bias, std::vector<float> output_scale, std::vector<float> output_tensorScale);
|
||||
MNN_PUBLIC VARP _EltwiseMaxInt8(VARP x, VARP y,
|
||||
std::vector<int8_t> x_weight, std::vector<int32_t> x_bias, std::vector<float> x_scale, std::vector<float> x_tensorScale,
|
||||
std::vector<int8_t> y_weight, std::vector<int32_t> y_bias, std::vector<float> y_scale, std::vector<float> y_tensorScale,
|
||||
std::vector<int8_t> output_weight, std::vector<int32_t> output_bias, std::vector<float> output_scale, std::vector<float> output_tensorScale);
|
||||
|
||||
|
||||
//OtherOPs
|
||||
template<typename T>
|
||||
VARP _Cast(VARP x) {
|
||||
return _Cast(x, halide_type_of<T>());
|
||||
}
|
||||
MNN_PUBLIC VARP _Cast(VARP x, halide_type_t dtype);
|
||||
MNN_PUBLIC VARP _MatMul(VARP a, VARP b, bool tranposeA = false, bool tranposeB = false);
|
||||
MNN_PUBLIC VARP _Normalize(VARP x, int32_t acrossSpatial, int32_t channelShared, float eps, std::vector<float> scale);
|
||||
MNN_PUBLIC VARP _ArgMax(VARP input, int axis = 0);
|
||||
MNN_PUBLIC VARP _ArgMin(VARP input, int axis = 0);
|
||||
MNN_PUBLIC VARP _BatchMatMul(VARP x, VARP y, bool adj_x = false, bool adj_y = false);
|
||||
MNN_PUBLIC VARP _UnravelIndex(VARP indices, VARP dims);
|
||||
MNN_PUBLIC VARP _ScatterNd(VARP indices, VARP updates, VARP shape);
|
||||
MNN_PUBLIC VARP _OneHot(VARP indices, VARP depth, VARP onValue, VARP offValue, int axis = -1);
|
||||
MNN_PUBLIC VARP _BroadcastTo(VARP a, VARP shape);
|
||||
MNN_PUBLIC VARP _LinSpace(VARP start, VARP stop, VARP num);
|
||||
}; // namespace Express
|
||||
}; // namespace MNN
|
||||
|
||||
#endif /* MathOp_HPP */
|
||||
142
3rd/win/mnn/include/MNN/expr/NeuralNetWorkOp.hpp
Normal file
142
3rd/win/mnn/include/MNN/expr/NeuralNetWorkOp.hpp
Normal file
@@ -0,0 +1,142 @@
|
||||
//
|
||||
// NeuralNetWorkOp.hpp
|
||||
// MNN
|
||||
//
|
||||
// Created by MNN on 2019/06/27.
|
||||
// Copyright © 2018, Alibaba Group Holding Limited
|
||||
//
|
||||
|
||||
#ifndef NeuralNetWorkOp_HPP
|
||||
#define NeuralNetWorkOp_HPP
|
||||
|
||||
namespace MNN {
|
||||
namespace Express {
|
||||
enum PaddingMode {CAFFE, VALID, SAME};
|
||||
enum PoolingMode {MAXPOOL, AVEPOOL};
|
||||
enum PadValueMode {CONSTANT, REFLECT, SYMMETRIC};
|
||||
MNN_PUBLIC VARP _Input(INTS shape = {}, Dimensionformat data_format = NC4HW4, halide_type_t dtype = halide_type_of<float>()) ;
|
||||
MNN_PUBLIC VARP _Clone(VARP source, bool deepCopy = false);
|
||||
|
||||
MNN_PUBLIC VARP _Scalar(const void* ptr, halide_type_t type);
|
||||
|
||||
template <typename T>
|
||||
VARP _Scalar(T value) {
|
||||
return _Scalar(&value, halide_type_of<T>());
|
||||
}
|
||||
|
||||
|
||||
MNN_PUBLIC VARP _Const(float value, INTS shape = {}, Dimensionformat format = NHWC);
|
||||
MNN_PUBLIC VARP _Const(const void* ptr, INTS shape = {}, Dimensionformat format = NHWC,
|
||||
halide_type_t type = halide_type_of<float>());
|
||||
MNN_PUBLIC VARP _TrainableParam(float value, INTS dims, Dimensionformat format);
|
||||
MNN_PUBLIC VARP _TrainableParam(const void* ptr, INTS dims, Dimensionformat format,
|
||||
halide_type_t type = halide_type_of<float>());
|
||||
MNN_PUBLIC VARP _InnerProduct(std::vector<float>&& weight, std::vector<float>&& bias, VARP x, INTS outputShape);
|
||||
MNN_PUBLIC VARP _Conv(VARP weight, VARP bias, VARP x, PaddingMode pad = VALID, INTS stride = {1, 1},
|
||||
INTS dilate = {1, 1}, int group = 1, INTS pads = {0, 0});
|
||||
|
||||
MNN_PUBLIC VARP _Conv(float weight, float bias, VARP x, INTS channel, INTS kernelSize, PaddingMode pad = VALID,
|
||||
INTS stride = {1, 1}, INTS dilate = {1, 1}, int group = 1);
|
||||
MNN_PUBLIC VARP _Conv(std::vector<int8_t>&& weight, std::vector<float>&& bias, VARP x, INTS channel, INTS kernelSize,
|
||||
PaddingMode pad = VALID, INTS stride = {1, 1}, INTS dilate = {1, 1}, int group = 1, INTS pads = {0, 0}, bool relu = false, bool relu6 = false, int nbits = 8);
|
||||
MNN_PUBLIC VARP _Conv(std::vector<float>&& weight, std::vector<float>&& bias, VARP x, INTS channel, INTS kernelSize,
|
||||
PaddingMode pad = VALID, INTS stride = {1, 1}, INTS dilate = {1, 1}, int group = 1, INTS pads = {0, 0}, bool relu = false, bool relu6 = false);
|
||||
MNN_PUBLIC VARP _Deconv(VARP weight, VARP bias, VARP x, PaddingMode pad = VALID, INTS stride = {1, 1},
|
||||
INTS dilate = {1, 1}, int group = 1, INTS pads = {0, 0});
|
||||
|
||||
MNN_PUBLIC VARP _Deconv(std::vector<float>&& weight, std::vector<float>&& bias, VARP x, INTS channel, INTS kernelSize,
|
||||
PaddingMode pad, INTS stride = {1, 1}, INTS dilate = {1, 1}, int group = 1, INTS pads = {0, 0}, bool relu = false, bool relu6 = false);
|
||||
|
||||
MNN_PUBLIC VARP _MaxPool(VARP x, INTS kernel, INTS stride = {1, 1}, PaddingMode pad = VALID, INTS pads= {0, 0});
|
||||
MNN_PUBLIC VARP _AvePool(VARP x, INTS kernel, INTS stride = {1, 1}, PaddingMode pad = VALID, INTS pads= {0, 0});
|
||||
MNN_PUBLIC VARP _Reshape(VARP x, INTS shape, Dimensionformat original_format = NCHW);
|
||||
MNN_PUBLIC VARP _Reshape(VARP x, VARP shape);
|
||||
MNN_PUBLIC VARP _Scale(VARP x, int channels, std::vector<float>&& scales, std::vector<float>&& bias);
|
||||
|
||||
MNN_PUBLIC VARP _Relu(VARP x, float slope = 0.0f);
|
||||
MNN_PUBLIC VARP _Relu6(VARP x, float minValue = 0.0f, float maxValue = 6.0f);
|
||||
MNN_PUBLIC VARP _PRelu(VARP x, std::vector<float> &&slopes);
|
||||
MNN_PUBLIC VARP _Softmax(VARP logits, int axis = -1);
|
||||
MNN_PUBLIC VARP _Softplus(VARP features);
|
||||
MNN_PUBLIC VARP _Softsign(VARP features);
|
||||
MNN_PUBLIC std::vector<VARP> _Split(VARP value, INTS size_splits, int axis = 0);
|
||||
MNN_PUBLIC VARP _Slice(VARP x, VARP starts, VARP sizes);
|
||||
MNN_PUBLIC VARP _StridedSlice(VARP input, VARP begin, VARP end, VARP strided,
|
||||
int32_t beginMask, int32_t endMask, int32_t ellipsisMask,
|
||||
int32_t newAxisMask, int32_t shrinkAxisMask);
|
||||
MNN_PUBLIC VARP _Concat(VARPS values, int axis);
|
||||
MNN_PUBLIC VARP _Convert(VARP input, Dimensionformat format);
|
||||
MNN_PUBLIC VARP _Transpose(VARP x, INTS perm);
|
||||
MNN_PUBLIC VARP _Transpose(VARP x, VARP perm);
|
||||
MNN_PUBLIC VARP _ChannelShuffle(VARP x, int group);
|
||||
MNN_PUBLIC VARP _ChangeInputFormat(VARP input, Dimensionformat format);
|
||||
MNN_PUBLIC VARP _Conv2DBackPropFilter(VARP input, VARP inputGrad, INTS kernelSize, PaddingMode pad = VALID, INTS stride = {1, 1}, INTS dilate = {1, 1}, int group = 1, INTS pads = {0, 0});
|
||||
MNN_PUBLIC VARP _PoolGrad(VARP originInput, VARP originOutput, VARP inputGrad, INTS kernel, INTS stride, PoolingMode type, PaddingMode pad = VALID, INTS pads= {0, 0});
|
||||
// FIXME: move the api to Array Ops
|
||||
MNN_PUBLIC VARP _ReverseSequence(VARP x, VARP y, int batchDim, int seqDim);
|
||||
// FIXME: move the api to Image Ops
|
||||
MNN_PUBLIC VARP _Crop(VARP images, VARP size, int axis, INTS offset);
|
||||
MNN_PUBLIC VARP _Resize(VARP images, float xScale, float yScale);
|
||||
MNN_PUBLIC VARP _Pad(VARP x, VARP paddings, PadValueMode mode = CONSTANT);
|
||||
MNN_PUBLIC VARP _ExpandDims(VARP input, int axis);
|
||||
MNN_PUBLIC VARP _ExpandDims(VARP input, VARP axis);
|
||||
|
||||
MNN_PUBLIC VARP _Shape(VARP input, bool nchw = false);
|
||||
MNN_PUBLIC VARP _Stack(VARPS values, int axis=0);
|
||||
enum InterpolationMethod {BILINEAR, NEAREST};
|
||||
MNN_PUBLIC VARP _CropAndResize(VARP image, VARP boxes, VARP box_ind, VARP crop_size,
|
||||
InterpolationMethod method, float extrapolation_value = 0.0);
|
||||
MNN_PUBLIC VARP _Fill(VARP dims, VARP value);
|
||||
MNN_PUBLIC VARP _Tile(VARP input, VARP multiples);
|
||||
MNN_PUBLIC VARP _Gather(VARP params, VARP indices);
|
||||
MNN_PUBLIC VARP _GatherV2(VARP params, VARP indices, VARP axis = nullptr);
|
||||
MNN_PUBLIC VARP _Squeeze(VARP input, INTS axis = {});
|
||||
MNN_PUBLIC VARP _Unsqueeze(VARP input, INTS axis = {});
|
||||
MNN_PUBLIC VARP _BatchToSpaceND(VARP input, VARP block_shape, VARP crops);
|
||||
MNN_PUBLIC VARP _GatherND(VARP params, VARP indices);
|
||||
MNN_PUBLIC VARP _Selu(VARP features, float scale, float alpha);
|
||||
MNN_PUBLIC VARP _Size(VARP input);
|
||||
MNN_PUBLIC VARP _Elu(VARP features, float alpha=1.0);
|
||||
MNN_PUBLIC VARP _Threshold(VARP features, float alpha=1.0);
|
||||
MNN_PUBLIC VARP _MatrixBandPart(VARP input, VARP num_lower, VARP num_upper);
|
||||
MNN_PUBLIC std::vector<VARP> _Moments(VARP x, INTS axis, VARP shift, bool keepDims);
|
||||
MNN_PUBLIC VARP _SetDiff1D(VARP x, VARP y);
|
||||
MNN_PUBLIC VARP _SpaceToDepth(VARP input, int block_size);
|
||||
MNN_PUBLIC VARP _SpaceToBatchND(VARP input, VARP block_shape, VARP paddings);
|
||||
MNN_PUBLIC VARP _ZerosLike(VARP input);
|
||||
MNN_PUBLIC std::vector<VARP> _Unstack(VARP value, int axis=0);
|
||||
MNN_PUBLIC VARP _Rank(VARP input);
|
||||
MNN_PUBLIC VARP _Range(VARP start, VARP limit, VARP delta);
|
||||
MNN_PUBLIC VARP _DepthToSpace(VARP input, int block_size);
|
||||
MNN_PUBLIC VARP _PriorBox(VARP feature, VARP image,
|
||||
std::vector<float> min_size, std::vector<float> max_size, std::vector<float>aspect_ratio,
|
||||
bool flip, bool clip, std::vector<float>variance,
|
||||
unsigned int img_h, unsigned int img_w, float step_h, float step_w, float offset = 0.5);
|
||||
MNN_PUBLIC VARP _Permute(VARP input, INTS dims);
|
||||
MNN_PUBLIC VARP _DetectionOutput(VARP location, VARP confidence, VARP priorbox,
|
||||
unsigned int num_classes, bool share_location, int background_label_id,
|
||||
float nms_threshhold, int nms_topk, int code_type,
|
||||
bool variance_encoded_in_target,
|
||||
int keep_top_k, float confidence_threshold, float visualize_threshold);
|
||||
MNN_PUBLIC std::vector<VARP> _DetectionPostProcess(VARP encode_boxes, VARP class_predictions, VARP anchors,
|
||||
int num_classes, int max_detections,
|
||||
int max_class_per_detection, int detections_per_class,
|
||||
float nms_threshold, float iou_threshold,
|
||||
bool use_regular_nms, std::vector<float> centersize_encoding);
|
||||
MNN_PUBLIC VARP _Interp(VARPS xs, float widthScale, float heightScale, int outputWidth, int outputHeight, int resizeType, bool alignCorners);
|
||||
|
||||
MNN_PUBLIC VARP _ZeroGrad(VARP x);
|
||||
|
||||
// Int8 Inference
|
||||
MNN_PUBLIC VARP _Conv(std::vector<int8_t>&& weight, std::vector<int>&& bias, std::vector<float>&& scale, VARP x, INTS channel, INTS kernelSize,
|
||||
PaddingMode pad, INTS stride, INTS dilate, int group, INTS pads, bool relu, int nbits = 8);
|
||||
MNN_PUBLIC VARP _CosineSimilarity(VARP input0, VARP input1, VARP inputDim);
|
||||
MNN_PUBLIC VARP _FloatToInt8(VARP x, VARP scale, char minValue, char maxValue);
|
||||
MNN_PUBLIC VARP _Int8ToFloat(VARP x, VARP scale);
|
||||
|
||||
MNN_PUBLIC VARP _Select(VARP select, VARP input0, VARP input1);
|
||||
|
||||
} // namespace Express
|
||||
} // namespace MNN
|
||||
|
||||
#endif /* NeuralNetWorkOp_HPP */
|
||||
64
3rd/win/mnn/include/MNN/expr/Optimizer.hpp
Normal file
64
3rd/win/mnn/include/MNN/expr/Optimizer.hpp
Normal file
@@ -0,0 +1,64 @@
|
||||
//
|
||||
// Optimizer.hpp
|
||||
// MNN
|
||||
//
|
||||
// Created by MNN on 2019/08/20.
|
||||
// Copyright © 2018, Alibaba Group Holding Limited
|
||||
//
|
||||
#ifndef Optimizer_hpp
|
||||
#define Optimizer_hpp
|
||||
#include <MNN/expr/Expr.hpp>
|
||||
#include <MNN/MNNForwardType.h>
|
||||
|
||||
namespace MNN {
|
||||
namespace Express {
|
||||
class MNN_PUBLIC Optimizer {
|
||||
public:
|
||||
enum Device {
|
||||
CPU = 0,
|
||||
GPU = 1,
|
||||
OTHER = 2,
|
||||
AUTO = 3
|
||||
};
|
||||
struct Config {
|
||||
Device device = CPU;
|
||||
MNNForwardType forwardType = MNN_FORWARD_ALL;
|
||||
int numThread = 4;
|
||||
};
|
||||
static std::shared_ptr<Optimizer> create(Config config);
|
||||
struct Cost {
|
||||
float compute; // MFlops
|
||||
float memory; // MB
|
||||
};
|
||||
class Parameters {
|
||||
public:
|
||||
Parameters(int n);
|
||||
virtual ~Parameters();
|
||||
|
||||
float* get() const {
|
||||
return mValue;
|
||||
}
|
||||
int size() const {
|
||||
return mSize;
|
||||
}
|
||||
|
||||
private:
|
||||
float* mValue;
|
||||
int mSize;
|
||||
};
|
||||
virtual std::shared_ptr<Parameters> onGetParameters(const std::vector<VARP>& outputs) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//Given paramters and measure cost, the parameters must be the same as onGetParameters
|
||||
virtual Cost onMeasure(const std::vector<VARP>& outputs, std::shared_ptr<Parameters> parameters = nullptr) = 0;
|
||||
|
||||
//Modify the output directly, the parameters must be the same as onGetParameters
|
||||
virtual bool onExecute(const std::vector<VARP>& outputs, std::shared_ptr<Parameters> parameters = nullptr) = 0;
|
||||
|
||||
Optimizer() = default;
|
||||
virtual ~Optimizer() = default;
|
||||
};
|
||||
} // namespace Express
|
||||
} // namespace MNN
|
||||
#endif
|
||||
Reference in New Issue
Block a user