(评论)
(comments)

原始链接: https://news.ycombinator.com/item?id=43179478

cublaslt在NVIDIA GPU(例如H200)(类似于H100的性能)上启用FP8混合精液计算,但具有多个约束,包括有限的支持的FP8类型组合和transpappy Matrix A布局要求。使用E4M3 FP8格式的基准测试达到了大约1.35 PETA-OPS的峰值,用于方形矩阵,约占广告的密集GEMM性能的67%。 钥匙优化涉及在FP8 GEMM期间在FFMA(融合乘以ADD)指令中操纵“产量”位。这使GPU的经线调度程序可以更频繁地在WARPS之间切换,从而改善吞吐量。优化对FP8计算特别有益,因为它们通常需要转换为更高的积累精度,从而为精确格式转换创建了其他FFMA指令。通过交替收益位并清除重复使用位,编译器优化了计算密集型MMA(矩阵多功能)操作和精确促销FFMA指令的交织。


原文


> FFMA SASS interleaving

> We observe a performance improvement in the CUTLASS FP8 kernel between NVCC 12.2 and 12.3. By comparing the compiled SASS, we discover that one bit in a series of FADD instructions is flipped in an interleaving pattern. After referencing some open-source CUDA assembler implementations, we identified that this bit controls yield, which may enhance warp-level parallelism (just a guess, yielding the current warp and let other warps work).

> To leverage this, we develop a similar script to modify the FFMA instructions in the compiled binary. Besides simply modifying the yield bit, we also flip the reuse bit (registers cannot be reused if the warp is yielded). This adjustment improves performance (10%+ in some cases) for fine-grained scaling FP8 GEMMs by creating more opportunities to overlap MMA instructions with promotion FFMA instructions.

I would say it is really mind-blowing.



From what I read elsewhere, this is the type of typical performance optimization for matrix math you would see when performance is critical. It’s just not been applied yet to this specific problem by other AI players since it wasn’t a necessity for other companies. But eventually everyone would probably end up here regardless.



How many people does it take to implement this? A 10% gain in performance could pay for a lot of people's salaries when your company is spending hundreds of millions on GPU clusters.



If you think how many people who looked and failed to realize this optimization in the preceding performance efforts of the community, you could argue for quite a big number.



Uh, three? I worked at $CORP where we had a three people sub-team, they reverse engineered most of Volta's SASS instruction encoding, built a working SASS assembler (before the open source one of course), with the ultimate goal of making GEMM / Conv faster. And they did it. Though it wasn't applied to a high-profile enough big picture so we never heard about it :>

If you don't believe me, previous open source SASS assemblers were mostly from university, they surely didn't have that many people.



I think we did release some of the optimized kernels but I don't think we have released any one with SASS black magic, at least not before I left. Already been sanctioned by BIS, better not annoy NVIDIA furthermore.



Just a reminder, this is the third of many open source releases from DeepSeek that they are willing to release, and that release is a very trivial low bar for them to find optimizations when it is needed.

I guess since the majority here are blown away by the very low-level code involved, it tells me that they're likely not ready to use it or have been stuck on very high level tools that abstract this away.



I think most AI players rely on high performance GEMM. But most people would be satisfied with cutlass or cublas, and the others implement gemm themselves, but not necessarily use undocumented features?



Using undocumented features is not rare. People reverse engineered Apple's undocumented AMX instructions on their CPU, and I know people use undocumented/private extensions for several different kinds of GPUs.



The speedup figures they report are compared to their own cutlass-based baseline. Has anyone done a performance comparison against cuBLAS?

All cutlass results I have seen so far for Gemm are within ~10% of cuBLAS. If the 2x-2.5x speedup they report holds up that would be extremely impressive.



I generally avoid FP8 and prefer I8, but your question got me wondering how well cuBLAS performs.

First of all, cuBLAS needs the cuBLASLt extension API for mixed-precision workloads to handle FP8. Second, some adequate type combinations, like E5M2 x E5M2 for A x B, are not supported, while others, like E5M2 x E4M3, are! Moreover, matrix A must always come in a transposed layout for Ampere, Hopper, and Blackwell... and the list of constraints goes on.

I've integrated FP8 cuBLASLt benchmarks into my "Less Slow C++" repository <https://github.com/ashvardanian/less_slow.cpp>, adding to the list of existing cuBLAS and hand-rolled CUDA and PTX benchmarks. I'm running them on H200 GPUs, which should have the same performance as H100. For square inputs, the throughput peaks around 1.35 Peta-ops.

  --------------------------------------------------------------------------------------------------
  Benchmark                                        Time             CPU   Iterations UserCounters...
  --------------------------------------------------------------------------------------------------
  cublaslt_tops/256         12496 ns        12496 ns        56284 TOP=2.67999T/s
  cublaslt_tops/512         13089 ns        13089 ns        53100 TOP=20.4883T/s
  cublaslt_tops/1024        14882 ns        14882 ns        46918 TOP=144.23T/s
  cublaslt_tops/2048        25802 ns        25802 ns        26869 TOP=665.679T/s
  cublaslt_tops/4096       109316 ns       109313 ns         6021 TOP=1.25715P/s
  cublaslt_tops/8192       821080 ns       821050 ns          629 TOP=1.33907P/s
  cublaslt_tops/16384     7135472 ns      7135461 ns           93 TOP=1.23269P/s
  cublaslt_tops_BigO         0.00 N^3        0.00 N^3  
  cublaslt_tops_RMS             2 %             2 % 
That's around 67% of the advertised number for dense GEMM https://resources.nvidia.com/en-us-data-center-overview-mc/e...>.


I heard that it is possible to achieve better performance than cuBLAS using CUTLASS? I thought they chose the better one among cuBLAS and CUTLASS as baseline.



This kind of stuff is an intersting demonstration of how far compilers are from extracting high performance from hardware based on high level code.

What would it take for traditional compiler tech or AI assisted optimization agents to come up with something like it?



I think these kind of open-source is really showing their objective of achieving efficiency in the industry. The reason is this kind of software benefits a lot to the big guys serving the model (competitors to Deekseek themselves if they are interested in being a provider) rather than to the general open-source community that wants to learn and tinker or serve model in consumer hardware.



I'm not sure the lower and lower precision optimization is a good idea long term. It indicates that models are really sparse and that may be true right now but I think that is likely just because we have some bad ideas about how to train them and not because they really should be that sparse.



Well, let's enjoy free "sparsity" until it doesn't. Being able to train a really good model but in higher precision only is a research problem. Low precision training and inference is an engineering one.

We've been doing this since CNN days (9 years ago if not more), and I believe we have a good few years left.



The activation function throws away much of the dynamic range of floating point numbers, it's relatively clear that having a lot of range where the activation is already saturated is unlikely to be useful.



That depends on the activation function. I personally think Layernorm is destroying density (and have some solid evidence for this) but it is in use because there is a lot of missing supporting structure to really help pump data into the weights so it helps so long as we are using simple linear combinations.



Basically every activation function throws away half of the dynamic range at every neuron, which across a deep network is a lot.

You make a good point about LayerNorm, it's probably even worse.



This might be rendered moot by native microscaling support in Blackwell (MXFP). They've manually done a coarser-grained version of that for Hopper, but with full FP32 scaling factors.



Yes.

These are very good and high profile public demonstrations of where $NVDA's moat is: that GPGPU is very flexible and you can program to do a lot of stuff that makes perfect sense but wasn't in the mind of hardware vendors.

Now, if you predict the future to eventually converge on more and more dedicated hardware support, to the point that there's no more software optimizations like these, then the so-called "CUDA moat" breaks.

To stay in this game, NVIDIA is breaking down their own moat :p



I keep wondering why there even are undocumented instruction.

Wouldn’t it make sense to provide these to the user? Even if they might not be perfectly reliable.

This stuff must be documented internally, why not just release it?

Security by obscurity does not work: Your competitor reverse engineer everything you do anyways.



Probably same reason as anything you work on might have undocumented stuff. Combo of lack of time and/or not wanting to imply support for unstable/experimental features. If you're only screwing over the team on the next desk or whatever it's a lot easier to change things.



> This stuff must be documented internally

Probably no. They are likely only documented in architectural design doc / spec etc which you surely do not want to share.



Honestly, this is beyond my usage and understanding. But I really appreciate such sharing findings and improvements so that everyone can benefit from them. It's a refreshment.



FFMA (Fused Floating-point Multiply-Add) is a fundamental GPU instruction that performs D = A*B + C in a single operation. This instruction is critical for matrix multiplication and deep learning workloads.

In NVIDIA's SASS (Streaming Assembly), FFMA instructions are encoded as 64-bit or 128-bit instructions with various control bits that determine their exact behavior.

When the yield bit is set the bit tells the warp scheduler that the current warp can yield execution after this instruction. The hardware can then schedule a different warp to execute, potentially hiding latency.

GPUs achieve high throughput through massive parallelism. When one warp stalls (e.g., waiting for memory), others can proceed. The yield bit creates explicit opportunities for the scheduler to switch warps.

This bit indicates whether the source registers can be reused immediately in subsequent operations. When the yield bit is set, the reuse bit must be cleared. If a warp yields, it might not be the next one to execute. Another warp might modify the register file state. The hardware cannot guarantee register values will remain unchanged across yields.

By setting the yield bit in an alternating pattern across FFMA instructions, the compiler creates explicit scheduling points where other warps can make progress. When modifying the yield bit, they also had to clear the reuse bit for affected instructions to maintain correctness. This modification specifically helps overlap two types of operations: MMA (Matrix Multiply-Accumulate) instructions: Heavy compute operations that form the core of matrix multiplication, and Promotion FFMA instructions: Operations that convert between precision formats (likely FP8 to higher precision for accumulation)

FP8 (8-bit floating point) GEMM operations have specific characteristics that make this optimization particularly effective. FP8 calculations typically require conversion to higher precision for accumulation and back, creating additional FFMA operations. FP8 reduces memory bandwidth requirements but creates complex computation patterns with promotion/demotion operations. The mention of "fine-grained scaling" suggests these are operations where precision is carefully managed at multiple points in the calculation.

The yield bit manipulation creates a more optimal interleaving of compute operations and format conversions, allowing the GPU to utilize its execution units more efficiently. Without this optimization, the warp scheduler might not find natural opportunities to switch between warps, leading to underutilization of compute resources.



This is crazy insightful, thanks! I’d really love to learn how to get to this level of understanding, but can’t seem to figure out what curriculum I’d follow where I’d end up with this level of technical competence.



You need to understand how the gpu architecture works on a abstract level. Try to understand the SIMT (Single Instruction Multiple Threads) principle. Doing some shader programming or writing a cuda kernel could be a nice exercise. In a nutshell, if you want to add two vectors with hundred elements, instead of looping from 0 to 99 you would call a function called "kernel" (or "shader" in graphics programming) 100 times and pass it different indices.

Then research how it is realized on the hardware with "warp"s or "wavefront"s (on AMD i think). How the cache works is also very important here. Sadly the information on the internet is relatively sparse here.



Very Nice!

Can you recommend some good resources/books on GPU/TPU/ML Accelerators/etc. architecture/ISA where i can read the above details? Also on Computer Math where one can study how FP8/etc. works?



Nice. I had looked at the older editions of this book but don't recall that it covered GPU ISA (i may be wrong here since i have not really put in the time to study GPUs) ?

Amazon search brought up the following two interesting books, perhaps somebody who has browsed/read them can chime in;

1) Advanced GPU Assembly Programming: A Technical Reference for NVIDIA and AMD Architectures by Gareth Thomas.

2) Numerical Computations with GPUs edited by Volodymyr Kindratenko.



Just tested and it doesn't work out of the box on the consumer 50 series ie. 5080:
    Testing GEMM:
    Assertion failed: 
    deep_gemm/jit/../include/deep_gemm/fp8_gemm.cuh:369, condition: cudaFuncSetAttribute(kernel, 
 cudaFuncAttributeMaxDynamicSharedMemorySize, smem_size) == cudaSuccess
    terminate called after throwing an instance of 
    'AssertionException'
      what():  Assertion failed: cudaFuncSetAttribute(kernel, cudaFuncAttributeMaxDynamicSharedMemorySize, smem_size) == cudaSuccess


Perhaps your card has less per-SM shared memory than the GPUs DeepSeek uses.

Try to lower the sm90_capacity value in gemm.py: I think 128KB is the correct value for RTX 5080 compared to 256KB for the H100/H800.

And probably add ", 3, 2, 1" after "6, 5, 4".



Lol. I don't think the people that buy/sell NVDA even know what this is about.

This is a highly specialized linear algebra library to do general matrix-matrix multiplications for low-precision floats (FP8, vs FP32 (float), FP64 (double)) while maintaining accuracy.

联系我们 contact @ memedata.com