From 02e42dcaa1a566a05994b950548b67bbb76cab67 Mon Sep 17 00:00:00 2001 From: Max Podkorytov <4273004+tenpercent@users.noreply.github.com> Date: Fri, 16 Jan 2026 01:23:21 -0600 Subject: [PATCH] Replace lambdas with named functors in container_concat MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lambdas create unique types per call site, causing duplicate template instantiations. Named functors are shared across call sites. Results: - container_concat: 186 → 93 instantiations (50% reduction) - Wall-clock: 518ms → 309ms (40% reduction) --- include/ck/utility/container_helper.hpp | 26 +++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/include/ck/utility/container_helper.hpp b/include/ck/utility/container_helper.hpp index 79cb657ec6..e09c32d20f 100644 --- a/include/ck/utility/container_helper.hpp +++ b/include/ck/utility/container_helper.hpp @@ -324,6 +324,26 @@ container_reverse_inclusive_scan(const Tuple& x, Reduce f, TData init) return y; } +// Named functors for container_concat to reduce template instantiations +// (lambdas create unique types per call site, functors are shared) +struct make_tuple_functor +{ + template + __host__ __device__ constexpr auto operator()(Ts&&... xs) const + { + return make_tuple(ck::forward(xs)...); + } +}; + +struct make_array_functor +{ + template + __host__ __device__ constexpr auto operator()(T&& x, Ts&&... xs) const + { + return make_array(ck::forward(x), ck::forward(xs)...); + } +}; + template __host__ __device__ constexpr auto container_concat(const X& x, const Ys&... ys) { @@ -333,15 +353,13 @@ __host__ __device__ constexpr auto container_concat(const X& x, const Ys&... ys) template __host__ __device__ constexpr auto container_concat(const Array& ax, const Array& ay) { - return unpack2( - [&](auto&&... zs) { return make_array(ck::forward(zs)...); }, ax, ay); + return unpack2(make_array_functor{}, ax, ay); } template __host__ __device__ constexpr auto container_concat(const Tuple& tx, const Tuple& ty) { - return unpack2( - [&](auto&&... zs) { return make_tuple(ck::forward(zs)...); }, tx, ty); + return unpack2(make_tuple_functor{}, tx, ty); } template