op_param.h 52.8 KB
Newer Older
W
wangliu 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13
/* Copyright (c) 2018 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. */
朔-望's avatar
朔-望 已提交
14

15
#pragma once
朔-望's avatar
朔-望 已提交
16

E
eclipsess 已提交
17
#include <string>
W
wangliu 已提交
18
#include <vector>
L
liuruilong 已提交
19
#include "common/log.h"
朔-望's avatar
朔-望 已提交
20
#include "common/type_define.h"
N
nhzlx 已提交
21
#include "common/types.h"
朔-望's avatar
朔-望 已提交
22 23 24 25
#include "framework/lod_tensor.h"
#include "framework/scope.h"
#include "framework/tensor.h"
#include "framework/variable.h"
Z
zhangyang 已提交
26
#ifdef PADDLE_MOBILE_FPGA
H
hanbuhe 已提交
27
#include "fpga/api.h"
Z
zhangyang 已提交
28
#endif
朔-望's avatar
朔-望 已提交
29 30

namespace paddle_mobile {
朔-望's avatar
朔-望 已提交
31 32
namespace operators {

W
wangliu 已提交
33 34 35 36 37 38 39
using framework::Attribute;
using framework::AttributeMap;
using framework::LoDTensor;
using framework::Scope;
using framework::Tensor;
using std::string;
using std::vector;
朔-望's avatar
朔-望 已提交
40

N
nhzlx 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
template <typename Dtype>
struct DtypeTensorTrait {
  typedef void ptype;
  typedef void rtype;
};

template <>
struct DtypeTensorTrait<CPU> {
  // This is the type we obtained in variable.
  typedef framework::LoDTensor gtype;
  // This type will be the parent class type
  // or the same type.
  typedef framework::Tensor rtype;
};

template <>
struct DtypeTensorTrait<FPGA> {
  // This is the type we obtained in variable.
  typedef framework::LoDTensor gtype;
  // This type will be the parent class type
  // or the same type.
  typedef framework::Tensor rtype;
};

template <>
struct DtypeTensorTrait<GPU_MALI> {
  // This is the type we obtained in variable.
  typedef framework::LoDTensor gtype;
  // This type will be the parent class type
  // or the same type.
  typedef framework::Tensor rtype;
};

L
liuruilong 已提交
74
class OpParam {
朔-望's avatar
朔-望 已提交
75
 protected:
76 77 78 79 80
  template <typename T>
  static T *InputAlphaFrom(const VariableNameMap &inputs, const Scope &scope) {
    return GetVarValue<T>("Alpha", inputs, scope);
  }

81 82 83 84 85 86 87 88 89 90 91 92 93 94
  template <typename T>
  static T *InputFrom(const VariableNameMap &inputs, const Scope &scope) {
    return GetVarValue<T>("Input", inputs, scope);
  }

  template <typename T>
  static T *InputXFrom(const VariableNameMap &inputs, const Scope &scope) {
    return GetVarValue<T>("X", inputs, scope);
  }

  template <typename T>
  static T *InputYFrom(const VariableNameMap &inputs, const Scope &scope) {
    return GetVarValue<T>("Y", inputs, scope);
  }
95 96 97 98
  template <typename T>
  static T *InputYFrom1(const VariableNameMap &inputs, const Scope &scope) {
    return GetVarValue1<T>("Y", inputs, scope);
  }
99

E
eclipsess 已提交
100 101 102 103 104
  template <typename T>
  static T *InputZFrom(const VariableNameMap &inputs, const Scope &scope) {
    return GetVarValue<T>("Z", inputs, scope);
  }

105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
  template <typename T>
  static T *InputBiasFrom(const VariableNameMap &inputs, const Scope &scope) {
    return GetVarValue<T>("Bias", inputs, scope);
  }
  template <typename T>
  static T *InputVarianceFrom(const VariableNameMap &inputs,
                              const Scope &scope) {
    return GetVarValue<T>("Variance", inputs, scope);
  }
  template <typename T>
  static T *InputMeanFrom(const VariableNameMap &inputs, const Scope &scope) {
    return GetVarValue<T>("Mean", inputs, scope);
  }
  template <typename T>
  static T *InputScaleFrom(const VariableNameMap &inputs, const Scope &scope) {
    return GetVarValue<T>("Scale", inputs, scope);
  }
E
eclipsess 已提交
122 123 124 125
  template <typename T>
  static T *InputImageFrom(const VariableNameMap &inputs, const Scope &scope) {
    return GetVarValue<T>("Image", inputs, scope);
  }
E
eclipsess 已提交
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
  template <typename T>
  static T *InputPriorBoxFrom(const VariableNameMap &inputs,
                              const Scope &scope) {
    return GetVarValue<T>("PriorBox", inputs, scope);
  }
  template <typename T>
  static T *InputPriorBoxVarFrom(const VariableNameMap &inputs,
                                 const Scope &scope) {
    return GetVarValue<T>("PriorBoxVar", inputs, scope);
  }
  // LoDTensor but now use Tensor
  template <typename T>
  static T *InputTargetBoxFrom(const VariableNameMap &inputs,
                               const Scope &scope) {
    return GetVarValue<T>("TargetBox", inputs, scope);
  }
142

E
eclipsess 已提交
143 144 145 146 147 148 149 150 151 152
  template <typename T>
  static T *InputBBoxesFrom(const VariableNameMap &inputs, const Scope &scope) {
    return GetVarValue<T>("BBoxes", inputs, scope);
  }

  template <typename T>
  static T *InputScoresFrom(const VariableNameMap &inputs, const Scope &scope) {
    return GetVarValue<T>("Scores", inputs, scope);
  }

E
eclipsess 已提交
153 154 155 156
  template <typename T>
  static T *InputShapeFrom(const VariableNameMap &inputs, const Scope &scope) {
    return GetVarValue<T>("Shape", inputs, scope);
  }
E
eclipsess 已提交
157

158
  template <typename T>
W
wangliu 已提交
159 160
  static vector<T *> InputMultiFrom(const VariableNameMap &inputs,
                                    const Scope &scope) {
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
    return GetMultiVarValue<T>("X", inputs, scope);
  }

  template <typename T>
  static T *OutputFrom(const VariableNameMap &outputs, const Scope &scope) {
    return GetVarValue<T>("Output", outputs, scope);
  }

  template <typename T>
  static T *OutFrom(const VariableNameMap &outputs, const Scope &scope) {
    return GetVarValue<T>("Out", outputs, scope);
  }

  template <typename T>
  static T *OutputYFrom(const VariableNameMap &outputs, const Scope &scope) {
    return GetVarValue<T>("Y", outputs, scope);
  }

E
eclipsess 已提交
179 180 181 182 183 184
  template <typename T>
  static T *OutputBoxesFrom(const VariableNameMap &outputs,
                            const Scope &scope) {
    return GetVarValue<T>("Boxes", outputs, scope);
  }

E
eclipsess 已提交
185 186 187 188 189
  template <typename T>
  static T *OutputBoxFrom(const VariableNameMap &outputs, const Scope &scope) {
    return GetVarValue<T>("OutputBox", outputs, scope);
  }

E
eclipsess 已提交
190 191 192 193 194 195
  template <typename T>
  static T *OutputVariancesFrom(const VariableNameMap &outputs,
                                const Scope &scope) {
    return GetVarValue<T>("Variances", outputs, scope);
  }

196 197 198 199 200 201 202 203 204 205 206
  template <typename T>
  static T *MidOutFrom(const VariableNameMap &outputs, const Scope &scope) {
    return GetVarValue<T>("MidOut", outputs, scope);
  }

  template <typename T>
  static T *FilterFrom(const VariableNameMap &inputs, const Scope &scope) {
    return GetVarValue<T>("Filter", inputs, scope);
  }

  template <typename T>
W
wangliu 已提交
207
  static const T GetAttr(const string &key, const AttributeMap &map) {
208 209 210 211
    return ((Attribute)map.at(key)).Get<T>();
  }

  template <typename T>
W
wangliu 已提交
212
  static T *GetVarValue(const string &key, const VariableNameMap &var_map,
213
                        const Scope &scope) {
W
wangliu 已提交
214 215
    PADDLE_MOBILE_ENFORCE(var_map.count(key) > 0,
                          "%s is not contained in var_map", key.c_str())
216 217 218 219 220 221
    auto var_vec = var_map.at(key);
    if (!var_vec.empty()) {
      auto var = scope.FindVar(var_vec[0]);
      return var->GetMutable<T>();
    } else {
      return nullptr;
朔-望's avatar
朔-望 已提交
222
    }
223
  }
224 225 226 227 228 229 230 231 232 233 234 235 236
  template <typename T>
  static T *GetVarValue1(const string &key, const VariableNameMap &var_map,
                         const Scope &scope) {
    PADDLE_MOBILE_ENFORCE(var_map.count(key) > 0,
                          "%s is not contained in var_map", key.c_str())
    auto var_vec = var_map.at(key);
    if (!var_vec.empty()) {
      auto var = scope.FindVar(var_vec[1]);
      return var->GetMutable<T>();
    } else {
      return nullptr;
    }
  }
朔-望's avatar
朔-望 已提交
237

238
  template <typename T>
W
wangliu 已提交
239 240 241
  static vector<T *> GetMultiVarValue(const string &key,
                                      const VariableNameMap &var_map,
                                      const Scope &scope) {
242 243
    auto var_vecs = var_map.at(key);
    assert(var_vecs.size() > 1);
W
wangliu 已提交
244
    vector<T *> var_res;
245 246 247
    for (auto &var_vec : var_vecs) {
      auto var = scope.FindVar(var_vec);
      var_res.push_back(var->GetMutable<T>());
朔-望's avatar
朔-望 已提交
248
    }
249 250
    return var_res;
  }
朔-望's avatar
朔-望 已提交
251 252
};

L
liuruilong 已提交
253
#ifdef CONV_OP
N
nhzlx 已提交
254
template <typename Dtype>
朔-望's avatar
朔-望 已提交
255
class ConvParam : OpParam {
N
nhzlx 已提交
256 257 258
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

朔-望's avatar
朔-望 已提交
259
 public:
260
  ConvParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
261
            const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
262 263 264
    filter_ = FilterFrom<GType>(inputs, scope);
    input_ = InputFrom<GType>(inputs, scope);
    output_ = OutputFrom<GType>(outputs, scope);
W
wangliu 已提交
265 266 267
    strides_ = GetAttr<vector<int>>("strides", attrs);
    paddings_ = GetAttr<vector<int>>("paddings", attrs);
    dilations_ = GetAttr<vector<int>>("dilations", attrs);
268 269
    groups = GetAttr<int>("groups", attrs);
  }
朔-望's avatar
朔-望 已提交
270

N
nhzlx 已提交
271
  const RType *Input() const { return input_; }
朔-望's avatar
朔-望 已提交
272

N
nhzlx 已提交
273
  RType *Filter() const { return filter_; }
朔-望's avatar
朔-望 已提交
274

N
nhzlx 已提交
275
  RType *Output() const { return output_; }
朔-望's avatar
朔-望 已提交
276

W
wangliu 已提交
277
  const vector<int> &Strides() const { return strides_; }
朔-望's avatar
朔-望 已提交
278

W
wangliu 已提交
279
  const vector<int> &Paddings() const { return paddings_; }
朔-望's avatar
朔-望 已提交
280

W
wangliu 已提交
281
  const vector<int> &Dilations() const { return dilations_; }
朔-望's avatar
朔-望 已提交
282

283
  const int &Groups() const { return groups; }
朔-望's avatar
朔-望 已提交
284

朔-望's avatar
朔-望 已提交
285
 private:
N
nhzlx 已提交
286 287 288
  RType *input_;
  RType *output_;
  RType *filter_;
W
wangliu 已提交
289 290 291
  vector<int> strides_;
  vector<int> paddings_;
  vector<int> dilations_;
292
  int groups;
朔-望's avatar
朔-望 已提交
293
};
N
nhzlx 已提交
294 295
template <typename Dtype>
Print &operator<<(Print &printer, const ConvParam<Dtype> &conv_param);
L
liuruilong 已提交
296
#endif
朔-望's avatar
朔-望 已提交
297

N
nhzlx 已提交
298
template <typename Dtype>
朔-望's avatar
朔-望 已提交
299
class ElementwiseAddParam : OpParam {
N
nhzlx 已提交
300 301 302
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

朔-望's avatar
朔-望 已提交
303
 public:
304
  ElementwiseAddParam(const VariableNameMap &inputs,
305 306
                      const VariableNameMap &outputs, const AttributeMap &attrs,
                      const Scope &scope) {
N
nhzlx 已提交
307 308 309
    input_x_ = InputXFrom<GType>(inputs, scope);
    input_y_ = InputYFrom<GType>(inputs, scope);
    out_ = OutFrom<GType>(outputs, scope);
310 311 312
    axis_ = GetAttr<int>("axis", attrs);
  }

N
nhzlx 已提交
313
  const RType *InputX() const { return input_x_; }
314

N
nhzlx 已提交
315
  const RType *InputY() const { return input_y_; }
316

N
nhzlx 已提交
317
  RType *Out() const { return out_; }
318 319 320

  const int &Axis() const { return axis_; }

朔-望's avatar
朔-望 已提交
321
 private:
N
nhzlx 已提交
322 323 324
  RType *input_x_;
  RType *input_y_;
  RType *out_;
325
  int axis_;
Z
zhangyang 已提交
326 327 328
#ifdef PADDLE_MOBILE_FPGA

 private:
H
hanbuhe 已提交
329
  fpga::EWAddArgs fpga_EW_add_args;
Z
zhangyang 已提交
330 331

 public:
H
hanbuhe 已提交
332 333
  const fpga::EWAddArgs &FpgaArgs() const { return fpga_EW_add_args; }
  void SetFpgaArgs(const fpga::EWAddArgs &args) { fpga_EW_add_args = args; }
Z
zhangyang 已提交
334
#endif
朔-望's avatar
朔-望 已提交
335 336
};

337
#ifdef FUSION_ELEMENTWISEADDRELU_OP
N
nhzlx 已提交
338 339
template <typename Dtype>
using ElementwiseAddReluParam = ElementwiseAddParam<Dtype>;
L
liuruilong 已提交
340 341 342
#endif

#ifdef MUL_OP
N
nhzlx 已提交
343
template <typename Dtype>
朔-望's avatar
朔-望 已提交
344
class MulParam : OpParam {
N
nhzlx 已提交
345 346 347
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

朔-望's avatar
朔-望 已提交
348
 public:
349
  MulParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
350
           const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
351 352 353
    input_x_ = InputXFrom<GType>(inputs, scope);
    input_y_ = InputYFrom<GType>(inputs, scope);
    out_ = OutFrom<GType>(outputs, scope);
354 355 356
    x_num_col_dims_ = GetAttr<int>("x_num_col_dims", attrs);
    y_num_col_dims_ = GetAttr<int>("y_num_col_dims", attrs);
  }
朔-望's avatar
朔-望 已提交
357

N
nhzlx 已提交
358
  const RType *InputX() const { return input_x_; }
朔-望's avatar
朔-望 已提交
359

N
nhzlx 已提交
360
  const RType *InputY() const { return input_y_; }
朔-望's avatar
朔-望 已提交
361

N
nhzlx 已提交
362
  RType *Out() const { return out_; }
朔-望's avatar
朔-望 已提交
363

364
  const int &XNumColDims() const { return x_num_col_dims_; }
朔-望's avatar
朔-望 已提交
365

366
  const int &YNumColDims() const { return y_num_col_dims_; }
朔-望's avatar
朔-望 已提交
367

朔-望's avatar
朔-望 已提交
368
 private:
N
nhzlx 已提交
369 370 371
  RType *input_x_;
  RType *input_y_;
  RType *out_;
372 373
  int x_num_col_dims_;
  int y_num_col_dims_;
朔-望's avatar
朔-望 已提交
374
};
L
liuruilong 已提交
375
#endif
朔-望's avatar
朔-望 已提交
376

L
liuruilong 已提交
377
#ifdef CONCAT_OP
N
nhzlx 已提交
378
template <typename Dtype>
朔-望's avatar
朔-望 已提交
379
class ConcatParam : public OpParam {
N
nhzlx 已提交
380 381 382
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

朔-望's avatar
朔-望 已提交
383
 public:
384
  ConcatParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
385
              const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
386 387
    inputs_ = InputMultiFrom<GType>(inputs, scope);
    out_ = OutFrom<GType>(outputs, scope);
388 389
    axis_ = GetAttr<int>("axis", attrs);
  }
朔-望's avatar
朔-望 已提交
390

N
nhzlx 已提交
391
  vector<GType *> Inputs() const { return inputs_; }
朔-望's avatar
朔-望 已提交
392

N
nhzlx 已提交
393
  RType *Out() const { return out_; }
朔-望's avatar
朔-望 已提交
394

395
  const int &Axis() const { return axis_; }
朔-望's avatar
朔-望 已提交
396

朔-望's avatar
朔-望 已提交
397
 private:
N
nhzlx 已提交
398 399
  vector<GType *> inputs_;
  RType *out_;
400
  int axis_;
朔-望's avatar
朔-望 已提交
401
};
L
liuruilong 已提交
402
#endif
朔-望's avatar
朔-望 已提交
403

L
liuruilong 已提交
404
#ifdef LRN_OP
N
nhzlx 已提交
405
template <typename Dtype>
E
eclipsess 已提交
406
class LrnParam : public OpParam {
N
nhzlx 已提交
407 408 409
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

朔-望's avatar
朔-望 已提交
410
 public:
411
  LrnParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
412
           const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
413 414 415
    input_x_ = InputXFrom<GType>(inputs, scope);
    out_ = OutFrom<GType>(outputs, scope);
    mid_out_ = MidOutFrom<GType>(outputs, scope);
416 417 418 419
    n_ = GetAttr<int>("n", attrs);
    alpha_ = GetAttr<float>("alpha", attrs);
    beta_ = GetAttr<float>("beta", attrs);
    k_ = GetAttr<float>("k", attrs);
W
wangliu 已提交
420
    data_format_ = GetAttr<string>("data_format", attrs);
421
  }
E
eclipsess 已提交
422

N
nhzlx 已提交
423
  const RType *InputX() const { return input_x_; }
E
eclipsess 已提交
424

N
nhzlx 已提交
425
  RType *Out() const { return out_; }
E
eclipsess 已提交
426

N
nhzlx 已提交
427
  RType *MidOut() const { return mid_out_; }
E
eclipsess 已提交
428

429
  const int &N() const { return n_; }
E
eclipsess 已提交
430

431
  const float &Alpha() const { return alpha_; }
E
eclipsess 已提交
432

433
  const float &Beta() const { return beta_; }
E
eclipsess 已提交
434

435
  const float &K() const { return k_; }
E
eclipsess 已提交
436

W
wangliu 已提交
437
  const string &DataFormat() const { return data_format_; }
E
eclipsess 已提交
438

朔-望's avatar
朔-望 已提交
439
 private:
N
nhzlx 已提交
440 441 442
  RType *input_x_;
  RType *out_;
  RType *mid_out_;
443 444 445 446
  int n_;
  float alpha_;
  float beta_;
  float k_;
W
wangliu 已提交
447
  string data_format_;
E
eclipsess 已提交
448
};
L
liuruilong 已提交
449 450 451
#endif

#ifdef BATCHNORM_OP
N
nhzlx 已提交
452
template <typename Dtype>
E
eclipsess 已提交
453
class BatchNormParam : OpParam {
N
nhzlx 已提交
454 455 456
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

朔-望's avatar
朔-望 已提交
457
 public:
458
  BatchNormParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
459
                 const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
460 461 462 463 464 465
    input_x_ = InputXFrom<GType>(inputs, scope);
    output_y_ = OutputYFrom<GType>(outputs, scope);
    input_bias_ = InputBiasFrom<GType>(inputs, scope);
    input_mean_ = InputMeanFrom<GType>(inputs, scope);
    input_scale_ = InputScaleFrom<GType>(inputs, scope);
    input_variance_ = InputVarianceFrom<GType>(inputs, scope);
466 467
    epsilon_ = GetAttr<float>("epsilon", attrs);
    momentum_ = GetAttr<float>("momentum", attrs);
L
liuruilong 已提交
468
    //    is_test_ = GetAttr<bool>("is_test", attrs);
469
  }
E
eclipsess 已提交
470

N
nhzlx 已提交
471
  const RType *InputX() const { return input_x_; }
E
eclipsess 已提交
472

N
nhzlx 已提交
473
  RType *OutputY() const { return output_y_; }
E
eclipsess 已提交
474

N
nhzlx 已提交
475
  const RType *InputBias() const { return input_bias_; }
E
eclipsess 已提交
476

N
nhzlx 已提交
477
  const RType *InputMean() const { return input_mean_; }
E
eclipsess 已提交
478

N
nhzlx 已提交
479
  const RType *InputScale() const { return input_scale_; }
E
eclipsess 已提交
480

N
nhzlx 已提交
481
  const RType *InputVariance() const { return input_variance_; }
E
eclipsess 已提交
482

483
  const float &Epsilon() const { return epsilon_; }
E
eclipsess 已提交
484

485
  const float &Momentum() const { return momentum_; }
E
eclipsess 已提交
486

487
  const bool &IsTest() const { return is_test_; }
E
eclipsess 已提交
488

W
wangliu 已提交
489
  const string &DataFormat() const { return data_format_; }
E
eclipsess 已提交
490

朔-望's avatar
朔-望 已提交
491
 private:
N
nhzlx 已提交
492 493 494 495 496 497
  RType *input_x_;
  RType *output_y_;
  RType *input_bias_;
  RType *input_mean_;
  RType *input_scale_;
  RType *input_variance_;
498 499 500
  float epsilon_;
  float momentum_;
  bool is_test_;
W
wangliu 已提交
501
  string data_format_;
E
eclipsess 已提交
502
};
L
liuruilong 已提交
503 504 505
#endif

#ifdef POOL_OP
N
nhzlx 已提交
506
template <typename Dtype>
507
class PoolParam : public OpParam {
N
nhzlx 已提交
508 509 510
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

朔-望's avatar
朔-望 已提交
511
 public:
512
  PoolParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
513
            const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
514
    input_ = InputXFrom<GType>(inputs, scope);
515

N
nhzlx 已提交
516
    output_ = OutFrom<GType>(outputs, scope);
W
wangliu 已提交
517 518 519 520
    pooling_type_ = GetAttr<string>("pooling_type", attrs);
    ksize_ = GetAttr<vector<int>>("ksize", attrs);
    strides_ = GetAttr<vector<int>>("strides", attrs);
    paddings_ = GetAttr<vector<int>>("paddings", attrs);
521
    ceil_mode_ = GetAttr<bool>("ceil_mode", attrs);
522
    global_pooling_ = GetAttr<bool>("global_pooling", attrs);
523
  }
524

N
nhzlx 已提交
525
  const RType *Input() const { return input_; }
526

N
nhzlx 已提交
527
  RType *Output() const { return output_; }
528

W
wangliu 已提交
529
  const string &PoolingType() const { return pooling_type_; }
530

W
wangliu 已提交
531
  const vector<int> &Ksize() const { return ksize_; }
532

W
wangliu 已提交
533
  const vector<int> &Strides() const { return strides_; }
534

W
wangliu 已提交
535
  const vector<int> &Paddings() const { return paddings_; }
536

537
  bool isCeilMode() const { return ceil_mode_; }
538

Z
zhangyang 已提交
539
  bool isGlobalPooling() const { return global_pooling_; }
540

朔-望's avatar
朔-望 已提交
541
 private:
N
nhzlx 已提交
542 543
  RType *input_;
  RType *output_;
W
wangliu 已提交
544 545 546 547
  string pooling_type_;
  vector<int> ksize_;
  vector<int> strides_;
  vector<int> paddings_;
548
  bool ceil_mode_;
549
  bool global_pooling_ = false;
Z
zhangyang 已提交
550
#ifdef PADDLE_MOBILE_FPGA
551 552

 private:
H
hanbuhe 已提交
553
  fpga::PoolingArgs fpga_pool_args;
Z
zhangyang 已提交
554 555

 public:
H
hanbuhe 已提交
556 557
  const fpga::PoolingArgs &FpgaArgs() const { return fpga_pool_args; }
  void SetFpgaArgs(const fpga::PoolingArgs &args) { fpga_pool_args = args; }
Z
zhangyang 已提交
558
#endif
559
};
L
liuruilong 已提交
560 561 562
#endif

#ifdef PRIORBOX_OP
N
nhzlx 已提交
563
template <typename Dtype>
E
eclipsess 已提交
564
class PriorBoxParam : public OpParam {
N
nhzlx 已提交
565 566 567
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

E
eclipsess 已提交
568 569
 public:
  PriorBoxParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
570
                const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
571 572 573 574
    input_ = InputFrom<GType>(inputs, scope);
    input_image_ = InputImageFrom<GType>(inputs, scope);
    output_boxes_ = OutputBoxesFrom<GType>(outputs, scope);
    output_variances_ = OutputVariancesFrom<GType>(outputs, scope);
W
wangliu 已提交
575 576 577 578
    min_sizes_ = GetAttr<vector<float>>("min_sizes", attrs);
    max_sizes_ = GetAttr<vector<float>>("max_sizes", attrs);
    aspect_ratios_ = GetAttr<vector<float>>("aspect_ratios", attrs);
    variances_ = GetAttr<vector<float>>("variances", attrs);
E
eclipsess 已提交
579 580 581 582 583 584
    flip_ = GetAttr<bool>("flip", attrs);
    clip_ = GetAttr<bool>("clip", attrs);
    step_w_ = GetAttr<float>("step_w", attrs);
    step_h_ = GetAttr<float>("step_h", attrs);
    offset_ = GetAttr<float>("offset", attrs);
  }
N
nhzlx 已提交
585
  const RType *Input() const { return input_; }
E
eclipsess 已提交
586

N
nhzlx 已提交
587
  const RType *InputImage() const { return input_image_; }
E
eclipsess 已提交
588

N
nhzlx 已提交
589
  RType *OutputBoxes() const { return output_boxes_; }
E
eclipsess 已提交
590

N
nhzlx 已提交
591
  RType *OutputVariances() const { return output_variances_; }
E
eclipsess 已提交
592

W
wangliu 已提交
593
  const vector<float> &MinSizes() const { return min_sizes_; }
E
eclipsess 已提交
594

W
wangliu 已提交
595
  const vector<float> &MaxSizes() const { return max_sizes_; }
E
eclipsess 已提交
596

W
wangliu 已提交
597
  const vector<float> &AspectRatios() const { return aspect_ratios_; }
E
eclipsess 已提交
598

W
wangliu 已提交
599
  const vector<float> &Variances() const { return variances_; }
E
eclipsess 已提交
600 601 602 603 604 605 606 607 608 609 610 611

  const bool &Flip() const { return flip_; }

  const bool &Clip() const { return clip_; }

  const float &StepW() const { return step_w_; }

  const float &StepH() const { return step_h_; }

  const float &Offset() const { return offset_; }

 private:
N
nhzlx 已提交
612 613 614 615
  RType *input_;
  RType *input_image_;
  RType *output_boxes_;
  RType *output_variances_;
W
wangliu 已提交
616 617 618 619
  vector<float> min_sizes_;
  vector<float> max_sizes_;
  vector<float> aspect_ratios_;
  vector<float> variances_;
E
eclipsess 已提交
620 621 622 623 624 625
  bool flip_;
  bool clip_;
  float step_w_;
  float step_h_;
  float offset_;
};
L
liuruilong 已提交
626
#endif
E
eclipsess 已提交
627

L
liuruilong 已提交
628
#ifdef BOXCODER_OP
N
nhzlx 已提交
629
template <typename Dtype>
E
eclipsess 已提交
630
class BoxCoderParam : public OpParam {
N
nhzlx 已提交
631 632 633
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

E
eclipsess 已提交
634 635
 public:
  BoxCoderParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
636
                const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
637 638 639 640
    input_priorbox_ = InputPriorBoxFrom<GType>(inputs, scope);
    input_priorboxvar_ = InputPriorBoxVarFrom<GType>(inputs, scope);
    input_targetbox_ = InputTargetBoxFrom<GType>(inputs, scope);
    output_box_ = OutputBoxFrom<GType>(outputs, scope);
E
eclipsess 已提交
641 642
    code_type_ = GetAttr<std::string>("code_type", attrs);
  }
N
nhzlx 已提交
643
  const RType *InputPriorBox() const { return input_priorbox_; }
E
eclipsess 已提交
644

N
nhzlx 已提交
645
  const RType *InputPriorBoxVar() const { return input_priorboxvar_; }
E
eclipsess 已提交
646

N
nhzlx 已提交
647
  const RType *InputTargetBox() const { return input_targetbox_; }
E
eclipsess 已提交
648

N
nhzlx 已提交
649
  RType *OutputBox() const { return output_box_; }
E
eclipsess 已提交
650 651 652 653

  const std::string &CodeType() const { return code_type_; }

 private:
N
nhzlx 已提交
654 655 656 657
  RType *input_priorbox_;
  RType *input_priorboxvar_;
  RType *input_targetbox_;
  RType *output_box_;
E
eclipsess 已提交
658 659
  std::string code_type_;
};
L
liuruilong 已提交
660
#endif
W
wangliu 已提交
661

L
liuruilong 已提交
662
#ifdef SOFTMAX_OP
N
nhzlx 已提交
663
template <typename Dtype>
W
wangliu 已提交
664
class SoftmaxParam : public OpParam {
N
nhzlx 已提交
665 666 667
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

W
wangliu 已提交
668 669
 public:
  SoftmaxParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
670
               const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
671 672
    input_x_ = InputXFrom<GType>(inputs, scope);
    out_ = OutFrom<GType>(outputs, scope);
W
wangliu 已提交
673
  }
N
nhzlx 已提交
674 675
  const RType *InputX() const { return input_x_; }
  RType *Out() const { return out_; }
W
wangliu 已提交
676 677

 private:
N
nhzlx 已提交
678 679
  RType *input_x_;
  RType *out_;
H
hanbuhe 已提交
680 681 682 683

#ifdef PADDLE_MOBILE_FPGA

 private:
N
nhzlx 已提交
684
  std::shared_ptr<RType> float_input_x_;
H
hanbuhe 已提交
685 686 687
  fpga::BypassArgs fpga_bypass_args;

 public:
N
nhzlx 已提交
688
  RType *FloatInput() {
H
hanbuhe 已提交
689 690 691 692 693 694
    return float_input_x_ == nullptr ? input_x_ : float_input_x_.get();
  }
  void SetFloatInput(Tensor *input) { float_input_x_.reset(input); }
  const fpga::BypassArgs &FpgaArgs() const { return fpga_bypass_args; }
  void SetFpgaArgs(const fpga::BypassArgs &args) { fpga_bypass_args = args; }
#endif
W
wangliu 已提交
695
};
L
liuruilong 已提交
696
#endif
W
wangliu 已提交
697

L
liuruilong 已提交
698
#ifdef SIGMOID_OP
N
nhzlx 已提交
699
template <typename Dtype>
W
wangliu 已提交
700
class SigmoidParam : public OpParam {
N
nhzlx 已提交
701 702 703
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

W
wangliu 已提交
704 705
 public:
  SigmoidParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
706
               const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
707 708
    input_x_ = InputXFrom<GType>(inputs, scope);
    out_ = OutFrom<GType>(outputs, scope);
W
wangliu 已提交
709
  }
N
nhzlx 已提交
710 711
  const RType *InputX() const { return input_x_; }
  RType *Out() const { return out_; }
W
wangliu 已提交
712 713

 private:
N
nhzlx 已提交
714 715
  RType *input_x_;
  RType *out_;
W
wangliu 已提交
716
};
L
liuruilong 已提交
717 718 719
#endif

#ifdef MULTICLASSNMS_OP
N
nhzlx 已提交
720
template <typename Dtype>
E
eclipsess 已提交
721
class MultiClassNMSParam : public OpParam {
N
nhzlx 已提交
722 723 724
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

E
eclipsess 已提交
725 726 727 728
 public:
  MultiClassNMSParam(const VariableNameMap &inputs,
                     const VariableNameMap &outputs, const AttributeMap &attrs,
                     const Scope &scope) {
N
nhzlx 已提交
729 730 731
    input_bboxes_ = InputBBoxesFrom<GType>(inputs, scope);
    input_scores_ = InputScoresFrom<GType>(inputs, scope);
    out_ = OutFrom<GType>(outputs, scope);
E
eclipsess 已提交
732 733 734 735 736 737 738 739
    background_label_ = GetAttr<int>("background_label", attrs);
    nms_top_k_ = GetAttr<int>("nms_top_k", attrs);
    keep_top_k_ = GetAttr<int>("keep_top_k", attrs);
    nms_threshold_ = GetAttr<float>("nms_threshold", attrs);
    nms_eta_ = GetAttr<float>("nms_eta", attrs);
    score_threshold_ = GetAttr<float>("score_threshold", attrs);
  }

N
nhzlx 已提交
740
  const RType *InputBBoxes() const { return input_bboxes_; }
E
eclipsess 已提交
741

N
nhzlx 已提交
742
  const RType *InputScores() const { return input_scores_; }
E
eclipsess 已提交
743

N
nhzlx 已提交
744
  RType *Out() const { return out_; }
E
eclipsess 已提交
745 746 747 748 749 750 751 752 753 754 755 756 757 758

  const int &BackGroundLabel() const { return background_label_; }

  const int &NMSTopK() const { return nms_top_k_; }

  const int &KeepTopK() const { return keep_top_k_; }

  const float &NMSThreshold() const { return nms_threshold_; }

  const float &NMSEta() const { return nms_eta_; }

  const float &ScoreThreshold() const { return score_threshold_; }

 private:
N
nhzlx 已提交
759 760 761
  RType *input_bboxes_;
  RType *input_scores_;
  RType *out_;
E
eclipsess 已提交
762 763 764 765 766 767 768
  int background_label_;
  int nms_top_k_;
  int keep_top_k_;
  float nms_threshold_;
  float nms_eta_;
  float score_threshold_;
};
L
liuruilong 已提交
769
#endif
W
wangliu 已提交
770

N
nhzlx 已提交
771
template <typename Dtype>
L
liuruilong 已提交
772
class FeedParam : public OpParam {
N
nhzlx 已提交
773 774 775
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

L
liuruilong 已提交
776 777
 public:
  FeedParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
L
liuruilong 已提交
778
            const AttributeMap &attrs, Scope *scope) {
N
nhzlx 已提交
779 780
    input_x_ = InputXFrom<GType>(inputs, *scope);
    out_ = OutFrom<GType>(outputs, *scope);
L
liuruilong 已提交
781
    auto var = scope->Var("batch_size");
W
wangliu 已提交
782
    batch_size = var->GetValue<int>();
L
liuruilong 已提交
783
  }
N
nhzlx 已提交
784 785
  const RType *InputX() const { return input_x_; }
  RType *Out() const { return out_; }
W
wangliu 已提交
786
  const int BatchSize() const { return batch_size; }
L
liuruilong 已提交
787

L
liuruilong 已提交
788
 private:
N
nhzlx 已提交
789 790
  RType *input_x_;
  RType *out_;
W
wangliu 已提交
791
  int batch_size;
L
liuruilong 已提交
792 793
};

N
nhzlx 已提交
794
template <typename Dtype>
L
liuruilong 已提交
795
class FetchParam : public OpParam {
N
nhzlx 已提交
796 797 798
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

L
liuruilong 已提交
799 800
 public:
  FetchParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
801
             const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
802 803
    input_x_ = InputXFrom<GType>(inputs, scope);
    out_ = OutFrom<GType>(outputs, scope);
L
liuruilong 已提交
804
  }
N
nhzlx 已提交
805 806
  const RType *InputX() const { return input_x_; }
  RType *Out() const { return out_; }
L
liuruilong 已提交
807

L
liuruilong 已提交
808
 private:
N
nhzlx 已提交
809 810
  RType *input_x_;
  RType *out_;
L
liuruilong 已提交
811 812
};

L
liuruilong 已提交
813
#ifdef TRANSPOSE_OP
N
nhzlx 已提交
814
template <typename Dtype>
E
eclipsess 已提交
815
class TransposeParam : public OpParam {
N
nhzlx 已提交
816 817 818
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

E
eclipsess 已提交
819 820 821
 public:
  TransposeParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
                 const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
822 823
    input_x_ = InputXFrom<GType>(inputs, scope);
    out_ = OutFrom<GType>(outputs, scope);
E
eclipsess 已提交
824 825 826
    axis_ = GetAttr<vector<int>>("axis", attrs);
  }

N
nhzlx 已提交
827
  const RType *InputX() const { return input_x_; }
E
eclipsess 已提交
828

N
nhzlx 已提交
829
  RType *Out() const { return out_; }
E
eclipsess 已提交
830 831 832 833

  const vector<int> &Axis() const { return axis_; }

 private:
N
nhzlx 已提交
834 835
  RType *input_x_;
  RType *out_;
E
eclipsess 已提交
836 837
  vector<int> axis_;
};
L
liuruilong 已提交
838
#endif
E
eclipsess 已提交
839

L
liuruilong 已提交
840
#ifdef RESHAPE_OP
N
nhzlx 已提交
841
template <typename Dtype>
E
eclipsess 已提交
842
class ReshapeParam : public OpParam {
N
nhzlx 已提交
843 844 845
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

E
eclipsess 已提交
846 847 848
 public:
  ReshapeParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
               const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
849 850 851
    input_x_ = InputXFrom<GType>(inputs, scope);
    input_shape_ = InputShapeFrom<GType>(inputs, scope);
    out_ = OutFrom<GType>(outputs, scope);
E
eclipsess 已提交
852 853 854 855
    shape_ = GetAttr<vector<int>>("shape", attrs);
    inplace_ = GetAttr<bool>("inplace", attrs);
  }

N
nhzlx 已提交
856
  const RType *InputX() const { return input_x_; }
E
eclipsess 已提交
857

N
nhzlx 已提交
858
  const RType *InputShape() const { return input_shape_; }
E
eclipsess 已提交
859

N
nhzlx 已提交
860
  RType *Out() const { return out_; }
E
eclipsess 已提交
861 862 863 864 865 866

  const vector<int> &Shape() const { return shape_; }

  const bool &Inplace() const { return inplace_; }

 private:
N
nhzlx 已提交
867 868 869
  RType *input_x_;
  RType *input_shape_;
  RType *out_;
E
eclipsess 已提交
870 871 872
  vector<int> shape_;
  bool inplace_;
};
L
liuruilong 已提交
873
#endif
E
eclipsess 已提交
874

T
Tian 已提交
875
#ifdef SCALE_OP
N
nhzlx 已提交
876
template <typename Dtype>
I
itminner 已提交
877
class ScaleParam : public OpParam {
N
nhzlx 已提交
878 879 880
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

I
itminner 已提交
881 882 883
 public:
  ScaleParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
             const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
884 885 886
    input_x_ = InputXFrom<GType>(inputs, scope);
    input_bias_ = InputBiasFrom<GType>(inputs, scope);
    out_ = OutFrom<GType>(outputs, scope);
I
itminner 已提交
887 888 889 890 891 892
    inplace_ = GetAttr<bool>("inplace", attrs);
    has_bias_ = GetAttr<bool>("has_bias", attrs);
    scales_ = GetAttr<vector<float>>("scales", attrs);
    biases_ = GetAttr<vector<float>>("biases", attrs);
  }

N
nhzlx 已提交
893
  const RType *InputX() const { return input_x_; }
I
itminner 已提交
894

N
nhzlx 已提交
895
  const RType *InputBias() const { return input_bias_; }
I
itminner 已提交
896

N
nhzlx 已提交
897
  RType *Out() const { return out_; }
I
itminner 已提交
898 899 900 901 902 903 904 905 906 907

  const bool &Inplace() const { return inplace_; }

  const bool &HasBias() const { return has_bias_; }

  const vector<float> &Scales() const { return scales_; }

  const vector<float> &Biases() const { return biases_; }

 private:
N
nhzlx 已提交
908 909 910
  RType *input_x_;
  RType *input_bias_;
  RType *out_;
I
itminner 已提交
911 912 913 914 915
  bool inplace_;
  bool has_bias_;
  vector<float> scales_;
  vector<float> biases_;
};
T
Tian 已提交
916 917 918
#endif

#ifdef SLICE_OP
N
nhzlx 已提交
919
template <typename Dtype>
I
itminner 已提交
920
class SliceParam : public OpParam {
N
nhzlx 已提交
921 922 923
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

I
itminner 已提交
924 925 926
 public:
  SliceParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
             const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
927 928 929
    input_x_ = InputXFrom<GType>(inputs, scope);
    input_shape_ = InputShapeFrom<GType>(inputs, scope);
    out_ = OutFrom<GType>(outputs, scope);
I
itminner 已提交
930 931 932 933 934
    axis_ = GetAttr<int>("axis", attrs);
    slice_points_ = GetAttr<vector<int>>("slice_points", attrs);
    inplace_ = GetAttr<bool>("inplace", attrs);
  }

N
nhzlx 已提交
935
  const RType *InputX() const { return input_x_; }
I
itminner 已提交
936

N
nhzlx 已提交
937
  const RType *InputShape() const { return input_shape_; }
I
itminner 已提交
938

N
nhzlx 已提交
939
  RType *Out() const { return out_; }
I
itminner 已提交
940 941 942 943 944 945 946 947

  const int &Axis() const { return axis_; }

  const vector<int> &SlicePoints() const { return slice_points_; }

  const bool &Inplace() const { return inplace_; }

 private:
N
nhzlx 已提交
948 949 950
  RType *input_x_;
  RType *input_shape_;
  RType *out_;
I
itminner 已提交
951 952 953 954
  int axis_;
  vector<int> slice_points_;
  bool inplace_;
};
T
Tian 已提交
955 956 957
#endif

#ifdef RESIZE_OP
N
nhzlx 已提交
958
template <typename Dtype>
T
Tian 已提交
959
class ResizeParam : public OpParam {
N
nhzlx 已提交
960 961 962
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

I
itminner 已提交
963 964 965
 public:
  ResizeParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
              const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
966 967 968
    input_x_ = InputXFrom<GType>(inputs, scope);
    input_shape_ = InputShapeFrom<GType>(inputs, scope);
    out_ = OutFrom<GType>(outputs, scope);
I
itminner 已提交
969 970 971 972 973 974
    is_pyramid_test_ = GetAttr<bool>("is_pyramid_test", attrs);
    height_ = GetAttr<int>("height", attrs);
    width_ = GetAttr<int>("width", attrs);
    out_height_scale_ = GetAttr<float>("out_height_scale", attrs);
    out_width_scale_ = GetAttr<float>("out_width_scale", attrs);
  }
T
Tian 已提交
975

N
nhzlx 已提交
976
  const RType *InputX() const { return input_x_; }
T
Tian 已提交
977

N
nhzlx 已提交
978
  const RType *InputShape() const { return input_shape_; }
T
Tian 已提交
979

N
nhzlx 已提交
980
  RType *Out() const { return out_; }
T
Tian 已提交
981

I
itminner 已提交
982
  const bool &IsPyramidTest() const { return is_pyramid_test_; }
T
Tian 已提交
983

I
itminner 已提交
984
  const int &Height() const { return height_; }
T
Tian 已提交
985

I
itminner 已提交
986
  const int &Width() const { return width_; }
T
Tian 已提交
987

I
itminner 已提交
988
  const float &OutHeightScale() const { return out_height_scale_; }
T
Tian 已提交
989

I
itminner 已提交
990
  const float &OutWidthScale() const { return out_width_scale_; }
T
Tian 已提交
991

I
itminner 已提交
992
 private:
N
nhzlx 已提交
993 994 995
  RType *input_x_;
  RType *input_shape_;
  RType *out_;
I
itminner 已提交
996 997 998 999 1000
  bool is_pyramid_test_;
  int height_;
  int width_;
  float out_height_scale_;
  float out_width_scale_;
T
Tian 已提交
1001 1002 1003
};
#endif

L
liuruilong 已提交
1004
#ifdef RELU_OP
L
liuruilong 已提交
1005 1006 1007
/*
 * @b op 层实例化好这个 param 传递给 kernel 层使用
 * */
N
nhzlx 已提交
1008
template <typename Dtype>
E
eclipsess 已提交
1009
class ReluParam : public OpParam {
N
nhzlx 已提交
1010 1011 1012
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

E
eclipsess 已提交
1013 1014 1015
 public:
  ReluParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
            const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
1016 1017
    input_x_ = InputXFrom<GType>(inputs, scope);
    out_ = OutFrom<GType>(outputs, scope);
E
eclipsess 已提交
1018 1019
  }

N
nhzlx 已提交
1020
  const RType *InputX() const { return input_x_; }
E
eclipsess 已提交
1021

N
nhzlx 已提交
1022
  RType *Out() const { return out_; }
E
eclipsess 已提交
1023 1024

 private:
N
nhzlx 已提交
1025 1026
  RType *input_x_;
  RType *out_;
E
eclipsess 已提交
1027
};
L
liuruilong 已提交
1028
#endif
E
eclipsess 已提交
1029

T
Tian 已提交
1030
#ifdef PRELU_OP
N
nhzlx 已提交
1031
template <typename Dtype>
T
Tian 已提交
1032
class PReluParam : public OpParam {
N
nhzlx 已提交
1033 1034 1035
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

I
itminner 已提交
1036 1037 1038
 public:
  PReluParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
             const AttributeMap &attrs, const Scope &scope) {
1039
    DLOG << "PReluParam inputs before";
N
nhzlx 已提交
1040
    input_x_ = InputXFrom<GType>(inputs, scope);
N
nhzlx 已提交
1041
    alpha_ = InputAlphaFrom<GType>(inputs, scope);
1042
    framework::DDim dims = alpha_->dims();
N
nhzlx 已提交
1043
    out_ = OutFrom<GType>(outputs, scope);
1044 1045
    mode_ = GetAttr<std::string>("mode", attrs);
    DLOG << "PReluParam mode after" << mode_;
I
itminner 已提交
1046
  }
N
nhzlx 已提交
1047
  const RType *InputX() const { return input_x_; }
N
nhzlx 已提交
1048
  const RType *InputAlpha() const { return alpha_; }
N
nhzlx 已提交
1049
  RType *Out() const { return out_; }
1050
  const std::string &Mode() const { return mode_; }
T
Tian 已提交
1051

I
itminner 已提交
1052
 private:
N
nhzlx 已提交
1053 1054
  RType *input_x_;
  RType *out_;
N
nhzlx 已提交
1055
  RType *alpha_;
1056
  std::string mode_;
T
Tian 已提交
1057 1058 1059
};
#endif

N
nhzlx 已提交
1060
template <typename Dtype>
L
liuruilong 已提交
1061
class FusionFcParam : public OpParam {
N
nhzlx 已提交
1062 1063 1064
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

E
eclipsess 已提交
1065
 public:
L
liuruilong 已提交
1066
  FusionFcParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
L
liuruilong 已提交
1067
                const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
1068 1069 1070 1071
    input_x_ = InputXFrom<GType>(inputs, scope);
    input_y_ = InputYFrom<GType>(inputs, scope);
    input_z_ = InputZFrom<GType>(inputs, scope);
    out_ = OutFrom<GType>(outputs, scope);
E
eclipsess 已提交
1072 1073 1074 1075
    x_num_col_dims_ = GetAttr<int>("x_num_col_dims", attrs);
    y_num_col_dims_ = GetAttr<int>("y_num_col_dims", attrs);
    axis_ = GetAttr<int>("axis", attrs);
  }
N
nhzlx 已提交
1076
  const RType *InputX() const { return input_x_; }
E
eclipsess 已提交
1077

1078
#ifdef PADDLE_MOBILE_FPGA
N
nhzlx 已提交
1079
  RType *InputY() const { return input_y_; }
1080
#else
N
nhzlx 已提交
1081
  const RType *InputY() const { return input_y_; }
1082
#endif
E
eclipsess 已提交
1083

N
nhzlx 已提交
1084
  const RType *InputZ() const { return input_z_; }
E
eclipsess 已提交
1085

N
nhzlx 已提交
1086
  RType *Out() const { return out_; }
E
eclipsess 已提交
1087 1088 1089 1090 1091 1092 1093 1094

  const int &XNumColDims() const { return x_num_col_dims_; }

  const int &YNumColDims() const { return y_num_col_dims_; }

  const int &Axis() const { return axis_; }

 private:
N
nhzlx 已提交
1095 1096 1097 1098
  RType *input_x_;
  RType *input_y_;
  RType *input_z_;
  RType *out_;
E
eclipsess 已提交
1099 1100 1101
  int x_num_col_dims_;
  int y_num_col_dims_;
  int axis_;
Z
zhangyang 已提交
1102 1103 1104
#ifdef PADDLE_MOBILE_FPGA

 private:
H
hanbuhe 已提交
1105
  fpga::ConvArgs fpga_conv_args;
Z
zhangyang 已提交
1106 1107

 public:
H
hanbuhe 已提交
1108 1109
  const fpga::ConvArgs &FpgaArgs() const { return fpga_conv_args; }
  void SetFpgaArgs(const fpga::ConvArgs &args) { fpga_conv_args = args; }
Z
zhangyang 已提交
1110
#endif
E
eclipsess 已提交
1111
};
1112 1113

#ifdef FUSION_FCRELU_OP
N
nhzlx 已提交
1114 1115
template <typename DeviceType>
using FusionFcReluParam = FusionFcParam<DeviceType>;
L
liuruilong 已提交
1116
#endif
E
eclipsess 已提交
1117

N
nhzlx 已提交
1118
template <typename Dtype>
L
liuruilong 已提交
1119
class FusionConvAddParam : public OpParam {
N
nhzlx 已提交
1120 1121 1122
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

W
wangliu 已提交
1123
 public:
L
liuruilong 已提交
1124
  FusionConvAddParam(const VariableNameMap &inputs,
L
liuruilong 已提交
1125 1126
                     const VariableNameMap &outputs, const AttributeMap &attrs,
                     const Scope &scope) {
N
nhzlx 已提交
1127
    bias_ = InputYFrom<GType>(inputs, scope);
W
wangliu 已提交
1128
    axis_ = GetAttr<int>("axis", attrs);
N
nhzlx 已提交
1129 1130 1131
    filter_ = FilterFrom<GType>(inputs, scope);
    input_ = InputFrom<GType>(inputs, scope);
    output_ = OutFrom<GType>(outputs, scope);
W
wangliu 已提交
1132 1133 1134 1135 1136
    strides_ = GetAttr<vector<int>>("strides", attrs);
    paddings_ = GetAttr<vector<int>>("paddings", attrs);
    dilations_ = GetAttr<vector<int>>("dilations", attrs);
    groups = GetAttr<int>("groups", attrs);
  }
N
nhzlx 已提交
1137
  RType *Bias() const { return bias_; }
W
wangliu 已提交
1138 1139 1140

  const int &Axis() const { return axis_; }

N
nhzlx 已提交
1141
  const RType *Input() const { return input_; }
W
wangliu 已提交
1142

1143
#ifdef PADDLE_MOBILE_FPGA
N
nhzlx 已提交
1144
  RType *Filter() const { return filter_; }
1145
#else
N
nhzlx 已提交
1146
  const RType *Filter() const { return filter_; }
1147
#endif
W
wangliu 已提交
1148

N
nhzlx 已提交
1149
  RType *Output() const { return output_; }
W
wangliu 已提交
1150 1151 1152 1153 1154 1155 1156 1157 1158

  const vector<int> &Strides() const { return strides_; }

  const vector<int> &Paddings() const { return paddings_; }

  const vector<int> &Dilations() const { return dilations_; }

  const int &Groups() const { return groups; }

L
liuruilong 已提交
1159
 protected:
N
nhzlx 已提交
1160
  RType *bias_;
W
wangliu 已提交
1161
  int axis_;
N
nhzlx 已提交
1162 1163 1164
  RType *input_;
  RType *output_;
  RType *filter_;
W
wangliu 已提交
1165 1166 1167 1168
  vector<int> strides_;
  vector<int> paddings_;
  vector<int> dilations_;
  int groups;
Z
zhangyang 已提交
1169 1170 1171
#ifdef PADDLE_MOBILE_FPGA

 private:
H
hanbuhe 已提交
1172
  fpga::ConvArgs fpga_conv_args;
Z
zhangyang 已提交
1173 1174

 public:
H
hanbuhe 已提交
1175 1176
  const fpga::ConvArgs &FpgaArgs() const { return fpga_conv_args; }
  void SetFpgaArgs(const fpga::ConvArgs &args) { fpga_conv_args = args; }
Z
zhangyang 已提交
1177
#endif
W
wangliu 已提交
1178 1179
};

N
nhzlx 已提交
1180 1181
template <typename Dtype>
Print &operator<<(Print &printer, const FusionConvAddParam<Dtype> &conv_param);
W
wangliu 已提交
1182

Z
zhangyang 已提交
1183
#ifdef FUSION_CONVADDRELU_OP
N
nhzlx 已提交
1184 1185
template <typename DeviceType>
class FusionConvAddReluParam : public FusionConvAddParam<DeviceType> {
L
liuruilong 已提交
1186
 public:
L
liuruilong 已提交
1187
  FusionConvAddReluParam(const VariableNameMap &inputs,
L
liuruilong 已提交
1188 1189
                         const VariableNameMap &outputs,
                         const AttributeMap &attrs, const Scope &scope)
N
nhzlx 已提交
1190
      : FusionConvAddParam<DeviceType>(inputs, outputs, attrs, scope) {}
L
liuruilong 已提交
1191 1192 1193
};
#endif

1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235
#ifdef FUSION_CONVADDPRELU_OP
class FusionConvAddPReluParam : public FusionConvAddParam {
 public:
  FusionConvAddPReluParam(const VariableNameMap &inputs,
                          const VariableNameMap &outputs,
                          const AttributeMap &attrs, const Scope &scope)
      : FusionConvAddParam(inputs, outputs, attrs, scope) {
    alpha_ = InputAlphaFrom<LoDTensor>(inputs, scope);
    mode_ = GetAttr<std::string>("mode", attrs);
    framework::DDim dims = alpha_->dims();
  }
  const Tensor *InputAlpha() const { return alpha_; }
  const std::string &Mode() const { return mode_; }

 private:
  Tensor *alpha_;
  std::string mode_;
};
#endif
#ifdef FUSION_CONVADDADDPRELU_OP
class FusionConvAddAddPReluParam : public FusionConvAddParam {
 public:
  FusionConvAddAddPReluParam(const VariableNameMap &inputs,
                             const VariableNameMap &outputs,
                             const AttributeMap &attrs, const Scope &scope)
      : FusionConvAddParam(inputs, outputs, attrs, scope) {
    bias1_ = InputYFrom1<LoDTensor>(inputs, scope);
    alpha_ = InputAlphaFrom<LoDTensor>(inputs, scope);
    mode_ = GetAttr<std::string>("mode", attrs);
    framework::DDim dims = alpha_->dims();
  }
  const Tensor *InputAlpha() const { return alpha_; }
  const std::string &Mode() const { return mode_; }
  const Tensor *Bias1() const { return bias1_; }

 private:
  Tensor *alpha_;
  std::string mode_;
  Tensor *bias1_;
};
#endif

E
eclipsess 已提交
1236
#ifdef FUSION_CONVADDBNRELU_OP
N
nhzlx 已提交
1237
template <typename Dtype>
E
eclipsess 已提交
1238
class FusionConvAddBNReluParam : public OpParam {
N
nhzlx 已提交
1239 1240 1241
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

E
eclipsess 已提交
1242 1243 1244 1245
 public:
  FusionConvAddBNReluParam(const VariableNameMap &inputs,
                           const VariableNameMap &outputs,
                           const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
1246
    bias_ = InputYFrom<GType>(inputs, scope);
E
eclipsess 已提交
1247
    axis_ = GetAttr<int>("axis", attrs);
N
nhzlx 已提交
1248 1249 1250
    filter_ = FilterFrom<GType>(inputs, scope);
    input_ = InputFrom<GType>(inputs, scope);
    output_ = OutFrom<GType>(outputs, scope);
E
eclipsess 已提交
1251 1252 1253 1254
    strides_ = GetAttr<vector<int>>("strides", attrs);
    paddings_ = GetAttr<vector<int>>("paddings", attrs);
    dilations_ = GetAttr<vector<int>>("dilations", attrs);
    groups = GetAttr<int>("groups", attrs);
N
nhzlx 已提交
1255 1256 1257 1258
    input_bias_ = InputBiasFrom<GType>(inputs, scope);
    input_mean_ = InputMeanFrom<GType>(inputs, scope);
    input_scale_ = InputScaleFrom<GType>(inputs, scope);
    input_variance_ = InputVarianceFrom<GType>(inputs, scope);
E
eclipsess 已提交
1259 1260
    epsilon_ = GetAttr<float>("epsilon", attrs);
    momentum_ = GetAttr<float>("momentum", attrs);
L
liuruilong 已提交
1261
    //    is_test_ = GetAttr<bool>("is_test", attrs);
E
eclipsess 已提交
1262
  }
N
nhzlx 已提交
1263
  RType *Bias() const { return bias_; }
E
eclipsess 已提交
1264 1265 1266

  const int &Axis() const { return axis_; }

N
nhzlx 已提交
1267
  const RType *Input() const { return input_; }
E
eclipsess 已提交
1268

1269
#ifdef PADDLE_MOBILE_FPGA
N
nhzlx 已提交
1270
  RType *Filter() const { return filter_; }
1271
#else
N
nhzlx 已提交
1272
  const RType *Filter() const { return filter_; }
1273
#endif
E
eclipsess 已提交
1274

N
nhzlx 已提交
1275
  RType *Output() const { return output_; }
E
eclipsess 已提交
1276 1277 1278 1279 1280 1281 1282 1283 1284

  const vector<int> &Strides() const { return strides_; }

  const vector<int> &Paddings() const { return paddings_; }

  const vector<int> &Dilations() const { return dilations_; }

  const int &Groups() const { return groups; }

N
nhzlx 已提交
1285
  const RType *InputBias() const { return input_bias_; }
E
eclipsess 已提交
1286

N
nhzlx 已提交
1287
  const RType *InputMean() const { return input_mean_; }
E
eclipsess 已提交
1288

N
nhzlx 已提交
1289
  const RType *InputScale() const { return input_scale_; }
E
eclipsess 已提交
1290

N
nhzlx 已提交
1291
  const RType *InputVariance() const { return input_variance_; }
E
eclipsess 已提交
1292 1293 1294 1295 1296 1297 1298

  const float &Epsilon() const { return epsilon_; }

  const float &Momentum() const { return momentum_; }

  const bool &IsTest() const { return is_test_; }

N
nhzlx 已提交
1299
  void SetNewScale(RType *new_scale) { new_scale_ = new_scale; }
E
eclipsess 已提交
1300

N
nhzlx 已提交
1301
  void SetNewBias(RType *new_bias) { new_bias_ = new_bias; }
E
eclipsess 已提交
1302

N
nhzlx 已提交
1303
  const RType *NewScale() const { return new_scale_; }
E
eclipsess 已提交
1304

N
nhzlx 已提交
1305
  const RType *NewBias() const { return new_bias_; }
E
eclipsess 已提交
1306 1307

 protected:
N
nhzlx 已提交
1308
  RType *bias_;
E
eclipsess 已提交
1309
  int axis_;
N
nhzlx 已提交
1310 1311 1312
  RType *input_;
  RType *output_;
  RType *filter_;
E
eclipsess 已提交
1313 1314 1315 1316
  vector<int> strides_;
  vector<int> paddings_;
  vector<int> dilations_;
  int groups;
N
nhzlx 已提交
1317 1318 1319 1320
  RType *input_bias_;
  RType *input_mean_;
  RType *input_scale_;
  RType *input_variance_;
E
eclipsess 已提交
1321 1322 1323
  float epsilon_;
  float momentum_;
  bool is_test_;
N
nhzlx 已提交
1324 1325
  RType *new_bias_;
  RType *new_scale_;
Z
zhangyang 已提交
1326 1327 1328
#ifdef PADDLE_MOBILE_FPGA

 private:
H
hanbuhe 已提交
1329
  fpga::ConvArgs fpga_conv_args;
Z
zhangyang 已提交
1330 1331

 public:
H
hanbuhe 已提交
1332 1333
  const fpga::ConvArgs &FpgaArgs() const { return fpga_conv_args; }
  void SetFpgaArgs(const fpga::ConvArgs &args) { fpga_conv_args = args; }
Z
zhangyang 已提交
1334
#endif
E
eclipsess 已提交
1335
};
1336
#endif
E
eclipsess 已提交
1337

Z
zhangyang 已提交
1338
#ifdef FUSION_CONVBN_OP
N
nhzlx 已提交
1339
template <typename Dtype>
Z
zhangyang 已提交
1340
class FusionConvBNParam : public OpParam {
N
nhzlx 已提交
1341 1342 1343
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

Z
zhangyang 已提交
1344 1345 1346 1347
 public:
  FusionConvBNParam(const VariableNameMap &inputs,
                    const VariableNameMap &outputs, const AttributeMap &attrs,
                    const Scope &scope) {
N
nhzlx 已提交
1348 1349 1350
    filter_ = FilterFrom<GType>(inputs, scope);
    input_ = InputFrom<GType>(inputs, scope);
    output_y_ = OutputYFrom<GType>(outputs, scope);
Z
zhangyang 已提交
1351 1352 1353 1354
    strides_ = GetAttr<vector<int>>("strides", attrs);
    paddings_ = GetAttr<vector<int>>("paddings", attrs);
    dilations_ = GetAttr<vector<int>>("dilations", attrs);
    groups = GetAttr<int>("groups", attrs);
N
nhzlx 已提交
1355 1356 1357 1358
    input_bias_ = InputBiasFrom<GType>(inputs, scope);
    input_mean_ = InputMeanFrom<GType>(inputs, scope);
    input_scale_ = InputScaleFrom<GType>(inputs, scope);
    input_variance_ = InputVarianceFrom<GType>(inputs, scope);
Z
zhangyang 已提交
1359 1360 1361 1362 1363
    epsilon_ = GetAttr<float>("epsilon", attrs);
    momentum_ = GetAttr<float>("momentum", attrs);
    //    is_test_ = GetAttr<bool>("is_test", attrs);
  }

N
nhzlx 已提交
1364
  const RType *Input() const { return input_; }
Z
zhangyang 已提交
1365 1366

#ifdef PADDLE_MOBILE_FPGA
N
nhzlx 已提交
1367
  RType *Filter() const { return filter_; }
Z
zhangyang 已提交
1368
#else
N
nhzlx 已提交
1369
  const RType *Filter() const { return filter_; }
Z
zhangyang 已提交
1370
#endif
N
nhzlx 已提交
1371
  RType *Output() const { return output_y_; }
Z
zhangyang 已提交
1372 1373 1374 1375 1376 1377 1378 1379 1380

  const vector<int> &Strides() const { return strides_; }

  const vector<int> &Paddings() const { return paddings_; }

  const vector<int> &Dilations() const { return dilations_; }

  const int &Groups() const { return groups; }

N
nhzlx 已提交
1381
  const RType *InputBias() const { return input_bias_; }
Z
zhangyang 已提交
1382

N
nhzlx 已提交
1383
  const RType *InputMean() const { return input_mean_; }
Z
zhangyang 已提交
1384

N
nhzlx 已提交
1385
  const RType *InputScale() const { return input_scale_; }
Z
zhangyang 已提交
1386

N
nhzlx 已提交
1387
  const RType *InputVariance() const { return input_variance_; }
Z
zhangyang 已提交
1388 1389 1390 1391 1392 1393 1394

  const float &Epsilon() const { return epsilon_; }

  const float &Momentum() const { return momentum_; }

  const bool &IsTest() const { return is_test_; }

N
nhzlx 已提交
1395
  void SetNewScale(RType *new_scale) { new_scale_ = new_scale; }
Z
zhangyang 已提交
1396

N
nhzlx 已提交
1397
  void SetNewBias(RType *new_bias) { new_bias_ = new_bias; }
Z
zhangyang 已提交
1398

N
nhzlx 已提交
1399
  const RType *NewScale() const { return new_scale_; }
Z
zhangyang 已提交
1400

N
nhzlx 已提交
1401
  const RType *NewBias() const { return new_bias_; }
Z
zhangyang 已提交
1402 1403

 protected:
N
nhzlx 已提交
1404 1405 1406
  RType *input_;
  RType *output_y_;
  RType *filter_;
Z
zhangyang 已提交
1407 1408 1409 1410
  vector<int> strides_;
  vector<int> paddings_;
  vector<int> dilations_;
  int groups;
N
nhzlx 已提交
1411 1412 1413 1414
  RType *input_bias_;
  RType *input_mean_;
  RType *input_scale_;
  RType *input_variance_;
Z
zhangyang 已提交
1415 1416 1417
  float epsilon_;
  float momentum_;
  bool is_test_;
N
nhzlx 已提交
1418 1419
  RType *new_bias_;
  RType *new_scale_;
Z
zhangyang 已提交
1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431
#ifdef PADDLE_MOBILE_FPGA

 private:
  fpga::ConvArgs fpga_conv_args;

 public:
  const fpga::ConvArgs &FpgaArgs() const { return fpga_conv_args; }
  void SetFpgaArgs(const fpga::ConvArgs &args) { fpga_conv_args = args; }
#endif
};
#endif

1432
#ifdef FUSION_CONVADDBN_OP
N
nhzlx 已提交
1433
template <typename Dtype>
1434
class FusionConvAddBNParam : public OpParam {
N
nhzlx 已提交
1435 1436 1437
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

1438 1439 1440 1441
 public:
  FusionConvAddBNParam(const VariableNameMap &inputs,
                       const VariableNameMap &outputs,
                       const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
1442
    bias_ = InputYFrom<GType>(inputs, scope);
1443
    axis_ = GetAttr<int>("axis", attrs);
N
nhzlx 已提交
1444 1445 1446
    filter_ = FilterFrom<GType>(inputs, scope);
    input_ = InputFrom<GType>(inputs, scope);
    output_y_ = OutputYFrom<GType>(outputs, scope);
1447 1448 1449 1450
    strides_ = GetAttr<vector<int>>("strides", attrs);
    paddings_ = GetAttr<vector<int>>("paddings", attrs);
    dilations_ = GetAttr<vector<int>>("dilations", attrs);
    groups = GetAttr<int>("groups", attrs);
N
nhzlx 已提交
1451 1452 1453 1454
    input_bias_ = InputBiasFrom<GType>(inputs, scope);
    input_mean_ = InputMeanFrom<GType>(inputs, scope);
    input_scale_ = InputScaleFrom<GType>(inputs, scope);
    input_variance_ = InputVarianceFrom<GType>(inputs, scope);
1455 1456 1457 1458
    epsilon_ = GetAttr<float>("epsilon", attrs);
    momentum_ = GetAttr<float>("momentum", attrs);
    //    is_test_ = GetAttr<bool>("is_test", attrs);
  }
N
nhzlx 已提交
1459
  RType *Bias() const { return bias_; }
1460 1461 1462

  const int &Axis() const { return axis_; }

N
nhzlx 已提交
1463
  const RType *Input() const { return input_; }
1464

1465
#ifdef PADDLE_MOBILE_FPGA
N
nhzlx 已提交
1466
  RType *Filter() const { return filter_; }
1467
#else
N
nhzlx 已提交
1468
  const RType *Filter() const { return filter_; }
1469
#endif
N
nhzlx 已提交
1470
  RType *Output() const { return output_y_; }
1471 1472 1473 1474 1475 1476 1477 1478 1479

  const vector<int> &Strides() const { return strides_; }

  const vector<int> &Paddings() const { return paddings_; }

  const vector<int> &Dilations() const { return dilations_; }

  const int &Groups() const { return groups; }

N
nhzlx 已提交
1480
  const RType *InputBias() const { return input_bias_; }
1481

N
nhzlx 已提交
1482
  const RType *InputMean() const { return input_mean_; }
1483

N
nhzlx 已提交
1484
  const RType *InputScale() const { return input_scale_; }
1485

N
nhzlx 已提交
1486
  const RType *InputVariance() const { return input_variance_; }
1487 1488 1489 1490 1491 1492 1493

  const float &Epsilon() const { return epsilon_; }

  const float &Momentum() const { return momentum_; }

  const bool &IsTest() const { return is_test_; }

N
nhzlx 已提交
1494
  void SetNewScale(RType *new_scale) { new_scale_ = new_scale; }
1495

N
nhzlx 已提交
1496
  void SetNewBias(RType *new_bias) { new_bias_ = new_bias; }
1497

N
nhzlx 已提交
1498
  const RType *NewScale() const { return new_scale_; }
1499

N
nhzlx 已提交
1500
  const RType *NewBias() const { return new_bias_; }
1501 1502

 protected:
N
nhzlx 已提交
1503
  RType *bias_;
1504
  int axis_;
N
nhzlx 已提交
1505 1506 1507
  RType *input_;
  RType *output_y_;
  RType *filter_;
1508 1509 1510 1511
  vector<int> strides_;
  vector<int> paddings_;
  vector<int> dilations_;
  int groups;
N
nhzlx 已提交
1512 1513 1514 1515
  RType *input_bias_;
  RType *input_mean_;
  RType *input_scale_;
  RType *input_variance_;
1516 1517 1518
  float epsilon_;
  float momentum_;
  bool is_test_;
N
nhzlx 已提交
1519 1520
  RType *new_bias_;
  RType *new_scale_;
Z
zhangyang 已提交
1521 1522 1523
#ifdef PADDLE_MOBILE_FPGA

 private:
H
hanbuhe 已提交
1524
  fpga::ConvArgs fpga_conv_args;
Z
zhangyang 已提交
1525 1526

 public:
H
hanbuhe 已提交
1527 1528
  const fpga::ConvArgs &FpgaArgs() const { return fpga_conv_args; }
  void SetFpgaArgs(const fpga::ConvArgs &args) { fpga_conv_args = args; }
Z
zhangyang 已提交
1529
#endif
1530
};
E
eclipsess 已提交
1531
#endif
Y
Yao,kun 已提交
1532

E
eclipsess 已提交
1533
#ifdef FUSION_DWCONVBNRELU_OP
N
nhzlx 已提交
1534
template <typename Dtype>
E
eclipsess 已提交
1535
class FusionDWConvBNReluParam : public OpParam {
N
nhzlx 已提交
1536 1537 1538
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

E
eclipsess 已提交
1539 1540 1541 1542
 public:
  FusionDWConvBNReluParam(const VariableNameMap &inputs,
                          const VariableNameMap &outputs,
                          const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
1543 1544 1545
    filter_ = FilterFrom<GType>(inputs, scope);
    input_ = InputFrom<GType>(inputs, scope);
    output_ = OutFrom<GType>(outputs, scope);
E
eclipsess 已提交
1546 1547 1548 1549
    strides_ = GetAttr<vector<int>>("strides", attrs);
    paddings_ = GetAttr<vector<int>>("paddings", attrs);
    dilations_ = GetAttr<vector<int>>("dilations", attrs);
    groups = GetAttr<int>("groups", attrs);
N
nhzlx 已提交
1550 1551 1552 1553
    input_bias_ = InputBiasFrom<GType>(inputs, scope);
    input_mean_ = InputMeanFrom<GType>(inputs, scope);
    input_scale_ = InputScaleFrom<GType>(inputs, scope);
    input_variance_ = InputVarianceFrom<GType>(inputs, scope);
E
eclipsess 已提交
1554 1555
    epsilon_ = GetAttr<float>("epsilon", attrs);
    momentum_ = GetAttr<float>("momentum", attrs);
1556
    //    is_test_ = GetAttr<bool>("is_test", attrs);
E
eclipsess 已提交
1557 1558
  }

N
nhzlx 已提交
1559
  const RType *Input() const { return input_; }
E
eclipsess 已提交
1560

N
nhzlx 已提交
1561
  const RType *Filter() const { return filter_; }
E
eclipsess 已提交
1562

N
nhzlx 已提交
1563
  RType *Output() const { return output_; }
E
eclipsess 已提交
1564 1565 1566 1567 1568 1569 1570 1571 1572

  const vector<int> &Strides() const { return strides_; }

  const vector<int> &Paddings() const { return paddings_; }

  const vector<int> &Dilations() const { return dilations_; }

  const int &Groups() const { return groups; }

N
nhzlx 已提交
1573
  const RType *InputBias() const { return input_bias_; }
E
eclipsess 已提交
1574

N
nhzlx 已提交
1575
  const RType *InputMean() const { return input_mean_; }
E
eclipsess 已提交
1576

N
nhzlx 已提交
1577
  const RType *InputScale() const { return input_scale_; }
E
eclipsess 已提交
1578

N
nhzlx 已提交
1579
  const RType *InputVariance() const { return input_variance_; }
E
eclipsess 已提交
1580 1581 1582 1583 1584 1585 1586

  const float &Epsilon() const { return epsilon_; }

  const float &Momentum() const { return momentum_; }

  const bool &IsTest() const { return is_test_; }

N
nhzlx 已提交
1587
  void SetNewScale(RType *new_scale) { new_scale_ = new_scale; }
E
eclipsess 已提交
1588

N
nhzlx 已提交
1589
  void SetNewBias(RType *new_bias) { new_bias_ = new_bias; }
E
eclipsess 已提交
1590

N
nhzlx 已提交
1591
  const RType *NewScale() const { return new_scale_; }
E
eclipsess 已提交
1592

N
nhzlx 已提交
1593
  const RType *NewBias() const { return new_bias_; }
E
eclipsess 已提交
1594 1595

 protected:
N
nhzlx 已提交
1596 1597 1598
  RType *input_;
  RType *output_;
  RType *filter_;
E
eclipsess 已提交
1599 1600 1601 1602
  vector<int> strides_;
  vector<int> paddings_;
  vector<int> dilations_;
  int groups;
N
nhzlx 已提交
1603 1604 1605 1606
  RType *input_bias_;
  RType *input_mean_;
  RType *input_scale_;
  RType *input_variance_;
E
eclipsess 已提交
1607 1608 1609
  float epsilon_;
  float momentum_;
  bool is_test_;
N
nhzlx 已提交
1610 1611
  RType *new_bias_;
  RType *new_scale_;
E
eclipsess 已提交
1612 1613 1614 1615
};

#endif

1616
#ifdef FUSION_CONVBNRELU_OP
N
nhzlx 已提交
1617
template <typename Dtype>
1618
class FusionConvBNReluParam : public OpParam {
N
nhzlx 已提交
1619 1620 1621
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

1622 1623 1624 1625
 public:
  FusionConvBNReluParam(const VariableNameMap &inputs,
                        const VariableNameMap &outputs,
                        const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
1626 1627 1628
    filter_ = FilterFrom<GType>(inputs, scope);
    input_ = InputFrom<GType>(inputs, scope);
    output_ = OutFrom<GType>(outputs, scope);
1629 1630 1631 1632 1633

    strides_ = GetAttr<vector<int>>("strides", attrs);
    paddings_ = GetAttr<vector<int>>("paddings", attrs);
    dilations_ = GetAttr<vector<int>>("dilations", attrs);
    groups = GetAttr<int>("groups", attrs);
N
nhzlx 已提交
1634 1635 1636 1637
    input_bias_ = InputBiasFrom<GType>(inputs, scope);
    input_mean_ = InputMeanFrom<GType>(inputs, scope);
    input_scale_ = InputScaleFrom<GType>(inputs, scope);
    input_variance_ = InputVarianceFrom<GType>(inputs, scope);
1638 1639 1640 1641 1642
    epsilon_ = GetAttr<float>("epsilon", attrs);
    momentum_ = GetAttr<float>("momentum", attrs);
    //    is_test_ = GetAttr<bool>("is_test", attrs);
  }

N
nhzlx 已提交
1643
  const RType *Input() const { return input_; }
1644

Z
zhangyang 已提交
1645
#ifdef PADDLE_MOBILE_FPGA
N
nhzlx 已提交
1646
  RType *Filter() const { return filter_; }
Z
zhangyang 已提交
1647
#else
N
nhzlx 已提交
1648
  const RType *Filter() const { return filter_; }
Z
zhangyang 已提交
1649
#endif
1650

N
nhzlx 已提交
1651
  RType *Output() const { return output_; }
1652 1653 1654 1655 1656 1657 1658 1659 1660

  const vector<int> &Strides() const { return strides_; }

  const vector<int> &Paddings() const { return paddings_; }

  const vector<int> &Dilations() const { return dilations_; }

  const int &Groups() const { return groups; }

N
nhzlx 已提交
1661
  const RType *InputBias() const { return input_bias_; }
1662

N
nhzlx 已提交
1663
  const RType *InputMean() const { return input_mean_; }
1664

N
nhzlx 已提交
1665
  const RType *InputScale() const { return input_scale_; }
1666

N
nhzlx 已提交
1667
  const RType *InputVariance() const { return input_variance_; }
1668 1669 1670 1671 1672 1673 1674

  const float &Epsilon() const { return epsilon_; }

  const float &Momentum() const { return momentum_; }

  const bool &IsTest() const { return is_test_; }

N
nhzlx 已提交
1675
  void SetNewScale(RType *new_scale) { new_scale_ = new_scale; }
1676

N
nhzlx 已提交
1677
  void SetNewBias(RType *new_bias) { new_bias_ = new_bias; }
1678

N
nhzlx 已提交
1679
  const RType *NewScale() const { return new_scale_; }
1680

N
nhzlx 已提交
1681
  const RType *NewBias() const { return new_bias_; }
1682 1683

 protected:
N
nhzlx 已提交
1684 1685 1686
  RType *input_;
  RType *output_;
  RType *filter_;
1687 1688 1689 1690
  vector<int> strides_;
  vector<int> paddings_;
  vector<int> dilations_;
  int groups;
N
nhzlx 已提交
1691 1692 1693 1694
  RType *input_bias_;
  RType *input_mean_;
  RType *input_scale_;
  RType *input_variance_;
1695 1696 1697
  float epsilon_;
  float momentum_;
  bool is_test_;
N
nhzlx 已提交
1698 1699
  RType *new_bias_;
  RType *new_scale_;
Z
zhangyang 已提交
1700 1701 1702 1703 1704 1705 1706 1707 1708
#ifdef PADDLE_MOBILE_FPGA

 private:
  fpga::ConvArgs fpga_conv_args;

 public:
  const fpga::ConvArgs &FpgaArgs() const { return fpga_conv_args; }
  void SetFpgaArgs(const fpga::ConvArgs &args) { fpga_conv_args = args; }
#endif
1709 1710 1711
};
#endif

Y
Yao,kun 已提交
1712
#ifdef IM2SEQUENCE_OP
N
nhzlx 已提交
1713
template <typename Dtype>
Y
Yao,kun 已提交
1714
class Im2SequenceParam : public OpParam {
N
nhzlx 已提交
1715 1716 1717
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

Y
Yao,kun 已提交
1718 1719 1720 1721
 public:
  Im2SequenceParam(const VariableNameMap &inputs,
                   const VariableNameMap &outputs, const AttributeMap &attrs,
                   const Scope &scope) {
N
nhzlx 已提交
1722 1723
    input_x_ = InputXFrom<GType>(inputs, scope);
    out_ = OutFrom<GType>(outputs, scope);
Y
Yao,kun 已提交
1724 1725 1726 1727 1728
    kernels_ = GetAttr<vector<int>>("kernels", attrs);
    strides_ = GetAttr<vector<int>>("strides", attrs);
    paddings_ = GetAttr<vector<int>>("paddings", attrs);
  }

N
nhzlx 已提交
1729
  const RType *Input() const { return input_x_; }
Y
Yao,kun 已提交
1730

N
nhzlx 已提交
1731
  RType *Output() const { return out_; }
Y
Yao,kun 已提交
1732 1733 1734 1735 1736 1737 1738 1739

  const vector<int> &Kernels() const { return kernels_; }

  const vector<int> &Strides() const { return strides_; }

  const vector<int> &Paddings() const { return paddings_; }

 private:
N
nhzlx 已提交
1740 1741
  RType *input_x_;
  RType *out_;
Y
Yao,kun 已提交
1742 1743 1744 1745
  vector<int> kernels_;
  vector<int> strides_;
  vector<int> paddings_;
};
1746
#endif
Y
Yao,kun 已提交
1747

1748
#ifdef DROPOUT_OP
N
nhzlx 已提交
1749
template <typename Dtype>
Y
Yao,kun 已提交
1750
class DropoutParam : public OpParam {
N
nhzlx 已提交
1751 1752 1753
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

Y
Yao,kun 已提交
1754 1755 1756
 public:
  DropoutParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
               const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
1757 1758
    input_x_ = InputXFrom<GType>(inputs, scope);
    out_ = OutFrom<GType>(outputs, scope);
Y
Yao,kun 已提交
1759 1760
  }

N
nhzlx 已提交
1761
  const RType *InputX() const { return input_x_; }
Y
Yao,kun 已提交
1762

N
nhzlx 已提交
1763
  RType *Out() const { return out_; }
Y
Yao,kun 已提交
1764 1765

 private:
N
nhzlx 已提交
1766 1767
  RType *input_x_;
  RType *out_;
Y
Yao,kun 已提交
1768
};
1769
#endif
Y
Yao,kun 已提交
1770

L
liuruilong 已提交
1771
#ifdef CONV_TRANSPOSE
N
nhzlx 已提交
1772
template <typename Dtype>
L
liuruilong 已提交
1773
class ConvTransposeParam : public OpParam {
N
nhzlx 已提交
1774 1775 1776
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

L
liuruilong 已提交
1777 1778 1779 1780
 public:
  ConvTransposeParam(const VariableNameMap &inputs,
                     const VariableNameMap &outputs, const AttributeMap &attrs,
                     const Scope &scope) {
N
nhzlx 已提交
1781 1782 1783
    filter_ = FilterFrom<GType>(inputs, scope);
    input_ = InputFrom<GType>(inputs, scope);
    output_ = OutputFrom<GType>(outputs, scope);
L
liuruilong 已提交
1784 1785 1786 1787 1788 1789
    strides_ = GetAttr<vector<int>>("strides", attrs);
    paddings_ = GetAttr<vector<int>>("paddings", attrs);
    dilations_ = GetAttr<vector<int>>("dilations", attrs);
    groups = GetAttr<int>("groups", attrs);
  }

N
nhzlx 已提交
1790
  const RType *Input() const { return input_; }
L
liuruilong 已提交
1791

N
nhzlx 已提交
1792
  const RType *Filter() const { return filter_; }
L
liuruilong 已提交
1793

N
nhzlx 已提交
1794
  RType *Output() const { return output_; }
L
liuruilong 已提交
1795 1796 1797 1798 1799 1800 1801 1802 1803 1804

  const vector<int> &Strides() const { return strides_; }

  const vector<int> &Paddings() const { return paddings_; }

  const vector<int> &Dilations() const { return dilations_; }

  const int &Groups() const { return groups; }

 private:
N
nhzlx 已提交
1805 1806 1807
  RType *input_;
  RType *output_;
  RType *filter_;
L
liuruilong 已提交
1808 1809 1810 1811 1812 1813 1814
  vector<int> strides_;
  vector<int> paddings_;
  vector<int> dilations_;
  int groups;
};
#endif

朔-望's avatar
朔-望 已提交
1815 1816
}  // namespace operators
}  // namespace paddle_mobile