未验证 提交 e92b3040 编写于 作者: C Chen Weihang 提交者: GitHub

[PTen] Auto generate include headers (#39123)

* auto gen include headers

* move to pten.cmake
上级 a14dc688
...@@ -5,6 +5,8 @@ paddle/fluid/API_PR.spec ...@@ -5,6 +5,8 @@ paddle/fluid/API_PR.spec
paddle/fluid/op_use_default_grad_maker_DEV.spec paddle/fluid/op_use_default_grad_maker_DEV.spec
paddle/fluid/op_use_default_grad_maker_PR.spec paddle/fluid/op_use_default_grad_maker_PR.spec
paddle/pten/api/*/api* paddle/pten/api/*/api*
paddle/pten/include/*
paddle/pten/extension.h
*.DS_Store *.DS_Store
*.vs *.vs
......
...@@ -12,6 +12,48 @@ ...@@ -12,6 +12,48 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
function(generate_unify_header DIR_NAME)
set(options "")
set(oneValueArgs HEADER_NAME SKIP_SUFFIX)
set(multiValueArgs "")
cmake_parse_arguments(generate_unify_header "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN})
# get header name and suffix
set(header_name "${DIR_NAME}")
list(LENGTH generate_unify_header_HEADER_NAME generate_unify_header_HEADER_NAME_len)
if(${generate_unify_header_HEADER_NAME_len} GREATER 0)
set(header_name "${generate_unify_header_HEADER_NAME}")
endif()
set(skip_suffix "")
list(LENGTH generate_unify_header_SKIP_SUFFIX generate_unify_header_SKIP_SUFFIX_len)
if(${generate_unify_header_SKIP_SUFFIX_len} GREATER 0)
set(skip_suffix "${generate_unify_header_SKIP_SUFFIX}")
endif()
# generate target header file
set(header_file ${CMAKE_CURRENT_SOURCE_DIR}/include/${header_name}.h)
file(WRITE ${header_file} "// Header file generated by paddle/pten/CMakeLists.txt for external users,\n// DO NOT edit or include it within paddle.\n\n#pragma once\n\n")
# get all top-level headers and write into header file
file(GLOB HEADERS "${CMAKE_CURRENT_SOURCE_DIR}\/${DIR_NAME}\/*.h")
foreach(header ${HEADERS})
if("${skip_suffix}" STREQUAL "")
string(REPLACE "${PADDLE_SOURCE_DIR}\/" "" header "${header}")
file(APPEND ${header_file} "#include \"${header}\"\n")
else()
string(FIND "${header}" "${skip_suffix}.h" skip_suffix_found)
if(${skip_suffix_found} EQUAL -1)
string(REPLACE "${PADDLE_SOURCE_DIR}\/" "" header "${header}")
file(APPEND ${header_file} "#include \"${header}\"\n")
endif()
endif()
endforeach()
# append header into extension.h
string(REPLACE "${PADDLE_SOURCE_DIR}\/" "" header_file "${header_file}")
file(APPEND ${pten_extension_header_file} "#include \"${header_file}\"\n")
endfunction()
# call kernel_declare need to make sure whether the target of input exists # call kernel_declare need to make sure whether the target of input exists
function(kernel_declare TARGET_LIST) function(kernel_declare TARGET_LIST)
foreach(kernel_path ${TARGET_LIST}) foreach(kernel_path ${TARGET_LIST})
......
# pten auto cmake utils
include(pten)
# paddle experimental common components # paddle experimental common components
add_subdirectory(common) add_subdirectory(common)
...@@ -25,3 +28,12 @@ message(STATUS "All standard pten kernels: ${pten_kernels}") ...@@ -25,3 +28,12 @@ message(STATUS "All standard pten kernels: ${pten_kernels}")
set(PTEN_DEPS ${PTEN_DEPS} ${pten_kernels}) set(PTEN_DEPS ${PTEN_DEPS} ${pten_kernels})
cc_library(pten DEPS ${PTEN_DEPS}) cc_library(pten DEPS ${PTEN_DEPS})
set(pten_extension_header_file ${CMAKE_CURRENT_SOURCE_DIR}/extension.h CACHE INTERNAL "pten/extension.h file")
file(WRITE ${pten_extension_header_file} "// Header file generated by paddle/pten/CMakeLists.txt for external users,\n// DO NOT edit or include it within paddle.\n\n#pragma once\n\n")
# generate inner headers include dir for users
generate_unify_header(backends)
generate_unify_header(core)
generate_unify_header(infermeta)
generate_unify_header(kernels SKIP_SUFFIX grad_kernel)
include(pten_kernel)
set(kernel_declare_file ${PADDLE_BINARY_DIR}/paddle/pten/kernels/declarations.h.tmp CACHE INTERNAL "declarations.h file") set(kernel_declare_file ${PADDLE_BINARY_DIR}/paddle/pten/kernels/declarations.h.tmp CACHE INTERNAL "declarations.h file")
set(kernel_declare_file_final ${PADDLE_BINARY_DIR}/paddle/pten/kernels/declarations.h) set(kernel_declare_file_final ${PADDLE_BINARY_DIR}/paddle/pten/kernels/declarations.h)
file(WRITE ${kernel_declare_file} "// Generated by the paddle/pten/kernels/CMakeLists.txt. DO NOT EDIT!\n\n#pragma once\n\n") file(WRITE ${kernel_declare_file} "// Generated by the paddle/pten/kernels/CMakeLists.txt. DO NOT EDIT!\n\n#pragma once\n\n")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册