Skip to content

Commit

Permalink
Add intel-sycl-rt wheel support (#1857)
Browse files Browse the repository at this point in the history
Add support to https://pypi.org/project/intel-sycl-rt/ wheel package
that is described #1717

---------

Signed-off-by: Anatoly Myachev <[email protected]>
Co-authored-by: Anatoly Myachev <[email protected]>
  • Loading branch information
ZzEeKkAa and anmyachev authored Aug 27, 2024
1 parent 1ae2e1e commit b9b1314
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 8 deletions.
9 changes: 8 additions & 1 deletion python/triton/runtime/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ def _build(name, src, srcdir, library_dirs, include_dirs, libraries):
cxx = os.environ.get("CXX")
if cxx is None:
clangpp = shutil.which("clang++")
gxx = shutil.which("g++")
icpx = shutil.which("icpx")
cxx = icpx if icpx is not None else clangpp
cxx = icpx or clangpp or gxx
if cxx is None:
raise RuntimeError("Failed to find C++ compiler. Please specify via CXX environment variable.")
import numpy as np
Expand All @@ -63,6 +64,8 @@ def _build(name, src, srcdir, library_dirs, include_dirs, libraries):
cc_cmd = [cxx]
if icpx is not None:
cc_cmd += ["-fsycl"]
else:
cc_cmd += ["--std=c++17"]
else:
cc_cmd = [cc]

Expand All @@ -71,6 +74,10 @@ def _build(name, src, srcdir, library_dirs, include_dirs, libraries):
cc_cmd += [f'-l{lib}' for lib in libraries]
cc_cmd += [f"-L{dir}" for dir in library_dirs]
cc_cmd += [f"-I{dir}" for dir in include_dirs if dir is not None]

if os.getenv("VERBOSE"):
print(" ".join(cc_cmd))

ret = subprocess.check_call(cc_cmd)
if ret == 0:
return so
Expand Down
64 changes: 57 additions & 7 deletions third_party/intel/backend/driver.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,76 @@
import importlib.metadata
import os
import hashlib
import shutil
import tempfile
from pathlib import Path
from triton.runtime.build import _build
from triton.runtime.cache import get_cache_manager
from triton.backends.compiler import GPUTarget
from triton.backends.driver import DriverBase
from packaging.version import Version
from packaging.specifiers import SpecifierSet

ze_root = os.getenv("ZE_PATH", default="/usr/local")
include_dir = [os.path.join(ze_root, "include")]

oneapi_root = os.getenv("ONEAPI_ROOT")
if oneapi_root:
include_dir += [
os.path.join(oneapi_root, "compiler/latest/include"),
os.path.join(oneapi_root, "compiler/latest/include/sycl")
]

def find_sycl(include_dir: list[str]) -> tuple[list[str], list[str]]:
"""
Looks for the sycl library in known places.
Arguments:
include_dir: list of include directories to pass to compiler.
Returns:
enriched include_dir and library_dir.
Raises:
AssertionError: if library was not found.
"""
library_dir = []
include_dir = include_dir.copy()
assertion_message = ("sycl headers not found, please install `icpx` compiler, "
"or provide `ONEAPI_ROOT` environment "
"or install `intel-sycl-rt>=2025.0.0` wheel")

if shutil.which("icpx"):
# only `icpx` compiler knows where sycl runtime binaries and header files are
return include_dir, library_dir

oneapi_root = os.getenv("ONEAPI_ROOT")
if oneapi_root:
include_dir += [
os.path.join(oneapi_root, "compiler/latest/include"),
os.path.join(oneapi_root, "compiler/latest/include/sycl")
]
return include_dir, library_dir

try:
sycl_rt = importlib.metadata.metadata("intel-sycl-rt")
except importlib.metadata.PackageNotFoundError:
raise AssertionError(assertion_message)

if Version(sycl_rt.get("version", "0.0.0")) in SpecifierSet("<2025.0.0a1"):
raise AssertionError(assertion_message)

for f in importlib.metadata.files("intel-sycl-rt"):
# sycl/sycl.hpp and sycl/CL/sycl.hpp results in both folders
# being add: include and include/sycl.
if f.name == "sycl.hpp":
include_dir += [f.locate().parent.parent.resolve().as_posix()]
if f.name == "libsycl.so":
library_dir += [f.locate().parent.resolve().as_posix()]

return include_dir, library_dir


include_dir, library_dir = find_sycl(include_dir)

dirname = os.path.dirname(os.path.realpath(__file__))
include_dir += [os.path.join(dirname, "include")]

library_dir = [os.path.join(dirname, "lib")]
library_dir += [os.path.join(dirname, "lib")]
libraries = ['ze_loader', 'sycl']


Expand Down

0 comments on commit b9b1314

Please sign in to comment.