Skip to content

Commit b5460a6

Browse files
committed
Fix compilation error when hipconfig is not found
We emit a warning instead and skip the linking part.
1 parent 05add7c commit b5460a6

File tree

5 files changed

+43
-34
lines changed

5 files changed

+43
-34
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ members = ["crates/*", "xtask"]
1010
edition = "2021"
1111
license = "MIT OR Apache-2.0"
1212
readme = "README.md"
13-
version = "6.4.43482"
13+
version = "6.43482.1"
1414

1515
[workspace.dependencies]
1616
bindgen = "0.70.1"

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,20 @@ Install ROCm following the [ROCm documentation][1]:
3030

3131
## Versioning Scheme
3232

33-
The crates in this repository follow the same versioning as HIP. Note that HIP version is somewhat different than ROCm version.
34-
The patch number of HIP version is a monotonic number that uniquely indentify the version of HIP.
33+
The crates in this repository follow the same versioning as HIP _but drop the minor version_ and use the patch number for
34+
this crate release number:
35+
36+
```
37+
<rocm_major>.<hip_patch>.<bindings_version>
38+
```
39+
40+
`bindings_version` starts at 0 for each new `<hip_patch>`, it allows us to release fixes for a same HIP patch.
41+
42+
For instance `6.43482.1` represents the second release (the one after the initial `6.43482.0`) for HIP `43482`.
3543

3644
This versioning scheme is in place as of May 2025, any previous version of this crate followed a different versioning scheme based
3745
on ROCm version instead of HIP.
3846

39-
Note also that multiple versions of ROCm can ship the same version of HIP.
40-
4147
### Example:
4248

4349
The `cubecl-hip-sys` version `6.4.43482` represents the HIP with the same version `6.4.43482`.

crates/cubecl-hip-sys/build.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ fn main() {
3030
println!("cargo::rerun-if-env-changed=ROCM_PATH");
3131
println!("cargo::rerun-if-env-changed=HIP_PATH");
3232
let hip_system_patch = get_hip_patch_version();
33-
set_hip_feature(&hip_system_patch);
34-
println!("cargo::rustc-link-lib=dylib=hiprtc");
35-
println!("cargo::rustc-link-lib=dylib=amdhip64");
36-
let lib_path = get_hip_ld_library_path();
37-
println!("cargo::rustc-link-search=native={lib_path}");
33+
if let Ok(ref patch) = hip_system_patch {
34+
set_hip_feature(patch);
35+
println!("cargo::rustc-link-lib=dylib=hiprtc");
36+
println!("cargo::rustc-link-lib=dylib=amdhip64");
37+
let lib_path = get_hip_ld_library_path().unwrap();
38+
println!("cargo::rustc-link-search=native={lib_path}");
39+
}
3840
}

crates/cubecl-hip-sys/src/hipconfig.rs

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,32 @@ use regex::Regex;
55
pub const HIPCONFIG: &str = "hipconfig";
66

77
/// Retrieve the ROCM_PATH with `hipconfig -R` command.
8-
pub fn get_rocm_path() -> String {
9-
exec_hipconfig(&["-R"]).unwrap()
8+
pub fn get_rocm_path() -> std::io::Result<String> {
9+
exec_hipconfig(&["-R"])
1010
}
1111

1212
/// Retrieve the HIP_PATH with `hipconfig -p` command.
13-
pub fn get_hip_path() -> String {
14-
exec_hipconfig(&["-p"]).unwrap()
13+
pub fn get_hip_path() -> std::io::Result<String> {
14+
exec_hipconfig(&["-p"])
1515
}
1616

1717
/// Retrieve the HIP patch number from the `hipconfig --version` output
18-
pub fn get_hip_patch_version() -> String {
19-
let hip_version = exec_hipconfig(&["--version"]).unwrap();
18+
pub fn get_hip_patch_version() -> std::io::Result<String> {
19+
let hip_version = exec_hipconfig(&["--version"])?;
2020
parse_hip_patch_number(&hip_version)
2121
}
2222

2323
/// Return the HIP path suitable for LD_LIBRARY_PATH.
24-
pub fn get_hip_ld_library_path() -> String {
25-
let rocm_path = get_rocm_path();
26-
let lib_dir = get_hip_library_directory_name(&rocm_path);
27-
format!("{rocm_path}/{lib_dir}")
24+
pub fn get_hip_ld_library_path() -> std::io::Result<String> {
25+
let rocm_path = get_rocm_path()?;
26+
let lib_dir = get_hip_library_directory_name(&rocm_path)?;
27+
Ok(format!("{rocm_path}/{lib_dir}"))
2828
}
2929

3030
/// Return the include path for HIP
31-
pub fn get_hip_include_path() -> String {
32-
let hip_path = get_hip_path();
33-
format!("{hip_path}/include")
31+
pub fn get_hip_include_path() -> std::io::Result<String> {
32+
let hip_path = get_hip_path()?;
33+
Ok(format!("{hip_path}/include"))
3434
}
3535

3636
/// Execute hipconfig
@@ -46,8 +46,9 @@ fn exec_hipconfig(args: &[&str]) -> std::io::Result<String> {
4646
);
4747
}
4848
}
49-
Err(ref e) if e.kind() == std::io::ErrorKind::NotFound => {
50-
panic!("Could not find '{HIPCONFIG}' in your PATH. You should install ROCm HIP or ensure '{HIPCONFIG}' is available. Fro more information please visit https://rocm.docs.amd.com/projects/install-on-linux/en/latest/.");
49+
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
50+
println!("cargo::warning=Could not find '{HIPCONFIG}' in your PATH. You should install ROCm HIP or ensure '{HIPCONFIG}' is available. For more information please visit https://rocm.docs.amd.com/projects/install-on-linux/en/latest/.");
51+
Err(e)
5152
}
5253
Err(e) => panic!(
5354
"Failed to run '{HIPCONFIG}' with args '{args:?}', reason: {}",
@@ -57,33 +58,33 @@ fn exec_hipconfig(args: &[&str]) -> std::io::Result<String> {
5758
}
5859

5960
/// extract the HIP patch number from hipconfig version output
60-
fn parse_hip_patch_number(version: &str) -> String {
61+
fn parse_hip_patch_number(version: &str) -> std::io::Result<String> {
6162
let re = Regex::new(r"\d+\.\d+\.(\d+)-").expect("regex should compile");
6263
if let Some(caps) = re.captures(version) {
6364
if let Some(m) = caps.get(1) {
64-
return m.as_str().to_string();
65+
return Ok(m.as_str().to_string());
6566
}
6667
}
6768
// cannot parse for the patch number
6869
panic!("Error retrieving HIP patch number from value '{version}'")
6970
}
7071

7172
/// Return the library directory using hipconfig
72-
fn get_hip_library_directory_name(rocm_path: &str) -> String {
73-
let clang_path = exec_hipconfig(&["-l"]).unwrap();
73+
fn get_hip_library_directory_name(rocm_path: &str) -> std::io::Result<String> {
74+
let clang_path = exec_hipconfig(&["-l"])?;
7475
parse_hip_library_directory_name(rocm_path, &clang_path)
7576
}
7677

7778
/// Parse out the first subdirectory under the ROCm path
78-
fn parse_hip_library_directory_name(rocm_path: &str, clang_path: &str) -> String {
79+
fn parse_hip_library_directory_name(rocm_path: &str, clang_path: &str) -> std::io::Result<String> {
7980
let rocm = rocm_path.trim().trim_end_matches('/');
8081
let clang = clang_path.trim();
8182
// Build a regex like "^/opt/rocm/([^/]+)"
8283
let pattern = format!(r"^{}\/([^/]+)", regex::escape(rocm));
8384
let re = Regex::new(&pattern).expect("regex should compile");
8485

8586
if let Some(caps) = re.captures(clang) {
86-
return caps[1].to_string();
87+
return Ok(caps[1].to_string());
8788
}
8889
panic!("Cannot retrieve the name of the HIP library directoy.");
8990
}
@@ -100,7 +101,7 @@ mod tests {
100101
#[case::missing_hyphen("6.4.43482", None)]
101102
#[case::completely_invalid("no numbers", None)]
102103
fn test_parse_hip_patch_number(#[case] input: &str, #[case] expected: Option<&str>) {
103-
let result = std::panic::catch_unwind(|| parse_hip_patch_number(input));
104+
let result = parse_hip_patch_number(input);
104105
match expected {
105106
Some(expected_str) => {
106107
let output = result.expect("should not panic for valid version");
@@ -126,7 +127,7 @@ mod tests {
126127
#[case] clang: &str,
127128
#[case] expected: Option<&str>,
128129
) {
129-
let result = std::panic::catch_unwind(|| parse_hip_library_directory_name(rocm, clang));
130+
let result = parse_hip_library_directory_name(rocm, clang);
130131
match expected {
131132
Some(expected_dir) => {
132133
// For valid inputs, it must not panic and return the directory name

0 commit comments

Comments
 (0)