pub trait Kernel: Send {
// Required method
fn execute(
&self,
inputs: &[TensorView<'_>],
outputs: &mut [TensorMut<'_>],
) -> Result<()>;
// Provided methods
fn set_constant_inputs(&mut self, constant_inputs: &[bool]) { ... }
fn execute_with_inputs(
&self,
inputs: &[KernelInput<'_>],
outputs: &mut [TensorMut<'_>],
) -> Result<()> { ... }
fn estimated_flops(&self) -> Option<u64> { ... }
fn view_outputs(
&self,
inputs: &[TensorView<'_>],
num_outputs: usize,
) -> Option<Vec<ViewOutput>> { ... }
fn supports_strided_input(&self, input_idx: usize) -> bool { ... }
fn preferred_output_layout(&self) -> Option<TensorLayout> { ... }
fn capture_support(&self) -> CaptureSupport { ... }
fn cuda_graph_compatible(&self) -> bool { ... }
}Expand description
A kernel ready to execute a specific op with specific shapes (§4.2).
Required Methods§
Provided Methods§
Sourcefn set_constant_inputs(&mut self, constant_inputs: &[bool])
fn set_constant_inputs(&mut self, constant_inputs: &[bool])
Tell the kernel which positional inputs are immutable graph constants.
The session calls this exactly once, immediately after construction. Kernels may use it to prepack or memoize those inputs. Runtime inputs must never be marked constant: caching them would return stale results.
Sourcefn execute_with_inputs(
&self,
inputs: &[KernelInput<'_>],
outputs: &mut [TensorMut<'_>],
) -> Result<()>
fn execute_with_inputs( &self, inputs: &[KernelInput<'_>], outputs: &mut [TensorMut<'_>], ) -> Result<()>
Execute through the general weight-delivery seam.
The default adapter accepts only resident tensor inputs and forwards to
Kernel::execute, so existing EPs compile and behave identically.
Paging-aware kernels override this method to consume lazy handles.
Sourcefn estimated_flops(&self) -> Option<u64>
fn estimated_flops(&self) -> Option<u64>
Estimated FLOPs, if known (for the cost model).
Sourcefn view_outputs(
&self,
inputs: &[TensorView<'_>],
num_outputs: usize,
) -> Option<Vec<ViewOutput>>
fn view_outputs( &self, inputs: &[TensorView<'_>], num_outputs: usize, ) -> Option<Vec<ViewOutput>>
Attempt to express this node’s outputs as zero-copy ViewOutputs over
its inputs instead of computing bytes (the layout/movement-op fast path).
inputs carries the real (possibly already-strided) input views and
num_outputs is the node’s output arity. Returning:
None— the default — means “compute normally”: the executor allocates output buffers and callsKernel::execute.Some(specs)means every output is a view;specs.len()MUST equalnum_outputs. A kernel that can view some but not all outputs must returnNone(all-or-nothing) so correctness never regresses.
When Some is returned, Kernel::execute is not invoked.
Sourcefn supports_strided_input(&self, input_idx: usize) -> bool
fn supports_strided_input(&self, input_idx: usize) -> bool
Whether the kernel accepts a non-contiguous (strided) input at idx.
Sourcefn preferred_output_layout(&self) -> Option<TensorLayout>
fn preferred_output_layout(&self) -> Option<TensorLayout>
The layout the kernel writes most efficiently, if it has a preference.
Sourcefn capture_support(&self) -> CaptureSupport
fn capture_support(&self) -> CaptureSupport
Whether this kernel can participate in device-graph capture.
The provided default is supported because capture is a runtime/EP capability: kernels that need restrictions override this method and return the exact failed precondition.
Sourcefn cuda_graph_compatible(&self) -> bool
fn cuda_graph_compatible(&self) -> bool
Compatibility shim for existing CUDA-graph callers.
New capture gates must use Kernel::capture_support so a decline
reason is never discarded.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".