Skip to main content

vulkane_kernel_text/
decline.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2//! Statements this emitter refuses **by name** because lowering them to a hardware operation on non-NVIDIA
3//! hardware risks infringing NVIDIA's patents. Twelve names: the four of board 434 C plus `CollectiveTuple` (CireSnave 2026-11-13) and the
4//! seven of its extension (CireSnave 2026-11-16).
5//!
6//! - Board 434 C, *"emitters may lower AsyncWait/CopyAsync/AsyncCommit/Collective for NVIDIA devices ... and decline by
7//!   name for non-NVIDIA devices"* (CireSnave 2026-11-13, "434: C."): `CopyAsync`, `AsyncCommit`, `AsyncWait` (NVIDIA
8//!   US11294713B2 and US12118382B2, an API that blocks a thread's instructions around an asynchronous shared-memory
9//!   copy; `unpopped` `docs/PATENT-SWEEP.md` hit 22) and `Collective`, and `CollectiveTuple`. `CollectiveTuple` is the tuple form of `Collective`: 434 C read as covering it; not named in the
10//!   ruling's list (pm-kernels 2026-11-17, PM no objection; rockfish, bonefish and fishstringer decline the family).
11//!
12//! CireSnave 2026-11-16, verbatim: *"For that patent, we add a note about the potential for infringement if
13//! non-Nvidia-specific emitters lower those operations to hardware ops and we ensure our projects' emitters for
14//! other manufacturers' hardware know about that and we consider ourselves not infringing."* and, for the second
15//! patent, *"I think we treat that patent like the others that are Nvidia-only. Add a note and specifically notify
16//! our non-Nvidia-emitter builders about the potential for infringement and not to."*
17//!
18//! Board 434 C extended (2026-11-16):
19//! - NVIDIA US11803380B2 (a synchronization barrier with an arrival counter, a phase and a hardware copy operator):
20//!   `MbarInit`, `MbarArrive`, `MbarCompleteTx`, `MbarWait`, `CopyBulk` (completes on an mbarrier) and
21//!   `Tcgen05Commit` (arrives on an mbarrier).
22//! - NVIDIA US12204897B2 and its continuation US12710961B2 (a wait on a count of pending matrix-multiply
23//!   operations): `WgmmaWait`.
24//!
25//! **Do not lower any of these to a hardware operation in this crate.** The walk below matches every [`Stmt`]
26//! variant explicitly and has no wildcard arm, so a new statement fails to compile here until someone decides which
27//! side of this list it is on.
28
29use unpopped::backend::LowerError;
30use unpopped::kernel::{Block, KernelFn, Stmt};
31
32/// The reason text the four board 434 C refusals carry, so a caller and a test can recognise it.
33pub const DECLINED_434C: &str = "declined: possible exposure, board 434 C";
34/// The reason text the seven board 434 C extended refusals carry.
35pub const DECLINED_434C_EXT: &str = "declined: possible exposure, board 434 C extended";
36
37/// The name of the first declined statement in `block` and the ruling text it carries, looking inside `If`, `For`
38/// and `While` at any depth.
39fn find(block: &Block) -> Option<Declined> {
40    block.0.iter().find_map(find_stmt)
41}
42
43/// A declined statement's name and the ruling text its refusal carries.
44type Declined = (&'static str, &'static str);
45
46fn find_stmt(stmt: &Stmt) -> Option<Declined> {
47    declined_434c(stmt)
48        .or_else(|| declined_extension(stmt))
49        .or_else(|| nested(stmt))
50}
51
52/// The five of board 434 C. The wildcard is fine here: exhaustiveness is enforced by [`nested`].
53fn declined_434c(stmt: &Stmt) -> Option<Declined> {
54    let name = match stmt {
55        Stmt::CopyAsync { .. } => "CopyAsync",
56        Stmt::AsyncCommit => "AsyncCommit",
57        Stmt::AsyncWait { .. } => "AsyncWait",
58        Stmt::Collective { .. } => "Collective",
59        Stmt::CollectiveTuple { .. } => "CollectiveTuple",
60        _ => return None,
61    };
62    Some((name, DECLINED_434C))
63}
64
65/// The seven of the 2026-11-16 extension, and `CopyUnpack` (unpopped 0.58: its own doc says the `CopyBulk` patent note applies and
66/// emitters for other manufacturers decline it).
67fn declined_extension(stmt: &Stmt) -> Option<Declined> {
68    let name = match stmt {
69        Stmt::MbarInit { .. } => "MbarInit",
70        Stmt::MbarArrive { .. } => "MbarArrive",
71        Stmt::MbarCompleteTx { .. } => "MbarCompleteTx",
72        Stmt::MbarWait { .. } => "MbarWait",
73        Stmt::CopyBulk { .. } => "CopyBulk",
74        Stmt::Tcgen05Commit { .. } => "Tcgen05Commit",
75        Stmt::WgmmaWait { .. } => "WgmmaWait",
76        Stmt::CopyUnpack { .. } => "CopyUnpack",
77        _ => return None,
78    };
79    Some((name, DECLINED_434C_EXT))
80}
81
82/// Look inside `If`, `For` and `While`. **This match has no wildcard arm on purpose**: it names every [`Stmt`] variant,
83/// so a new statement in `unpopped` fails to compile here until someone decides which side of the declined list it is
84/// on. The declined ones are listed (and answered `None`: they were already found by the two functions above).
85fn nested(stmt: &Stmt) -> Option<Declined> {
86    match stmt {
87        Stmt::If { then, els, .. } => find(then).or_else(|| find(els)),
88        Stmt::For { body, .. } | Stmt::While { body, .. } => find(body),
89        // The declined statements (found above, and none holds a block).
90        Stmt::CopyAsync { .. }
91        | Stmt::AsyncCommit
92        | Stmt::AsyncWait { .. }
93        | Stmt::Collective { .. }
94        | Stmt::CollectiveTuple { .. }
95        | Stmt::MbarInit { .. }
96        | Stmt::MbarArrive { .. }
97        | Stmt::MbarCompleteTx { .. }
98        | Stmt::MbarWait { .. }
99        | Stmt::CopyBulk { .. }
100        | Stmt::Tcgen05Commit { .. }
101        | Stmt::WgmmaWait { .. }
102        | Stmt::CopyUnpack { .. }
103        // Every other statement is not declined by name here.
104        | Stmt::Let { .. }
105        | Stmt::Load { .. }
106        | Stmt::Assign { .. }
107        | Stmt::Store { .. }
108        | Stmt::MaskedLoad { .. }
109        | Stmt::MaskedStore { .. }
110        | Stmt::Break
111        | Stmt::Continue
112        | Stmt::Return
113        | Stmt::Barrier { .. }
114        | Stmt::AtomicRmw { .. }
115        | Stmt::AtomicCas { .. }
116        | Stmt::MulticastLoadReduce { .. }
117        | Stmt::GridDepWait
118        | Stmt::GridDepLaunchDependents
119        | Stmt::ProxyFence { .. }
120        | Stmt::Fence { .. }
121        | Stmt::Mma { .. }
122        | Stmt::MatrixLoad { .. }
123        | Stmt::MatrixStore { .. }
124        | Stmt::Wgmma { .. }
125        | Stmt::WgmmaCommit
126        | Stmt::Tcgen05Mma { .. }
127        | Stmt::Tcgen05Ld { .. }
128        | Stmt::Tcgen05Alloc { .. }
129        | Stmt::Tcgen05Dealloc { .. }
130        | Stmt::Tcgen05RelinquishPermit
131        | Stmt::Call { .. }
132        | Stmt::CallTuple { .. }
133        | Stmt::ExternCall { .. } => None,
134    }
135}
136
137/// The by-name refusal of the first declined statement in `kernel` (at any depth), or `None`.
138///
139/// `backend` is the name used in the text (`glsl`, `wgsl`).
140#[must_use]
141pub fn declined_by_name(backend: &str, kernel: &KernelFn) -> Option<LowerError> {
142    let (name, ruling) = find(&kernel.body)?;
143    Some(LowerError::UnsupportedKernel {
144        detail: format!(
145            "backend `{backend}` refuses `Stmt::{name}` by name ({ruling}); it is not lowered to a hardware operation on non-NVIDIA hardware (kernel `{}`)",
146            kernel.name
147        ),
148    })
149}