Repository navigation
Commit 07e646c
committed
GPU: give Metal its own spellings for two math helpers
GPUCA_CHOICE routes Metal down the OpenCL arm, and three of those spellings do
not exist in MSL. One of the three needs no Metal case: MSL has no nan() in any
form, but it does define NAN, and so does OpenCL -- a constant expression of
type float representing a quiet NaN -- so the shared arm uses that instead of
nan(0u).
remainder() does not exist either, and __builtin_remainderf is not a way around
it: that compiles, then fails to link against an undefined remainderf. MSL does
have fmod, which is exact, so Remainderf reduces with that and nudges the result
into [-|y|/2, |y|/2], rounding the quotient of a tie to even. It agrees with
remainderf bit for bit over six million samples, from the TwoPI wrapping its
only caller does up to |x| of 1e30, ties swept exhaustively for a power-of-two
divisor. Reducing as x - y * rint(x / y) would have been shorter, but x / y
rounds in float, so rint picks the wrong multiple outside a narrow range around
the divisor and the result is wrong almost everywhere else.
MSL's sincos returns the sine and takes the cosine by thread reference rather
than by pointer, and cannot write through the generic reference SinCos is given,
so the result goes via a local.
Host, CUDA, HIP and cling keep the GPUCA_CHOICE arms they had; OpenCL swaps
nan(0u) for NAN.1 parent c0d5eb7 commit 07e646c
1 file changed
Lines changed: 21 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | | - | |
| 108 | + | |
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| |||
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
248 | | - | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
249 | 263 | | |
250 | 264 | | |
251 | 265 | | |
| |||
302 | 316 | | |
303 | 317 | | |
304 | 318 | | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
305 | 324 | | |
306 | 325 | | |
307 | 326 | | |
| |||
0 commit comments