Skip to content

Commit 2de8180

Browse files
vmxRDambrosio016
andauthored
Add support for getting the UUID of a device (#71)
* 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]>
1 parent 28d1269 commit 2de8180

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

crates/cust/src/device.rs

+23
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,29 @@ impl Device {
327327
}
328328
}
329329

330+
/// Returns the UUID of this device.
331+
///
332+
/// # Example
333+
/// ```
334+
/// # use cust::*;
335+
/// # use std::error::Error;
336+
/// # fn main() -> Result<(), Box<dyn Error>> {
337+
/// # init(CudaFlags::empty())?;
338+
/// use cust::device::Device;
339+
/// let device = Device::get_device(0)?;
340+
/// println!("Device UUID: {:?}", device.uuid()?);
341+
/// # Ok(())
342+
/// # }
343+
/// ```
344+
pub fn uuid(self) -> CudaResult<[u8; 16]> {
345+
let mut cu_uuid = CUuuid { bytes: [0i8; 16] };
346+
unsafe {
347+
cuDeviceGetUuid(&mut cu_uuid, self.device).to_result()?;
348+
}
349+
let uuid: [u8; 16] = cu_uuid.bytes.map(|byte| byte as u8);
350+
Ok(uuid)
351+
}
352+
330353
/// Returns information about this device.
331354
///
332355
/// # Example

0 commit comments

Comments
 (0)