Skip to content

Commit

Permalink
Add support for getting the UUID of a device (#71)
Browse files Browse the repository at this point in the history
* Feat: Add support for getting the UUID of a device

`Device::uuid()` was added to get the UUID of a device via the underlying
`cuDevuceGetUuid()` call.

* Fix: Use casting instead of `to_ne_bytes`

Instead of using the `to_ne_bytes()` function, cast directly as `u8`.

Co-authored-by: Riccardo D'Ambrosio <[email protected]>

Co-authored-by: Riccardo D'Ambrosio <[email protected]>
  • Loading branch information
vmx and RDambrosio016 authored May 12, 2022
1 parent 28d1269 commit 2de8180
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions crates/cust/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,29 @@ impl Device {
}
}

/// Returns the UUID of this device.
///
/// # Example
/// ```
/// # use cust::*;
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// # init(CudaFlags::empty())?;
/// use cust::device::Device;
/// let device = Device::get_device(0)?;
/// println!("Device UUID: {:?}", device.uuid()?);
/// # Ok(())
/// # }
/// ```
pub fn uuid(self) -> CudaResult<[u8; 16]> {
let mut cu_uuid = CUuuid { bytes: [0i8; 16] };
unsafe {
cuDeviceGetUuid(&mut cu_uuid, self.device).to_result()?;
}
let uuid: [u8; 16] = cu_uuid.bytes.map(|byte| byte as u8);
Ok(uuid)
}

/// Returns information about this device.
///
/// # Example
Expand Down

0 comments on commit 2de8180

Please sign in to comment.