From c403e1e325199568f5396dbf1426da25bb36957f Mon Sep 17 00:00:00 2001 From: jameswu2014 <545426914@qq.com> Date: Tue, 4 Jun 2019 19:40:38 +0800 Subject: [PATCH] concat+fetch bug for FPGA V1 track (#1678) * marker1-anchor update * concat-fetch bug --- src/fpga/V1/api.cpp | 1 + src/framework/executor.cpp | 6 +++--- src/io/api_paddle_mobile.cc | 16 ++++++++++++++++ src/operators/kernel/fpga/V1/relu_kernel.cpp | 4 +++- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/fpga/V1/api.cpp b/src/fpga/V1/api.cpp index 2bcae0cb47..dc5163d2b2 100644 --- a/src/fpga/V1/api.cpp +++ b/src/fpga/V1/api.cpp @@ -273,6 +273,7 @@ void format_concat_output(framework::Tensor *out, int height, int width, auto ddim = framework::make_ddim({1, sum_channel, height, width}); out->Resize(ddim); out->reset_data_ptr(data_ptr); + out->fpga_data_num = sum_cw * height; out->set_type(type_id().hash_code()); } void format_conv_data(framework::Tensor *filter_tensor, diff --git a/src/framework/executor.cpp b/src/framework/executor.cpp index 28b8b1f652..57af9c62de 100644 --- a/src/framework/executor.cpp +++ b/src/framework/executor.cpp @@ -561,9 +561,9 @@ template void Executor::FeedData(const std::vector &v) { auto input_size = v.size(); int index = 0; - auto vars = program_.scope->VarContain("feed", &index); - PADDLE_MOBILE_ENFORCE(input_size == vars.size(), - "input data number not correct"); + // auto vars = program_.scope->VarContain("feed", &index); + // PADDLE_MOBILE_ENFORCE(input_size == vars.size(), + // "input data number not correct"); for (int i = 0; i < input_size; i++) { auto var = program_.scope->Var("feed", i + index); auto feed_tensor = var->template GetMutable(); diff --git a/src/io/api_paddle_mobile.cc b/src/io/api_paddle_mobile.cc index 1c1bb11d6e..ac5a0681f1 100644 --- a/src/io/api_paddle_mobile.cc +++ b/src/io/api_paddle_mobile.cc @@ -19,6 +19,9 @@ #include #include "common/enforce.h" #include "framework/tensor.h" +#ifdef PADDLE_MOBILE_FPGA +#include +#endif namespace paddle_mobile { @@ -179,6 +182,19 @@ void PaddleMobilePredictor::FetchPaddleTensors(PaddleTensor *output, int id) { std::shared_ptr tensor_ptr = paddle_mobile_->FetchResult(id); + void *data_addr = nullptr; + int data_sizeof = 1; + if (tensor_ptr.get()->type() == type_id().hash_code()) { + data_addr = tensor_ptr.get()->data(); + data_sizeof = sizeof(half); + } else if (tensor_ptr.get()->type() == type_id().hash_code()) { + data_addr = tensor_ptr.get()->data(); + data_sizeof = sizeof(float); + } else { + PADDLE_MOBILE_ENFORCE(0, "output typeid is not supported"); + } + size_t size = tensor_ptr.get()->numel() * data_sizeof; + fpga::fpga_invalidate(data_addr, size); ConvertTensors(*(tensor_ptr.get()), output); return; } diff --git a/src/operators/kernel/fpga/V1/relu_kernel.cpp b/src/operators/kernel/fpga/V1/relu_kernel.cpp index 6fff10f620..75dda4bf6d 100644 --- a/src/operators/kernel/fpga/V1/relu_kernel.cpp +++ b/src/operators/kernel/fpga/V1/relu_kernel.cpp @@ -26,7 +26,9 @@ bool ReluKernel::Init(ReluParam *param) { } template <> -void ReluKernel::Compute(const ReluParam ¶m) {} +void ReluKernel::Compute(const ReluParam ¶m) { + PADDLE_MOBILE_ENFORCE(0, "relu as a single op is wrong"); +} } // namespace operators } // namespace paddle_mobile -- GitLab