From 9d127391895e6ac11abf6cd2f3ccc2bac27ebef5 Mon Sep 17 00:00:00 2001 From: nhzlx Date: Thu, 20 Jun 2019 08:24:26 +0000 Subject: [PATCH] add gemv gemm int8 neon impl (no test) add empty conv kernel --- paddle/fluid/lite/arm/math/CMakeLists.txt | 2 ++ paddle/fluid/lite/core/target_wrapper.h | 12 ++++++++++ paddle/fluid/lite/kernels/arm/conv_compute.cc | 23 +++++++++++++++++++ paddle/fluid/lite/kernels/arm/conv_compute.h | 19 +++++++++++++++ 4 files changed, 56 insertions(+) diff --git a/paddle/fluid/lite/arm/math/CMakeLists.txt b/paddle/fluid/lite/arm/math/CMakeLists.txt index 883e7bc4609..0f832029c86 100644 --- a/paddle/fluid/lite/arm/math/CMakeLists.txt +++ b/paddle/fluid/lite/arm/math/CMakeLists.txt @@ -35,6 +35,8 @@ cc_library(math_arm SRCS split.cc activation.cc dropout.cc + gemm_prepacked_int8.cc + gemv_arm_int8.cc DEPS ${lite_kernel_deps} eigen3 framework_proto_lite) # TODO(TJ): fix me do not deps proto diff --git a/paddle/fluid/lite/core/target_wrapper.h b/paddle/fluid/lite/core/target_wrapper.h index c4a870ab83f..858ce65853e 100644 --- a/paddle/fluid/lite/core/target_wrapper.h +++ b/paddle/fluid/lite/core/target_wrapper.h @@ -38,6 +38,7 @@ enum class PrecisionType : int { kUnk = 0, kFloat, kInt8, + kInt32, kAny, // any precision NUM, // number of fields. }; @@ -48,6 +49,17 @@ enum class DataLayoutType : int { NUM, // number of fields. }; +static size_t PrecisionTypeLength(PrecisionType type) { + switch (type) { + case PrecisionType::kFloat: + return 4; + case PrecisionType::kInt8: + return 1; + default: + return 4; + } +} + // Some helper macro to get a specific TargetType. #define TARGET(item__) paddle::lite::TargetType::item__ // Some helper macro to get a specific PrecisionType. diff --git a/paddle/fluid/lite/kernels/arm/conv_compute.cc b/paddle/fluid/lite/kernels/arm/conv_compute.cc index a7cd385be98..4ac6cd4b761 100644 --- a/paddle/fluid/lite/kernels/arm/conv_compute.cc +++ b/paddle/fluid/lite/kernels/arm/conv_compute.cc @@ -94,6 +94,9 @@ void ConvCompute::Run() { // } } +void ConvComputeInt8::PrepareForRun() {} +void ConvComputeInt8::Run() {} + } // namespace arm } // namespace kernels } // namespace lite @@ -114,3 +117,23 @@ REGISTER_LITE_KERNEL(depthwise_conv2d, kARM, kFloat, kNCHW, .BindInput("Filter", {LiteType::GetTensorTy(TARGET(kARM))}) .BindOutput("Output", {LiteType::GetTensorTy(TARGET(kARM))}) .Finalize(); + +REGISTER_LITE_KERNEL(conv2d, kARM, kInt8, kNCHW, + paddle::lite::kernels::arm::ConvComputeInt8, def) + .BindInput("Input", {LiteType::GetTensorTy(TARGET(kARM), PRECISION(kInt8))}) + .BindInput("Bias", {LiteType::GetTensorTy(TARGET(kARM), PRECISION(kInt32))}) + .BindInput("Filter", + {LiteType::GetTensorTy(TARGET(kARM), PRECISION(kInt8))}) + .BindOutput("Output", + {LiteType::GetTensorTy(TARGET(kARM), PRECISION(kInt8))}) + .Finalize(); + +REGISTER_LITE_KERNEL(depthwise_conv2d, kARM, kInt8, kNCHW, + paddle::lite::kernels::arm::ConvComputeInt8, def) + .BindInput("Input", {LiteType::GetTensorTy(TARGET(kARM), PRECISION(kInt8))}) + .BindInput("Bias", {LiteType::GetTensorTy(TARGET(kARM), PRECISION(kInt32))}) + .BindInput("Filter", + {LiteType::GetTensorTy(TARGET(kARM), PRECISION(kInt8))}) + .BindOutput("Output", + {LiteType::GetTensorTy(TARGET(kARM), PRECISION(kInt8))}) + .Finalize(); diff --git a/paddle/fluid/lite/kernels/arm/conv_compute.h b/paddle/fluid/lite/kernels/arm/conv_compute.h index 21fabf8c3e8..e5d5721a3b3 100644 --- a/paddle/fluid/lite/kernels/arm/conv_compute.h +++ b/paddle/fluid/lite/kernels/arm/conv_compute.h @@ -41,6 +41,25 @@ class ConvCompute : public KernelLite { nullptr}; }; +class ConvComputeInt8 : public KernelLite { + public: + using param_t = operators::ConvParam; + + void PrepareForRun() override; + + void Run() override; + + ~ConvComputeInt8() { + if (impl_ != nullptr) { + delete impl_; + } + } + + private: + lite::arm::math::ImplBase* impl_{ + nullptr}; +}; + } // namespace arm } // namespace kernels } // namespace lite -- GitLab