vulkane_kernel_text/
coverage.rs1use unpopped::kernel::Stmt;
5
6#[derive(Clone, Debug, PartialEq, Eq)]
8pub enum Coverage {
9 Lowered,
11 Row(&'static str),
13 Patent,
15 Nvidia(&'static str),
17}
18
19#[must_use]
22pub fn coverage(stmt: &Stmt) -> Coverage {
23 match stmt {
24 Stmt::Let { .. }
25 | Stmt::Load { .. }
26 | Stmt::Assign { .. }
27 | Stmt::Store { .. }
28 | Stmt::MaskedLoad { .. }
29 | Stmt::MaskedStore { .. }
30 | Stmt::If { .. }
31 | Stmt::For { .. }
32 | Stmt::While { .. }
33 | Stmt::Break
34 | Stmt::Continue
35 | Stmt::Return
36 | Stmt::Barrier { .. }
37 | Stmt::Fence { .. }
38 | Stmt::AtomicRmw { .. }
39 | Stmt::AtomicCas { .. } => Coverage::Lowered,
40 Stmt::Call { .. } | Stmt::CallTuple { .. } | Stmt::ExternCall { .. } => {
41 Coverage::Row("ROADMAP row 8g: device function calls are not lowered yet")
42 }
43 Stmt::Mma { .. } | Stmt::MatrixLoad { .. } | Stmt::MatrixStore { .. } => Coverage::Row(
44 "ROADMAP row 8j: matrix multiply-accumulate waits on a device with the extension (SPIR-V, GLSL) and on Unpopped's tile statements (Metal)",
45 ),
46 Stmt::CopyAsync { .. }
47 | Stmt::AsyncCommit
48 | Stmt::AsyncWait { .. }
49 | Stmt::Collective { .. }
50 | Stmt::CollectiveTuple { .. }
51 | Stmt::MbarInit { .. }
52 | Stmt::MbarArrive { .. }
53 | Stmt::MbarCompleteTx { .. }
54 | Stmt::MbarWait { .. }
55 | Stmt::CopyBulk { .. }
56 | Stmt::Tcgen05Commit { .. }
57 | Stmt::WgmmaWait { .. }
58 | Stmt::CopyUnpack { .. } => Coverage::Patent,
59 Stmt::Wgmma { .. } | Stmt::WgmmaCommit => Coverage::Nvidia(
60 "a warpgroup-level asynchronous matrix multiply-accumulate (PTX `wgmma`, Hopper); none of SPIR-V, GLSL, HLSL, WGSL or MSL has a construct with its asynchronous warpgroup semantics",
61 ),
62 Stmt::Tcgen05Mma { .. }
63 | Stmt::Tcgen05Ld { .. }
64 | Stmt::Tcgen05Alloc { .. }
65 | Stmt::Tcgen05Dealloc { .. }
66 | Stmt::Tcgen05RelinquishPermit => Coverage::Nvidia(
67 "a fifth-generation tensor-core operation on tensor memory (PTX `tcgen05`, Blackwell); no target language of this repository has tensor memory",
68 ),
69 Stmt::ProxyFence { .. } => Coverage::Nvidia(
70 "an async-proxy fence (PTX `fence.proxy.async`, as unpopped documents `ProxyFence`): it orders generic-proxy writes against the asynchronous proxy that `CopyBulk` and `wgmma` use; no target language of this repository has memory proxies",
71 ),
72 Stmt::GridDepWait | Stmt::GridDepLaunchDependents => Coverage::Nvidia(
73 "CUDA programmatic dependent launch (a kernel waiting on, or releasing, the next kernel of a stream); a Vulkan dispatch has no in-kernel dependency on another dispatch",
74 ),
75 Stmt::MulticastLoadReduce { .. } => Coverage::Nvidia(
76 "an NVLink multicast load-reduce (PTX `multimem`) over several devices' memory; no target language of this repository addresses another device's memory",
77 ),
78 }
79}
80
81#[must_use]
84pub fn not_lowered_note(stmt: &Stmt) -> Option<String> {
85 match coverage(stmt) {
86 Coverage::Lowered => None,
87 Coverage::Row(why) => Some(why.to_string()),
88 Coverage::Patent => Some(
89 "refused by name for possible patent exposure (board 434 C), see `declined_by_name`"
90 .to_string(),
91 ),
92 Coverage::Nvidia(why) => Some(format!("NVIDIA-specific: {why}")),
93 }
94}
95
96#[cfg(test)]
97mod tests {
98 use super::*;
99 use unpopped::exec::Scope;
100 use unpopped::kernel::{BarrierKind, Stmt};
101
102 #[test]
103 fn the_cheap_to_build_variants_are_classified_as_documented() {
104 assert_eq!(coverage(&Stmt::Break), Coverage::Lowered);
105 assert_eq!(
106 coverage(&Stmt::Barrier {
107 scope: Scope::Block,
108 kind: BarrierKind::Full
109 }),
110 Coverage::Lowered
111 );
112 assert_eq!(coverage(&Stmt::AsyncCommit), Coverage::Patent);
113 for s in [
114 Stmt::WgmmaCommit,
115 Stmt::GridDepWait,
116 Stmt::GridDepLaunchDependents,
117 ] {
118 assert!(
119 matches!(coverage(&s), Coverage::Nvidia(why) if !why.is_empty()),
120 "{s:?}"
121 );
122 }
123 }
124
125 #[test]
126 fn a_lowered_statement_has_no_note_and_the_others_say_why() {
127 assert_eq!(not_lowered_note(&Stmt::Return), None);
128 let n = not_lowered_note(&Stmt::GridDepWait).expect("a note");
129 assert!(
130 n.contains("NVIDIA-specific") && n.contains("dependent launch"),
131 "{n}"
132 );
133 let p = not_lowered_note(&Stmt::AsyncCommit).expect("a note");
134 assert!(p.contains("board 434 C"), "{p}");
135 }
136}