From 854a7ab3589704499a8332b9967011c4457fd507 Mon Sep 17 00:00:00 2001 From: Shang Zhizhou Date: Fri, 21 Jan 2022 18:46:24 +0800 Subject: [PATCH] add pten dependency to infrt (#39079) * add pten dependency to infrt * fix code style * add pten::CPUContext * revert .ignore --- paddle/infrt/CMakeLists.txt | 7 ++++-- paddle/infrt/host_context/value.h | 5 ++++ paddle/infrt/kernel/CMakeLists.txt | 1 + paddle/infrt/kernel/pten_kernels.cc | 37 +++++++++++++++++++++++++++++ paddle/infrt/kernel/pten_kernels.h | 35 +++++++++++++++++++++++++++ paddle/scripts/infrt_build.sh | 0 6 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 paddle/infrt/kernel/pten_kernels.cc create mode 100644 paddle/infrt/kernel/pten_kernels.h mode change 100644 => 100755 paddle/scripts/infrt_build.sh diff --git a/paddle/infrt/CMakeLists.txt b/paddle/infrt/CMakeLists.txt index 8af3012a220..e371e239182 100644 --- a/paddle/infrt/CMakeLists.txt +++ b/paddle/infrt/CMakeLists.txt @@ -1,3 +1,6 @@ +#TO DO:remove fluid +include_directories(${PADDLE_SOURCE_DIR}/paddle/fluid/platform) + if (NOT WITH_INFRT) return() endif() @@ -88,8 +91,8 @@ set(infrt_mlir_incs ) message(STATUS "infrt srcs:\n${infrt_src}") -cc_library(infrt SHARED SRCS ${infrt_src} DEPS glog boost ${mlir_libs} paddle_framework_proto) -cc_library(infrt_static SRCS ${infrt_src} DEPS glog boost ${mlir_libs} paddle_framework_proto) +cc_library(infrt SHARED SRCS ${infrt_src} DEPS glog boost ${mlir_libs} paddle_framework_proto pten dense_tensor) +cc_library(infrt_static SRCS ${infrt_src} DEPS glog boost ${mlir_libs} paddle_framework_proto pten dense_tensor) add_dependencies(infrt ${infrt_mlir_incs}) add_custom_target(test_infrt_exec DEPENDS ${INFRT_TEST_TARGETS}) diff --git a/paddle/infrt/host_context/value.h b/paddle/infrt/host_context/value.h index 4a2b92a7e69..7f68e59f8a6 100644 --- a/paddle/infrt/host_context/value.h +++ b/paddle/infrt/host_context/value.h @@ -29,6 +29,9 @@ #include "paddle/infrt/tensor/tensor_map.h" #include "paddle/infrt/tensor/tensor_shape.h" +#include "paddle/pten/backends/cpu/cpu_context.h" +#include "paddle/pten/core/dense_tensor.h" + namespace infrt { namespace host_context { @@ -45,6 +48,8 @@ using ValueVariantType = Variant, std::vector, std::vector, diff --git a/paddle/infrt/kernel/CMakeLists.txt b/paddle/infrt/kernel/CMakeLists.txt index da858aad28f..7e9ed8e5572 100644 --- a/paddle/infrt/kernel/CMakeLists.txt +++ b/paddle/infrt/kernel/CMakeLists.txt @@ -2,6 +2,7 @@ core_gather_headers() gather_srcs(infrt_src SRCS basic_kernels.cc + pten_kernels.cc test_kernels.cc tensor_shape_kernels.cc tensor_kernels.cc diff --git a/paddle/infrt/kernel/pten_kernels.cc b/paddle/infrt/kernel/pten_kernels.cc new file mode 100644 index 00000000000..70c44b829f7 --- /dev/null +++ b/paddle/infrt/kernel/pten_kernels.cc @@ -0,0 +1,37 @@ +// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include + +#include "paddle/infrt/host_context/kernel_registry.h" +#include "paddle/infrt/host_context/kernel_utils.h" +#include "paddle/infrt/kernel/pten_kernels.h" +#include "paddle/pten/backends/cpu/cpu_context.h" +#include "paddle/pten/kernels/math_kernel.h" + +using infrt::host_context::Attribute; + +namespace infrt { +namespace kernel { + +void RegisterPtenKernels(host_context::KernelRegistry* registry) { + registry->AddKernel("pd_cpu.add.float32", + INFRT_KERNEL(pten::AddKernel)); + registry->AddKernel("pd_cpu.add.int32", + INFRT_KERNEL(pten::AddKernel)); +} + +} // namespace kernel +} // namespace infrt diff --git a/paddle/infrt/kernel/pten_kernels.h b/paddle/infrt/kernel/pten_kernels.h new file mode 100644 index 00000000000..c290f8ea524 --- /dev/null +++ b/paddle/infrt/kernel/pten_kernels.h @@ -0,0 +1,35 @@ +// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once +#include + +namespace infrt { +namespace host_context { + +struct KernelRegistry; + +} // namespace host_context +} // namespace infrt + +namespace infrt { +namespace kernel { + +/** + * Register all the pten kernels to registry. + */ +void RegisterPtenKernels(host_context::KernelRegistry* registry); + +} // namespace kernel +} // namespace infrt diff --git a/paddle/scripts/infrt_build.sh b/paddle/scripts/infrt_build.sh old mode 100644 new mode 100755 -- GitLab