tcFFT: Accelerating Half-Precision FFT through Tensor Cores

Bin-Rui Li, Shenggan Cheng, James LinarXiv 2021

Introduction

The Fast Fourier Transform (FFT) is a fundamental algorithm in scientific computing, essential for fields ranging from medical imaging to cosmological simulations. As data volumes explode, there is a growing shift toward half-precision (FP16) arithmetic to reduce energy consumption and increase throughput. NVIDIA's Tensor Cores, specialized hardware units designed for high-performance matrix-matrix multiplications (GEMM) in AI workloads, offer a massive theoretical performance advantage over standard floating-point units. For instance, on the NVIDIA A100, FP16 Tensor Cores can reach 312 teraFLOPS, compared to only 19.5 teraFLOPS for peak FP32.

However, mapping FFTs to Tensor Cores is non-trivial. FFTs rely on complex "butterfly" operations and element-wise multiplications with "twiddle factors," which do not naturally align with the rigid GEMM interface of Tensor Core APIs. Previous attempts to bridge this gap often suffered from high latency due to frequent data movement between registers and shared memory. This paper introduces tcFFT, a novel library designed to overcome these hurdles and unlock the full potential of Tensor Cores for FFT acceleration.

Methods: Reimagining FFT for Tensor Cores

The core innovation of tcFFT lies in its ability to treat FFT stages as matrix operations that can be efficiently processed by Tensor Cores. The architecture follows a structured execution flow, as shown in Figure 1.

The tcFFT execution flow, illustrating the plan-based selection of merging kernels and the iterative processing through global and shared memory.

1. Direct Fragment Manipulation

A major bottleneck in using Tensor Cores via the Warp Matrix Multiply Accumulate (WMMA) API is the "black box" nature of fragments. Data is distributed across a warp's registers in an opaque mapping, making it difficult to perform element-wise operations like twiddle factor multiplication without moving data back to shared memory.

The authors of tcFFT reverse-engineered this mapping, allowing for direct register-level manipulation. By knowing exactly which thread holds which matrix element, they can perform complex multiplications directly in the registers before invoking the Tensor Core. This "Direct Fragment Manipulation" is detailed in Algorithm 2, which shows how complex-matrix access and element-wise multiplication are handled in a thread-centric view.

Algorithm for complex-matrix access and element-wise multiplication, enabling twiddle factor application directly within register fragments.

2. Optimized Merging Kernels and Planning

FFT performance is often limited by memory bandwidth rather than raw compute power. To address this, tcFFT utilizes a "plan" system that selects the most efficient "merging kernels" for a given problem size. These kernels, such as Radix-16 or Radix-512, combine multiple FFT stages into a single GPU kernel pass. This strategy maximizes "arithmetic intensity" by keeping intermediate data in fast on-chip registers and shared memory, minimizing expensive trips to global VRAM. Furthermore, the library ensures that global memory accesses are coalesced, maintaining high efficiency even for large-scale transforms.

Evaluation and Results

The performance of tcFFT was rigorously tested against NVIDIA’s industry-standard cuFFT library using synthetic benchmarks on V100 (Volta) and A100 (Ampere) GPUs. The benchmarks covered 1D FFTs (up to 134 million points) and various 2D FFT configurations.

Performance Gains

On the V100, tcFFT achieved speedups ranging from 1.29x to 3.24x over cuFFT. On the newer A100, the speedup remained significant, between 1.10x and 3.03x. These results demonstrate that tcFFT effectively translates the high TFLOPS of Tensor Cores into real-world FFT performance.

Efficiency and Precision

Beyond raw speed, tcFFT showed exceptional bandwidth efficiency, reaching up to 97.8% of the theoretical peak memory bandwidth for sequences that fit within shared memory. Importantly, this performance does not come at the cost of accuracy. The relative error for tcFFT remained approximately 1.7% for 1D FP16 transforms, which is on par with cuFFT, proving that Tensor Cores are suitable for scientific computations within the standard limits of half-precision arithmetic.

Conclusion and Future Directions

tcFFT represents a significant step forward in high-performance scientific computing by successfully repurposing AI-centric hardware for general mathematical algorithms. By bypassing API limitations through register-level optimizations and employing a sophisticated kernel merging strategy, it delivers substantial speedups over existing state-of-the-art libraries.

While currently focused on FP16, future iterations of tcFFT could explore higher-precision units or incorporate precision recovery techniques like Kahan summation to broaden its applicability. The ultimate goal is the integration of tcFFT into production-level scientific software, such as gravitational wave analysis tools and cosmological simulators, where its performance gains can accelerate the pace of discovery.

Summary updated

BibTeX
@misc{li2021tcfft,
  author = {Bin-Rui Li and Shenggan Cheng and James Lin},
  title = {{tcFFT: Accelerating Half-Precision FFT through Tensor Cores}},
  year = {2021},
  eprint = {2104.11471},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2104.11471},
}
Figure