Skip to content

Commit e34b1da

Browse files
committed
Remove build_script crate
1 parent f845278 commit e34b1da

File tree

8 files changed

+90
-16
lines changed

8 files changed

+90
-16
lines changed

Cargo.lock

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

crates/build-script/Cargo.toml

Lines changed: 0 additions & 9 deletions
This file was deleted.

crates/cubecl-hip-sys/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::env;
33
const ROCM_FEATURE_PREFIX: &str = "CARGO_FEATURE_ROCM__";
44
const ROCM_HIP_FEATURE_PREFIX: &str = "CARGO_FEATURE_HIP_";
55

6-
include!("../build-script/src/lib.rs");
6+
include!("src/build_script.rs");
77

88
/// Make sure that at least one and only one hip feature is set
99
fn ensure_single_rocm_hip_feature_set() {
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
use std::fmt;
2+
use std::path::Path;
3+
4+
pub struct Version {
5+
pub major: u8,
6+
pub minor: u8,
7+
pub patch: u32,
8+
}
9+
10+
impl fmt::Display for Version {
11+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
12+
write!(f, "{}.{}.{}", self.major, self.minor, self.patch)
13+
}
14+
}
15+
16+
/// Reads the header inside the rocm folder that contains the ROCm global version
17+
pub fn get_rocm_system_version(rocm_path: impl AsRef<Path>) -> std::io::Result<Version> {
18+
let version_path = rocm_path.as_ref().join("include/rocm-core/rocm_version.h");
19+
let version_file = std::fs::read_to_string(version_path)?;
20+
let version_lines = version_file.lines().collect::<Vec<_>>();
21+
22+
let major = version_lines
23+
.iter()
24+
.find_map(|line| line.strip_prefix("#define ROCM_VERSION_MAJOR "))
25+
.expect("Invalid rocm_version.h file structure: Major version line not found.")
26+
.trim()
27+
.parse::<u8>()
28+
.expect("Invalid rocm_version.h file structure: Couldn't parse major version.");
29+
let minor = version_lines
30+
.iter()
31+
.find_map(|line| line.strip_prefix("#define ROCM_VERSION_MINOR "))
32+
.expect("Invalid rocm_version.h file structure: Minor version line not found.")
33+
.trim()
34+
.parse::<u8>()
35+
.expect("Invalid rocm_version.h file structure: Couldn't parse minor version.");
36+
let patch = version_lines
37+
.iter()
38+
.find_map(|line| line.strip_prefix("#define ROCM_VERSION_PATCH "))
39+
.expect("Invalid rocm_version.h file structure: Patch version line not found.")
40+
.trim()
41+
.parse::<u32>()
42+
.expect("Invalid rocm_version.h file structure: Couldn't parse patch version.");
43+
44+
Ok(Version {
45+
major,
46+
minor,
47+
patch,
48+
})
49+
}
50+
51+
/// Reads the HIP header inside the rocm folder that contains the HIP specific version
52+
pub fn get_hip_system_version(rocm_path: impl AsRef<Path>) -> std::io::Result<Version> {
53+
let version_path = rocm_path.as_ref().join("include/hip/hip_version.h");
54+
let version_file = std::fs::read_to_string(version_path)?;
55+
let version_lines = version_file.lines().collect::<Vec<_>>();
56+
57+
let major = version_lines
58+
.iter()
59+
.find_map(|line| line.strip_prefix("#define HIP_VERSION_MAJOR "))
60+
.expect("Invalid hip_version.h file structure: Major version line not found.")
61+
.trim()
62+
.parse::<u8>()
63+
.expect("Invalid hip_version.h file structure: Couldn't parse major version.");
64+
let minor = version_lines
65+
.iter()
66+
.find_map(|line| line.strip_prefix("#define HIP_VERSION_MINOR "))
67+
.expect("Invalid hip_version.h file structure: Minor version line not found.")
68+
.trim()
69+
.parse::<u8>()
70+
.expect("Invalid hip_version.h file structure: Couldn't parse minor version.");
71+
let patch = version_lines
72+
.iter()
73+
.find_map(|line| line.strip_prefix("#define HIP_VERSION_PATCH "))
74+
.expect("Invalid hip_version.h file structure: Patch version line not found.")
75+
.trim()
76+
.parse::<u32>()
77+
.expect("Invalid hip_version.h file structure: Couldn't parse patch version.");
78+
79+
Ok(Version {
80+
major,
81+
minor,
82+
patch,
83+
})
84+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#![allow(non_upper_case_globals)]
77
#![allow(unused_variables)]
88

9+
pub mod build_script;
10+
911
#[cfg(target_os = "linux")]
1012
mod bindings;
1113
#[cfg(target_os = "linux")]

xtask/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "1.0.0"
44
edition = "2021"
55

66
[dependencies]
7-
build-script = { path = "../crates/build-script" }
7+
cubecl-hip-sys = { path = "../crates/cubecl-hip-sys" }
88
bindgen = { workspace = true }
99
strum = { workspace = true }
1010
log = { workspace = true }

xtask/src/commands/bindgen.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::path::{Path, PathBuf};
22

3+
use cubecl_hip_sys::build_script;
34
use tracel_xtask::{
45
prelude::*,
56
utils::workspace::{get_workspace_members, WorkspaceMember, WorkspaceMemberType},

0 commit comments

Comments
 (0)