-
Notifications
You must be signed in to change notification settings - Fork 75
Replace tuple-based type iteration with C++20 fold expressions #5798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Reduces build time by ~11-16% by replacing cartesian_product/any_check patterns with direct fold expressions and fast_apply. Removes the now-unused cartesian_product and any_check functions.
Description
|
| Relevant files | |||||
|---|---|---|---|---|---|
| Enhancement |
|
PR Reviewer Guide
Here are some key observations to aid the review process:
| 🧪 No relevant tests |
| 🔒 No security concerns identified |
| ⚡ Recommended focus areas for review |
Missing Tests
|
|
!test |
PR: Replace tuple-based type iteration with C++20 fold expressions
Summary
This PR reduces nvFuser build time by 11-16% by replacing expensive tuple-based template metaprogramming with direct C++20 fold expressions in the DynamicType library.
Build Time Results
Full builds with
MAX_JOBS=12Motivation
DynamicType uses extensive compile-time type iteration to check operator compatibility across all type combinations. The original implementation used:
cartesian_product()- O(N²) tuple construction for M×N type pairsany_check()-std::applyover cartesian productsstd::apply- triggers expensivestd::is_nothrow_invocableinstantiationThese patterns cause significant template instantiation overhead that doesn't parallelize well across compilation units.
What Changed
1. Added
fast_apply(type_traits.h)Replaces
std::applyby skipping thenoexceptspecification machinery:2. Added
TypeListhelper (type_traits.h)Simple type container for fold expressions:
3. Replaced
belongs_to(type_traits.h)Before:
After:
4. Replaced binary operator type checks (dynamic_type.h)
Before: Used
DT::dispatch()with validity-checking lambdaAfter: M×N nested fold expressions:
5. Replaced all
any_checkusagesConverted 8 sites including:
can_cast_to- usesrequires+ foldhas_square_bracket/has_any_square_bracket+,-,~,!)++/--operator*(dereference)operator<<(printing)has_cross_type_equalityFiles Changed
lib/dynamic_type/src/dynamic_type/type_traits.hfast_apply,TypeList,any_can_cast_to, simplifiedbelongs_to; removedcartesian_product/any_checklib/dynamic_type/src/dynamic_type/dynamic_type.hTypeListTmemberReview Guide
fast_apply,TypeList,any_can_cast_to)belongs_toTypeListTadditions toContainersandDynamicTypeDEFINE_BINARY_OPmacro with nested fold helpershas_cross_type_equalitywith nested foldsTesting
Notes
cartesian_productandany_checkfunctions were removed (~95 lines) as they're no longer used<variant>header is now included in type_traits.h (needed for TypeList usage patterns)requiresexpressions which are already required by nvFuser