|
| 1 | +# CUDA LLM Kernel Optimization |
| 2 | + |
| 3 | +[](https://github.com/LessUp/llm-speed/actions/workflows/ci.yml) |
| 4 | +[](LICENSE) |
| 5 | + |
| 6 | + |
| 7 | +[简体中文](README.md) | English |
| 8 | + |
| 9 | +High-performance CUDA operator library for LLM inference optimization, including FlashAttention and high-performance GEMM kernels. |
| 10 | + |
| 11 | +## Features |
| 12 | + |
| 13 | +- **FlashAttention**: Online Softmax, O(N) memory, causal mask support |
| 14 | +- **High-Performance GEMM**: FP32/FP16/INT8 mixed precision, Tensor Core (WMMA) |
| 15 | +- **Progressive Optimization**: Naive → Tiled → FlashAttention (double-buffered) |
| 16 | +- **Register Tiling GEMM**: 128×128 blocks + 8×8 register accumulation + double buffer pipeline |
| 17 | +- **PyTorch Integration**: pybind11 Python bindings, direct PyTorch Tensor I/O |
| 18 | +- **Property Testing**: Hypothesis-driven property-based tests |
| 19 | + |
| 20 | +## Installation |
| 21 | + |
| 22 | +```bash |
| 23 | +pip install -r requirements.txt |
| 24 | +pip install -e . |
| 25 | +``` |
| 26 | + |
| 27 | +### CMake Build |
| 28 | + |
| 29 | +```bash |
| 30 | +cmake --preset release |
| 31 | +cmake --build --preset release |
| 32 | +``` |
| 33 | + |
| 34 | +## Usage |
| 35 | + |
| 36 | +```python |
| 37 | +from cuda_llm_ops import flash_attention, gemm, tensor_core_gemm |
| 38 | + |
| 39 | +# FlashAttention (causal mask) |
| 40 | +output = flash_attention(q, k, v, is_causal=True) |
| 41 | + |
| 42 | +# High-performance GEMM |
| 43 | +c = gemm(a, b, alpha=1.0, beta=0.0) |
| 44 | + |
| 45 | +# Tensor Core GEMM (FP16 → FP32) |
| 46 | +c_fp32 = tensor_core_gemm(a, b) |
| 47 | +``` |
| 48 | + |
| 49 | +## Testing |
| 50 | + |
| 51 | +```bash |
| 52 | +pytest tests/ -v # All tests |
| 53 | +pytest tests/ -v -m property # Property tests |
| 54 | +python benchmarks/benchmark_attention.py # Benchmarks |
| 55 | +``` |
| 56 | + |
| 57 | +## GPU Architecture Support |
| 58 | + |
| 59 | +| Arch | SM | Features | |
| 60 | +|------|-----|----------| |
| 61 | +| Volta | 7.0 | FP16 Tensor Core | |
| 62 | +| Turing | 7.5 | FP16 + INT8 | |
| 63 | +| Ampere | 8.0, 8.6 | TF32 + async copy | |
| 64 | +| Ada | 8.9 | FP8 | |
| 65 | +| Hopper | 9.0 | TMA + Warp Group MMA | |
| 66 | + |
| 67 | +## License |
| 68 | + |
| 69 | +MIT License |
0 commit comments