diff --git a/cmake/inference_lib.cmake b/cmake/inference_lib.cmake index e5a7f0d2bef5403e49330afd539ee0702cb528c5..1334bf2f96494f82f0fe475d59adf1521525fcb3 100644 --- a/cmake/inference_lib.cmake +++ b/cmake/inference_lib.cmake @@ -216,10 +216,7 @@ copy(inference_lib_dist DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/crypto/) include_directories(${CMAKE_BINARY_DIR}/../paddle/fluid/framework/io) -# TODO(chenweihang, before 11.27) Here, the header file of pten is copied to -# the experimental directory, the include path needs to be changed, so the -# header file path needs to be processed here -# copy api headers for custom op +# copy api headers for pten & custom op copy(inference_lib_dist SRCS ${PADDLE_SOURCE_DIR}/paddle/pten/api/ext/* DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/experimental/pten/api/ext/) @@ -231,21 +228,25 @@ copy(inference_lib_dist DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/experimental/pten/api/) copy(inference_lib_dist SRCS ${PADDLE_SOURCE_DIR}/paddle/pten/common/* - DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/experimental/pten/common/) -copy(inference_lib_dist - SRCS ${PADDLE_SOURCE_DIR}/paddle/fluid/platform/complex.h - DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/experimental/pten/common/) -copy(inference_lib_dist - SRCS ${PADDLE_SOURCE_DIR}/paddle/fluid/platform/float16.h - DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/experimental/pten/common/) + ${PADDLE_SOURCE_DIR}/paddle/fluid/platform/bfloat16.h + ${PADDLE_SOURCE_DIR}/paddle/fluid/platform/complex.h + ${PADDLE_SOURCE_DIR}/paddle/fluid/platform/float16.h + DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/experimental/pten/common/ + ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/experimental/pten/common/ + ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/experimental/pten/common/ + ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/experimental/pten/common/) copy(inference_lib_dist SRCS ${PADDLE_SOURCE_DIR}/paddle/utils/any.h DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/experimental/utils/) -# In order to be compatible with the original behavior, the header file name needs to be changed copy(inference_lib_dist SRCS ${PADDLE_SOURCE_DIR}/paddle/extension.h - DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/experimental/ext_all.h) + DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/experimental/) +# the header file of pten is copied to the experimental directory, +# the include path of pten needs to be changed to adapt to inference api path +add_custom_command(TARGET inference_lib_dist POST_BUILD + COMMAND ${CMAKE_COMMAND} -P "${PADDLE_SOURCE_DIR}/cmake/pten.cmake" + COMMENT "Change pten header include path to adapt to inference api path") # CAPI inference library for only inference set(PADDLE_INFERENCE_C_INSTALL_DIR "${CMAKE_BINARY_DIR}/paddle_inference_c_install_dir" CACHE STRING diff --git a/cmake/pten.cmake b/cmake/pten.cmake new file mode 100644 index 0000000000000000000000000000000000000000..77d04a2570cab45cca0fe0ff557b1a5c93d2d541 --- /dev/null +++ b/cmake/pten.cmake @@ -0,0 +1,43 @@ +# Copyright (c) 2021 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. + +set(PADDLE_INFERENCE_INSTALL_DIR "${CMAKE_BINARY_DIR}/paddle_inference_install_dir") + +function(pten_header_path_compat TARGET_PATH) +message(STATUS "pten header path compat processing: ${TARGET_PATH}") +string(FIND ${TARGET_PATH} "experimental" pos) +if (pos GREATER 1) + file(GLOB HEADERS "${TARGET_PATH}/*" "*.h") + foreach(header ${HEADERS}) + string(FIND ${header} ".h" hpos) + if (hpos GREATER 1) + file(READ ${header} HEADER_CONTENT) + string(REPLACE "paddle/pten/" "paddle/include/experimental/pten/" HEADER_CONTENT "${HEADER_CONTENT}") + string(REPLACE "paddle/utils/" "paddle/include/experimental/utils/" HEADER_CONTENT "${HEADER_CONTENT}") + file(WRITE ${header} "${HEADER_CONTENT}") + message(STATUS "pten header path compat processing complete: ${header}") + endif() + endforeach() +endif() +endfunction() + +pten_header_path_compat(${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/experimental) +pten_header_path_compat(${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/experimental/pten/api) +pten_header_path_compat(${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/experimental/pten/api/ext) +pten_header_path_compat(${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/experimental/pten/api/include) +pten_header_path_compat(${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/experimental/pten/common) + +# In order to be compatible with the original behavior, the header file name needs to be changed +file(RENAME ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/experimental/extension.h + ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/experimental/ext_all.h) \ No newline at end of file diff --git a/paddle/fluid/eager/tests/data_structure_tests/eager_tensor_test.cc b/paddle/fluid/eager/tests/data_structure_tests/eager_tensor_test.cc index a528867d4420361e2d70f00d81816d83a41a6e35..61ad2e1c5fe4e5ea77f048899283fcc8bc17131f 100644 --- a/paddle/fluid/eager/tests/data_structure_tests/eager_tensor_test.cc +++ b/paddle/fluid/eager/tests/data_structure_tests/eager_tensor_test.cc @@ -16,6 +16,7 @@ #include "gtest/gtest.h" #include "paddle/fluid/eager/eager_tensor.h" +#include "paddle/pten/api/lib/api_declare.h" #include "paddle/pten/api/lib/utils/allocator.h" // TODO(jiabin): remove nolint here!!! diff --git a/paddle/fluid/framework/custom_operator.cc b/paddle/fluid/framework/custom_operator.cc index 88cfd74cdaf99228238457f9d2f16f57677c468a..5f731ea9ac8f8884216701d169e2433ba8ea0949 100644 --- a/paddle/fluid/framework/custom_operator.cc +++ b/paddle/fluid/framework/custom_operator.cc @@ -34,6 +34,7 @@ limitations under the License. */ #include "paddle/fluid/platform/dynload/dynamic_loader.h" #include "paddle/fluid/string/string_helper.h" #include "paddle/pten/api/all.h" +#include "paddle/pten/api/lib/api_declare.h" #include "paddle/pten/api/lib/ext_compat_utils.h" #include "paddle/pten/api/lib/utils/tensor_utils.h" #include "paddle/pten/core/convert_utils.h" diff --git a/paddle/pten/api/all.h b/paddle/pten/api/all.h index a55d3332bcd1e14545b12b065e348ec559b05b60..22cbe5fa1fd23be2c3d5e9068ebb6df457b6c46f 100644 --- a/paddle/pten/api/all.h +++ b/paddle/pten/api/all.h @@ -44,12 +44,3 @@ limitations under the License. */ #include "paddle/pten/api/ext/exception.h" #include "paddle/pten/api/ext/op_meta_info.h" #include "paddle/pten/api/ext/place.h" - -// api symbols declare, remove in the future -#include "paddle/pten/api/include/registry.h" - -PT_DECLARE_API(Creation); -PT_DECLARE_API(Linalg); -PT_DECLARE_API(Manipulation); -PT_DECLARE_API(Math); -PT_DECLARE_API(Utils); diff --git a/paddle/pten/api/lib/api_declare.h b/paddle/pten/api/lib/api_declare.h new file mode 100644 index 0000000000000000000000000000000000000000..d29050c8ba4a825e161c92f9aa6dac7a86988154 --- /dev/null +++ b/paddle/pten/api/lib/api_declare.h @@ -0,0 +1,24 @@ +/* Copyright (c) 2021 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 + +// api symbols declare, remove in the future +#include "paddle/pten/api/lib/api_registry.h" + +PT_DECLARE_API(Creation); +PT_DECLARE_API(Linalg); +PT_DECLARE_API(Manipulation); +PT_DECLARE_API(Math); +PT_DECLARE_API(Utils); diff --git a/paddle/pten/api/include/registry.h b/paddle/pten/api/lib/api_registry.h similarity index 100% rename from paddle/pten/api/include/registry.h rename to paddle/pten/api/lib/api_registry.h diff --git a/paddle/pten/api/lib/creation.cc b/paddle/pten/api/lib/creation.cc index 5745267156cf291e233bf16f6414476d3c29f5f9..523c2f6bd10e9537d4c91cbee40286e79b0a6f90 100644 --- a/paddle/pten/api/lib/creation.cc +++ b/paddle/pten/api/lib/creation.cc @@ -18,7 +18,7 @@ limitations under the License. */ #include "glog/logging.h" -#include "paddle/pten/api/include/registry.h" +#include "paddle/pten/api/lib/api_registry.h" #include "paddle/pten/api/lib/kernel_dispatch.h" #include "paddle/pten/api/lib/utils/allocator.h" #include "paddle/pten/core/kernel_registry.h" diff --git a/paddle/pten/api/lib/linalg.cc b/paddle/pten/api/lib/linalg.cc index 2ea142be716e652f119b9574f66168580b94fa1a..3b7d4994ab75ab4655835b69349ec737958877fa 100644 --- a/paddle/pten/api/lib/linalg.cc +++ b/paddle/pten/api/lib/linalg.cc @@ -18,7 +18,7 @@ limitations under the License. */ #include "glog/logging.h" -#include "paddle/pten/api/include/registry.h" +#include "paddle/pten/api/lib/api_registry.h" #include "paddle/pten/api/lib/kernel_dispatch.h" #include "paddle/pten/api/lib/utils/allocator.h" #include "paddle/pten/core/convert_utils.h" diff --git a/paddle/pten/api/lib/manipulation.cc b/paddle/pten/api/lib/manipulation.cc index f3cc647e702ae040ab09fb3f9d92cf7bf5259a64..d06602d721d712a91443d7c6926ed09f4ef9b256 100644 --- a/paddle/pten/api/lib/manipulation.cc +++ b/paddle/pten/api/lib/manipulation.cc @@ -17,7 +17,7 @@ limitations under the License. */ #include #include "glog/logging.h" -#include "paddle/pten/api/include/registry.h" +#include "paddle/pten/api/lib/api_registry.h" #include "paddle/pten/api/lib/kernel_dispatch.h" #include "paddle/pten/api/lib/utils/allocator.h" #include "paddle/pten/core/kernel_registry.h" diff --git a/paddle/pten/api/lib/math.cc b/paddle/pten/api/lib/math.cc index e5c955b623cb1a0d00ef400515fab95e9d6f27e9..b7fcdd027cf2847440069409d6ca4d40358616c3 100644 --- a/paddle/pten/api/lib/math.cc +++ b/paddle/pten/api/lib/math.cc @@ -18,7 +18,7 @@ limitations under the License. */ #include "glog/logging.h" -#include "paddle/pten/api/include/registry.h" +#include "paddle/pten/api/lib/api_registry.h" #include "paddle/pten/api/lib/kernel_dispatch.h" #include "paddle/pten/api/lib/utils/allocator.h" #include "paddle/pten/core/kernel_registry.h" diff --git a/paddle/pten/api/lib/utils.cc b/paddle/pten/api/lib/utils.cc index a09e1b2c9e19cf91a74f358287ac0371a98a1bca..603699b26c15cff3ed19ed1a733dfa67c333602e 100644 --- a/paddle/pten/api/lib/utils.cc +++ b/paddle/pten/api/lib/utils.cc @@ -18,12 +18,19 @@ limitations under the License. */ #include "glog/logging.h" -#include "paddle/pten/api/include/registry.h" +#include "paddle/pten/api/lib/api_registry.h" #include "paddle/pten/api/lib/kernel_dispatch.h" #include "paddle/pten/api/lib/utils/allocator.h" +#include "paddle/pten/core/kernel_registry.h" #include "paddle/pten/include/core.h" #include "paddle/pten/include/infershape.h" +PT_DECLARE_MODULE(UtilsCPU); + +#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) +PT_DECLARE_MODULE(UtilsCUDA); +#endif + namespace paddle { namespace experimental { diff --git a/paddle/pten/tests/api/test_to_api.cc b/paddle/pten/tests/api/test_to_api.cc index 278735033e33d7e32b10ff9686e069517b904880..5374903cbb7ff91eb8e4503babe64f7b575e2782 100644 --- a/paddle/pten/tests/api/test_to_api.cc +++ b/paddle/pten/tests/api/test_to_api.cc @@ -21,12 +21,6 @@ limitations under the License. */ #include "paddle/pten/core/dense_tensor.h" #include "paddle/pten/core/kernel_registry.h" -PT_DECLARE_MODULE(UtilsCPU); - -#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) -PT_DECLARE_MODULE(UtilsCUDA); -#endif - namespace pten { namespace tests {