Skip to content

Commit

Permalink
Remove build_script crate
Browse files Browse the repository at this point in the history
  • Loading branch information
syl20bnr committed Dec 10, 2024
1 parent f845278 commit e34b1da
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 16 deletions.
6 changes: 1 addition & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 0 additions & 9 deletions crates/build-script/Cargo.toml

This file was deleted.

2 changes: 1 addition & 1 deletion crates/cubecl-hip-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::env;
const ROCM_FEATURE_PREFIX: &str = "CARGO_FEATURE_ROCM__";
const ROCM_HIP_FEATURE_PREFIX: &str = "CARGO_FEATURE_HIP_";

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

/// Make sure that at least one and only one hip feature is set
fn ensure_single_rocm_hip_feature_set() {
Expand Down
File renamed without changes.
84 changes: 84 additions & 0 deletions crates/cubecl-hip-sys/src/build_script.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
use std::fmt;
use std::path::Path;

pub struct Version {
pub major: u8,
pub minor: u8,
pub patch: u32,
}

impl fmt::Display for Version {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}.{}.{}", self.major, self.minor, self.patch)
}
}

/// Reads the header inside the rocm folder that contains the ROCm global version
pub fn get_rocm_system_version(rocm_path: impl AsRef<Path>) -> std::io::Result<Version> {
let version_path = rocm_path.as_ref().join("include/rocm-core/rocm_version.h");
let version_file = std::fs::read_to_string(version_path)?;
let version_lines = version_file.lines().collect::<Vec<_>>();

let major = version_lines
.iter()
.find_map(|line| line.strip_prefix("#define ROCM_VERSION_MAJOR "))
.expect("Invalid rocm_version.h file structure: Major version line not found.")
.trim()
.parse::<u8>()
.expect("Invalid rocm_version.h file structure: Couldn't parse major version.");
let minor = version_lines
.iter()
.find_map(|line| line.strip_prefix("#define ROCM_VERSION_MINOR "))
.expect("Invalid rocm_version.h file structure: Minor version line not found.")
.trim()
.parse::<u8>()
.expect("Invalid rocm_version.h file structure: Couldn't parse minor version.");
let patch = version_lines
.iter()
.find_map(|line| line.strip_prefix("#define ROCM_VERSION_PATCH "))
.expect("Invalid rocm_version.h file structure: Patch version line not found.")
.trim()
.parse::<u32>()
.expect("Invalid rocm_version.h file structure: Couldn't parse patch version.");

Ok(Version {
major,
minor,
patch,
})
}

/// Reads the HIP header inside the rocm folder that contains the HIP specific version
pub fn get_hip_system_version(rocm_path: impl AsRef<Path>) -> std::io::Result<Version> {
let version_path = rocm_path.as_ref().join("include/hip/hip_version.h");
let version_file = std::fs::read_to_string(version_path)?;
let version_lines = version_file.lines().collect::<Vec<_>>();

let major = version_lines
.iter()
.find_map(|line| line.strip_prefix("#define HIP_VERSION_MAJOR "))
.expect("Invalid hip_version.h file structure: Major version line not found.")
.trim()
.parse::<u8>()
.expect("Invalid hip_version.h file structure: Couldn't parse major version.");
let minor = version_lines
.iter()
.find_map(|line| line.strip_prefix("#define HIP_VERSION_MINOR "))
.expect("Invalid hip_version.h file structure: Minor version line not found.")
.trim()
.parse::<u8>()
.expect("Invalid hip_version.h file structure: Couldn't parse minor version.");
let patch = version_lines
.iter()
.find_map(|line| line.strip_prefix("#define HIP_VERSION_PATCH "))
.expect("Invalid hip_version.h file structure: Patch version line not found.")
.trim()
.parse::<u32>()
.expect("Invalid hip_version.h file structure: Couldn't parse patch version.");

Ok(Version {
major,
minor,
patch,
})
}
2 changes: 2 additions & 0 deletions crates/cubecl-hip-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#![allow(non_upper_case_globals)]
#![allow(unused_variables)]

pub mod build_script;

#[cfg(target_os = "linux")]
mod bindings;
#[cfg(target_os = "linux")]
Expand Down
2 changes: 1 addition & 1 deletion xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "1.0.0"
edition = "2021"

[dependencies]
build-script = { path = "../crates/build-script" }
cubecl-hip-sys = { path = "../crates/cubecl-hip-sys" }
bindgen = { workspace = true }
strum = { workspace = true }
log = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions xtask/src/commands/bindgen.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::path::{Path, PathBuf};

use cubecl_hip_sys::build_script;
use tracel_xtask::{
prelude::*,
utils::workspace::{get_workspace_members, WorkspaceMember, WorkspaceMemberType},
Expand Down

0 comments on commit e34b1da

Please sign in to comment.