Skip to content
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

closes #1. add runtime_get_version() #9

Merged
merged 3 commits into from
Nov 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/runtime/safe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,40 @@ pub fn device_total_mem(device: Device) -> Result<usize> {
}
}

fn decode_hip_version(version: i32) -> Version {
if version == -1 {
return Version::new(0, 0, 0);
}
let major = version / 1_000_000;
let minor = (version / 1_000) % 1_000;
let patch = version % 1_000;
Version::new(major as u64, minor as u64, patch as u64)
}

pub fn runtime_get_version() -> Result<Version> {
unsafe {
let mut version: i32 = -1;
let code = sys::hipRuntimeGetVersion(&mut version);
let version = decode_hip_version(version);
(version, code).to_result()
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_runtime_get_version() {
let result = runtime_get_version();
assert!(result.is_ok());
let version = result.unwrap();
println!(
"Runtime version: {}.{}.{}",
version.major, version.minor, version.patch
);
}

#[test]
fn test_device_total_mem() {
let device = Device::new(0);
Expand Down