Skip to content

Commit 4d8e9bb

Browse files
yudongsianmyachev
andauthored
Fix AOT compilation failed in Test with pip workflow (#3135)
Use g++ instead of icpx when DLE/PTDB/ONEAPI not installed. Information about `sycl` usage in Triton XPU. ![image](https://github.com/user-attachments/assets/4ea4b253-9785-454c-b8df-072b7b7a86bb) --------- Co-authored-by: Anatoly Myachev <[email protected]>
1 parent 4ea9537 commit 4d8e9bb

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

python/test/unit/tools/test_aot.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,16 @@ def kernel(C, A, B, M, N, K,
102102
def gen_kernel_library_xpu(dir, libname):
103103
cpp_files = glob.glob(os.path.join(dir, "*.cpp"))
104104
subprocess.run(
105-
["icpx"] + cpp_files + ["-I", COMPILATION_HELPER.include_dir[0], "-c", "-fsycl", "-fPIC"],
105+
["g++"] + cpp_files + ["-I" + include_dir for include_dir in COMPILATION_HELPER.include_dir] +
106+
["-L" + COMPILATION_HELPER.libsycl_dir, "-c", "-lsycl", "-fPIC"],
106107
check=True,
107108
cwd=dir,
108109
)
109110
o_files = glob.glob(os.path.join(dir, "*.o"))
110111

111-
command = ["icpx", "-fsycl", "-lze_loader", *o_files, "-shared", "-o", libname]
112-
for lib_dir in COMPILATION_HELPER.library_dir:
113-
command.extend(["-L", lib_dir])
114-
if COMPILATION_HELPER.libsycl_dir:
115-
for lib_dir in COMPILATION_HELPER.libsycl_dir:
116-
command.extend(["-L", lib_dir])
117-
subprocess.run(command, check=True, cwd=dir)
112+
subprocess.run(["g++"] + [*o_files, "-shared", "-o", libname] +
113+
["-L" + library_dir for library_dir in COMPILATION_HELPER.library_dir] +
114+
["-L" + COMPILATION_HELPER.libsycl_dir, "-lsycl", "-lze_loader"], check=True, cwd=dir)
118115

119116

120117
def gen_kernel_library(dir, libname):
@@ -297,15 +294,15 @@ def gen_test_bin(dir, M, N, K, exe="test", algo_id=0):
297294
command.extend(["-l", "cuda", "-L", dir, "-l", "kernel", "-o", exe])
298295

299296
if is_xpu():
300-
command = ["icpx", "test.cpp"]
297+
command = ["g++", "test.cpp"]
301298
for inc_dir in COMPILATION_HELPER.include_dir:
302299
command.extend(["-I", inc_dir])
303300
for lib_dir in COMPILATION_HELPER.library_dir:
304301
command.extend(["-L", lib_dir])
305302
if COMPILATION_HELPER.libsycl_dir:
306303
for lib_dir in COMPILATION_HELPER.libsycl_dir:
307304
command.extend(["-L", lib_dir])
308-
command.extend(["-fsycl", "-lze_loader", "-L", dir, "-l", "kernel", "-o", exe])
305+
command.extend(["-lsycl", "-lze_loader", "-L", dir, "-l", "kernel", "-o", exe])
309306
subprocess.run(command, check=True, cwd=dir)
310307

311308

third_party/intel/backend/driver.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66
import tempfile
77
from pathlib import Path
88
from functools import cached_property
9-
from typing import Optional
109

1110
from triton.runtime.build import _build
1211
from triton.runtime.cache import get_cache_manager
1312
from triton.backends.compiler import GPUTarget
1413
from triton.backends.driver import DriverBase
1514

1615

17-
def find_sycl(include_dir: list[str]) -> tuple[list[str], Optional[str]]:
16+
def find_sycl(include_dir: list[str]) -> tuple[list[str], str]:
1817
"""
1918
Looks for the sycl library in known places.
2019
@@ -28,21 +27,26 @@ def find_sycl(include_dir: list[str]) -> tuple[list[str], Optional[str]]:
2827
AssertionError: if library was not found.
2928
"""
3029
include_dir = include_dir.copy()
30+
sycl_dir = None
3131
assertion_message = ("sycl headers not found, please install `icpx` compiler, "
3232
"or provide `ONEAPI_ROOT` environment "
3333
"or install `intel-sycl-rt>=2025.0.0` wheel")
34-
35-
if shutil.which("icpx") and os.name != "nt":
34+
icpx_path = shutil.which("icpx")
35+
if icpx_path and os.name != "nt":
3636
# only `icpx` compiler knows where sycl runtime binaries and header files are
37-
return include_dir, None
37+
compiler_root = os.path.abspath(f"{icpx_path}/../..")
38+
include_dir += [os.path.join(compiler_root, "include"), os.path.join(compiler_root, "include/sycl")]
39+
sycl_dir = os.path.join(compiler_root, "lib")
40+
return include_dir, sycl_dir
3841

3942
oneapi_root = os.getenv("ONEAPI_ROOT")
4043
if oneapi_root:
4144
include_dir += [
4245
os.path.join(oneapi_root, "compiler/latest/include"),
4346
os.path.join(oneapi_root, "compiler/latest/include/sycl")
4447
]
45-
return include_dir, None
48+
sycl_dir = os.path.join(oneapi_root, "compiler/latest/lib"),
49+
return include_dir, sycl_dir
4650

4751
try:
4852
sycl_rt = importlib.metadata.metadata("intel-sycl-rt")
@@ -52,7 +56,6 @@ def find_sycl(include_dir: list[str]) -> tuple[list[str], Optional[str]]:
5256
if sycl_rt.get("version", "0.0.0").startswith("2024"):
5357
raise AssertionError(assertion_message)
5458

55-
sycl_dir = None
5659
for f in importlib.metadata.files("intel-sycl-rt"):
5760
# sycl/sycl.hpp and sycl/CL/sycl.hpp results in both folders
5861
# being add: include and include/sycl.
@@ -122,7 +125,7 @@ def include_dir(self) -> list[str]:
122125
return self._include_dir
123126

124127
@cached_property
125-
def libsycl_dir(self) -> Optional[str]:
128+
def libsycl_dir(self) -> str:
126129
self._compute_compilation_options_lazy
127130
return self._libsycl_dir
128131

0 commit comments

Comments
 (0)