mirror of
https://github.com/ROCm/composable_kernel.git
synced 2026-07-16 08:44:55 +00:00
Replace generate_tuple lambda with pack expansion in InitializeElementSize
The InitializeElementSize function used generate_tuple with a lambda to compute visible dimension lengths. Each TensorDescriptor type created a unique lambda type, causing 78 instantiations (385ms). Replace with direct pack expansion using helper functions, eliminating the lambda instantiation overhead entirely. Results on example_grouped_conv_fwd_xdl_fp16: - generate_tuple lambdas: 178 -> 100 (44% reduction) - Template instantiation time: 19.5s -> 19.0s
This commit is contained in:
@@ -49,27 +49,29 @@ struct TensorDescriptor
|
||||
return unique_sort_all_dim_ids::Size();
|
||||
}
|
||||
|
||||
// Helper to get length of a visible dimension from transforms
|
||||
template <index_t I>
|
||||
__host__ __device__ static constexpr auto
|
||||
GetVisibleDimLengthFromTransforms(const Transforms& transforms)
|
||||
{
|
||||
constexpr auto result =
|
||||
find_in_tuple_of_sequences<VisibleDimensionIds::At(Number<I>{})>(UpperDimensionIdss{});
|
||||
static_assert(result.found, "wrong! not found matching transformation and upper-dimension");
|
||||
return transforms[Number<result.itran>{}].GetUpperLengths()[Number<result.idim_up>{}];
|
||||
}
|
||||
|
||||
// Compute element size using pack expansion instead of generate_tuple with lambda
|
||||
template <index_t... Is>
|
||||
__host__ __device__ static constexpr auto ComputeElementSizeImpl(const Transforms& transforms,
|
||||
Sequence<Is...>)
|
||||
{
|
||||
return (GetVisibleDimLengthFromTransforms<Is>(transforms) * ...);
|
||||
}
|
||||
|
||||
__host__ __device__ static constexpr auto InitializeElementSize(const Transforms& transforms)
|
||||
{
|
||||
const auto lengths = generate_tuple(
|
||||
[&](auto idim_visible) {
|
||||
constexpr auto tmp = GetTransformAndItsUpperDimension(idim_visible);
|
||||
|
||||
constexpr index_t itran = tmp[Number<0>{}];
|
||||
constexpr index_t idim_up = tmp[Number<1>{}];
|
||||
constexpr bool found = tmp[Number<2>{}];
|
||||
|
||||
static_assert(found == true,
|
||||
"wrong! not found matching transformation and upper-dimension");
|
||||
|
||||
const auto length =
|
||||
transforms[Number<itran>{}].GetUpperLengths()[Number<idim_up>{}];
|
||||
|
||||
return length;
|
||||
},
|
||||
Number<ndim_visible_>{});
|
||||
|
||||
return container_product(lengths);
|
||||
return ComputeElementSizeImpl(
|
||||
transforms, typename arithmetic_sequence_gen<0, ndim_visible_, 1>::type{});
|
||||
}
|
||||
|
||||
template <index_t IDim>
|
||||
|
||||
Reference in New Issue
Block a user