1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
//! GPU substrate for de-nested cubic-cell **derivative moments**.
//!
//! This module is the shared GPU evaluator for the de-nested cubic transport
//! kernel that currently lives in `src/families/cubic_cell_kernel.rs`. For
//! each partition cell `(left, right, c_0, c_1, c_2, c_3)` it computes the
//! derivative-moment vector
//!
//! ```text
//! M_k = ∫_{left}^{right} z^k · exp(-q(z)) dz, k = 0..=max_degree,
//! q(z) = 0.5 · (z² + η(z)²),
//! η(z) = c_0 + c_1·z + c_2·z² + c_3·z³.
//! ```
//!
//! Three branches feed into the same device API:
//!
//! * **Affine** (`c_2 = c_3 = 0`, finite interval): closed-form via the
//! `T_n(a,b)` recurrence used by `affine_anchor_moment_vector_into`.
//! * **Non-affine finite**: fixed 384-point Gauss–Legendre on the cell.
//! * **Affine tail**: closed-form on a semi-infinite (or whole-line) interval.
//!
//! This is **distinct** from `src/gpu/cubic_bspline_moments.rs`, which
//! computes tensor B-spline cell moments. The two modules share neither math
//! nor data layout: do not conflate them.
//!
//! ## Layout
//!
//! * [`branch`] — host-side branch classifier; mirrors
//! `cubic_cell_kernel::branch_cell` + the semi-infinite tail logic of
//! `evaluate_cell_state_dispatched`.
//! * `tests_host_substrate` — test-only CPU oracle for device-kernel parity.
//! * [`kernel_src`] — NVRTC-compilable CUDA C++ source as Rust string
//! constants (D9 / D15 / D21 specializations).
//! * [`device`] — Linux+CUDA dispatcher that classifies each cell once,
//! compiles and launches the all-branch NVRTC kernel, and leaves moments
//! device-resident for the consuming row kernel.
// The branch classifier feeds only the CUDA dispatcher below, so off-Linux it
// has no caller and `-D dead-code` rejects the whole module (the break that
// has been failing the macOS/Windows wheel jobs). Gate it with its consumer.
pub
pub
// The host oracle exercises the Linux-only substrate items, so it is gated with
// them; stacked attributes read as AND.
pub
use GpuError;
/// Maximum derivative-moment degree the substrate is built to evaluate.
///
/// Consumers and their high-water marks:
/// * Bernoulli flex Hessian: 9
/// * BMS outer higher-derivative reuse: 21
/// * Survival flex Hessian (with `D_uv` cross terms): 24
// Consumed by the CUDA device dispatcher (`device`, Linux-only) and by the
// host-substrate/ABI test oracles. Off-Linux the lib target has no caller, so
// `-D dead-code` rejects it — the break that has been failing the macOS and
// Windows wheel jobs. Gate to the platform that owns the callers instead of
// suppressing the lint; the oracles that exercise it are gated alongside it.
pub const MAX_SUPPORTED_DEGREE: usize = 24;
/// A single de-nested cubic-cell payload in the layout the device kernels
/// consume. Matches the CPU layout in `cubic_cell_kernel.rs`: the cubic
/// correction `η(z) = c_0 + c_1·z + c_2·z² + c_3·z³` evaluated over
/// `[left, right]`.
pub
/// Canonical branch classification encoded for the all-branch device kernel.
// Consumed by the CUDA device dispatcher (`device`, Linux-only) and by the
// host-substrate/ABI test oracles. Off-Linux the lib target has no caller, so
// `-D dead-code` rejects it — the break that has been failing the macOS and
// Windows wheel jobs. Gate to the platform that owns the callers instead of
// suppressing the lint; the oracles that exercise it are gated alongside it.
pub
/// Typed per-cell status decoded from the device kernel ABI.
// Consumed by the CUDA device dispatcher (`device`, Linux-only) and by the
// host-substrate/ABI test oracles. Off-Linux the lib target has no caller, so
// `-D dead-code` rejects it — the break that has been failing the macOS and
// Windows wheel jobs. Gate to the platform that owns the callers instead of
// suppressing the lint; the oracles that exercise it are gated alongside it.
pub
/// Host-side input view for `try_build_cubic_cell_derivative_moments`.
/// The substrate borrows cell data from the caller and owns branch
/// classification so callers cannot drift from the kernel's tolerance.
// Consumed by the CUDA device dispatcher (`device`, Linux-only) and by the
// host-substrate/ABI test oracles. Off-Linux the lib target has no caller, so
// `-D dead-code` rejects it — the break that has been failing the macOS and
// Windows wheel jobs. Gate to the platform that owns the callers instead of
// suppressing the lint; the oracles that exercise it are gated alongside it.
pub
/// Device-resident output of `try_build_cubic_cell_derivative_moments`.
pub
/// Try to build derivative moments via the substrate.
///
/// On Linux+CUDA, the dispatcher classifies every cell through the canonical
/// CPU predicate, launches the all-branch NVRTC kernel, and returns one
/// device-resident output. Runtime absence at this already-selected device
/// boundary is a typed error, never host substitution.
///
/// Returns `Ok(None)` only when the workload is empty.
///
pub