Skip to content

Commit

Permalink
enable compiled into one library on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
chunhuanMeng committed Dec 25, 2024
1 parent 5bfd384 commit 89af91f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 25 deletions.
4 changes: 2 additions & 2 deletions cmake/BuildFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "MSVC"
set(SYCL_OFFLINE_COMPILER_CG_OPTIONS "-options '${SYCL_OFFLINE_COMPILER_CG_OPTIONS}'")

if(WIN32)
set(AOT_TARGETS "ats-m150,mtl-u,mtl-h,xe2-lpg,xe2-hpg")
set(AOT_TARGETS "dg2-g10,mtl-u,mtl-h,xe2-lpg,xe2-hpg")
else()
set(AOT_TARGETS "pvc,xe-lpg,ats-m150")
set(AOT_TARGETS "pvc,xe-lpg,dg2-g10,xe2-lpg,xe2-hpg")
endif()
if((DEFINED ENV{TORCH_XPU_ARCH_LIST}) AND NOT ("$ENV{TORCH_XPU_ARCH_LIST}" STREQUAL ""))
set(AOT_TARGETS "$ENV{TORCH_XPU_ARCH_LIST}")
Expand Down
31 changes: 24 additions & 7 deletions cmake/Modules/FindSYCL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,17 @@ macro(SYCL_WRAP_SRCS sycl_target generated_files)
set(SYCL_flags "")
set(generated_extension ${CMAKE_${SYCL_C_OR_CXX}_OUTPUT_EXTENSION})

set(library_name)
if(${sycl_target} STREQUAL "xpu_ops_kernels")
set(library_name torch_xpu_ops_sycl_kernels)
else()
set(library_name ${sycl_target})
endif()

set(SYCL_include_dirs "${SYCL_INCLUDE_DIR}")
list(APPEND SYCL_include_dirs "$<TARGET_PROPERTY:${sycl_target},INCLUDE_DIRECTORIES>")
list(APPEND SYCL_include_dirs "$<TARGET_PROPERTY:${library_name},INCLUDE_DIRECTORIES>")

set(SYCL_compile_definitions "$<TARGET_PROPERTY:${sycl_target},COMPILE_DEFINITIONS>")
set(SYCL_compile_definitions "$<TARGET_PROPERTY:${library_name},COMPILE_DEFINITIONS>")

SYCL_GET_SOURCES_AND_OPTIONS(
_sycl_sources
Expand Down Expand Up @@ -264,7 +271,7 @@ macro(SYCL_WRAP_SRCS sycl_target generated_files)

get_filename_component( basename ${file} NAME )
set(generated_file_path "${SYCL_compile_output_dir}/${CMAKE_CFG_INTDIR}")
set(generated_file_basename "${sycl_target}_generated_${basename}${generated_extension}")
set(generated_file_basename "${sycl_target}_gen_${basename}${generated_extension}")
set(generated_file "${generated_file_path}/${generated_file_basename}")
set(SYCL_generated_dependency_file "${SYCL_compile_intermediate_directory}/${generated_file_basename}.SYCL-depend") # generate by compiler options -M -MF
set(cmake_dependency_file "${SYCL_compile_intermediate_directory}/${generated_file_basename}.depend") # parse and convert SYCL_generated_dependency_file(compiler format) to cmake format
Expand Down Expand Up @@ -434,6 +441,16 @@ macro(SYCL_ADD_LIBRARY sycl_target)
${ARGN})

SYCL_BUILD_SHARED_LIBRARY(_sycl_shared_flag ${ARGN})

# For one library, in which case the sycl_target should be shorter to fit the
# character limit of Windows batch files, and the library_name is set to be
# more recognizable.
set(library_name)
if(${sycl_target} STREQUAL "xpu_ops_kernels")
set(library_name torch_xpu_ops_sycl_kernels)
else()
set(library_name ${sycl_target})
endif()

if(_sycl_sources)
# Compile sycl sources
Expand All @@ -455,24 +472,24 @@ macro(SYCL_ADD_LIBRARY sycl_target)
${${sycl_target}_sycl_objects})

add_library(
${sycl_target}
${library_name}
${_cmake_options}
${_cxx_sources}
${${sycl_target}_sycl_objects}
${device_object})
else()
add_library(
${sycl_target}
${library_name}
${_cmake_options}
${_cxx_sources})
endif()

target_link_libraries(
${sycl_target}
${library_name}
${SYCL_LINK_LIBRARIES_KEYWORD}
${SYCL_LIBRARY})

set_target_properties(${sycl_target}
set_target_properties(${library_name}
PROPERTIES
LINKER_LANGUAGE ${SYCL_C_OR_CXX})

Expand Down
44 changes: 28 additions & 16 deletions src/BuildOnWindows.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ if(BUILD_SEPARATE_OPS)
# Decouple with PyTorch cmake definition.
install(TARGETS ${sycl_lib} DESTINATION "${TORCH_INSTALL_LIB_DIR}")
endforeach()
else()
elseif(BUILD_SPLIT_KERNEL_LIB)
# Split SYCL kernels into 2 libraries as categories 1) Unary+Binary 2) Others.
set(ATen_XPU_SYCL_BINARY_SRCS)
set(ATen_XPU_SYCL_UNARY_SRCS)
Expand All @@ -60,13 +60,13 @@ else()
string(REGEX MATCH "Activation" IS_ACTIVATION ${sycl_src})
string(REGEX MATCH "Foreach" IS_FOREACH ${sycl_src})
string(REGEX MATCH "Reduce" IS_REDUCE ${sycl_src})
string(REGEX MATCH "Tensor" IS_TENSOR ${sycl_src})
string(REGEX MATCH "Norm" IS_NORM ${sycl_src})
string(REGEX MATCH "Loss" IS_LOSS ${sycl_src})
string(REGEX MATCH "Polynomial" IS_POLY ${sycl_src})
#Move resize kernel to Norm and Loss lib, to resolve symbol.
string(REGEX MATCH "Resize" IS_RESIZE ${sycl_src})
string(REGEX MATCH "Distribution" IS_DISTRIBUTION ${sycl_src})
string(REGEX MATCH "Tensor" IS_TENSOR ${sycl_src})
string(REGEX MATCH "Norm" IS_NORM ${sycl_src})
string(REGEX MATCH "Loss" IS_LOSS ${sycl_src})
string(REGEX MATCH "Polynomial" IS_POLY ${sycl_src})
#Move resize kernel to Norm and Loss lib, to resolve symbol.
string(REGEX MATCH "Resize" IS_RESIZE ${sycl_src})
string(REGEX MATCH "Distribution" IS_DISTRIBUTION ${sycl_src})

if(NOT IS_FOREACH STREQUAL "")
list(APPEND ATen_XPU_SYCL_FOREACH_SRCS ${sycl_src})
Expand All @@ -78,14 +78,14 @@ else()
list(APPEND ATen_XPU_SYCL_REDUCE_SRCS ${sycl_src})
elseif(NOT IS_ACTIVATION STREQUAL "")
list(APPEND ATen_XPU_SYCL_ACTIVATION_SRCS ${sycl_src})
elseif(NOT IS_TENSOR STREQUAL "")
list(APPEND ATen_XPU_SYCL_TENSOR_SRCS ${sycl_src})
elseif(NOT IS_DISTRIBUTION STREQUAL "")
list(APPEND ATen_XPU_SYCL_DISTRIBUTION_SRCS ${sycl_src})
elseif(NOT IS_NORM STREQUAL "" OR NOT IS_LOSS STREQUAL "" OR NOT IS_RESIZE STREQUAL "")
list(APPEND ATen_XPU_SYCL_NORM_LOSS_SRCS ${sycl_src})
elseif(NOT IS_POLY STREQUAL "")
list(APPEND ATen_XPU_SYCL_POLY_SRCS ${sycl_src})
elseif(NOT IS_TENSOR STREQUAL "")
list(APPEND ATen_XPU_SYCL_TENSOR_SRCS ${sycl_src})
elseif(NOT IS_DISTRIBUTION STREQUAL "")
list(APPEND ATen_XPU_SYCL_DISTRIBUTION_SRCS ${sycl_src})
elseif(NOT IS_NORM STREQUAL "" OR NOT IS_LOSS STREQUAL "" OR NOT IS_RESIZE STREQUAL "")
list(APPEND ATen_XPU_SYCL_NORM_LOSS_SRCS ${sycl_src})
elseif(NOT IS_POLY STREQUAL "")
list(APPEND ATen_XPU_SYCL_POLY_SRCS ${sycl_src})
else()
list(APPEND ATen_XPU_SYCL_OTHERS_SRCS ${sycl_src})
endif()
Expand Down Expand Up @@ -229,6 +229,18 @@ else()

# Decouple with PyTorch cmake definition.
install(TARGETS ${sycl_lib} DESTINATION "${TORCH_INSTALL_LIB_DIR}")
else()
sycl_add_library(
xpu_ops_kernels
SHARED
SYCL_SOURCES ${ATen_XPU_SYCL_SRCS})
target_compile_definitions(torch_xpu_ops_sycl_kernels PRIVATE TORCH_XPU_BUILD_MAIN_LIB)
target_link_libraries(torch_xpu_ops_aten PUBLIC torch_xpu_ops_sycl_kernels)
target_link_libraries(torch_xpu_ops_sycl_kernels PUBLIC torch_xpu)
list(APPEND TORCH_XPU_OPS_LIBRARIES torch_xpu_ops_sycl_kernels)

# Decouple with PyTorch cmake definition.
install(TARGETS torch_xpu_ops_sycl_kernels DESTINATION "${TORCH_INSTALL_LIB_DIR}")
endif()
set(SYCL_LINK_LIBRARIES_KEYWORD)

Expand Down

0 comments on commit 89af91f

Please sign in to comment.