Support XPU ABI=0 build (#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 https://github.com/pytorch/pytorch/pull/131643.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/130110
Approved by: https://github.com/EikanWang, https://github.com/gujinghui, https://github.com/albanD
This commit is contained in:
Yu, Guangye
2024-08-01 16:28:12 +00:00
committed by PyTorch MergeBot
parent 997f64af38
commit 92bebb46fa
5 changed files with 26 additions and 16 deletions

View File

@ -252,6 +252,8 @@ If you would like to compile PyTorch with [new C++ ABI](https://gcc.gnu.org/onli
export _GLIBCXX_USE_CXX11_ABI=1 export _GLIBCXX_USE_CXX11_ABI=1
``` ```
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).
If you're compiling for AMD ROCm then first run this command: If you're compiling for AMD ROCm then first run this command:
```bash ```bash
# Only run this if you're compiling for ROCm # Only run this if you're compiling for ROCm

View File

@ -30,21 +30,21 @@ set(C10_XPU_HEADERS
impl/XPUGuardImpl.h impl/XPUGuardImpl.h
) )
if(NOT BUILD_LIBTORCHLESS) if(NOT BUILD_LIBTORCHLESS)
add_library(c10_xpu ${C10_XPU_SRCS} ${C10_XPU_HEADERS}) add_library(c10_xpu ${C10_XPU_SRCS} ${C10_XPU_HEADERS})
target_compile_options(c10_xpu PRIVATE "-DC10_XPU_BUILD_MAIN_LIB") target_compile_options(c10_xpu PRIVATE "-DC10_XPU_BUILD_MAIN_LIB")
# Enable hidden visibility if compiler supports it. # Enable hidden visibility if compiler supports it.
if(${COMPILER_SUPPORTS_HIDDEN_VISIBILITY}) if(${COMPILER_SUPPORTS_HIDDEN_VISIBILITY})
target_compile_options(c10_xpu PRIVATE "-fvisibility=hidden") target_compile_options(c10_xpu PRIVATE "-fvisibility=hidden")
endif() endif()
# ---[ Dependency of c10_xpu # ---[ Dependency of c10_xpu
target_link_libraries(c10_xpu PUBLIC c10 torch::xpurt) target_link_libraries(c10_xpu PUBLIC c10 torch::xpurt)
target_include_directories( target_include_directories(
c10_xpu PUBLIC c10_xpu PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../..> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../..>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}> $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
$<INSTALL_INTERFACE:include> $<INSTALL_INTERFACE:include>
) )
install(TARGETS c10_xpu EXPORT Caffe2Targets DESTINATION lib) install(TARGETS c10_xpu EXPORT Caffe2Targets DESTINATION lib)
set(C10_XPU_LIB c10_xpu) set(C10_XPU_LIB c10_xpu)
add_subdirectory(test) add_subdirectory(test)

View File

@ -90,6 +90,10 @@ if(USE_XPU)
message(WARNING "Not compiling with XPU. Could NOT find SYCL." message(WARNING "Not compiling with XPU. Could NOT find SYCL."
"Suppress this warning with -DUSE_XPU=OFF.") "Suppress this warning with -DUSE_XPU=OFF.")
caffe2_update_option(USE_XPU OFF) caffe2_update_option(USE_XPU OFF)
else()
if(LINUX)
string(APPEND CMAKE_CXX_FLAGS " -D__INTEL_PREVIEW_BREAKING_CHANGES")
endif()
endif() endif()
endif() endif()

View File

@ -36,18 +36,22 @@ IF(NOT MKLDNN_FOUND)
set(DNNL_MAKE_COMMAND "cmake" "--build" ".") set(DNNL_MAKE_COMMAND "cmake" "--build" ".")
include(ProcessorCount) include(ProcessorCount)
ProcessorCount(proc_cnt) ProcessorCount(proc_cnt)
if ((DEFINED ENV{MAX_JOBS}) AND ("$ENV{MAX_JOBS}" LESS_EQUAL ${proc_cnt})) if((DEFINED ENV{MAX_JOBS}) AND ("$ENV{MAX_JOBS}" LESS_EQUAL ${proc_cnt}))
list(APPEND DNNL_MAKE_COMMAND "-j" "$ENV{MAX_JOBS}") list(APPEND DNNL_MAKE_COMMAND "-j" "$ENV{MAX_JOBS}")
if(CMAKE_GENERATOR MATCHES "Make|Ninja") if(CMAKE_GENERATOR MATCHES "Make|Ninja")
list(APPEND DNNL_MAKE_COMMAND "--" "-l" "$ENV{MAX_JOBS}") list(APPEND DNNL_MAKE_COMMAND "--" "-l" "$ENV{MAX_JOBS}")
endif() endif()
endif() endif()
if(LINUX)
set(ABI_NEUTRAL_FLAGS -fpreview-breaking-changes)
endif()
ExternalProject_Add(xpu_mkldnn_proj ExternalProject_Add(xpu_mkldnn_proj
SOURCE_DIR ${MKLDNN_ROOT} SOURCE_DIR ${MKLDNN_ROOT}
PREFIX ${XPU_MKLDNN_DIR_PREFIX} PREFIX ${XPU_MKLDNN_DIR_PREFIX}
BUILD_IN_SOURCE 0 BUILD_IN_SOURCE 0
CMAKE_ARGS -DCMAKE_C_COMPILER=icx CMAKE_ARGS -DCMAKE_C_COMPILER=icx
-DCMAKE_CXX_COMPILER=${SYCL_CXX_DRIVER} -DCMAKE_CXX_COMPILER=${SYCL_CXX_DRIVER}
-DCMAKE_CXX_FLAGS=${ABI_NEUTRAL_FLAGS}
-DDNNL_GPU_RUNTIME=SYCL -DDNNL_GPU_RUNTIME=SYCL
-DDNNL_CPU_RUNTIME=THREADPOOL -DDNNL_CPU_RUNTIME=THREADPOOL
-DDNNL_BUILD_TESTS=OFF -DDNNL_BUILD_TESTS=OFF

View File

@ -51,7 +51,7 @@ find_file(
# Find SYCL library fullname. # Find SYCL library fullname.
find_library( find_library(
SYCL_LIBRARY SYCL_LIBRARY
NAMES sycl NAMES sycl-preview
HINTS ${SYCL_LIBRARY_DIR} HINTS ${SYCL_LIBRARY_DIR}
NO_DEFAULT_PATH NO_DEFAULT_PATH
) )