pub struct Device(/* private fields */);Expand description
A CUDA device (Runtime API view — a bare ordinal).
Implementations§
Source§impl Device
impl Device
Sourcepub const fn from_ordinal(ordinal: u32) -> Self
pub const fn from_ordinal(ordinal: u32) -> Self
Construct a Device for the given ordinal. Does not validate — use
Device::all if you want a checked enumeration.
Sourcepub fn all() -> Result<Vec<Self>>
pub fn all() -> Result<Vec<Self>>
All visible devices, in ordinal order.
Examples found in repository?
18fn main() -> Result<(), Box<dyn std::error::Error>> {
19 println!("CUDA driver version: {}", driver_version()?);
20 println!("CUDA runtime version: {}", runtime_version()?);
21
22 let devices = Device::all()?;
23 println!("found {} CUDA device(s)", devices.len());
24
25 for dev in &devices {
26 // Switch current-thread device before querying properties:
27 // `device_properties` reads via `cudaGetDeviceProperties`, which
28 // is keyed off the ordinal we pass — but other Runtime calls
29 // (memory queries, kernel launches) operate on the current
30 // device, so it's good practice to bind first.
31 dev.set_current()?;
32 let props = device_properties(dev)?;
33 let (cc_major, cc_minor) = dev.compute_capability()?;
34 let sm_count = dev.multiprocessor_count()?;
35 let warp = dev.warp_size()?;
36
37 let gib = (props.total_global_memory_bytes as f64) / (1024.0 * 1024.0 * 1024.0);
38 println!(
39 " [{}] {:30} cc {}.{} {} SMs warp {} {:.2} GiB",
40 dev.ordinal(),
41 props.name,
42 cc_major,
43 cc_minor,
44 sm_count,
45 warp,
46 gib,
47 );
48 }
49
50 // Make sure all pending work on every device (none here) is done.
51 device_synchronize()?;
52 println!("OK");
53 Ok(())
54}Sourcepub fn set_current(&self) -> Result<()>
pub fn set_current(&self) -> Result<()>
Set this device as current on the calling thread. Subsequent Runtime API calls (allocations, launches, …) operate on this device.
Examples found in repository?
18fn main() -> Result<(), Box<dyn std::error::Error>> {
19 println!("CUDA driver version: {}", driver_version()?);
20 println!("CUDA runtime version: {}", runtime_version()?);
21
22 let devices = Device::all()?;
23 println!("found {} CUDA device(s)", devices.len());
24
25 for dev in &devices {
26 // Switch current-thread device before querying properties:
27 // `device_properties` reads via `cudaGetDeviceProperties`, which
28 // is keyed off the ordinal we pass — but other Runtime calls
29 // (memory queries, kernel launches) operate on the current
30 // device, so it's good practice to bind first.
31 dev.set_current()?;
32 let props = device_properties(dev)?;
33 let (cc_major, cc_minor) = dev.compute_capability()?;
34 let sm_count = dev.multiprocessor_count()?;
35 let warp = dev.warp_size()?;
36
37 let gib = (props.total_global_memory_bytes as f64) / (1024.0 * 1024.0 * 1024.0);
38 println!(
39 " [{}] {:30} cc {}.{} {} SMs warp {} {:.2} GiB",
40 dev.ordinal(),
41 props.name,
42 cc_major,
43 cc_minor,
44 sm_count,
45 warp,
46 gib,
47 );
48 }
49
50 // Make sure all pending work on every device (none here) is done.
51 device_synchronize()?;
52 println!("OK");
53 Ok(())
54}Sourcepub fn ordinal(&self) -> i32
pub fn ordinal(&self) -> i32
Ordinal of this device (0, 1, …).
Examples found in repository?
18fn main() -> Result<(), Box<dyn std::error::Error>> {
19 println!("CUDA driver version: {}", driver_version()?);
20 println!("CUDA runtime version: {}", runtime_version()?);
21
22 let devices = Device::all()?;
23 println!("found {} CUDA device(s)", devices.len());
24
25 for dev in &devices {
26 // Switch current-thread device before querying properties:
27 // `device_properties` reads via `cudaGetDeviceProperties`, which
28 // is keyed off the ordinal we pass — but other Runtime calls
29 // (memory queries, kernel launches) operate on the current
30 // device, so it's good practice to bind first.
31 dev.set_current()?;
32 let props = device_properties(dev)?;
33 let (cc_major, cc_minor) = dev.compute_capability()?;
34 let sm_count = dev.multiprocessor_count()?;
35 let warp = dev.warp_size()?;
36
37 let gib = (props.total_global_memory_bytes as f64) / (1024.0 * 1024.0 * 1024.0);
38 println!(
39 " [{}] {:30} cc {}.{} {} SMs warp {} {:.2} GiB",
40 dev.ordinal(),
41 props.name,
42 cc_major,
43 cc_minor,
44 sm_count,
45 warp,
46 gib,
47 );
48 }
49
50 // Make sure all pending work on every device (none here) is done.
51 device_synchronize()?;
52 println!("OK");
53 Ok(())
54}Sourcepub fn compute_capability(&self) -> Result<(u32, u32)>
pub fn compute_capability(&self) -> Result<(u32, u32)>
Compute capability as (major, minor).
Examples found in repository?
18fn main() -> Result<(), Box<dyn std::error::Error>> {
19 println!("CUDA driver version: {}", driver_version()?);
20 println!("CUDA runtime version: {}", runtime_version()?);
21
22 let devices = Device::all()?;
23 println!("found {} CUDA device(s)", devices.len());
24
25 for dev in &devices {
26 // Switch current-thread device before querying properties:
27 // `device_properties` reads via `cudaGetDeviceProperties`, which
28 // is keyed off the ordinal we pass — but other Runtime calls
29 // (memory queries, kernel launches) operate on the current
30 // device, so it's good practice to bind first.
31 dev.set_current()?;
32 let props = device_properties(dev)?;
33 let (cc_major, cc_minor) = dev.compute_capability()?;
34 let sm_count = dev.multiprocessor_count()?;
35 let warp = dev.warp_size()?;
36
37 let gib = (props.total_global_memory_bytes as f64) / (1024.0 * 1024.0 * 1024.0);
38 println!(
39 " [{}] {:30} cc {}.{} {} SMs warp {} {:.2} GiB",
40 dev.ordinal(),
41 props.name,
42 cc_major,
43 cc_minor,
44 sm_count,
45 warp,
46 gib,
47 );
48 }
49
50 // Make sure all pending work on every device (none here) is done.
51 device_synchronize()?;
52 println!("OK");
53 Ok(())
54}Sourcepub fn multiprocessor_count(&self) -> Result<u32>
pub fn multiprocessor_count(&self) -> Result<u32>
Multiprocessor count.
Examples found in repository?
18fn main() -> Result<(), Box<dyn std::error::Error>> {
19 println!("CUDA driver version: {}", driver_version()?);
20 println!("CUDA runtime version: {}", runtime_version()?);
21
22 let devices = Device::all()?;
23 println!("found {} CUDA device(s)", devices.len());
24
25 for dev in &devices {
26 // Switch current-thread device before querying properties:
27 // `device_properties` reads via `cudaGetDeviceProperties`, which
28 // is keyed off the ordinal we pass — but other Runtime calls
29 // (memory queries, kernel launches) operate on the current
30 // device, so it's good practice to bind first.
31 dev.set_current()?;
32 let props = device_properties(dev)?;
33 let (cc_major, cc_minor) = dev.compute_capability()?;
34 let sm_count = dev.multiprocessor_count()?;
35 let warp = dev.warp_size()?;
36
37 let gib = (props.total_global_memory_bytes as f64) / (1024.0 * 1024.0 * 1024.0);
38 println!(
39 " [{}] {:30} cc {}.{} {} SMs warp {} {:.2} GiB",
40 dev.ordinal(),
41 props.name,
42 cc_major,
43 cc_minor,
44 sm_count,
45 warp,
46 gib,
47 );
48 }
49
50 // Make sure all pending work on every device (none here) is done.
51 device_synchronize()?;
52 println!("OK");
53 Ok(())
54}Sourcepub fn warp_size(&self) -> Result<u32>
pub fn warp_size(&self) -> Result<u32>
Warp size in threads.
Examples found in repository?
18fn main() -> Result<(), Box<dyn std::error::Error>> {
19 println!("CUDA driver version: {}", driver_version()?);
20 println!("CUDA runtime version: {}", runtime_version()?);
21
22 let devices = Device::all()?;
23 println!("found {} CUDA device(s)", devices.len());
24
25 for dev in &devices {
26 // Switch current-thread device before querying properties:
27 // `device_properties` reads via `cudaGetDeviceProperties`, which
28 // is keyed off the ordinal we pass — but other Runtime calls
29 // (memory queries, kernel launches) operate on the current
30 // device, so it's good practice to bind first.
31 dev.set_current()?;
32 let props = device_properties(dev)?;
33 let (cc_major, cc_minor) = dev.compute_capability()?;
34 let sm_count = dev.multiprocessor_count()?;
35 let warp = dev.warp_size()?;
36
37 let gib = (props.total_global_memory_bytes as f64) / (1024.0 * 1024.0 * 1024.0);
38 println!(
39 " [{}] {:30} cc {}.{} {} SMs warp {} {:.2} GiB",
40 dev.ordinal(),
41 props.name,
42 cc_major,
43 cc_minor,
44 sm_count,
45 warp,
46 gib,
47 );
48 }
49
50 // Make sure all pending work on every device (none here) is done.
51 device_synchronize()?;
52 println!("OK");
53 Ok(())
54}Sourcepub fn attribute(&self, attr: i32) -> Result<i32>
pub fn attribute(&self, attr: i32) -> Result<i32>
Raw device-attribute query. See baracuda_cuda_sys::runtime::types::cudaDeviceAttr.
Sourcepub fn can_access_peer(&self, peer: &Device) -> Result<bool>
pub fn can_access_peer(&self, peer: &Device) -> Result<bool>
true if this device can peer-access peer’s allocations (P2P).
Call Device::enable_peer_access before actually using peer
pointers in kernels.
Sourcepub fn enable_peer_access(peer: &Device) -> Result<()>
pub fn enable_peer_access(peer: &Device) -> Result<()>
Enable peer access from the current device to peer’s
allocations. Call Device::set_current() on the accessing device
first.
Sourcepub fn disable_peer_access(peer: &Device) -> Result<()>
pub fn disable_peer_access(peer: &Device) -> Result<()>
Disable peer access previously enabled via
Device::enable_peer_access.