From af27bfffc0842dd40b91e2674e286c58384d4f46 Mon Sep 17 00:00:00 2001 From: yongqiang Date: Wed, 9 Sep 2020 13:30:28 +0000 Subject: [PATCH] add calib kernel to support int64 to float32. test=develop --- lite/kernels/arm/calib_compute.cc | 79 +++++++++++++++++++++++++++++++ lite/kernels/arm/calib_compute.h | 13 +++++ 2 files changed, 92 insertions(+) diff --git a/lite/kernels/arm/calib_compute.cc b/lite/kernels/arm/calib_compute.cc index 383e868843..c0b7405015 100644 --- a/lite/kernels/arm/calib_compute.cc +++ b/lite/kernels/arm/calib_compute.cc @@ -44,6 +44,17 @@ void CalibComputeInt64ToInt32::Run() { } } +template +void CalibComputeInt64ToFloat32::Run() { + auto& param = this->template Param(); + const auto* din = param.input->template data(); + std::vector scale = {param.scale}; + auto* dout = param.output->template mutable_data(); + for (auto i = 0; i < param.input->numel(); ++i) { + dout[i] = din[i]; + } +} + template void CalibComputeInt8ToFp32::Run() { auto& param = this->template Param(); @@ -133,6 +144,40 @@ REGISTER_LITE_KERNEL( DATALAYOUT(kNCHW))}) .Finalize(); +REGISTER_LITE_KERNEL( + calib, + kARM, + kFloat, + kNCHW, + paddle::lite::kernels::arm::CalibComputeInt64ToFloat32, + int64_to_float32) + .BindInput("Input", + {LiteType::GetTensorTy(TARGET(kAny), + PRECISION(kInt64), + DATALAYOUT(kNCHW))}) + .BindOutput("Out", + {LiteType::GetTensorTy(TARGET(kARM), + PRECISION(kFloat), + DATALAYOUT(kNCHW))}) + .Finalize(); + +REGISTER_LITE_KERNEL( + calib, + kARM, + kInt64, + kNCHW, + paddle::lite::kernels::arm::CalibComputeInt64ToFloat32, + int64_to_float32) + .BindInput("Input", + {LiteType::GetTensorTy(TARGET(kHost), + PRECISION(kInt64), + DATALAYOUT(kNCHW))}) + .BindOutput("Out", + {LiteType::GetTensorTy(TARGET(kARM), + PRECISION(kFloat), + DATALAYOUT(kNCHW))}) + .Finalize(); + REGISTER_LITE_KERNEL( calib_once, kARM, @@ -206,3 +251,37 @@ REGISTER_LITE_KERNEL( PRECISION(kInt32), DATALAYOUT(kNCHW))}) .Finalize(); + +REGISTER_LITE_KERNEL( + calib_once, + kARM, + kFloat, + kNCHW, + paddle::lite::kernels::arm::CalibComputeInt64ToFloat32, + int64_to_float32) + .BindInput("Input", + {LiteType::GetTensorTy(TARGET(kARM), + PRECISION(kInt64), + DATALAYOUT(kNCHW))}) + .BindOutput("Out", + {LiteType::GetTensorTy(TARGET(kARM), + PRECISION(kFloat), + DATALAYOUT(kNCHW))}) + .Finalize(); + +REGISTER_LITE_KERNEL( + calib_once, + kARM, + kInt64, + kNCHW, + paddle::lite::kernels::arm::CalibComputeInt64ToFloat32, + int64_to_float32) + .BindInput("Input", + {LiteType::GetTensorTy(TARGET(kHost), + PRECISION(kInt64), + DATALAYOUT(kNCHW))}) + .BindOutput("Out", + {LiteType::GetTensorTy(TARGET(kARM), + PRECISION(kFloat), + DATALAYOUT(kNCHW))}) + .Finalize(); diff --git a/lite/kernels/arm/calib_compute.h b/lite/kernels/arm/calib_compute.h index f10bb931df..365c1815bf 100644 --- a/lite/kernels/arm/calib_compute.h +++ b/lite/kernels/arm/calib_compute.h @@ -47,6 +47,19 @@ class CalibComputeInt64ToInt32 private: }; +template +class CalibComputeInt64ToFloat32 + : public KernelLite { + public: + using param_t = operators::CalibParam; + + void Run() override; + + ~CalibComputeInt64ToFloat32() override{}; + + private: +}; + template class CalibComputeInt8ToFp32 : public KernelLite { -- GitLab