Skip to content

Commit 1d2371c

Browse files
authored
Support IPEX ABI=0 build (#4910)
1 parent afe96e8 commit 1d2371c

File tree

7 files changed

+39
-12
lines changed

7 files changed

+39
-12
lines changed

cmake/BuildFlags.cmake

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,9 @@ if(BUILD_MODULE_TYPE STREQUAL "GPU")
1313
endif()
1414

1515
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
16-
if(NOT WINDOWS)
17-
string(REGEX MATCH "-D_GLIBCXX_USE_CXX11_ABI=([0-9]+)" torch_cxx11 ${TORCH_CXX_FLAGS})
18-
set(GLIBCXX_USE_CXX11_ABI ${CMAKE_MATCH_1})
19-
if(BUILD_WITH_XPU AND NOT GLIBCXX_USE_CXX11_ABI)
20-
message(FATAL_ERROR "Must set _GLIBCXX_USE_CXX11_ABI=1 for XPU build, but not is ${GLIBCXX_USE_CXX11_ABI}!")
21-
endif()
16+
if(NOT WINDOWS)
17+
string(REGEX MATCH "-D_GLIBCXX_USE_CXX11_ABI=([0-9]+)" torch_cxx11 ${TORCH_CXX_FLAGS})
18+
set(GLIBCXX_USE_CXX11_ABI ${CMAKE_MATCH_1})
2219
endif()
2320

2421
# Since 2016 Debian start using RUNPATH instead of normally RPATH, which gave the annoy effect that

cmake/Modules/FindoneDNN.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,15 @@ ELSE()
106106
SET(DNNL_ENABLE_CONCURRENT_EXEC TRUE CACHE BOOL "multi-thread primitive execution" FORCE)
107107
SET(DNNL_EXPERIMENTAL TRUE CACHE BOOL "use one pass for oneDNN BatchNorm" FORCE)
108108

109+
IF(LINUX)
110+
set(_original_cmake_cxx_flags "${CMAKE_CXX_FLAGS}")
111+
# Workaround: when use icpx to build oneDNN, -fpreview-breaking-changes has to be explicitly passed.
112+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpreview-breaking-changes")
113+
ENDIF()
109114
ADD_SUBDIRECTORY(${ONEDNN_ROOT} oneDNN EXCLUDE_FROM_ALL)
115+
IF(LINUX)
116+
set(CMAKE_CXX_FLAGS "${_original_cmake_cxx_flags}")
117+
ENDIF()
110118
SET(ONEDNN_LIBRARY ${DNNL_LIBRARY_NAME})
111119
IF(NOT TARGET ${ONEDNN_LIBRARY})
112120
MESSAGE(FATAL_ERROR "Failed to include oneDNN target")

cmake/gpu/SYCL.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ set(IPEX_SYCL_KERNEL_FLAGS ${IPEX_SYCL_KERNEL_FLAGS} -fhonor-nans)
101101
set(IPEX_SYCL_KERNEL_FLAGS ${IPEX_SYCL_KERNEL_FLAGS} -fhonor-infinities)
102102
set(IPEX_SYCL_KERNEL_FLAGS ${IPEX_SYCL_KERNEL_FLAGS} -fno-associative-math)
103103
set(IPEX_SYCL_KERNEL_FLAGS ${IPEX_SYCL_KERNEL_FLAGS} -fno-approx-func)
104+
# It informs compiler to link the ABI-neutral library.
105+
if(LINUX)
106+
set(IPEX_SYCL_KERNEL_FLAGS ${IPEX_SYCL_KERNEL_FLAGS} -fpreview-breaking-changes)
107+
set(IPEX_SYCL_LINK_FLAGS ${IPEX_SYCL_LINK_FLAGS} -fpreview-breaking-changes)
108+
endif()
104109

105110
# Explicitly limit the index range (< Max int32) in kernel
106111
# set(IPEX_SYCL_KERNEL_FLAGS ${IPEX_SYCL_KERNEL_FLAGS} -fsycl-id-queries-fit-in-int)

csrc/gpu/aten/operators/xetla/kernels/compile_library.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ function(add_library_with_options TARGET USE_DOUBLE_GRF AOT_DEVLIST)
66
-fsycl-device-code-split=per_kernel
77
-fsycl-max-parallel-link-jobs=${SYCL_MAX_PARALLEL_LINK_JOBS}
88
)
9+
if(LINUX)
10+
set(XETLA_KERNEL_FLAGS ${XETLA_KERNEL_FLAGS} -fpreview-breaking-changes)
11+
endif()
912

1013
if (AOT_DEVLIST)
1114
set(XETLA_KERNEL_FLAGS ${XETLA_KERNEL_FLAGS} -fsycl-targets=spir64_gen)
@@ -67,6 +70,9 @@ function(add_library_with_options TARGET USE_DOUBLE_GRF AOT_DEVLIST)
6770

6871
target_link_options(${TARGET} PRIVATE ${XETLA_KERNEL_FLAGS})
6972
target_compile_options(${TARGET} PRIVATE -fsycl)
73+
if(LINUX)
74+
target_compile_options(${TARGET} PRIVATE -fpreview-breaking-changes)
75+
endif()
7076
if (AOT_DEVLIST)
7177
target_compile_options(${TARGET} PRIVATE -fsycl-targets=spir64_gen)
7278
endif()

docs/tutorials/known_issues.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Troubleshooting
2121
- **Cause**: DPC++ does not support `_GLIBCXX_USE_CXX11_ABI=0`, Intel® Extension for PyTorch\* is always compiled with `_GLIBCXX_USE_CXX11_ABI=1`. This symbol undefined issue appears when PyTorch\* is
2222
compiled with `_GLIBCXX_USE_CXX11_ABI=0`.
2323
- **Solution**: Pass `export GLIBCXX_USE_CXX11_ABI=1` and compile PyTorch\* with particular compiler which supports `_GLIBCXX_USE_CXX11_ABI=1`. We recommend using prebuilt wheels
24-
in [download server](https:// developer.intel.com/ipex-whl-stable-xpu) to avoid this issue.
24+
in [download server](https:// developer.intel.com/ipex-whl-stable-xpu) to avoid this issue. Please **note** that starting from Intel® Extension for PyTorch\* 2.5, it supports both new and old C++ ABIs. Previously, it only supported the new C++ ABI.
2525
- **Problem**: `-997 runtime error` when running some AI models on Intel® Arc™ A-Series GPUs.
2626
- **Cause**: Some of the `-997 runtime error` are actually out-of-memory errors. As Intel® Arc™ A-Series GPUs have less device memory than Intel® Data Center GPU Flex Series 170 and Intel® Data Center GPU
2727
Max Series, running some AI models on them may trigger out-of-memory errors and cause them to report failure such as `-997 runtime error` most likely. This is expected. Memory usage optimization is a work in progress to allow Intel® Arc™ A-Series GPUs to support more AI models.

examples/gpu/inference/cpp/example-usm/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@ set(target example-usm)
77
add_executable(${target} example-usm.cpp)
88
target_link_libraries(${target} ${TORCH_IPEX_LIBRARIES})
99
list(APPEND CMAKE_CXX_FLAGS "-fsycl")
10+
if(LINUX)
11+
list(APPEND CMAKE_CXX_FLAGS " -fpreview-breaking-changes")
12+
endif()
1013

1114
set_property(TARGET ${target} PROPERTY CXX_STANDARD 17)

intel_extension_for_pytorch/xpu/cpp_extension.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
CLIB_EXT = ".dll" if IS_WINDOWS else ".so"
3434
SHARED_FLAG = "/DLL" if IS_WINDOWS else "-shared"
3535
SYCL_FLAG = "-fsycl"
36+
ABI_FLAG = "-fpreview-breaking-changes" if IS_LINUX else ""
3637

3738
MINIMUM_GCC_VERSION = (5, 0, 0)
3839
MINIMUM_MSVC_VERSION = (19, 0, 24215)
@@ -321,7 +322,7 @@ def _gen_link_lib_cmd_line(
321322

322323
libraries_args = []
323324
libraries_args += [f"-l{x}" for x in libraries]
324-
common_args = [SHARED_FLAG] + [SYCL_FLAG]
325+
common_args = [SHARED_FLAG] + [SYCL_FLAG] + [ABI_FLAG]
325326

326327
"""
327328
link command formats:
@@ -452,7 +453,7 @@ def unix_wrap_ninja_link_shared_object(
452453
# create output directories avoid linker error.
453454
create_parent_dirs_by_path(output_libname)
454455

455-
ldflags = [SHARED_FLAG] + [SYCL_FLAG]
456+
ldflags = [SHARED_FLAG] + [SYCL_FLAG] + [ABI_FLAG]
456457
ldflags += [f"-L{x}" for x in library_dirs]
457458
ldflags += [f"-L{x}" for x in runtime_library_dirs]
458459
ldflags += extra_postargs
@@ -510,7 +511,7 @@ def spawn(cmd):
510511

511512
if "-fPIC" in cflags: # Windows does not support this argument
512513
cflags.remove("-fPIC")
513-
cflags = cflags + ["-std=c++17", SYCL_FLAG]
514+
cflags = cflags + ["-std=c++17", SYCL_FLAG, ABI_FLAG]
514515

515516
cmd = [_bin, "-c", src, "-o", obj] + include_list + cflags
516517
elif isinstance(self.cflags, dict):
@@ -1004,9 +1005,11 @@ def library_paths() -> List[str]:
10041005
def _prepare_compile_flags(extra_compile_args):
10051006
if isinstance(extra_compile_args, List):
10061007
extra_compile_args.append(SYCL_FLAG)
1008+
extra_compile_args.append(ABI_FLAG)
10071009
elif isinstance(extra_compile_args, dict):
10081010
cl_flags = extra_compile_args.get("cxx", [])
10091011
cl_flags.append(SYCL_FLAG)
1012+
cl_flags.append(ABI_FLAG)
10101013
extra_compile_args["cxx"] = cl_flags
10111014

10121015
return extra_compile_args
@@ -1048,7 +1051,7 @@ def _prepare_ldflags(extra_ldflags, verbose, is_standalone):
10481051
oneapi_link_args += ["-Wl,--start-group"]
10491052
oneapi_link_args += [f"{x}" for x in get_one_api_help().get_onemkl_libraries()]
10501053
oneapi_link_args += ["-Wl,--end-group"]
1051-
oneapi_link_args += ["-lsycl", "-lOpenCL", "-lpthread", "-lm", "-ldl"]
1054+
oneapi_link_args += ["-lOpenCL", "-lpthread", "-lm", "-ldl"]
10521055

10531056
# Append IPEX link parameters.
10541057
oneapi_link_args += ["-lintel-ext-pt-gpu"]
@@ -1244,7 +1247,12 @@ def object_file_path(source_file: str) -> str:
12441247
return target
12451248

12461249
objects = [object_file_path(src) for src in sources]
1247-
ldflags = ([] if is_standalone else [SHARED_FLAG]) + [SYCL_FLAG] + extra_ldflags
1250+
ldflags = (
1251+
([] if is_standalone else [SHARED_FLAG])
1252+
+ [SYCL_FLAG]
1253+
+ [ABI_FLAG]
1254+
+ extra_ldflags
1255+
)
12481256

12491257
# The darwin linker needs explicit consent to ignore unresolved symbols.
12501258
if IS_MACOS:

0 commit comments

Comments
 (0)