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

#pragma once
16
#include <memory>
Y
Yan Chunwei 已提交
17
#include <string>
18
#include <utility>
Y
Yan Chunwei 已提交
19
#include <vector>
20
#include "lite/api/paddle_place.h"
Y
Yan Chunwei 已提交
21 22
#include "lite/core/scope.h"
#include "lite/core/tensor.h"
23
#include "lite/core/types.h"
Y
Yan Chunwei 已提交
24 25 26
#include "lite/model_parser/cpp/block_desc.h"
#include "lite/model_parser/desc_apis.h"
#include "lite/utils/all.h"
27
#include "lite/utils/variant.h"
Y
Yan Chunwei 已提交
28 29 30 31 32 33 34 35
/*
 * This file contains all the argument parameter data structure for operators.
 */

namespace paddle {
namespace lite {
namespace operators {

36 37
struct ParamBase {
 public:
38 39 40 41 42
  virtual ~ParamBase() {}
  virtual const std::vector<const Tensor*>* input_tensor_ptrs() {
    return nullptr;
  }
  virtual std::vector<Tensor*>* output_tensor_ptrs() { return nullptr; }
43 44 45 46 47 48

 protected:
  std::shared_ptr<std::vector<const Tensor*>> input_tensor_ptrs_cache_{nullptr};
  std::shared_ptr<std::vector<Tensor*>> output_tensor_ptrs_cache_{nullptr};
};

Y
Yan Chunwei 已提交
49 50 51
using param_t = Any;
#define WITH_INT8_CONFIG             \
  bool enable_int8{false};           \
52
  float input_scale{1.0f};           \
Y
Yan Chunwei 已提交
53
  std::vector<float> weight_scale{}; \
54
  float output_scale{1.0f};          \
55
  int bit_length{8};
Y
Yan Chunwei 已提交
56 57

/// ----------------------- Functional operators ------------------------------
58
struct FeedParam : ParamBase {
Y
Yan Chunwei 已提交
59 60 61 62 63
  std::vector<lite::Tensor>* feed_list{};
  lite::Tensor* out{};
  int col;
};

64
struct FetchParam : ParamBase {
Y
Yan Chunwei 已提交
65 66 67 68 69 70
  const lite::Tensor* input{};
  std::vector<lite::Tensor>* fetch_list{};
  int col;
};

// Helper op for lite framework
71
struct IoCopyParam : ParamBase {
Y
Yan Chunwei 已提交
72 73
  const lite::Tensor* x{};
  lite::Tensor* y{};
74
  int process_type{0};
Y
Yan Chunwei 已提交
75 76
};

77
struct LayoutParam : ParamBase {
Y
Yan Chunwei 已提交
78 79
  const lite::Tensor* x{};
  lite::Tensor* y{};
80
  int process_type{0};
Y
Yan Chunwei 已提交
81 82
};

83
struct CalibParam : ParamBase {
Y
Yan Chunwei 已提交
84 85 86 87 88
  const lite::Tensor* input{};
  lite::Tensor* output{};
  float scale;
};

89
struct SubgraphParam : ParamBase {
90 91 92 93 94 95 96
  std::vector<std::string> input_names{};
  std::vector<std::string> output_names{};
  std::vector<std::string> input_data_names{};
  std::vector<std::string> output_data_names{};
  int sub_block_idx{-1};
  cpp::BlockDesc* sub_block_desc{nullptr};
  Scope* scope{nullptr};
Y
Yan Chunwei 已提交
97 98 99 100
};

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

101
struct FcParam : ParamBase {
Y
Yan Chunwei 已提交
102 103 104 105 106 107
  lite::Tensor* input{nullptr};
  lite::Tensor* w{nullptr};
  lite::Tensor* bias{nullptr};
  lite::Tensor* output{nullptr};
  lite::DDim in_mat_dims;
  int in_num_col_dims{1};
108
  std::string activation_type{""};
109
  bool padding_weights{false};
Y
Yan Chunwei 已提交
110 111
  // for int8
  WITH_INT8_CONFIG
112 113
  ///////////////////////////////////////////////////////////////////////////////////
  // get a vector of input tensors
114 115
  const std::vector<const Tensor*>* input_tensor_ptrs() override {
    if (!input_tensor_ptrs_cache_) {
116 117 118 119 120
      input_tensor_ptrs_cache_.reset(new std::vector<const Tensor*>({input}));
    }
    return input_tensor_ptrs_cache_.get();
  }
  // get a vector of output tensors
121 122
  std::vector<Tensor*>* output_tensor_ptrs() override {
    if (!output_tensor_ptrs_cache_) {
123 124 125 126 127 128 129
      output_tensor_ptrs_cache_.reset(new std::vector<lite::Tensor*>({output}));
    }
    return output_tensor_ptrs_cache_.get();
  }
};

struct SearchSeqFcParam : ParamBase {
130 131 132 133 134 135 136
  lite::Tensor* x{nullptr};
  lite::Tensor* w{nullptr};
  lite::Tensor* b{nullptr};
  lite::Tensor* out{nullptr};
  int out_size;
};

Y
Yan Chunwei 已提交
137
// For Interpolate Op
138
struct InterpolateParam : ParamBase {
Y
Yan Chunwei 已提交
139 140 141
  lite::Tensor* X{};
  lite::Tensor* OutSize{};
  lite::Tensor* Out{};
L
liu zhengxi 已提交
142
  std::vector<const lite::Tensor*> SizeTensor;
143
  lite::Tensor* Scale{};
Y
Yan Chunwei 已提交
144 145 146 147 148

  float scale{0.f};
  int out_h{-1};
  int out_w{-1};
  bool align_corners{true};
149
  int align_mode{1};
Y
Yan Chunwei 已提交
150
  std::string interp_method{"Nearest"};
L
liu zhengxi 已提交
151
  DataLayoutType data_layout{DATALAYOUT(kNCHW)};
Y
Yan Chunwei 已提交
152 153 154
};

// For Mul Op
155
struct MulParam : ParamBase {
Y
Yan Chunwei 已提交
156 157 158 159 160 161 162 163
  const lite::Tensor* x{};
  const lite::Tensor* y{};
  lite::Tensor* output{};

  int x_num_col_dims{1};
  int y_num_col_dims{1};
  // for int8
  WITH_INT8_CONFIG
164 165
  ///////////////////////////////////////////////////////////////////////////////////
  // get a vector of input tensors
166 167
  const std::vector<const Tensor*>* input_tensor_ptrs() override {
    if (!input_tensor_ptrs_cache_) {
168 169 170 171 172
      input_tensor_ptrs_cache_.reset(new std::vector<const Tensor*>({x, y}));
    }
    return input_tensor_ptrs_cache_.get();
  }
  // get a vector of output tensors
173 174
  std::vector<Tensor*>* output_tensor_ptrs() override {
    if (!output_tensor_ptrs_cache_) {
175 176 177 178
      output_tensor_ptrs_cache_.reset(new std::vector<lite::Tensor*>({output}));
    }
    return output_tensor_ptrs_cache_.get();
  }
Y
Yan Chunwei 已提交
179 180
};

181
struct MulGradParam : ParamBase {
Y
Yan Chunwei 已提交
182 183 184 185 186 187 188 189 190 191
  const lite::Tensor* x{};
  const lite::Tensor* y{};
  const lite::Tensor* output_grad{};
  lite::Tensor* x_grad{};
  lite::Tensor* y_grad{};

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

192
// For ReduceMean Op
193
struct ReduceMeanParam : ParamBase {
194 195 196 197 198 199 200 201
  lite::Tensor* X{};
  lite::Tensor* Out{};

  std::vector<int> dim;
  bool keep_dim{false};
};

// For Stack Op
202
struct StackParam : ParamBase {
203 204 205 206 207 208
  std::vector<lite::Tensor*> X;
  lite::Tensor* Out{};

  int axis{0};
};

Y
Yan Chunwei 已提交
209
// For Power Op
210
struct PowerParam : ParamBase {
Y
Yan Chunwei 已提交
211 212 213 214 215 216 217 218
  const lite::Tensor* X{};
  lite::Tensor* Out{};

  float scale{};
  float shift{};
  float power{};
};

219
struct ShuffleChannelParam : ParamBase {
Y
Yan Chunwei 已提交
220 221 222 223 224 225 226
  const lite::Tensor* X{};
  lite::Tensor* Out{};

  int group;
};

// For Yolobox
227
struct YoloBoxParam : ParamBase {
Y
Yan Chunwei 已提交
228 229 230 231 232 233 234 235 236 237 238 239
  lite::Tensor* X{};
  lite::Tensor* ImgSize{};
  lite::Tensor* Boxes{};
  lite::Tensor* Scores{};

  std::vector<int> anchors{};
  int class_num{0};
  float conf_thresh{0.f};
  int downsample_ratio{0};
};

// For Scale Op
240
struct ScaleParam : ParamBase {
Y
Yan Chunwei 已提交
241 242 243 244 245 246
  lite::Tensor* x{};
  lite::Tensor* output{};

  float scale{1.};
  float bias{};
  bool bias_after_scale{true};
247 248 249
  std::string activation_type{""};
  bool fuse_relu{false};
  float alpha{6.};
250 251
  ///////////////////////////////////////////////////////////////////////////////////
  // get a vector of input tensors
252 253
  const std::vector<const Tensor*>* input_tensor_ptrs() override {
    if (!input_tensor_ptrs_cache_) {
254 255 256 257 258
      input_tensor_ptrs_cache_.reset(new std::vector<const Tensor*>({x}));
    }
    return input_tensor_ptrs_cache_.get();
  }
  // get a vector of output tensors
259 260
  std::vector<Tensor*>* output_tensor_ptrs() override {
    if (!output_tensor_ptrs_cache_) {
261 262 263 264
      output_tensor_ptrs_cache_.reset(new std::vector<lite::Tensor*>({output}));
    }
    return output_tensor_ptrs_cache_.get();
  }
Y
Yan Chunwei 已提交
265 266 267
};

// For Softmax op
268
struct SoftmaxParam : ParamBase {
Y
Yan Chunwei 已提交
269 270 271
  lite::Tensor* x{};
  lite::Tensor* output{};
  int axis{-1};
272 273
  ///////////////////////////////////////////////////////////////////////////////////
  // get a vector of input tensors
274 275
  const std::vector<const Tensor*>* input_tensor_ptrs() override {
    if (!input_tensor_ptrs_cache_) {
276 277 278 279 280
      input_tensor_ptrs_cache_.reset(new std::vector<const Tensor*>({x}));
    }
    return input_tensor_ptrs_cache_.get();
  }
  // get a vector of output tensors
281 282
  std::vector<Tensor*>* output_tensor_ptrs() override {
    if (!output_tensor_ptrs_cache_) {
283 284 285 286
      output_tensor_ptrs_cache_.reset(new std::vector<lite::Tensor*>({output}));
    }
    return output_tensor_ptrs_cache_.get();
  }
Y
Yan Chunwei 已提交
287 288 289
};

// For Reshape and Reshape2 Op
290
struct ReshapeParam : ParamBase {
Y
Yan Chunwei 已提交
291
  const lite::Tensor* x{};
292 293 294
  std::vector<const lite::Tensor*> shape_tensor_vct{};
  const lite::Tensor* shape_tensor{};
  std::vector<int> shape_vct{};
Y
Yan Chunwei 已提交
295 296
  lite::Tensor* output{};

297
  lite::Tensor* xshape{};
Y
Yan Chunwei 已提交
298
  bool inplace{false};
299 300
  ///////////////////////////////////////////////////////////////////////////////////
  // get a vector of input tensors
301 302
  const std::vector<const Tensor*>* input_tensor_ptrs() override {
    if (!input_tensor_ptrs_cache_) {
303 304 305 306 307
      input_tensor_ptrs_cache_.reset(new std::vector<const Tensor*>({x}));
    }
    return input_tensor_ptrs_cache_.get();
  }
  // get a vector of output tensors
308 309
  std::vector<Tensor*>* output_tensor_ptrs() override {
    if (!output_tensor_ptrs_cache_) {
310 311 312 313
      output_tensor_ptrs_cache_.reset(new std::vector<lite::Tensor*>({output}));
    }
    return output_tensor_ptrs_cache_.get();
  }
Y
Yan Chunwei 已提交
314 315 316
};

// For Concat op
317
struct ConcatParam : ParamBase {
Y
Yan Chunwei 已提交
318 319 320
  std::vector<lite::Tensor*> x{};
  lite::Tensor* output{};
  int axis{0};
321
  lite::Tensor* axis_tensor{};
322
  // get a vector of input tensors
323 324
  const std::vector<const Tensor*>* input_tensor_ptrs() override {
    if (!input_tensor_ptrs_cache_) {
325 326 327 328 329 330 331 332 333
      std::vector<const Tensor*> vec;
      for (auto in : x) {
        vec.push_back(in);
      }
      input_tensor_ptrs_cache_.reset(new std::vector<const Tensor*>(vec));
    }
    return input_tensor_ptrs_cache_.get();
  }
  // get a vector of output tensors
334 335
  std::vector<Tensor*>* output_tensor_ptrs() override {
    if (!output_tensor_ptrs_cache_) {
336 337 338 339
      output_tensor_ptrs_cache_.reset(new std::vector<lite::Tensor*>({output}));
    }
    return output_tensor_ptrs_cache_.get();
  }
Y
Yan Chunwei 已提交
340 341
};

342
/// ----------------------- activation operators ----------------------
343
struct ActivationParam : ParamBase {
344
  const lite::Tensor* X{};
345
  lite::Tensor* Out{};
346
  lite_api::ActivationType active_type{lite_api::ActivationType::kIndentity};
347
  bool has_active{false};
348 349 350 351 352 353
  float Leaky_relu_alpha{0};   // leaky_relu param
  float Relu_clipped_coef{6};  // relu_clipped param
  std::string Prelu_mode{
      "channel"};  // prelu param, can be "all", "channel" or "element"
  lite::Tensor* Prelu_alpha{};  // prelu param
  float Swish_beta;             // swish param
354
  // hard_sigmoid param
355 356
  float hard_sigmoid_slope{0.2f};
  float hard_sigmoid_offset{0.5f};
357 358 359 360
  // hard_swish param
  float hard_swish_threshold{6.0};
  float hard_swish_scale{6.0};
  float hard_swish_offset{3.0};
361 362
};

363
struct ActivationGradParam : ParamBase {
364 365 366 367 368 369 370
  const lite::Tensor* X{};
  const lite::Tensor* Out{};
  // for backward
  lite::Tensor* X_grad{};
  const lite::Tensor* Out_grad{};
};

Y
Yan Chunwei 已提交
371
// For Convolution op
372
struct ConvParam : ParamBase {
Y
Yan Chunwei 已提交
373 374 375 376 377 378
  lite::Tensor* x{};
  lite::Tensor* filter{};
  lite::Tensor* bias{nullptr};
  lite::Tensor* residualData{nullptr};
  lite::Tensor* output{};
  std::vector<int> strides{1, 1};
H
HappyAngel 已提交
379
  /* paddings type change
380 381 382 383
   * from std::vector<int> to std::shared_ptr<std::vector<int>>
   * to support dynamically modify padding
   * let kernel param and operator param Synchronous update
   */
H
HappyAngel 已提交
384
  std::shared_ptr<std::vector<int>> paddings;
Y
Yan Chunwei 已提交
385
  int groups{1};
H
HappyAngel 已提交
386
  /* dilations type change
387 388 389 390
   * from std::vector<int> to std::shared_ptr<std::vector<int>>
   * to support dynamically modify padding
   * let kernel param and operator param Synchronous update
   */
H
HappyAngel 已提交
391
  std::shared_ptr<std::vector<int>> dilations;
Y
Yan Chunwei 已提交
392 393 394 395 396 397 398 399 400 401 402 403
  bool fuse_relu_before_depthwise_conv{false};
  bool use_mkldnn{false};
  bool fuse_relu{false};  // only used in mkldnn kernel
  bool use_quantizer{
      false};  // set true for op that should be quantized, only used for cpu
  bool fuse_residual_connection{false};
  float scale_in{1.0f};           // only used with mkl-dnn int8
  float scale_out{1.0f};          // only used with mkl-dnn int8
  float scale_in_eltwise{1.0f};   // only used with mkl-dnn int8
  float scale_weights{1.0f};      // only used with mkl-dnn int8
  bool force_fp32_output{false};  // only used in mkl-dnn int8
  std::string data_format{"Anylayout"};
404 405
  // for activation
  ActivationParam activation_param;
W
Wilber 已提交
406 407
  // support var_length or not
  bool var_length{false};
408 409
  // only used in conv_transpose.
  std::vector<int> output_size;
Y
Yan Chunwei 已提交
410 411
  // for int8
  WITH_INT8_CONFIG
412 413 414

  ///////////////////////////////////////////////////////////////////////////////////
  // get a vector of input tensors
415 416
  const std::vector<const Tensor*>* input_tensor_ptrs() override {
    if (!input_tensor_ptrs_cache_) {
417 418 419 420 421
      input_tensor_ptrs_cache_.reset(new std::vector<const Tensor*>({x}));
    }
    return input_tensor_ptrs_cache_.get();
  }
  // get a vector of output tensors
422 423
  std::vector<Tensor*>* output_tensor_ptrs() override {
    if (!output_tensor_ptrs_cache_) {
424 425 426 427
      output_tensor_ptrs_cache_.reset(new std::vector<lite::Tensor*>({output}));
    }
    return output_tensor_ptrs_cache_.get();
  }
Y
Yan Chunwei 已提交
428 429 430
};

// For BatchNorm op
431
struct BatchNormParam : ParamBase {
Y
Yan Chunwei 已提交
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446
  lite::Tensor* x{};
  lite::Tensor* bias{};
  lite::Tensor* scale{};
  lite::Tensor* mean{};
  lite::Tensor* variance{};
  lite::Tensor* y{};
  lite::Tensor* mean_out{};
  lite::Tensor* variance_out{};
  lite::Tensor* saved_mean{};
  lite::Tensor* saved_variance{};
  bool is_test{true};
  bool use_global_stats{false};
  float epsilon;
  float momentum;
  DataLayoutType data_layout{DATALAYOUT(kNCHW)};
447 448
  ///////////////////////////////////////////////////////////////////////////////////
  // get a vector of input tensors
449 450
  const std::vector<const Tensor*>* input_tensor_ptrs() override {
    if (!input_tensor_ptrs_cache_) {
451 452 453 454 455
      input_tensor_ptrs_cache_.reset(new std::vector<const Tensor*>({x}));
    }
    return input_tensor_ptrs_cache_.get();
  }
  // get a vector of output tensors
456 457
  std::vector<Tensor*>* output_tensor_ptrs() override {
    if (!output_tensor_ptrs_cache_) {
458 459 460 461
      output_tensor_ptrs_cache_.reset(new std::vector<lite::Tensor*>({y}));
    }
    return output_tensor_ptrs_cache_.get();
  }
Y
Yan Chunwei 已提交
462 463 464
};

// For Pooling op
465
struct PoolParam : ParamBase {
Y
Yan Chunwei 已提交
466 467 468 469 470 471 472
  lite::Tensor* x{};
  lite::Tensor* output{};
  std::string pooling_type{""};
  std::vector<int> ksize{};
  bool global_pooling{
      false};  // if true, knernel size and paddings will be ignored
  std::vector<int> strides{1, 1};
473
  /* paddings type change
474 475 476 477
   * from std::vector<int> to std::shared_ptr<std::vector<int>>
   * to support dynamically modify padding
   * let kernel param and operator param Synchronous update
   */
478
  std::shared_ptr<std::vector<int>> paddings;
Y
Yan Chunwei 已提交
479 480 481 482 483
  bool exclusive{true};
  bool adaptive{false};
  bool ceil_mode{false};
  bool use_quantizer{false};
  std::string data_format{"AnyLayout"};
J
juncaipeng 已提交
484 485
  // for int8
  WITH_INT8_CONFIG
486 487
  ///////////////////////////////////////////////////////////////////////////////////
  // get a vector of input tensors
488 489
  const std::vector<const Tensor*>* input_tensor_ptrs() override {
    if (!input_tensor_ptrs_cache_) {
490 491 492 493 494
      input_tensor_ptrs_cache_.reset(new std::vector<const Tensor*>({x}));
    }
    return input_tensor_ptrs_cache_.get();
  }
  // get a vector of output tensors
495 496
  std::vector<Tensor*>* output_tensor_ptrs() override {
    if (!output_tensor_ptrs_cache_) {
497 498 499 500
      output_tensor_ptrs_cache_.reset(new std::vector<lite::Tensor*>({output}));
    }
    return output_tensor_ptrs_cache_.get();
  }
Y
Yan Chunwei 已提交
501 502 503
};

// For Dropout op
504
struct DropoutParam : ParamBase {
Y
Yan Chunwei 已提交
505 506 507 508 509 510 511 512 513 514 515
  const lite::Tensor* x{};
  lite::Tensor* output{};
  lite::Tensor* mask{};
  float dropout_prob{.5f};
  bool is_test{false};
  bool fix_seed{false};
  int seed{0};
  std::string dropout_implementation{"downgrade_in_infer"};
};

// For Split op
516
struct SplitParam : ParamBase {
Y
Yan Chunwei 已提交
517 518
  lite::Tensor* x{};
  std::vector<lite::Tensor*> output{};
519 520 521
  lite::Tensor* axis_tensor;
  std::vector<lite::Tensor*> sections_tensor_list{};

Y
Yan Chunwei 已提交
522 523 524
  int axis{-1};
  int num{0};
  std::vector<int> sections;
525 526
  ///////////////////////////////////////////////////////////////////////////////////
  // get a vector of input tensors
527 528
  const std::vector<const Tensor*>* input_tensor_ptrs() override {
    if (!input_tensor_ptrs_cache_) {
529 530 531 532 533
      input_tensor_ptrs_cache_.reset(new std::vector<const Tensor*>({x}));
    }
    return input_tensor_ptrs_cache_.get();
  }
  // get a vector of output tensors
534 535
  std::vector<Tensor*>* output_tensor_ptrs() override {
    if (!output_tensor_ptrs_cache_) {
536 537 538 539
      output_tensor_ptrs_cache_.reset(new std::vector<lite::Tensor*>({output}));
    }
    return output_tensor_ptrs_cache_.get();
  }
Y
Yan Chunwei 已提交
540 541 542
};

// For Transpose op
543
struct TransposeParam : ParamBase {
Y
Yan Chunwei 已提交
544 545
  const lite::Tensor* x{};
  lite::Tensor* output{};
546 547
  lite::Tensor* xshape{};

Y
Yan Chunwei 已提交
548 549 550
  std::vector<int> axis;
  bool use_mkldnn{false};
  std::string data_format{"AnyLayout"};
551 552
  ///////////////////////////////////////////////////////////////////////////////////
  //  // get a vector of input tensors
553 554
  const std::vector<const Tensor*>* input_tensor_ptrs() override {
    if (!input_tensor_ptrs_cache_) {
555 556 557 558 559
      input_tensor_ptrs_cache_.reset(new std::vector<const Tensor*>({x}));
    }
    return input_tensor_ptrs_cache_.get();
  }
  // get a vector of output tensors
560 561
  std::vector<Tensor*>* output_tensor_ptrs() override {
    if (!output_tensor_ptrs_cache_) {
562 563 564 565
      output_tensor_ptrs_cache_.reset(new std::vector<lite::Tensor*>({output}));
    }
    return output_tensor_ptrs_cache_.get();
  }
Y
Yan Chunwei 已提交
566 567 568
};

/// ----------------------- element wise operators ----------------------
569
struct ElementwiseParam : ParamBase {
Y
Yan Chunwei 已提交
570 571 572 573
  const lite::Tensor* X{};
  const lite::Tensor* Y{};
  lite::Tensor* Out{};
  int axis{-1};  // for broadcasting.
J
juncaipeng 已提交
574
  // for int8
Z
Zhaolong Xing 已提交
575
  WITH_INT8_CONFIG
J
juncaipeng 已提交
576 577
  float x_input_scale{1.0};
  float y_input_scale{1.0};
578 579
  ///////////////////////////////////////////////////////////////////////////////////
  // get a vector of input tensors
580 581
  const std::vector<const Tensor*>* input_tensor_ptrs() override {
    if (!input_tensor_ptrs_cache_) {
582 583 584 585 586
      input_tensor_ptrs_cache_.reset(new std::vector<const Tensor*>({X, Y}));
    }
    return input_tensor_ptrs_cache_.get();
  }
  // get a vector of output tensors
587 588
  std::vector<Tensor*>* output_tensor_ptrs() override {
    if (!output_tensor_ptrs_cache_) {
589 590 591 592 593 594 595
      output_tensor_ptrs_cache_.reset(new std::vector<lite::Tensor*>({Out}));
    }
    return output_tensor_ptrs_cache_.get();
  }
};

struct ElementwiseGradParam : ParamBase {
X
xiaogang 已提交
596
  const lite::Tensor* X{};
Y
Yan Chunwei 已提交
597
  const lite::Tensor* Y{};
X
xiaogang 已提交
598 599 600
  const lite::Tensor* OutGrad{};
  lite::Tensor* XGrad{};
  lite::Tensor* YGrad{};
Y
Yan Chunwei 已提交
601 602 603 604 605 606 607 608 609 610 611 612
  int axis{-1};  // for broadcasting.
};

struct FusionElementwiseActivationParam : public ElementwiseParam {
  std::string act_type;
};

struct FusionElementwiseActivationGradParam : public ElementwiseGradParam {
  std::string act_type;
};

/// ----------------------- mean operators ----------------------
613
struct MeanParam : ParamBase {
Y
Yan Chunwei 已提交
614 615 616 617
  const lite::Tensor* X{};
  lite::Tensor* Out{};
};

618
struct MeanGradParam : ParamBase {
Y
Yan Chunwei 已提交
619 620 621 622 623 624 625
  const lite::Tensor* X{};
  const lite::Tensor* Out_grad{};
  // for backward
  lite::Tensor* X_grad{};
};

/// ----------------------- fill_constant operators ----------------------
626
struct FillConstantParam : ParamBase {
Y
Yan Chunwei 已提交
627 628
  int dtype{static_cast<int>(VarDescAPI::VarDataType::FP32)};
  std::vector<int64_t> shape{};
629
  lite::Tensor* shape_tensor{nullptr};
630 631
  std::vector<lite::Tensor*> shape_tensor_list{};

T
TianXiaogang 已提交
632 633 634 635 636
  float value{0.0f};
  // useless for x86, keep it for compatibility
  bool force_cpu{false};
  lite::Tensor* out{};
};
Y
Yan Chunwei 已提交
637

638
struct FillConstantBatchSizeLikeParam : ParamBase {
639 640
  const lite::Tensor* input{nullptr};
  lite::Tensor* out{nullptr};
641

642
  std::vector<int> shape{};
643 644 645 646
  int input_dim_idx{0};
  int output_dim_idx{0};
  int dtype{static_cast<int>(VarDescAPI::VarDataType::FP32)};
  float value{0.0f};
647 648
  // useless for x86, keep it for compatibility
  bool force_cpu{false};
649 650
};

Y
Yan Chunwei 已提交
651
//
652
struct FakeQuantizeMovingAvgMaxAbsParam : ParamBase {
Y
Yan Chunwei 已提交
653 654 655 656 657 658 659 660 661 662
  const lite::Tensor* x{};
  const lite::Tensor* in_scale{};
  const lite::Tensor* in_accum{};
  const lite::Tensor* in_state{};
  lite::Tensor* out{};
  lite::Tensor* out_scale{};
  lite::Tensor* out_state{};
  lite::Tensor* out_accum{};
  int bit_length;
  bool is_test{true};
663
  float moving_rate{0.9f};
Y
Yan Chunwei 已提交
664 665
};

666
struct FakeDequantizeMaxAbsParam : ParamBase {
Y
Yan Chunwei 已提交
667 668 669 670 671 672
  const lite::Tensor* x{};
  const lite::Tensor* in_scale{};
  lite::Tensor* out{};
  float max_range;
};

673
struct FakeChannelWiseDequantizeMaxAbsParam : ParamBase {
674 675 676 677 678 679
  const lite::Tensor* x{};
  std::vector<const lite::Tensor*> scale_tensors{};
  lite::Tensor* out{};
  std::vector<int> quant_bits;
};

Y
Yan Chunwei 已提交
680
/// ----------------------- sgd operators ----------------------
681
struct SGDParam : ParamBase {
Y
Yan Chunwei 已提交
682 683 684 685 686 687 688 689 690
  int dtype{static_cast<int>(VarDescAPI::VarDataType::FP32)};

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

/// ----------------------- uniform_random operators ----------------------
691
struct UniformRandomParam : ParamBase {
Y
Yan Chunwei 已提交
692 693 694 695 696 697 698 699
  std::vector<int64_t> shape{};
  float min{-1.0f};
  float max{1.0f};
  int seed{0};
  int dtype{static_cast<int>(VarDescAPI::VarDataType::FP32)};
  lite::Tensor* Out{};
};
/// ----------------------- negative operators --------------
700
struct NegativeParam : ParamBase {
Y
Yan Chunwei 已提交
701 702 703 704
  const lite::Tensor* X{};
  lite::Tensor* Out{};
};
/// ----------------------- pad2d operators ----------------------
705
struct Pad2dParam : ParamBase {
Y
Yan Chunwei 已提交
706 707 708 709 710 711 712 713 714
  const lite::Tensor* X{};
  lite::Tensor* Out{};
  std::vector<int> paddings{0, 0, 0, 0};
  std::string mode{"constant"};
  float pad_value = 0.f;
  std::string data_format{"NCHW"};
};

/// ----------------------- Crop operators ----------------------
715
struct CropParam : ParamBase {
Y
Yan Chunwei 已提交
716 717 718 719 720 721 722
  const lite::Tensor* X{};
  lite::Tensor* Out{};
  std::vector<int> offsets;
  std::vector<int> shape;
};

///----------------------- argmax operators ----------------------
723
struct ArgmaxParam : ParamBase {
Y
Yan Chunwei 已提交
724 725 726 727 728 729
  lite::Tensor* X{};
  lite::Tensor* Out{};
  int Axis{0};
};

///----------------------- axpy operators ----------------------
730
struct AxpyParam : ParamBase {
Y
Yan Chunwei 已提交
731 732 733 734 735 736
  lite::Tensor* Scale{};
  lite::Tensor* X{};
  lite::Tensor* Bias{};
  lite::Tensor* Out{};
};
/// ----------------------- GRU unit operators ----------------------f
737
struct GRUUnitParam : ParamBase {
Y
Yan Chunwei 已提交
738 739 740 741 742 743 744 745 746 747 748 749 750 751 752
  enum ActType { identity, sigmoid, tanh, relu };
  const lite::Tensor* input{nullptr};
  const lite::Tensor* hidden_prev{nullptr};
  const lite::Tensor* weight{nullptr};
  const lite::Tensor* bias{nullptr};
  lite::Tensor* gate{nullptr};
  lite::Tensor* reset_hidden_prev{nullptr};
  lite::Tensor* hidden{nullptr};

  int gate_activation{ActType::sigmoid};
  int activation{ActType::tanh};
  bool origin_mode{false};
};

/// ------------------------------ lrn operators ------------------------------
753
struct LrnParam : ParamBase {
Y
Yan Chunwei 已提交
754 755
  const lite::Tensor* X{};
  lite::Tensor* Out{};
756
  int n{5};
757 758 759
  float alpha{1e-4f};
  float beta{0.75f};
  float k{1.f};
Y
Yan Chunwei 已提交
760 761 762 763
  std::string norm_region{"AcrossChannels"};
};

/// ----------------------- decode_bboxes operators ----------------------
764
struct DecodeBboxesParam : ParamBase {
Y
Yan Chunwei 已提交
765 766 767 768 769 770 771 772 773 774 775 776 777 778 779
  const lite::Tensor* loc_data{};
  const lite::Tensor* prior_data{};
  lite::Tensor* bbox_data{};

  int batch_num;
  int num_priors;
  int num_loc_classes{0};
  int background_label_id{0};
  bool share_location{true};
  bool variance_encoded_in_target;
  // code_type:  corner, cente_size, corner_size
  std::string code_type;
};

/// ----------------------- box_coder operators ----------------------
780
struct BoxCoderParam : ParamBase {
Y
Yan Chunwei 已提交
781 782 783 784 785
  const lite::Tensor* prior_box{};
  const lite::Tensor* prior_box_var{};
  const lite::Tensor* target_box{};
  lite::Tensor* proposals{};
  // code_type: encode_center_size and decode_center_size
786 787 788 789
  std::string code_type{"encode_center_size"};
  bool box_normalized{true};
  int axis{0};
  std::vector<float> variance{};
Y
Yan Chunwei 已提交
790 791 792
};

/// ----------------------- multiclass_nms operators ----------------------
793
struct MulticlassNmsParam : ParamBase {
794 795 796
  const lite::Tensor* bboxes{};
  const lite::Tensor* scores{};
  lite::Tensor* out{};
797
  lite::Tensor* index{};
798 799 800
  int background_label{0};
  float score_threshold{};
  int nms_top_k{};
801 802
  float nms_threshold{0.3f};
  float nms_eta{1.0f};
Y
Yan Chunwei 已提交
803
  int keep_top_k;
804
  bool normalized{true};
Y
Yan Chunwei 已提交
805 806 807
};

/// ----------------------- priorbox operators ----------------------
808
struct PriorBoxParam : ParamBase {
Y
Yan Chunwei 已提交
809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827
  lite::Tensor* input{};
  lite::Tensor* image{};
  lite::Tensor* boxes{};
  lite::Tensor* variances{};

  bool flip;
  bool clip;
  std::vector<float> min_sizes;
  std::vector<float> max_sizes;
  std::vector<float> aspect_ratios;
  std::vector<float> variances_;
  int img_w{0};
  int img_h{0};
  float step_w{0};
  float step_h{0};
  float offset{0.5};
  int prior_num{0};
  // priortype: prior_min, prior_max, prior_com
  std::vector<std::string> order;
828
  bool min_max_aspect_ratios_order{false};
Y
Yan Chunwei 已提交
829 830 831 832 833
};

struct DensityPriorBoxParam : public PriorBoxParam {
  std::vector<float> fixed_sizes;
  std::vector<float> fixed_ratios;
T
TianXiaogang 已提交
834
  std::vector<int> density_sizes;
Y
Yan Chunwei 已提交
835 836
};
/// ----------------------- GRU operators ----------------------f
837
struct GRUParam : ParamBase {
Y
Yan Chunwei 已提交
838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853
  const lite::Tensor* input{nullptr};
  const lite::Tensor* h0{nullptr};
  const lite::Tensor* weight{nullptr};
  const lite::Tensor* bias{nullptr};
  lite::Tensor* batch_gate{nullptr};
  lite::Tensor* batch_reset_hidden_prev{nullptr};
  lite::Tensor* batch_hidden{nullptr};
  lite::Tensor* hidden{nullptr};

  std::string gate_activation{"sigmoid"};
  std::string activation{"tanh"};
  bool is_reverse{false};
  bool origin_mode{false};
};

/// ----------------------- BeamSearchDecode operators ----------------------f
854
struct BeamSearchDecodeParam : ParamBase {
Y
Yan Chunwei 已提交
855 856 857 858 859 860 861 862 863
  std::vector<lite::Tensor>* ids{nullptr};
  std::vector<lite::Tensor>* scores{nullptr};
  lite::Tensor* sentence_ids{nullptr};
  lite::Tensor* sentence_scores{nullptr};
  int beam_size;
  int end_id;
};

/// ----------------------- LookupTable operators ----------------------f
864
struct LookupTableParam : ParamBase {
865 866
  const lite::Tensor* W{nullptr};
  const lite::Tensor* Ids{nullptr};
Y
Yan Chunwei 已提交
867 868 869 870
  lite::Tensor* Out{nullptr};
  int64_t padding_idx{-1};
};

871
struct LookupTableDequantParam : ParamBase {
M
mapingshuo 已提交
872 873 874 875 876 877
  lite::Tensor* W{nullptr};
  lite::Tensor* Ids{nullptr};
  lite::Tensor* Out{nullptr};
  int64_t padding_idx{-1};
};

878
struct Im2SequenceParam : ParamBase {
Y
Yan Chunwei 已提交
879 880 881 882 883 884 885 886 887
  const lite::Tensor* X{};
  const lite::Tensor* Y{};
  lite::Tensor* Out{};
  std::vector<int> kernels{3, 3};
  std::vector<int> strides{1, 1};
  std::vector<int> paddings{0, 0, 0, 0};
  std::vector<int> out_strides{1, 1};
};

888
struct SequenceSoftmaxParam : ParamBase {
Y
Yan Chunwei 已提交
889 890
  const lite::Tensor* X{};
  lite::Tensor* Out{};
891 892
  ///////////////////////////////////////////////////////////////////////////////////
  //  // get a vector of input tensors
893 894
  const std::vector<const Tensor*>* input_tensor_ptrs() override {
    if (!input_tensor_ptrs_cache_) {
895 896 897 898 899
      input_tensor_ptrs_cache_.reset(new std::vector<const Tensor*>({X}));
    }
    return input_tensor_ptrs_cache_.get();
  }
  // get a vector of output tensors
900 901
  std::vector<Tensor*>* output_tensor_ptrs() override {
    if (!output_tensor_ptrs_cache_) {
902 903 904 905
      output_tensor_ptrs_cache_.reset(new std::vector<lite::Tensor*>({Out}));
    }
    return output_tensor_ptrs_cache_.get();
  }
Y
Yan Chunwei 已提交
906 907
};

908
struct NormParam : ParamBase {
Y
Yan Chunwei 已提交
909 910
  const lite::Tensor* X{};
  lite::Tensor* Out{};
911
  lite::Tensor* Norm{};
Y
Yan Chunwei 已提交
912
  int axis{1};
913
  float epsilon{1e-10f};
Y
Yan Chunwei 已提交
914
};
915
struct LayerNormParam : ParamBase {
T
TianXiaogang 已提交
916 917 918 919 920 921 922
  const lite::Tensor* X{};
  const lite::Tensor* Scale{};
  const lite::Tensor* Bias{};
  lite::Tensor* Y{};
  lite::Tensor* Mean{};
  lite::Tensor* Variance{};
  int begin_norm_axis{1};
923
  float epsilon{1e-5f};
T
TianXiaogang 已提交
924
};
Y
Yan Chunwei 已提交
925

926
struct LogicalParam : ParamBase {
Y
Yan Chunwei 已提交
927 928 929 930 931
  const lite::Tensor* X{};
  const lite::Tensor* Y{};
  lite::Tensor* Out{};
};

932
struct CompareParam : ParamBase {
Y
Yan Chunwei 已提交
933 934 935 936 937 938 939
  const lite::Tensor* X{};
  const lite::Tensor* Y{};
  bool force_cpu{0};
  int axis{-1};
  lite::Tensor* Out{};
};

940
struct WhileParam : ParamBase {
Y
Yan Chunwei 已提交
941 942 943 944 945 946 947
  Scope* scope{};
  Tensor* cond{};
  cpp::BlockDesc* sub_block{};
  std::vector<Tensor*> x{};
  std::vector<Tensor*> outs{};
};

948
struct TopkParam : ParamBase {
Y
Yan Chunwei 已提交
949 950 951 952 953 954
  const lite::Tensor* X{};
  lite::Tensor* Out{};
  lite::Tensor* Indices{};
  int K{1};
};

955
struct IncrementParam : ParamBase {
Y
Yan Chunwei 已提交
956 957 958 959 960
  const lite::Tensor* X{};
  lite::Tensor* Out{};
  float step{1};
};

961
struct WriteToArrayParam : ParamBase {
962 963 964
  const lite::Tensor* X{nullptr};
  const lite::Tensor* I{nullptr};
  std::vector<lite::Tensor>* Out{nullptr};
Y
Yan Chunwei 已提交
965 966
};

967
struct ReadFromArrayParam : ParamBase {
968 969 970
  const std::vector<lite::Tensor>* X{nullptr};
  const lite::Tensor* I{nullptr};
  lite::Tensor* Out{nullptr};
Y
Yan Chunwei 已提交
971 972
};

973
struct BeamSearchParam : ParamBase {
Y
Yan Chunwei 已提交
974 975 976 977 978 979 980 981 982 983 984 985 986
  const lite::Tensor* pre_ids{};
  const lite::Tensor* pre_scores{};
  const lite::Tensor* ids{};
  const lite::Tensor* scores{};
  lite::Tensor* selected_ids{};
  lite::Tensor* selected_scores{};
  lite::Tensor* parent_idx{};
  int level;
  int beam_size;
  int end_id;
  bool is_accumulated;
};

987
struct SequencePoolParam : ParamBase {
Y
Yan Chunwei 已提交
988 989
  const lite::Tensor* X{};
  lite::Tensor* Out{};
990 991 992
  std::string pool_type{"AVERAGE"};
#ifdef LITE_WITH_X86
  float pad_value{0.0};
993
  lite::Tensor* MaxIndex{};
994
#endif
Y
Yan Chunwei 已提交
995 996
};

997
struct SequenceConvParam : ParamBase {
998 999 1000 1001 1002 1003 1004 1005
  const lite::Tensor* X{};
  const lite::Tensor* Filter{};
  lite::Tensor* Out{};
  int contextStart{0};
  int contextStride{1};
  int contextLength;
};

1006
struct SequencePoolConcatParam : ParamBase {
1007 1008 1009 1010 1011
  std::vector<lite::Tensor*> X{};
  lite::Tensor* Out{};
  std::vector<std::string> pool_type{};
};

1012
struct SearchGroupPaddingParam : ParamBase {
1013 1014 1015 1016 1017 1018 1019
  lite::Tensor* x{};
  lite::Tensor* out_emb_padding{};
  lite::Tensor* out_new{};
  lite::Tensor* out_padding{};
  int pad_id;
};

1020
struct SequenceReshapeParam : ParamBase {
1021 1022 1023 1024 1025
  lite::Tensor* x{};
  lite::Tensor* output{};
  int new_dim;
};

1026
struct SequenceExpandParam : ParamBase {
Y
Yan Chunwei 已提交
1027 1028 1029 1030 1031 1032
  const lite::Tensor* X{};
  const lite::Tensor* Y{};
  lite::Tensor* Out{};
  int ref_level{-1};
};

1033 1034 1035 1036 1037 1038
struct SequenceUnpadParam : ParamBase {
  const lite::Tensor* X{};
  const lite::Tensor* Length{};
  lite::Tensor* Out{};
};

1039
struct SequenceExpandAsParam : ParamBase {
L
lhl960107 已提交
1040 1041 1042 1043 1044
  const lite::Tensor* x{nullptr};
  const lite::Tensor* y{nullptr};
  lite::Tensor* out{nullptr};
};

1045
struct SequenceReverseParam : ParamBase {
1046 1047 1048 1049
  const lite::Tensor* X{};
  lite::Tensor* Out{};
};

1050
struct SequenceConcatParam : ParamBase {
1051 1052 1053 1054
  std::vector<lite::Tensor*> X{};
  lite::Tensor* Out{};
};

1055
struct AttentionPaddingMaskParam : ParamBase {
1056 1057 1058 1059 1060 1061 1062 1063
  const lite::Tensor* X{};
  const lite::Tensor* Y{};
  int pad_id;
  float mask;
  lite::Tensor* Out{};
  lite::Tensor* pad_begin{};
};

1064
struct SequenceArithmeticParam : ParamBase {
1065 1066 1067 1068 1069 1070
  const lite::Tensor* X{};
  const lite::Tensor* Y{};
  int op_type{1};
  lite::Tensor* Out{};
};

1071
struct ReduceMaxParam : ParamBase {
Y
Yan Chunwei 已提交
1072 1073 1074 1075 1076 1077
  const lite::Tensor* X{};
  lite::Tensor* Out{};
  std::vector<int> dim{};
  bool keep_dim{false};
};

1078
struct LodResetParam : ParamBase {
Y
Yan Chunwei 已提交
1079 1080 1081 1082 1083 1084 1085
  const lite::Tensor* X{};
  const lite::Tensor* Y{};
  lite::Tensor* Out{};
  std::vector<int> target_lod;
  bool append;
};

1086
struct IsEmptyParam : ParamBase {
Y
Yan Chunwei 已提交
1087 1088 1089
  const lite::Tensor* X{};
  lite::Tensor* Out{};
};
1090

1091
struct ReduceParam : ParamBase {
1092 1093 1094 1095 1096 1097 1098
  lite::Tensor* x{};
  lite::Tensor* output{};
  std::vector<int> dim{0};
  bool keep_dim{false};
  bool reduce_all{false};
};

1099
struct VarConv2DParam : ParamBase {
1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112
  const lite::Tensor* X{};
  const lite::Tensor* ROW{};
  const lite::Tensor* COLUMN{};
  const lite::Tensor* W{};
  lite::Tensor* Out{};
  lite::Tensor* Col{};

  int input_channel;
  int output_channel;
  int stride_h;
  int stride_w;
  int kernel_h;
  int kernel_w;
1113 1114

  bool fuse_relu{false};
1115 1116
};

Y
Yan Chunwei 已提交
1117
/// ----------------------- shape operators ----------------------
1118
struct ShapeParam : ParamBase {
Y
Yan Chunwei 已提交
1119 1120 1121 1122
  const lite::Tensor* X{};
  lite::Tensor* Out{};
};

1123
struct CastParam : ParamBase {
Y
Yan Chunwei 已提交
1124 1125 1126 1127 1128 1129
  const lite::Tensor* X{};
  lite::Tensor* Out{};
  int out_dtype{2};
  int in_dtype{2};
};

1130
struct SliceParam : ParamBase {
Y
Yan Chunwei 已提交
1131 1132 1133 1134 1135 1136
  const lite::Tensor* X{};
  lite::Tensor* Out{};
  std::vector<int> axes{};
  std::vector<int> starts{};
  std::vector<int> ends{};
  std::vector<int> decrease_axis{};
1137 1138 1139 1140 1141
  std::vector<int> infer_flags{};
  std::vector<lite::Tensor*> StartsTensorList{};
  std::vector<lite::Tensor*> EndsTensorList{};
  lite::Tensor* StartsTensor{nullptr};
  lite::Tensor* EndsTensor{nullptr};
1142 1143
  ///////////////////////////////////////////////////////////////////////////////////
  // get a vector of input tensors
1144 1145
  const std::vector<const Tensor*>* input_tensor_ptrs() override {
    if (!input_tensor_ptrs_cache_) {
1146 1147 1148 1149 1150
      input_tensor_ptrs_cache_.reset(new std::vector<const Tensor*>({X}));
    }
    return input_tensor_ptrs_cache_.get();
  }
  // get a vector of output tensors
1151 1152
  std::vector<Tensor*>* output_tensor_ptrs() override {
    if (!output_tensor_ptrs_cache_) {
1153 1154 1155 1156
      output_tensor_ptrs_cache_.reset(new std::vector<lite::Tensor*>({Out}));
    }
    return output_tensor_ptrs_cache_.get();
  }
Y
Yan Chunwei 已提交
1157
};
Y
Yan Chunwei 已提交
1158

1159
struct AffineChannelParam : ParamBase {
1160 1161 1162 1163 1164 1165 1166
  const lite::Tensor* X{};  // X is 4D tensor
  const lite::Tensor* Scale{};
  const lite::Tensor* Bias{};
  std::string data_layout{"NCHW"};  // optional string from: NHWC, NCHW.
  lite::Tensor* Out{};
};

1167
struct AnchorGeneratorParam : ParamBase {
1168 1169 1170 1171
  const lite::Tensor* Input{};
  std::vector<float> anchor_sizes{};
  std::vector<float> aspect_ratios{};
  std::vector<float> stride{};
1172 1173
  std::vector<float> variances{{0.1f, 0.1f, 0.2f, 0.2f}};
  float offset{0.5f};
1174 1175 1176 1177 1178

  lite::Tensor* Anchors{};
  lite::Tensor* Variances{};
};

1179
struct GenerateProposalsParam : ParamBase {
1180 1181 1182 1183 1184 1185 1186 1187 1188 1189
  // inputs
  const lite::Tensor* Scores{};
  const lite::Tensor* BboxDeltas{};
  const lite::Tensor* ImInfo{};
  lite::Tensor* Anchors{};
  lite::Tensor* Variances{};

  // attrs
  int pre_nms_topN{6000};
  int post_nms_topN{1000};
1190 1191 1192
  float nms_thresh{0.5f};
  float min_size{0.1f};
  float eta{1.0f};
1193 1194 1195 1196 1197

  // outputs
  lite::Tensor* RpnRois{};
  lite::Tensor* RpnRoiProbs{};
};
W
Wilber 已提交
1198
/// ----------------------- squeeze operators ----------------------
1199
struct SqueezeParam : ParamBase {
Y
Yan Chunwei 已提交
1200 1201 1202 1203
  const lite::Tensor* X{};
  lite::Tensor* Out{};
  lite::Tensor* XShape{};
  std::vector<int> axes{};
1204 1205
  ///////////////////////////////////////////////////////////////////////////////////
  // get a vector of input tensors
1206 1207
  const std::vector<const Tensor*>* input_tensor_ptrs() override {
    if (!input_tensor_ptrs_cache_) {
1208 1209 1210 1211 1212
      input_tensor_ptrs_cache_.reset(new std::vector<const Tensor*>({X}));
    }
    return input_tensor_ptrs_cache_.get();
  }
  // get a vector of output tensors
1213 1214
  std::vector<Tensor*>* output_tensor_ptrs() override {
    if (!output_tensor_ptrs_cache_) {
1215 1216 1217 1218
      output_tensor_ptrs_cache_.reset(new std::vector<lite::Tensor*>({Out}));
    }
    return output_tensor_ptrs_cache_.get();
  }
Y
Yan Chunwei 已提交
1219 1220
};

1221
struct UnsqueezeParam : ParamBase {
1222 1223 1224 1225
  const lite::Tensor* X{};
  lite::Tensor* Out{};
  lite::Tensor* XShape{};
  std::vector<int> axes{};
1226
  const lite::Tensor* axes_tensor{};
1227
  std::vector<const lite::Tensor*> axes_tensor_vct{};
1228 1229
  ///////////////////////////////////////////////////////////////////////////////////
  // get a vector of input tensors
1230 1231
  const std::vector<const Tensor*>* input_tensor_ptrs() override {
    if (!input_tensor_ptrs_cache_) {
1232 1233 1234 1235 1236
      input_tensor_ptrs_cache_.reset(new std::vector<const Tensor*>({X}));
    }
    return input_tensor_ptrs_cache_.get();
  }
  // get a vector of output tensors
1237 1238
  std::vector<Tensor*>* output_tensor_ptrs() override {
    if (!output_tensor_ptrs_cache_) {
1239 1240 1241 1242
      output_tensor_ptrs_cache_.reset(new std::vector<lite::Tensor*>({Out}));
    }
    return output_tensor_ptrs_cache_.get();
  }
1243 1244
};

Y
Yan Chunwei 已提交
1245
/// ----------------------- expand operators ----------------------
1246
struct ExpandParam : ParamBase {
Y
Yan Chunwei 已提交
1247 1248 1249 1250 1251 1252
  const lite::Tensor* X{};
  lite::Tensor* Out{};
  std::vector<int> expand_times{};
};

/// ----------------------- matmul operators ----------------------
1253
struct MatMulParam : ParamBase {
Y
Yan Chunwei 已提交
1254 1255 1256 1257 1258 1259
  const lite::Tensor* X{};
  const lite::Tensor* Y{};
  lite::Tensor* Out{};
  bool transpose_X{false};
  bool transpose_Y{false};
  float alpha{1.0f};
1260 1261
  ///////////////////////////////////////////////////////////////////////////////////
  // get a vector of input tensors
1262 1263
  const std::vector<const Tensor*>* input_tensor_ptrs() override {
    if (!input_tensor_ptrs_cache_) {
1264 1265 1266 1267 1268
      input_tensor_ptrs_cache_.reset(new std::vector<const Tensor*>({X, Y}));
    }
    return input_tensor_ptrs_cache_.get();
  }
  // get a vector of output tensors
1269 1270
  std::vector<Tensor*>* output_tensor_ptrs() override {
    if (!output_tensor_ptrs_cache_) {
1271 1272 1273 1274
      output_tensor_ptrs_cache_.reset(new std::vector<lite::Tensor*>({Out}));
    }
    return output_tensor_ptrs_cache_.get();
  }
Y
Yan Chunwei 已提交
1275
};
1276

1277
struct GatherParam : ParamBase {
T
TianXiaogang 已提交
1278 1279 1280 1281 1282
  const lite::Tensor* X{};
  const lite::Tensor* Index{};
  lite::Tensor* Out{};
};

1283
/// ----------------------- assign operators -----------------------
1284
struct AssignParam : ParamBase {
1285 1286 1287 1288 1289 1290 1291
  // for tensor
  const lite::Tensor* X{nullptr};
  lite::Tensor* Out{nullptr};

  // for tensor_array
  const std::vector<lite::Tensor>* X_array{nullptr};
  std::vector<lite::Tensor>* Out_array{nullptr};
1292
};
1293

1294
/// ----------------------- roi_align operators -----------------------
1295
struct RoiAlignParam : ParamBase {
1296 1297 1298 1299 1300 1301 1302 1303 1304
  lite::Tensor* X{};
  lite::Tensor* ROIs{};
  lite::Tensor* Out{};
  float spatial_scale{1.0};
  int pooled_height{1};
  int pooled_width{1};
  int sampling_ratio{-1};
};

1305
/// ----------------------- box_clip operators -----------------------
1306
struct BoxClipParam : ParamBase {
1307 1308 1309 1310 1311
  const lite::Tensor* Input{};
  const lite::Tensor* ImInfo{};
  lite::Tensor* Output{};
};

1312
struct RangeParam : ParamBase {
1313 1314 1315 1316 1317 1318
  const lite::Tensor* Start;
  const lite::Tensor* End;
  const lite::Tensor* Step;
  lite::Tensor* Out;
};

1319
/// ----------------------- assign_value operators -----------------------
1320
struct AssignValueParam : ParamBase {
1321 1322 1323 1324 1325 1326 1327
  std::vector<int> shape{};
  int dtype{};
  std::vector<float> fp32_values{};
  std::vector<int> int32_values{};
  lite::Tensor* Out{};
};

1328
/// --------------- sequence_topk_avg_pooling operators ------------------
1329
struct SequenceTopkAvgPoolingParam : ParamBase {
1330 1331 1332 1333 1334 1335 1336 1337 1338 1339
  const lite::Tensor* X{};
  const lite::Tensor* ROW{};
  const lite::Tensor* COLUMN{};
  lite::Tensor* Out{};
  lite::Tensor* pos{};
  int channel_num{};
  std::vector<int> topks{};
};

/// --------------- search_fc operators ------------------
1340
struct SearchFcParam : ParamBase {
1341 1342 1343 1344 1345 1346
  const lite::Tensor* X{};
  const lite::Tensor* W{};
  const lite::Tensor* b{};
  lite::Tensor* Out{};
  int out_size{};
};
J
juncaipeng 已提交
1347
/// --------------------- match_matrix_tensor operators --------------------
1348
struct MatchMatrixTensorParam : ParamBase {
J
juncaipeng 已提交
1349 1350 1351 1352 1353 1354 1355 1356 1357 1358
  const lite::Tensor* x{};
  const lite::Tensor* y{};
  const lite::Tensor* w{};
  lite::Tensor* out{};
  lite::Tensor* tmp{};

  int dim_t;
};

/// --------------------- search_seq_depadding operators --------------------
1359
struct SearchSeqDepaddingParam : ParamBase {
J
juncaipeng 已提交
1360 1361 1362 1363 1364 1365
  const lite::Tensor* pad{};
  const lite::Tensor* src{};
  lite::Tensor* out{};
};

/// --------------------- search_grnn operators --------------------
1366
struct SearchGrnnParam : ParamBase {
J
juncaipeng 已提交
1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378
  const lite::Tensor* x{};
  const lite::Tensor* wi{};
  const lite::Tensor* wh{};
  int num_input;
  int num_hidden;

  lite::Tensor* out{};
  lite::Tensor* tmp_buffer{};
  lite::Tensor* idx_sorted_by_width{};
  lite::Tensor* layout_input{};
};

1379
struct SplitLodTensorParam : ParamBase {
J
juncaipeng 已提交
1380 1381 1382 1383 1384 1385 1386
  const lite::Tensor* x{};
  const lite::Tensor* mask{};
  lite::Tensor* out_true{};
  lite::Tensor* out_false{};
  int level{};
};

1387
struct MergeLodTensorParam : ParamBase {
J
juncaipeng 已提交
1388 1389 1390 1391 1392 1393 1394 1395
  const lite::Tensor* x{};
  const lite::Tensor* mask{};
  const lite::Tensor* in_true{};
  const lite::Tensor* in_false{};
  lite::Tensor* out{};
  int level{};
};

1396
struct ConditionalBlockParam : ParamBase {
J
juncaipeng 已提交
1397 1398 1399 1400 1401 1402 1403 1404
  const lite::Tensor* cond{};
  std::vector<lite::Tensor*> x{};
  std::vector<lite::Tensor*> outs{};
  cpp::BlockDesc* sub_block{};
  Scope* scope{};
  bool is_scalar_condition{};
};

1405
struct CollectFpnProposalsParam : ParamBase {
J
juncaipeng 已提交
1406 1407 1408 1409 1410 1411
  std::vector<lite::Tensor*> multi_level_rois{};
  std::vector<lite::Tensor*> multi_level_scores{};
  lite::Tensor* fpn_rois{};
  int post_nms_topN{};
};

1412
struct DistributeFpnProposalsParam : ParamBase {
J
juncaipeng 已提交
1413 1414 1415 1416 1417 1418 1419 1420 1421
  const lite::Tensor* fpn_rois{};
  std::vector<lite::Tensor*> multi_fpn_rois{};
  lite::Tensor* restore_index{};
  int min_level{};
  int max_level{};
  int refer_level{};
  int refer_scale{};
};

1422
/// --------------------- instance_norm operators --------------------
1423
struct InstanceNormParam : ParamBase {
1424 1425 1426 1427 1428 1429 1430 1431
  lite::Tensor* x{};
  lite::Tensor* out{};
  lite::Tensor* bias{};
  lite::Tensor* scale{};
  lite::Tensor* saved_mean{};
  lite::Tensor* saved_variance{};
  float epsilon;
};
H
HappyAngel 已提交
1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444
/// --------------------- group_norm operators --------------------
struct GroupNormParam : ParamBase {
  lite::Tensor* x{};
  lite::Tensor* out{};
  lite::Tensor* bias{};
  lite::Tensor* scale{};
  lite::Tensor* saved_mean{};
  lite::Tensor* saved_variance{};
  float epsilon;
  int groups;
  int channels;
};

1445
/// --------------------- grid sampler operators --------------------
1446
struct GridSamplerParam : ParamBase {
1447 1448 1449 1450
  lite::Tensor* x{};
  lite::Tensor* out{};
  lite::Tensor* grid{};
};
1451
struct LstmParam : ParamBase {
X
xiaogang 已提交
1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466
  lite::Tensor* Input{};
  lite::Tensor* Weight{};
  lite::Tensor* Bias{};
  lite::Tensor* Hidden{};
  lite::Tensor* Cell{};
  lite::Tensor* BatchGate{};
  lite::Tensor* BatchCellPreAct{};
  lite::Tensor* H0{nullptr};
  lite::Tensor* C0{nullptr};
  bool use_peepholes;
  bool is_reverse;
  std::string gate_activation;
  std::string cell_activation;
  std::string candidate_activation;
};
1467

1468
struct CrfDecodingParam : ParamBase {
C
cc 已提交
1469 1470 1471 1472 1473 1474 1475
  lite::Tensor* emission{};
  lite::Tensor* transition{};
  lite::Tensor* label{};
  lite::Tensor* length{};
  lite::Tensor* viterbi_path{};
};

1476 1477 1478 1479 1480 1481 1482 1483 1484 1485
struct CtcAlignParam : ParamBase {
  lite::Tensor* input{};
  lite::Tensor* input_length{};
  lite::Tensor* output{};
  lite::Tensor* output_length{};
  int blank{0};
  bool merge_repeated{true};
  int padding_value{0};
};

1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507
struct XPUResNet50Param : ParamBase {
  lite::Tensor* input{};
  std::vector<lite::Tensor*> filter;
  std::vector<lite::Tensor*> bias;
  std::vector<lite::Tensor*> max_filter;
  lite::Tensor* output{};
};

struct XPUMultiEncoderParam : ParamBase {
  lite::Tensor* input{};
  std::vector<lite::Tensor*> fc_weight;
  std::vector<lite::Tensor*> fc_bias;
  std::vector<lite::Tensor*> ln_scale;
  std::vector<lite::Tensor*> ln_bias;
  lite::Tensor* fc_weight_max{};
  lite::Tensor* mask{};
  lite::Tensor* output{};

  int n_layers{};
  int head_num{};
  int size_per_head{};
  std::string act_type{};
1508
  std::string precision{};
1509 1510
};

C
Cwndmiao 已提交
1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530
struct XPUEmbeddingWithEltwiseAddParam : ParamBase {
  std::vector<lite::Tensor*> Ids;
  std::vector<lite::Tensor*> Tables;
  lite::Tensor* Out{};
  int64_t padding_idx{-1};
};

struct XPUFcParam : ParamBase {
  lite::Tensor* input{nullptr};
  lite::Tensor* w{nullptr};
  lite::Tensor* bias{nullptr};
  lite::Tensor* output{nullptr};

  int in_num_col_dims{1};
  lite::DDim in_mat_dims;
  float w_max{0.0f};
  bool transpose_w{true};
  std::string activation_type{""};
};

H
HappyAngel 已提交
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
// For DeformableConvolution op
struct DeformableConvParam : ParamBase {
  lite::Tensor* x{};
  lite::Tensor* offset{};
  lite::Tensor* mask{};
  lite::Tensor* output{};
  int deformable_groups{1};
  int im2col_step{1};
  bool modulated{true};  // True-v2 False-v1
  std::string data_format{"Anylayout"};
  // convolution parameter
  ConvParam conv_param;
  // support var_length or not
  bool var_length{false};
  // only used in conv_transpose.
  std::vector<int> output_size;
  ///////////////////////////////////////////////////////////////////////////////////
  // get a vector of input tensors
  const std::vector<const Tensor*>* input_tensor_ptrs() override {
    if (!input_tensor_ptrs_cache_) {
      input_tensor_ptrs_cache_.reset(new std::vector<const Tensor*>({x}));
    }
    return input_tensor_ptrs_cache_.get();
  }
  // get a vector of output tensors
  std::vector<Tensor*>* output_tensor_ptrs() override {
    if (!output_tensor_ptrs_cache_) {
      output_tensor_ptrs_cache_.reset(new std::vector<lite::Tensor*>({output}));
    }
    return output_tensor_ptrs_cache_.get();
  }
};

1564 1565 1566 1567 1568
struct PixelShuffleParam : ParamBase {
  lite::Tensor* x{nullptr};
  lite::Tensor* output{nullptr};
  int upscale_factor{1};
};
Y
Yan Chunwei 已提交
1569 1570 1571
}  // namespace operators
}  // namespace lite
}  // namespace paddle