spark_model/layers/kernel_probe.rs
1// SPDX-License-Identifier: AGPL-3.0-only
2
3//! Optional kernel lookups: the handle if the kernel is there, `0` if not —
4//! and, for a module only some targets compile, no lookup at all where it
5//! was never built.
6
7use spark_runtime::gpu::{GpuBackend, KernelHandle};
8
9/// Probe a kernel that only SOME targets compile — a Hopper-owned twin, a
10/// tensor-core tier the gb10 tree does not carry — without issuing a lookup
11/// on a target that never built the module. The boot audit records every
12/// failed lookup as a dispatch site on a silent fallback path and refuses to
13/// serve; a target that does not carry the source has no fallback to be
14/// silent about, it has its only path. Stack 1089308's first campaign found
15/// 17 such lookups on GB10 and could not boot. On a target that DOES carry
16/// the module this is exactly [`try_kernel`], audit included.
17#[track_caller]
18pub fn try_target_kernel(gpu: &dyn GpuBackend, module: &str, func: &str) -> KernelHandle {
19 if !gpu.has_module(module) {
20 return KernelHandle(0);
21 }
22 try_kernel(gpu, module, func)
23}
24
25#[track_caller]
26pub fn try_kernel(gpu: &dyn GpuBackend, module: &str, func: &str) -> KernelHandle {
27 match gpu.kernel(module, func) {
28 Ok(h) => h,
29 Err(_) => {
30 tracing::debug!("Optional kernel '{module}::{func}' not loaded");
31 KernelHandle(0)
32 }
33 }
34}
35
36#[cfg(test)]
37#[path = "kernel_probe_tests.rs"]
38mod kernel_probe_tests;