pe_params.hpp 5.0 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>
M
MyPandaShaoxiang 已提交
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;
M
MyPandaShaoxiang 已提交
30
  float leaky_relu_factor = 0.0f;
Y
Yan Chunwei 已提交
31 32 33 34 35
};

struct PEParam {
  ReLUParam relu;
};
C
Chon 已提交
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50

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 已提交
51 52 53
  Tensor* input = nullptr;
  Tensor* output = nullptr;

C
Chon 已提交
54 55 56 57 58 59 60 61
  Tensor* bias = nullptr;
  Tensor* scale = nullptr;
  Tensor* mean = nullptr;
  Tensor* variance = nullptr;
  float epsilon = 0;
};

struct BasicConvParam {
Y
Yan Chunwei 已提交
62
  Tensor input;
C
Chon 已提交
63 64 65 66 67 68 69 70 71 72 73
  Tensor output;
  Tensor filter;
  Tensor scaleBias;
  ConvArgs args;
};

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

C
Chon 已提交
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
  int groups = 1;
  std::vector<int> strides;
  std::vector<int> paddings;
  std::vector<int> kernelSize;
  std::vector<int> dilations;

  Tensor* scale() { return scale_; }

  Tensor* bias() { return bias_; }

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

 protected:
  std::vector<BasicConvParam*> splitParams_;
  Tensor* scale_ = new Tensor();
  Tensor* bias_ = new Tensor();
};

struct DepthwiseConvParam : ConvParam {
 public:
  Tensor* quantizedFilter() { return quantizedFilter_; }

  DWconvArgs args;

 protected:
  Tensor* quantizedFilter_ = new Tensor();
};

M
MyPandaShaoxiang 已提交
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
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;
};

C
Chon 已提交
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 151 152 153 154 155
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;
};

M
MyPandaShaoxiang 已提交
156 157 158 159 160 161
struct ElementwiseMulParam : PEParam {
 public:
  std::vector<Tensor*> inputs;
  Tensor* output = nullptr;
};

C
Chon 已提交
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
struct FullyConnectedParam : PEParam {
 public:
  Tensor* input = nullptr;
  Tensor* filter = nullptr;
  Tensor* bias = nullptr;
  Tensor* output = nullptr;

  Tensor* quantizedFilter() { return quantizedFilter_; }

  Tensor* biasScale() { return biasScale_; }

 protected:
  Tensor* quantizedFilter_ = new Tensor();
  Tensor* biasScale_ = new Tensor();
};

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

  Tensor* output = nullptr;

 private:
  Tensor* floatInput = nullptr;
};
Y
Yan Chunwei 已提交
187 188 189 190 191 192 193 194 195

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

C
Chon 已提交
196 197 198 199 200
struct NormParam : PEParam {
 public:
  Tensor* input = nullptr;

  Tensor* output = nullptr;
Y
Yan Chunwei 已提交
201
  float epsilon = 0;
C
Chon 已提交
202 203 204 205 206

 private:
  Tensor* floatInput = nullptr;
};

Y
Yan Chunwei 已提交
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
struct PriorBoxParam : PEParam {
  Tensor* input;
  Tensor* image;
  Tensor* outputBoxes;
  Tensor* outputVariances;

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

struct ScaleParam : PEParam {
 public:
  Tensor* input = nullptr;
  Tensor* output = nullptr;
  Tensor* scale = nullptr;
  Tensor* bias = nullptr;

  Tensor* alignedScale() { return alignedScale_; }

  Tensor* alignedBias() { return alignedBias_; }

  ScaleArgs args = {0};

 protected:
  Tensor* alignedScale_ = new Tensor();
  Tensor* alignedBias_ = new Tensor();
};

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;
};
}  // namespace zynqmp
}  // namespace paddle