From 2de8180da71e336588890db5c6cd7cca08452976 Mon Sep 17 00:00:00 2001 From: Volker Mische Date: Thu, 12 May 2022 02:38:18 +0100 Subject: [PATCH] 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 Co-authored-by: Riccardo D'Ambrosio --- crates/cust/src/device.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/crates/cust/src/device.rs b/crates/cust/src/device.rs index 562231d..e876fb5 100644 --- a/crates/cust/src/device.rs +++ b/crates/cust/src/device.rs @@ -327,6 +327,29 @@ impl Device { } } + /// Returns the UUID of this device. + /// + /// # Example + /// ``` + /// # use cust::*; + /// # use std::error::Error; + /// # fn main() -> Result<(), Box> { + /// # 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