[BugFix][CUDA] Fall back for non-MMA GEMM K shapes - #2818
Conversation
|
👋 Hi! Thank you for contributing to the TileLang project. Please remember to run We appreciate you taking this step! Our team will review your contribution, and we look forward to your awesome work! 🚀 |
📝 WalkthroughWalkthroughGEMM layout selection now falls back to padded layouts for unsupported strides, while instruction selection falls back from MMA to CUDA FMA for unsupported K shapes. A CUDA regression test covers FP16 GEMM cases with K values 16, 20, and 28. ChangesGEMM shape fallback
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@testing/python/issue/test_tilelang_issue_2715.py`:
- Around line 29-40: Extend test_gemm_falls_back_for_non_swizzle_stride to
inspect the lowered CUDA source or instruction output for each parameterized k
value. Assert that k=16 uses the optimized CUDA MMA/GEMM instruction path, while
k=20 and k=28 use the scalar FMA fallback, preserving the existing numerical
correctness assertion.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 4a6753e2-f5ad-458d-a650-2e23913931eb
📒 Files selected for processing (3)
src/cuda/op/gemm.ccsrc/layout/gemm_layouts.cctesting/python/issue/test_tilelang_issue_2715.py
T.gemm selected bank-swizzled layouts and tensor-core MMA for K extents such as 20 and 28. The layout constructor rejected the stride first; bypassing that check alone only exposed the MMA atom divisibility assertion. Route unsupported MMA K atoms through the existing CUDA FMA implementation and use the padded shared-memory layout whenever a swizzle stride is invalid. Add A100/H100 numerical coverage for aligned and fallback K shapes. Co-authored-by: dingsg <shengge.ding@enflame-tech.com>
a2949c0 to
962c804
Compare
Fixes #2715
Summary
CUDA GEMM lowering selected the shared-memory layout and the MMA emitter independently. For K=20 and K=28, the swizzled layout fails its stride check; bypassing that check only moves the failure to the MMA atom divisibility check.
The layout and emitter now use the same MMA-shape check. Supported shapes keep the existing MMA path; other valid K extents use the padded shared-memory layout and the existing CUDA FMA emitter. Both choices are made in TileLang's GEMM lowering, so callers do not need to pad the mathematical K extent.
Changes
Review Notes
Validation
testing/python/issue/test_tilelang_issue_gemm_non_mma_k_fallback.py: 3 passed on NVIDIA A100.testing/python/issue/test_tilelang_issue_gemm_non_mma_k_fallback.py: 3 passed on NVIDIA H100.clang-formatandgit diff --checkpassed.