Skip to content

Commit

Permalink
add hip_call() (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
smedegaard authored Dec 21, 2024
1 parent ce0d3d3 commit 6225eeb
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/core/hip_call.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use super::{sys, HipResult, Result};

#[macro_export]
macro_rules! hip_call {
($call:expr) => {{
let code = unsafe { $call };
((), code).to_result()
}};
}

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

#[test]
fn test_hip_call_simple() {
let result = hip_call!(sys::hipDeviceSynchronize());
assert!(result.is_ok());
}

#[test]
fn test_hip_call_with_value() {
let mut count = 0;
let result = hip_call!(sys::hipGetDeviceCount(&mut count));
assert!(result.is_ok());
assert!(count > 0);
}

#[test]
fn test_hip_call_error() {
// Call with invalid device ID should return error
let result = hip_call!(sys::hipSetDevice(99));
assert!(result.is_err());
}
}
2 changes: 2 additions & 0 deletions src/core/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod device;
mod device_types;
mod flags;
mod hip_call;
mod init;
mod memory;
mod result;
Expand All @@ -11,6 +12,7 @@ pub mod sys;
pub use device::*;
pub use device_types::*;
pub use flags::*;
pub use hip_call::*;
pub use init::*;
pub use memory::*;
pub use result::*;
Expand Down

0 comments on commit 6225eeb

Please sign in to comment.