CUDApp
CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.
Brought by drakestapleton
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note The epilogue of one tile row (or, when no element is recomputed, of adjacent rows packed as one; every element is |
| 3 | note independent) of the general GEMM (CUDApp#144, src/omega_gpu_gemm_ex.c l.428-439, store_c): |
| 4 | note v = alpha * a (a = 0 + P for one k part, else the k-part sum; the host recompute where flagged), plus beta * C |
| 5 | note when beta != 0 (a NaN beta counts), stored as f32, or RNE bf16 / f16 through the f64 to f32 round to odd. |
| 6 | note q: 0 nc (<= 4096), 1 c_type, 2 compute, 3 one part, 4 alpha f64 bits, 5 beta f64 bits. c holds the nc stored C |
| 7 | note elements of the row as halfwords (the C shell copies them in and out): one per bf16 / f16 element, the low then |
| 8 | note the high half of each f32 element; pv the nc P bits (binary32). Gives the elements recomputed (host_fixed). |
| 9 | note The q words are read once, into scalars: a store into the view c may alias q, so a q read inside the element |
| 10 | note loop would be read again after every store. |
| 11 | |
| 12 | note ms: bits 0-1 the c_type, bit 2 compute, bit 3 k-part sums (clear: one k part). |
| 13 | note the compute part of element j before alpha (called only with bit 2 set). For one k part a = 0 + P: that add gives |
| 14 | note P itself except -0 + 0 = +0 (IEEE 754 6.3, round to nearest; a NaN P stays the same quiet NaN), so the P bits |
| 15 | note 80000000 (2147483648) become 0 instead. |
| 16 | fn gx_ea pv view uint 16384 acc view ulong 4096 fix view ulong 4096 bad view uchar 4096 j ulong ms ulong to f64 |
| 17 | a = bitcast f64 get acc j |
| 18 | if eq and ms 8 0 |
| 19 | p = get pv j |
| 20 | if eq p uint 2147483648 |
| 21 | p = uint 0 |
| 22 | end |
| 23 | a = f64 bitcast f32 p |
| 24 | end |
| 25 | if ne get bad j 0 |
| 26 | a = bitcast f64 get fix j |
| 27 | end |
| 28 | ret a |
| 29 | end |
| 30 | |
| 31 | note the beta term and the store of element j as c_type (ms bits 0-1) |
| 32 | fn gx_eb c edit ushort 32768 j ulong ms ulong bt f64 v f64 to void |
| 33 | ct = and ms 3 |
| 34 | k = add j j |
| 35 | if ne bt bitcast f64 ulong 0 |
| 36 | if eq ct 0 |
| 37 | u = shl uint get c add k 1 16 |
| 38 | v = add v mul bt f64 bitcast f32 or u uint get c k |
| 39 | else |
| 40 | v = add v mul bt f64 gx_ldf ct uint get c j |
| 41 | end |
| 42 | end |
| 43 | u = bitcast uint f32 v |
| 44 | if eq ct 0 |
| 45 | put c k ushort and u 65535 |
| 46 | put c add k 1 ushort shr u 16 |
| 47 | else |
| 48 | u = bitcast uint gx_d2fo v |
| 49 | if eq ct 1 |
| 50 | u = gx_f2bf u |
| 51 | else |
| 52 | u = gx_f2h u |
| 53 | end |
| 54 | put c j ushort u |
| 55 | end |
| 56 | end |
| 57 | |
| 58 | fn gemm_ex_epi q view ulong 8 pv view uint 16384 acc view ulong 4096 fix view ulong 4096 bad view uchar 4096 c edit ushort 32768 to ulong |
| 59 | ms = get q 1 |
| 60 | if ne get q 2 0 |
| 61 | ms = or ms 12 |
| 62 | if ne get q 3 0 |
| 63 | ms = xor ms 8 |
| 64 | end |
| 65 | end |
| 66 | al = bitcast f64 get q 4 |
| 67 | bt = bitcast f64 get q 5 |
| 68 | n = ulong 0 |
| 69 | for j ulong get q 0 |
| 70 | if gt ms 3 |
| 71 | gx_eb edit c j ms bt mul al gx_ea view pv view acc view fix view bad j ms |
| 72 | if ne get bad j 0 |
| 73 | n = add n 1 |
| 74 | end |
| 75 | else |
| 76 | gx_eb edit c j ms bt bitcast f64 ulong 0 |
| 77 | end |
| 78 | end |
| 79 | ret n |
| 80 | end |