pe_params.hpp 5.5 KB
Newer Older
C
Chon 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/* 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

#include <stdio.h>
T
TianXiaogang 已提交
18
#include <string>
C
Chon 已提交
19 20
#include <vector>

21 22
#include "lite/backends/fpga/KD/llapi/zynqmp_api.h"
#include "lite/backends/fpga/KD/tensor.hpp"
C
Chon 已提交
23

Y
Yan Chunwei 已提交
24
namespace paddle {
C
Chon 已提交
25 26
namespace zynqmp {

Y
Yan Chunwei 已提交
27 28 29
struct ReLUParam {
 public:
  bool enabled = false;
T
TianXiaogang 已提交
30
  float leaky_relu_factor = 0.0f;
Y
Yan Chunwei 已提交
31 32
};

C
chonwhite 已提交
33 34 35 36 37
struct ActiveParam {
  enum ActiveType type = TYPE_NONE;
  float leaky_relu_factor;
};

Y
Yan Chunwei 已提交
38
struct PEParam {
C
chonwhite 已提交
39
  ActiveParam activeParam;
Y
Yan Chunwei 已提交
40
};
C
Chon 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55

struct InputParam : PEParam {
 public:
  Tensor* input = nullptr;
  Tensor* output = nullptr;
};

struct OutputParam : PEParam {
 public:
  Tensor* input = nullptr;
  Tensor* output = nullptr;
};

struct BatchnormParam : PEParam {
 public:
Y
Yan Chunwei 已提交
56 57 58
  Tensor* input = nullptr;
  Tensor* output = nullptr;

C
Chon 已提交
59 60 61 62 63 64 65 66
  Tensor* bias = nullptr;
  Tensor* scale = nullptr;
  Tensor* mean = nullptr;
  Tensor* variance = nullptr;
  float epsilon = 0;
};

struct BasicConvParam {
Y
Yan Chunwei 已提交
67
  Tensor input;
C
Chon 已提交
68 69 70 71 72 73 74 75 76 77 78
  Tensor output;
  Tensor filter;
  Tensor scaleBias;
  ConvArgs args;
};

struct ConvParam : PEParam {
 public:
  Tensor* input = nullptr;
  Tensor* output = nullptr;
  Tensor* filter = nullptr;
Y
Yan Chunwei 已提交
79

C
Chon 已提交
80 81 82 83 84 85
  int groups = 1;
  std::vector<int> strides;
  std::vector<int> paddings;
  std::vector<int> kernelSize;
  std::vector<int> dilations;

C
chonwhite 已提交
86
  Tensor* scale() { return &scale_; }
C
Chon 已提交
87

C
chonwhite 已提交
88
  Tensor* bias() { return &bias_; }
C
Chon 已提交
89 90 91

  std::vector<BasicConvParam*>& splitParams() { return splitParams_; }

C
chonwhite 已提交
92 93 94 95 96 97 98 99
  ~ConvParam() {
    for (int i = 0; i < splitParams_.size(); i++) {
      BasicConvParam* basic_param = splitParams_[i];
      delete basic_param;
    }
    splitParams_.clear();
  }

C
Chon 已提交
100 101
 protected:
  std::vector<BasicConvParam*> splitParams_;
C
chonwhite 已提交
102 103
  Tensor scale_;
  Tensor bias_;
C
Chon 已提交
104 105 106 107
};

struct DepthwiseConvParam : ConvParam {
 public:
C
chonwhite 已提交
108
  Tensor* quantizedFilter() { return &quantizedFilter_; }
C
Chon 已提交
109 110 111 112

  DWconvArgs args;

 protected:
C
chonwhite 已提交
113
  Tensor quantizedFilter_;
C
Chon 已提交
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
};

enum PoolingType : int {
  MAX = 0,
  AVERAGE = 1,
};

struct PoolingParam : PEParam {
 public:
  Tensor* input = nullptr;
  Tensor* output = nullptr;

  PoolingType type = PoolingType::MAX;
  bool globalPooling = false;
  std::vector<int> kernelSize;
  std::vector<int> strides;
  std::vector<int> paddings;

  PoolingArgs poolingArgs = {0};
};

struct ConcatParam : PEParam {
 public:
  std::vector<Tensor*> inputs;
  Tensor* output;
  int axis = 0;
};

struct ElementwiseAddParam : PEParam {
 public:
  std::vector<Tensor*> inputs;
  Tensor* output = nullptr;
  int axis = 0;

  EWAddArgs ewargs;
};

T
TianXiaogang 已提交
151 152
struct ElementwiseMulParam : PEParam {
 public:
C
chonwhite 已提交
153
  Tensor* input_x = nullptr;
C
chonwhite 已提交
154
  Tensor* input_y = nullptr;
T
TianXiaogang 已提交
155 156 157
  Tensor* output = nullptr;
};

C
Chon 已提交
158 159 160 161 162 163 164
struct FullyConnectedParam : PEParam {
 public:
  Tensor* input = nullptr;
  Tensor* filter = nullptr;
  Tensor* bias = nullptr;
  Tensor* output = nullptr;

C
chonwhite 已提交
165
  Tensor* quantizedFilter() { return &quantizedFilter_; }
C
Chon 已提交
166

C
chonwhite 已提交
167
  Tensor* biasScale() { return &biasScale_; }
C
Chon 已提交
168 169

 protected:
C
chonwhite 已提交
170 171
  Tensor quantizedFilter_;
  Tensor biasScale_;
C
Chon 已提交
172 173 174 175 176 177 178 179 180 181 182
};

struct SoftmaxParam : PEParam {
 public:
  Tensor* input = nullptr;

  Tensor* output = nullptr;

 private:
  Tensor* floatInput = nullptr;
};
Y
Yan Chunwei 已提交
183 184 185 186 187 188 189 190 191

struct SplitParam : PEParam {
 public:
  Tensor* input = nullptr;
  std::vector<Tensor*> outputs;
  int axis = 1;
  int num = 1;
};

C
Chon 已提交
192 193 194 195 196
struct NormParam : PEParam {
 public:
  Tensor* input = nullptr;

  Tensor* output = nullptr;
Y
Yan Chunwei 已提交
197
  float epsilon = 0;
C
Chon 已提交
198 199 200 201 202

 private:
  Tensor* floatInput = nullptr;
};

Y
Yan Chunwei 已提交
203
struct PriorBoxParam : PEParam {
C
chonwhite 已提交
204 205 206 207
  Tensor* input = nullptr;
  Tensor* image = nullptr;
  Tensor* outputBoxes = nullptr;
  Tensor* outputVariances = nullptr;
Y
Yan Chunwei 已提交
208 209 210 211 212 213 214 215 216 217 218 219 220 221

  std::vector<float> minSizes;
  std::vector<float> maxSizes;
  std::vector<float> aspectRatios;
  std::vector<float> variances;

  bool minMaxAspectRatiosOrder;
  bool flip;
  bool clip;
  float stepW;
  float stepH;
  float offset;
};

C
chonwhite 已提交
222
struct YoloBoxParam : PEParam {
C
chonwhite 已提交
223 224 225 226
  Tensor* input = nullptr;
  Tensor* imgSize = nullptr;
  Tensor* outputBoxes = nullptr;
  Tensor* outputScores = nullptr;
C
chonwhite 已提交
227 228 229 230 231 232
  int downsampleRatio;
  std::vector<int> anchors;
  int classNum;
  float confThresh;
};

Y
Yan Chunwei 已提交
233 234 235 236 237 238 239
struct ScaleParam : PEParam {
 public:
  Tensor* input = nullptr;
  Tensor* output = nullptr;
  Tensor* scale = nullptr;
  Tensor* bias = nullptr;

C
chonwhite 已提交
240
  Tensor* alignedScale() { return &alignedScale_; }
Y
Yan Chunwei 已提交
241

C
chonwhite 已提交
242
  Tensor* alignedBias() { return &alignedBias_; }
Y
Yan Chunwei 已提交
243 244 245 246

  ScaleArgs args = {0};

 protected:
C
chonwhite 已提交
247 248
  Tensor alignedScale_;
  Tensor alignedBias_;
Y
Yan Chunwei 已提交
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
};

struct ResizeParam : PEParam {
 public:
  Tensor* input = nullptr;
  Tensor* output = nullptr;
};

struct CropParam : PEParam {
 public:
  Tensor* input = nullptr;
  Tensor* output = nullptr;
  int axis = 2;
  std::vector<int> offsets;
  std::vector<int> shape;
};
C
chonwhite 已提交
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283

struct GRUParam : PEParam {
 public:
  Tensor* input = nullptr;
  Tensor* h0 = nullptr;
  Tensor* weight = nullptr;
  Tensor* bias = nullptr;

  Tensor* batch_gate = nullptr;
  Tensor* batch_reset_hidden_prev = nullptr;
  Tensor* batch_hidden = nullptr;
  Tensor* hidden = nullptr;

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

Y
Yan Chunwei 已提交
284 285
}  // namespace zynqmp
}  // namespace paddle