Skip to content

Commit

Permalink
Support XPU ABI neutral build
Browse files Browse the repository at this point in the history
  • Loading branch information
CuiYifeng committed Jul 12, 2024
1 parent 0ff60c6 commit 6540075
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
6 changes: 3 additions & 3 deletions cmake/BuildFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
3 changes: 1 addition & 2 deletions cmake/Modules/FindSYCL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ else()
endif()

set(SYCL_LIBRARIES)
find_library(SYCL_RUNTIME_LIBRARY sycl HINTS ${SYCL_LIBRARY_DIR})
find_library(SYCL_RUNTIME_LIBRARY sycl-preview 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,
Expand Down Expand Up @@ -427,7 +427,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}\""
Expand Down
7 changes: 6 additions & 1 deletion cmake/Modules/FindSYCLToolkit.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ find_file(

find_library(
SYCL_LIBRARY
NAMES sycl
NAMES sycl-preview
HINTS ${SYCL_LIBRARY_DIR}
NO_DEFAULT_PATH
)
Expand Down Expand Up @@ -202,6 +202,11 @@ set(SYCL_FLAGS "")
set(SYCL_LINK_FLAGS "")
list(APPEND SYCL_FLAGS "-fsycl")
list(APPEND SYCL_LINK_FLAGS "-fsycl")
# Workaround about XPU ABI neutral build
if(LINUX)
list(APPEND SYCL_FLAGS "-fpreview-breaking-changes")
list(APPEND SYCL_LINK_FLAGS "-fpreview-breaking-changes")
endif()

set(SYCL_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SYCL_FLAGS}")

Expand Down
2 changes: 1 addition & 1 deletion cmake/SYCL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if(NOT SYCL_VERSION)
return()
endif()

find_library(SYCL_LIBRARIES sycl HINTS ${SYCL_LIBRARY_DIR})
find_library(SYCL_LIBRARIES sycl-preview 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,
Expand Down
4 changes: 2 additions & 2 deletions src/ATen/native/xpu/sycl/AmpKernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_) {
Expand Down

0 comments on commit 6540075

Please sign in to comment.