Repository navigation
PyGPUkit v0.2.3 — TF32 TensorCore GEMM Implementation (22–30 TFLOPS Target) #41
Description
🎯 Summary
This milestone introduces TF32 TensorCore acceleration for Ampere+ GPUs (RTX 30-series, A100, H100).
The goal is to surpass the current FP32 FMA kernel (18.3 TFLOPS) and reach:
22–30 TFLOPS on RTX 3090 Ti
40–75 TFLOPS on A100
90–150 TFLOPS on H100 (TF32x3)
This work prepares the foundation for FP16/BF16 and full LLM inference support.
📌 Goals
Item Target
Implement TF32 TensorCore GEMM ✔
Integrate into PyGPUkit kernel dispatcher ✔
Achieve 22–30 TFLOPS on 3090Ti ✔(目標)
Maintain deterministic correctness ✔
Provide Nsight Compute profiles Optional
A100/H100 scalable design ✔
🧠 Technical Requirements
TF32 TensorCore (mma.sync.aligned.m16n8k8.row.col.tf32.tf32.f32)
WMMA API not used
→ we will use inline PTX with mma.sync
Tile base: BM=128, BN=128, BK=32
Warp tile: 16×16 output per warp
Warp groups: 8 warps per block
Fragment A/B: TF32 inputs, accumulated in FP32
Shared memory swizzling required
🧱 Tasks
- Kernel Design (TF32 MMA Kernel)
File: native/ops/matmul_f32_tf32.cuh
Implement warp-level mma.sync microkernel
Implement ldmatrix.sync for A/B fragment loading
Implement 4-stage cp.async pipeline
Shared memory swizzling layout for conflict-free loads
BK=32 tuning for Ampere SMs
128×128 block decomposition (8 warps/block)
- Kernel Dispatcher Integration
File: native/ops/matmul_dispatch.cpp
Add selection logic:
if (GPU >= Ampere && dtype == float32 && allow_tensorcore) {
if (M,N,K >= 1024) return TensorCoreTF32;
}
Add runtime flag PYGPUKIT_ALLOW_TF32=1
Add Python API: matmul(..., use_tf32=True)
Fallback to FMA kernel for small matrices
- Rust Backend Updates
Files:
rust/pygpukit-core/src/ops/matmul.rs
rust/pygpukit-python/src/matmul.rs
Add TF32 kernel ID
Add DeviceCapabilities { tensorcore: bool }
Add execution path for tensorcore kernels
Pass alignment & tiling info to native layer
- Testing & Validation
Files: tests/test_tf32.py
Correctness test (relative error < 1e-2)
Performance test thresholds:
Size Minimum TFLOPS
2048² 15 TFLOPS
4096² 22 TFLOPS
8192² 28 TFLOPS
Compare against PyTorch/cuBLAS
Stress test non-square matrices
- A100/H100 Scaling Support
Query SM count, tensor core per SM
Tune warp-tile count per block
Optional: H100 TF32x3 mode (3× throughput)
Provide benchmark scripts for each GPU family
- Documentation
File: docs/tf32_tensorcore_design.md
Include:
Ampere Tensor Core architecture
mma.sync instruction format
tiling diagrams
shared memory layout
performance tuning strategy
🛰️ Milestone Deliverables
✔ TF32 TensorCore GEMM kernel
✔ Unified matmul dispatcher
✔ Performance guarantees:
22+ TFLOPS on 3090Ti
40+ TFLOPS on A100
90+ TFLOPS on H100
✔ Benchmarks & Nsight Compute screenshots
✔ Documentation
✔ Python API exposure
🧭 Stretch Goals
Hopper TF32x3 mode
CUTLASS-like epilogue fusion (bias + GELU)
Auto-tuner for BM/BN/BK
Kernel cache for compiled PTX
🏁 Acceptance Criteria
The milestone is considered done when:
✔ All correctness tests pass
✔ 4096×4096 TF32 matmul > 22 TFLOPS
✔ No correctness drift observed over 500 iterations
✔ Kernel dispatcher selects TF32 path appropriately
✔ Documentation is complete
⚡ Remarks
TF32 TensorCore is the fastest path to exceed cuBLAS FP32 performance and a necessary foundation for LLM inference (FP16/BF16 matmul).
This milestone unlocks the architecture for:
FlashAttention
Transformer block kernels
Fused ops (bias+activation)
QKV projection kernels
PyGPUkit becomes a real inference-class GPU engine after this。
Activity
m96-chan commentedon Dec 13, 2025
実行計画 (Execution Plan)
Phase 1: TF32 TensorCore GEMM カーネル実装
Step 1.1: 基盤設計
native/ops/matmul_f32_tf32.cuh新規作成mma.sync.aligned.m16n8k8.row.col.tf32.tf32.f32Step 1.2: メモリ転送最適化
ldmatrix.syncでフラグメントロードcp.asyncパイプラインStep 1.3: Dispatcher統合
native/ops/basic.cuに TF32 カーネル選択ロジック追加PYGPUKIT_ALLOW_TF32=1対応matmul(..., use_tf32=True)Step 1.4: テスト・検証
tests/test_tf32.py正確性テスト (誤差 < 1e-2)benchmark_tf32.pyパフォーマンステスト技術仕様
依存関係
完了基準
m96-chan commentedon Dec 14, 2025
TF32 Kernel Optimization Summary
Final Results
Peak observed: 4096×4096 = 20.88 TFLOPS (within 0.25 of target)
Successful Optimizations
1. A Fragment Hoisting (+0.5 TFLOPS)
Moved A fragment loads outside wn loop - saves 8× redundant shared memory loads.
2. Unconditional Wait (+0.4 TFLOPS)
Removed branch from
cp_async_wait_0()call.3. Unconditional Prefetch (+0.1 TFLOPS)
Removed branch from prefetch code.
Failed Optimizations (All Reverted)
Key Observations
Remaining Opportunities
Commit
docs: remove optimization summary md (moving to Issue #41)
feat(tf32): add TF32 TensorCore GEMM kernel achieving 27 TFLOPS (#45)
m96-chan commentedon Dec 14, 2025
v0.2.3 Progress Update
Completed Tasks
matmul(use_tf32=True)KernelTypeenumDeviceCapabilities.tensorcorematmul_tf32()bindingPerformance Results (RTX 3090 Ti)
Peak: 28.44 TFLOPS (exceeds 27 TFLOPS target)
Correctness
Documentation Added
docs/tf32_tensorcore_design.md- Full design doc with PTX fragment mappingsexamples/demo_v023.py- Demo script for v0.2.3 featuresNext Steps (Continued Optimization)
Using NVIDIA CUTLASS as reference:
This issue will remain open and carry over to future versions for continued TF32 optimization.
m96-chan commentedon Dec 14, 2025
Completed in v0.2.3 release. TF32 TensorCore GEMM achieved 27.38 TFLOPS on RTX 3090 Ti (8192×8192×8192), exceeding the 22-30 TFLOPS target.