pub struct ThreadIndexedSlice<'a, T> { /* private fields */ }Expand description
Safely pass a list to a kernel and let every thread mutably access one element of the list.
The size of the list needs to be equal to the number of launched threads otherwise launching the kernel panics.
§Example
use gpu_kernel::{kernel, ThreadIndexedSlice};
gpu_kernel::kernel_lib!();
#[kernel]
fn kernel(elem: ThreadIndexedSlice<'_, i32>) {
// Every thread writes two into the element assigned to this thread
*elem.get_mut() = 2;
}
fn main() {
// Needs the same length as the number of threads launched
let mut data = vec![0; 10];
kernel.launch(
gpu_kernel::LaunchConfig::new()
.threads_per_workgroup([data.len() as u32, 1, 1])
.workgroups([1, 1, 1]),
&mut data,
);
}Implementations§
Source§impl<'a, T> ThreadIndexedSlice<'a, T>
impl<'a, T> ThreadIndexedSlice<'a, T>
Sourcepub unsafe fn from_ptr(ptr: *mut T) -> Self
pub unsafe fn from_ptr(ptr: *mut T) -> Self
Constructs a ThreadIndexedSlice from a raw base pointer.
§Safety
ptrmust point to at least number of GPU threads consecutive properly initialized values of type T.- No constant or mutable reference to the data must exist for the lifetime of this struct.
Sourcepub fn as_mut_base_ptr(&mut self) -> *mut T
pub fn as_mut_base_ptr(&mut self) -> *mut T
Returns the base pointer of the wrapped list.
Auto Trait Implementations§
impl<'a, T> !Send for ThreadIndexedSlice<'a, T>
impl<'a, T> !Sync for ThreadIndexedSlice<'a, T>
impl<'a, T> !UnwindSafe for ThreadIndexedSlice<'a, T>
impl<'a, T> Freeze for ThreadIndexedSlice<'a, T>
impl<'a, T> RefUnwindSafe for ThreadIndexedSlice<'a, T>
impl<'a, T> Unpin for ThreadIndexedSlice<'a, T>
impl<'a, T> UnsafeUnpin for ThreadIndexedSlice<'a, T>
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