[CUDA] Bridge half-style math intrinsics for 16-bit CUTLASS types - #3077
[CUDA] Bridge half-style math intrinsics for 16-bit CUTLASS types#3077Chennesxu wants to merge 1 commit into
Conversation
TVM lowers 16-bit math operations to CUDA's half-style names, but CUDA provides overloads only for native __half and __nv_bfloat16 values. Calls with CUTLASS half_t and bfloat16_t wrappers therefore failed to compile. Add explicit forwarding overloads for hexp, hexp2, hexp10, hlog, hlog2, hlog10, hsin, hcos, hfloor, hceil, hrint, and htrunc. Each overload converts the wrapper to its native CUDA type, calls the existing intrinsic, and wraps the result back in the original type. Fold the previous standalone bfloat16 hexp bridge into the complete overload set. Codegen and the fast-math path remain unchanged. Add scalar runtime coverage for both wrapper types using materialized temporaries, separate valid input domains, generated-call assertions, and torch references.
|
👋 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! 🚀 |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughChangesCUDA 16-bit math support
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to This localized change adds half-style math forwarding for CUTLASS 16-bit types and includes focused coverage; no actionable merge-blocking risk remains beyond normal checks and review. Sequence Diagram(s)sequenceDiagram
participant Test
participant TileLangCompiler
participant CUDA
participant PyTorch
Test->>TileLangCompiler: Compile half_math_kernel
TileLangCompiler-->>Test: Return generated CUDA
Test->>CUDA: Execute kernel
CUDA-->>Test: Return outputs
Test->>PyTorch: Compute reference outputs
PyTorch-->>Test: Return references
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 |
Summary
Many unary
T.*math ops fail onfloat16andbfloat16because CUDA lowering emits half-style names such ashlogandhfloor, while CUDA only overloads them for native__halfand__nv_bfloat16, not CUTLASS wrappers.Fix
Add flat
half_tandbfloat16_tforwarding overloads for:hexp,hexp2,hexp10,hlog,hlog2,hlog10,hsin,hcos,hfloor,hceil,hrint, andhtrunc. Each overload calls the existing native CUDA intrinsic and wraps the result back in the original type. The existing bfloat16hexpoverload is retained as part of the completed set. Codegen and the fast-math path are unchanged.This enables
T.exp,T.exp2,T.exp10,T.log,T.log2,T.log10,T.sin,T.cos,T.floor,T.ceil,T.round,T.trunc, andT.sigmoidthrough itsexplowering.Tests
Added one kernel per dtype covering all 12 intrinsics with materialized temporaries, valid positive/mixed-sign inputs, entry-body codegen assertions, and torch references.
Verified locally on
sm_75/ CUDA 12.4:Scope
Limited to half-style names that already have native CUDA intrinsics. Operations requiring a float32 fallback, missing lowering rules, or separate float8/integer dtype policy remain out of scope.
Summary
half_tandbfloat16_t.Validation
sm_75with CUDA 12.4.C++ style / lint notes
src/tl_templates/cuda/common.h.docs/developer_guide/cpp_style.md.