pub struct CudaFlags { /* private fields */ }
Expand description
Bit flags for initializing the CUDA driver. Currently, no flags are defined,
so CudaFlags::empty()
is the only valid value.
Implementations§
Source§impl CudaFlags
impl CudaFlags
Sourcepub const fn empty() -> CudaFlags
pub const fn empty() -> CudaFlags
Returns an empty set of flags
Examples found in repository?
examples/launch.rs (line 10)
8fn main() -> Result<(), Box<dyn Error>> {
9 // Set up the context, load the module, and create a stream to run kernels in.
10 rustacuda::init(CudaFlags::empty())?;
11 let device = Device::get_device(0)?;
12 let _ctx = Context::create_and_push(ContextFlags::MAP_HOST | ContextFlags::SCHED_AUTO, device)?;
13
14 let ptx = CString::new(include_str!("../resources/add.ptx"))?;
15 let module = Module::load_from_string(&ptx)?;
16 let stream = Stream::new(StreamFlags::NON_BLOCKING, None)?;
17
18 // Create buffers for data
19 let mut in_x = DeviceBuffer::from_slice(&[1.0f32; 10])?;
20 let mut in_y = DeviceBuffer::from_slice(&[2.0f32; 10])?;
21 let mut out_1 = DeviceBuffer::from_slice(&[0.0f32; 10])?;
22 let mut out_2 = DeviceBuffer::from_slice(&[0.0f32; 10])?;
23
24 // This kernel adds each element in `in_x` and `in_y` and writes the result into `out`.
25 unsafe {
26 // Launch the kernel with one block of one thread, no dynamic shared memory on `stream`.
27 let result = launch!(module.sum<<<1, 1, 0, stream>>>(
28 in_x.as_device_ptr(),
29 in_y.as_device_ptr(),
30 out_1.as_device_ptr(),
31 out_1.len()
32 ));
33 result?;
34
35 // Launch the kernel again using the `function` form:
36 let function_name = CString::new("sum")?;
37 let sum = module.get_function(&function_name)?;
38 // Launch with 1x1x1 (1) blocks of 10x1x1 (10) threads, to show that you can use tuples to
39 // configure grid and block size.
40 let result = launch!(sum<<<(1, 1, 1), (10, 1, 1), 0, stream>>>(
41 in_x.as_device_ptr(),
42 in_y.as_device_ptr(),
43 out_2.as_device_ptr(),
44 out_2.len()
45 ));
46 result?;
47 }
48
49 // Kernel launches are asynchronous, so we wait for the kernels to finish executing.
50 stream.synchronize()?;
51
52 // Copy the results back to host memory
53 let mut out_host = [0.0f32; 20];
54 out_1.copy_to(&mut out_host[0..10])?;
55 out_2.copy_to(&mut out_host[10..20])?;
56
57 for x in out_host.iter() {
58 assert_eq!(3.0 as u32, *x as u32);
59 }
60
61 println!("Launched kernel successfully.");
62 Ok(())
63}
Sourcepub fn from_bits(bits: u32) -> Option<CudaFlags>
pub fn from_bits(bits: u32) -> Option<CudaFlags>
Convert from underlying bit representation, unless that representation contains bits that do not correspond to a flag.
Sourcepub const fn from_bits_truncate(bits: u32) -> CudaFlags
pub const fn from_bits_truncate(bits: u32) -> CudaFlags
Convert from underlying bit representation, dropping any bits that do not correspond to flags.
Sourcepub const unsafe fn from_bits_unchecked(bits: u32) -> CudaFlags
pub const unsafe fn from_bits_unchecked(bits: u32) -> CudaFlags
Convert from underlying bit representation, preserving all bits (even those not corresponding to a defined flag).
Sourcepub const fn intersects(&self, other: CudaFlags) -> bool
pub const fn intersects(&self, other: CudaFlags) -> bool
Returns true
if there are flags common to both self
and other
.
Trait Implementations§
Source§impl BitAndAssign for CudaFlags
impl BitAndAssign for CudaFlags
Source§fn bitand_assign(&mut self, other: CudaFlags)
fn bitand_assign(&mut self, other: CudaFlags)
Disables all flags disabled in the set.
Source§impl BitOrAssign for CudaFlags
impl BitOrAssign for CudaFlags
Source§fn bitor_assign(&mut self, other: CudaFlags)
fn bitor_assign(&mut self, other: CudaFlags)
Adds the set of flags.
Source§impl BitXorAssign for CudaFlags
impl BitXorAssign for CudaFlags
Source§fn bitxor_assign(&mut self, other: CudaFlags)
fn bitxor_assign(&mut self, other: CudaFlags)
Toggles the set of flags.
Source§impl Extend<CudaFlags> for CudaFlags
impl Extend<CudaFlags> for CudaFlags
Source§fn extend<T: IntoIterator<Item = CudaFlags>>(&mut self, iterator: T)
fn extend<T: IntoIterator<Item = CudaFlags>>(&mut self, iterator: T)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one
)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Source§impl FromIterator<CudaFlags> for CudaFlags
impl FromIterator<CudaFlags> for CudaFlags
Source§impl Ord for CudaFlags
impl Ord for CudaFlags
Source§impl PartialOrd for CudaFlags
impl PartialOrd for CudaFlags
Source§impl SubAssign for CudaFlags
impl SubAssign for CudaFlags
Source§fn sub_assign(&mut self, other: CudaFlags)
fn sub_assign(&mut self, other: CudaFlags)
Disables all flags enabled in the set.
impl Copy for CudaFlags
impl Eq for CudaFlags
impl StructuralPartialEq for CudaFlags
Auto Trait Implementations§
impl Freeze for CudaFlags
impl RefUnwindSafe for CudaFlags
impl Send for CudaFlags
impl Sync for CudaFlags
impl Unpin for CudaFlags
impl UnwindSafe for CudaFlags
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more