Skip to main content

ruccl/in_process/
device.rs

1use std::error::Error;
2
3pub trait InProcessDevice<T> {
4    type Context: Clone + Send + Sync + 'static;
5    type Buffer: Clone + Send + Sync + 'static;
6    type Kernel: Clone + Send + Sync + 'static;
7    type ReductionLaunch;
8    type Error: Error + Send + Sync + 'static;
9
10    const ELEMENT_SIZE: usize;
11    fn buffer_len(buffer: &Self::Buffer) -> usize;
12    fn buffer_is_empty(buffer: &Self::Buffer) -> bool;
13
14    fn alloc(context: &Self::Context, length: usize) -> Result<Self::Buffer, Self::Error>;
15    fn copy_to_device(
16        context: &Self::Context,
17        buffer: &Self::Buffer,
18        values: &[T],
19    ) -> Result<(), Self::Error>;
20    fn copy_to_device_at(
21        context: &Self::Context,
22        buffer: &Self::Buffer,
23        offset: usize,
24        values: &[T],
25    ) -> Result<(), Self::Error>;
26    fn copy_from_device(
27        context: &Self::Context,
28        buffer: &Self::Buffer,
29    ) -> Result<Vec<T>, Self::Error>;
30    fn copy_from_device_at(
31        context: &Self::Context,
32        buffer: &Self::Buffer,
33        offset: usize,
34        length: usize,
35    ) -> Result<Vec<T>, Self::Error>;
36    fn prepare_reduction(length: u32, destination_offset: u32) -> Self::ReductionLaunch;
37    fn launch_reduction(
38        context: &Self::Context,
39        kernel: &Self::Kernel,
40        launch: &Self::ReductionLaunch,
41        source: &Self::Buffer,
42        destination: &Self::Buffer,
43    ) -> Result<(), Self::Error>;
44}