op_param.h 45.5 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 21 22 23 24
#include "common/type_define.h"
#include "framework/lod_tensor.h"
#include "framework/scope.h"
#include "framework/tensor.h"
#include "framework/variable.h"
Z
zhangyang 已提交
25 26 27
#ifdef PADDLE_MOBILE_FPGA
#include "fpga/api/fpga_api.h"
#endif
朔-望's avatar
朔-望 已提交
28 29

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

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

L
liuruilong 已提交
40
class OpParam {
朔-望's avatar
朔-望 已提交
41
 protected:
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
  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);
  }

E
eclipsess 已提交
57 58 59 60 61
  template <typename T>
  static T *InputZFrom(const VariableNameMap &inputs, const Scope &scope) {
    return GetVarValue<T>("Z", inputs, scope);
  }

62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
  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 已提交
79 80 81 82
  template <typename T>
  static T *InputImageFrom(const VariableNameMap &inputs, const Scope &scope) {
    return GetVarValue<T>("Image", inputs, scope);
  }
E
eclipsess 已提交
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
  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);
  }
99

E
eclipsess 已提交
100 101 102 103 104 105 106 107 108 109
  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 已提交
110 111 112 113
  template <typename T>
  static T *InputShapeFrom(const VariableNameMap &inputs, const Scope &scope) {
    return GetVarValue<T>("Shape", inputs, scope);
  }
E
eclipsess 已提交
114

115
  template <typename T>
W
wangliu 已提交
116 117
  static vector<T *> InputMultiFrom(const VariableNameMap &inputs,
                                    const Scope &scope) {
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
    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 已提交
136 137 138 139 140 141
  template <typename T>
  static T *OutputBoxesFrom(const VariableNameMap &outputs,
                            const Scope &scope) {
    return GetVarValue<T>("Boxes", outputs, scope);
  }

E
eclipsess 已提交
142 143 144 145 146
  template <typename T>
  static T *OutputBoxFrom(const VariableNameMap &outputs, const Scope &scope) {
    return GetVarValue<T>("OutputBox", outputs, scope);
  }

E
eclipsess 已提交
147 148 149 150 151 152
  template <typename T>
  static T *OutputVariancesFrom(const VariableNameMap &outputs,
                                const Scope &scope) {
    return GetVarValue<T>("Variances", outputs, scope);
  }

153 154 155 156 157 158 159 160 161 162 163
  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 已提交
164
  static const T GetAttr(const string &key, const AttributeMap &map) {
165 166 167 168
    return ((Attribute)map.at(key)).Get<T>();
  }

  template <typename T>
W
wangliu 已提交
169
  static T *GetVarValue(const string &key, const VariableNameMap &var_map,
170
                        const Scope &scope) {
W
wangliu 已提交
171 172
    PADDLE_MOBILE_ENFORCE(var_map.count(key) > 0,
                          "%s is not contained in var_map", key.c_str())
173 174 175 176 177 178
    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
朔-望 已提交
179
    }
180
  }
朔-望's avatar
朔-望 已提交
181

182
  template <typename T>
W
wangliu 已提交
183 184 185
  static vector<T *> GetMultiVarValue(const string &key,
                                      const VariableNameMap &var_map,
                                      const Scope &scope) {
186 187
    auto var_vecs = var_map.at(key);
    assert(var_vecs.size() > 1);
W
wangliu 已提交
188
    vector<T *> var_res;
189 190 191
    for (auto &var_vec : var_vecs) {
      auto var = scope.FindVar(var_vec);
      var_res.push_back(var->GetMutable<T>());
朔-望's avatar
朔-望 已提交
192
    }
193 194
    return var_res;
  }
朔-望's avatar
朔-望 已提交
195 196
};

L
liuruilong 已提交
197
#ifdef CONV_OP
朔-望's avatar
朔-望 已提交
198
class ConvParam : OpParam {
朔-望's avatar
朔-望 已提交
199
 public:
200
  ConvParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
201
            const AttributeMap &attrs, const Scope &scope) {
W
wangliu 已提交
202
    filter_ = FilterFrom<LoDTensor>(inputs, scope);
W
wangliu 已提交
203 204
    input_ = InputFrom<LoDTensor>(inputs, scope);
    output_ = OutputFrom<LoDTensor>(outputs, scope);
W
wangliu 已提交
205 206 207
    strides_ = GetAttr<vector<int>>("strides", attrs);
    paddings_ = GetAttr<vector<int>>("paddings", attrs);
    dilations_ = GetAttr<vector<int>>("dilations", attrs);
208 209
    groups = GetAttr<int>("groups", attrs);
  }
朔-望's avatar
朔-望 已提交
210

211
  const Tensor *Input() const { return input_; }
朔-望's avatar
朔-望 已提交
212

C
chonwhite 已提交
213
  Tensor *Filter() const { return filter_; }
朔-望's avatar
朔-望 已提交
214

215
  Tensor *Output() const { return output_; }
朔-望's avatar
朔-望 已提交
216

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

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

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

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

朔-望's avatar
朔-望 已提交
225
 private:
226 227
  Tensor *input_;
  Tensor *output_;
E
eclipsess 已提交
228
  Tensor *filter_;
W
wangliu 已提交
229 230 231
  vector<int> strides_;
  vector<int> paddings_;
  vector<int> dilations_;
232
  int groups;
朔-望's avatar
朔-望 已提交
233 234 235
};

Print &operator<<(Print &printer, const ConvParam &conv_param);
L
liuruilong 已提交
236
#endif
朔-望's avatar
朔-望 已提交
237 238

class ElementwiseAddParam : OpParam {
朔-望's avatar
朔-望 已提交
239
 public:
240
  ElementwiseAddParam(const VariableNameMap &inputs,
241 242 243 244 245
                      const VariableNameMap &outputs, const AttributeMap &attrs,
                      const Scope &scope) {
    input_x_ = InputXFrom<LoDTensor>(inputs, scope);
    input_y_ = InputYFrom<LoDTensor>(inputs, scope);
    out_ = OutFrom<LoDTensor>(outputs, scope);
246 247 248 249 250 251 252 253 254 255 256
    axis_ = GetAttr<int>("axis", attrs);
  }

  const Tensor *InputX() const { return input_x_; }

  const Tensor *InputY() const { return input_y_; }

  Tensor *Out() const { return out_; }

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

朔-望's avatar
朔-望 已提交
257
 private:
258 259 260 261
  Tensor *input_x_;
  Tensor *input_y_;
  Tensor *out_;
  int axis_;
Z
zhangyang 已提交
262 263 264
#ifdef PADDLE_MOBILE_FPGA

 private:
H
hanbuhe 已提交
265
  fpga::EWAddArgs fpga_EW_add_args;
Z
zhangyang 已提交
266 267

 public:
H
hanbuhe 已提交
268 269
  const fpga::EWAddArgs &FpgaArgs() const { return fpga_EW_add_args; }
  void SetFpgaArgs(const fpga::EWAddArgs &args) { fpga_EW_add_args = args; }
Z
zhangyang 已提交
270
#endif
朔-望's avatar
朔-望 已提交
271 272
};

273 274
#ifdef FUSION_ELEMENTWISEADDRELU_OP
using ElementwiseAddReluParam = ElementwiseAddParam;
L
liuruilong 已提交
275 276 277
#endif

#ifdef MUL_OP
朔-望's avatar
朔-望 已提交
278
class MulParam : OpParam {
朔-望's avatar
朔-望 已提交
279
 public:
280
  MulParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
281 282 283 284
           const AttributeMap &attrs, const Scope &scope) {
    input_x_ = InputXFrom<LoDTensor>(inputs, scope);
    input_y_ = InputYFrom<LoDTensor>(inputs, scope);
    out_ = OutFrom<LoDTensor>(outputs, scope);
285 286 287
    x_num_col_dims_ = GetAttr<int>("x_num_col_dims", attrs);
    y_num_col_dims_ = GetAttr<int>("y_num_col_dims", attrs);
  }
朔-望's avatar
朔-望 已提交
288

289
  const Tensor *InputX() const { return input_x_; }
朔-望's avatar
朔-望 已提交
290

291
  const Tensor *InputY() const { return input_y_; }
朔-望's avatar
朔-望 已提交
292

293
  Tensor *Out() const { return out_; }
朔-望's avatar
朔-望 已提交
294

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

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

朔-望's avatar
朔-望 已提交
299
 private:
300 301 302 303 304
  Tensor *input_x_;
  Tensor *input_y_;
  Tensor *out_;
  int x_num_col_dims_;
  int y_num_col_dims_;
朔-望's avatar
朔-望 已提交
305
};
L
liuruilong 已提交
306
#endif
朔-望's avatar
朔-望 已提交
307

L
liuruilong 已提交
308
#ifdef CONCAT_OP
朔-望's avatar
朔-望 已提交
309
class ConcatParam : public OpParam {
朔-望's avatar
朔-望 已提交
310
 public:
311
  ConcatParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
312
              const AttributeMap &attrs, const Scope &scope) {
W
wangliu 已提交
313
    inputs_ = InputMultiFrom<LoDTensor>(inputs, scope);
314
    out_ = OutFrom<LoDTensor>(outputs, scope);
315 316
    axis_ = GetAttr<int>("axis", attrs);
  }
朔-望's avatar
朔-望 已提交
317

W
wangliu 已提交
318
  vector<LoDTensor *> Inputs() const { return inputs_; }
朔-望's avatar
朔-望 已提交
319

320
  Tensor *Out() const { return out_; }
朔-望's avatar
朔-望 已提交
321

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

朔-望's avatar
朔-望 已提交
324
 private:
W
wangliu 已提交
325
  vector<LoDTensor *> inputs_;
326 327
  Tensor *out_;
  int axis_;
朔-望's avatar
朔-望 已提交
328
};
L
liuruilong 已提交
329
#endif
朔-望's avatar
朔-望 已提交
330

L
liuruilong 已提交
331
#ifdef LRN_OP
E
eclipsess 已提交
332
class LrnParam : public OpParam {
朔-望's avatar
朔-望 已提交
333
 public:
334
  LrnParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
335 336 337 338
           const AttributeMap &attrs, const Scope &scope) {
    input_x_ = InputXFrom<LoDTensor>(inputs, scope);
    out_ = OutFrom<LoDTensor>(outputs, scope);
    mid_out_ = MidOutFrom<LoDTensor>(outputs, scope);
339 340 341 342
    n_ = GetAttr<int>("n", attrs);
    alpha_ = GetAttr<float>("alpha", attrs);
    beta_ = GetAttr<float>("beta", attrs);
    k_ = GetAttr<float>("k", attrs);
W
wangliu 已提交
343
    data_format_ = GetAttr<string>("data_format", attrs);
344
  }
E
eclipsess 已提交
345

346
  const Tensor *InputX() const { return input_x_; }
E
eclipsess 已提交
347

348
  Tensor *Out() const { return out_; }
E
eclipsess 已提交
349

350
  Tensor *MidOut() const { return mid_out_; }
E
eclipsess 已提交
351

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

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

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

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

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

朔-望's avatar
朔-望 已提交
362
 private:
363 364 365 366 367 368 369
  Tensor *input_x_;
  Tensor *out_;
  Tensor *mid_out_;
  int n_;
  float alpha_;
  float beta_;
  float k_;
W
wangliu 已提交
370
  string data_format_;
E
eclipsess 已提交
371
};
L
liuruilong 已提交
372 373 374
#endif

#ifdef BATCHNORM_OP
E
eclipsess 已提交
375
class BatchNormParam : OpParam {
朔-望's avatar
朔-望 已提交
376
 public:
377
  BatchNormParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
378 379 380 381 382 383 384
                 const AttributeMap &attrs, const Scope &scope) {
    input_x_ = InputXFrom<LoDTensor>(inputs, scope);
    output_y_ = OutputYFrom<LoDTensor>(outputs, scope);
    input_bias_ = InputBiasFrom<LoDTensor>(inputs, scope);
    input_mean_ = InputMeanFrom<LoDTensor>(inputs, scope);
    input_scale_ = InputScaleFrom<LoDTensor>(inputs, scope);
    input_variance_ = InputVarianceFrom<LoDTensor>(inputs, scope);
385 386
    epsilon_ = GetAttr<float>("epsilon", attrs);
    momentum_ = GetAttr<float>("momentum", attrs);
L
liuruilong 已提交
387
    //    is_test_ = GetAttr<bool>("is_test", attrs);
388
  }
E
eclipsess 已提交
389

390
  const Tensor *InputX() const { return input_x_; }
E
eclipsess 已提交
391

392
  Tensor *OutputY() const { return output_y_; }
E
eclipsess 已提交
393

394
  const Tensor *InputBias() const { return input_bias_; }
E
eclipsess 已提交
395

396
  const Tensor *InputMean() const { return input_mean_; }
E
eclipsess 已提交
397

398
  const Tensor *InputScale() const { return input_scale_; }
E
eclipsess 已提交
399

400
  const Tensor *InputVariance() const { return input_variance_; }
E
eclipsess 已提交
401

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

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

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

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

朔-望's avatar
朔-望 已提交
410
 private:
411 412 413 414 415 416 417 418 419
  Tensor *input_x_;
  Tensor *output_y_;
  Tensor *input_bias_;
  Tensor *input_mean_;
  Tensor *input_scale_;
  Tensor *input_variance_;
  float epsilon_;
  float momentum_;
  bool is_test_;
W
wangliu 已提交
420
  string data_format_;
E
eclipsess 已提交
421
};
L
liuruilong 已提交
422 423 424
#endif

#ifdef POOL_OP
425
class PoolParam : public OpParam {
朔-望's avatar
朔-望 已提交
426
 public:
427
  PoolParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
428 429
            const AttributeMap &attrs, const Scope &scope) {
    input_ = InputXFrom<LoDTensor>(inputs, scope);
430

431
    output_ = OutFrom<LoDTensor>(outputs, scope);
W
wangliu 已提交
432 433 434 435
    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);
436
    ceil_mode_ = GetAttr<bool>("ceil_mode", attrs);
437
    global_pooling_ = GetAttr<bool>("global_pooling", attrs);
438
  }
439

440
  const Tensor *Input() const { return input_; }
441

442
  Tensor *Output() const { return output_; }
443

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

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

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

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

452
  bool isCeilMode() const { return ceil_mode_; }
453

Z
zhangyang 已提交
454
  bool isGlobalPooling() const { return global_pooling_; }
455

朔-望's avatar
朔-望 已提交
456
 private:
457 458
  Tensor *input_;
  Tensor *output_;
W
wangliu 已提交
459 460 461 462
  string pooling_type_;
  vector<int> ksize_;
  vector<int> strides_;
  vector<int> paddings_;
463
  bool ceil_mode_;
464
  bool global_pooling_ = false;
Z
zhangyang 已提交
465
#ifdef PADDLE_MOBILE_FPGA
466 467

 private:
H
hanbuhe 已提交
468
  fpga::PoolingArgs fpga_pool_args;
Z
zhangyang 已提交
469 470

 public:
H
hanbuhe 已提交
471 472
  const fpga::PoolingArgs &FpgaArgs() const { return fpga_pool_args; }
  void SetFpgaArgs(const fpga::PoolingArgs &args) { fpga_pool_args = args; }
Z
zhangyang 已提交
473
#endif
474
};
L
liuruilong 已提交
475 476 477
#endif

#ifdef PRIORBOX_OP
E
eclipsess 已提交
478 479 480
class PriorBoxParam : public OpParam {
 public:
  PriorBoxParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
481 482 483 484 485
                const AttributeMap &attrs, const Scope &scope) {
    input_ = InputFrom<LoDTensor>(inputs, scope);
    input_image_ = InputImageFrom<LoDTensor>(inputs, scope);
    output_boxes_ = OutputBoxesFrom<LoDTensor>(outputs, scope);
    output_variances_ = OutputVariancesFrom<LoDTensor>(outputs, scope);
W
wangliu 已提交
486 487 488 489
    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 已提交
490 491 492 493 494 495 496 497 498 499 500 501 502 503
    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);
  }
  const Tensor *Input() const { return input_; }

  const Tensor *InputImage() const { return input_image_; }

  Tensor *OutputBoxes() const { return output_boxes_; }

  Tensor *OutputVariances() const { return output_variances_; }

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

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

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

W
wangliu 已提交
510
  const vector<float> &Variances() const { return variances_; }
E
eclipsess 已提交
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526

  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:
  Tensor *input_;
  Tensor *input_image_;
  Tensor *output_boxes_;
  Tensor *output_variances_;
W
wangliu 已提交
527 528 529 530
  vector<float> min_sizes_;
  vector<float> max_sizes_;
  vector<float> aspect_ratios_;
  vector<float> variances_;
E
eclipsess 已提交
531 532 533 534 535 536
  bool flip_;
  bool clip_;
  float step_w_;
  float step_h_;
  float offset_;
};
L
liuruilong 已提交
537
#endif
E
eclipsess 已提交
538

L
liuruilong 已提交
539
#ifdef BOXCODER_OP
E
eclipsess 已提交
540 541 542
class BoxCoderParam : public OpParam {
 public:
  BoxCoderParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
543 544 545 546 547
                const AttributeMap &attrs, const Scope &scope) {
    input_priorbox_ = InputPriorBoxFrom<LoDTensor>(inputs, scope);
    input_priorboxvar_ = InputPriorBoxVarFrom<LoDTensor>(inputs, scope);
    input_targetbox_ = InputTargetBoxFrom<LoDTensor>(inputs, scope);
    output_box_ = OutputBoxFrom<LoDTensor>(outputs, scope);
E
eclipsess 已提交
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566
    code_type_ = GetAttr<std::string>("code_type", attrs);
  }
  const Tensor *InputPriorBox() const { return input_priorbox_; }

  const Tensor *InputPriorBoxVar() const { return input_priorboxvar_; }

  const Tensor *InputTargetBox() const { return input_targetbox_; }

  Tensor *OutputBox() const { return output_box_; }

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

 private:
  Tensor *input_priorbox_;
  Tensor *input_priorboxvar_;
  Tensor *input_targetbox_;
  Tensor *output_box_;
  std::string code_type_;
};
L
liuruilong 已提交
567
#endif
W
wangliu 已提交
568

L
liuruilong 已提交
569
#ifdef SOFTMAX_OP
W
wangliu 已提交
570 571 572
class SoftmaxParam : public OpParam {
 public:
  SoftmaxParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
573 574 575
               const AttributeMap &attrs, const Scope &scope) {
    input_x_ = InputXFrom<LoDTensor>(inputs, scope);
    out_ = OutFrom<LoDTensor>(outputs, scope);
W
wangliu 已提交
576 577 578 579 580 581 582 583
  }
  const Tensor *InputX() const { return input_x_; }
  Tensor *Out() const { return out_; }

 private:
  Tensor *input_x_;
  Tensor *out_;
};
L
liuruilong 已提交
584
#endif
W
wangliu 已提交
585

L
liuruilong 已提交
586
#ifdef SIGMOID_OP
W
wangliu 已提交
587 588 589
class SigmoidParam : public OpParam {
 public:
  SigmoidParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
590 591 592
               const AttributeMap &attrs, const Scope &scope) {
    input_x_ = InputXFrom<LoDTensor>(inputs, scope);
    out_ = OutFrom<LoDTensor>(outputs, scope);
W
wangliu 已提交
593 594 595 596 597 598 599 600
  }
  const Tensor *InputX() const { return input_x_; }
  Tensor *Out() const { return out_; }

 private:
  Tensor *input_x_;
  Tensor *out_;
};
L
liuruilong 已提交
601 602 603
#endif

#ifdef MULTICLASSNMS_OP
E
eclipsess 已提交
604 605 606 607 608
class MultiClassNMSParam : public OpParam {
 public:
  MultiClassNMSParam(const VariableNameMap &inputs,
                     const VariableNameMap &outputs, const AttributeMap &attrs,
                     const Scope &scope) {
W
wangliu 已提交
609 610 611
    input_bboxes_ = InputBBoxesFrom<LoDTensor>(inputs, scope);
    input_scores_ = InputScoresFrom<LoDTensor>(inputs, scope);
    out_ = OutFrom<LoDTensor>(outputs, scope);
E
eclipsess 已提交
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648
    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);
  }

  const Tensor *InputBBoxes() const { return input_bboxes_; }

  const Tensor *InputScores() const { return input_scores_; }

  Tensor *Out() const { return out_; }

  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:
  Tensor *input_bboxes_;
  Tensor *input_scores_;
  Tensor *out_;
  int background_label_;
  int nms_top_k_;
  int keep_top_k_;
  float nms_threshold_;
  float nms_eta_;
  float score_threshold_;
};
L
liuruilong 已提交
649
#endif
W
wangliu 已提交
650

L
liuruilong 已提交
651 652 653
class FeedParam : public OpParam {
 public:
  FeedParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
L
liuruilong 已提交
654 655 656 657
            const AttributeMap &attrs, Scope *scope) {
    input_x_ = InputXFrom<LoDTensor>(inputs, *scope);
    out_ = OutFrom<LoDTensor>(outputs, *scope);
    auto var = scope->Var("batch_size");
W
wangliu 已提交
658
    batch_size = var->GetValue<int>();
L
liuruilong 已提交
659 660 661
  }
  const Tensor *InputX() const { return input_x_; }
  Tensor *Out() const { return out_; }
W
wangliu 已提交
662
  const int BatchSize() const { return batch_size; }
L
liuruilong 已提交
663

L
liuruilong 已提交
664 665 666
 private:
  Tensor *input_x_;
  Tensor *out_;
W
wangliu 已提交
667
  int batch_size;
L
liuruilong 已提交
668 669 670 671 672
};

class FetchParam : public OpParam {
 public:
  FetchParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
673 674 675
             const AttributeMap &attrs, const Scope &scope) {
    input_x_ = InputXFrom<LoDTensor>(inputs, scope);
    out_ = OutFrom<LoDTensor>(outputs, scope);
L
liuruilong 已提交
676 677 678
  }
  const Tensor *InputX() const { return input_x_; }
  Tensor *Out() const { return out_; }
L
liuruilong 已提交
679

L
liuruilong 已提交
680 681 682 683 684
 private:
  Tensor *input_x_;
  Tensor *out_;
};

L
liuruilong 已提交
685
#ifdef TRANSPOSE_OP
E
eclipsess 已提交
686 687 688 689
class TransposeParam : public OpParam {
 public:
  TransposeParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
                 const AttributeMap &attrs, const Scope &scope) {
W
wangliu 已提交
690 691
    input_x_ = InputXFrom<LoDTensor>(inputs, scope);
    out_ = OutFrom<LoDTensor>(outputs, scope);
E
eclipsess 已提交
692 693 694 695 696 697 698 699 700 701 702 703 704 705
    axis_ = GetAttr<vector<int>>("axis", attrs);
  }

  const Tensor *InputX() const { return input_x_; }

  Tensor *Out() const { return out_; }

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

 private:
  Tensor *input_x_;
  Tensor *out_;
  vector<int> axis_;
};
L
liuruilong 已提交
706
#endif
E
eclipsess 已提交
707

L
liuruilong 已提交
708
#ifdef RESHAPE_OP
E
eclipsess 已提交
709 710 711 712
class ReshapeParam : public OpParam {
 public:
  ReshapeParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
               const AttributeMap &attrs, const Scope &scope) {
W
wangliu 已提交
713 714 715
    input_x_ = InputXFrom<LoDTensor>(inputs, scope);
    input_shape_ = InputShapeFrom<LoDTensor>(inputs, scope);
    out_ = OutFrom<LoDTensor>(outputs, scope);
E
eclipsess 已提交
716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736
    shape_ = GetAttr<vector<int>>("shape", attrs);
    inplace_ = GetAttr<bool>("inplace", attrs);
  }

  const Tensor *InputX() const { return input_x_; }

  const Tensor *InputShape() const { return input_shape_; }

  Tensor *Out() const { return out_; }

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

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

 private:
  Tensor *input_x_;
  Tensor *input_shape_;
  Tensor *out_;
  vector<int> shape_;
  bool inplace_;
};
L
liuruilong 已提交
737
#endif
E
eclipsess 已提交
738

T
Tian 已提交
739
#ifdef SCALE_OP
I
itminner 已提交
740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775
class ScaleParam : public OpParam {
 public:
  ScaleParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
             const AttributeMap &attrs, const Scope &scope) {
    input_x_ = InputXFrom<LoDTensor>(inputs, scope);
    input_bias_ = InputBiasFrom<framework::LoDTensor>(inputs, scope);
    out_ = OutFrom<LoDTensor>(outputs, scope);
    inplace_ = GetAttr<bool>("inplace", attrs);
    has_bias_ = GetAttr<bool>("has_bias", attrs);
    scales_ = GetAttr<vector<float>>("scales", attrs);
    biases_ = GetAttr<vector<float>>("biases", attrs);
  }

  const Tensor *InputX() const { return input_x_; }

  const Tensor *InputBias() const { return input_bias_; }

  Tensor *Out() const { return out_; }

  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:
  Tensor *input_x_;
  Tensor *input_bias_;
  Tensor *out_;
  bool inplace_;
  bool has_bias_;
  vector<float> scales_;
  vector<float> biases_;
};
T
Tian 已提交
776 777 778
#endif

#ifdef SLICE_OP
I
itminner 已提交
779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810
class SliceParam : public OpParam {
 public:
  SliceParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
             const AttributeMap &attrs, const Scope &scope) {
    input_x_ = InputXFrom<LoDTensor>(inputs, scope);
    input_shape_ = InputShapeFrom<LoDTensor>(inputs, scope);
    out_ = OutFrom<LoDTensor>(outputs, scope);
    axis_ = GetAttr<int>("axis", attrs);
    slice_points_ = GetAttr<vector<int>>("slice_points", attrs);
    inplace_ = GetAttr<bool>("inplace", attrs);
  }

  const Tensor *InputX() const { return input_x_; }

  const Tensor *InputShape() const { return input_shape_; }

  Tensor *Out() const { return out_; }

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

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

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

 private:
  Tensor *input_x_;
  Tensor *input_shape_;
  Tensor *out_;
  int axis_;
  vector<int> slice_points_;
  bool inplace_;
};
T
Tian 已提交
811 812 813 814
#endif

#ifdef RESIZE_OP
class ResizeParam : public OpParam {
I
itminner 已提交
815 816 817 818 819 820 821 822 823 824 825 826
 public:
  ResizeParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
              const AttributeMap &attrs, const Scope &scope) {
    input_x_ = InputXFrom<LoDTensor>(inputs, scope);
    input_shape_ = InputShapeFrom<LoDTensor>(inputs, scope);
    out_ = OutFrom<LoDTensor>(outputs, scope);
    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 已提交
827

I
itminner 已提交
828
  const Tensor *InputX() const { return input_x_; }
T
Tian 已提交
829

I
itminner 已提交
830
  const Tensor *InputShape() const { return input_shape_; }
T
Tian 已提交
831

I
itminner 已提交
832
  Tensor *Out() const { return out_; }
T
Tian 已提交
833

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

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

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

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

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

I
itminner 已提交
844 845 846 847 848 849 850 851 852
 private:
  Tensor *input_x_;
  Tensor *input_shape_;
  Tensor *out_;
  bool is_pyramid_test_;
  int height_;
  int width_;
  float out_height_scale_;
  float out_width_scale_;
T
Tian 已提交
853 854 855
};
#endif

L
liuruilong 已提交
856
#ifdef RELU_OP
L
liuruilong 已提交
857 858 859
/*
 * @b op 层实例化好这个 param 传递给 kernel 层使用
 * */
E
eclipsess 已提交
860 861 862 863
class ReluParam : public OpParam {
 public:
  ReluParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
            const AttributeMap &attrs, const Scope &scope) {
W
wangliu 已提交
864 865
    input_x_ = InputXFrom<LoDTensor>(inputs, scope);
    out_ = OutFrom<LoDTensor>(outputs, scope);
E
eclipsess 已提交
866 867 868 869 870 871 872 873 874 875
  }

  const Tensor *InputX() const { return input_x_; }

  Tensor *Out() const { return out_; }

 private:
  Tensor *input_x_;
  Tensor *out_;
};
L
liuruilong 已提交
876
#endif
E
eclipsess 已提交
877

T
Tian 已提交
878 879
#ifdef PRELU_OP
class PReluParam : public OpParam {
I
itminner 已提交
880 881 882 883 884 885 886
 public:
  PReluParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
             const AttributeMap &attrs, const Scope &scope) {
    input_x_ = InputXFrom<LoDTensor>(inputs, scope);
    out_ = OutFrom<LoDTensor>(outputs, scope);
    slopes_ = GetAttr<vector<float>>("slopes", attrs);
  }
T
Tian 已提交
887

I
itminner 已提交
888 889 890
  const Tensor *InputX() const { return input_x_; }
  Tensor *Out() const { return out_; }
  const vector<float> &Slopes() const { return slopes_; }
T
Tian 已提交
891

I
itminner 已提交
892 893 894 895
 private:
  Tensor *input_x_;
  Tensor *out_;
  vector<float> slopes_;
T
Tian 已提交
896 897 898
};
#endif

L
liuruilong 已提交
899
class FusionFcParam : public OpParam {
E
eclipsess 已提交
900
 public:
L
liuruilong 已提交
901
  FusionFcParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
L
liuruilong 已提交
902
                const AttributeMap &attrs, const Scope &scope) {
E
eclipsess 已提交
903 904 905 906
    input_x_ = InputXFrom<LoDTensor>(inputs, scope);
    input_y_ = InputYFrom<LoDTensor>(inputs, scope);
    input_z_ = InputZFrom<LoDTensor>(inputs, scope);
    out_ = OutFrom<LoDTensor>(outputs, scope);
E
eclipsess 已提交
907 908 909 910 911 912
    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);
  }
  const Tensor *InputX() const { return input_x_; }

913 914 915
#ifdef PADDLE_MOBILE_FPGA
  Tensor *InputY() const { return input_y_; }
#else
E
eclipsess 已提交
916
  const Tensor *InputY() const { return input_y_; }
917
#endif
E
eclipsess 已提交
918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936

  const Tensor *InputZ() const { return input_z_; }

  Tensor *Out() const { return out_; }

  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:
  Tensor *input_x_;
  Tensor *input_y_;
  Tensor *input_z_;
  Tensor *out_;
  int x_num_col_dims_;
  int y_num_col_dims_;
  int axis_;
Z
zhangyang 已提交
937 938 939
#ifdef PADDLE_MOBILE_FPGA

 private:
H
hanbuhe 已提交
940
  fpga::ConvArgs fpga_conv_args;
Z
zhangyang 已提交
941 942

 public:
H
hanbuhe 已提交
943 944
  const fpga::ConvArgs &FpgaArgs() const { return fpga_conv_args; }
  void SetFpgaArgs(const fpga::ConvArgs &args) { fpga_conv_args = args; }
Z
zhangyang 已提交
945
#endif
E
eclipsess 已提交
946
};
947 948 949

#ifdef FUSION_FCRELU_OP
using FusionFcReluParam = FusionFcParam;
L
liuruilong 已提交
950
#endif
E
eclipsess 已提交
951

L
liuruilong 已提交
952
class FusionConvAddParam : public OpParam {
W
wangliu 已提交
953
 public:
L
liuruilong 已提交
954
  FusionConvAddParam(const VariableNameMap &inputs,
L
liuruilong 已提交
955 956
                     const VariableNameMap &outputs, const AttributeMap &attrs,
                     const Scope &scope) {
W
wangliu 已提交
957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972
    bias_ = InputYFrom<LoDTensor>(inputs, scope);
    axis_ = GetAttr<int>("axis", attrs);
    filter_ = FilterFrom<LoDTensor>(inputs, scope);
    input_ = InputFrom<LoDTensor>(inputs, scope);
    output_ = OutFrom<LoDTensor>(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);
  }
  Tensor *Bias() const { return bias_; }

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

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

973 974 975
#ifdef PADDLE_MOBILE_FPGA
  Tensor *Filter() const { return filter_; }
#else
W
wangliu 已提交
976
  const Tensor *Filter() const { return filter_; }
977
#endif
W
wangliu 已提交
978 979 980 981 982 983 984 985 986 987 988

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

L
liuruilong 已提交
989
 protected:
W
wangliu 已提交
990 991 992 993 994 995 996 997 998
  Tensor *bias_;
  int axis_;
  Tensor *input_;
  Tensor *output_;
  Tensor *filter_;
  vector<int> strides_;
  vector<int> paddings_;
  vector<int> dilations_;
  int groups;
Z
zhangyang 已提交
999 1000 1001
#ifdef PADDLE_MOBILE_FPGA

 private:
H
hanbuhe 已提交
1002
  fpga::ConvArgs fpga_conv_args;
Z
zhangyang 已提交
1003 1004

 public:
H
hanbuhe 已提交
1005 1006
  const fpga::ConvArgs &FpgaArgs() const { return fpga_conv_args; }
  void SetFpgaArgs(const fpga::ConvArgs &args) { fpga_conv_args = args; }
Z
zhangyang 已提交
1007
#endif
W
wangliu 已提交
1008 1009
};

L
liuruilong 已提交
1010
Print &operator<<(Print &printer, const FusionConvAddParam &conv_param);
W
wangliu 已提交
1011

Z
zhangyang 已提交
1012
#ifdef FUSION_CONVADDRELU_OP
L
liuruilong 已提交
1013
class FusionConvAddReluParam : public FusionConvAddParam {
L
liuruilong 已提交
1014
 public:
L
liuruilong 已提交
1015
  FusionConvAddReluParam(const VariableNameMap &inputs,
L
liuruilong 已提交
1016 1017
                         const VariableNameMap &outputs,
                         const AttributeMap &attrs, const Scope &scope)
L
liuruilong 已提交
1018
      : FusionConvAddParam(inputs, outputs, attrs, scope) {}
L
liuruilong 已提交
1019 1020 1021
};
#endif

E
eclipsess 已提交
1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036
#ifdef FUSION_CONVADDBNRELU_OP
class FusionConvAddBNReluParam : public OpParam {
 public:
  FusionConvAddBNReluParam(const VariableNameMap &inputs,
                           const VariableNameMap &outputs,
                           const AttributeMap &attrs, const Scope &scope) {
    bias_ = InputYFrom<LoDTensor>(inputs, scope);
    axis_ = GetAttr<int>("axis", attrs);
    filter_ = FilterFrom<LoDTensor>(inputs, scope);
    input_ = InputFrom<LoDTensor>(inputs, scope);
    output_ = OutFrom<LoDTensor>(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);
1037 1038 1039 1040
    input_bias_ = InputBiasFrom<LoDTensor>(inputs, scope);
    input_mean_ = InputMeanFrom<LoDTensor>(inputs, scope);
    input_scale_ = InputScaleFrom<LoDTensor>(inputs, scope);
    input_variance_ = InputVarianceFrom<LoDTensor>(inputs, scope);
E
eclipsess 已提交
1041 1042
    epsilon_ = GetAttr<float>("epsilon", attrs);
    momentum_ = GetAttr<float>("momentum", attrs);
L
liuruilong 已提交
1043
    //    is_test_ = GetAttr<bool>("is_test", attrs);
E
eclipsess 已提交
1044 1045 1046 1047 1048 1049 1050
  }
  Tensor *Bias() const { return bias_; }

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

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

1051 1052 1053
#ifdef PADDLE_MOBILE_FPGA
  Tensor *Filter() const { return filter_; }
#else
E
eclipsess 已提交
1054
  const Tensor *Filter() const { return filter_; }
1055
#endif
E
eclipsess 已提交
1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107

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

  const Tensor *InputBias() const { return input_bias_; }

  const Tensor *InputMean() const { return input_mean_; }

  const Tensor *InputScale() const { return input_scale_; }

  const Tensor *InputVariance() const { return input_variance_; }

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

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

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

  void SetNewScale(Tensor *new_scale) { new_scale_ = new_scale; }

  void SetNewBias(Tensor *new_bias) { new_bias_ = new_bias; }

  const Tensor *NewScale() const { return new_scale_; }

  const Tensor *NewBias() const { return new_bias_; }

 protected:
  Tensor *bias_;
  int axis_;
  Tensor *input_;
  Tensor *output_;
  Tensor *filter_;
  vector<int> strides_;
  vector<int> paddings_;
  vector<int> dilations_;
  int groups;
  Tensor *input_bias_;
  Tensor *input_mean_;
  Tensor *input_scale_;
  Tensor *input_variance_;
  float epsilon_;
  float momentum_;
  bool is_test_;
  Tensor *new_bias_;
  Tensor *new_scale_;
Z
zhangyang 已提交
1108 1109 1110
#ifdef PADDLE_MOBILE_FPGA

 private:
H
hanbuhe 已提交
1111
  fpga::ConvArgs fpga_conv_args;
Z
zhangyang 已提交
1112 1113

 public:
H
hanbuhe 已提交
1114 1115
  const fpga::ConvArgs &FpgaArgs() const { return fpga_conv_args; }
  void SetFpgaArgs(const fpga::ConvArgs &args) { fpga_conv_args = args; }
Z
zhangyang 已提交
1116
#endif
E
eclipsess 已提交
1117
};
1118
#endif
E
eclipsess 已提交
1119

Z
zhangyang 已提交
1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209
#ifdef FUSION_CONVBN_OP
class FusionConvBNParam : public OpParam {
 public:
  FusionConvBNParam(const VariableNameMap &inputs,
                    const VariableNameMap &outputs, const AttributeMap &attrs,
                    const Scope &scope) {
    filter_ = FilterFrom<LoDTensor>(inputs, scope);
    input_ = InputFrom<LoDTensor>(inputs, scope);
    output_y_ = OutputYFrom<LoDTensor>(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);
    input_bias_ = InputBiasFrom<LoDTensor>(inputs, scope);
    input_mean_ = InputMeanFrom<LoDTensor>(inputs, scope);
    input_scale_ = InputScaleFrom<LoDTensor>(inputs, scope);
    input_variance_ = InputVarianceFrom<LoDTensor>(inputs, scope);
    epsilon_ = GetAttr<float>("epsilon", attrs);
    momentum_ = GetAttr<float>("momentum", attrs);
    //    is_test_ = GetAttr<bool>("is_test", attrs);
  }

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

#ifdef PADDLE_MOBILE_FPGA
  Tensor *Filter() const { return filter_; }
#else
  const Tensor *Filter() const { return filter_; }
#endif
  Tensor *Output() const { return output_y_; }

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

  const Tensor *InputBias() const { return input_bias_; }

  const Tensor *InputMean() const { return input_mean_; }

  const Tensor *InputScale() const { return input_scale_; }

  const Tensor *InputVariance() const { return input_variance_; }

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

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

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

  void SetNewScale(Tensor *new_scale) { new_scale_ = new_scale; }

  void SetNewBias(Tensor *new_bias) { new_bias_ = new_bias; }

  const Tensor *NewScale() const { return new_scale_; }

  const Tensor *NewBias() const { return new_bias_; }

 protected:
  Tensor *input_;
  Tensor *output_y_;
  Tensor *filter_;
  vector<int> strides_;
  vector<int> paddings_;
  vector<int> dilations_;
  int groups;
  Tensor *input_bias_;
  Tensor *input_mean_;
  Tensor *input_scale_;
  Tensor *input_variance_;
  float epsilon_;
  float momentum_;
  bool is_test_;
  Tensor *new_bias_;
  Tensor *new_scale_;
#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

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
#ifdef FUSION_CONVADDBN_OP
class FusionConvAddBNParam : public OpParam {
 public:
  FusionConvAddBNParam(const VariableNameMap &inputs,
                       const VariableNameMap &outputs,
                       const AttributeMap &attrs, const Scope &scope) {
    bias_ = InputYFrom<LoDTensor>(inputs, scope);
    axis_ = GetAttr<int>("axis", attrs);
    filter_ = FilterFrom<LoDTensor>(inputs, scope);
    input_ = InputFrom<LoDTensor>(inputs, scope);
    output_y_ = OutputYFrom<LoDTensor>(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);
    input_bias_ = InputBiasFrom<LoDTensor>(inputs, scope);
    input_mean_ = InputMeanFrom<LoDTensor>(inputs, scope);
    input_scale_ = InputScaleFrom<LoDTensor>(inputs, scope);
    input_variance_ = InputVarianceFrom<LoDTensor>(inputs, scope);
    epsilon_ = GetAttr<float>("epsilon", attrs);
    momentum_ = GetAttr<float>("momentum", attrs);
    //    is_test_ = GetAttr<bool>("is_test", attrs);
  }
  Tensor *Bias() const { return bias_; }

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

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

1239 1240 1241
#ifdef PADDLE_MOBILE_FPGA
  Tensor *Filter() const { return filter_; }
#else
1242
  const Tensor *Filter() const { return filter_; }
1243
#endif
Z
zhangyang 已提交
1244
  Tensor *Output() const { return output_y_; }
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

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

  const Tensor *InputBias() const { return input_bias_; }

  const Tensor *InputMean() const { return input_mean_; }

  const Tensor *InputScale() const { return input_scale_; }

  const Tensor *InputVariance() const { return input_variance_; }

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

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

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

  void SetNewScale(Tensor *new_scale) { new_scale_ = new_scale; }

  void SetNewBias(Tensor *new_bias) { new_bias_ = new_bias; }

  const Tensor *NewScale() const { return new_scale_; }

  const Tensor *NewBias() const { return new_bias_; }

 protected:
  Tensor *bias_;
  int axis_;
  Tensor *input_;
  Tensor *output_y_;
  Tensor *filter_;
  vector<int> strides_;
  vector<int> paddings_;
  vector<int> dilations_;
  int groups;
  Tensor *input_bias_;
  Tensor *input_mean_;
  Tensor *input_scale_;
  Tensor *input_variance_;
  float epsilon_;
  float momentum_;
  bool is_test_;
  Tensor *new_bias_;
  Tensor *new_scale_;
Z
zhangyang 已提交
1295 1296 1297
#ifdef PADDLE_MOBILE_FPGA

 private:
H
hanbuhe 已提交
1298
  fpga::ConvArgs fpga_conv_args;
Z
zhangyang 已提交
1299 1300

 public:
H
hanbuhe 已提交
1301 1302
  const fpga::ConvArgs &FpgaArgs() const { return fpga_conv_args; }
  void SetFpgaArgs(const fpga::ConvArgs &args) { fpga_conv_args = args; }
Z
zhangyang 已提交
1303
#endif
1304
};
E
eclipsess 已提交
1305
#endif
Y
Yao,kun 已提交
1306

E
eclipsess 已提交
1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325
#ifdef FUSION_DWCONVBNRELU_OP
class FusionDWConvBNReluParam : public OpParam {
 public:
  FusionDWConvBNReluParam(const VariableNameMap &inputs,
                          const VariableNameMap &outputs,
                          const AttributeMap &attrs, const Scope &scope) {
    filter_ = FilterFrom<LoDTensor>(inputs, scope);
    input_ = InputFrom<LoDTensor>(inputs, scope);
    output_ = OutFrom<LoDTensor>(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);
    input_bias_ = InputBiasFrom<LoDTensor>(inputs, scope);
    input_mean_ = InputMeanFrom<LoDTensor>(inputs, scope);
    input_scale_ = InputScaleFrom<LoDTensor>(inputs, scope);
    input_variance_ = InputVarianceFrom<LoDTensor>(inputs, scope);
    epsilon_ = GetAttr<float>("epsilon", attrs);
    momentum_ = GetAttr<float>("momentum", attrs);
1326
    //    is_test_ = GetAttr<bool>("is_test", attrs);
E
eclipsess 已提交
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 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386
  }

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

  const Tensor *Filter() const { return filter_; }

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

  const Tensor *InputBias() const { return input_bias_; }

  const Tensor *InputMean() const { return input_mean_; }

  const Tensor *InputScale() const { return input_scale_; }

  const Tensor *InputVariance() const { return input_variance_; }

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

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

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

  void SetNewScale(Tensor *new_scale) { new_scale_ = new_scale; }

  void SetNewBias(Tensor *new_bias) { new_bias_ = new_bias; }

  const Tensor *NewScale() const { return new_scale_; }

  const Tensor *NewBias() const { return new_bias_; }

 protected:
  Tensor *input_;
  Tensor *output_;
  Tensor *filter_;
  vector<int> strides_;
  vector<int> paddings_;
  vector<int> dilations_;
  int groups;
  Tensor *input_bias_;
  Tensor *input_mean_;
  Tensor *input_scale_;
  Tensor *input_variance_;
  float epsilon_;
  float momentum_;
  bool is_test_;
  Tensor *new_bias_;
  Tensor *new_scale_;
};

Print &operator<<(Print &printer, const FusionConvAddParam &conv_param);
#endif

1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411
#ifdef FUSION_CONVBNRELU_OP
class FusionConvBNReluParam : public OpParam {
 public:
  FusionConvBNReluParam(const VariableNameMap &inputs,
                        const VariableNameMap &outputs,
                        const AttributeMap &attrs, const Scope &scope) {
    filter_ = FilterFrom<LoDTensor>(inputs, scope);
    input_ = InputFrom<LoDTensor>(inputs, scope);
    output_ = OutFrom<LoDTensor>(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);
    input_bias_ = InputBiasFrom<LoDTensor>(inputs, scope);
    input_mean_ = InputMeanFrom<LoDTensor>(inputs, scope);
    input_scale_ = InputScaleFrom<LoDTensor>(inputs, scope);
    input_variance_ = InputVarianceFrom<LoDTensor>(inputs, scope);
    epsilon_ = GetAttr<float>("epsilon", attrs);
    momentum_ = GetAttr<float>("momentum", attrs);
    //    is_test_ = GetAttr<bool>("is_test", attrs);
  }

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

Z
zhangyang 已提交
1412 1413 1414
#ifdef PADDLE_MOBILE_FPGA
  Tensor *Filter() const { return filter_; }
#else
1415
  const Tensor *Filter() const { return filter_; }
Z
zhangyang 已提交
1416
#endif
1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466

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

  const Tensor *InputBias() const { return input_bias_; }

  const Tensor *InputMean() const { return input_mean_; }

  const Tensor *InputScale() const { return input_scale_; }

  const Tensor *InputVariance() const { return input_variance_; }

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

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

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

  void SetNewScale(Tensor *new_scale) { new_scale_ = new_scale; }

  void SetNewBias(Tensor *new_bias) { new_bias_ = new_bias; }

  const Tensor *NewScale() const { return new_scale_; }

  const Tensor *NewBias() const { return new_bias_; }

 protected:
  Tensor *input_;
  Tensor *output_;
  Tensor *filter_;
  vector<int> strides_;
  vector<int> paddings_;
  vector<int> dilations_;
  int groups;
  Tensor *input_bias_;
  Tensor *input_mean_;
  Tensor *input_scale_;
  Tensor *input_variance_;
  float epsilon_;
  float momentum_;
  bool is_test_;
  Tensor *new_bias_;
  Tensor *new_scale_;
Z
zhangyang 已提交
1467 1468 1469 1470 1471 1472 1473 1474 1475
#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
1476 1477 1478
};
#endif

Y
Yao,kun 已提交
1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508
#ifdef IM2SEQUENCE_OP
class Im2SequenceParam : public OpParam {
 public:
  Im2SequenceParam(const VariableNameMap &inputs,
                   const VariableNameMap &outputs, const AttributeMap &attrs,
                   const Scope &scope) {
    input_x_ = InputXFrom<LoDTensor>(inputs, scope);
    out_ = OutFrom<LoDTensor>(outputs, scope);
    kernels_ = GetAttr<vector<int>>("kernels", attrs);
    strides_ = GetAttr<vector<int>>("strides", attrs);
    paddings_ = GetAttr<vector<int>>("paddings", attrs);
  }

  const Tensor *Input() const { return input_x_; }

  Tensor *Output() const { return out_; }

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

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

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

 private:
  Tensor *input_x_;
  Tensor *out_;
  vector<int> kernels_;
  vector<int> strides_;
  vector<int> paddings_;
};
1509
#endif
Y
Yao,kun 已提交
1510

1511
#ifdef DROPOUT_OP
Y
Yao,kun 已提交
1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527
class DropoutParam : public OpParam {
 public:
  DropoutParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
               const AttributeMap &attrs, const Scope &scope) {
    input_x_ = InputXFrom<LoDTensor>(inputs, scope);
    out_ = OutFrom<LoDTensor>(outputs, scope);
  }

  const Tensor *InputX() const { return input_x_; }

  Tensor *Out() const { return out_; }

 private:
  Tensor *input_x_;
  Tensor *out_;
};
1528
#endif
Y
Yao,kun 已提交
1529

L
liuruilong 已提交
1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569
#ifdef CONV_TRANSPOSE
class ConvTransposeParam : public OpParam {
 public:
  ConvTransposeParam(const VariableNameMap &inputs,
                     const VariableNameMap &outputs, const AttributeMap &attrs,
                     const Scope &scope) {
    filter_ = FilterFrom<LoDTensor>(inputs, scope);
    input_ = InputFrom<LoDTensor>(inputs, scope);
    output_ = OutputFrom<LoDTensor>(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 Tensor *Input() const { return input_; }

  const Tensor *Filter() const { return filter_; }

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

 private:
  Tensor *input_;
  Tensor *output_;
  Tensor *filter_;
  vector<int> strides_;
  vector<int> paddings_;
  vector<int> dilations_;
  int groups;
};
#endif

朔-望's avatar
朔-望 已提交
1570 1571
}  // namespace operators
}  // namespace paddle_mobile