Skip to content

Commit 7f375af

Browse files
committed
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.
1 parent f1fa04f commit 7f375af

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/device.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,29 @@ impl Device {
328328
}
329329
}
330330

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

0 commit comments

Comments
 (0)