pub trait Backend: Send + Sync {
// Required methods
fn backend_type(&self) -> GpuBackend;
fn initialize(&mut self) -> Result<(), BackendError>;
fn device_count(&self) -> Result<u32, BackendError>;
fn device_capabilities(
&self,
device_id: u32,
) -> Result<DeviceCapabilities, BackendError>;
fn set_device(&mut self, device_id: u32) -> Result<(), BackendError>;
fn allocate(&self, size: usize) -> Result<DeviceMemory, BackendError>;
fn deallocate(&self, memory: DeviceMemory) -> Result<(), BackendError>;
fn copy_to_device(
&self,
src: &[u8],
dst: &DeviceMemory,
) -> Result<(), BackendError>;
fn copy_to_host(
&self,
src: &DeviceMemory,
dst: &mut [u8],
) -> Result<(), BackendError>;
fn synchronize(&self) -> Result<(), BackendError>;
fn launch_kernel(
&self,
kernel: &CompiledKernel,
args: &[KernelArg],
) -> Result<(), BackendError>;
}Expand description
Trait for GPU backend implementations
Required Methods§
Sourcefn backend_type(&self) -> GpuBackend
fn backend_type(&self) -> GpuBackend
Get backend type
Sourcefn initialize(&mut self) -> Result<(), BackendError>
fn initialize(&mut self) -> Result<(), BackendError>
Initialize the backend
Sourcefn device_count(&self) -> Result<u32, BackendError>
fn device_count(&self) -> Result<u32, BackendError>
Get device count
Sourcefn device_capabilities(
&self,
device_id: u32,
) -> Result<DeviceCapabilities, BackendError>
fn device_capabilities( &self, device_id: u32, ) -> Result<DeviceCapabilities, BackendError>
Get device capabilities
Sourcefn set_device(&mut self, device_id: u32) -> Result<(), BackendError>
fn set_device(&mut self, device_id: u32) -> Result<(), BackendError>
Set active device
Sourcefn allocate(&self, size: usize) -> Result<DeviceMemory, BackendError>
fn allocate(&self, size: usize) -> Result<DeviceMemory, BackendError>
Allocate memory on device
Sourcefn deallocate(&self, memory: DeviceMemory) -> Result<(), BackendError>
fn deallocate(&self, memory: DeviceMemory) -> Result<(), BackendError>
Free device memory
Sourcefn copy_to_device(
&self,
src: &[u8],
dst: &DeviceMemory,
) -> Result<(), BackendError>
fn copy_to_device( &self, src: &[u8], dst: &DeviceMemory, ) -> Result<(), BackendError>
Copy memory from host to device
Sourcefn copy_to_host(
&self,
src: &DeviceMemory,
dst: &mut [u8],
) -> Result<(), BackendError>
fn copy_to_host( &self, src: &DeviceMemory, dst: &mut [u8], ) -> Result<(), BackendError>
Copy memory from device to host
Sourcefn synchronize(&self) -> Result<(), BackendError>
fn synchronize(&self) -> Result<(), BackendError>
Synchronize device
Sourcefn launch_kernel(
&self,
kernel: &CompiledKernel,
args: &[KernelArg],
) -> Result<(), BackendError>
fn launch_kernel( &self, kernel: &CompiledKernel, args: &[KernelArg], ) -> Result<(), BackendError>
Launch kernel