pool_kernel.cpp 1.8 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 19 20
/* 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 POOL_OP

#include "operators/kernel/pool_kernel.h"
#include "fpga/api/fpga_api.h"

class PoolingArgs;
namespace paddle_mobile {
21 22 23 24 25 26 27 28 29 30 31
namespace operators {

template <>
bool PoolKernel<FPGA, float>::Init(PoolParam *param) {
  const Tensor *input = param->Input();
  auto input_ptr = input->data<float>();
  Tensor *output = param->Output();
  auto output_ptr = output->data<float>();
  vector<int> ksize = param->Ksize();
  vector<int> strides = param->Strides();
  vector<int> paddings = param->Paddings();
qnqinan's avatar
qnqinan 已提交
32

33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
  fpga::PoolingArgs poolArgs;
  poolArgs.image.address = (void *)input_ptr;
  poolArgs.image.channels = input->dims()[1];
  poolArgs.image.height = input->dims()[2];
  poolArgs.image.width = input->dims()[3];
  poolArgs.image.pad_height = paddings[0];
  poolArgs.image.pad_width = paddings[1];
  poolArgs.output.address = output_ptr;
  poolArgs.kernel.height = ksize[0];
  poolArgs.kernel.width = ksize[1];
  poolArgs.kernel.stride_h = strides[0];
  poolArgs.kernel.stride_w = strides[1];
  param->SetFpgaArgs(poolArgs);
  return true;
}

template <>
void PoolKernel<FPGA, float>::Compute(const PoolParam &param) const {
qnqinan's avatar
qnqinan 已提交
51
#ifdef PADDLE_MOBILE_FPGA
52
  fpga::ComputeFpgaPool(param.FpgaArgs());
qnqinan's avatar
qnqinan 已提交
53
#endif
54 55
}
}  // namespace operators
qnqinan's avatar
qnqinan 已提交
56 57
}  // namespace paddle_mobile

58
#endif