Skip to content

Commit ec9987d

Browse files
pruthvistonypragupta
authored andcommitted
CONSOLIDATED COMMITS: Triton build updates
========================================== Triton build conditionalized on ROCM_VERSION Include the ROCm version in triton version (cherry picked from commit 7d33910) (cherry picked from commit 0412eb4) Update triton-rocm.txt to triton.txt (cherry picked from commit 0ce9f6e) Use ROCm/triton for install_triton.sh (cherry picked from commit 6e9714b) update triton commit Revert "Use ROCm/triton for install_triton.sh" This reverts commit 81b0cbc. change triton repo Update triton.txt to use release/internal/3.3.x branch Use ROCm/triton Use ROCm/triton for install_triton.sh (cherry picked from commit 0036db5)
1 parent b97cff1 commit ec9987d

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

.ci/docker/common/install_triton.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ elif [ -n "${TRITON_CPU}" ]; then
2121
TRITON_REPO="https://github.com/triton-lang/triton-cpu"
2222
TRITON_TEXT_FILE="triton-cpu"
2323
else
24-
TRITON_REPO="https://github.com/triton-lang/triton"
24+
TRITON_REPO="https://github.com/ROCm/triton"
2525
TRITON_TEXT_FILE="triton"
2626
fi
2727

.github/scripts/build_triton_wheel.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
22

33
import os
4+
import re
45
import shutil
56
import sys
67
from pathlib import Path
@@ -50,6 +51,31 @@ def patch_init_py(
5051
with open(path, "w") as f:
5152
f.write(orig)
5253

54+
def get_rocm_version() -> str:
55+
rocm_path = os.environ.get('ROCM_HOME') or os.environ.get('ROCM_PATH') or "/opt/rocm"
56+
rocm_version = "0.0.0"
57+
rocm_version_h = f"{rocm_path}/include/rocm-core/rocm_version.h"
58+
if not os.path.isfile(rocm_version_h):
59+
rocm_version_h = f"{rocm_path}/include/rocm_version.h"
60+
61+
# The file could be missing due to 1) ROCm version < 5.2, or 2) no ROCm install.
62+
if os.path.isfile(rocm_version_h):
63+
RE_MAJOR = re.compile(r"#define\s+ROCM_VERSION_MAJOR\s+(\d+)")
64+
RE_MINOR = re.compile(r"#define\s+ROCM_VERSION_MINOR\s+(\d+)")
65+
RE_PATCH = re.compile(r"#define\s+ROCM_VERSION_PATCH\s+(\d+)")
66+
major, minor, patch = 0, 0, 0
67+
for line in open(rocm_version_h):
68+
match = RE_MAJOR.search(line)
69+
if match:
70+
major = int(match.group(1))
71+
match = RE_MINOR.search(line)
72+
if match:
73+
minor = int(match.group(1))
74+
match = RE_PATCH.search(line)
75+
if match:
76+
patch = int(match.group(1))
77+
rocm_version = str(major)+"."+str(minor)+"."+str(patch)
78+
return rocm_version
5379

5480
def build_triton(
5581
*,
@@ -65,13 +91,22 @@ def build_triton(
6591
max_jobs = os.cpu_count() or 1
6692
env["MAX_JOBS"] = str(max_jobs)
6793

94+
version_suffix = ""
95+
if not release:
96+
# Nightly binaries include the triton commit hash, i.e. 2.1.0+e6216047b8
97+
# while release build should only include the version, i.e. 2.1.0
98+
rocm_version = get_rocm_version()
99+
version_suffix = f"+rocm{rocm_version}_{commit_hash[:10]}"
100+
version += version_suffix
101+
68102
with TemporaryDirectory() as tmpdir:
69103
triton_basedir = Path(tmpdir) / "triton"
70104
triton_pythondir = triton_basedir / "python"
71105

72106
triton_repo = "https://github.com/openai/triton"
73107
if device == "rocm":
74108
triton_pkg_name = "pytorch-triton-rocm"
109+
triton_repo = "https://github.com/ROCm/triton/"
75110
elif device == "xpu":
76111
triton_pkg_name = "pytorch-triton-xpu"
77112
triton_repo = "https://github.com/intel/intel-xpu-backend-for-triton"
@@ -104,6 +139,8 @@ def build_triton(
104139
cwd=triton_basedir,
105140
shell=True,
106141
)
142+
cur_rocm_ver = get_rocm_version()
143+
check_call(["scripts/amd/setup_rocm_libs.sh", cur_rocm_ver], cwd=triton_basedir)
107144
print("ROCm libraries setup for triton installation...")
108145

109146
# old triton versions have setup.py in the python/ dir,

0 commit comments

Comments
 (0)