Repository navigation
Commit 170d0ce
committed
GPU: add an emulated binary64 and a selector for GPUdoubleCalc
GPUdoubleCalc now names one of four representations, chosen by GPUCA_DOUBLECALC:
hardware double, plain float, the compensated two-float type, or a full IEEE-754
binary64 in software. The default is unchanged, double everywhere except Metal
and the two-float type there, so this is a no-op for every existing build. It
replaces GPUCA_FORCE_DOUBLECALC and GPUCA_FORCE_FLOATCALC, which could only
express two of the four.
The binary64 emulation is round to nearest even with subnormals, infinities and
NaNs, and correctly rounded division; NaN propagation follows the ARM64 order so
an Apple host is a reference down to the payload. It is not for production: over
the whole propagateTo kernel on an M1 Max it costs of the order of a hundred
times plain float, against roughly two for the two-float type. It is here because it
reproduces the CPU result exactly -- every covariance element bit-identical --
which turns a disagreement between Metal and the CPU into a search over code
rather than over numerics.
Measured on that kernel, 524288 tracks with strongly correlated covariances,
median of ten runs, error as |dC_ij| / sqrt(C_ii C_jj) against the CPU double
result: plain float 0.108 ns and 1.2e-5, two-float 0.256 ns and 5.6e-7, binary64
12.2 ns and zero. Only the binary64 kernel is unstable run to run, between 9.1
and 12.3 ns; the others vary by a few percent. For scale, the CPU double result
is itself 1.1e-6 from a cancellation-free reference, so the two-float type is
already at the noise floor of the formula.
For scale in the other direction, the same propagateTo on this machine's CPU,
where double is native, costs 23.5 ns in float and 27.1 ns in double, so real
hardware double is a 1.15x proposition. None of this arithmetic would be needed
if Metal had it.
Validated against hardware double on 9M operand pairs per operation, over uniform
bit patterns, near-equal exponents, the subnormal band, sparse mantissas for the
exact and halfway cases, the special values and track-like magnitudes, plus 4M
conversions each way: no mismatches.
The arithmetic must stay out of line on Metal. Inlined into a kernel it drops the
occupancy and runs two to five times slower than the call.1 parent 7d739bc commit 170d0ce
3 files changed
Lines changed: 433 additions & 13 deletions
File tree
- DataFormats/Reconstruction/src
- GPU/Common
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1087 | 1087 | | |
1088 | 1088 | | |
1089 | 1089 | | |
1090 | | - | |
| 1090 | + | |
1091 | 1091 | | |
1092 | 1092 | | |
1093 | 1093 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
194 | 195 | | |
195 | 196 | | |
196 | 197 | | |
197 | | - | |
198 | | - | |
199 | | - | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
200 | 201 | | |
201 | 202 | | |
202 | 203 | | |
203 | 204 | | |
204 | 205 | | |
205 | 206 | | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
211 | 241 | | |
212 | | - | |
| 242 | + | |
213 | 243 | | |
214 | | - | |
215 | | - | |
| 244 | + | |
| 245 | + | |
216 | 246 | | |
217 | | - | |
| 247 | + | |
218 | 248 | | |
219 | 249 | | |
220 | 250 | | |
| |||
0 commit comments