Support slice for device code
Revival of https://github.com/rust-accel/accel/pull/16
Objective
Slice patterns in the kernel arguments become to work, and make it safe function
#[kernel]
pub fn add(a: &[f64], b: &[f64], c: &mut [f64]) {
let i = accel_core::index() as usize;
if i < c.len() {
c[i] = a[i] + b[i];
}
}
Semantics
a, b, c and other slices are passed as a element length (in size, not byte) and a pointer of actual data. Pointer must be one of following:
- a device pointer (i.e. casted from
CUdeviceptr) - a host pointer which can be accessed from device directly.
- e.g. a host memory allocated by cuMemAllocHost
TODO
-
Add custom trait for device sendable to change its behavior for primitive types / slice -
DeviceSendtrait in !41 (merged)
-
-
Implement DeviceSendto&[T]and&mut [T] -
Test slice can be access from device code
Edited by termoshtt