op_param.h 56.4 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
  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);
  }
90 91 92 93
  template <typename T>
  static T *InputXFrom1(const VariableNameMap &inputs, const Scope &scope) {
    return GetVarValue1<T>("addX", inputs, scope);
  }
94 95 96 97 98 99

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

100 101 102 103 104
  template <typename T>
  static T *InputYFrom1(const VariableNameMap &inputs, const Scope &scope) {
    return GetVarValue1<T>("Y", inputs, scope);
  }

E
eclipsess 已提交
105 106 107 108 109
  template <typename T>
  static T *InputZFrom(const VariableNameMap &inputs, const Scope &scope) {
    return GetVarValue<T>("Z", inputs, scope);
  }

110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
  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 已提交
127 128 129 130
  template <typename T>
  static T *InputImageFrom(const VariableNameMap &inputs, const Scope &scope) {
    return GetVarValue<T>("Image", inputs, scope);
  }
E
eclipsess 已提交
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
  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);
  }
147

E
eclipsess 已提交
148 149 150 151 152 153 154 155 156 157
  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 已提交
158 159 160 161
  template <typename T>
  static T *InputShapeFrom(const VariableNameMap &inputs, const Scope &scope) {
    return GetVarValue<T>("Shape", inputs, scope);
  }
E
eclipsess 已提交
162

163
  template <typename T>
W
wangliu 已提交
164 165
  static vector<T *> InputMultiFrom(const VariableNameMap &inputs,
                                    const Scope &scope) {
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
    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 已提交
184 185 186 187 188 189
  template <typename T>
  static T *OutputBoxesFrom(const VariableNameMap &outputs,
                            const Scope &scope) {
    return GetVarValue<T>("Boxes", outputs, scope);
  }

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

E
eclipsess 已提交
195 196 197 198 199 200
  template <typename T>
  static T *OutputVariancesFrom(const VariableNameMap &outputs,
                                const Scope &scope) {
    return GetVarValue<T>("Variances", outputs, scope);
  }

201 202 203 204 205 206 207 208 209 210 211
  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 已提交
212
  static const T GetAttr(const string &key, const AttributeMap &map) {
213 214 215 216
    return ((Attribute)map.at(key)).Get<T>();
  }

  template <typename T>
W
wangliu 已提交
217
  static T *GetVarValue(const string &key, const VariableNameMap &var_map,
218
                        const Scope &scope) {
W
wangliu 已提交
219 220
    PADDLE_MOBILE_ENFORCE(var_map.count(key) > 0,
                          "%s is not contained in var_map", key.c_str())
221 222 223 224 225 226
    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
朔-望 已提交
227
    }
228
  }
朔-望's avatar
朔-望 已提交
229

230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
  static std::string getkey(const string &key, const VariableNameMap &var_map,
                            int index) {
    auto var_vec = var_map.at(key);
    return var_vec[index];
  }

  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;
    }
  }

250
  template <typename T>
W
wangliu 已提交
251 252 253
  static vector<T *> GetMultiVarValue(const string &key,
                                      const VariableNameMap &var_map,
                                      const Scope &scope) {
254 255
    auto var_vecs = var_map.at(key);
    assert(var_vecs.size() > 1);
W
wangliu 已提交
256
    vector<T *> var_res;
257 258 259
    for (auto &var_vec : var_vecs) {
      auto var = scope.FindVar(var_vec);
      var_res.push_back(var->GetMutable<T>());
朔-望's avatar
朔-望 已提交
260
    }
261 262
    return var_res;
  }
朔-望's avatar
朔-望 已提交
263 264
};

L
liuruilong 已提交
265
#ifdef CONV_OP
N
nhzlx 已提交
266
template <typename Dtype>
朔-望's avatar
朔-望 已提交
267
class ConvParam : OpParam {
N
nhzlx 已提交
268 269 270
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

朔-望's avatar
朔-望 已提交
271
 public:
272
  ConvParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
273
            const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
274 275 276
    filter_ = FilterFrom<GType>(inputs, scope);
    input_ = InputFrom<GType>(inputs, scope);
    output_ = OutputFrom<GType>(outputs, scope);
W
wangliu 已提交
277 278 279
    strides_ = GetAttr<vector<int>>("strides", attrs);
    paddings_ = GetAttr<vector<int>>("paddings", attrs);
    dilations_ = GetAttr<vector<int>>("dilations", attrs);
280 281
    groups = GetAttr<int>("groups", attrs);
  }
朔-望's avatar
朔-望 已提交
282

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

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

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

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

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

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

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

朔-望's avatar
朔-望 已提交
297
 private:
N
nhzlx 已提交
298 299 300
  RType *input_;
  RType *output_;
  RType *filter_;
W
wangliu 已提交
301 302 303
  vector<int> strides_;
  vector<int> paddings_;
  vector<int> dilations_;
304
  int groups;
朔-望's avatar
朔-望 已提交
305
};
N
nhzlx 已提交
306 307
template <typename Dtype>
Print &operator<<(Print &printer, const ConvParam<Dtype> &conv_param);
L
liuruilong 已提交
308
#endif
朔-望's avatar
朔-望 已提交
309

N
nhzlx 已提交
310
template <typename Dtype>
朔-望's avatar
朔-望 已提交
311
class ElementwiseAddParam : OpParam {
N
nhzlx 已提交
312 313 314
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

朔-望's avatar
朔-望 已提交
315
 public:
316
  ElementwiseAddParam(const VariableNameMap &inputs,
317 318
                      const VariableNameMap &outputs, const AttributeMap &attrs,
                      const Scope &scope) {
N
nhzlx 已提交
319 320 321
    input_x_ = InputXFrom<GType>(inputs, scope);
    input_y_ = InputYFrom<GType>(inputs, scope);
    out_ = OutFrom<GType>(outputs, scope);
322 323 324
    axis_ = GetAttr<int>("axis", attrs);
  }

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

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

N
nhzlx 已提交
329
  RType *Out() const { return out_; }
330 331 332

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

朔-望's avatar
朔-望 已提交
333
 private:
N
nhzlx 已提交
334 335 336
  RType *input_x_;
  RType *input_y_;
  RType *out_;
337
  int axis_;
Z
zhangyang 已提交
338 339 340
#ifdef PADDLE_MOBILE_FPGA

 private:
H
hanbuhe 已提交
341
  fpga::EWAddArgs fpga_EW_add_args;
Z
zhangyang 已提交
342 343

 public:
H
hanbuhe 已提交
344 345
  const fpga::EWAddArgs &FpgaArgs() const { return fpga_EW_add_args; }
  void SetFpgaArgs(const fpga::EWAddArgs &args) { fpga_EW_add_args = args; }
Z
zhangyang 已提交
346
#endif
朔-望's avatar
朔-望 已提交
347 348
};

349
#ifdef FUSION_ELEMENTWISEADDRELU_OP
N
nhzlx 已提交
350 351
template <typename Dtype>
using ElementwiseAddReluParam = ElementwiseAddParam<Dtype>;
L
liuruilong 已提交
352 353 354
#endif

#ifdef MUL_OP
N
nhzlx 已提交
355
template <typename Dtype>
朔-望's avatar
朔-望 已提交
356
class MulParam : OpParam {
N
nhzlx 已提交
357 358 359
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

朔-望's avatar
朔-望 已提交
360
 public:
361
  MulParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
362
           const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
363 364 365
    input_x_ = InputXFrom<GType>(inputs, scope);
    input_y_ = InputYFrom<GType>(inputs, scope);
    out_ = OutFrom<GType>(outputs, scope);
366 367 368
    x_num_col_dims_ = GetAttr<int>("x_num_col_dims", attrs);
    y_num_col_dims_ = GetAttr<int>("y_num_col_dims", attrs);
  }
朔-望's avatar
朔-望 已提交
369

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

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

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

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

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

朔-望's avatar
朔-望 已提交
380
 private:
N
nhzlx 已提交
381 382 383
  RType *input_x_;
  RType *input_y_;
  RType *out_;
384 385
  int x_num_col_dims_;
  int y_num_col_dims_;
朔-望's avatar
朔-望 已提交
386
};
L
liuruilong 已提交
387
#endif
朔-望's avatar
朔-望 已提交
388

L
liuruilong 已提交
389
#ifdef CONCAT_OP
N
nhzlx 已提交
390
template <typename Dtype>
朔-望's avatar
朔-望 已提交
391
class ConcatParam : public OpParam {
N
nhzlx 已提交
392 393 394
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

朔-望's avatar
朔-望 已提交
395
 public:
396
  ConcatParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
397
              const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
398 399
    inputs_ = InputMultiFrom<GType>(inputs, scope);
    out_ = OutFrom<GType>(outputs, scope);
400 401
    axis_ = GetAttr<int>("axis", attrs);
  }
朔-望's avatar
朔-望 已提交
402

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

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

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

朔-望's avatar
朔-望 已提交
409
 private:
N
nhzlx 已提交
410 411
  vector<GType *> inputs_;
  RType *out_;
412
  int axis_;
朔-望's avatar
朔-望 已提交
413
};
L
liuruilong 已提交
414
#endif
朔-望's avatar
朔-望 已提交
415

L
liuruilong 已提交
416
#ifdef LRN_OP
N
nhzlx 已提交
417
template <typename Dtype>
E
eclipsess 已提交
418
class LrnParam : public OpParam {
N
nhzlx 已提交
419 420 421
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

朔-望's avatar
朔-望 已提交
422
 public:
423
  LrnParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
424
           const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
425 426 427
    input_x_ = InputXFrom<GType>(inputs, scope);
    out_ = OutFrom<GType>(outputs, scope);
    mid_out_ = MidOutFrom<GType>(outputs, scope);
428 429 430 431
    n_ = GetAttr<int>("n", attrs);
    alpha_ = GetAttr<float>("alpha", attrs);
    beta_ = GetAttr<float>("beta", attrs);
    k_ = GetAttr<float>("k", attrs);
W
wangliu 已提交
432
    data_format_ = GetAttr<string>("data_format", attrs);
433
  }
E
eclipsess 已提交
434

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

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

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

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

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

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

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

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

朔-望's avatar
朔-望 已提交
451
 private:
N
nhzlx 已提交
452 453 454
  RType *input_x_;
  RType *out_;
  RType *mid_out_;
455 456 457 458
  int n_;
  float alpha_;
  float beta_;
  float k_;
W
wangliu 已提交
459
  string data_format_;
E
eclipsess 已提交
460
};
L
liuruilong 已提交
461 462 463
#endif

#ifdef BATCHNORM_OP
N
nhzlx 已提交
464
template <typename Dtype>
E
eclipsess 已提交
465
class BatchNormParam : OpParam {
N
nhzlx 已提交
466 467 468
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

朔-望's avatar
朔-望 已提交
469
 public:
470
  BatchNormParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
471
                 const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
472 473 474 475 476 477
    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);
478 479
    epsilon_ = GetAttr<float>("epsilon", attrs);
    momentum_ = GetAttr<float>("momentum", attrs);
L
liuruilong 已提交
480
    //    is_test_ = GetAttr<bool>("is_test", attrs);
481
  }
E
eclipsess 已提交
482

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

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

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

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

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

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

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

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

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

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

朔-望's avatar
朔-望 已提交
503
 private:
N
nhzlx 已提交
504 505 506 507 508 509
  RType *input_x_;
  RType *output_y_;
  RType *input_bias_;
  RType *input_mean_;
  RType *input_scale_;
  RType *input_variance_;
510 511 512
  float epsilon_;
  float momentum_;
  bool is_test_;
W
wangliu 已提交
513
  string data_format_;
E
eclipsess 已提交
514
};
L
liuruilong 已提交
515 516 517
#endif

#ifdef POOL_OP
N
nhzlx 已提交
518
template <typename Dtype>
519
class PoolParam : public OpParam {
N
nhzlx 已提交
520 521 522
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

朔-望's avatar
朔-望 已提交
523
 public:
524
  PoolParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
525
            const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
526
    input_ = InputXFrom<GType>(inputs, scope);
527

N
nhzlx 已提交
528
    output_ = OutFrom<GType>(outputs, scope);
W
wangliu 已提交
529 530 531 532
    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);
533
    ceil_mode_ = GetAttr<bool>("ceil_mode", attrs);
534
    global_pooling_ = GetAttr<bool>("global_pooling", attrs);
535
  }
536

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

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

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

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

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

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

549
  bool isCeilMode() const { return ceil_mode_; }
550

Z
zhangyang 已提交
551
  bool isGlobalPooling() const { return global_pooling_; }
552

朔-望's avatar
朔-望 已提交
553
 private:
N
nhzlx 已提交
554 555
  RType *input_;
  RType *output_;
W
wangliu 已提交
556 557 558 559
  string pooling_type_;
  vector<int> ksize_;
  vector<int> strides_;
  vector<int> paddings_;
560
  bool ceil_mode_;
561
  bool global_pooling_ = false;
Z
zhangyang 已提交
562
#ifdef PADDLE_MOBILE_FPGA
563 564

 private:
H
hanbuhe 已提交
565
  fpga::PoolingArgs fpga_pool_args;
Z
zhangyang 已提交
566 567

 public:
H
hanbuhe 已提交
568 569
  const fpga::PoolingArgs &FpgaArgs() const { return fpga_pool_args; }
  void SetFpgaArgs(const fpga::PoolingArgs &args) { fpga_pool_args = args; }
Z
zhangyang 已提交
570
#endif
571
};
L
liuruilong 已提交
572 573 574
#endif

#ifdef PRIORBOX_OP
N
nhzlx 已提交
575
template <typename Dtype>
E
eclipsess 已提交
576
class PriorBoxParam : public OpParam {
N
nhzlx 已提交
577 578 579
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

E
eclipsess 已提交
580 581
 public:
  PriorBoxParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
582
                const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
583 584 585 586
    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 已提交
587 588 589 590
    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 已提交
591 592 593 594 595 596
    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 已提交
597
  const RType *Input() const { return input_; }
E
eclipsess 已提交
598

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

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

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

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

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

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

W
wangliu 已提交
611
  const vector<float> &Variances() const { return variances_; }
E
eclipsess 已提交
612 613 614 615 616 617 618 619 620 621 622 623

  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 已提交
624 625 626 627
  RType *input_;
  RType *input_image_;
  RType *output_boxes_;
  RType *output_variances_;
W
wangliu 已提交
628 629 630 631
  vector<float> min_sizes_;
  vector<float> max_sizes_;
  vector<float> aspect_ratios_;
  vector<float> variances_;
E
eclipsess 已提交
632 633 634 635 636 637
  bool flip_;
  bool clip_;
  float step_w_;
  float step_h_;
  float offset_;
};
L
liuruilong 已提交
638
#endif
E
eclipsess 已提交
639

L
liuruilong 已提交
640
#ifdef BOXCODER_OP
N
nhzlx 已提交
641
template <typename Dtype>
E
eclipsess 已提交
642
class BoxCoderParam : public OpParam {
N
nhzlx 已提交
643 644 645
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

E
eclipsess 已提交
646 647
 public:
  BoxCoderParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
648
                const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
649 650 651 652
    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 已提交
653 654
    code_type_ = GetAttr<std::string>("code_type", attrs);
  }
N
nhzlx 已提交
655
  const RType *InputPriorBox() const { return input_priorbox_; }
E
eclipsess 已提交
656

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

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

N
nhzlx 已提交
661
  RType *OutputBox() const { return output_box_; }
E
eclipsess 已提交
662 663 664 665

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

 private:
N
nhzlx 已提交
666 667 668 669
  RType *input_priorbox_;
  RType *input_priorboxvar_;
  RType *input_targetbox_;
  RType *output_box_;
E
eclipsess 已提交
670 671
  std::string code_type_;
};
L
liuruilong 已提交
672
#endif
W
wangliu 已提交
673

L
liuruilong 已提交
674
#ifdef SOFTMAX_OP
N
nhzlx 已提交
675
template <typename Dtype>
W
wangliu 已提交
676
class SoftmaxParam : public OpParam {
N
nhzlx 已提交
677 678 679
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

W
wangliu 已提交
680 681
 public:
  SoftmaxParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
682
               const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
683 684
    input_x_ = InputXFrom<GType>(inputs, scope);
    out_ = OutFrom<GType>(outputs, scope);
W
wangliu 已提交
685
  }
N
nhzlx 已提交
686 687
  const RType *InputX() const { return input_x_; }
  RType *Out() const { return out_; }
W
wangliu 已提交
688 689

 private:
N
nhzlx 已提交
690 691
  RType *input_x_;
  RType *out_;
H
hanbuhe 已提交
692 693 694 695

#ifdef PADDLE_MOBILE_FPGA

 private:
N
nhzlx 已提交
696
  std::shared_ptr<RType> float_input_x_;
H
hanbuhe 已提交
697 698 699
  fpga::BypassArgs fpga_bypass_args;

 public:
N
nhzlx 已提交
700
  RType *FloatInput() {
H
hanbuhe 已提交
701 702 703 704 705 706
    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 已提交
707
};
L
liuruilong 已提交
708
#endif
W
wangliu 已提交
709

L
liuruilong 已提交
710
#ifdef SIGMOID_OP
N
nhzlx 已提交
711
template <typename Dtype>
W
wangliu 已提交
712
class SigmoidParam : public OpParam {
N
nhzlx 已提交
713 714 715
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

W
wangliu 已提交
716 717
 public:
  SigmoidParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
718
               const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
719 720
    input_x_ = InputXFrom<GType>(inputs, scope);
    out_ = OutFrom<GType>(outputs, scope);
W
wangliu 已提交
721
  }
N
nhzlx 已提交
722 723
  const RType *InputX() const { return input_x_; }
  RType *Out() const { return out_; }
W
wangliu 已提交
724 725

 private:
N
nhzlx 已提交
726 727
  RType *input_x_;
  RType *out_;
W
wangliu 已提交
728
};
L
liuruilong 已提交
729 730 731
#endif

#ifdef MULTICLASSNMS_OP
N
nhzlx 已提交
732
template <typename Dtype>
E
eclipsess 已提交
733
class MultiClassNMSParam : public OpParam {
N
nhzlx 已提交
734 735 736
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

E
eclipsess 已提交
737 738 739 740
 public:
  MultiClassNMSParam(const VariableNameMap &inputs,
                     const VariableNameMap &outputs, const AttributeMap &attrs,
                     const Scope &scope) {
N
nhzlx 已提交
741 742 743
    input_bboxes_ = InputBBoxesFrom<GType>(inputs, scope);
    input_scores_ = InputScoresFrom<GType>(inputs, scope);
    out_ = OutFrom<GType>(outputs, scope);
E
eclipsess 已提交
744 745 746 747 748 749 750 751
    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 已提交
752
  const RType *InputBBoxes() const { return input_bboxes_; }
E
eclipsess 已提交
753

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

N
nhzlx 已提交
756
  RType *Out() const { return out_; }
E
eclipsess 已提交
757 758 759 760 761 762 763 764 765 766 767 768 769 770

  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 已提交
771 772 773
  RType *input_bboxes_;
  RType *input_scores_;
  RType *out_;
E
eclipsess 已提交
774 775 776 777 778 779 780
  int background_label_;
  int nms_top_k_;
  int keep_top_k_;
  float nms_threshold_;
  float nms_eta_;
  float score_threshold_;
};
L
liuruilong 已提交
781
#endif
W
wangliu 已提交
782

N
nhzlx 已提交
783
template <typename Dtype>
L
liuruilong 已提交
784
class FeedParam : public OpParam {
N
nhzlx 已提交
785 786 787
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

L
liuruilong 已提交
788 789
 public:
  FeedParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
L
liuruilong 已提交
790
            const AttributeMap &attrs, Scope *scope) {
N
nhzlx 已提交
791 792
    input_x_ = InputXFrom<GType>(inputs, *scope);
    out_ = OutFrom<GType>(outputs, *scope);
L
liuruilong 已提交
793
    auto var = scope->Var("batch_size");
W
wangliu 已提交
794
    batch_size = var->GetValue<int>();
L
liuruilong 已提交
795
  }
N
nhzlx 已提交
796 797
  const RType *InputX() const { return input_x_; }
  RType *Out() const { return out_; }
W
wangliu 已提交
798
  const int BatchSize() const { return batch_size; }
L
liuruilong 已提交
799

L
liuruilong 已提交
800
 private:
N
nhzlx 已提交
801 802
  RType *input_x_;
  RType *out_;
W
wangliu 已提交
803
  int batch_size;
L
liuruilong 已提交
804 805
};

N
nhzlx 已提交
806
template <typename Dtype>
L
liuruilong 已提交
807
class FetchParam : public OpParam {
N
nhzlx 已提交
808 809 810
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

L
liuruilong 已提交
811 812
 public:
  FetchParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
813
             const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
814 815
    input_x_ = InputXFrom<GType>(inputs, scope);
    out_ = OutFrom<GType>(outputs, scope);
L
liuruilong 已提交
816
  }
N
nhzlx 已提交
817 818
  const RType *InputX() const { return input_x_; }
  RType *Out() const { return out_; }
L
liuruilong 已提交
819

L
liuruilong 已提交
820
 private:
N
nhzlx 已提交
821 822
  RType *input_x_;
  RType *out_;
L
liuruilong 已提交
823 824
};

L
liuruilong 已提交
825
#ifdef TRANSPOSE_OP
N
nhzlx 已提交
826
template <typename Dtype>
E
eclipsess 已提交
827
class TransposeParam : public OpParam {
N
nhzlx 已提交
828 829 830
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

E
eclipsess 已提交
831 832 833
 public:
  TransposeParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
                 const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
834 835
    input_x_ = InputXFrom<GType>(inputs, scope);
    out_ = OutFrom<GType>(outputs, scope);
E
eclipsess 已提交
836 837 838
    axis_ = GetAttr<vector<int>>("axis", attrs);
  }

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

N
nhzlx 已提交
841
  RType *Out() const { return out_; }
E
eclipsess 已提交
842 843 844 845

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

 private:
N
nhzlx 已提交
846 847
  RType *input_x_;
  RType *out_;
E
eclipsess 已提交
848 849
  vector<int> axis_;
};
L
liuruilong 已提交
850
#endif
E
eclipsess 已提交
851

L
liuruilong 已提交
852
#ifdef RESHAPE_OP
N
nhzlx 已提交
853
template <typename Dtype>
E
eclipsess 已提交
854
class ReshapeParam : public OpParam {
N
nhzlx 已提交
855 856 857
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

E
eclipsess 已提交
858 859 860
 public:
  ReshapeParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
               const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
861 862 863
    input_x_ = InputXFrom<GType>(inputs, scope);
    input_shape_ = InputShapeFrom<GType>(inputs, scope);
    out_ = OutFrom<GType>(outputs, scope);
E
eclipsess 已提交
864 865 866 867
    shape_ = GetAttr<vector<int>>("shape", attrs);
    inplace_ = GetAttr<bool>("inplace", attrs);
  }

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

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

N
nhzlx 已提交
872
  RType *Out() const { return out_; }
E
eclipsess 已提交
873 874 875 876 877 878

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

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

 private:
N
nhzlx 已提交
879 880 881
  RType *input_x_;
  RType *input_shape_;
  RType *out_;
E
eclipsess 已提交
882 883 884
  vector<int> shape_;
  bool inplace_;
};
L
liuruilong 已提交
885
#endif
E
eclipsess 已提交
886

T
Tian 已提交
887
#ifdef SCALE_OP
N
nhzlx 已提交
888
template <typename Dtype>
I
itminner 已提交
889
class ScaleParam : public OpParam {
N
nhzlx 已提交
890 891 892
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

I
itminner 已提交
893 894 895
 public:
  ScaleParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
             const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
896 897 898
    input_x_ = InputXFrom<GType>(inputs, scope);
    input_bias_ = InputBiasFrom<GType>(inputs, scope);
    out_ = OutFrom<GType>(outputs, scope);
I
itminner 已提交
899 900 901 902 903 904
    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 已提交
905
  const RType *InputX() const { return input_x_; }
I
itminner 已提交
906

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

N
nhzlx 已提交
909
  RType *Out() const { return out_; }
I
itminner 已提交
910 911 912 913 914 915 916 917 918 919

  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 已提交
920 921 922
  RType *input_x_;
  RType *input_bias_;
  RType *out_;
I
itminner 已提交
923 924 925 926 927
  bool inplace_;
  bool has_bias_;
  vector<float> scales_;
  vector<float> biases_;
};
T
Tian 已提交
928 929 930
#endif

#ifdef SLICE_OP
N
nhzlx 已提交
931
template <typename Dtype>
I
itminner 已提交
932
class SliceParam : public OpParam {
N
nhzlx 已提交
933 934 935
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

I
itminner 已提交
936 937 938
 public:
  SliceParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
             const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
939 940 941
    input_x_ = InputXFrom<GType>(inputs, scope);
    input_shape_ = InputShapeFrom<GType>(inputs, scope);
    out_ = OutFrom<GType>(outputs, scope);
I
itminner 已提交
942 943 944 945 946
    axis_ = GetAttr<int>("axis", attrs);
    slice_points_ = GetAttr<vector<int>>("slice_points", attrs);
    inplace_ = GetAttr<bool>("inplace", attrs);
  }

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

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

N
nhzlx 已提交
951
  RType *Out() const { return out_; }
I
itminner 已提交
952 953 954 955 956 957 958 959

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

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

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

 private:
N
nhzlx 已提交
960 961 962
  RType *input_x_;
  RType *input_shape_;
  RType *out_;
I
itminner 已提交
963 964 965 966
  int axis_;
  vector<int> slice_points_;
  bool inplace_;
};
T
Tian 已提交
967 968 969
#endif

#ifdef RESIZE_OP
N
nhzlx 已提交
970
template <typename Dtype>
T
Tian 已提交
971
class ResizeParam : public OpParam {
N
nhzlx 已提交
972 973 974
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

I
itminner 已提交
975 976 977
 public:
  ResizeParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
              const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
978 979 980
    input_x_ = InputXFrom<GType>(inputs, scope);
    input_shape_ = InputShapeFrom<GType>(inputs, scope);
    out_ = OutFrom<GType>(outputs, scope);
I
itminner 已提交
981 982 983 984 985 986
    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 已提交
987

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

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

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

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

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

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

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

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

I
itminner 已提交
1004
 private:
N
nhzlx 已提交
1005 1006 1007
  RType *input_x_;
  RType *input_shape_;
  RType *out_;
I
itminner 已提交
1008 1009 1010 1011 1012
  bool is_pyramid_test_;
  int height_;
  int width_;
  float out_height_scale_;
  float out_width_scale_;
T
Tian 已提交
1013 1014 1015
};
#endif

L
liuruilong 已提交
1016
#ifdef RELU_OP
L
liuruilong 已提交
1017 1018 1019
/*
 * @b op 层实例化好这个 param 传递给 kernel 层使用
 * */
N
nhzlx 已提交
1020
template <typename Dtype>
E
eclipsess 已提交
1021
class ReluParam : public OpParam {
N
nhzlx 已提交
1022 1023 1024
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

E
eclipsess 已提交
1025 1026 1027
 public:
  ReluParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
            const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
1028 1029
    input_x_ = InputXFrom<GType>(inputs, scope);
    out_ = OutFrom<GType>(outputs, scope);
E
eclipsess 已提交
1030 1031
  }

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

N
nhzlx 已提交
1034
  RType *Out() const { return out_; }
E
eclipsess 已提交
1035 1036

 private:
N
nhzlx 已提交
1037 1038
  RType *input_x_;
  RType *out_;
E
eclipsess 已提交
1039
};
L
liuruilong 已提交
1040
#endif
E
eclipsess 已提交
1041

T
Tian 已提交
1042
#ifdef PRELU_OP
N
nhzlx 已提交
1043
template <typename Dtype>
T
Tian 已提交
1044
class PReluParam : public OpParam {
N
nhzlx 已提交
1045 1046 1047
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

I
itminner 已提交
1048 1049 1050
 public:
  PReluParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
             const AttributeMap &attrs, const Scope &scope) {
1051
    DLOG << "PReluParam inputs before";
N
nhzlx 已提交
1052
    input_x_ = InputXFrom<GType>(inputs, scope);
N
nhzlx 已提交
1053
    alpha_ = InputAlphaFrom<GType>(inputs, scope);
1054
    framework::DDim dims = alpha_->dims();
N
nhzlx 已提交
1055
    out_ = OutFrom<GType>(outputs, scope);
1056 1057
    mode_ = GetAttr<std::string>("mode", attrs);
    DLOG << "PReluParam mode after" << mode_;
I
itminner 已提交
1058
  }
N
nhzlx 已提交
1059
  const RType *InputX() const { return input_x_; }
N
nhzlx 已提交
1060
  const RType *InputAlpha() const { return alpha_; }
N
nhzlx 已提交
1061
  RType *Out() const { return out_; }
1062
  const std::string &Mode() const { return mode_; }
T
Tian 已提交
1063

I
itminner 已提交
1064
 private:
N
nhzlx 已提交
1065 1066
  RType *input_x_;
  RType *out_;
N
nhzlx 已提交
1067
  RType *alpha_;
1068
  std::string mode_;
T
Tian 已提交
1069 1070 1071
};
#endif

N
nhzlx 已提交
1072
template <typename Dtype>
L
liuruilong 已提交
1073
class FusionFcParam : public OpParam {
N
nhzlx 已提交
1074 1075 1076
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

E
eclipsess 已提交
1077
 public:
L
liuruilong 已提交
1078
  FusionFcParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
L
liuruilong 已提交
1079
                const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
1080 1081 1082 1083
    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 已提交
1084 1085 1086 1087
    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 已提交
1088
  const RType *InputX() const { return input_x_; }
E
eclipsess 已提交
1089

1090
#ifdef PADDLE_MOBILE_FPGA
N
nhzlx 已提交
1091
  RType *InputY() const { return input_y_; }
1092
#else
N
nhzlx 已提交
1093
  const RType *InputY() const { return input_y_; }
1094
#endif
E
eclipsess 已提交
1095

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

N
nhzlx 已提交
1098
  RType *Out() const { return out_; }
E
eclipsess 已提交
1099 1100 1101 1102 1103 1104 1105 1106

  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 已提交
1107 1108 1109 1110
  RType *input_x_;
  RType *input_y_;
  RType *input_z_;
  RType *out_;
E
eclipsess 已提交
1111 1112 1113
  int x_num_col_dims_;
  int y_num_col_dims_;
  int axis_;
Z
zhangyang 已提交
1114 1115 1116
#ifdef PADDLE_MOBILE_FPGA

 private:
H
hanbuhe 已提交
1117
  fpga::ConvArgs fpga_conv_args;
Z
zhangyang 已提交
1118 1119

 public:
H
hanbuhe 已提交
1120 1121
  const fpga::ConvArgs &FpgaArgs() const { return fpga_conv_args; }
  void SetFpgaArgs(const fpga::ConvArgs &args) { fpga_conv_args = args; }
Z
zhangyang 已提交
1122
#endif
E
eclipsess 已提交
1123
};
1124 1125

#ifdef FUSION_FCRELU_OP
N
nhzlx 已提交
1126 1127
template <typename DeviceType>
using FusionFcReluParam = FusionFcParam<DeviceType>;
L
liuruilong 已提交
1128
#endif
E
eclipsess 已提交
1129

N
nhzlx 已提交
1130
template <typename Dtype>
L
liuruilong 已提交
1131
class FusionConvAddParam : public OpParam {
N
nhzlx 已提交
1132 1133 1134
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

W
wangliu 已提交
1135
 public:
L
liuruilong 已提交
1136
  FusionConvAddParam(const VariableNameMap &inputs,
L
liuruilong 已提交
1137 1138
                     const VariableNameMap &outputs, const AttributeMap &attrs,
                     const Scope &scope) {
N
nhzlx 已提交
1139
    bias_ = InputYFrom<GType>(inputs, scope);
W
wangliu 已提交
1140
    axis_ = GetAttr<int>("axis", attrs);
N
nhzlx 已提交
1141 1142 1143
    filter_ = FilterFrom<GType>(inputs, scope);
    input_ = InputFrom<GType>(inputs, scope);
    output_ = OutFrom<GType>(outputs, scope);
W
wangliu 已提交
1144 1145 1146 1147 1148
    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 已提交
1149
  RType *Bias() const { return bias_; }
W
wangliu 已提交
1150 1151 1152

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

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

1155
#ifdef PADDLE_MOBILE_FPGA
N
nhzlx 已提交
1156
  RType *Filter() const { return filter_; }
1157
#else
N
nhzlx 已提交
1158
  const RType *Filter() const { return filter_; }
1159
#endif
W
wangliu 已提交
1160

N
nhzlx 已提交
1161
  RType *Output() const { return output_; }
W
wangliu 已提交
1162 1163 1164 1165 1166 1167 1168 1169 1170

  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 已提交
1171
 protected:
N
nhzlx 已提交
1172
  RType *bias_;
W
wangliu 已提交
1173
  int axis_;
N
nhzlx 已提交
1174 1175 1176
  RType *input_;
  RType *output_;
  RType *filter_;
W
wangliu 已提交
1177 1178 1179 1180
  vector<int> strides_;
  vector<int> paddings_;
  vector<int> dilations_;
  int groups;
Z
zhangyang 已提交
1181 1182 1183
#ifdef PADDLE_MOBILE_FPGA

 private:
H
hanbuhe 已提交
1184
  fpga::ConvArgs fpga_conv_args;
Z
zhangyang 已提交
1185 1186

 public:
H
hanbuhe 已提交
1187 1188
  const fpga::ConvArgs &FpgaArgs() const { return fpga_conv_args; }
  void SetFpgaArgs(const fpga::ConvArgs &args) { fpga_conv_args = args; }
Z
zhangyang 已提交
1189
#endif
W
wangliu 已提交
1190 1191
};

N
nhzlx 已提交
1192 1193
template <typename Dtype>
Print &operator<<(Print &printer, const FusionConvAddParam<Dtype> &conv_param);
W
wangliu 已提交
1194

Z
zhangyang 已提交
1195
#ifdef FUSION_CONVADDRELU_OP
N
nhzlx 已提交
1196 1197
template <typename DeviceType>
class FusionConvAddReluParam : public FusionConvAddParam<DeviceType> {
L
liuruilong 已提交
1198
 public:
L
liuruilong 已提交
1199
  FusionConvAddReluParam(const VariableNameMap &inputs,
L
liuruilong 已提交
1200 1201
                         const VariableNameMap &outputs,
                         const AttributeMap &attrs, const Scope &scope)
N
nhzlx 已提交
1202
      : FusionConvAddParam<DeviceType>(inputs, outputs, attrs, scope) {}
L
liuruilong 已提交
1203 1204 1205
};
#endif

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 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362
#ifdef FUSION_CONVADDPRELU_OP
template <typename DeviceType>
class FusionConvAddPReluParam : public OpParam {
  typedef typename DtypeTensorTrait<DeviceType>::gtype GType;
  typedef typename DtypeTensorTrait<DeviceType>::rtype RType;

 public:
  FusionConvAddPReluParam(const VariableNameMap &inputs,
                          const VariableNameMap &outputs,
                          const AttributeMap &attrs, const Scope &scope) {
    alpha_ = InputAlphaFrom<GType>(inputs, scope);
    mode_ = GetAttr<std::string>("mode", attrs);
    framework::DDim dims = alpha_->dims();
    bias_ = InputYFrom<GType>(inputs, scope);
    axis_ = GetAttr<int>("axis", attrs);
    filter_ = FilterFrom<GType>(inputs, scope);
    input_ = InputFrom<GType>(inputs, scope);
    output_ = OutFrom<GType>(outputs, scope);
    strides_ = GetAttr<vector<int>>("strides", attrs);
    paddings_ = GetAttr<vector<int>>("paddings", attrs);
    dilations_ = GetAttr<vector<int>>("dilations", attrs);
    groups = GetAttr<int>("groups", attrs);
  }
  const RType *InputAlpha() const { return alpha_; }
  const std::string &Mode() const { return mode_; }
  RType *Bias() const { return bias_; }

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

  const RType *Input() const { return input_; }

#ifdef PADDLE_MOBILE_FPGA
  RType *Filter() const { return filter_; }
#else
  const RType *Filter() const { return filter_; }
#endif

  RType *Output() const { return output_; }

  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; }

 protected:
  RType *bias_;
  int axis_;
  RType *input_;
  RType *output_;
  RType *filter_;
  vector<int> strides_;
  vector<int> paddings_;
  vector<int> dilations_;
  int groups;
  RType *alpha_;
  std::string mode_;
#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

#ifdef FUSION_CONVADDADDPRELU_OP
template <typename DeviceType>
class FusionConvAddAddPReluParam : public OpParam {
  typedef typename DtypeTensorTrait<DeviceType>::gtype GType;
  typedef typename DtypeTensorTrait<DeviceType>::rtype RType;

 public:
  FusionConvAddAddPReluParam(const VariableNameMap &inputs,
                             const VariableNameMap &outputs,
                             const AttributeMap &attrs, const Scope &scope) {
    bias1_ = InputYFrom1<GType>(inputs, scope);
    alpha_ = InputAlphaFrom<GType>(inputs, scope);
    mode_ = GetAttr<std::string>("mode", attrs);
    framework::DDim dims = alpha_->dims();
    bias_ = InputYFrom<GType>(inputs, scope);
    axis_ = GetAttr<int>("axis", attrs);
    filter_ = FilterFrom<GType>(inputs, scope);
    input_ = InputFrom<GType>(inputs, scope);
    output_ = OutFrom<GType>(outputs, scope);
    strides_ = GetAttr<vector<int>>("strides", attrs);
    paddings_ = GetAttr<vector<int>>("paddings", attrs);
    dilations_ = GetAttr<vector<int>>("dilations", attrs);
    groups = GetAttr<int>("groups", attrs);
    keyOutput_ = getkey("addOut", inputs, 0);
    keyX1_ = getkey("addX", inputs, 1);
    keyY1_ = getkey("Y", inputs, 1);
    if (keyX1_ == keyOutput_) {
      bias1_ = InputYFrom1<GType>(inputs, scope);
    } else if (keyY1_ == keyOutput_) {
      bias1_ = InputXFrom1<GType>(inputs, scope);
    }
  }
  const RType *InputAlpha() const { return alpha_; }
  const std::string &Mode() const { return mode_; }
  const RType *Bias1() const { return bias1_; }

  RType *Bias() const { return bias_; }

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

  const RType *Input() const { return input_; }

#ifdef PADDLE_MOBILE_FPGA
  RType *Filter() const { return filter_; }
#else
  const RType *Filter() const { return filter_; }
#endif

  RType *Output() const { return output_; }

  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; }

 protected:
  RType *bias_;
  int axis_;
  RType *input_;
  RType *output_;
  RType *filter_;
  vector<int> strides_;
  vector<int> paddings_;
  vector<int> dilations_;
  int groups;
  RType *alpha_;
  std::string mode_;
  RType *bias1_;
  std::string keyOutput_;
  std::string keyX1_;
  std::string keyY1_;
#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

E
eclipsess 已提交
1363
#ifdef FUSION_CONVADDBNRELU_OP
N
nhzlx 已提交
1364
template <typename Dtype>
E
eclipsess 已提交
1365
class FusionConvAddBNReluParam : public OpParam {
N
nhzlx 已提交
1366 1367 1368
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

E
eclipsess 已提交
1369 1370 1371 1372
 public:
  FusionConvAddBNReluParam(const VariableNameMap &inputs,
                           const VariableNameMap &outputs,
                           const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
1373
    bias_ = InputYFrom<GType>(inputs, scope);
E
eclipsess 已提交
1374
    axis_ = GetAttr<int>("axis", attrs);
N
nhzlx 已提交
1375 1376 1377
    filter_ = FilterFrom<GType>(inputs, scope);
    input_ = InputFrom<GType>(inputs, scope);
    output_ = OutFrom<GType>(outputs, scope);
E
eclipsess 已提交
1378 1379 1380 1381
    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 已提交
1382 1383 1384 1385
    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 已提交
1386 1387
    epsilon_ = GetAttr<float>("epsilon", attrs);
    momentum_ = GetAttr<float>("momentum", attrs);
L
liuruilong 已提交
1388
    //    is_test_ = GetAttr<bool>("is_test", attrs);
E
eclipsess 已提交
1389
  }
N
nhzlx 已提交
1390
  RType *Bias() const { return bias_; }
E
eclipsess 已提交
1391 1392 1393

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

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

1396
#ifdef PADDLE_MOBILE_FPGA
N
nhzlx 已提交
1397
  RType *Filter() const { return filter_; }
1398
#else
N
nhzlx 已提交
1399
  const RType *Filter() const { return filter_; }
1400
#endif
E
eclipsess 已提交
1401

N
nhzlx 已提交
1402
  RType *Output() const { return output_; }
E
eclipsess 已提交
1403 1404 1405 1406 1407 1408 1409 1410 1411

  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 已提交
1412
  const RType *InputBias() const { return input_bias_; }
E
eclipsess 已提交
1413

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

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

N
nhzlx 已提交
1418
  const RType *InputVariance() const { return input_variance_; }
E
eclipsess 已提交
1419 1420 1421 1422 1423 1424 1425

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

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

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

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

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

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

N
nhzlx 已提交
1432
  const RType *NewBias() const { return new_bias_; }
E
eclipsess 已提交
1433 1434

 protected:
N
nhzlx 已提交
1435
  RType *bias_;
E
eclipsess 已提交
1436
  int axis_;
N
nhzlx 已提交
1437 1438 1439
  RType *input_;
  RType *output_;
  RType *filter_;
E
eclipsess 已提交
1440 1441 1442 1443
  vector<int> strides_;
  vector<int> paddings_;
  vector<int> dilations_;
  int groups;
N
nhzlx 已提交
1444 1445 1446 1447
  RType *input_bias_;
  RType *input_mean_;
  RType *input_scale_;
  RType *input_variance_;
E
eclipsess 已提交
1448 1449 1450
  float epsilon_;
  float momentum_;
  bool is_test_;
N
nhzlx 已提交
1451 1452
  RType *new_bias_;
  RType *new_scale_;
Z
zhangyang 已提交
1453 1454 1455
#ifdef PADDLE_MOBILE_FPGA

 private:
H
hanbuhe 已提交
1456
  fpga::ConvArgs fpga_conv_args;
Z
zhangyang 已提交
1457 1458

 public:
H
hanbuhe 已提交
1459 1460
  const fpga::ConvArgs &FpgaArgs() const { return fpga_conv_args; }
  void SetFpgaArgs(const fpga::ConvArgs &args) { fpga_conv_args = args; }
Z
zhangyang 已提交
1461
#endif
E
eclipsess 已提交
1462
};
1463
#endif
E
eclipsess 已提交
1464

Z
zhangyang 已提交
1465
#ifdef FUSION_CONVBN_OP
N
nhzlx 已提交
1466
template <typename Dtype>
Z
zhangyang 已提交
1467
class FusionConvBNParam : public OpParam {
N
nhzlx 已提交
1468 1469 1470
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

Z
zhangyang 已提交
1471 1472 1473 1474
 public:
  FusionConvBNParam(const VariableNameMap &inputs,
                    const VariableNameMap &outputs, const AttributeMap &attrs,
                    const Scope &scope) {
N
nhzlx 已提交
1475 1476 1477
    filter_ = FilterFrom<GType>(inputs, scope);
    input_ = InputFrom<GType>(inputs, scope);
    output_y_ = OutputYFrom<GType>(outputs, scope);
Z
zhangyang 已提交
1478 1479 1480 1481
    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 已提交
1482 1483 1484 1485
    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 已提交
1486 1487 1488 1489 1490
    epsilon_ = GetAttr<float>("epsilon", attrs);
    momentum_ = GetAttr<float>("momentum", attrs);
    //    is_test_ = GetAttr<bool>("is_test", attrs);
  }

N
nhzlx 已提交
1491
  const RType *Input() const { return input_; }
Z
zhangyang 已提交
1492 1493

#ifdef PADDLE_MOBILE_FPGA
N
nhzlx 已提交
1494
  RType *Filter() const { return filter_; }
Z
zhangyang 已提交
1495
#else
N
nhzlx 已提交
1496
  const RType *Filter() const { return filter_; }
Z
zhangyang 已提交
1497
#endif
N
nhzlx 已提交
1498
  RType *Output() const { return output_y_; }
Z
zhangyang 已提交
1499 1500 1501 1502 1503 1504 1505 1506 1507

  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 已提交
1508
  const RType *InputBias() const { return input_bias_; }
Z
zhangyang 已提交
1509

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

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

N
nhzlx 已提交
1514
  const RType *InputVariance() const { return input_variance_; }
Z
zhangyang 已提交
1515 1516 1517 1518 1519 1520 1521

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

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

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

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

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

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

N
nhzlx 已提交
1528
  const RType *NewBias() const { return new_bias_; }
Z
zhangyang 已提交
1529 1530

 protected:
N
nhzlx 已提交
1531 1532 1533
  RType *input_;
  RType *output_y_;
  RType *filter_;
Z
zhangyang 已提交
1534 1535 1536 1537
  vector<int> strides_;
  vector<int> paddings_;
  vector<int> dilations_;
  int groups;
N
nhzlx 已提交
1538 1539 1540 1541
  RType *input_bias_;
  RType *input_mean_;
  RType *input_scale_;
  RType *input_variance_;
Z
zhangyang 已提交
1542 1543 1544
  float epsilon_;
  float momentum_;
  bool is_test_;
N
nhzlx 已提交
1545 1546
  RType *new_bias_;
  RType *new_scale_;
Z
zhangyang 已提交
1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558
#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

1559
#ifdef FUSION_CONVADDBN_OP
N
nhzlx 已提交
1560
template <typename Dtype>
1561
class FusionConvAddBNParam : public OpParam {
N
nhzlx 已提交
1562 1563 1564
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

1565 1566 1567 1568
 public:
  FusionConvAddBNParam(const VariableNameMap &inputs,
                       const VariableNameMap &outputs,
                       const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
1569
    bias_ = InputYFrom<GType>(inputs, scope);
1570
    axis_ = GetAttr<int>("axis", attrs);
N
nhzlx 已提交
1571 1572 1573
    filter_ = FilterFrom<GType>(inputs, scope);
    input_ = InputFrom<GType>(inputs, scope);
    output_y_ = OutputYFrom<GType>(outputs, scope);
1574 1575 1576 1577
    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 已提交
1578 1579 1580 1581
    input_bias_ = InputBiasFrom<GType>(inputs, scope);
    input_mean_ = InputMeanFrom<GType>(inputs, scope);
    input_scale_ = InputScaleFrom<GType>(inputs, scope);
    input_variance_ = InputVarianceFrom<GType>(inputs, scope);
1582 1583 1584 1585
    epsilon_ = GetAttr<float>("epsilon", attrs);
    momentum_ = GetAttr<float>("momentum", attrs);
    //    is_test_ = GetAttr<bool>("is_test", attrs);
  }
N
nhzlx 已提交
1586
  RType *Bias() const { return bias_; }
1587 1588 1589

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

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

1592
#ifdef PADDLE_MOBILE_FPGA
N
nhzlx 已提交
1593
  RType *Filter() const { return filter_; }
1594
#else
N
nhzlx 已提交
1595
  const RType *Filter() const { return filter_; }
1596
#endif
N
nhzlx 已提交
1597
  RType *Output() const { return output_y_; }
1598 1599 1600 1601 1602 1603 1604 1605 1606

  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 已提交
1607
  const RType *InputBias() const { return input_bias_; }
1608

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

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

N
nhzlx 已提交
1613
  const RType *InputVariance() const { return input_variance_; }
1614 1615 1616 1617 1618 1619 1620

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

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

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

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

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

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

N
nhzlx 已提交
1627
  const RType *NewBias() const { return new_bias_; }
1628 1629

 protected:
N
nhzlx 已提交
1630
  RType *bias_;
1631
  int axis_;
N
nhzlx 已提交
1632 1633 1634
  RType *input_;
  RType *output_y_;
  RType *filter_;
1635 1636 1637 1638
  vector<int> strides_;
  vector<int> paddings_;
  vector<int> dilations_;
  int groups;
N
nhzlx 已提交
1639 1640 1641 1642
  RType *input_bias_;
  RType *input_mean_;
  RType *input_scale_;
  RType *input_variance_;
1643 1644 1645
  float epsilon_;
  float momentum_;
  bool is_test_;
N
nhzlx 已提交
1646 1647
  RType *new_bias_;
  RType *new_scale_;
Z
zhangyang 已提交
1648 1649 1650
#ifdef PADDLE_MOBILE_FPGA

 private:
H
hanbuhe 已提交
1651
  fpga::ConvArgs fpga_conv_args;
Z
zhangyang 已提交
1652 1653

 public:
H
hanbuhe 已提交
1654 1655
  const fpga::ConvArgs &FpgaArgs() const { return fpga_conv_args; }
  void SetFpgaArgs(const fpga::ConvArgs &args) { fpga_conv_args = args; }
Z
zhangyang 已提交
1656
#endif
1657
};
E
eclipsess 已提交
1658
#endif
Y
Yao,kun 已提交
1659

E
eclipsess 已提交
1660
#ifdef FUSION_DWCONVBNRELU_OP
N
nhzlx 已提交
1661
template <typename Dtype>
E
eclipsess 已提交
1662
class FusionDWConvBNReluParam : public OpParam {
N
nhzlx 已提交
1663 1664 1665
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

E
eclipsess 已提交
1666 1667 1668 1669
 public:
  FusionDWConvBNReluParam(const VariableNameMap &inputs,
                          const VariableNameMap &outputs,
                          const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
1670 1671 1672
    filter_ = FilterFrom<GType>(inputs, scope);
    input_ = InputFrom<GType>(inputs, scope);
    output_ = OutFrom<GType>(outputs, scope);
E
eclipsess 已提交
1673 1674 1675 1676
    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 已提交
1677 1678 1679 1680
    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 已提交
1681 1682
    epsilon_ = GetAttr<float>("epsilon", attrs);
    momentum_ = GetAttr<float>("momentum", attrs);
1683
    //    is_test_ = GetAttr<bool>("is_test", attrs);
E
eclipsess 已提交
1684 1685
  }

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

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

N
nhzlx 已提交
1690
  RType *Output() const { return output_; }
E
eclipsess 已提交
1691 1692 1693 1694 1695 1696 1697 1698 1699

  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 已提交
1700
  const RType *InputBias() const { return input_bias_; }
E
eclipsess 已提交
1701

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

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

N
nhzlx 已提交
1706
  const RType *InputVariance() const { return input_variance_; }
E
eclipsess 已提交
1707 1708 1709 1710 1711 1712 1713

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

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

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

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

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

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

N
nhzlx 已提交
1720
  const RType *NewBias() const { return new_bias_; }
E
eclipsess 已提交
1721 1722

 protected:
N
nhzlx 已提交
1723 1724 1725
  RType *input_;
  RType *output_;
  RType *filter_;
E
eclipsess 已提交
1726 1727 1728 1729
  vector<int> strides_;
  vector<int> paddings_;
  vector<int> dilations_;
  int groups;
N
nhzlx 已提交
1730 1731 1732 1733
  RType *input_bias_;
  RType *input_mean_;
  RType *input_scale_;
  RType *input_variance_;
E
eclipsess 已提交
1734 1735 1736
  float epsilon_;
  float momentum_;
  bool is_test_;
N
nhzlx 已提交
1737 1738
  RType *new_bias_;
  RType *new_scale_;
E
eclipsess 已提交
1739 1740 1741 1742
};

#endif

1743
#ifdef FUSION_CONVBNRELU_OP
N
nhzlx 已提交
1744
template <typename Dtype>
1745
class FusionConvBNReluParam : public OpParam {
N
nhzlx 已提交
1746 1747 1748
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

1749 1750 1751 1752
 public:
  FusionConvBNReluParam(const VariableNameMap &inputs,
                        const VariableNameMap &outputs,
                        const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
1753 1754 1755
    filter_ = FilterFrom<GType>(inputs, scope);
    input_ = InputFrom<GType>(inputs, scope);
    output_ = OutFrom<GType>(outputs, scope);
1756 1757 1758 1759 1760

    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 已提交
1761 1762 1763 1764
    input_bias_ = InputBiasFrom<GType>(inputs, scope);
    input_mean_ = InputMeanFrom<GType>(inputs, scope);
    input_scale_ = InputScaleFrom<GType>(inputs, scope);
    input_variance_ = InputVarianceFrom<GType>(inputs, scope);
1765 1766 1767 1768 1769
    epsilon_ = GetAttr<float>("epsilon", attrs);
    momentum_ = GetAttr<float>("momentum", attrs);
    //    is_test_ = GetAttr<bool>("is_test", attrs);
  }

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

Z
zhangyang 已提交
1772
#ifdef PADDLE_MOBILE_FPGA
N
nhzlx 已提交
1773
  RType *Filter() const { return filter_; }
Z
zhangyang 已提交
1774
#else
N
nhzlx 已提交
1775
  const RType *Filter() const { return filter_; }
Z
zhangyang 已提交
1776
#endif
1777

N
nhzlx 已提交
1778
  RType *Output() const { return output_; }
1779 1780 1781 1782 1783 1784 1785 1786 1787

  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 已提交
1788
  const RType *InputBias() const { return input_bias_; }
1789

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

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

N
nhzlx 已提交
1794
  const RType *InputVariance() const { return input_variance_; }
1795 1796 1797 1798 1799 1800 1801

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

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

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

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

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

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

N
nhzlx 已提交
1808
  const RType *NewBias() const { return new_bias_; }
1809 1810

 protected:
N
nhzlx 已提交
1811 1812 1813
  RType *input_;
  RType *output_;
  RType *filter_;
1814 1815 1816 1817
  vector<int> strides_;
  vector<int> paddings_;
  vector<int> dilations_;
  int groups;
N
nhzlx 已提交
1818 1819 1820 1821
  RType *input_bias_;
  RType *input_mean_;
  RType *input_scale_;
  RType *input_variance_;
1822 1823 1824
  float epsilon_;
  float momentum_;
  bool is_test_;
N
nhzlx 已提交
1825 1826
  RType *new_bias_;
  RType *new_scale_;
Z
zhangyang 已提交
1827 1828 1829 1830 1831 1832 1833 1834 1835
#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
1836 1837 1838
};
#endif

Y
Yao,kun 已提交
1839
#ifdef IM2SEQUENCE_OP
N
nhzlx 已提交
1840
template <typename Dtype>
Y
Yao,kun 已提交
1841
class Im2SequenceParam : public OpParam {
N
nhzlx 已提交
1842 1843 1844
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

Y
Yao,kun 已提交
1845 1846 1847 1848
 public:
  Im2SequenceParam(const VariableNameMap &inputs,
                   const VariableNameMap &outputs, const AttributeMap &attrs,
                   const Scope &scope) {
N
nhzlx 已提交
1849 1850
    input_x_ = InputXFrom<GType>(inputs, scope);
    out_ = OutFrom<GType>(outputs, scope);
Y
Yao,kun 已提交
1851 1852 1853 1854 1855
    kernels_ = GetAttr<vector<int>>("kernels", attrs);
    strides_ = GetAttr<vector<int>>("strides", attrs);
    paddings_ = GetAttr<vector<int>>("paddings", attrs);
  }

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

N
nhzlx 已提交
1858
  RType *Output() const { return out_; }
Y
Yao,kun 已提交
1859 1860 1861 1862 1863 1864 1865 1866

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

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

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

 private:
N
nhzlx 已提交
1867 1868
  RType *input_x_;
  RType *out_;
Y
Yao,kun 已提交
1869 1870 1871 1872
  vector<int> kernels_;
  vector<int> strides_;
  vector<int> paddings_;
};
1873
#endif
Y
Yao,kun 已提交
1874

1875
#ifdef DROPOUT_OP
N
nhzlx 已提交
1876
template <typename Dtype>
Y
Yao,kun 已提交
1877
class DropoutParam : public OpParam {
N
nhzlx 已提交
1878 1879 1880
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

Y
Yao,kun 已提交
1881 1882 1883
 public:
  DropoutParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
               const AttributeMap &attrs, const Scope &scope) {
N
nhzlx 已提交
1884 1885
    input_x_ = InputXFrom<GType>(inputs, scope);
    out_ = OutFrom<GType>(outputs, scope);
Y
Yao,kun 已提交
1886 1887
  }

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

N
nhzlx 已提交
1890
  RType *Out() const { return out_; }
Y
Yao,kun 已提交
1891 1892

 private:
N
nhzlx 已提交
1893 1894
  RType *input_x_;
  RType *out_;
Y
Yao,kun 已提交
1895
};
1896
#endif
Y
Yao,kun 已提交
1897

L
liuruilong 已提交
1898
#ifdef CONV_TRANSPOSE
N
nhzlx 已提交
1899
template <typename Dtype>
L
liuruilong 已提交
1900
class ConvTransposeParam : public OpParam {
N
nhzlx 已提交
1901 1902 1903
  typedef typename DtypeTensorTrait<Dtype>::gtype GType;
  typedef typename DtypeTensorTrait<Dtype>::rtype RType;

L
liuruilong 已提交
1904 1905 1906 1907
 public:
  ConvTransposeParam(const VariableNameMap &inputs,
                     const VariableNameMap &outputs, const AttributeMap &attrs,
                     const Scope &scope) {
N
nhzlx 已提交
1908 1909 1910
    filter_ = FilterFrom<GType>(inputs, scope);
    input_ = InputFrom<GType>(inputs, scope);
    output_ = OutputFrom<GType>(outputs, scope);
L
liuruilong 已提交
1911 1912 1913 1914 1915 1916
    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 已提交
1917
  const RType *Input() const { return input_; }
L
liuruilong 已提交
1918

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

N
nhzlx 已提交
1921
  RType *Output() const { return output_; }
L
liuruilong 已提交
1922 1923 1924 1925 1926 1927 1928 1929 1930 1931

  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 已提交
1932 1933 1934
  RType *input_;
  RType *output_;
  RType *filter_;
L
liuruilong 已提交
1935 1936 1937 1938 1939 1940 1941
  vector<int> strides_;
  vector<int> paddings_;
  vector<int> dilations_;
  int groups;
};
#endif

朔-望's avatar
朔-望 已提交
1942 1943
}  // namespace operators
}  // namespace paddle_mobile