nndeploy C++ API  0.2.0
nndeploy C++ API
expr.h
Go to the documentation of this file.
1 
2 #ifndef _NNDEPLOY_OP_EXPR_H_
3 #define _NNDEPLOY_OP_EXPR_H_
4 
5 #include "nndeploy/base/macro.h"
7 #include "nndeploy/ir/ir.h"
8 
9 namespace nndeploy {
10 namespace op {
11 
12 // 标识Expr的类型
13 enum ExprType : int {
17 };
18 
19 extern NNDEPLOY_CC_API std::string exprTypeToString(ExprType type);
20 extern NNDEPLOY_CC_API ExprType stringToExprType(const std::string &src);
21 
23  public:
24  Expr(const std::string &name);
25  Expr(const std::string &name, base::DataType data_type);
26  Expr(const std::string &name, base::DataType data_type,
28  Expr(std::shared_ptr<ir::ValueDesc> value_desc);
29  Expr(std::shared_ptr<ir::OpDesc> op_desc);
30  Expr(std::shared_ptr<ir::ModelDesc> model_desc);
31 
32  ~Expr();
33 
34  std::vector<std::string> getOutputName();
35 
36  protected:
38  std::shared_ptr<ir::ValueDesc> value_desc_;
39  std::shared_ptr<ir::OpDesc> op_desc_;
40  std::shared_ptr<ir::ModelDesc> model_desc_;
41 };
42 
49 // input
50 NNDEPLOY_CC_API std::shared_ptr<Expr> makeInput(
51  ir::ModelDesc *model_desc, std::string name,
54 // constant
55 NNDEPLOY_CC_API std::shared_ptr<Expr> makeConstant(ir::ModelDesc *model_desc,
56  std::string name);
57 // output
59  std::shared_ptr<Expr> expr);
60 // block
61 NNDEPLOY_CC_API std::shared_ptr<Expr> makeBlock(
62  ir::ModelDesc *model_desc, std::shared_ptr<ir::ModelDesc> model_block);
63 // conv2d
64 NNDEPLOY_CC_API std::shared_ptr<Expr> makeConv(
65  ir::ModelDesc *model_desc, std::shared_ptr<Expr> input,
66  std::shared_ptr<ir::ConvParam> param, const std::string &weight,
67  const std::string &bias = "", std::string op_name = "",
68  std::string output_name = "");
69 // relu
70 NNDEPLOY_CC_API std::shared_ptr<Expr> makeRelu(ir::ModelDesc *model_desc,
71  std::shared_ptr<Expr> input,
72  std::string op_name = "",
73  std::string output_name = "");
74 // relu
75 NNDEPLOY_CC_API std::shared_ptr<Expr> makeSigmoid(ir::ModelDesc *model_desc,
76  std::shared_ptr<Expr> input,
77  std::string op_name = "",
78  std::string output_name = "");
79 
80 // softmax
81 NNDEPLOY_CC_API std::shared_ptr<Expr> makeSoftmax(
82  ir::ModelDesc *model_desc, std::shared_ptr<Expr> input,
83  std::shared_ptr<ir::SoftmaxParam> param, std::string op_name = "",
84  std::string output_name = "");
85 
86 // batchnorm
87 NNDEPLOY_CC_API std::shared_ptr<Expr> makeBatchNorm(
88  ir::ModelDesc *model_desc, std::shared_ptr<Expr> input,
89  std::shared_ptr<ir::BatchNormalizationParam> param,
90  const std::string &scale, const std::string &bias, const std::string &mean,
91  const std::string &var, std::string op_name = "",
92  std::string output_name = "");
93 
94 // add
95 NNDEPLOY_CC_API std::shared_ptr<Expr> makeAdd(ir::ModelDesc *model_desc,
96  std::shared_ptr<Expr> input_0,
97  std::shared_ptr<Expr> input_1,
98  std::string op_name = "",
99  std::string output_name = "");
100 
101 // gemm
102 NNDEPLOY_CC_API std::shared_ptr<Expr> makeGemm(
103  ir::ModelDesc *model_desc, std::shared_ptr<Expr> input,
104  std::shared_ptr<ir::GemmParam> param, const std::string &weight,
105  const std::string &bias = "", std::string op_name = "",
106  std::string output_name = "");
107 
108 // flatten
109 NNDEPLOY_CC_API std::shared_ptr<Expr> makeFlatten(
110  ir::ModelDesc *model_desc, std::shared_ptr<Expr> input,
111  std::shared_ptr<ir::FlattenParam> param, std::string op_name = "",
112  std::string output_name = "");
113 
114 // MaxPool
115 NNDEPLOY_CC_API std::shared_ptr<Expr> makeMaxPool(
116  ir::ModelDesc *model_desc, std::shared_ptr<Expr> input,
117  std::shared_ptr<ir::MaxPoolParam> param, std::string op_name = "",
118  std::string output_name = "");
119 
120 // GlobalAveragePool
122  ir::ModelDesc *model_desc, std::shared_ptr<Expr> input,
123  std::string op_name = "", std::string output_name = "");
124 
125 // TODO: @Leonisux:
126 // 补充llama的算子的手动构图函数
127 // matmul
128 NNDEPLOY_CC_API std::shared_ptr<Expr> makeEmbedding(
129  ir::ModelDesc *model_desc, std::shared_ptr<Expr> indices,
130  std::string op_name, std::string output_name);
131 
132 } // namespace op
133 } // namespace nndeploy
134 
135 #endif
参照onnx的格式,描述模型的结构
Definition: ir.h:109
Expr(std::shared_ptr< ir::OpDesc > op_desc)
Expr(const std::string &name)
std::shared_ptr< ir::ValueDesc > value_desc_
Definition: expr.h:38
Expr(std::shared_ptr< ir::ModelDesc > model_desc)
std::shared_ptr< ir::ModelDesc > model_desc_
Definition: expr.h:40
Expr(const std::string &name, base::DataType data_type, base::IntVector shape)
std::shared_ptr< ir::OpDesc > op_desc_
Definition: expr.h:39
Expr(const std::string &name, base::DataType data_type)
std::vector< std::string > getOutputName()
Expr(std::shared_ptr< ir::ValueDesc > value_desc)
ExprType expr_type_
Definition: expr.h:37
#define NNDEPLOY_CC_API
api
Definition: macro.h:29
std::vector< int > IntVector
Definition: common.h:379
DataType dataTypeOf< float >()
std::shared_ptr< Expr > makeRelu(ir::ModelDesc *model_desc, std::shared_ptr< Expr > input, std::string op_name="", std::string output_name="")
std::shared_ptr< Expr > makeFlatten(ir::ModelDesc *model_desc, std::shared_ptr< Expr > input, std::shared_ptr< ir::FlattenParam > param, std::string op_name="", std::string output_name="")
ExprType stringToExprType(const std::string &src)
std::shared_ptr< Expr > makeBatchNorm(ir::ModelDesc *model_desc, std::shared_ptr< Expr > input, std::shared_ptr< ir::BatchNormalizationParam > param, const std::string &scale, const std::string &bias, const std::string &mean, const std::string &var, std::string op_name="", std::string output_name="")
std::shared_ptr< Expr > makeConstant(ir::ModelDesc *model_desc, std::string name)
std::shared_ptr< Expr > makeGlobalAveragePool(ir::ModelDesc *model_desc, std::shared_ptr< Expr > input, std::string op_name="", std::string output_name="")
std::shared_ptr< Expr > makeMaxPool(ir::ModelDesc *model_desc, std::shared_ptr< Expr > input, std::shared_ptr< ir::MaxPoolParam > param, std::string op_name="", std::string output_name="")
@ kExprTypeValueDesc
Definition: expr.h:14
@ kExprTypeModelDesc
Definition: expr.h:16
@ kExprTypeOpDesc
Definition: expr.h:15
std::shared_ptr< Expr > makeGemm(ir::ModelDesc *model_desc, std::shared_ptr< Expr > input, std::shared_ptr< ir::GemmParam > param, const std::string &weight, const std::string &bias="", std::string op_name="", std::string output_name="")
std::string exprTypeToString(ExprType type)
std::shared_ptr< Expr > makeConv(ir::ModelDesc *model_desc, std::shared_ptr< Expr > input, std::shared_ptr< ir::ConvParam > param, const std::string &weight, const std::string &bias="", std::string op_name="", std::string output_name="")
base::Status shape(device::Tensor *input, std::shared_ptr< ir::ShapeParam > param, device::Tensor *output)
std::shared_ptr< Expr > makeSoftmax(ir::ModelDesc *model_desc, std::shared_ptr< Expr > input, std::shared_ptr< ir::SoftmaxParam > param, std::string op_name="", std::string output_name="")
std::shared_ptr< Expr > makeBlock(ir::ModelDesc *model_desc, std::shared_ptr< ir::ModelDesc > model_block)
std::shared_ptr< Expr > makeSigmoid(ir::ModelDesc *model_desc, std::shared_ptr< Expr > input, std::string op_name="", std::string output_name="")
std::shared_ptr< Expr > makeAdd(ir::ModelDesc *model_desc, std::shared_ptr< Expr > input_0, std::shared_ptr< Expr > input_1, std::string op_name="", std::string output_name="")
void makeOutput(ir::ModelDesc *model_desc, std::shared_ptr< Expr > expr)
std::shared_ptr< Expr > makeEmbedding(ir::ModelDesc *model_desc, std::shared_ptr< Expr > indices, std::string op_name, std::string output_name)
std::shared_ptr< Expr > makeInput(ir::ModelDesc *model_desc, std::string name, base::DataType data_type=base::dataTypeOf< float >(), base::IntVector shape=base::IntVector())
一系列创建函数