未验证 提交 1047cb17 编写于 作者: L Leo Chen 提交者: GitHub

compile phi/backends into one static library (#44373)

* compile into one static library

* fix xpu compile

* fix xpu compile

* fix inference compile

* fix inference compile

* add custom test

* revert one file
上级 4e1f7692
...@@ -52,7 +52,7 @@ if(WITH_GPU) ...@@ -52,7 +52,7 @@ if(WITH_GPU)
cc_library( cc_library(
layout_autotune layout_autotune
SRCS layout_autotune.cc SRCS layout_autotune.cc
DEPS op_info phi_gpu_info) DEPS op_info phi_backends)
else() else()
cc_library( cc_library(
layout_autotune layout_autotune
......
include(ExternalProject) include(ExternalProject)
set(ALLOCATOR_DEPS place stats profiler) set(ALLOCATOR_DEPS place stats profiler phi_backends)
set(ALLOCATOR_SRCS set(ALLOCATOR_SRCS
allocator.cc allocator.cc
cpu_allocator.cc cpu_allocator.cc
...@@ -54,7 +54,6 @@ endif() ...@@ -54,7 +54,6 @@ endif()
if(WITH_CUSTOM_DEVICE) if(WITH_CUSTOM_DEVICE)
list(APPEND ALLOCATOR_SRCS custom_allocator.cc) list(APPEND ALLOCATOR_SRCS custom_allocator.cc)
list(APPEND ALLOCATOR_DEPS device_manager)
endif() endif()
if(WITH_XPU) if(WITH_XPU)
......
...@@ -220,16 +220,9 @@ cc_library( ...@@ -220,16 +220,9 @@ cc_library(
${XPU_CTX_DEPS} ${XPU_CTX_DEPS}
${MLU_CTX_DEPS} ${MLU_CTX_DEPS}
eigen3 eigen3
phi_backends
phi_device_context
generator) generator)
if(WITH_XPU)
target_link_libraries(device_context xpu_context xpu_resource_pool)
endif()
if(WITH_MKLDNN)
target_link_libraries(device_context onednn_context)
endif()
target_link_libraries(device_context cpu_context)
cc_library( cc_library(
collective_helper collective_helper
...@@ -244,22 +237,19 @@ if(WITH_CNCL) ...@@ -244,22 +237,19 @@ if(WITH_CNCL)
endif() endif()
if(WITH_GPU OR WITH_ROCM) if(WITH_GPU OR WITH_ROCM)
target_link_libraries(device_context gpu_info gpu_context phi_gpu_info)
target_link_libraries(device_context gpu_resource_pool) target_link_libraries(device_context gpu_resource_pool)
endif() endif()
if(WITH_CUSTOM_DEVICE)
target_link_libraries(device_context custom_context)
endif()
if(WITH_ASCEND_CL) if(WITH_ASCEND_CL)
target_link_libraries(device_context npu_resource_pool) target_link_libraries(device_context npu_resource_pool)
endif() endif()
if(WITH_MLU) if(WITH_XPU)
target_link_libraries(device_context mlu_resource_pool) target_link_libraries(device_context xpu_resource_pool)
endif() endif()
if(WITH_CUSTOM_DEVICE) if(WITH_MLU)
target_link_libraries(device_context custom_context) target_link_libraries(device_context mlu_resource_pool)
endif() endif()
cc_test( cc_test(
......
...@@ -3,7 +3,7 @@ if(WITH_GPU) ...@@ -3,7 +3,7 @@ if(WITH_GPU)
nv_library( nv_library(
gpu_info gpu_info
SRCS gpu_info.cc SRCS gpu_info.cc
DEPS phi_gpu_info gflags glog enforce monitor dynload_cuda) DEPS phi_backends gflags glog enforce monitor dynload_cuda)
nv_test(cuda_helper_test SRCS cuda_helper_test.cu) nv_test(cuda_helper_test SRCS cuda_helper_test.cu)
nv_test( nv_test(
...@@ -15,7 +15,7 @@ elseif(WITH_ROCM) ...@@ -15,7 +15,7 @@ elseif(WITH_ROCM)
hip_library( hip_library(
gpu_info gpu_info
SRCS gpu_info.cc SRCS gpu_info.cc
DEPS phi_gpu_info gflags glog enforce monitor dynload_cuda) DEPS phi_backends gflags glog enforce monitor dynload_cuda)
hip_test(cuda_helper_test SRCS cuda_helper_test.cu) hip_test(cuda_helper_test SRCS cuda_helper_test.cu)
hip_test( hip_test(
......
...@@ -20,7 +20,7 @@ cc_library( ...@@ -20,7 +20,7 @@ cc_library(
xpulib xpulib
device_context device_context
place place
phi_xpu_info) phi_backends)
cc_library( cc_library(
xpu_op_list xpu_op_list
SRCS xpu_op_list.cc SRCS xpu_op_list.cc
......
...@@ -30,7 +30,7 @@ endif() ...@@ -30,7 +30,7 @@ endif()
set(PHI_DEPS set(PHI_DEPS
convert_utils convert_utils
dense_tensor dense_tensor
phi_context phi_backends
kernel_factory kernel_factory
kernel_context kernel_context
arg_map_context arg_map_context
......
...@@ -351,12 +351,12 @@ cc_library( ...@@ -351,12 +351,12 @@ cc_library(
cc_library( cc_library(
context_pool context_pool
SRCS context_pool.cc SRCS context_pool.cc
DEPS phi_context phi_enforce place init) DEPS phi_backends phi_enforce place init)
cc_library( cc_library(
kernel_dispatch kernel_dispatch
SRCS kernel_dispatch.cc SRCS kernel_dispatch.cc
DEPS phi_tensor_raw phi_context kernel_factory context_pool) DEPS phi_tensor_raw phi_backends kernel_factory context_pool)
cc_library( cc_library(
api_gen_utils api_gen_utils
SRCS api_gen_utils.cc SRCS api_gen_utils.cc
......
add_subdirectory(dynload) add_subdirectory(dynload)
add_subdirectory(cpu) set(BACKENDS_SRCS all_context.cc cpu/cpu_context.cc)
set(BACKENDS_DEPS enforce place flags)
add_subdirectory(custom)
if(WITH_GPU OR WITH_ROCM) if(WITH_GPU OR WITH_ROCM)
add_subdirectory(gpu) list(APPEND BACKENDS_SRCS gpu/gpu_context.cc gpu/gpu_info.cc
gpu/gpu_resources.cc)
if(WITH_GPU)
list(APPEND BACKENDS_SRCS gpu/cuda/cuda_info.cc)
endif()
if(WITH_ROCM)
list(APPEND BACKENDS_SRCS gpu/rocm/rocm_info.cc)
endif()
list(APPEND BACKENDS_DEPS phi_dynload_cuda)
endif() endif()
if(WITH_XPU) if(WITH_XPU)
add_subdirectory(xpu) list(APPEND BACKENDS_SRCS xpu/xpu_context.cc xpu/xpu_info.cc)
endif() endif()
if(WITH_MKLDNN) if(WITH_MKLDNN)
add_subdirectory(onednn) list(APPEND BACKENDS_SRCS onednn/onednn_context.cc)
list(APPEND BACKENDS_DEPS mkldnn)
endif() endif()
cc_library( if(WITH_CUSTOM_DEVICE)
phi_context list(
SRCS all_context.cc APPEND
DEPS device_context cpu_context) BACKENDS_SRCS
callback_manager.cc
if(WITH_XPU) device_guard.cc
add_dependencies(phi_context xpu_context) stream.cc
event.cc
device_base.cc
device_manager.cc
custom/custom_context.cc
custom/custom_device.cc)
endif() endif()
if(WITH_GPU) add_library(phi_backends "${BACKENDS_SRCS}")
add_dependencies(phi_context gpu_context) target_link_libraries(phi_backends ${BACKENDS_DEPS})
endif()
# for inference library
get_property(phi_modules GLOBAL PROPERTY PHI_MODULES)
set(phi_modules ${phi_modules} phi_backends)
set_property(GLOBAL PROPERTY PHI_MODULES "${phi_modules}")
if(WITH_CUSTOM_DEVICE) if(WITH_CUSTOM_DEVICE)
add_dependencies(phi_context custom_context) cc_test(
cc_library( custom_device_test
callback_manager SRCS custom/custom_device_test.cc
SRCS callback_manager.cc DEPS phi_backends phi_device_context)
DEPS enforce place) cc_test(
cc_library( capi_test
device_guard SRCS custom/capi_test.cc
SRCS device_guard.cc DEPS phi_capi)
DEPS enforce place)
cc_library(
stream
SRCS stream.cc
DEPS callback_manager)
cc_library(
event
SRCS event.cc
DEPS enforce place)
cc_library(
device_base
SRCS device_base.cc
DEPS stream event callback_manager device_guard device_context flags)
cc_library(
device_manager
SRCS device_manager.cc
DEPS custom_device)
set(GLOB_DEV_LIB
device_manager custom_device
CACHE INTERNAL "Global DEV library")
endif() endif()
if(WITH_MKLDNN)
# TODO(wilber): support mkldnn context.
cc_library(
cpu_context
SRCS cpu_context.cc
DEPS phi_device_context mkldnn eigen3)
else()
cc_library(
cpu_context
SRCS cpu_context.cc
DEPS phi_device_context eigen3)
endif()
if(WITH_GPU)
add_subdirectory(cuda)
nv_library(
phi_gpu_info
SRCS gpu_info.cc
DEPS phi_cuda_info gflags glog enforce phi_dynload_cuda)
elseif(WITH_ROCM)
add_subdirectory(rocm)
hip_library(
phi_gpu_info
SRCS gpu_info.cc
DEPS phi_rocm_info gflags glog enforce phi_dynload_cuda)
endif()
cc_library(
gpu_resources
SRCS gpu_resources.cc
DEPS phi_device_context phi_gpu_info)
cc_library(
gpu_context
SRCS gpu_context.cc
DEPS phi_device_context phi_gpu_info eigen3 gpu_resources)
nv_library(
phi_cuda_info
SRCS cuda_info.cc
DEPS gflags glog enforce phi_dynload_cuda)
hip_library(
phi_rocm_info
SRCS rocm_info.cc
DEPS gflags glog enforce phi_dynload_cuda)
if(WITH_MKLDNN)
cc_library(
onednn_context
SRCS onednn_context.cc
DEPS cpu_context mkldnn)
endif()
cc_library(
phi_xpu_info
SRCS xpu_info.cc
DEPS enforce xpulib phi_place)
cc_library(
xpu_context
SRCS xpu_context.cc
DEPS phi_device_context phi_xpu_info)
...@@ -6,7 +6,7 @@ cc_library( ...@@ -6,7 +6,7 @@ cc_library(
cc_library( cc_library(
phi_c_device_context phi_c_device_context
SRCS c_device_context.cc SRCS c_device_context.cc
DEPS phi_context) DEPS phi_backends)
cc_library( cc_library(
phi_c_int_array phi_c_int_array
......
...@@ -2,12 +2,12 @@ if(WITH_GPU) ...@@ -2,12 +2,12 @@ if(WITH_GPU)
nv_library( nv_library(
phi_place phi_place
SRCS place.cc SRCS place.cc
DEPS phi_gpu_info) DEPS phi_backends)
elseif(WITH_ROCM) elseif(WITH_ROCM)
hip_library( hip_library(
phi_place phi_place
SRCS place.cc SRCS place.cc
DEPS phi_gpu_info) DEPS phi_backends)
else() else()
cc_library(phi_place SRCS place.cc) cc_library(phi_place SRCS place.cc)
endif() endif()
......
...@@ -18,7 +18,7 @@ cc_library( ...@@ -18,7 +18,7 @@ cc_library(
cc_library( cc_library(
kernel_context kernel_context
SRCS kernel_context.cc SRCS kernel_context.cc
DEPS phi_enforce phi_context) DEPS phi_enforce phi_backends)
cc_library( cc_library(
ddim ddim
...@@ -86,38 +86,20 @@ if(WITH_GPU) ...@@ -86,38 +86,20 @@ if(WITH_GPU)
nv_library( nv_library(
phi_tensor_utils phi_tensor_utils
SRCS tensor_utils.cc SRCS tensor_utils.cc
DEPS cpu_context DEPS phi_backends dense_tensor selected_rows malloc memcpy device_context)
gpu_context
dense_tensor
selected_rows
malloc
memcpy
device_context)
elseif(WITH_ROCM) elseif(WITH_ROCM)
hip_library( hip_library(
phi_tensor_utils phi_tensor_utils
SRCS tensor_utils.cc SRCS tensor_utils.cc
DEPS cpu_context DEPS phi_backends dense_tensor selected_rows malloc memcpy device_context)
gpu_context
dense_tensor
selected_rows
malloc
memcpy
device_context)
elseif(WITH_XPU_KP) elseif(WITH_XPU_KP)
xpu_library( xpu_library(
phi_tensor_utils phi_tensor_utils
SRCS tensor_utils.cc SRCS tensor_utils.cc
DEPS cpu_context DEPS phi_backends dense_tensor selected_rows malloc memcpy device_context)
xpu_context
dense_tensor
selected_rows
malloc
memcpy
device_context)
else() else()
cc_library( cc_library(
phi_tensor_utils phi_tensor_utils
SRCS tensor_utils.cc SRCS tensor_utils.cc
DEPS cpu_context dense_tensor selected_rows malloc memcpy device_context) DEPS dense_tensor selected_rows malloc memcpy device_context phi_backends)
endif() endif()
...@@ -7,18 +7,8 @@ cc_library( ...@@ -7,18 +7,8 @@ cc_library(
SRCS op_utils.cc SRCS op_utils.cc
DEPS arg_map_context enforce) DEPS arg_map_context enforce)
set(convert_utils_deps data_type place op_utils) set(convert_utils_deps data_type place op_utils phi_backends)
if(WITH_GPU)
set(convert_utils_deps ${convert_utils_deps} phi_gpu_info)
elseif(WITH_ROCM)
set(convert_utils_deps ${convert_utils_deps} phi_gpu_info)
elseif(WITH_XPU)
set(convert_utils_deps ${convert_utils_deps} phi_xpu_info)
endif()
if(WITH_CUSTOM_DEVICE)
set(convert_utils_deps ${convert_utils_deps} device_manager)
endif()
cc_library( cc_library(
convert_utils convert_utils
SRCS convert_utils.cc SRCS convert_utils.cc
......
...@@ -157,7 +157,7 @@ endif() ...@@ -157,7 +157,7 @@ endif()
if(WITH_MKLDNN) if(WITH_MKLDNN)
add_library(phi_onednn ${kernel_onednn}) add_library(phi_onednn ${kernel_onednn})
kernel_declare(${kernel_onednn}) kernel_declare(${kernel_onednn})
set(COMMON_KERNEL_DEPS ${COMMON_KERNEL_DEPS} onednn_context) set(COMMON_KERNEL_DEPS ${COMMON_KERNEL_DEPS} phi_backends)
target_link_libraries(phi_onednn ${COMMON_KERNEL_DEPS}) target_link_libraries(phi_onednn ${COMMON_KERNEL_DEPS})
set(ADD_PHI_KERNELS ${ADD_PHI_KERNELS} phi_onednn) set(ADD_PHI_KERNELS ${ADD_PHI_KERNELS} phi_onednn)
endif() endif()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册