elementwise_add_relu_kernel.cpp 2.2 KB
Newer Older
qnqinan's avatar
qnqinan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#ifdef FUSION_ELEMENTWISEADDRELU_OP

#include "operators/kernel/elementwise_add_relu_kernel.h"

namespace paddle_mobile {
19 20 21 22
namespace operators {

template <>
bool ElementwiseAddReluKernel<FPGA, float>::Init(
N
nhzlx 已提交
23
    ElementwiseAddReluParam<FPGA> *param) {
24
  bool relu_enabled = true;
Z
zhangyang 已提交
25 26
  Tensor *input_x = const_cast<Tensor *>(param->InputX());
  Tensor *input_y = const_cast<Tensor *>(param->InputY());
27
  Tensor *out = param->Out();
28 29
  auto input_x_ptr = input_x->data<half>();
  auto input_y_ptr = input_y->data<half>();
Z
zhangyang 已提交
30
  fpga::format_ofm(out);
31
  auto out_ptr = out->mutable_data<half>();
qnqinan's avatar
qnqinan 已提交
32

33 34 35 36 37 38
  fpga::EWAddArgs ewaddArgs;
  ewaddArgs.relu_enabled = relu_enabled;
  ewaddArgs.const0 = 1;
  ewaddArgs.const1 = 1;
  ewaddArgs.image0.address = (void *)input_x_ptr;
  ewaddArgs.image0.channels = input_x->dims()[1];
Z
zhangyang 已提交
39
  ewaddArgs.image0.scale_address = input_x->scale;
40 41
  ewaddArgs.image0.height = input_x->dims()[2];
  ewaddArgs.image0.width = input_x->dims()[3];
42 43
  ewaddArgs.image0.pad_height = 0;
  ewaddArgs.image0.pad_width = 0;
44 45
  ewaddArgs.image1.address = (void *)input_y_ptr;
  ewaddArgs.image1.channels = input_y->dims()[1];
Z
zhangyang 已提交
46
  ewaddArgs.image1.scale_address = input_y->scale;
47 48
  ewaddArgs.image1.height = input_y->dims()[2];
  ewaddArgs.image1.width = input_y->dims()[3];
49 50
  ewaddArgs.image1.pad_height = 0;
  ewaddArgs.image1.pad_width = 0;
Z
zhangyang 已提交
51
  ewaddArgs.output.scale_address = out->scale;
52 53 54 55 56 57 58
  ewaddArgs.output.address = (void *)out_ptr;
  param->SetFpgaArgs(ewaddArgs);
  return true;
}

template <>
void ElementwiseAddReluKernel<FPGA, float>::Compute(
N
nhzlx 已提交
59
    const ElementwiseAddReluParam<FPGA> &param) const {
60 61 62
  fpga::ComputeFpgaEWAdd(param.FpgaArgs());
}
}  // namespace operators
qnqinan's avatar
qnqinan 已提交
63 64
}  // namespace paddle_mobile

65
#endif