Skip to content

Commit

Permalink
7 hipdevicetotalmem (#8)
Browse files Browse the repository at this point in the history
* 'add device_total_mem()'
  • Loading branch information
smedegaard authored Nov 2, 2024
1 parent d8846b8 commit 8e9ab44
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/runtime/safe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub fn set_device(device: Device) -> Result<Device> {
/// # Returns
/// * `Result<Version>` - On success, returns a `Version` struct containing the major and minor version
/// numbers of the device's compute capability. On failure, returns an error indicating what went wrong.
pub fn get_device_compute_capability(device: Device) -> Result<Version> {
pub fn device_compute_capability(device: Device) -> Result<Version> {
unsafe {
let mut major: i32 = -1;
let mut minor: i32 = -1;
Expand All @@ -105,15 +105,35 @@ pub fn get_device_compute_capability(device: Device) -> Result<Version> {
}
}

pub fn device_total_mem(device: Device) -> Result<usize> {
unsafe {
let mut size: usize = 0;
let code = sys::hipDeviceTotalMem(&mut size, device.id);
(size, code).to_result()
}
}

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

#[test]
fn test_device_total_mem() {
let device = Device::new(0);
let result = device_total_mem(device);
assert!(result.is_ok());
let size = result.unwrap();
assert!(size > 0);
println!("Total memory in bytes: {}", size);
}

#[test]
fn test_get_device_compute_capability() {
let device = Device::new(0);
let result = get_device_compute_capability(device);
let result = device_compute_capability(device);
assert!(result.is_ok());
let version = result.unwrap();
assert!(version.major > 0);
println!("Compute Capability: {}.{}", version.major, version.minor);
}

Expand Down

0 comments on commit 8e9ab44

Please sign in to comment.