Skip to content

Commit 92bebb4

Browse files
guangyeypytorchmergebot
authored andcommitted
Support XPU ABI=0 build (pytorch#130110)
# Motivation This PR intends to support ABI=0 build for XPU backend. # Additional Context The major change is adding a compilation option `-D__INTEL_PREVIEW_BREAKING_CHANGES` for the host compiler(gcc) and `-fpreview-breaking-changes` for XPU device kernel code compiler(icpx), why? Because we use - gcc to compile host code and link SYCL runtime. So we need to pass `-D__INTEL_PREVIEW_BREAKING_CHANGES` to tell the host compiler invoking the ABI-neutral API included in SYCL. And - use icpx to compile device kernel code and link SYCL runtime. So we need to pass `-fpreview-breaking-changes` to tell the device kernel compiler building ABI-neutral code. Besides, - `libsycl-preview.so` is an ABI-neutral library but `libsycl.so` is not. This PR depends on pytorch#131643. Pull Request resolved: pytorch#130110 Approved by: https://github.com/EikanWang, https://github.com/gujinghui, https://github.com/albanD
1 parent 997f64a commit 92bebb4

File tree

5 files changed

+27
-17
lines changed

5 files changed

+27
-17
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ If you would like to compile PyTorch with [new C++ ABI](https://gcc.gnu.org/onli
252252
export _GLIBCXX_USE_CXX11_ABI=1
253253
```
254254

255+
Please **note** that starting from PyTorch 2.5, the PyTorch build with XPU supports both new and old C++ ABIs. Previously, XPU only supported the new C++ ABI. If you want to compile with Intel GPU support, please follow [Intel GPU Support](#intel-gpu-support).
256+
255257
If you're compiling for AMD ROCm then first run this command:
256258
```bash
257259
# Only run this if you're compiling for ROCm

c10/xpu/CMakeLists.txt

+15-15
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@ set(C10_XPU_HEADERS
3030
impl/XPUGuardImpl.h
3131
)
3232
if(NOT BUILD_LIBTORCHLESS)
33-
add_library(c10_xpu ${C10_XPU_SRCS} ${C10_XPU_HEADERS})
34-
target_compile_options(c10_xpu PRIVATE "-DC10_XPU_BUILD_MAIN_LIB")
35-
# Enable hidden visibility if compiler supports it.
36-
if(${COMPILER_SUPPORTS_HIDDEN_VISIBILITY})
37-
target_compile_options(c10_xpu PRIVATE "-fvisibility=hidden")
38-
endif()
39-
40-
# ---[ Dependency of c10_xpu
41-
target_link_libraries(c10_xpu PUBLIC c10 torch::xpurt)
42-
target_include_directories(
43-
c10_xpu PUBLIC
44-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../..>
45-
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
46-
$<INSTALL_INTERFACE:include>
47-
)
33+
add_library(c10_xpu ${C10_XPU_SRCS} ${C10_XPU_HEADERS})
34+
target_compile_options(c10_xpu PRIVATE "-DC10_XPU_BUILD_MAIN_LIB")
35+
# Enable hidden visibility if compiler supports it.
36+
if(${COMPILER_SUPPORTS_HIDDEN_VISIBILITY})
37+
target_compile_options(c10_xpu PRIVATE "-fvisibility=hidden")
38+
endif()
39+
40+
# ---[ Dependency of c10_xpu
41+
target_link_libraries(c10_xpu PUBLIC c10 torch::xpurt)
42+
target_include_directories(
43+
c10_xpu PUBLIC
44+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../..>
45+
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
46+
$<INSTALL_INTERFACE:include>
47+
)
4848
install(TARGETS c10_xpu EXPORT Caffe2Targets DESTINATION lib)
4949
set(C10_XPU_LIB c10_xpu)
5050
add_subdirectory(test)

cmake/Dependencies.cmake

+4
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ if(USE_XPU)
9090
message(WARNING "Not compiling with XPU. Could NOT find SYCL."
9191
"Suppress this warning with -DUSE_XPU=OFF.")
9292
caffe2_update_option(USE_XPU OFF)
93+
else()
94+
if(LINUX)
95+
string(APPEND CMAKE_CXX_FLAGS " -D__INTEL_PREVIEW_BREAKING_CHANGES")
96+
endif()
9397
endif()
9498
endif()
9599

cmake/Modules/FindMKLDNN.cmake

+5-1
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,22 @@ IF(NOT MKLDNN_FOUND)
3636
set(DNNL_MAKE_COMMAND "cmake" "--build" ".")
3737
include(ProcessorCount)
3838
ProcessorCount(proc_cnt)
39-
if ((DEFINED ENV{MAX_JOBS}) AND ("$ENV{MAX_JOBS}" LESS_EQUAL ${proc_cnt}))
39+
if((DEFINED ENV{MAX_JOBS}) AND ("$ENV{MAX_JOBS}" LESS_EQUAL ${proc_cnt}))
4040
list(APPEND DNNL_MAKE_COMMAND "-j" "$ENV{MAX_JOBS}")
4141
if(CMAKE_GENERATOR MATCHES "Make|Ninja")
4242
list(APPEND DNNL_MAKE_COMMAND "--" "-l" "$ENV{MAX_JOBS}")
4343
endif()
4444
endif()
45+
if(LINUX)
46+
set(ABI_NEUTRAL_FLAGS -fpreview-breaking-changes)
47+
endif()
4548
ExternalProject_Add(xpu_mkldnn_proj
4649
SOURCE_DIR ${MKLDNN_ROOT}
4750
PREFIX ${XPU_MKLDNN_DIR_PREFIX}
4851
BUILD_IN_SOURCE 0
4952
CMAKE_ARGS -DCMAKE_C_COMPILER=icx
5053
-DCMAKE_CXX_COMPILER=${SYCL_CXX_DRIVER}
54+
-DCMAKE_CXX_FLAGS=${ABI_NEUTRAL_FLAGS}
5155
-DDNNL_GPU_RUNTIME=SYCL
5256
-DDNNL_CPU_RUNTIME=THREADPOOL
5357
-DDNNL_BUILD_TESTS=OFF

cmake/Modules/FindSYCLToolkit.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ find_file(
5151
# Find SYCL library fullname.
5252
find_library(
5353
SYCL_LIBRARY
54-
NAMES sycl
54+
NAMES sycl-preview
5555
HINTS ${SYCL_LIBRARY_DIR}
5656
NO_DEFAULT_PATH
5757
)

0 commit comments

Comments
 (0)