Sub-views of CudaSlices
coreylowman opened this issue · comments
Would be similar to slices of Vecs.
Ideal interface would be:
let a: CudaSlice<f32> = ...;
let b: CudaSlice<f32> = a.offset(123);
where offset would panic if there aren't enough elements, otherwise make a copy of the device pointer.
Scenarios to figure out:
let a: CudaSlice<f32> = ...;
let b: CudaSlice<f32> = a.offset(123);
drop(a);
// b should still be valid here, so the underlying device pointer should not be dropped
It might not be sound to return CudaSlice instances. e.g.:
let a: CudaSlice<f32> = dev.alloc_zeros_async(1000);
let mut b: CudaSlice<f32> = a.slice(100..200);
let mut c: CudaSlice<f32> = a.slice(150..300);
f.launch_async(cfg, (&mut b, &mut c));
would mutate the same indices of b and c.
would be safer to do something like:
let a: CudaSlice<f32> = dev.alloc_zeros_async(1000);
let mut b: &CudaView<f32> = a.slice(100..200);
let mut c: &mut CudaView<f32> = a.slice_mut(150..300);
f.launch_async(cfg, (&mut b, &mut c));
Perhaps add/slice could return something like a Cow object?