Skip to content

Commit

Permalink
kernel dispatch ok; need to fix lifetime issues
Browse files Browse the repository at this point in the history
  • Loading branch information
imrn99 committed Nov 16, 2023
1 parent 3cbe4f9 commit 588503b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion benches/feature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ use poc_kokkos_rs::{

// 1D regular for init & populating
fn f1(length: usize) {
let mut v_y = ViewOwned::new_from_data(vec![0.0; length], Layout::Right, [length]);
let mut v_y: ViewOwned<'static, 1, _> =
ViewOwned::new_from_data(vec![0.0; length], Layout::Right, [length]);
black_box(&mut v_y); // prevents the first init to be optimized away
let execp = ExecutionPolicy {
space: ExecutionSpace::DeviceCPU,
Expand Down
6 changes: 5 additions & 1 deletion src/routines/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,12 @@ cfg_if::cfg_if! {
let chunk_size = n_items / num_cpus::get() + 1;
// leak indices so that they continue to exist during all threads execution
let indices = range.collect::<Vec<usize>>().leak();
// dispatch the kernel through raw pointers copies
let kernel_ptr = Box::into_raw(kernel);
let handles: Vec<_> = indices.chunks(chunk_size).map(|chunk: &'static [usize]| {
std::thread::spawn(|| chunk.iter().map(|idx_ref| KernelArgs::Index1D(*idx_ref)).for_each(kernel))
// rebuild the kernel from the copied raw pointer
let loc_kernel: ForKernelType<N> = unsafe { Box::from_raw(kernel_ptr) };
std::thread::spawn(|| chunk.iter().map(|idx_ref| KernelArgs::Index1D(*idx_ref)).for_each(loc_kernel))
}).collect();

for handle in handles {
Expand Down

0 comments on commit 588503b

Please sign in to comment.