From c3248eaad890a5bff438c81637a82face188b9cc Mon Sep 17 00:00:00 2001 From: zhangyang Date: Thu, 16 Aug 2018 15:56:52 +0800 Subject: [PATCH] correct FPGA kernels --- src/operators/kernel/fpga/conv_add_bn_kernel.cpp | 6 +++--- src/operators/kernel/fpga/conv_add_bn_relu_kernel.cpp | 6 +++--- src/operators/kernel/fpga/conv_add_relu_kernel.cpp | 6 +++--- src/operators/kernel/fpga/conv_bn_kernel.cpp | 6 +++--- src/operators/kernel/fpga/conv_bn_relu_kernel.cpp | 6 +++--- src/operators/kernel/fpga/fc_relu_kernel.cpp | 2 +- src/operators/kernel/fpga/fusion_fc_kernel.cpp | 2 +- test/net/test_resnet.cpp | 6 ++++++ 8 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/operators/kernel/fpga/conv_add_bn_kernel.cpp b/src/operators/kernel/fpga/conv_add_bn_kernel.cpp index c2a6d29ac1..152b200cfa 100644 --- a/src/operators/kernel/fpga/conv_add_bn_kernel.cpp +++ b/src/operators/kernel/fpga/conv_add_bn_kernel.cpp @@ -37,11 +37,11 @@ bool ConvAddBNKernel::Init(FusionConvAddBNParam *param) { auto bn_scale_ptr = param->InputScale()->data(); auto bn_bias_ptr = param->InputBias()->data(); const float epsilon = param->Epsilon(); - PADDLE_MOBILE_ENFORCE(input->dims()[1] == bias->dims()[0] && + PADDLE_MOBILE_ENFORCE(out->dims()[1] == bias->dims()[0] && bias->dims()[0] == param->InputBias()->dims()[0], - "Image channel should be equal to bias number"); + "Output channel should be equal to bias number"); - const int channel = input->dims()[1]; + const int channel = out->dims()[1]; float *bs_ptr = reinterpret_cast(fpga::fpga_malloc(2 * channel * sizeof(float))); Tensor *new_scale = new Tensor(); diff --git a/src/operators/kernel/fpga/conv_add_bn_relu_kernel.cpp b/src/operators/kernel/fpga/conv_add_bn_relu_kernel.cpp index a6018df987..caa1e94c6b 100644 --- a/src/operators/kernel/fpga/conv_add_bn_relu_kernel.cpp +++ b/src/operators/kernel/fpga/conv_add_bn_relu_kernel.cpp @@ -35,11 +35,11 @@ bool ConvAddBNReluKernel::Init(FusionConvAddBNReluParam *param) { auto bn_scale_ptr = param->InputScale()->data(); auto bn_bias_ptr = param->InputBias()->data(); const float epsilon = param->Epsilon(); - PADDLE_MOBILE_ENFORCE(input->dims()[1] == bias->dims()[0] && + PADDLE_MOBILE_ENFORCE(out->dims()[1] == bias->dims()[0] && bias->dims()[0] == param->InputBias()->dims()[0], - "Image channel should be equal to bias number"); + "Output channel should be equal to bias number"); - const int channel = input->dims()[1]; + const int channel = out->dims()[1]; float *bs_ptr = (float *)fpga::fpga_malloc(2 * channel * sizeof(float)); Tensor *new_scale = new Tensor(); Tensor *new_bias = new Tensor(); diff --git a/src/operators/kernel/fpga/conv_add_relu_kernel.cpp b/src/operators/kernel/fpga/conv_add_relu_kernel.cpp index c5383bf1e9..33e55773ad 100644 --- a/src/operators/kernel/fpga/conv_add_relu_kernel.cpp +++ b/src/operators/kernel/fpga/conv_add_relu_kernel.cpp @@ -31,9 +31,9 @@ bool ConvAddReluKernel::Init(FusionConvAddReluParam *param) { Tensor *out = param->Output(); auto out_ptr = out->mutable_data(); - PADDLE_MOBILE_ENFORCE(input->dims()[1] == bias->dims()[0], - "Image channel should be equal to bias number"); - int channel = input->dims()[1]; + PADDLE_MOBILE_ENFORCE(out->dims()[1] == bias->dims()[0], + "Output channel should be equal to bias number"); + int channel = out->dims()[1]; float *bs_ptr = (float *)fpga::fpga_malloc(2 * channel * sizeof(float)); for (int i = 0; i < channel; i++) { bs_ptr[i * 2] = 1; diff --git a/src/operators/kernel/fpga/conv_bn_kernel.cpp b/src/operators/kernel/fpga/conv_bn_kernel.cpp index ee66c951a1..3ad65a254f 100644 --- a/src/operators/kernel/fpga/conv_bn_kernel.cpp +++ b/src/operators/kernel/fpga/conv_bn_kernel.cpp @@ -35,10 +35,10 @@ bool ConvBNKernel::Init(FusionConvBNParam *param) { auto bn_scale_ptr = param->InputScale()->data(); auto bn_bias_ptr = param->InputBias()->data(); const float epsilon = param->Epsilon(); - PADDLE_MOBILE_ENFORCE(input->dims()[1] == param->InputBias()->dims()[0], - "Image channel should be equal to bias number"); + PADDLE_MOBILE_ENFORCE(out->dims()[1] == param->InputBias()->dims()[0], + "Output channel should be equal to bias number"); - const int channel = input->dims()[1]; + const int channel = out->dims()[1]; float *bs_ptr = reinterpret_cast(fpga::fpga_malloc(2 * channel * sizeof(float))); Tensor *new_scale = new Tensor(); diff --git a/src/operators/kernel/fpga/conv_bn_relu_kernel.cpp b/src/operators/kernel/fpga/conv_bn_relu_kernel.cpp index f062cdce08..18ef4b4e15 100644 --- a/src/operators/kernel/fpga/conv_bn_relu_kernel.cpp +++ b/src/operators/kernel/fpga/conv_bn_relu_kernel.cpp @@ -33,10 +33,10 @@ bool ConvBNReluKernel::Init(FusionConvBNReluParam *param) { auto bn_scale_ptr = param->InputScale()->data(); auto bn_bias_ptr = param->InputBias()->data(); const float epsilon = param->Epsilon(); - PADDLE_MOBILE_ENFORCE(input->dims()[1] == param->InputBias()->dims()[0], - "Image channel should be equal to bias number"); + PADDLE_MOBILE_ENFORCE(out->dims()[1] == param->InputBias()->dims()[0], + "Output channel should be equal to bias number"); - const int channel = input->dims()[1]; + const int channel = out->dims()[1]; float *bs_ptr = (float *)fpga::fpga_malloc(2 * channel * sizeof(float)); Tensor *new_scale = new Tensor(); Tensor *new_bias = new Tensor(); diff --git a/src/operators/kernel/fpga/fc_relu_kernel.cpp b/src/operators/kernel/fpga/fc_relu_kernel.cpp index 499ced8d74..fb6a3e7508 100644 --- a/src/operators/kernel/fpga/fc_relu_kernel.cpp +++ b/src/operators/kernel/fpga/fc_relu_kernel.cpp @@ -33,7 +33,7 @@ bool FusionFcReluKernel::Init(FusionFcReluParam *param) { PADDLE_MOBILE_ENFORCE(input_x->dims()[1] == input_y->dims()[0], "Image channel should be equal to weight number"); - int channel = input_x->dims()[1]; + int channel = out->dims()[1]; float *bs_ptr = (float *)fpga::fpga_malloc(2 * channel * sizeof(float)); for (int i = 0; i < channel; i++) { bs_ptr[i * 2] = 1; diff --git a/src/operators/kernel/fpga/fusion_fc_kernel.cpp b/src/operators/kernel/fpga/fusion_fc_kernel.cpp index e269bcb5a3..5479deb6c1 100644 --- a/src/operators/kernel/fpga/fusion_fc_kernel.cpp +++ b/src/operators/kernel/fpga/fusion_fc_kernel.cpp @@ -32,7 +32,7 @@ bool FusionFcKernel::Init(FusionFcParam *param) { PADDLE_MOBILE_ENFORCE(input_x->dims()[1] == input_y->dims()[0], "Image channel should be equal to weight number"); - int channel = input_x->dims()[1]; + int channel = out->dims()[1]; float *bs_ptr = (float *)fpga::fpga_malloc(2 * channel * sizeof(float)); for (int i = 0; i < channel; i++) { bs_ptr[i * 2] = 1; diff --git a/test/net/test_resnet.cpp b/test/net/test_resnet.cpp index 73ac88ef77..82fdc22763 100644 --- a/test/net/test_resnet.cpp +++ b/test/net/test_resnet.cpp @@ -17,7 +17,13 @@ limitations under the License. */ #include "../test_include.h" int main() { +#ifdef PADDLE_MOBILE_FPGA + paddle_mobile::PaddleMobile paddle_mobile; +#endif + +#ifdef PADDLE_MOBILE_CPU paddle_mobile::PaddleMobile paddle_mobile; +#endif paddle_mobile.SetThreadNum(4); auto time1 = time(); if (paddle_mobile.Load(g_resnet, true)) { -- GitLab