op_params.h 6.1 KB
Newer Older
S
update  
superjomn 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once
16
#include <string>
S
superjomn 已提交
17
#include <vector>
18
#include "paddle/fluid/lite/core/compatible_tensor.h"
Y
Yan Chunwei 已提交
19
#include "paddle/fluid/lite/core/framework.pb.h"
S
update  
superjomn 已提交
20 21 22 23 24 25 26 27 28 29
#include "paddle/fluid/lite/utils/all.h"

/*
 * This file contains all the argument parameter data structure for operators.
 */

namespace paddle {
namespace lite {
namespace operators {

Y
Yan Chunwei 已提交
30 31 32
using param_t = Any;

/// ----------------------- Functional operators ------------------------------
S
Superjomn 已提交
33
struct FeedParam {
34 35
  const std::vector<lite::Tensor>* feed_list{};
  lite::Tensor* out{};
36 37 38 39
  int col;
};

struct FetchParam {
40 41
  const lite::Tensor* input{};
  std::vector<lite::Tensor>* fetch_list{};
S
Superjomn 已提交
42 43 44
  int col;
};

Y
Yan Chunwei 已提交
45 46 47 48 49 50 51 52
// Helper op for lite framework
struct IoCopyParam {
  const lite::Tensor* x{};
  lite::Tensor* y{};
};

/// -------------------------- NN operators ------------------------------------

S
update  
superjomn 已提交
53
struct FcParam {
54 55 56 57 58
  lite::Tensor* input{};
  lite::Tensor* w{};
  lite::Tensor* bias{};
  lite::Tensor* output{};
  lite::DDim in_mat_dims;
S
superjomn 已提交
59
  int in_num_col_dims{1};
S
update  
superjomn 已提交
60 61
};

S
superjomn 已提交
62
struct ReluParam {
63 64
  lite::Tensor* input{};
  lite::Tensor* output{};
S
superjomn 已提交
65 66
};

S
superjomn 已提交
67 68
// For Mul Op
struct MulParam {
69 70 71
  lite::Tensor* x{};
  lite::Tensor* y{};
  lite::Tensor* output{};
S
superjomn 已提交
72 73 74 75 76

  int x_num_col_dims{1};
  int y_num_col_dims{1};
};

L
liuwei1031 已提交
77 78 79 80 81 82 83 84 85 86 87
struct MulGradParam {
  const lite::Tensor* x{};
  const lite::Tensor* y{};
  const lite::Tensor* output_grad{};
  lite::Tensor* x_grad{};
  lite::Tensor* y_grad{};

  int x_num_col_dims{1};
  int y_num_col_dims{1};
};

S
superjomn 已提交
88 89
// For Scale Op
struct ScaleParam {
90 91
  lite::Tensor* x{};
  lite::Tensor* output{};
S
superjomn 已提交
92 93 94 95 96 97

  float scale{1.};
  float bias{};
  bool bias_after_scale{true};
};

98
// For Softmax op
99 100 101 102 103 104
struct SoftmaxParam {
  lite::Tensor* x{};
  lite::Tensor* output{};
  int axis{-1};
};

105 106 107 108 109 110 111 112 113 114 115
// For Reshape and Reshape2 Op
struct ReshapeParam {
  const lite::Tensor* x{};
  const lite::Tensor* actual_shape{nullptr};
  lite::Tensor* output{};
  lite::Tensor* xshape{};

  std::vector<int> shape{};
  bool inplace{false};
};

116 117 118 119 120 121 122
// For Concat op
struct ConcatParam {
  std::vector<lite::Tensor*> x{};
  lite::Tensor* output{};
  int axis{0};
};

123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
// For Convolution op
struct ConvParam {
  lite::Tensor* x{};
  lite::Tensor* filter{};
  lite::Tensor* bias{};
  lite::Tensor* residualData{};
  lite::Tensor* output{};
  std::vector<int> strides{1, 1};
  std::vector<int> paddings{0, 0};
  int groups{1};
  std::vector<int> dilations{1, 1};
  bool fuse_relu_before_depthwise_conv{false};
  bool use_mkldnn{false};
  bool fuse_relu{false};  // only used in mkldnn kernel
  bool use_quantizer{
      false};  // set true for op that should be quantized, only used for cpu
  bool fuse_residual_connection{false};
  float scale_in{1.0f};           // only used with mkl-dnn int8
  float scale_out{1.0f};          // only used with mkl-dnn int8
  float scale_in_eltwise{1.0f};   // only used with mkl-dnn int8
  float scale_weights{1.0f};      // only used with mkl-dnn int8
  bool force_fp32_output{false};  // only used in mkl-dnn int8
  std::string data_format{"Anylayout"};
};

// For Pooling op
struct PoolParam {
  lite::Tensor* x{};
  lite::Tensor* output{};
  std::string pooling_type{""};
  std::vector<int> ksize{};
  bool global_pooling{
      false};  // if true, knernel size and paddings will be ignored
  std::vector<int> strides{1, 1};
  std::vector<int> paddings{0, 0};
  bool exclusive{true};
  bool adaptive{false};
  bool ceil_mode{false};
  bool use_quantizer{false};
  std::string data_format{"AnyLayout"};
};

// For Dropout op
struct DropoutParam {
  const lite::Tensor* x{};
  lite::Tensor* output{};
  lite::Tensor* mask{};
  float dropout_prob{.5f};
  bool is_test{false};
  bool fix_seed{false};
  int seed{0};
  std::string dropout_implementation{"downgrade_in_infer"};
};

Y
Yan Chunwei 已提交
177 178 179 180 181 182 183 184 185
/// ----------------------- element wise operators ----------------------
struct ElementwiseParam {
  const lite::Tensor* X{};
  const lite::Tensor* Y{};
  lite::Tensor* Out{};
  int axis{-1};  // for broadcasting.
};

struct ElementwiseGradParam {
L
liuwei1031 已提交
186 187 188 189
  const lite::Tensor* Y{};
  const lite::Tensor* Out_grad{};
  lite::Tensor* X_grad{};
  lite::Tensor* Y_grad{};
Y
Yan Chunwei 已提交
190
  int axis{-1};  // for broadcasting.
S
Superjomn 已提交
191 192
};

Y
Yan Chunwei 已提交
193 194 195 196 197 198 199 200 201 202 203 204 205
/// ----------------------- activation operators ----------------------
struct ActivationParam {
  const lite::Tensor* X{};
  lite::Tensor* Out{};
};

struct ActivationGradParam {
  const lite::Tensor* X{};
  const lite::Tensor* Out{};
  // for backward
  lite::Tensor* X_grad{};
  const lite::Tensor* Out_grad{};
};
S
update  
superjomn 已提交
206

L
liuwei1031 已提交
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
/// ----------------------- mean operators ----------------------
struct MeanParam {
  const lite::Tensor* X{};
  lite::Tensor* Out{};
};

struct MeanGradParam {
  const lite::Tensor* X{};
  const lite::Tensor* Out_grad{};
  // for backward
  lite::Tensor* X_grad{};
};

/// ----------------------- fill_constant operators ----------------------
struct FillConstantParam {
  int dtype{framework::proto::VarType::FP32};
  std::vector<int64_t> shape{};
  float value{0.0f};
  // useless for x86, keep it for compatibility
  bool force_cpu{false};
  lite::Tensor* Out{};
};

/// ----------------------- sgd operators ----------------------
struct SGDParam {
  int dtype{framework::proto::VarType::FP32};

  const lite::Tensor* Param{};
  const lite::Tensor* LearningRate{};
  const lite::Tensor* Grad{};
  lite::Tensor* ParamOut{};
};

240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
//
struct BatchNormParam {
  lite::Tensor* x{};
  lite::Tensor* bias{};
  lite::Tensor* mean{};
  lite::Tensor* scale{};
  lite::Tensor* var{};
  lite::Tensor* out{};
  lite::Tensor* mean_out{};
  lite::Tensor* var_out{};
  lite::Tensor* saved_mean{};
  lite::Tensor* saved_var{};

  float eps{1e-5};
};

S
update  
superjomn 已提交
256 257 258
}  // namespace operators
}  // namespace lite
}  // namespace paddle