#
…

2021-04-17

00:12DarkShadow44 has quit [Quit: Free ZNC ~ Powered by LunarBNC: https://LunarBNC.net]
00:13DarkShadow44 has joined #asahi-gpu
00:40odmir has quit [Remote host closed the connection]
00:41odmir has joined #asahi-gpu
00:45odmir has quit [Ping timeout: 240 seconds]
01:12odmir has joined #asahi-gpu
01:20Emantor has quit [Quit: ZNC - http://znc.in]
01:22Emantor has joined #asahi-gpu
01:30odmir has quit [Remote host closed the connection]
01:30odmir has joined #asahi-gpu
01:42bloompiles of ALU
01:47bloomdougall: hey, I have a reversing question for you
01:47bloomI'd like to know what the thresholds are for register usage --> thread occupancy
01:48bloomThe cmdstream just specifies register count/4, but that seems more fine grained than real hw would implement
01:48bloomBut! Apple docs talk about occupancy perf counters?
01:48bloomSo it ought to be able to figure out from the other direction like you've done with the cpu?
01:55bloomOh, even better maxTotalThreadsPerThreadgroup is literally in the Metal API. nice!
01:57bloom"Advanced Metal Shader Optimization" from WWDC'16 is still relevant :)
02:01bloom"the shader cores... feature a constant execution and prefetch"
02:04dougallhmm... yeah, i've been wanting to get at those counters, but i'm not quite sure how to approach it
02:07dougalli think a granularity of four is possibly correct... register granularity is observable by using out-of-range register ids. occupancy would be 'floor(total / round_up(register_count))' right?
02:08bloomPossibly, possibly not.
02:08bloomGranularity of 4 is almost certainly the allocation of registers
02:08bloombut that might not be the allocation of threads
02:09bloom(that could be granularity of 8 instead, for example. etc)
02:34Necrosporus has quit [Ping timeout: 252 seconds]
02:37robinp has quit [Read error: Connection reset by peer]
02:38robinp has joined #asahi-gpu
02:41odmir has quit [Remote host closed the connection]
02:47Necrosporus has joined #asahi-gpu
02:50phiologe has quit [Ping timeout: 250 seconds]
02:50phiologe has joined #asahi-gpu
02:52bloomnote to self: r5 appears preloaded with vertex id in vs
03:03blooma bit of a hunch looking at a funny shader I compiled -- looks like integer ALU issues 2 insructions at once, maybe?
03:03bloomthe way it schedules the scalarization of vec4 arithmetic is suggestive
03:10bloomdougall: Oh, ouch, embarassing - misread the sqrt op
03:10bloomthe thing I called sqrt, call it f(x)
03:10bloomit's actually sqrt(x) = f(x) * x
03:11bloomso it's in fact rsqrt
03:11bloombut we already.. had rsqrt
03:16dougall"Implemented as x * rsqrt(x) with special cases handled correctly" - so i guess how does sqrt(x) differ from x * rsqrt(x)?
03:16dougall(asside from precision)
03:17bloomProbably the usual suspects: NaN, Inf, signed zero
03:17bloomrsqrt(0) is probably NaN and NaN * 0 = NaN, yet sqrt(0) = 0
03:18bloomso rsqrt_special has to define rsqrt(0) to be finite (which is wrong)
03:18dougallah, yeah, that'd make sense :)
03:19bloomalso need sqrt(-0.0) = -0.0
03:19bloomwhich holds if we set rsqrt(-0.0) = 0.0 since 0.0 * -0.0 = -0.0
03:20bloomlikewise, we want sqrt(+inf) = +inf
03:20bloombut rsqrt(+inf) = 0.0 and 0.0 * +inf = NaN (indeterminate form)
03:21bloomSo rsqrt_special(+inf) needs to be some positive number.
03:41The_DarkFire_[m] has joined #asahi-gpu
03:46bloomdougall: Ok, I just r/e'd thread count
03:46bloomactually r/e is a stretch
03:46bloomJust dumped maxTotalThreadsPerThreadgroup and varied register pressure systematically
03:47dougallah, what's it look like?
03:48bloomSo, in terms of the "register quadwords" field in the cmdstream:
03:48bloom(call that Q)
03:48bloomIf Q <= 13, then you have 1024 threads.
03:50bloomIf Q >= 14, you have less. I was about to say I had the formula but my formula is buggy, hang on
03:50dougall(is one register quadword like r0-r3 or like r0l-r1h?)
03:52* bloomjust bruteforces
04:02bloomI guess that's a linear allocation, just a lot of rounding needed
04:03bloomSo.. a 192kb register file
04:05bloomit's past midnight i cant units
04:05dougallyeah, i think that all makes sense
04:06bloomnumbers still feel suspect.
04:06bloomWhat am I missing
04:07bloomSZ = (128*4)*384
04:07bloom>>> SZ / (29*16)
04:07bloom423.7241379310345
04:07bloomwhich is less than the 448 actually issues
04:08bloomI guess this is all of-by-one
04:13bloomIf you take SZ = 384 * (32 * 4 * 4), everything is too small except the biggest
04:13bloombut if you doubled that, you would expect the last thread count to double
04:13bloombut if you take SZ to be somewhere in betwee, everything rounds right
04:14bloom212992 = ((384 + 448)/2) * 32 * 4 * 4
04:14bloom^ smack int he middle
04:14bloomand indeed:
04:14bloom>>> { x: math.floor((SZ_ / (x*4*4)) / 64) * 64 for x in range(13, 32) }
04:14bloom{13: 1024, 14: 896, 15: 832, 16: 832, 17: 768, 18: 704, 19: 640, 20: 640, 21: 576, 22: 576, 23: 576, 24: 512, 25: 512, 26: 512, 27: 448, 28: 448, 29: 448, 30: 384, 31: 384}
04:15bloomExpanding out:
04:15bloommin(1024, math.floor((SZ_ / (math.ceil(reg_count / 4)*4*4)) / 64) * 64)
04:22bloomHere's a better formula
04:22bloomThe register file is M = 53248 words.
04:23bloomEvery thread requires R words from the register file.
04:23bloomThreads may only be dispatched in groups of 64.
04:23bloomNo more than 1024 threads may be dispatched.
04:24bloomTherefore, we may dispatch `min(1024, align_down(M / R, 64))` threads.
04:24bloom(where align_down(x, y) = floor(x / y) * y)
04:25mxw39 has quit [Ping timeout: 240 seconds]
04:25mxw39 has joined #asahi-gpu
04:26bloomPossible addendum: But threads can only require multiples of 4 word-sized registers.
04:27bloomTherefore, we may dispatch `min(1024, align_down(M / align_up(R, 4), 64))` threads.
04:27bloom(where align_up(x, y) = ceil(x / y) * y)
04:29method_ has joined #asahi-gpu
04:43bloom"total, the M1 GPU contains up to 128 EUs and 1024 ALUs,[12] which by Apple's claim can execute nearly 25,000 threads simultaneously"
04:43bloomI assume "nearly 25,000" is marketing speak for 1024 * 24 = 24576 threads
04:44bloomwhich means scaling our estimated size up by 24x to 212992 * 24 = 5111808 = 4.9 MB of register file on the M1 GPU!
04:49bloomStraight from the horse's mouth https://www.apple.com/mac/m1/
04:50dougallyeah... that number is right, but i'm a bit confused where the 24x comes from? like is the register file per-core? (i assume so, and that'd an 8x, but then where's the 3x?)
04:51bloomdougall: Can't tell.
04:51bloomBut the 24k is from apple's marketing
04:52bloomnot sure where the 3x is.
04:53dougallyeah, i'm quite confused... "128 execution units", so 16 per core? when a simd-group is 32? is that like AMDs thing where you just put each half through the pipeline over two cycles?
04:53bloomdunno where the 128 execution units comes from
04:53bloomsome of that is speculation from anandtech
04:54dougall(that's from the announcement video iirc)
04:54bloomOh, I see.
04:56method_interesting
04:56dougallyeah, i'm sure it'll make more sense as we figure more out, but definitely plenty of puzzles left :)
04:57blooma lot of this stuff is irrelevant/invisible to software
07:51vlixa has quit [Remote host closed the connection]
09:51vlixa has joined #asahi-gpu
12:00glibcoh, they don't use a fast sin at all? That's interesting indeed
12:28odmir has joined #asahi-gpu
15:31bloomOh, theres's a cute optimization I need to check the legitimacy of
15:32bloomIf two 16-bit values are in a packed register (r0l/r0h say) can we use bitop_mov on the 32-bit register (r0) for vectorization?
15:33bloomI bet so.
15:34bloomLikewise using mov_imm as a 32-bit thing
15:46* bloomspun up an optimizer for agx
15:46bloomhandles the core floating point stuff
16:00morelightning[m] has quit [Quit: Idle for 30+ days]
16:58artemist has joined #asahi-gpu
17:24odmir has quit [Remote host closed the connection]
17:25odmir has joined #asahi-gpu
17:30odmir has quit [Ping timeout: 240 seconds]
17:50odmir has joined #asahi-gpu
18:21m42uko has quit [Quit: Leaving.]
18:21m42uko has joined #asahi-gpu
19:50odmir has quit [Remote host closed the connection]
19:51odmir has joined #asahi-gpu
19:55odmir has quit [Ping timeout: 240 seconds]
20:25odmir has joined #asahi-gpu
20:55odmir has quit [Ping timeout: 240 seconds]
21:09odmir has joined #asahi-gpu
21:10vlixa has quit [Remote host closed the connection]
21:41vlixa has joined #asahi-gpu
21:43odmir has quit [Ping timeout: 268 seconds]
21:55odmir has joined #asahi-gpu
22:04odmir has quit [Remote host closed the connection]
22:05odmir has joined #asahi-gpu
22:34vlixa has quit [Remote host closed the connection]
22:38vlixa has joined #asahi-gpu
…