op_params.h 53.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"
24 25
#include "lite/model_parser/base/apis.h"
#include "lite/model_parser/cpp_desc.h"
Y
Yan Chunwei 已提交
26 27 28 29 30 31 32 33 34
#include "lite/utils/all.h"
/*
 * This file contains all the argument parameter data structure for operators.
 */

namespace paddle {
namespace lite {
namespace operators {

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

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

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

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

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

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

82
struct CalibParam : ParamBase {
Y
Yan Chunwei 已提交
83 84 85
  const lite::Tensor* input{};
  lite::Tensor* output{};
  float scale;
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
  ///////////////////////////////////////////////////////////////////////////////////
  // 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*>({input}));
    }
    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();
  }
Y
Yan Chunwei 已提交
101 102
};

103
struct SubgraphParam : ParamBase {
104 105 106 107
  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{};
108 109 110
  int block_idx{-1};
  std::shared_ptr<const cpp::ProgramDesc> program_desc{nullptr};
  Scope* exec_scope{nullptr};
Y
Yan Chunwei 已提交
111 112 113 114
};

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

115
struct FcParam : ParamBase {
Y
Yan Chunwei 已提交
116 117 118 119 120
  lite::Tensor* input{nullptr};
  lite::Tensor* w{nullptr};
  lite::Tensor* bias{nullptr};
  lite::Tensor* output{nullptr};
  lite::DDim in_mat_dims;
H
huzhiqiang 已提交
121 122
  // original dims of input weight
  lite::DDim w_dims;
Y
Yan Chunwei 已提交
123
  int in_num_col_dims{1};
124
  std::string activation_type{""};
125
  bool padding_weights{false};
Y
Yan Chunwei 已提交
126 127
  // for int8
  WITH_INT8_CONFIG
128 129
  ///////////////////////////////////////////////////////////////////////////////////
  // get a vector of input tensors
130 131
  const std::vector<const Tensor*>* input_tensor_ptrs() override {
    if (!input_tensor_ptrs_cache_) {
132 133 134 135 136
      input_tensor_ptrs_cache_.reset(new std::vector<const Tensor*>({input}));
    }
    return input_tensor_ptrs_cache_.get();
  }
  // get a vector of output tensors
137 138
  std::vector<Tensor*>* output_tensor_ptrs() override {
    if (!output_tensor_ptrs_cache_) {
139 140 141 142 143 144 145
      output_tensor_ptrs_cache_.reset(new std::vector<lite::Tensor*>({output}));
    }
    return output_tensor_ptrs_cache_.get();
  }
};

struct SearchSeqFcParam : ParamBase {
146 147 148 149 150 151 152
  lite::Tensor* x{nullptr};
  lite::Tensor* w{nullptr};
  lite::Tensor* b{nullptr};
  lite::Tensor* out{nullptr};
  int out_size;
};

Y
Yan Chunwei 已提交
153
// For Interpolate Op
154
struct InterpolateParam : ParamBase {
Y
Yan Chunwei 已提交
155 156 157
  lite::Tensor* X{};
  lite::Tensor* OutSize{};
  lite::Tensor* Out{};
L
liu zhengxi 已提交
158
  std::vector<const lite::Tensor*> SizeTensor;
159
  lite::Tensor* Scale{};
Y
Yan Chunwei 已提交
160 161 162 163 164

  float scale{0.f};
  int out_h{-1};
  int out_w{-1};
  bool align_corners{true};
165
  int align_mode{1};
Y
Yan Chunwei 已提交
166
  std::string interp_method{"Nearest"};
L
liu zhengxi 已提交
167
  DataLayoutType data_layout{DATALAYOUT(kNCHW)};
Y
Yan Chunwei 已提交
168 169 170
};

// For Mul Op
171
struct MulParam : ParamBase {
Y
Yan Chunwei 已提交
172 173 174 175 176 177 178 179
  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
180 181
  ///////////////////////////////////////////////////////////////////////////////////
  // get a vector of input tensors
182 183
  const std::vector<const Tensor*>* input_tensor_ptrs() override {
    if (!input_tensor_ptrs_cache_) {
184 185 186 187 188
      input_tensor_ptrs_cache_.reset(new std::vector<const Tensor*>({x, y}));
    }
    return input_tensor_ptrs_cache_.get();
  }
  // get a vector of output tensors
189 190
  std::vector<Tensor*>* output_tensor_ptrs() override {
    if (!output_tensor_ptrs_cache_) {
191 192 193 194
      output_tensor_ptrs_cache_.reset(new std::vector<lite::Tensor*>({output}));
    }
    return output_tensor_ptrs_cache_.get();
  }
Y
Yan Chunwei 已提交
195 196
};

197
struct MulGradParam : ParamBase {
Y
Yan Chunwei 已提交
198 199 200 201 202 203 204 205 206 207
  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};
};

208
// For ReduceMean Op
209
struct ReduceMeanParam : ParamBase {
210 211 212 213 214 215 216 217
  lite::Tensor* X{};
  lite::Tensor* Out{};

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

// For Stack Op
218
struct StackParam : ParamBase {
219 220 221 222 223 224
  std::vector<lite::Tensor*> X;
  lite::Tensor* Out{};

  int axis{0};
};

Y
Yan Chunwei 已提交
225
// For Power Op
226
struct PowerParam : ParamBase {
Y
Yan Chunwei 已提交
227 228 229 230 231 232 233 234
  const lite::Tensor* X{};
  lite::Tensor* Out{};

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

235 236 237 238 239 240 241 242 243 244 245 246 247 248
// For Pow Op
struct PowParam : ParamBase {
  const lite::Tensor* X{};
  lite::Tensor* Out{};

  float factor{1.};
};

// For Sign Op
struct SignParam : ParamBase {
  const lite::Tensor* X{};
  lite::Tensor* Out{};
};

249
struct ShuffleChannelParam : ParamBase {
Y
Yan Chunwei 已提交
250 251 252 253 254 255 256
  const lite::Tensor* X{};
  lite::Tensor* Out{};

  int group;
};

// For Yolobox
257
struct YoloBoxParam : ParamBase {
Y
Yan Chunwei 已提交
258 259 260 261 262 263 264 265 266 267 268 269
  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
270
struct ScaleParam : ParamBase {
Y
Yan Chunwei 已提交
271 272 273 274 275 276
  lite::Tensor* x{};
  lite::Tensor* output{};

  float scale{1.};
  float bias{};
  bool bias_after_scale{true};
277 278 279
  std::string activation_type{""};
  bool fuse_relu{false};
  float alpha{6.};
280 281
  ///////////////////////////////////////////////////////////////////////////////////
  // get a vector of input tensors
282 283
  const std::vector<const Tensor*>* input_tensor_ptrs() override {
    if (!input_tensor_ptrs_cache_) {
284 285 286 287 288
      input_tensor_ptrs_cache_.reset(new std::vector<const Tensor*>({x}));
    }
    return input_tensor_ptrs_cache_.get();
  }
  // get a vector of output tensors
289 290
  std::vector<Tensor*>* output_tensor_ptrs() override {
    if (!output_tensor_ptrs_cache_) {
291 292 293 294
      output_tensor_ptrs_cache_.reset(new std::vector<lite::Tensor*>({output}));
    }
    return output_tensor_ptrs_cache_.get();
  }
Y
Yan Chunwei 已提交
295 296
};

297 298 299 300 301 302 303 304 305 306
// For Scatter OP
struct ScatterParam : ParamBase {
  lite::Tensor* x{};
  lite::Tensor* indexs{};
  lite::Tensor* updates{};
  lite::Tensor* output{};

  bool overwrite{true};
};

Y
Yan Chunwei 已提交
307
// For Softmax op
308
struct SoftmaxParam : ParamBase {
Y
Yan Chunwei 已提交
309 310 311
  lite::Tensor* x{};
  lite::Tensor* output{};
  int axis{-1};
W
Wilber 已提交
312
  bool use_cudnn{true};
313 314
  ///////////////////////////////////////////////////////////////////////////////////
  // get a vector of input tensors
315 316
  const std::vector<const Tensor*>* input_tensor_ptrs() override {
    if (!input_tensor_ptrs_cache_) {
317 318 319 320 321
      input_tensor_ptrs_cache_.reset(new std::vector<const Tensor*>({x}));
    }
    return input_tensor_ptrs_cache_.get();
  }
  // get a vector of output tensors
322 323
  std::vector<Tensor*>* output_tensor_ptrs() override {
    if (!output_tensor_ptrs_cache_) {
324 325 326 327
      output_tensor_ptrs_cache_.reset(new std::vector<lite::Tensor*>({output}));
    }
    return output_tensor_ptrs_cache_.get();
  }
Y
Yan Chunwei 已提交
328 329 330
};

// For Reshape and Reshape2 Op
331
struct ReshapeParam : ParamBase {
Y
Yan Chunwei 已提交
332
  const lite::Tensor* x{};
333 334 335
  std::vector<const lite::Tensor*> shape_tensor_vct{};
  const lite::Tensor* shape_tensor{};
  std::vector<int> shape_vct{};
Y
Yan Chunwei 已提交
336 337
  lite::Tensor* output{};

338
  lite::Tensor* xshape{};
Y
Yan Chunwei 已提交
339
  bool inplace{false};
340 341
  ///////////////////////////////////////////////////////////////////////////////////
  // get a vector of input tensors
342 343
  const std::vector<const Tensor*>* input_tensor_ptrs() override {
    if (!input_tensor_ptrs_cache_) {
344 345 346 347 348
      input_tensor_ptrs_cache_.reset(new std::vector<const Tensor*>({x}));
    }
    return input_tensor_ptrs_cache_.get();
  }
  // get a vector of output tensors
349 350
  std::vector<Tensor*>* output_tensor_ptrs() override {
    if (!output_tensor_ptrs_cache_) {
351 352 353 354
      output_tensor_ptrs_cache_.reset(new std::vector<lite::Tensor*>({output}));
    }
    return output_tensor_ptrs_cache_.get();
  }
Y
Yan Chunwei 已提交
355 356 357
};

// For Concat op
358
struct ConcatParam : ParamBase {
Y
Yan Chunwei 已提交
359 360 361
  std::vector<lite::Tensor*> x{};
  lite::Tensor* output{};
  int axis{0};
362
  lite::Tensor* axis_tensor{};
363
  // get a vector of input tensors
364 365
  const std::vector<const Tensor*>* input_tensor_ptrs() override {
    if (!input_tensor_ptrs_cache_) {
366 367 368 369 370 371 372 373 374
      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
375 376
  std::vector<Tensor*>* output_tensor_ptrs() override {
    if (!output_tensor_ptrs_cache_) {
377 378 379 380
      output_tensor_ptrs_cache_.reset(new std::vector<lite::Tensor*>({output}));
    }
    return output_tensor_ptrs_cache_.get();
  }
Y
Yan Chunwei 已提交
381 382
};

383
/// ----------------------- activation operators ----------------------
384
struct ActivationParam : ParamBase {
385
  const lite::Tensor* X{};
386
  lite::Tensor* Out{};
387
  lite_api::ActivationType active_type{lite_api::ActivationType::kIndentity};
388
  bool has_active{false};
389 390 391 392 393 394
  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
395
  // hard_sigmoid param
396 397
  float hard_sigmoid_slope{0.2f};
  float hard_sigmoid_offset{0.5f};
398 399 400 401
  // hard_swish param
  float hard_swish_threshold{6.0};
  float hard_swish_scale{6.0};
  float hard_swish_offset{3.0};
402 403
  // thresholded_relu
  float relu_threshold{1.0f};
H
HappyAngel 已提交
404 405
  // elu
  float Elu_alpha{1.0f};
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421

  ///////////////////////////////////////////////////////////////////////////////////
  // 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*>({Out}));
    }
    return output_tensor_ptrs_cache_.get();
  }
422 423
};

424
struct ActivationGradParam : ParamBase {
425 426 427 428 429 430 431
  const lite::Tensor* X{};
  const lite::Tensor* Out{};
  // for backward
  lite::Tensor* X_grad{};
  const lite::Tensor* Out_grad{};
};

Y
Yan Chunwei 已提交
432
// For Convolution op
433
struct ConvParam : ParamBase {
Y
Yan Chunwei 已提交
434 435 436 437 438 439
  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 已提交
440
  /* paddings type change
441 442 443 444
   * 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 已提交
445
  std::shared_ptr<std::vector<int>> paddings;
Y
Yan Chunwei 已提交
446
  int groups{1};
H
HappyAngel 已提交
447
  /* dilations type change
448 449 450 451
   * 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 已提交
452
  std::shared_ptr<std::vector<int>> dilations;
Y
Yan Chunwei 已提交
453 454 455 456 457 458 459 460 461 462 463 464
  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"};
465 466
  // for activation
  ActivationParam activation_param;
W
Wilber 已提交
467 468
  // support var_length or not
  bool var_length{false};
469 470
  // only used in conv_transpose.
  std::vector<int> output_size;
Y
Yan Chunwei 已提交
471 472
  // for int8
  WITH_INT8_CONFIG
473 474 475

  ///////////////////////////////////////////////////////////////////////////////////
  // get a vector of input tensors
476 477
  const std::vector<const Tensor*>* input_tensor_ptrs() override {
    if (!input_tensor_ptrs_cache_) {
478 479 480 481 482
      input_tensor_ptrs_cache_.reset(new std::vector<const Tensor*>({x}));
    }
    return input_tensor_ptrs_cache_.get();
  }
  // get a vector of output tensors
483 484
  std::vector<Tensor*>* output_tensor_ptrs() override {
    if (!output_tensor_ptrs_cache_) {
485 486 487 488
      output_tensor_ptrs_cache_.reset(new std::vector<lite::Tensor*>({output}));
    }
    return output_tensor_ptrs_cache_.get();
  }
Y
Yan Chunwei 已提交
489 490 491
};

// For BatchNorm op
492
struct BatchNormParam : ParamBase {
Y
Yan Chunwei 已提交
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
  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)};
508 509
  ///////////////////////////////////////////////////////////////////////////////////
  // get a vector of input tensors
510 511
  const std::vector<const Tensor*>* input_tensor_ptrs() override {
    if (!input_tensor_ptrs_cache_) {
512 513 514 515 516
      input_tensor_ptrs_cache_.reset(new std::vector<const Tensor*>({x}));
    }
    return input_tensor_ptrs_cache_.get();
  }
  // get a vector of output tensors
517 518
  std::vector<Tensor*>* output_tensor_ptrs() override {
    if (!output_tensor_ptrs_cache_) {
519 520 521 522
      output_tensor_ptrs_cache_.reset(new std::vector<lite::Tensor*>({y}));
    }
    return output_tensor_ptrs_cache_.get();
  }
Y
Yan Chunwei 已提交
523 524 525
};

// For Pooling op
526
struct PoolParam : ParamBase {
Y
Yan Chunwei 已提交
527 528 529 530 531 532 533
  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};
534
  /* paddings type change
535 536 537 538
   * from std::vector<int> to std::shared_ptr<std::vector<int>>
   * to support dynamically modify padding
   * let kernel param and operator param Synchronous update
   */
539
  std::shared_ptr<std::vector<int>> paddings;
Y
Yan Chunwei 已提交
540 541 542 543 544
  bool exclusive{true};
  bool adaptive{false};
  bool ceil_mode{false};
  bool use_quantizer{false};
  std::string data_format{"AnyLayout"};
J
juncaipeng 已提交
545 546
  // for int8
  WITH_INT8_CONFIG
547 548
  ///////////////////////////////////////////////////////////////////////////////////
  // get a vector of input tensors
549 550
  const std::vector<const Tensor*>* input_tensor_ptrs() override {
    if (!input_tensor_ptrs_cache_) {
551 552 553 554 555
      input_tensor_ptrs_cache_.reset(new std::vector<const Tensor*>({x}));
    }
    return input_tensor_ptrs_cache_.get();
  }
  // get a vector of output tensors
556 557
  std::vector<Tensor*>* output_tensor_ptrs() override {
    if (!output_tensor_ptrs_cache_) {
558 559 560 561
      output_tensor_ptrs_cache_.reset(new std::vector<lite::Tensor*>({output}));
    }
    return output_tensor_ptrs_cache_.get();
  }
Y
Yan Chunwei 已提交
562 563 564
};

// For Dropout op
565
struct DropoutParam : ParamBase {
Y
Yan Chunwei 已提交
566 567 568 569 570 571 572 573 574 575 576
  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
577
struct SplitParam : ParamBase {
Y
Yan Chunwei 已提交
578 579
  lite::Tensor* x{};
  std::vector<lite::Tensor*> output{};
580 581 582
  lite::Tensor* axis_tensor;
  std::vector<lite::Tensor*> sections_tensor_list{};

Y
Yan Chunwei 已提交
583 584 585
  int axis{-1};
  int num{0};
  std::vector<int> sections;
586 587
  ///////////////////////////////////////////////////////////////////////////////////
  // get a vector of input tensors
588 589
  const std::vector<const Tensor*>* input_tensor_ptrs() override {
    if (!input_tensor_ptrs_cache_) {
590 591 592 593 594
      input_tensor_ptrs_cache_.reset(new std::vector<const Tensor*>({x}));
    }
    return input_tensor_ptrs_cache_.get();
  }
  // get a vector of output tensors
595 596
  std::vector<Tensor*>* output_tensor_ptrs() override {
    if (!output_tensor_ptrs_cache_) {
597 598 599 600
      output_tensor_ptrs_cache_.reset(new std::vector<lite::Tensor*>({output}));
    }
    return output_tensor_ptrs_cache_.get();
  }
Y
Yan Chunwei 已提交
601 602 603
};

// For Transpose op
604
struct TransposeParam : ParamBase {
Y
Yan Chunwei 已提交
605 606
  const lite::Tensor* x{};
  lite::Tensor* output{};
607 608
  lite::Tensor* xshape{};

Y
Yan Chunwei 已提交
609 610 611
  std::vector<int> axis;
  bool use_mkldnn{false};
  std::string data_format{"AnyLayout"};
612 613
  ///////////////////////////////////////////////////////////////////////////////////
  //  // get a vector of input tensors
614 615
  const std::vector<const Tensor*>* input_tensor_ptrs() override {
    if (!input_tensor_ptrs_cache_) {
616 617 618 619 620
      input_tensor_ptrs_cache_.reset(new std::vector<const Tensor*>({x}));
    }
    return input_tensor_ptrs_cache_.get();
  }
  // get a vector of output tensors
621 622
  std::vector<Tensor*>* output_tensor_ptrs() override {
    if (!output_tensor_ptrs_cache_) {
623 624 625 626
      output_tensor_ptrs_cache_.reset(new std::vector<lite::Tensor*>({output}));
    }
    return output_tensor_ptrs_cache_.get();
  }
Y
Yan Chunwei 已提交
627 628 629
};

/// ----------------------- element wise operators ----------------------
630
struct ElementwiseParam : ParamBase {
Y
Yan Chunwei 已提交
631 632 633 634
  const lite::Tensor* X{};
  const lite::Tensor* Y{};
  lite::Tensor* Out{};
  int axis{-1};  // for broadcasting.
J
juncaipeng 已提交
635
  // for int8
Z
Zhaolong Xing 已提交
636
  WITH_INT8_CONFIG
J
juncaipeng 已提交
637 638
  float x_input_scale{1.0};
  float y_input_scale{1.0};
639 640
  ///////////////////////////////////////////////////////////////////////////////////
  // get a vector of input tensors
641 642
  const std::vector<const Tensor*>* input_tensor_ptrs() override {
    if (!input_tensor_ptrs_cache_) {
643 644 645 646 647
      input_tensor_ptrs_cache_.reset(new std::vector<const Tensor*>({X, Y}));
    }
    return input_tensor_ptrs_cache_.get();
  }
  // get a vector of output tensors
648 649
  std::vector<Tensor*>* output_tensor_ptrs() override {
    if (!output_tensor_ptrs_cache_) {
650 651 652 653 654 655 656
      output_tensor_ptrs_cache_.reset(new std::vector<lite::Tensor*>({Out}));
    }
    return output_tensor_ptrs_cache_.get();
  }
};

struct ElementwiseGradParam : ParamBase {
X
xiaogang 已提交
657
  const lite::Tensor* X{};
Y
Yan Chunwei 已提交
658
  const lite::Tensor* Y{};
X
xiaogang 已提交
659 660 661
  const lite::Tensor* OutGrad{};
  lite::Tensor* XGrad{};
  lite::Tensor* YGrad{};
Y
Yan Chunwei 已提交
662 663 664 665 666 667 668 669 670 671 672 673
  int axis{-1};  // for broadcasting.
};

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

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

/// ----------------------- mean operators ----------------------
674
struct MeanParam : ParamBase {
Y
Yan Chunwei 已提交
675 676 677 678
  const lite::Tensor* X{};
  lite::Tensor* Out{};
};

679
struct MeanGradParam : ParamBase {
Y
Yan Chunwei 已提交
680 681 682 683 684 685 686
  const lite::Tensor* X{};
  const lite::Tensor* Out_grad{};
  // for backward
  lite::Tensor* X_grad{};
};

/// ----------------------- fill_constant operators ----------------------
687
struct FillConstantParam : ParamBase {
Y
Yan Chunwei 已提交
688 689
  int dtype{static_cast<int>(VarDescAPI::VarDataType::FP32)};
  std::vector<int64_t> shape{};
690
  lite::Tensor* shape_tensor{nullptr};
691 692
  std::vector<lite::Tensor*> shape_tensor_list{};

T
TianXiaogang 已提交
693 694 695 696 697
  float value{0.0f};
  // useless for x86, keep it for compatibility
  bool force_cpu{false};
  lite::Tensor* out{};
};
Y
Yan Chunwei 已提交
698

699
struct FillConstantBatchSizeLikeParam : ParamBase {
700 701
  const lite::Tensor* input{nullptr};
  lite::Tensor* out{nullptr};
702

703
  std::vector<int> shape{};
704 705 706 707
  int input_dim_idx{0};
  int output_dim_idx{0};
  int dtype{static_cast<int>(VarDescAPI::VarDataType::FP32)};
  float value{0.0f};
708 709
  // useless for x86, keep it for compatibility
  bool force_cpu{false};
710 711
};

Y
Yan Chunwei 已提交
712
//
713
struct FakeQuantizeMovingAvgMaxAbsParam : ParamBase {
Y
Yan Chunwei 已提交
714 715 716 717 718 719 720 721 722 723
  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};
724
  float moving_rate{0.9f};
Y
Yan Chunwei 已提交
725 726
};

727
struct FakeDequantizeMaxAbsParam : ParamBase {
Y
Yan Chunwei 已提交
728 729 730 731 732 733
  const lite::Tensor* x{};
  const lite::Tensor* in_scale{};
  lite::Tensor* out{};
  float max_range;
};

734
struct FakeChannelWiseDequantizeMaxAbsParam : ParamBase {
735 736 737 738 739 740
  const lite::Tensor* x{};
  std::vector<const lite::Tensor*> scale_tensors{};
  lite::Tensor* out{};
  std::vector<int> quant_bits;
};

741 742 743 744 745 746 747
struct FakeQuantDequantAbsMaxParam : ParamBase {
  const lite::Tensor* x{};
  lite::Tensor* out{};
  lite::Tensor* out_scale{};
  int bit_length;
};

Y
Yan Chunwei 已提交
748
/// ----------------------- sgd operators ----------------------
749
struct SGDParam : ParamBase {
Y
Yan Chunwei 已提交
750 751 752 753 754 755 756 757 758
  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 ----------------------
759
struct UniformRandomParam : ParamBase {
760
  const lite::Tensor* X{nullptr};
Y
Yan Chunwei 已提交
761 762 763 764 765 766 767 768
  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 --------------
769
struct NegativeParam : ParamBase {
Y
Yan Chunwei 已提交
770 771 772 773
  const lite::Tensor* X{};
  lite::Tensor* Out{};
};
/// ----------------------- pad2d operators ----------------------
774
struct Pad2dParam : ParamBase {
Y
Yan Chunwei 已提交
775 776 777 778 779 780 781 782 783
  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 ----------------------
784
struct CropParam : ParamBase {
Y
Yan Chunwei 已提交
785 786 787 788 789 790 791
  const lite::Tensor* X{};
  lite::Tensor* Out{};
  std::vector<int> offsets;
  std::vector<int> shape;
};

///----------------------- argmax operators ----------------------
792
struct ArgmaxParam : ParamBase {
Y
Yan Chunwei 已提交
793 794 795 796 797 798
  lite::Tensor* X{};
  lite::Tensor* Out{};
  int Axis{0};
};

///----------------------- axpy operators ----------------------
799
struct AxpyParam : ParamBase {
Y
Yan Chunwei 已提交
800 801 802 803 804 805
  lite::Tensor* Scale{};
  lite::Tensor* X{};
  lite::Tensor* Bias{};
  lite::Tensor* Out{};
};
/// ----------------------- GRU unit operators ----------------------f
806
struct GRUUnitParam : ParamBase {
Y
Yan Chunwei 已提交
807 808 809 810 811 812 813 814 815 816 817 818 819 820 821
  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 ------------------------------
822
struct LrnParam : ParamBase {
Y
Yan Chunwei 已提交
823 824
  const lite::Tensor* X{};
  lite::Tensor* Out{};
825
  int n{5};
826 827 828
  float alpha{1e-4f};
  float beta{0.75f};
  float k{1.f};
Y
Yan Chunwei 已提交
829 830 831 832
  std::string norm_region{"AcrossChannels"};
};

/// ----------------------- decode_bboxes operators ----------------------
833
struct DecodeBboxesParam : ParamBase {
Y
Yan Chunwei 已提交
834 835 836 837 838 839 840 841 842 843 844 845 846 847 848
  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 ----------------------
849
struct BoxCoderParam : ParamBase {
Y
Yan Chunwei 已提交
850 851 852 853 854
  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
855 856 857 858
  std::string code_type{"encode_center_size"};
  bool box_normalized{true};
  int axis{0};
  std::vector<float> variance{};
859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875
  ///////////////////////////////////////////////////////////////////////////////////
  // 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*>(
          {prior_box, prior_box_var, target_box}));
    }
    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*>({proposals}));
    }
    return output_tensor_ptrs_cache_.get();
  }
Y
Yan Chunwei 已提交
876 877 878
};

/// ----------------------- multiclass_nms operators ----------------------
879
struct MulticlassNmsParam : ParamBase {
880 881 882
  const lite::Tensor* bboxes{};
  const lite::Tensor* scores{};
  lite::Tensor* out{};
883
  lite::Tensor* index{};
884 885 886
  int background_label{0};
  float score_threshold{};
  int nms_top_k{};
887 888
  float nms_threshold{0.3f};
  float nms_eta{1.0f};
Y
Yan Chunwei 已提交
889
  int keep_top_k;
890
  bool normalized{true};
Y
Yan Chunwei 已提交
891 892 893
};

/// ----------------------- priorbox operators ----------------------
894
struct PriorBoxParam : ParamBase {
Y
Yan Chunwei 已提交
895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913
  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;
914
  bool min_max_aspect_ratios_order{false};
915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931
  ///////////////////////////////////////////////////////////////////////////////////
  // 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*>({input, image}));
    }
    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*>({boxes, variances}));
    }
    return output_tensor_ptrs_cache_.get();
  }
Y
Yan Chunwei 已提交
932 933 934 935 936
};

struct DensityPriorBoxParam : public PriorBoxParam {
  std::vector<float> fixed_sizes;
  std::vector<float> fixed_ratios;
T
TianXiaogang 已提交
937
  std::vector<int> density_sizes;
Y
Yan Chunwei 已提交
938 939
};
/// ----------------------- GRU operators ----------------------f
940
struct GRUParam : ParamBase {
Y
Yan Chunwei 已提交
941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956
  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
957
struct BeamSearchDecodeParam : ParamBase {
Y
Yan Chunwei 已提交
958 959 960 961 962 963 964 965 966
  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
967
struct LookupTableParam : ParamBase {
968 969
  const lite::Tensor* W{nullptr};
  const lite::Tensor* Ids{nullptr};
Y
Yan Chunwei 已提交
970 971 972 973
  lite::Tensor* Out{nullptr};
  int64_t padding_idx{-1};
};

974
struct LookupTableDequantParam : ParamBase {
M
mapingshuo 已提交
975 976 977 978 979 980
  lite::Tensor* W{nullptr};
  lite::Tensor* Ids{nullptr};
  lite::Tensor* Out{nullptr};
  int64_t padding_idx{-1};
};

981
struct Im2SequenceParam : ParamBase {
Y
Yan Chunwei 已提交
982 983 984 985 986 987 988 989 990
  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};
};

991
struct SequenceSoftmaxParam : ParamBase {
Y
Yan Chunwei 已提交
992 993
  const lite::Tensor* X{};
  lite::Tensor* Out{};
994 995
  ///////////////////////////////////////////////////////////////////////////////////
  //  // get a vector of input tensors
996 997
  const std::vector<const Tensor*>* input_tensor_ptrs() override {
    if (!input_tensor_ptrs_cache_) {
998 999 1000 1001 1002
      input_tensor_ptrs_cache_.reset(new std::vector<const Tensor*>({X}));
    }
    return input_tensor_ptrs_cache_.get();
  }
  // get a vector of output tensors
1003 1004
  std::vector<Tensor*>* output_tensor_ptrs() override {
    if (!output_tensor_ptrs_cache_) {
1005 1006 1007 1008
      output_tensor_ptrs_cache_.reset(new std::vector<lite::Tensor*>({Out}));
    }
    return output_tensor_ptrs_cache_.get();
  }
Y
Yan Chunwei 已提交
1009 1010
};

1011
struct NormParam : ParamBase {
Y
Yan Chunwei 已提交
1012 1013
  const lite::Tensor* X{};
  lite::Tensor* Out{};
1014
  lite::Tensor* Norm{};
Y
Yan Chunwei 已提交
1015
  int axis{1};
1016
  float epsilon{1e-10f};
Y
Yan Chunwei 已提交
1017
};
1018
struct LayerNormParam : ParamBase {
T
TianXiaogang 已提交
1019 1020 1021 1022 1023 1024 1025
  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};
1026
  float epsilon{1e-5f};
T
TianXiaogang 已提交
1027
};
Y
Yan Chunwei 已提交
1028

1029
struct LogicalParam : ParamBase {
Y
Yan Chunwei 已提交
1030 1031 1032 1033 1034
  const lite::Tensor* X{};
  const lite::Tensor* Y{};
  lite::Tensor* Out{};
};

1035
struct CompareParam : ParamBase {
Y
Yan Chunwei 已提交
1036 1037 1038 1039 1040 1041 1042
  const lite::Tensor* X{};
  const lite::Tensor* Y{};
  bool force_cpu{0};
  int axis{-1};
  lite::Tensor* Out{};
};

1043
struct WhileParam : ParamBase {
Y
Yan Chunwei 已提交
1044
  Tensor* cond{};
1045 1046 1047
  int block_idx{-1};
  std::shared_ptr<const cpp::ProgramDesc> program_desc{nullptr};
  Scope* exec_scope{nullptr};
Y
Yan Chunwei 已提交
1048 1049
};

1050
struct TopkParam : ParamBase {
Y
Yan Chunwei 已提交
1051 1052 1053 1054 1055 1056
  const lite::Tensor* X{};
  lite::Tensor* Out{};
  lite::Tensor* Indices{};
  int K{1};
};

1057
struct IncrementParam : ParamBase {
Y
Yan Chunwei 已提交
1058 1059 1060 1061 1062
  const lite::Tensor* X{};
  lite::Tensor* Out{};
  float step{1};
};

1063
struct WriteToArrayParam : ParamBase {
1064 1065 1066
  const lite::Tensor* X{nullptr};
  const lite::Tensor* I{nullptr};
  std::vector<lite::Tensor>* Out{nullptr};
Y
Yan Chunwei 已提交
1067 1068
};

1069
struct ReadFromArrayParam : ParamBase {
1070 1071 1072
  const std::vector<lite::Tensor>* X{nullptr};
  const lite::Tensor* I{nullptr};
  lite::Tensor* Out{nullptr};
Y
Yan Chunwei 已提交
1073 1074
};

1075
struct BeamSearchParam : ParamBase {
Y
Yan Chunwei 已提交
1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088
  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;
};

1089
struct SequencePoolParam : ParamBase {
Y
Yan Chunwei 已提交
1090 1091
  const lite::Tensor* X{};
  lite::Tensor* Out{};
1092
  lite::Tensor* MaxIndex{};
1093 1094 1095 1096
  std::string pool_type{"AVERAGE"};
#ifdef LITE_WITH_X86
  float pad_value{0.0};
#endif
Y
Yan Chunwei 已提交
1097 1098
};

1099
struct SequenceConvParam : ParamBase {
1100 1101 1102 1103 1104 1105 1106 1107
  const lite::Tensor* X{};
  const lite::Tensor* Filter{};
  lite::Tensor* Out{};
  int contextStart{0};
  int contextStride{1};
  int contextLength;
};

1108
struct SequencePoolConcatParam : ParamBase {
1109 1110 1111 1112 1113
  std::vector<lite::Tensor*> X{};
  lite::Tensor* Out{};
  std::vector<std::string> pool_type{};
};

1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125
struct SequencePoolGradParam : ParamBase {
  const lite::Tensor* X{};
  std::string pool_type{"AVERAGE"};
#ifdef LITE_WITH_X86
  float pad_value{0.0};
#endif
  // for backward
  const lite::Tensor* Out_Grad{};
  const lite::Tensor* MaxIndex_Grad{};
  lite::Tensor* X_Grad{};
};

1126
struct SearchGroupPaddingParam : ParamBase {
1127 1128 1129 1130 1131 1132 1133
  lite::Tensor* x{};
  lite::Tensor* out_emb_padding{};
  lite::Tensor* out_new{};
  lite::Tensor* out_padding{};
  int pad_id;
};

1134
struct SequenceReshapeParam : ParamBase {
1135 1136 1137 1138 1139
  lite::Tensor* x{};
  lite::Tensor* output{};
  int new_dim;
};

1140
struct SequenceExpandParam : ParamBase {
Y
Yan Chunwei 已提交
1141 1142 1143 1144 1145 1146
  const lite::Tensor* X{};
  const lite::Tensor* Y{};
  lite::Tensor* Out{};
  int ref_level{-1};
};

1147 1148 1149 1150 1151 1152 1153 1154
struct SequencePadParam : ParamBase {
  const lite::Tensor* X{};
  const lite::Tensor* PadValue{};
  lite::Tensor* Out{};
  lite::Tensor* Length{};
  int padded_length{-1};
};

1155 1156 1157 1158 1159 1160
struct SequenceUnpadParam : ParamBase {
  const lite::Tensor* X{};
  const lite::Tensor* Length{};
  lite::Tensor* Out{};
};

1161 1162 1163 1164 1165 1166 1167 1168
struct SequenceMaskParam : ParamBase {
  const lite::Tensor* X{};
  const lite::Tensor* MaxLenTensor{nullptr};
  lite::Tensor* Y{};
  int maxlen{-1};
  int out_dtype;
};

1169
struct SequenceExpandAsParam : ParamBase {
L
lhl960107 已提交
1170 1171 1172 1173 1174
  const lite::Tensor* x{nullptr};
  const lite::Tensor* y{nullptr};
  lite::Tensor* out{nullptr};
};

1175
struct SequenceReverseParam : ParamBase {
1176 1177 1178 1179
  const lite::Tensor* X{};
  lite::Tensor* Out{};
};

1180
struct SequenceConcatParam : ParamBase {
1181 1182 1183 1184
  std::vector<lite::Tensor*> X{};
  lite::Tensor* Out{};
};

1185
struct AttentionPaddingMaskParam : ParamBase {
1186 1187 1188 1189 1190 1191 1192 1193
  const lite::Tensor* X{};
  const lite::Tensor* Y{};
  int pad_id;
  float mask;
  lite::Tensor* Out{};
  lite::Tensor* pad_begin{};
};

1194
struct SequenceArithmeticParam : ParamBase {
1195 1196 1197 1198 1199 1200
  const lite::Tensor* X{};
  const lite::Tensor* Y{};
  int op_type{1};
  lite::Tensor* Out{};
};

1201
struct ReduceMaxParam : ParamBase {
Y
Yan Chunwei 已提交
1202 1203 1204 1205 1206 1207
  const lite::Tensor* X{};
  lite::Tensor* Out{};
  std::vector<int> dim{};
  bool keep_dim{false};
};

1208
struct LodResetParam : ParamBase {
Y
Yan Chunwei 已提交
1209 1210 1211 1212 1213 1214 1215
  const lite::Tensor* X{};
  const lite::Tensor* Y{};
  lite::Tensor* Out{};
  std::vector<int> target_lod;
  bool append;
};

1216
struct IsEmptyParam : ParamBase {
Y
Yan Chunwei 已提交
1217 1218 1219
  const lite::Tensor* X{};
  lite::Tensor* Out{};
};
1220

1221
struct ReduceParam : ParamBase {
1222 1223 1224 1225 1226 1227 1228
  lite::Tensor* x{};
  lite::Tensor* output{};
  std::vector<int> dim{0};
  bool keep_dim{false};
  bool reduce_all{false};
};

1229
struct VarConv2DParam : ParamBase {
1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242
  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;
1243 1244

  bool fuse_relu{false};
1245 1246 1247 1248 1249

#ifdef LITE_WITH_XPU
  bool __xpu__float_to_fix{false};  // Is W already converted to int16/int8
  float __xpu__w_max{0.0f};         // Abs max in W
#endif
1250 1251
};

Y
Yan Chunwei 已提交
1252
/// ----------------------- shape operators ----------------------
1253
struct ShapeParam : ParamBase {
Y
Yan Chunwei 已提交
1254 1255 1256 1257
  const lite::Tensor* X{};
  lite::Tensor* Out{};
};

1258
struct CastParam : ParamBase {
Y
Yan Chunwei 已提交
1259 1260 1261 1262 1263 1264
  const lite::Tensor* X{};
  lite::Tensor* Out{};
  int out_dtype{2};
  int in_dtype{2};
};

1265
struct SliceParam : ParamBase {
Y
Yan Chunwei 已提交
1266 1267 1268 1269 1270 1271
  const lite::Tensor* X{};
  lite::Tensor* Out{};
  std::vector<int> axes{};
  std::vector<int> starts{};
  std::vector<int> ends{};
  std::vector<int> decrease_axis{};
1272 1273 1274 1275 1276
  std::vector<int> infer_flags{};
  std::vector<lite::Tensor*> StartsTensorList{};
  std::vector<lite::Tensor*> EndsTensorList{};
  lite::Tensor* StartsTensor{nullptr};
  lite::Tensor* EndsTensor{nullptr};
1277 1278
  ///////////////////////////////////////////////////////////////////////////////////
  // get a vector of input tensors
1279 1280
  const std::vector<const Tensor*>* input_tensor_ptrs() override {
    if (!input_tensor_ptrs_cache_) {
1281 1282 1283 1284 1285
      input_tensor_ptrs_cache_.reset(new std::vector<const Tensor*>({X}));
    }
    return input_tensor_ptrs_cache_.get();
  }
  // get a vector of output tensors
1286 1287
  std::vector<Tensor*>* output_tensor_ptrs() override {
    if (!output_tensor_ptrs_cache_) {
1288 1289 1290 1291
      output_tensor_ptrs_cache_.reset(new std::vector<lite::Tensor*>({Out}));
    }
    return output_tensor_ptrs_cache_.get();
  }
Y
Yan Chunwei 已提交
1292
};
Y
Yan Chunwei 已提交
1293

1294
struct AffineChannelParam : ParamBase {
1295 1296 1297 1298 1299 1300 1301
  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{};
};

1302 1303 1304 1305 1306 1307 1308
struct AffineGridParam : ParamBase {
  const lite::Tensor* X{};  // Theta:shape {?, 2, 3}
  std::vector<int> output_shape;
  const lite::Tensor* OutputShape;
  lite::Tensor* Out{};
};

1309
struct AnchorGeneratorParam : ParamBase {
1310 1311 1312 1313
  const lite::Tensor* Input{};
  std::vector<float> anchor_sizes{};
  std::vector<float> aspect_ratios{};
  std::vector<float> stride{};
1314 1315
  std::vector<float> variances{{0.1f, 0.1f, 0.2f, 0.2f}};
  float offset{0.5f};
1316 1317 1318 1319 1320

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

1321
struct GenerateProposalsParam : ParamBase {
1322 1323 1324 1325 1326 1327 1328 1329 1330 1331
  // 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};
1332 1333 1334
  float nms_thresh{0.5f};
  float min_size{0.1f};
  float eta{1.0f};
1335 1336 1337 1338 1339

  // outputs
  lite::Tensor* RpnRois{};
  lite::Tensor* RpnRoiProbs{};
};
W
Wilber 已提交
1340
/// ----------------------- squeeze operators ----------------------
1341
struct SqueezeParam : ParamBase {
Y
Yan Chunwei 已提交
1342 1343 1344 1345
  const lite::Tensor* X{};
  lite::Tensor* Out{};
  lite::Tensor* XShape{};
  std::vector<int> axes{};
1346 1347
  ///////////////////////////////////////////////////////////////////////////////////
  // get a vector of input tensors
1348 1349
  const std::vector<const Tensor*>* input_tensor_ptrs() override {
    if (!input_tensor_ptrs_cache_) {
1350 1351 1352 1353 1354
      input_tensor_ptrs_cache_.reset(new std::vector<const Tensor*>({X}));
    }
    return input_tensor_ptrs_cache_.get();
  }
  // get a vector of output tensors
1355 1356
  std::vector<Tensor*>* output_tensor_ptrs() override {
    if (!output_tensor_ptrs_cache_) {
1357 1358 1359 1360
      output_tensor_ptrs_cache_.reset(new std::vector<lite::Tensor*>({Out}));
    }
    return output_tensor_ptrs_cache_.get();
  }
Y
Yan Chunwei 已提交
1361 1362
};

1363
struct UnsqueezeParam : ParamBase {
1364 1365 1366 1367
  const lite::Tensor* X{};
  lite::Tensor* Out{};
  lite::Tensor* XShape{};
  std::vector<int> axes{};
1368
  const lite::Tensor* axes_tensor{};
1369
  std::vector<const lite::Tensor*> axes_tensor_vct{};
1370 1371
  ///////////////////////////////////////////////////////////////////////////////////
  // get a vector of input tensors
1372 1373
  const std::vector<const Tensor*>* input_tensor_ptrs() override {
    if (!input_tensor_ptrs_cache_) {
1374 1375 1376 1377 1378
      input_tensor_ptrs_cache_.reset(new std::vector<const Tensor*>({X}));
    }
    return input_tensor_ptrs_cache_.get();
  }
  // get a vector of output tensors
1379 1380
  std::vector<Tensor*>* output_tensor_ptrs() override {
    if (!output_tensor_ptrs_cache_) {
1381 1382 1383 1384
      output_tensor_ptrs_cache_.reset(new std::vector<lite::Tensor*>({Out}));
    }
    return output_tensor_ptrs_cache_.get();
  }
1385 1386
};

Y
Yan Chunwei 已提交
1387
/// ----------------------- expand operators ----------------------
1388
struct ExpandParam : ParamBase {
Y
Yan Chunwei 已提交
1389 1390 1391 1392 1393
  const lite::Tensor* X{};
  lite::Tensor* Out{};
  std::vector<int> expand_times{};
};

1394 1395 1396 1397 1398 1399 1400
/// ----------------------- expand as operators ----------------------
struct ExpandAsParam : ParamBase {
  const lite::Tensor* X{};
  const lite::Tensor* Target{};
  lite::Tensor* Out{};
};

Y
Yan Chunwei 已提交
1401
/// ----------------------- matmul operators ----------------------
1402
struct MatMulParam : ParamBase {
Y
Yan Chunwei 已提交
1403 1404 1405 1406 1407 1408
  const lite::Tensor* X{};
  const lite::Tensor* Y{};
  lite::Tensor* Out{};
  bool transpose_X{false};
  bool transpose_Y{false};
  float alpha{1.0f};
1409 1410
  ///////////////////////////////////////////////////////////////////////////////////
  // get a vector of input tensors
1411 1412
  const std::vector<const Tensor*>* input_tensor_ptrs() override {
    if (!input_tensor_ptrs_cache_) {
1413 1414 1415 1416 1417
      input_tensor_ptrs_cache_.reset(new std::vector<const Tensor*>({X, Y}));
    }
    return input_tensor_ptrs_cache_.get();
  }
  // get a vector of output tensors
1418 1419
  std::vector<Tensor*>* output_tensor_ptrs() override {
    if (!output_tensor_ptrs_cache_) {
1420 1421 1422 1423
      output_tensor_ptrs_cache_.reset(new std::vector<lite::Tensor*>({Out}));
    }
    return output_tensor_ptrs_cache_.get();
  }
Y
Yan Chunwei 已提交
1424
};
1425

1426
struct GatherParam : ParamBase {
T
TianXiaogang 已提交
1427 1428 1429 1430 1431
  const lite::Tensor* X{};
  const lite::Tensor* Index{};
  lite::Tensor* Out{};
};

1432
/// ----------------------- assign operators -----------------------
1433
struct AssignParam : ParamBase {
1434 1435 1436 1437 1438 1439 1440
  // 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};
1441
};
1442

1443
/// ----------------------- roi_align operators -----------------------
1444
struct RoiAlignParam : ParamBase {
1445 1446 1447 1448 1449 1450 1451 1452 1453
  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};
};

1454
/// ----------------------- box_clip operators -----------------------
1455
struct BoxClipParam : ParamBase {
1456 1457 1458 1459 1460
  const lite::Tensor* Input{};
  const lite::Tensor* ImInfo{};
  lite::Tensor* Output{};
};

1461
struct RangeParam : ParamBase {
1462 1463 1464 1465 1466 1467
  const lite::Tensor* Start;
  const lite::Tensor* End;
  const lite::Tensor* Step;
  lite::Tensor* Out;
};

1468
/// ----------------------- assign_value operators -----------------------
1469
struct AssignValueParam : ParamBase {
1470 1471 1472 1473
  std::vector<int> shape{};
  int dtype{};
  std::vector<float> fp32_values{};
  std::vector<int> int32_values{};
1474 1475
  std::vector<int64_t> int64_values{};
  std::vector<int> bool_values{};
1476 1477 1478
  lite::Tensor* Out{};
};

1479
/// --------------- sequence_topk_avg_pooling operators ------------------
1480
struct SequenceTopkAvgPoolingParam : ParamBase {
1481 1482 1483 1484 1485 1486 1487 1488 1489
  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{};
};

1490 1491 1492 1493 1494 1495 1496 1497 1498
/// --------------- topk_pooling operators ------------------
struct TopkPoolingParam : ParamBase {
  const lite::Tensor* X{};
  const lite::Tensor* Y{};
  lite::Tensor* Out{};
  int top_k{1};
  int feat_map_num{1};
};

1499
/// --------------- search_fc operators ------------------
1500
struct SearchFcParam : ParamBase {
1501 1502 1503 1504 1505
  const lite::Tensor* X{};
  const lite::Tensor* W{};
  const lite::Tensor* b{};
  lite::Tensor* Out{};
  int out_size{};
1506 1507 1508 1509 1510 1511 1512

  bool fuse_relu{false};

#ifdef LITE_WITH_XPU
  bool __xpu__float_to_fix{false};  // Is W already converted to int16/int8
  float __xpu__w_max{0.0f};         // Abs max in W
#endif
1513
};
J
juncaipeng 已提交
1514
/// --------------------- match_matrix_tensor operators --------------------
1515
struct MatchMatrixTensorParam : ParamBase {
J
juncaipeng 已提交
1516 1517 1518 1519 1520 1521 1522
  const lite::Tensor* x{};
  const lite::Tensor* y{};
  const lite::Tensor* w{};
  lite::Tensor* out{};
  lite::Tensor* tmp{};

  int dim_t;
1523 1524 1525 1526 1527 1528
  bool fuse_relu{false};

#ifdef LITE_WITH_XPU
  bool __xpu__float_to_fix{false};  // Is w already converted to int16/int8
  float __xpu__w_max{0.0f};         // Abs max in w
#endif
J
juncaipeng 已提交
1529 1530 1531
};

/// --------------------- search_seq_depadding operators --------------------
1532
struct SearchSeqDepaddingParam : ParamBase {
J
juncaipeng 已提交
1533 1534 1535 1536 1537 1538
  const lite::Tensor* pad{};
  const lite::Tensor* src{};
  lite::Tensor* out{};
};

/// --------------------- search_grnn operators --------------------
1539
struct SearchGrnnParam : ParamBase {
J
juncaipeng 已提交
1540 1541 1542 1543 1544 1545 1546 1547 1548 1549
  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{};
1550 1551 1552 1553 1554 1555

#ifdef LITE_WITH_XPU
  bool __xpu__float_to_fix{false};   // Is wi/wh already converted to int16/int8
  std::vector<float> __xpu__wi_max;  // Abs max in wi
  std::vector<float> __xpu__wh_max;  // Abs max in wh
#endif
J
juncaipeng 已提交
1556 1557
};

1558
struct SplitLodTensorParam : ParamBase {
J
juncaipeng 已提交
1559 1560 1561 1562 1563 1564 1565
  const lite::Tensor* x{};
  const lite::Tensor* mask{};
  lite::Tensor* out_true{};
  lite::Tensor* out_false{};
  int level{};
};

1566
struct MergeLodTensorParam : ParamBase {
J
juncaipeng 已提交
1567 1568 1569 1570 1571 1572 1573 1574
  const lite::Tensor* x{};
  const lite::Tensor* mask{};
  const lite::Tensor* in_true{};
  const lite::Tensor* in_false{};
  lite::Tensor* out{};
  int level{};
};

1575
struct ConditionalBlockParam : ParamBase {
J
juncaipeng 已提交
1576
  const lite::Tensor* cond{};
1577
  std::vector<lite::Tensor*> inputs{};
J
juncaipeng 已提交
1578
  std::vector<lite::Tensor*> outs{};
1579 1580 1581
  int block_idx{-1};
  std::shared_ptr<const cpp::ProgramDesc> program_desc{nullptr};
  Scope* exec_scope{nullptr};
J
juncaipeng 已提交
1582 1583 1584
  bool is_scalar_condition{};
};

1585
struct CollectFpnProposalsParam : ParamBase {
J
juncaipeng 已提交
1586 1587 1588 1589 1590 1591
  std::vector<lite::Tensor*> multi_level_rois{};
  std::vector<lite::Tensor*> multi_level_scores{};
  lite::Tensor* fpn_rois{};
  int post_nms_topN{};
};

1592
struct DistributeFpnProposalsParam : ParamBase {
J
juncaipeng 已提交
1593 1594 1595 1596 1597 1598 1599 1600 1601
  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{};
};

1602
/// --------------------- instance_norm operators --------------------
1603
struct InstanceNormParam : ParamBase {
1604 1605 1606 1607 1608 1609 1610 1611
  lite::Tensor* x{};
  lite::Tensor* out{};
  lite::Tensor* bias{};
  lite::Tensor* scale{};
  lite::Tensor* saved_mean{};
  lite::Tensor* saved_variance{};
  float epsilon;
};
H
HappyAngel 已提交
1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624
/// --------------------- 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;
};

1625
/// --------------------- grid sampler operators --------------------
1626
struct GridSamplerParam : ParamBase {
1627 1628 1629 1630
  lite::Tensor* x{};
  lite::Tensor* out{};
  lite::Tensor* grid{};
};
1631
struct LstmParam : ParamBase {
X
xiaogang 已提交
1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646
  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;
};
1647

1648
struct CrfDecodingParam : ParamBase {
C
cc 已提交
1649 1650 1651 1652 1653 1654 1655
  lite::Tensor* emission{};
  lite::Tensor* transition{};
  lite::Tensor* label{};
  lite::Tensor* length{};
  lite::Tensor* viterbi_path{};
};

1656 1657 1658 1659 1660 1661 1662 1663 1664 1665
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};
};

1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687
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{};
1688
  std::string precision{};
1689
  bool enable_qkv_fusion{false};
1690 1691
};

C
Cwndmiao 已提交
1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711
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{""};
};

1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751
struct XPUResNetCbamParam : ParamBase {
  lite::Tensor* input{};
  std::vector<lite::Tensor*> filter;
  std::vector<lite::Tensor*> bias;
  std::vector<lite::Tensor*> max_filter;
  lite::Tensor* output{};

  float pool_p{1.0f};
};

struct XPUMmdnnSearchAttentionParam : ParamBase {
  lite::Tensor* X{};
  lite::Tensor* W{};
  lite::Tensor* b{};
  lite::Tensor* Out{};

  float W_max{0.0f};
  int pad_id{0};
  float alpha0{1.0f};
  float alpha1{1.0f};
  float mask{1.0f};
};

struct XPUMmdnnBidEmbGrnnAttParam : ParamBase {
  lite::Tensor* id0{};
  lite::Tensor* id1{};
  lite::Tensor* emb_tbl{};
  lite::Tensor* grnn_fw_wh{};
  lite::Tensor* grnn_fw_wi{};
  lite::Tensor* grnn_rv_wh{};
  lite::Tensor* grnn_rv_wi{};
  lite::Tensor* att_fc_w{};
  lite::Tensor* att_fc_b{};

  std::vector<float> grnn_fw_wh_maxs;
  std::vector<float> grnn_fw_wi_maxs;
  std::vector<float> grnn_rv_wh_maxs;
  std::vector<float> grnn_rv_wi_maxs;
  float att_fc_w_max{0.0f};

1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781
  lite::Tensor* grnn_fw_pool_out{};
  lite::Tensor* grnn_rv_pool_out{};
  lite::Tensor* att_pool_out{};
  lite::Tensor* concat_3in1_out{};
  lite::Tensor* emb_fw_out{};
};

struct XPUMmdnnBidEmbGrnnAttParam2 : ParamBase {
  lite::Tensor* id0{};
  lite::Tensor* id1{};
  lite::Tensor* emb_tbl{};
  lite::Tensor* grnn_fw_wh{};
  lite::Tensor* grnn_fw_wi{};
  lite::Tensor* grnn_rv_wh{};
  lite::Tensor* grnn_rv_wi{};
  lite::Tensor* att_fc_w{};
  lite::Tensor* att_fc_b{};

  std::vector<float> grnn_fw_wh_maxs;
  std::vector<float> grnn_fw_wi_maxs;
  std::vector<float> grnn_rv_wh_maxs;
  std::vector<float> grnn_rv_wi_maxs;
  float att_fc_w_max{0.0f};

  lite::Tensor* emb0_out{};
  lite::Tensor* grnn_fw_pool_out{};
  lite::Tensor* grnn_rv_pool_out{};
  lite::Tensor* att_pool_out{};
  lite::Tensor* concat_3in1_out{};
  lite::Tensor* emb_fw_out{};
1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792
};

struct XPUMmdnnBidEmbAttParam : ParamBase {
  lite::Tensor* id0{};
  lite::Tensor* id1{};
  lite::Tensor* emb_tbl{};
  lite::Tensor* att_fc_w{};
  lite::Tensor* att_fc_b{};

  float att_fc_w_max{0.0f};

1793 1794
  lite::Tensor* att_pool_out{};
  lite::Tensor* emb_fw_out{};
1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805
};

struct XPUMmdnnMatchConvTopkParam : ParamBase {
  lite::Tensor* input_x{};
  lite::Tensor* input_y{};
  lite::Tensor* input_w{};
  lite::Tensor* conv_w{};

  float input_w_max{0.0f};
  float conv_w_max{0.0f};
  std::vector<int> topks;
1806
  int output_channel{0};
1807 1808 1809 1810 1811 1812 1813 1814
  int channel_num{0};
  int dim_t{0};

  lite::Tensor* topk_out{};
};

struct XPUMmdnnMergeAllParam : ParamBase {
  std::vector<lite::Tensor*> concat_7in1_x;
1815
  std::vector<lite::Tensor*> concat_topk_x;
1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837
  lite::Tensor* grnn_fw_wh{};
  lite::Tensor* grnn_fw_wi{};
  lite::Tensor* grnn_rv_wh{};
  lite::Tensor* grnn_rv_wi{};
  lite::Tensor* fc0_w{};
  lite::Tensor* fc0_b{};
  lite::Tensor* fc1_w{};
  lite::Tensor* fc1_b{};
  lite::Tensor* fc2_w{};
  lite::Tensor* fc2_b{};

  std::vector<float> grnn_fw_wh_maxs;
  std::vector<float> grnn_fw_wi_maxs;
  std::vector<float> grnn_rv_wh_maxs;
  std::vector<float> grnn_rv_wi_maxs;
  float fc0_w_max{0.0f};
  float fc1_w_max{0.0f};
  float fc2_w_max{0.0f};

  lite::Tensor* out{};
};

1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848
struct XPUConv2dParam : ParamBase {
  lite::Tensor* Input{nullptr};
  lite::Tensor* Filter{nullptr};
  lite::Tensor* InputMax{nullptr};
  lite::Tensor* FilterMax{nullptr};
  lite::Tensor* Bias{nullptr};
  lite::Tensor* Branch{nullptr};
  lite::Tensor* Output{nullptr};
  lite::Tensor* OutputMax{nullptr};

  int groups{1};
1849
  std::string act_type{""};
1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862
  std::string filter_type{""};
  std::vector<int> strides;
  std::shared_ptr<std::vector<int>> paddings;
  std::shared_ptr<std::vector<int>> dilations;
};

struct XPUSfaHeadParam : ParamBase {
  lite::Tensor* input{nullptr};
  lite::Tensor* output{nullptr};

  std::string op_type{""};
};

H
HappyAngel 已提交
1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895
// 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();
  }
};

1896 1897 1898 1899 1900
struct PixelShuffleParam : ParamBase {
  lite::Tensor* x{nullptr};
  lite::Tensor* output{nullptr};
  int upscale_factor{1};
};
1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914

struct RetinanetDetectionOutputParam : ParamBase {
  std::vector<Tensor*> bboxes{};
  std::vector<Tensor*> scores{};
  std::vector<Tensor*> anchors{};
  Tensor* im_info{};
  Tensor* out{};
  float score_threshold{};
  int nms_top_k{};
  float nms_threshold{};
  float nms_eta{};
  int keep_top_k{};
};

Y
yiicy 已提交
1915 1916 1917 1918 1919
struct WhereIndexParam : ParamBase {
  const lite::Tensor* input{nullptr};
  lite::Tensor* output{nullptr};
};

C
cc 已提交
1920 1921 1922 1923 1924 1925 1926 1927 1928
struct ClipParam : ParamBase {
  Tensor* x{};
  Tensor* min_tensor{};
  Tensor* max_tensor{};
  Tensor* out{};
  float min{};
  float max{};
};

1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944
struct PrintParam : ParamBase {
  const lite::Tensor* in{};
  lite::Tensor* out{};
  std::string name;
  int first_n{-1};
  std::string message;
  int summarize{20};
  bool print_tensor_name{true};
  bool print_tensor_type{true};
  bool print_tensor_shape{true};
  bool print_tensor_lod{true};
  bool print_tensor_layout{true};
  std::string print_phase;
  bool is_forward{true};
};

1945 1946 1947 1948 1949 1950 1951 1952 1953
struct OneHotParam : ParamBase {
  const lite::Tensor* X{};
  const lite::Tensor* depth_tensor{nullptr};
  lite::Tensor* Out{};
  int depth;
  int dtype;
  bool allow_out_of_range;
};

Y
Yan Chunwei 已提交
1954 1955 1956
}  // namespace operators
}  // namespace lite
}  // namespace paddle