Returns the name 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 Name: {}", device.name()?); # Ok(()) # } ```
(self)
| 309 | /// # } |
| 310 | /// ``` |
| 311 | pub fn name(self) -> CudaResult<String> { |
| 312 | unsafe { |
| 313 | let mut name = [0u8; 128]; // Hopefully this is big enough... |
| 314 | cuDeviceGetName( |
| 315 | &mut name[0] as *mut u8 as *mut ::std::os::raw::c_char, |
| 316 | 128, |
| 317 | self.device, |
| 318 | ) |
| 319 | .to_result()?; |
| 320 | let nul_index = name |
| 321 | .iter() |
| 322 | .cloned() |
| 323 | .position(|byte| byte == 0) |
| 324 | .expect("Expected device name to fit in 128 bytes and be nul-terminated."); |
| 325 | let cstr = CStr::from_bytes_with_nul_unchecked(&name[0..=nul_index]); |
| 326 | Ok(cstr.to_string_lossy().into_owned()) |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | /// Returns information about this device. |
| 331 | /// |