Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HACKATHON 6th] Refactor phi module structure #64541

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "[HACKATHON 6th] refactor phi module structure again"
This reverts commit 0dd9dab.
silverling committed Jun 1, 2024
commit c1eebd5bc08c7cbf11ca5d1fbdb8dad0007630fb
4 changes: 3 additions & 1 deletion cmake/generic.cmake
Original file line number Diff line number Diff line change
@@ -604,8 +604,10 @@ function(paddle_test_build TARGET_NAME)
endif()
if(WITH_SHARED_PHI)
target_link_libraries(${TARGET_NAME} $<TARGET_LINKER_FILE:phi>)
target_link_libraries(${TARGET_NAME} $<TARGET_LINKER_FILE:phi_main>)
if(WITH_GPU OR WITH_ROCM)
target_link_libraries(${TARGET_NAME} $<TARGET_LINKER_FILE:phi_gpu>)
target_link_libraries(${TARGET_NAME}
$<TARGET_LINKER_FILE:phi_kernel_gpu>)
endif()
add_dependencies(${TARGET_NAME} phi)
endif()
3 changes: 2 additions & 1 deletion paddle/fluid/eager/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
set(eager_deps
phi
phi_main
common
hook_utils
utils
@@ -14,7 +15,7 @@ set(eager_deps
custom_operator_node)

if(WITH_GPU OR WITH_ROCM)
set(eager_deps ${eager_deps} phi_gpu)
set(eager_deps ${eager_deps} phi_kernel_gpu)
endif()

if(NOT (NOT WITH_PYTHON AND ON_INFER))
6 changes: 5 additions & 1 deletion paddle/fluid/eager/auto_code_generator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -58,9 +58,13 @@ if(WIN32)
OUTPUT ${eager_generator_path}/phi.dll
COMMAND ${CMAKE_COMMAND} -E copy ${PHI_LIB} ${eager_generator_path}
DEPENDS phi)
add_custom_command(
OUTPUT ${eager_generator_path}/phi_main.dll
COMMAND ${CMAKE_COMMAND} -E copy ${PHI_MAIN_LIB} ${eager_generator_path}
DEPENDS phi)
if(WITH_GPU OR WITH_ROCM)
add_custom_command(
OUTPUT ${eager_generator_path}/phi_gpu.dll
OUTPUT ${eager_generator_path}/phi_kernel_gpu.dll
COMMAND ${CMAKE_COMMAND} -E copy ${PHI_KERNEL_GPU_LIB}
${eager_generator_path}
DEPENDS phi)
6 changes: 3 additions & 3 deletions paddle/fluid/inference/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -96,10 +96,10 @@ list(REMOVE_ITEM fluid_modules cinn_op_dialect)
# shared library to prune library size.
# list(REMOVE_ITEM fluid_modules ${not_infer_modules})

set(SHARED_INFERENCE_DEPS phi common ${fluid_modules} analysis_predictor
${utils_modules})
set(SHARED_INFERENCE_DEPS phi phi_main common ${fluid_modules}
analysis_predictor ${utils_modules})
if(WITH_GPU OR WITH_ROCM)
list(APPEND SHARED_INFERENCE_DEPS phi_gpu)
list(APPEND SHARED_INFERENCE_DEPS phi_kernel_gpu)
endif()
if(NOT WIN32)
list(APPEND SHARED_INFERENCE_DEPS ${ir_targets})
4 changes: 3 additions & 1 deletion paddle/fluid/inference/api/demo_ci/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -211,11 +211,13 @@ if(NOT WIN32)
if(WITH_SHARED_PHI)
set(DEPS
${DEPS} ${PADDLE_LIB}/paddle/lib/libphi${CMAKE_SHARED_LIBRARY_SUFFIX}
${PADDLE_LIB}/paddle/lib/libphi_main${CMAKE_SHARED_LIBRARY_SUFFIX}
${PADDLE_LIB}/paddle/lib/libcommon${CMAKE_SHARED_LIBRARY_SUFFIX})
if(WITH_GPU OR WITH_ROCM)
set(DEPS
${DEPS}
${PADDLE_LIB}/paddle/lib/libphi_gpu${CMAKE_SHARED_LIBRARY_SUFFIX})
${PADDLE_LIB}/paddle/lib/libphi_kernel_gpu${CMAKE_SHARED_LIBRARY_SUFFIX}
)
endif()
endif()
else()
6 changes: 5 additions & 1 deletion paddle/fluid/pybind/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -370,9 +370,13 @@ if(WITH_PYTHON)
OUTPUT ${op_impl_path}/phi.dll
COMMAND ${CMAKE_COMMAND} -E copy ${PHI_LIB} ${op_impl_path}
DEPENDS phi)
add_custom_command(
OUTPUT ${op_impl_path}/phi_main.dll
COMMAND ${CMAKE_COMMAND} -E copy ${PHI_MAIN_LIB} ${op_impl_path}
DEPENDS phi)
if(WITH_GPU OR WITH_ROCM)
add_custom_command(
OUTPUT ${op_impl_path}/phi_gpu.dll
OUTPUT ${op_impl_path}/phi_kernel_gpu.dll
COMMAND ${CMAKE_COMMAND} -E copy ${PHI_KERNEL_GPU_LIB} ${op_impl_path}
DEPENDS phi)
endif()
68 changes: 44 additions & 24 deletions paddle/phi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -103,7 +103,8 @@ if(WITH_DGC)
list(APPEND PHI_DEPS dgc)
endif()

set(PHI_SRCS
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/phi_dummy.cpp "")
set(PHI_MAIN_SRCS
${common_srcs}
${api_srcs}
${core_srcs}
@@ -112,7 +113,7 @@ set(PHI_SRCS
${infermeta_srcs}
${capi_srcs})

set(PHI_GPU_SRCS ${kernels_gpu_srcs})
set(PHI_KERNEL_GPU_SRCS ${kernels_gpu_srcs})

if(WITH_SHARED_PHI)
set(PHI_BUILD_TYPE
@@ -142,47 +143,61 @@ if(WITH_GPU)
PROPERTIES COMPILE_FLAGS
"-DCUDA_REAL_ARCHS=\"${NVCC_FLAGS_EXTRA_real_archs}\"")
nv_library(
phi ${PHI_BUILD_TYPE}
SRCS ${PHI_SRCS}
phi_main ${PHI_BUILD_TYPE}
SRCS ${PHI_MAIN_SRCS}
DEPS ${PHI_DEPS})
nv_library(
phi_gpu ${PHI_BUILD_TYPE}
SRCS ${PHI_GPU_SRCS}
DEPS ${PHI_DEPS} phi)
phi_kernel_gpu ${PHI_BUILD_TYPE}
SRCS ${PHI_KERNEL_GPU_SRCS}
DEPS ${PHI_DEPS} phi_main)
nv_library(
phi ${PHI_BUILD_TYPE}
SRCS ${CMAKE_CURRENT_BINARY_DIR}/phi_dummy.cpp
DEPS phi_main phi_kernel_gpu)

elseif(WITH_ROCM)
hip_library(
phi ${PHI_BUILD_TYPE}
SRCS ${PHI_SRCS}
phi_main ${PHI_BUILD_TYPE}
SRCS ${PHI_MAIN_SRCS}
DEPS ${PHI_DEPS})
hip_library(
phi_gpu ${PHI_BUILD_TYPE}
SRCS ${PHI_GPU_SRCS}
DEPS ${PHI_DEPS} phi)
phi_kernel_gpu ${PHI_BUILD_TYPE}
SRCS ${PHI_KERNEL_GPU_SRCS}
DEPS ${PHI_DEPS} phi_main)
hip_library(
phi ${PHI_BUILD_TYPE}
SRCS ${CMAKE_CURRENT_BINARY_DIR}/phi_dummy.cpp
DEPS phi_main phi_kernel_gpu)

elseif(WITH_XPU_KP)
xpu_library(
phi ${PHI_BUILD_TYPE}
SRCS ${PHI_SRCS}
phi_main ${PHI_BUILD_TYPE}
SRCS ${PHI_MAIN_SRCS}
DEPS ${PHI_DEPS})

xpu_library(
phi ${PHI_BUILD_TYPE}
SRCS ${CMAKE_CURRENT_BINARY_DIR}/phi_dummy.cpp
DEPS phi_main)
else()
cc_library(
phi ${PHI_BUILD_TYPE}
SRCS ${PHI_SRCS}
phi_main ${PHI_BUILD_TYPE}
SRCS ${PHI_MAIN_SRCS}
DEPS ${PHI_DEPS})

cc_library(
phi ${PHI_BUILD_TYPE}
SRCS ${CMAKE_CURRENT_BINARY_DIR}/phi_dummy.cpp
DEPS phi_main)
endif()

target_compile_definitions(phi PUBLIC PHI_INNER)
target_compile_definitions(phi_main PUBLIC PHI_INNER)

if(WIN32)
target_link_libraries(phi shlwapi.lib)
target_link_libraries(phi_main shlwapi.lib)
endif()

if(WIN32)
if(WITH_SHARED_PHI)
set_property(TARGET phi PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS ON)
set_property(TARGET phi_main PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS ON)
set(PHI_NAME
phi.dll
CACHE INTERNAL "" FORCE)
@@ -217,15 +232,20 @@ set(PHI_LIB
"${CMAKE_CURRENT_BINARY_DIR}/${PHI_NAME}"
CACHE FILEPATH "PHI Dummy Library" FORCE)

string(REPLACE "phi" "phi_main" PHI_MAIN_NAME ${PHI_NAME})
set(PHI_MAIN_LIB
"${CMAKE_CURRENT_BINARY_DIR}/${PHI_MAIN_NAME}"
CACHE FILEPATH "PHI Main Library" FORCE)

if(WITH_GPU OR WITH_ROCM)
string(REPLACE "phi" "phi_gpu" PHI_GPU_NAME ${PHI_NAME})
string(REPLACE "phi" "phi_kernel_gpu" PHI_KERNEL_GPU_NAME ${PHI_NAME})
set(PHI_KERNEL_GPU_LIB
"${CMAKE_CURRENT_BINARY_DIR}/${PHI_GPU_NAME}"
"${CMAKE_CURRENT_BINARY_DIR}/${PHI_KERNEL_GPU_NAME}"
CACHE FILEPATH "PHI Kernel GPU Library" FORCE)
endif()

if(MKL_FOUND AND WITH_ONEMKL)
target_include_directories(phi PRIVATE ${MKL_INCLUDE})
target_include_directories(phi_main PRIVATE ${MKL_INCLUDE})
endif()

add_dependencies(phi extern_lapack)
4 changes: 3 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -227,8 +227,10 @@ if(${len} GREATER_EQUAL 1)
target_link_libraries(${test_name} $<TARGET_LINKER_FILE:${paddle_lib}>)
if(WITH_SHARED_PHI)
target_link_libraries(${test_name} $<TARGET_LINKER_FILE:phi>)
target_link_libraries(${test_name} $<TARGET_LINKER_FILE:phi_main>)
if(WITH_GPU OR WITH_ROCM)
target_link_libraries(${test_name} $<TARGET_LINKER_FILE:phi_gpu>)
target_link_libraries(${test_name}
$<TARGET_LINKER_FILE:phi_kernel_gpu>)
endif()
endif()
if(WITH_SHARED_IR)