From 84a38b19fb65061ef8539131dd3cbb57ea920734 Mon Sep 17 00:00:00 2001 From: hanbuhe Date: Wed, 12 Sep 2018 20:21:22 +0800 Subject: [PATCH] softmax added cpu cache flush and invalidate --- src/operators/kernel/fpga/softmax_kernel.cpp | 39 ++++++++++++-------- src/operators/op_param.h | 2 +- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/operators/kernel/fpga/softmax_kernel.cpp b/src/operators/kernel/fpga/softmax_kernel.cpp index 7c784ce474..f218edbec6 100644 --- a/src/operators/kernel/fpga/softmax_kernel.cpp +++ b/src/operators/kernel/fpga/softmax_kernel.cpp @@ -25,21 +25,23 @@ namespace operators { template <> bool SoftmaxKernel::Init(SoftmaxParam *param) { const Tensor *input = param->InputX(); - if (input->type() == typeid(half)) { - auto input_ptr = input->data(); - auto output_ptr = param->Out(); - fpga::BypassArgs args; - args.input_layout_type = fpga::LAYOUT_HWC; - args.output_layout_type = fpga::LAYOUT_CHW; - args.input_data_type = fpga::DATA_TYPE_FP16; - args.output_data_type = fpga::DATA_TYPE_FP32; - args.image.address = (void *)(input_ptr); - args.image.height = (uint32_t)input->dims()[0]; - args.image.width = (uint32_t)input->dims()[1]; - args.image.channels = 1; - args.output.address = output_ptr; - param->SetFpgaArgs(args); - } + auto input_ptr = input->data(); + auto output_ptr = param->Out(); + Tensor *floatInput = new Tensor(*input); + fpga::BypassArgs args; + args.input_layout_type = fpga::LAYOUT_HWC; + args.output_layout_type = fpga::LAYOUT_CHW; + args.input_data_type = fpga::DATA_TYPE_FP16; + args.output_data_type = fpga::DATA_TYPE_FP32; + args.image.address = reinterpret_cast(input_ptr); + args.image.height = (uint32_t)input->dims()[0]; + args.image.width = (uint32_t)input->dims()[1]; + args.image.channels = 1; + args.output.address = + reinterpret_cast floatInput->mutable_data(); + + param->SetFloatInput(floatInput); + param->SetFpgaArgs(args); return true; } @@ -48,8 +50,13 @@ void SoftmaxKernel::Compute( const SoftmaxParam ¶m) const { DLOG << "======================================= FPGA SoftMAX " "==============================================="; - const Tensor *in_x = param.InputX(); + const Tensor *in_x = param.FloatInput(); Tensor *out = param.Out(); + fpga::fpga_flush(reinterpret_cast in_x->data(), + in_x->memory_size()); + fpga::PerformBypass(param.FpgaArgs()); + fpga::fpga_invalidate(out->data(), out->memory_size()); + auto x_dims = in_x->dims(); out->Resize(x_dims); math::SoftmaxFuntor()(in_x, out); diff --git a/src/operators/op_param.h b/src/operators/op_param.h index 1728e6a6cc..1c5815c642 100644 --- a/src/operators/op_param.h +++ b/src/operators/op_param.h @@ -785,7 +785,7 @@ class SoftmaxParam : public OpParam { fpga::BypassArgs fpga_bypass_args; public: - RType *FloatInput() { + RType *FloatInput() const { return float_input_x_ == nullptr ? input_x_ : float_input_x_.get(); } void SetFloatInput(Tensor *input) { float_input_x_.reset(input); } -- GitLab