Skip to content

Commit 05add7c

Browse files
authored
Use hipconfig in build script (#19)
* Use hipconfig to get the ROCm and HIP installation paths * Simplify HIP version detection by using hipconfig as source of truth * Rename build_script.rs to hipconfig.rs
1 parent bd7e617 commit 05add7c

File tree

10 files changed

+465
-512
lines changed

10 files changed

+465
-512
lines changed

Cargo.lock

Lines changed: 192 additions & 65 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
[workspace]
2-
# Try
3-
# require version 2 to avoid "feature" additiveness for dev-dependencies
4-
# https://doc.rust-lang.org/cargo/reference/resolver.html#feature-resolver-version-2
5-
resolver = "2"
2+
# Try
3+
# require version 2 to avoid "feature" additiveness for dev-dependencies
4+
# https://doc.rust-lang.org/cargo/reference/resolver.html#feature-resolver-version-2
5+
resolver = "2"
66

7-
members = ["crates/*", "xtask"]
7+
members = ["crates/*", "xtask"]
88

9-
[workspace.package]
10-
edition = "2021"
11-
license = "MIT OR Apache-2.0"
12-
readme = "README.md"
13-
version = "6.4.0"
9+
[workspace.package]
10+
edition = "2021"
11+
license = "MIT OR Apache-2.0"
12+
readme = "README.md"
13+
version = "6.4.43482"
1414

15-
[workspace.dependencies]
16-
bindgen = "0.70.1"
17-
libc = "0.2.159"
18-
log = "0.4.22"
19-
rstest = "0.2.1"
20-
strum = {version = "0.26.3", features = ["derive"]}
15+
[workspace.dependencies]
16+
bindgen = "0.70.1"
17+
libc = "0.2.159"
18+
log = "0.4.22"
19+
regex = "1.11.1"
20+
rstest = "0.25.0"
21+
strum = {version = "0.26.3", features = ["derive"]}
2122

22-
### For xtask crate ###
23-
tracel-xtask = {version = "=1.1.8"}
23+
### For xtask crate ###
24+
tracel-xtask = {version = "=1.1.8"}
2425

2526
[profile.dev]
26-
debug = 0 # Speed up compilation time and not necessary.
27+
debug = 0 # Speed up compilation time and not necessary.

README.md

Lines changed: 40 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<br/>
1515
</div>
1616

17-
This repository contains Rust bindings for AMD ROCm HIP runtime libraries used by CubeCL.
17+
This repository contains Rust bindings for AMD ROCm HIP runtime libraries (hiprtc, amdhip64) used by CubeCL.
1818

1919
## ⚠️ Notes
2020
These bindings are unsafe as they are just the raw bindings generated by bindgen with no improvements.
@@ -26,107 +26,79 @@ These bindings are unsafe as they are just the raw bindings generated by bindgen
2626

2727
## Prerequisites
2828

29-
Install ROCm in the default directory under `/opt` following the [ROCm documentation][1]:
29+
Install ROCm following the [ROCm documentation][1]:
3030

3131
## Versioning Scheme
3232

33-
The crates in this repository follow the versioning conventions outlined below:
34-
- The latest supported ROCm version of the crates is used as the base version.
35-
- The patch version of the ROCm release is multiplied by 1000, allowing multiple revisions of a crate for the same ROCm version.
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.
3635

37-
### Example:
36+
This versioning scheme is in place as of May 2025, any previous version of this crate followed a different versioning scheme based
37+
on ROCm version instead of HIP.
3838

39-
The `cubecl-hip-sys` version `6.2.4000` represents the first release with ROCm `6.2.4`.
40-
If a fix is required and the ROCm version remains `6.2.4`, the `cubecl-hip-sys` version is incremented to `6.2.4001`.
39+
Note also that multiple versions of ROCm can ship the same version of HIP.
4140

42-
## Usage
41+
### Example:
4342

44-
Add the crate [cubecl-hip-sys][2] to the `Cargo.toml` file of your project and enable the feature
45-
corresponding to the version of ROCm you have installed.
43+
The `cubecl-hip-sys` version `6.4.43482` represents the HIP with the same version `6.4.43482`.
4644

47-
If no feature is provided then the build script will attempt to find the default ROCm version installed on your system.
48-
Read the `warning` messages in the build output to learn about the script behavior.
45+
## Usage
4946

50-
```toml
51-
cubecl-hip-sys = { version = "6.3.1000", features = ["rocm__6_3_1"] }
52-
```
47+
Add the crate [cubecl-hip-sys][2] to the `Cargo.toml` file of your project. If no feature is set then cargo will select the HIP
48+
version returned by the `hipconfig` utility.
5349

54-
If you installed a newer ROCm version that is not yet supported by this crate then read the next section to learn
55-
how to generate and submit new bindings for your version.
50+
To specify a different version of HIP manually set the environment variable HIP_PATH to a valid HIP installation path. You can
51+
verify that your system points to the expected version with the command `hipconfig --version`.
5652

57-
Next you need to point out where you installed ROCm so that `rustc` can link to your ROCM libraries. To do so set the variable `ROCM_PATH`, or `HIP_PATH` or the more specific `CUBECL_ROCM_PATH` to its
58-
installation base directory, it is often `/opt/rocm`.
53+
Remark: Don't set manually the `hip_xxx` feature for this crate. This is the responsibility of the `build.rs` script to set it
54+
accordingly to your `hipconfig` output.
5955

6056
Here is the table of currently available bindings:
6157

62-
| ROCm Version | Feature | Crates |
63-
|:-------------|:------------|:---------------|
64-
| 6.2.2 | rocm__6_2_2 | cubecl-hip-sys |
65-
| 6.2.4 | rocm__6_2_4 | cubecl-hip-sys |
66-
| 6.3.0 | rocm__6_3_0 | cubecl-hip-sys |
67-
| 6.3.1 | rocm__6_3_1 | cubecl-hip-sys |
68-
| 6.3.2 | rocm__6_3_2 | cubecl-hip-sys |
69-
| 6.3.3 | rocm__6_3_3 | cubecl-hip-sys |
70-
| 6.3.4 | rocm__6_3_4 | cubecl-hip-sys |
71-
| 6.4.0 | rocm__6_4_0 | cubecl-hip-sys |
72-
73-
Here is a table of the libraries covered by each crate:
74-
75-
| Crate | ROCm libraries |
76-
|:---------------|:-----------------|
77-
| cubecl-hip-sys | hiprtc, amdhip64 |
58+
| HIP Version | Corresponding ROCm Version Range |
59+
|:------------|:---------------------------------|
60+
| 41134 | 6.2.2~6.2.4 |
61+
| 42131 | 6.3.0 |
62+
| 42133 | 6.3.1 |
63+
| 42134 | 6.3.2~6.3.4 |
64+
| 43482 | 6.4.0 |
7865

7966
## Running tests
8067

81-
To run tests you need to first meet the expectations for both `Prerequisites` and `Usage`
82-
sections.
68+
To run tests you need to first meet the expectations for `Prerequisites` section.
8369

84-
Then execute the following xtask command by providing the version of ROCm to test, for instance `-v 6.2.2`:
70+
Then execute the following xtask command:
8571

8672
```sh
8773
# test ROCm bindings againt the system default ROCm installation if found
8874
cargo xtask test
89-
# test a specific version that is not the default
90-
cargo xtask test -v 6.2.2
75+
# test a specific version that is not the default by providing a value for HIP_PATH using -p
76+
xtask test -p /opt/rocm-6.3.0
9177
```
9278

93-
Important: always make sure that ROCm environment variable (see Usage) points to a version that matches the
94-
tested version.
95-
9679
## Generate bindings for a given version of ROCm
9780

98-
1) To generate the bindings you need to first meet the expectations for both `Prerequisites`
99-
and `Usage` sections.
81+
1) To generate the bindings you first need to meet the expectations for `Prerequisites` section.
82+
83+
2) Make sure that `hipconfig` returns the path of the HIP version you want to wrap. Adapt the `HIP_PATH`
84+
environment variable to point to the version you are interested in.
10085

101-
2) Generate the bindings using the dedicated xtask command `bindgen`. For instance, to generate
102-
the bindings for the crate `cubecl-hip-sys` and the ROCm version `6.3.0`:
86+
3) Generate the bindings using the dedicated xtask command `bindgen`:
10387

10488
```sh
105-
cargo xtask bindgen -c cubecl-hip-sys -v 6.3.0
89+
cargo xtask bindgen
10690
```
10791

108-
3) If the HIP bindings patch version has changed, declare a new `hip` feature in the `Cargo.toml`
109-
of the corresponding crate `cubecl-hip-sys` with the format `hip_<patch_version>`. For instance
110-
the version `6.3.0` has a new HIP patch version which is `42131`. Is the patch version did not
111-
change then skip this step.
92+
4) Declare a new `hip` feature in the `Cargo.toml` in `cubecl-hip-sys` crate with the format
93+
`hip_<patch_version>`. You can retrieve the patch version with the command `hipconfig --version`.
94+
For instance for a new HIP patch version which is `42131` add the following feature:
11295

11396
```toml
11497
[features]
11598
hip_42131 = []
11699
```
117100

118-
4) Declare a new `rocm` feature in the `Cargo.toml` of the corresponding crate `cubecl-hip-sys`
119-
with the format `rocm__<version>` where `<version>` is the ROCm version with `_` separator and
120-
add a dependency on its corresponding HIP bindings patch version. Note that sometimes the HIP
121-
bindings are not changed between two version of ROCm, in this case reuse the already existing
122-
hip feature.
123-
124-
```toml
125-
[features]
126-
rocm__6_3_0 = [ "hip_42131" ]
127-
```
128-
129-
4) Add the generated bindings module to the file `crates/cubecl-hip-sys/src/bindings/mod.rs`
101+
5) Add the generated bindings module to the file `crates/cubecl-hip-sys/src/bindings/mod.rs`
130102
conditionally to the new feature you just declared as well as the re-exports:
131103

132104
```rs
@@ -136,12 +108,13 @@ mod bindings_42131;
136108
pub use bindings_42131::*;
137109
```
138110

139-
5) Run the tests as explain in the previous section using the new feature you just created.
111+
5) Run the tests as explain in the previous section.
140112

141113
6) Open a pull request with the modifications, do not forget to add the new generated bindings
142114
file in the `crates/cubecl-hip-sys/src/bindings/` directory.
143115

144-
7) Note that the CI runner might need to be updated by an administrator to install the new version of ROCm.
116+
7) Note that the CI runner might need to be updated by an administrator so that the new HIP version is available
117+
on the runner.
145118

146119
[1]: https://rocmdocs.amd.com/projects/install-on-linux/en/latest/install/detailed-install.html
147120
[2]: https://crates.io/crates/cubecl-hip-sys

crates/cubecl-hip-sys/Cargo.toml

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,31 @@
11
[package]
2-
authors = ["Tracel Technologies Inc."]
3-
categories = ["external-ffi-bindings"]
4-
description = "Rust bindings for AMD ROCm HIP runtime libraries used by CubeCL."
5-
edition.workspace = true
6-
keywords = ["cubecl", "ROCm", "HIP", "API", "bindings"]
7-
license.workspace = true
8-
name = "cubecl-hip-sys"
9-
readme.workspace = true
10-
repository = "https://github.com/tracel-ai/cubecl-hip/tree/main/crates/cubecl-hip-sys"
11-
rust-version = "1.81"
12-
version.workspace = true
2+
authors = ["Tracel Technologies Inc."]
3+
categories = ["external-ffi-bindings"]
4+
description = "Rust bindings for AMD ROCm HIP runtime libraries used by CubeCL."
5+
edition.workspace = true
6+
keywords = ["cubecl", "ROCm", "HIP", "API", "bindings"]
7+
license.workspace = true
8+
name = "cubecl-hip-sys"
9+
readme.workspace = true
10+
repository = "https://github.com/tracel-ai/cubecl-hip/tree/main/crates/cubecl-hip-sys"
11+
rust-version = "1.81"
12+
version.workspace = true
1313

1414
[features]
15-
default = []
16-
17-
# ROCm versions
18-
rocm__6_2_2 = ["hip_41134"]
19-
rocm__6_2_4 = ["hip_41134"]
20-
rocm__6_3_0 = ["hip_42131"]
21-
rocm__6_3_1 = ["hip_42133"]
22-
rocm__6_3_2 = ["hip_42134"]
23-
rocm__6_3_3 = ["hip_42134"]
24-
rocm__6_3_4 = ["hip_42134"]
25-
rocm__6_4_0 = ["hip_43482"]
26-
27-
# HIP versions
28-
hip_41134 = []
29-
hip_42131 = []
30-
hip_42133 = []
31-
hip_42134 = []
32-
hip_43482 = []
15+
default = []
16+
# supported HIP patch versions
17+
hip_41134 = []
18+
hip_42131 = []
19+
hip_42133 = []
20+
hip_42134 = []
21+
hip_43482 = []
3322

3423
[dependencies]
35-
libc = {workspace = true}
24+
libc = {workspace = true}
25+
regex = {workspace = true}
3626

3727
[dev-dependencies]
38-
rstest = {workspace = true}
28+
rstest = {workspace = true}
29+
30+
[build-dependencies]
31+
regex = {workspace = true}

0 commit comments

Comments
 (0)