Mojo on the graphics card: the first idea
A GPU kernel is a small function that runs on thousands of threads at once. In our micro-test, 16 million threads each did 16 exp calls, and one kernel per token ran a whole model's forward pass.
Posts with this tag: 4
A GPU kernel is a small function that runs on thousands of threads at once. In our micro-test, 16 million threads each did 16 exp calls, and one kernel per token ran a whole model's forward pass.
A matrix multiplication is rows times columns, added up. Our hand-written fp16 version on an RX 7900 XTX ran ahead of AMD's own library at ten square sizes, from 1.01 times at 256 to 1.35 times at 1536.
An integer dot product and a subgroup reduction each cut the GEMV time by 10 percent at 4096 by 4096 and the integer one cut the energy per GEMV by 16 percent. Two other lines of attack were invalid or no faster, and a llama.cpp kernel wins one shape only with a different output.
On our 7900 XTX, 55 to 68 percent of flash attention's wave cycles went to the LDS, a small shared memory. Packing the intermediate results into registers cut the forward kernel by 22 to 24 percent and the dq kernel by 17 percent, byte for byte equal. A fused backward kernel was withdrawn on arithmetic.