6 ms·
Writing Speed-of-Light Flash Attention for 5090 in CUDA C++
- doctorpangloss 1y agoHmm, but supposing the accelerated NVIDIA specific inference data types were available for Triton, then you would just use that? Why not contribute to Triton, they accept PRs? Like so what if you do free product ecosystem development for NVIDIA and giant corporations by contributing to Triton?
- qeternity 1y agoSecond line of the post: > The main objective is to learn writing attention in CUDA C++, since many features are not available in Triton, such as MXFP8 / NVFP4 MMA for sm120.
- doctorpangloss 1y agoYes… I read it. If the feature is missing, why not contribute it instead?
- almostgotcaught 1y agoHow many PRs do you have landed in Triton that you can just blithely say "contribute it"?
- saagarjha 1y agoI mean, you can look at the most recent commit and see that the infrastructure is being built out for this right now (of course OpenAI doesn't care about sm_120, though).
- almostgotcaught 1y agoi don't know what this comment has to do with my point that OAI doesn't take commits from randoms, especially for infra code.
- saagarjha 1y agoYeah they do
- doctorpangloss 1y agoBy all means, the guy could have written the triton fixes he needs and NOT sent it up stream. It would still make more sense to do that! He’s obviously an expert, and I was sincerely wondering, why bother with the C++ stuff if he already knew the better way, and also has the chops to implement it?
- almostgotcaught 1y agoThere's an enormous difference between writing kernels and writing compiler infra.
- steinvakt2 1y agoI had a 5090 some months ago but couldnt get flash attention to work. Does it now work natively? What about 5080?
- sigmoid10 1y agoPytorch now has native support for the Blackwell architecture: https://pytorch.org/blog/pytorch-2-7/ https://pytorch.org/blog/pytorch-2-7/
- SynasterBeiter 1y agoIt does, but the performance is pretty bad, worse than Hopper.
- zackangelo 1y agoCurious what issues you were having. The kernel should compile natively if you pass nvcc the correct arch flags, although it probably won't take advantage of any new hardware features.
- saagarjha 1y agoHigh-performance GPU code typically uses nonportable features that are not supported across generations.
- ProofHouse 1y agoDamn awesome. This going to take me 3 reads and a week to digest
- neilmovva 1y agoI was surprised to see 5090's theoretical BF16 TFLOPs at just 209.5. That's not even 10% of the server Blackwell (B200 is 2250, and GB200 is 2500). B200 costs around $30-40k per GPU, so they are pretty close in performance per dollar. Starting with 4090, NVIDIA limits the performance of tensor cores on gaming cards, specifically for ops that might be used in ML training. FP8 and FP16 matmuls run at full speed if accumulating in FP16 (I've never seen anyone use this), but only half speed when accumulating in FP32. This restriction is not present for lower precision matmuls like FP4, and is removed entirely on the workstation-class cards like RTX Pro 6000. It doesn't seem worth it to use NVIDIA gaming cards as a "cheaper FLOPs" alternative anymore (e.g. diffusion models could have been cheaper to run on 3090 than A100). They are generous with memory bandwidth though, nearly 2TB/s on 5090 is amazing!
- steinvakt2 1y agoIsn't 5090 FE (roughly 2500 USD in my country) pretty good FLOP value? 32 GB VRAM (and flash attention pushes it even faster compared to apple/mps relatively cheap "vram")
- neilmovva 1y agoNot really: 5090: 210 TF / $2k == 105 TF/$k B200: 2250 TF / $40k == 56 TF/$k Getting only 2x the FLOPs per dollar probably isn't worth the hassle of having to rack 10x as many GPUs, while having no NVLink.
- lossolo 1y agoOne of the reasons they removed NVLink from consumer cards (they supported it before). There’s also an issue with power consumption (1xB200 vs 10x5090)
- steinvakt2 1y agoSure, but when spending 20x more, getting almost twice the compute per buck seems expected
- 1y ago
- Scene_Cast2 1y agoMy issue with upgrading to the 5090 for workstation ML use is that it both has higher TDP than the 4090 and it can only be limited to 70% power (not 50% like the 4090).
- saagarjha 1y ago> Due to improvements in newer hardware, you might need to use more tricks to reach Speed-of-Light on older GPUs e.g. pipeline shared memory to register memory data movements. On the contrary, older GPUs are a lot easier to hit rooflines on. Newer GPUs run so fast that they keep adding new tricks to remove bottlenecks. Not to discount the author's work here but a 5090 is pretty bad on the FLOPs/memory bandwidth ratio so it's comparatively easier to get throttled by tensor cores there; on datacenter hardware your tensor cores are so fast that you'll hit limits that were glossed over here. For example, using Ampere "mma" instructions won't cut it, because they compute a really small MMA and force your input to live in registers. You'll need TMA to get data into shared memory and wmma to do a matrix multiply out of them. At those speeds you will run into issues with dispatching instructions and computing addresses (and doing out-of-bounds calculation) fast enough that you will need to offload it to specialized hardware to keep up with the tensor cores.
- a_t48 1y agoDefinitely going to save this for later and come back to it after I get some more CUDA experience under my belt. It feels so nice right now making nice beautiful to use pipeline code w/ npp and some CUDA kernels here and there, the code is much faster than what it's replacing, but then I look at this guy getting down into the weeds of memory bank contention, prefetching, loop invariance, etc. Makes me feel like I'm playing with LEGO, I'm a little jealous. The tip that Nsight can run on Mac over SSH is great, too. I've been capturing and viewing data over RDP, basically, will have to give it a shot next week.