Skip to main content

Module kernel

Module kernel 

Source
Expand description

Core trait definitions for the kernel dispatch system.

Kernel is a marker trait that associates typed input/output with a compute operation. KernelDispatch<K> is implemented by each concrete backend device (CudaDevice, VulkanDevice, CpuDevice) and by DeviceBackend itself, so callers never need to name the backend:

let output = backend.run::<CompareScore>(input)?;

§Adding a new kernel

  1. Create src/kernels/my_kernel.rs, define a marker struct + typed Input/Output and impl Kernel for MyKernel.
  2. For CUDA add src/backend/cuda/launch/my_kernel.rs with impl KernelDispatch<MyKernel> for CudaDevice.
  3. Add the CPU fallback impl KernelDispatch<MyKernel> for CpuDevice in src/backend/cpu/launch/my_kernel.rs.
  4. Add impl KernelDispatch<MyKernel> for DeviceBackend in src/backend/mod.rs (a match that delegates to the above).
  5. Register the new kernel in build.rs so it gets compiled to PTX.

Traits§

Kernel
Marker trait that binds typed Input and Output to a compute operation.
KernelDispatch
Execute kernel K on self.