mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
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:
committed by
PyTorch MergeBot
parent
997f64af38
commit
92bebb46fa
@ -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
|
||||
```
|
||||
|
||||
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:
|
||||
```bash
|
||||
# Only run this if you're compiling for ROCm
|
||||
|
@ -30,21 +30,21 @@ set(C10_XPU_HEADERS
|
||||
impl/XPUGuardImpl.h
|
||||
)
|
||||
if(NOT BUILD_LIBTORCHLESS)
|
||||
add_library(c10_xpu ${C10_XPU_SRCS} ${C10_XPU_HEADERS})
|
||||
target_compile_options(c10_xpu PRIVATE "-DC10_XPU_BUILD_MAIN_LIB")
|
||||
# Enable hidden visibility if compiler supports it.
|
||||
if(${COMPILER_SUPPORTS_HIDDEN_VISIBILITY})
|
||||
target_compile_options(c10_xpu PRIVATE "-fvisibility=hidden")
|
||||
endif()
|
||||
add_library(c10_xpu ${C10_XPU_SRCS} ${C10_XPU_HEADERS})
|
||||
target_compile_options(c10_xpu PRIVATE "-DC10_XPU_BUILD_MAIN_LIB")
|
||||
# Enable hidden visibility if compiler supports it.
|
||||
if(${COMPILER_SUPPORTS_HIDDEN_VISIBILITY})
|
||||
target_compile_options(c10_xpu PRIVATE "-fvisibility=hidden")
|
||||
endif()
|
||||
|
||||
# ---[ Dependency of c10_xpu
|
||||
target_link_libraries(c10_xpu PUBLIC c10 torch::xpurt)
|
||||
target_include_directories(
|
||||
c10_xpu PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../..>
|
||||
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
)
|
||||
# ---[ Dependency of c10_xpu
|
||||
target_link_libraries(c10_xpu PUBLIC c10 torch::xpurt)
|
||||
target_include_directories(
|
||||
c10_xpu PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../..>
|
||||
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
)
|
||||
install(TARGETS c10_xpu EXPORT Caffe2Targets DESTINATION lib)
|
||||
set(C10_XPU_LIB c10_xpu)
|
||||
add_subdirectory(test)
|
||||
|
@ -90,6 +90,10 @@ if(USE_XPU)
|
||||
message(WARNING "Not compiling with XPU. Could NOT find SYCL."
|
||||
"Suppress this warning with -DUSE_XPU=OFF.")
|
||||
caffe2_update_option(USE_XPU OFF)
|
||||
else()
|
||||
if(LINUX)
|
||||
string(APPEND CMAKE_CXX_FLAGS " -D__INTEL_PREVIEW_BREAKING_CHANGES")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
@ -36,18 +36,22 @@ IF(NOT MKLDNN_FOUND)
|
||||
set(DNNL_MAKE_COMMAND "cmake" "--build" ".")
|
||||
include(ProcessorCount)
|
||||
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}")
|
||||
if(CMAKE_GENERATOR MATCHES "Make|Ninja")
|
||||
list(APPEND DNNL_MAKE_COMMAND "--" "-l" "$ENV{MAX_JOBS}")
|
||||
endif()
|
||||
endif()
|
||||
if(LINUX)
|
||||
set(ABI_NEUTRAL_FLAGS -fpreview-breaking-changes)
|
||||
endif()
|
||||
ExternalProject_Add(xpu_mkldnn_proj
|
||||
SOURCE_DIR ${MKLDNN_ROOT}
|
||||
PREFIX ${XPU_MKLDNN_DIR_PREFIX}
|
||||
BUILD_IN_SOURCE 0
|
||||
CMAKE_ARGS -DCMAKE_C_COMPILER=icx
|
||||
-DCMAKE_CXX_COMPILER=${SYCL_CXX_DRIVER}
|
||||
-DCMAKE_CXX_FLAGS=${ABI_NEUTRAL_FLAGS}
|
||||
-DDNNL_GPU_RUNTIME=SYCL
|
||||
-DDNNL_CPU_RUNTIME=THREADPOOL
|
||||
-DDNNL_BUILD_TESTS=OFF
|
||||
|
@ -51,7 +51,7 @@ find_file(
|
||||
# Find SYCL library fullname.
|
||||
find_library(
|
||||
SYCL_LIBRARY
|
||||
NAMES sycl
|
||||
NAMES sycl-preview
|
||||
HINTS ${SYCL_LIBRARY_DIR}
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
|
Reference in New Issue
Block a user