composable_kernel icon indicating copy to clipboard operation
composable_kernel copied to clipboard

Template recursion-free static_ford

Open tenpercent opened this issue 10 months ago • 0 comments

Proposed changes

The current implementation of static_ford uses recursion over the sequence of dimensions and instantiates lambdas at each internal step. This can be avoided and should improve compilation time. The current most time consuming template is static_for(0,1) from static_ford instantiation internals for both old CK and CK-tile

Checklist

Please put an x into the boxes that apply. You can also fill these out after creating the PR. If you're not sure, please don't hesitate to ask.

  • [ ] I have added tests relevant to the introduced functionality, and the unit tests are passing locally
  • [ ] I have added the test to REGRESSION_TESTS list defined at the top of CMakeLists.txt in tests/CMakeLists.txt, IF the test takes more than 30 seconds to run.
  • [ ] I have added inline documentation which enables the maintainers with understanding the motivation
  • [ ] I have removed the stale documentation which is no longer relevant after this pull request
  • [ ] (If this change is user-facing) I have added release notes which provide the end users with a brief summary of the improvement from this pull request
  • [x] I have run clang-format on all changed files
  • [ ] Any dependent changes have been merged

Discussion

Snapshot -

ck::static_ford<ck::Sequence<14, 14, 16>>{} ([] (auto I) {
        I.Print();
    });
*** Old
 10703 ms: ck::static_for<0, 14, 1>::operator()<(lambda at ../include/ck/utility/functional3.hpp:31:52)> (15 times, avg 713 ms)
 10701 ms: ck::detail::static_for_impl<ck::Sequence<0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13>>::operator()<(lambda at ../include/ck/utility/functional3.hpp:31:52)> (15 times, avg 713 ms)
  5364 ms: ck::static_ford<ck::Sequence<14, 14, 16>>::operator()<(lambda at main.cpp:114:50)> (1 times, avg 5364 ms)
  5358 ms: ck::detail::static_ford_impl<const ck::Sequence<14, 14, 16>, ck::Sequence<0, 1, 2>>::operator()<(lambda at main.cpp:114:50), ck::Sequence<>> (1 times, avg 5358 ms)
  5210 ms: ck::static_for<0, 16, 1>::operator()<(lambda at ../include/ck/utility/functional3.hpp:31:52)> (196 times, avg 26 ms)
  5184 ms: ck::detail::static_for_impl<ck::Sequence<0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15>>::operator()<(lambda at ../include/ck/utility/functional3.hpp:31:52)> (196 times, avg 26 ms)
  1844 ms: ck::static_for<0, 3, 1>::operator()<(lambda at ../include/ck/utility/sequence.hpp:182:36)> (3136 times, avg 0 ms)
   401 ms: ck::detail::static_ford_impl<const ck::Sequence<14, 14, 16>, ck::Sequence<0, 1, 2>>::operator()((lambda at main.cpp:114:50), ck::Sequence<>)::(anonymous class)::operator()<ck::integral_constant<int, 7>> (1 times, avg 401 ms)
   400 ms: ck::detail::static_ford_impl<ck::Sequence<14, 16>, ck::Sequence<0, 1, 2>>::operator()<(lambda at main.cpp:114:50), ck::Sequence<7>> (1 times, avg 400 ms)
   399 ms: ck::detail::static_ford_impl<const ck::Sequence<14, 14, 16>, ck::Sequence<0, 1, 2>>::operator()((lambda at main.cpp:114:50), ck::Sequence<>)::(anonymous class)::operator()<ck::integral_constant<int, 11>> (1 times, avg 399 ms)
   398 ms: ck::detail::static_ford_impl<ck::Sequence<14, 16>, ck::Sequence<0, 1, 2>>::operator()<(lambda at main.cpp:114:50), ck::Sequence<11>> (1 times, avg 398 ms)
...
*** New
  2978 ms: ck::static_for<0, 3, 1>::operator()<(lambda at ../include/ck/utility/sequence.hpp:182:36)> (3136 times, avg 0 ms)
  2639 ms: ck::detail::static_for_impl<ck::Sequence<0, 1, 2>>::operator()<(lambda at ../include/ck/utility/sequence.hpp:182:36)> (3136 times, avg 0 ms)
  1457 ms: ck::static_ford<ck::Sequence<14, 14, 16>>::operator()<(lambda at main.cpp:114:50), ck::static_ford<ck::Sequence<14, 14, 16>>::convert_t> (1 times, avg 1457 ms)
  1457 ms: ck::detail::applier<int, 0, 1, 2, 3, 4, 5, 6, 7... (1 times, avg 1457 ms)
    20 ms: ck::Sequence<9, 12, 13>::Print (1 times, avg 20 ms)
...

tenpercent avatar Mar 25 '25 03:03 tenpercent