Skip to content

Commit e89a6f7

Browse files
authored
Build PTI wheels from sources (#5383)
The current method we agreed on with the PTI team is to copy the files (which are necessary for building the wheels and which are currently in `build_pti_data` folder) from their internal repo, since they currently do not plan to opensource these files. The current way to install dev pti and use it for Proton (I'll try to simplify it in the future): ```bash ./scripts/install-pti.sh --build-level-zero PTI_LIBS_DIR=$(python ./scripts/pti_lib.py) export LD_LIBRARY_PATH=${{ env.PTI_LIBS_DIR }}:$LD_LIBRARY_PATH ``` --------- Signed-off-by: Anatoly Myachev <[email protected]>
1 parent a39c5c1 commit e89a6f7

File tree

7 files changed

+240
-16
lines changed

7 files changed

+240
-16
lines changed

.github/workflows/build-test-reusable.yml

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ jobs:
127127
DEBUG=1
128128
python -m build --wheel --no-isolation && pip install dist/*.whl
129129
130+
- name: Build PTI
131+
run: |
132+
./scripts/install-pti.sh --build-level-zero
133+
130134
- name: Set test-triton command line
131135
id: test-triton
132136
run: |
@@ -175,6 +179,12 @@ jobs:
175179
name: triton-${{ inputs.python_version }}-${{ inputs.runner_label || inputs.driver_version }}
176180
path: dist/*.whl
177181

182+
- name: Upload PTI wheels
183+
uses: actions/upload-artifact@v4
184+
with:
185+
name: pti-${{ inputs.python_version }}-${{ inputs.runner_label || inputs.driver_version }}
186+
path: .scripts_cache/pti/dist/*.whl
187+
178188
- name: Upload test reports
179189
uses: actions/upload-artifact@v5
180190
with:
@@ -242,11 +252,23 @@ jobs:
242252
with:
243253
name: triton-${{ inputs.python_version }}-${{ inputs.runner_label || inputs.driver_version }}
244254

255+
- name: Download PTI wheels
256+
uses: actions/download-artifact@v5
257+
with:
258+
name: pti-${{ inputs.python_version }}-${{ inputs.runner_label || inputs.driver_version }}
259+
245260
- name: Install Triton
246261
run: |
247262
pip install triton-*.whl
248263
python -c 'import triton; print(triton.__version__)'
249264
265+
- name: Install PTI
266+
run: |
267+
pip install intel_pti-*.whl
268+
PTI_LIBS_DIR=$(python ./scripts/pti_lib.py)
269+
ls $PTI_LIBS_DIR
270+
echo "PTI_LIBS_DIR=$PTI_LIBS_DIR" | tee -a $GITHUB_ENV
271+
250272
- name: Report environment details
251273
run: |
252274
if [ "${{ matrix.suite }}" == "minicore" ]; then
@@ -283,21 +305,7 @@ jobs:
283305
- name: Build PTI && Run Proton tests
284306
if: matrix.suite == 'rest'
285307
run: |
286-
# `intel-pti` can be installed in "Setup PyTorch" step with `pytorch_mode==wheels`
287-
pip uninstall intel-pti -y
288-
PTI_COMMIT_ID="$(<.github/pins/pti.txt)"
289-
git clone https://github.com/intel/pti-gpu.git
290-
cd pti-gpu
291-
git checkout $PTI_COMMIT_ID
292-
cd sdk
293-
cmake --preset linux-icpx-release
294-
BUILD_TESTING=1 PTI_BUILD_SAMPLES=1 cmake --build --preset linux-icpx-release
295-
296-
PTI_LIBS_DIR="$(pwd)/build-linux-icpx-release/lib/"
297-
cd ../..
298-
299-
export LD_LIBRARY_PATH=$PTI_LIBS_DIR:$LD_LIBRARY_PATH
300-
export TRITON_XPUPTI_LIB_PATH=$PTI_LIBS_DIR
308+
export LD_LIBRARY_PATH=${{ env.PTI_LIBS_DIR }}:$LD_LIBRARY_PATH
301309
cd third_party/proton/test
302310
pytest test_api.py test_cmd.py test_lib.py test_profile.py test_viewer.py --device xpu -s -v
303311
cd ..
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
cmake_minimum_required(VERSION 3.20)
2+
3+
project(
4+
pti-python-binaries
5+
VERSION 0.0.1
6+
LANGUAGES C CXX)
7+
8+
include(FetchContent)
9+
10+
if(DEFINED ENV{PTI_PINNED_COMMIT})
11+
set(PTI_PINNED_COMMIT $ENV{PTI_PINNED_COMMIT})
12+
else()
13+
message(FATAL_ERROR "PTI_PINNED_COMMIT env var not defined")
14+
endif()
15+
16+
if(DEFINED ENV{LEVELZERO_INCLUDE_DIR})
17+
set(LevelZero_INCLUDE_DIR "$ENV{LEVELZERO_INCLUDE_DIR}")
18+
else()
19+
message(STATUS "LEVELZERO_INCLUDE_DIR env var not defined; try to use system version")
20+
endif()
21+
22+
if(DEFINED ENV{LEVELZERO_LIBRARY})
23+
set(LevelZero_LIBRARY "$ENV{LEVELZERO_LIBRARY}")
24+
else()
25+
message(STATUS "LEVELZERO_LIBRARY env var not defined; try to use system version")
26+
endif()
27+
28+
FetchContent_Declare(
29+
pti-lib
30+
GIT_REPOSITORY https://github.com/intel/pti-gpu.git
31+
GIT_TAG ${PTI_PINNED_COMMIT}
32+
SOURCE_SUBDIR sdk
33+
)
34+
35+
if(NOT APPLE)
36+
list(APPEND CMAKE_INSTALL_RPATH $ORIGIN)
37+
endif()
38+
39+
# Sets the installation directories to be inside the root of the virtual
40+
# environment, .e.g., .venv/lib/libpti_view.so (note: this is non-standard).
41+
# However, this is what other oneAPI components and PyTorch XPU (Intel backend)
42+
# expects.
43+
set(CMAKE_INSTALL_LIBDIR "${SKBUILD_DATA_DIR}/lib")
44+
set(CMAKE_INSTALL_INCLUDEDIR "${SKBUILD_DATA_DIR}/include")
45+
set(CMAKE_INSTALL_BINDIR "${SKBUILD_DATA_DIR}/bin")
46+
set(CMAKE_INSTALL_DOCDIR "${SKBUILD_DATA_DIR}/share")
47+
48+
49+
FetchContent_MakeAvailable(pti-lib)

scripts/build_pti_data/README.md

Whitespace-only changes.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
[project]
2+
name = "intel-pti"
3+
version = "0.14.0.dev1"
4+
description = "Add your description here"
5+
readme = "README.md"
6+
license = "MIT"
7+
8+
requires-python = ">=3.9"
9+
dependencies = []
10+
classifiers = [
11+
"Development Status :: 5 - Production/Stable",
12+
13+
# Indicate who your project is intended for
14+
"Intended Audience :: Developers",
15+
"Intended Audience :: Education",
16+
"Intended Audience :: Science/Research",
17+
"Intended Audience :: System Administrators",
18+
"Intended Audience :: Other Audience",
19+
20+
"Topic :: Software Development :: Libraries",
21+
22+
"Operating System :: Microsoft :: Windows",
23+
"Operating System :: POSIX :: Linux",
24+
25+
"Environment :: GPU",
26+
]
27+
28+
[tool.scikit-build]
29+
build.verbose = true
30+
logging.level = "INFO"
31+
cmake.version = ">=3.20.0"
32+
cmake.build-type = "Release"
33+
cmake.args = ["-GNinja"]
34+
ninja.version = ">=1.13"
35+
minimum-version = "build-system.requires"
36+
sdist.exclude = ["levelzero", "level-zero", "src"]
37+
38+
[tool.uv]
39+
cache-keys = [{ file = "pyproject.toml" }, { file = "CMakeLists.txt" }]
40+
41+
[build-system]
42+
requires = ["scikit-build-core>=0.10"]
43+
build-backend = "scikit_build_core.build"
44+
45+
[project.urls]
46+
Homepage = "https://github.com/intel/pti-gpu/tree/master/sdk"
47+
Documentation = "https://github.com/intel/pti-gpu/blob/master/sdk/README.md"
48+
Repository = "https://github.com/intel/pti-gpu"
49+
Issues = "https://github.com/intel/pti-gpu/issues"

scripts/install-pti.sh

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
# Select what to build.
6+
BUILD_LEVEL_ZERO=false
7+
for arg in "$@"; do
8+
case $arg in
9+
--build-level-zero)
10+
BUILD_LEVEL_ZERO=true
11+
shift
12+
;;
13+
--help)
14+
echo "Example usage: ./install-pti.sh [--build-level-zero]"
15+
exit 1
16+
;;
17+
*)
18+
echo "Unknown argument: $arg."
19+
exit 1
20+
;;
21+
esac
22+
done
23+
24+
25+
# Configure, build and install PyTorch from source.
26+
27+
# intel-xpu-backend-for-triton project root
28+
ROOT=$(cd "$(dirname "$0")/.." && pwd)
29+
30+
SCRIPTS_DIR=$ROOT/scripts
31+
PTI_PROJ=$ROOT/.scripts_cache/pti
32+
LEVEL_ZERO_PROJ=$ROOT/.scripts_cache/level_zero_for_pti
33+
BASE=$(dirname "$PTI_PROJ")
34+
35+
echo "**** BASE is set to $BASE ****"
36+
echo "**** PTI_PROJ is set to $PTI_PROJ ****"
37+
mkdir -p $BASE
38+
39+
function build_level_zero {
40+
rm -rf "$LEVEL_ZERO_PROJ"
41+
mkdir -p "$LEVEL_ZERO_PROJ"
42+
cd "$LEVEL_ZERO_PROJ"
43+
LEVEL_ZERO_VERSION=1.24.2
44+
LEVEL_ZERO_SHA256=b77e6e28623134ee4e99e2321c127b554bdd5bfa3e80064922eba293041c6c52
45+
46+
wget --progress=dot:giga -e use_proxy=yes "https://github.com/oneapi-src/level-zero/archive/refs/tags/v${LEVEL_ZERO_VERSION}.tar.gz"
47+
echo "${LEVEL_ZERO_SHA256} v${LEVEL_ZERO_VERSION}.tar.gz" > "v${LEVEL_ZERO_VERSION}.tar.gz.sha256"
48+
sha256sum -c "v${LEVEL_ZERO_VERSION}.tar.gz.sha256"
49+
tar -xf "v${LEVEL_ZERO_VERSION}.tar.gz"
50+
cd "level-zero-${LEVEL_ZERO_VERSION}"
51+
echo "${LEVEL_ZERO_VERSION}" | awk -F. '{print $3}' > VERSION_PATCH
52+
mkdir build
53+
cd build
54+
cmake .. -DCMAKE_BUILD_TYPE=Release
55+
cmake --build . --config Release --parallel "$(nproc)"
56+
# cmake --build . --config Release --target install
57+
export LEVELZERO_INCLUDE_DIR="$LEVEL_ZERO_PROJ/level-zero-${LEVEL_ZERO_VERSION}"
58+
export LEVELZERO_LIBRARY="$LEVEL_ZERO_PROJ/level-zero-${LEVEL_ZERO_VERSION}/build/lib/libze_loader.so"
59+
}
60+
61+
function build_pti {
62+
rm -rf "$PTI_PROJ"
63+
mkdir -p "$PTI_PROJ"
64+
65+
echo "****** Building $PTI_PROJ ******"
66+
cd "$PTI_PROJ"
67+
cp "$SCRIPTS_DIR"/build_pti_data/* .
68+
pip install uv
69+
70+
export PTI_PINNED_COMMIT="$(<$ROOT/.github/pins/pti.txt)"
71+
72+
uv version 0.14.0.dev1
73+
uv build
74+
}
75+
76+
function install_pti {
77+
echo "****** Installing PTI ******"
78+
cd "$PTI_PROJ"
79+
pip install dist/*.whl
80+
}
81+
82+
if [ "$BUILD_LEVEL_ZERO" = true ]; then
83+
build_level_zero
84+
fi
85+
86+
build_pti
87+
install_pti

scripts/pti_lib.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""Prints a lib directory for pti."""
2+
3+
import importlib.metadata
4+
import pathlib
5+
6+
7+
def get_pti_lib_path() -> pathlib.Path:
8+
"""Returns library path for pti.
9+
10+
Raises:
11+
importlib.metadata.PackageNotFoundError: if 'intel-pti' not installed.
12+
AssertionError: if libpti_view.so not found.
13+
"""
14+
files = importlib.metadata.files('intel-pti') or []
15+
for f in files:
16+
if f.name == 'libpti_view.so':
17+
return pathlib.Path(f.locate()).parent.resolve()
18+
raise AssertionError('libpti_view.so not found')
19+
20+
21+
if __name__ == '__main__':
22+
print(get_pti_lib_path())

third_party/proton/proton/profile.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
from typing import Optional, Union
2+
import importlib.metadata
3+
import pathlib
4+
import os
15
import functools
26
import triton
37

@@ -6,7 +10,6 @@
610
from .flags import flags
711
from .hooks import HookManager, LaunchHook, InstrumentationHook
812
from .mode import BaseMode
9-
from typing import Optional, Union
1013

1114
DEFAULT_PROFILE_NAME = "proton"
1215
UTILS_CACHE_PATH = None
@@ -21,6 +24,12 @@ def _select_backend() -> str:
2124
elif backend == "xpu":
2225
global UTILS_CACHE_PATH
2326
UTILS_CACHE_PATH = triton.runtime.driver.active.build_proton_help_lib()
27+
files = importlib.metadata.files('intel-pti')
28+
if files is not None:
29+
for f in files:
30+
if f.name == 'libpti_view.so':
31+
os.environ["TRITON_XPUPTI_LIB_PATH"] = str(pathlib.Path(f.locate()).parent.resolve())
32+
break
2433
return "xpupti"
2534
else:
2635
raise ValueError("No backend is available for the current target.")

0 commit comments

Comments
 (0)