-
Notifications
You must be signed in to change notification settings - Fork 8
[Feature] Support environments built by TheRock build system #172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
960425f
274f5cc
8d63dba
03b9ac2
871f978
6d2c37a
1909936
d5e9691
11d49d0
0bd52f3
fd189e5
66c6897
d47465c
a4e946c
6b9be8d
1810bf5
4a70dff
9aaec3c
e2c89ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,40 +6,123 @@ | |
| FLASHINFER_SUPPORTED_ROCM_ARCHS = ["gfx942"] | ||
|
|
||
|
|
||
| def get_system_rocm_version(): | ||
| def get_rocm_home(): | ||
| """ | ||
| Attempt to detect the system ROCm version. | ||
| Get the ROCM_HOME directory from environment variables or default path. | ||
|
|
||
| Returns: | ||
| str: ROCm version like "6.4" or "7.0", or None if not detectable | ||
| str: Path to ROCm installation (e.g., "/opt/rocm") | ||
| """ | ||
| import os | ||
| import re | ||
| import subprocess | ||
|
|
||
| # Method 1: Try /opt/rocm/.info/version (most reliable) | ||
| rocm_path = os.environ.get("ROCM_PATH", "/opt/rocm") | ||
| version_file = os.path.join(rocm_path, ".info", "version") | ||
| return os.environ.get("ROCM_PATH") or os.environ.get("ROCM_HOME") or "/opt/rocm" | ||
|
|
||
|
|
||
| def is_therock_build() -> bool: | ||
| """ | ||
| Check if ROCm was built using TheRock build system. | ||
|
|
||
| Returns: | ||
| bool: True if TheRock build is detected, False otherwise | ||
| """ | ||
| import os | ||
|
|
||
| # First, try checking for rocm_sdk package | ||
| try: | ||
| import rocm_sdk | ||
|
|
||
| if hasattr(rocm_sdk, "__version__") and rocm_sdk.__version__: | ||
| return True | ||
| except ImportError: | ||
| pass | ||
|
|
||
| # Fall back to checking for TheRock manifest file | ||
| rocm_home = get_rocm_home() | ||
|
eppaneamd marked this conversation as resolved.
|
||
| manifest_path = os.path.join(rocm_home, "share", "therock", "therock_manifest.json") | ||
| return os.path.isfile(manifest_path) | ||
|
|
||
|
|
||
| def get_system_rocm_version_from_info_file(): | ||
| """ | ||
| Try to get ROCm version from .info/version file located in ROCM_HOME. | ||
|
|
||
| Returns: | ||
| str: ROCm version like "7.1.0" or None if not found | ||
| """ | ||
| import os | ||
|
|
||
| rocm_home = get_rocm_home() | ||
| version_file = os.path.join(rocm_home, ".info", "version") | ||
|
eppaneamd marked this conversation as resolved.
|
||
| try: | ||
| with open(version_file, "r") as f: | ||
| version = f.read().strip() | ||
| return ".".join(version.split(".")[:3]) | ||
| except (FileNotFoundError, IOError): | ||
| return None | ||
|
|
||
|
|
||
| def get_system_rocm_version_from_hipconfig(): | ||
| """ | ||
| Try to get ROCm version from hipconfig --version command. | ||
|
|
||
| Returns: | ||
| str: ROCm version like "7.1.0" or None if not found | ||
| """ | ||
| import re | ||
| import subprocess | ||
|
|
||
| try: | ||
| result = subprocess.run( | ||
| ["hipconfig", "--version"], | ||
| capture_output=True, | ||
| text=True, | ||
| timeout=5, | ||
| check=False, | ||
| ) | ||
| if result.returncode == 0: | ||
| match = re.search(r"(\d+\.\d+\.\d+)", result.stdout) | ||
| if match: | ||
| return match.group(1) | ||
| except (subprocess.TimeoutExpired, FileNotFoundError): | ||
| pass | ||
|
|
||
| # Method 2: Try amd-smi command | ||
| return None | ||
|
|
||
|
|
||
| def get_system_rocm_version_from_amd_smi(): | ||
| """ | ||
| Try to get ROCm version from amd-smi command. | ||
|
|
||
| Returns: | ||
| str: ROCm version like "7.1.0" or None if not found | ||
| """ | ||
| import re | ||
| import subprocess | ||
|
|
||
| try: | ||
| result = subprocess.run( | ||
| ["amd-smi"], capture_output=True, text=True, timeout=5, check=False | ||
| ) | ||
| if result.returncode == 0: | ||
| match = re.search(r"ROCm version:\s*(\d+\.\d+\.\d)", result.stdout) | ||
| match = re.search(r"ROCm version:\s*(\d+\.\d+\.\d+)", result.stdout) | ||
| if match: | ||
| return match.group(1) | ||
| except (subprocess.TimeoutExpired, FileNotFoundError): | ||
| pass | ||
|
|
||
| # Method 3: Try dpkg (Ubuntu/Debian) | ||
| return None | ||
|
|
||
|
|
||
| def get_system_rocm_version_from_dpkg(): | ||
| """ | ||
| Try to get ROCm version from dpkg (Ubuntu/Debian package manager). | ||
|
|
||
| Returns: | ||
| str: ROCm version like "7.1.0" or None if not found | ||
| """ | ||
| import re | ||
| import subprocess | ||
|
|
||
| try: | ||
| result = subprocess.run( | ||
| ["dpkg", "-l", "rocm-core"], | ||
|
|
@@ -49,7 +132,7 @@ def get_system_rocm_version(): | |
| check=False, | ||
| ) | ||
| if result.returncode == 0: | ||
| match = re.search(r"rocm-core\s+(\d+\.\d+\.\d)", result.stdout) | ||
| match = re.search(r"rocm-core\s+(\d+\.\d+\.\d+)", result.stdout) | ||
| if match: | ||
| return match.group(1) | ||
| except (subprocess.TimeoutExpired, FileNotFoundError): | ||
|
|
@@ -58,6 +141,37 @@ def get_system_rocm_version(): | |
| return None | ||
|
|
||
|
|
||
| def get_system_rocm_version(): | ||
| """ | ||
| Attempt to detect the system ROCm version. | ||
|
|
||
| For standard builds, tries methods in order of reliability. | ||
| For TheRock builds, prioritizes hipconfig as it's more reliable. | ||
|
|
||
| Returns: | ||
| str: ROCm version like "7.1.0" or None if not detectable | ||
| """ | ||
| # For TheRock builds, prioritize hipconfig | ||
| if is_therock_build(): | ||
| return get_system_rocm_version_from_hipconfig() | ||
|
eppaneamd marked this conversation as resolved.
eppaneamd marked this conversation as resolved.
|
||
|
|
||
| # Try standard detection methods in order of reliability | ||
| detection_methods = [ | ||
| get_system_rocm_version_from_info_file, | ||
| get_system_rocm_version_from_amd_smi, | ||
| get_system_rocm_version_from_dpkg, | ||
| get_system_rocm_version_from_hipconfig, | ||
| ] | ||
|
|
||
| for method in detection_methods: | ||
| version = method() | ||
| if version: | ||
| return version | ||
| print(f"ROCm version not found using {method.__name__}. Trying next method...") | ||
|
eppaneamd marked this conversation as resolved.
|
||
|
|
||
|
eppaneamd marked this conversation as resolved.
|
||
| return None | ||
|
|
||
|
|
||
|
Comment on lines
+169
to
+174
|
||
| def validate_rocm_arch(arch_list: str = None, verbose: bool = False) -> str: | ||
| """ | ||
| Validate ROCm architecture against system ROCm version. | ||
|
|
@@ -77,42 +191,33 @@ def validate_rocm_arch(arch_list: str = None, verbose: bool = False) -> str: | |
|
|
||
| # ROCm compatibility matrix: version -> supported gfx architectures | ||
| # Refer: https://rocm.docs.amd.com/en/latest/compatibility/compatibility-matrix.html | ||
| # https://github.com/ROCm/TheRock/blob/main/SUPPORTED_GPUS.md#rocm-on-linux | ||
| # Update lists for adding or removing a version or arch | ||
| # Add new tuple for adding a new version group | ||
| _ROCM_ARCH_GROUPS = [ | ||
| ( | ||
| ["7.3", "7.2", "7.1", "7.0"], | ||
| [ | ||
| "gfx950", | ||
| "gfx1201", | ||
| "gfx1200", | ||
| "gfx1101", | ||
| "gfx1100", | ||
| "gfx1030", | ||
| "gfx942", | ||
| "gfx90a", | ||
| "gfx908", | ||
| ], | ||
| ), | ||
| ( | ||
| ["6.4", "6.3"], | ||
| ["gfx1100", "gfx1030", "gfx942", "gfx90a", "gfx908"], | ||
| ), | ||
| ] | ||
|
eppaneamd marked this conversation as resolved.
|
||
|
|
||
| # Build the compatibility matrix | ||
| ROCM_COMPAT_MATRIX = { | ||
| "7.2": [ | ||
| "gfx950", | ||
| "gfx1201", | ||
| "gfx1200", | ||
| "gfx1101", | ||
| "gfx1100", | ||
| "gfx1030", | ||
| "gfx942", | ||
| "gfx90a", | ||
| "gfx908", | ||
| ], | ||
| "7.1": [ | ||
| "gfx950", | ||
| "gfx1201", | ||
| "gfx1200", | ||
| "gfx1101", | ||
| "gfx1100", | ||
| "gfx1030", | ||
| "gfx942", | ||
| "gfx90a", | ||
| "gfx908", | ||
| ], | ||
| "7.0": [ | ||
| "gfx950", | ||
| "gfx1201", | ||
| "gfx1200", | ||
| "gfx1101", | ||
| "gfx1100", | ||
| "gfx1030", | ||
| "gfx942", | ||
| "gfx90a", | ||
| "gfx908", | ||
| ], | ||
| "6.4": ["gfx1100", "gfx1030", "gfx942", "gfx90a", "gfx908"], | ||
| "6.3": ["gfx1100", "gfx1030", "gfx942", "gfx90a", "gfx908"], | ||
| version: archs for versions, archs in _ROCM_ARCH_GROUPS for version in versions | ||
| } | ||
|
|
||
| # Get architecture list from parameter, env var, or default | ||
|
|
@@ -124,7 +229,7 @@ def validate_rocm_arch(arch_list: str = None, verbose: bool = False) -> str: | |
| if system_rocm_version is None: | ||
| raise RuntimeError( | ||
| "Could not detect ROCm installation. Please ensure ROCm is installed and " | ||
| "accessible (check ROCM_PATH or /opt/rocm)." | ||
| "accessible (check ROCM_PATH, ROCM_HOME or /opt/rocm)." | ||
| ) | ||
|
|
||
| # Parse version to major.minor for compatibility check | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_rocm_home()falls back to/opt/rocmwithout attempting any discovery when neitherROCM_PATHnorROCM_HOMEis set. This can break environments where ROCm is installed in a non-standard prefix (including TheRock wheel installs) unless users also set one of those env vars. Consider adding an additional fallback that derives the prefix fromPYTORCH_AMDCLANG(if set) and/or from ahipcc/amdclang++found onPATH, before defaulting to/opt/rocm.