MCPcopy Create free account
hub / github.com/Rust-GPU/rust-cuda / name

Method name

crates/cust/src/device.rs:311–328  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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 ///

Callers 2

infoMethod · 0.45
test_get_nameFunction · 0.45

Calls 3

iterMethod · 0.80
to_resultMethod · 0.45
expectMethod · 0.45

Tested by 1

test_get_nameFunction · 0.36