From f211745420ca8ee9170c2e4411a0c18cff2b0c92 Mon Sep 17 00:00:00 2001 From: qnqinan Date: Thu, 16 Aug 2018 13:17:39 +0800 Subject: [PATCH] add quantilization function to fc --- src/operators/kernel/fpga/fc_relu_kernel.cpp | 7 +++++-- src/operators/kernel/fpga/fusion_fc_kernel.cpp | 11 +++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/operators/kernel/fpga/fc_relu_kernel.cpp b/src/operators/kernel/fpga/fc_relu_kernel.cpp index 21e334b12b..d3683d321c 100644 --- a/src/operators/kernel/fpga/fc_relu_kernel.cpp +++ b/src/operators/kernel/fpga/fc_relu_kernel.cpp @@ -14,6 +14,7 @@ limitations under the License. */ #ifdef FUSION_FCRELU_OP #include "operators/kernel/fc_relu_kernel.h" #include "fpga/api/fpga_api.h" +#include "fpga/fpga_quantilization.h" namespace paddle_mobile { namespace operators { @@ -23,8 +24,7 @@ bool FusionFcReluKernel::Init(FusionFcReluParam *param) { bool relu_enabled = true; const Tensor *input_x = param->InputX(); auto input_x_ptr = input_x->data(); - const Tensor *input_y = param->InputY(); - auto input_y_ptr = input_y->data(); + Tensor *input_y = param->InputY(); const Tensor *input_z = param->InputZ(); auto input_z_ptr = input_z->data(); Tensor *out = param->Out(); @@ -39,6 +39,9 @@ bool FusionFcReluKernel::Init(FusionFcReluParam *param) { bs_ptr[i * 2 + 1] = input_z_ptr[i]; } + fpga::quantify_filter(input_y); + auto input_y_ptr = input_y->data(); + fpga::ConvArgs convArgs; convArgs.relu_enabled = relu_enabled; convArgs.filter_address = (void *)input_y_ptr; diff --git a/src/operators/kernel/fpga/fusion_fc_kernel.cpp b/src/operators/kernel/fpga/fusion_fc_kernel.cpp index 505b876856..1e5825599a 100644 --- a/src/operators/kernel/fpga/fusion_fc_kernel.cpp +++ b/src/operators/kernel/fpga/fusion_fc_kernel.cpp @@ -14,6 +14,7 @@ limitations under the License. */ #ifdef FUSION_FC_OP #include "operators/kernel/fusion_fc_kernel.h" +#include "fpga/fpga_quantilization.h" namespace paddle_mobile { namespace operators { @@ -23,8 +24,7 @@ bool FusionFcKernel::Init(FusionFcParam *param) { bool relu_enabled = false; const Tensor *input_x = param->InputX(); auto input_x_ptr = input_x->data(); - const Tensor *input_y = param->InputY(); - auto input_y_ptr = input_y->data(); + Tensor *input_y = param->InputY(); const Tensor *input_z = param->InputZ(); auto input_z_ptr = input_z->data(); Tensor *out = param->Out(); @@ -39,6 +39,9 @@ bool FusionFcKernel::Init(FusionFcParam *param) { bs_ptr[i * 2 + 1] = input_z_ptr[i]; } + fpga::quantify_filter(input_y); + auto input_y_ptr = input_y->data(); + fpga::ConvArgs convArgs; convArgs.relu_enabled = relu_enabled; convArgs.filter_address = (void *)input_y_ptr; @@ -56,10 +59,10 @@ bool FusionFcKernel::Init(FusionFcParam *param) { convArgs.image.pad_height = 0; convArgs.image.pad_width = 0; convArgs.image.scale_address = - input_x->fpga_args().scale_pointer(); // fc input has scale attribute?? + input_x->fpga_args().scale_pointer(); convArgs.output.address = (void *)out_ptr; convArgs.output.scale_address = - out->fpga_args().scale_pointer(); // fc output has scale attribute?? + out->fpga_args().scale_pointer(); param->SetFpgaArgs(convArgs); return true; } -- GitLab