diff --git a/cmake/BuildFlags.cmake b/cmake/BuildFlags.cmake index d0eb3e299..2f05d1ab0 100644 --- a/cmake/BuildFlags.cmake +++ b/cmake/BuildFlags.cmake @@ -59,10 +59,10 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" set(SYCL_KERNEL_OPTIONS ${SYCL_KERNEL_OPTIONS} -fno-approx-func) set(SYCL_KERNEL_OPTIONS ${SYCL_KERNEL_OPTIONS} -Wno-absolute-value) set(SYCL_KERNEL_OPTIONS ${SYCL_KERNEL_OPTIONS} -no-ftz) + # Equivalent to build option -fpreview-breaking-changes for SYCL compiler. + set(SYCL_KERNEL_OPTIONS ${SYCL_KERNEL_OPTIONS} -D__INTEL_PREVIEW_BREAKING_CHANGES) + set(SYCL_KERNEL_OPTIONS ${SYCL_KERNEL_OPTIONS} -D_GLIBCXX_USE_CXX11_ABI=${GLIBCXX_USE_CXX11_ABI}) endif() - # TODO: Align with PyTorch and switch to ABI=0 eventually, after - # resolving incompatible implementation in SYCL runtime. - set(SYCL_KERNEL_OPTIONS ${SYCL_KERNEL_OPTIONS} -D_GLIBCXX_USE_CXX11_ABI=1) set(SYCL_FLAGS ${SYCL_FLAGS} ${SYCL_KERNEL_OPTIONS}) set(TORCH_XPU_OPS_FLAGS ${SYCL_HOST_FLAGS}) diff --git a/cmake/Modules/FindSYCL.cmake b/cmake/Modules/FindSYCL.cmake index b8fc8ba22..4e266a26f 100644 --- a/cmake/Modules/FindSYCL.cmake +++ b/cmake/Modules/FindSYCL.cmake @@ -407,7 +407,6 @@ macro(SYCL_LINK_DEVICE_OBJECTS output_file sycl_target) OUTPUT ${output_file} DEPENDS ${object_files} COMMAND ${SYCL_EXECUTABLE} - -fsycl ${SYCL_device_link_flags} -fsycl-link ${object_files} -Xs "\"${SYCL_OFFLINE_COMPILER_FLAGS}\"" @@ -471,7 +470,7 @@ macro(SYCL_ADD_LIBRARY sycl_target) target_link_libraries( ${sycl_target} ${SYCL_LINK_LIBRARIES_KEYWORD} - ${SYCL_LIBRARIES}) + ${SYCL_LIBRARY}) set_target_properties(${sycl_target} PROPERTIES @@ -530,7 +529,7 @@ macro(SYCL_ADD_EXECUTABLE sycl_target) target_link_libraries( ${sycl_target} ${SYCL_LINK_LIBRARIES_KEYWORD} - ${SYCL_LIBRARIES}) + ${SYCL_LIBRARY}) set_target_properties(${sycl_target} PROPERTIES diff --git a/cmake/Modules/FindSYCLToolkit.cmake b/cmake/Modules/FindSYCLToolkit.cmake index e478cb4c5..46e34c7f8 100644 --- a/cmake/Modules/FindSYCLToolkit.cmake +++ b/cmake/Modules/FindSYCLToolkit.cmake @@ -25,16 +25,20 @@ This will define the following variables: #]=======================================================================] -set(SYCLTOOLKIT_FOUND False) -include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) +include(${TORCH_ROOT}/cmake/Modules/FindSYCLToolkit.cmake) -set(SYCL_ROOT "") -if(DEFINED ENV{SYCL_ROOT}) - set(SYCL_ROOT $ENV{SYCL_ROOT}) -elseif(DEFINED ENV{CMPLR_ROOT}) - set(SYCL_ROOT $ENV{CMPLR_ROOT}) +if(NOT SYCL_FOUND) + set(SYCLTOOLKIT_FOUND FALSE) + return() endif() +if(SYCLTOOLKIT_FOUND) + return() +endif() +set(SYCLTOOLKIT_FOUND TRUE) + +include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) + if(WIN32) set(SYCL_EXECUTABLE_NAME icx) else() @@ -71,43 +75,6 @@ if(nocmplr) set(SYCL_NOT_FOUND_MESSAGE "${SYCL_REASON_FAILURE}") endif() -find_file( - SYCL_INCLUDE_DIR - NAMES include - HINTS ${SYCL_ROOT} - NO_DEFAULT_PATH - ) - -find_file( - SYCL_INCLUDE_SYCL_DIR - NAMES sycl - HINTS ${SYCL_ROOT}/include - NO_DEFAULT_PATH - ) - -list(APPEND SYCL_INCLUDE_DIR ${SYCL_INCLUDE_SYCL_DIR}) - -find_file( - SYCL_LIBRARY_DIR - NAMES lib lib64 - HINTS ${SYCL_ROOT} - NO_DEFAULT_PATH - ) - -find_library( - SYCL_LIBRARY - NAMES sycl - HINTS ${SYCL_LIBRARY_DIR} - NO_DEFAULT_PATH -) - -if((NOT SYCL_INCLUDE_DIR) OR (NOT SYCL_LIBRARY_DIR) OR (NOT SYCL_LIBRARY)) - set(SYCLTOOLKIT_FOUND False) - set(SYCL_REASON_FAILURE "SYCL sdk is incomplete!!") - set(SYCL_NOT_FOUND_MESSAGE "${SYCL_REASON_FAILURE}") - return() -endif() - # Function to write a test case to verify SYCL features. function(SYCL_CMPLR_TEST_WRITE src) @@ -202,6 +169,13 @@ set(SYCL_FLAGS "") set(SYCL_LINK_FLAGS "") list(APPEND SYCL_FLAGS "-fsycl") list(APPEND SYCL_LINK_FLAGS "-fsycl") +if(LINUX) + string(REGEX MATCH "libsycl-preview.so" is_abi_neutral ${SYCL_LIBRARY}) + if(is_abi_neutral) + list(APPEND SYCL_FLAGS "-fpreview-breaking-changes") + list(APPEND SYCL_LINK_FLAGS "-fpreview-breaking-changes") + endif() +endif() set(SYCL_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SYCL_FLAGS}") @@ -249,14 +223,3 @@ endif() message(DEBUG "The SYCL compiler is ${SYCL_COMPILER}") message(DEBUG "The SYCL Flags are ${SYCL_FLAGS}") - -# Avoid module variables conflict due to calling find_package recursively -# e.g. find_package -> add_subdirectory(entering in a sub-project) -> find_package -# find_package_handle_standard_args( -# SYCLToolkit -# FOUND_VAR SYCLTOOLKIT_FOUND -# REQUIRED_VARS SYCL_INCLUDE_DIR SYCL_LIBRARY_DIR SYCL_LIBRARY SYCL_FLAGS -# VERSION_VAR SYCL_LANGUAGE_VERSION -# REASON_FAILURE_MESSAGE "${SYCL_REASON_FAILURE}") -set(SYCLTOOLKIT_FOUND True) - diff --git a/cmake/SYCL.cmake b/cmake/SYCL.cmake index b2bbadaa4..f0724ef55 100644 --- a/cmake/SYCL.cmake +++ b/cmake/SYCL.cmake @@ -25,24 +25,6 @@ if(NOT SYCL_VERSION) return() endif() -find_library(SYCL_LIBRARIES sycl HINTS ${SYCL_LIBRARY_DIR}) -# On Windows, currently there's no sycl.lib. Only sycl7.lib with version suffix, -# where the current version of the SYCL runtime is 7. -# Until oneAPI adds support to sycl.lib without the version suffix, -# sycl_runtime_version needs to be hardcoded and uplifted when SYCL runtime version uplifts. -# TODO: remove this when sycl.lib is supported on Windows -if(WIN32) - set(sycl_runtime_version 7) - find_library( - SYCL_LIBRARIES - NAMES "sycl${sycl_runtime_version}" - HINTS ${SYCL_LIBRARY_DIR} - ) - if(SYCL_LIBRARIES STREQUAL "SYCL_LIBRARIES-NOTFOUND") - message(FATAL_ERROR "Cannot find a SYCL library on Windows") - endif() -endif() - set(SYCL_COMPILER_VERSION) file(READ ${SYCL_VERSION} version_contents) string(REGEX MATCHALL "__SYCL_COMPILER_VERSION +[0-9]+" VERSION_LINE "${version_contents}") diff --git a/src/ATen/CMakeLists.txt b/src/ATen/CMakeLists.txt index c95e860fa..815ad018f 100644 --- a/src/ATen/CMakeLists.txt +++ b/src/ATen/CMakeLists.txt @@ -1,6 +1,6 @@ # ATen XPU sources -file(GLOB xpu_cpp "xpu/*.cpp", "native/xpu/*.cpp", "native/sparse/*.cpp") +file(GLOB xpu_cpp "xpu/*.cpp" "native/xpu/*.cpp" "native/sparse/*.cpp") file(GLOB xpu_sycl "native/xpu/sycl/*.cpp") list(APPEND ATen_XPU_CPP_SRCS ${xpu_cpp}) diff --git a/src/ATen/native/xpu/sycl/AmpKernels.cpp b/src/ATen/native/xpu/sycl/AmpKernels.cpp index 5e8d258a6..87354eea9 100644 --- a/src/ATen/native/xpu/sycl/AmpKernels.cpp +++ b/src/ATen/native/xpu/sycl/AmpKernels.cpp @@ -102,9 +102,9 @@ void amp_foreach_non_finite_check_and_unscale_kernel( } struct AmpUpdateScaleKernelFunctor { - void operator()(sycl::item<1> item) const { + void operator()(sycl::nd_item<1> item) const { // There is only single item/task scheduled. - if (item.get_linear_id() != 0) + if (item.get_global_linear_id() != 0) return; if (*found_inf_) { diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a5e0a8549..fa17491a2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -82,7 +82,7 @@ foreach(lib ${TORCH_XPU_OPS_LIBRARIES}) target_include_directories(${lib} PUBLIC ${ATen_XPU_INCLUDE_DIRS}) target_include_directories(${lib} PUBLIC ${SYCL_INCLUDE_DIR}) - target_link_libraries(${lib} PUBLIC ${SYCL_LIBRARIES}) + target_link_libraries(${lib} PUBLIC ${SYCL_LIBRARY}) endforeach() include(${TORCH_XPU_OPS_ROOT}/cmake/ClangFormat.cmake) diff --git a/test/sycl/CMakeLists.txt b/test/sycl/CMakeLists.txt index 0671fbc94..5bbee8643 100644 --- a/test/sycl/CMakeLists.txt +++ b/test/sycl/CMakeLists.txt @@ -42,7 +42,7 @@ add_dependencies(test_sycl_build_archive sycl_simple_kernel_test) # Instead, we use explicit linkage option '--whole-archive', which is required # by linkage of device object modules archived in the static library. Then # explicit linkage configuration of SYCL runtime library is required. -target_link_libraries(test_sycl_build_archive ${SYCL_LIBRARIES}) +target_link_libraries(test_sycl_build_archive ${SYCL_LIBRARY}) if(INSTALL_TEST) install(TARGETS test_sycl_build_archive DESTINATION bin)