interplane.Get Omega
Read in your language

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

branch main Branches Tags History

CUDApp / om / gemmex / epi.om

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