Expand description
Buffers.
Buffers store data, and can be arguments to kernels. Buffers on the host
store data inline, essentially as a Vec
or slice.
BufferBase
is a generic buffer. ScalarBufferBase
is a dynamically typed buffer.
§Example
use krnl::{anyhow::Result, device::Device, buffer::{Buffer, Slice, SliceMut}};
fn saxpy(x: Slice<f32>, alpha: f32, mut y: SliceMut<f32>) -> Result<()> {
if let Some((x, y)) = x.as_host_slice().zip(y.as_host_slice_mut()) {
for (x, y) in x.iter().copied().zip(y) {
*y += alpha * x;
}
return Ok(());
}
todo!()
}
fn main() -> Result<()> {
let x = vec![1f32];
let alpha = 2f32;
let y = vec![0f32];
let device = Device::builder().build().ok().unwrap_or(Device::host());
let x = Buffer::from(x).into_device(device.clone())?;
let mut y = Buffer::from(y).into_device(device.clone())?;
saxpy(x.as_slice(), alpha, y.as_slice_mut())?;
let y = y.into_vec()?;
println!("{y:?}");
Ok(())
}
Modules§
- Errors.
Structs§
ArcBuffer
representation.- A buffer.
Buffer
representation.ScalarArcBuffer
representation.- Dynamically typed buffer.
ScalarBuffer
representation.ScalarBuffer
representation.ScalarSlice
representation.SliceMut
representation.Slice
representation.
Enums§
CowBuffer
representation.ScalarCowBuffer
representation.
Traits§
- Marker trait for buffers.
- Marker trait for mutable buffers.
- Marker trait for owned buffers.
- Marker trait for scalar buffers.
- Marker trait for mutable scalar buffers.
- Marker trait for owned scalar buffers.
Type Aliases§
- ArcBuffer
- Buffer
- CowBuffer
- ScalarArcBuffer
- ScalarBuffer
- CowBuffer
- ScalarSlice
- ScalarSliceMut
- Slice
- SliceMut