Skip to content

Replace nested static_for lambdas with compile-time search helper - #6696

Merged
illsilin merged 2 commits into
developfrom
users/tenpercent/ck/tensor-descriptor-lambda-elimination
Jun 2, 2026
Merged

Replace nested static_for lambdas with compile-time search helper#6696
illsilin merged 2 commits into
developfrom
users/tenpercent/ck/tensor-descriptor-lambda-elimination

Conversation

@tenpercent

@tenpercent tenpercent commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add sequence_find_value and find_in_tuple_of_sequences compile-time search helpers with O(1) template depth
  • Replace nested static_for lambdas in TensorDescriptor::GetTransformAndItsUpperDimension and InitializeElementSize
  • Apply same optimizations to TensorAdaptor

Supersedes #4287. Conflict-resolved rebase of ROCm/composable_kernel#3600 onto current develop.

Motivation

The TensorDescriptor and TensorAdaptor classes had excessive template instantiation from:

  1. Nested static_for loops with lambdas creating unique closure types at every call site
  2. generate_tuple with lambdas causing per-type instantiation overhead

The new helpers use constexpr array lookup and pack expansion instead of recursive template patterns, achieving O(1) template depth.

Results (example_grouped_conv_fwd_xdl_fp16, n=10, interleaved, -j1, -ftime-trace)

TU Baseline (mean) New (mean) Delta Wilcoxon p Mann-Whitney p
grouped_conv_fwd_xdl_fp16 (host) 14,886 ms 13,353 ms -10.3% 0.002 0.0002
grouped_conv_fwd_xdl_fp16 (device) 27,762 ms 25,629 ms -7.7% 0.002 0.0002
Total (all TUs) 57,732 ms 54,030 ms -6.4%

Unrelated TUs (device_memory, host_tensor, convolution_parameter) show no significant difference (p > 0.3), serving as negative controls.

Methodology

  • 10 interleaved runs (baseline₁, new₁, baseline₂, new₂, ...) on the same node to eliminate ordering/warmup bias
  • Wilcoxon signed-rank test (paired, non-parametric) and Mann-Whitney U test (unpaired)
  • Built with patched clang (LLVM 22) on ctr2-alola-compile-11, -j1 for accurate per-TU timing
  • Raw data available in Slurm job 275230 results

Test plan

  • 11 unit tests added (5 for sequence_find_value, 6 for find_in_tuple_of_sequences)
  • Compile-time benchmark with statistical significance (p < 0.01)
  • Full CI

Tracking issue: #4229


Generated-by: Claude Code (claude-sonnet-4-6)

Add sequence_find_value and find_in_tuple_of_sequences helpers using
O(1) template depth via constexpr array lookup and pack expansion.

Replace nested static_for lambdas in TensorDescriptor and TensorAdaptor:
- GetTransformAndItsUpperDimension: use find_in_tuple_of_sequences
- InitializeElementSize: replace generate_tuple lambda with pack expansion

This eliminates the bulk of applier::operator() instantiations that
previously came from nested lambda closures in the tensor descriptor
transform search.

Conflict-resolved rebase of ROCm/composable_kernel#3600 onto develop.
Supersedes #4287.

Generated-by: Claude Code (claude-sonnet-4-6)
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been inactive for 25 days and will be marked as stale.

If you would like to keep this PR open, please:

  • Add new commits
  • Add a comment explaining why it should remain open

This PR will be automatically closed in 5 days if no further activity occurs.

@github-actions github-actions Bot added the Stale PR has no activity for 25+ days label May 19, 2026
@tenpercent tenpercent removed the Stale PR has no activity for 25+ days label May 19, 2026
@illsilin
illsilin merged commit 9627b91 into develop Jun 2, 2026
32 checks passed
@illsilin
illsilin deleted the users/tenpercent/ck/tensor-descriptor-lambda-elimination branch June 2, 2026 23:13
assistant-librarian Bot pushed a commit to ROCm/composable_kernel that referenced this pull request Jun 2, 2026
Replace nested static_for lambdas with compile-time search
 helper (#6696)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

## Summary

- Add `sequence_find_value` and `find_in_tuple_of_sequences`
compile-time search helpers with O(1) template depth
- Replace nested `static_for` lambdas in
`TensorDescriptor::GetTransformAndItsUpperDimension` and
`InitializeElementSize`
- Apply same optimizations to `TensorAdaptor`

Supersedes #4287. Conflict-resolved rebase of
#3600 onto current develop.

## Motivation

The `TensorDescriptor` and `TensorAdaptor` classes had excessive
template instantiation from:
1. Nested `static_for` loops with lambdas creating unique closure types
at every call site
2. `generate_tuple` with lambdas causing per-type instantiation overhead

The new helpers use constexpr array lookup and pack expansion instead of
recursive template patterns, achieving O(1) template depth.

## Results (`example_grouped_conv_fwd_xdl_fp16`, n=10, interleaved,
`-j1`, `-ftime-trace`)

| TU | Baseline (mean) | New (mean) | Delta | Wilcoxon p | Mann-Whitney
p |

|----|-----------------|------------|-------|-----------|---------------|
| `grouped_conv_fwd_xdl_fp16` (host) | 14,886 ms | 13,353 ms |
**-10.3%** | **0.002** | **0.0002** |
| `grouped_conv_fwd_xdl_fp16` (device) | 27,762 ms | 25,629 ms |
**-7.7%** | **0.002** | **0.0002** |
| **Total (all TUs)** | **57,732 ms** | **54,030 ms** | **-6.4%** | | |

Unrelated TUs (`device_memory`, `host_tensor`, `convolution_parameter`)
show no significant difference (p > 0.3), serving as negative controls.

### Methodology

- 10 interleaved runs (baseline₁, new₁, baseline₂, new₂, ...) on the
same node to eliminate ordering/warmup bias
- Wilcoxon signed-rank test (paired, non-parametric) and Mann-Whitney U
test (unpaired)
- Built with patched clang (LLVM 22) on ctr2-alola-compile-11, `-j1` for
accurate per-TU timing
- Raw data available in Slurm job 275230 results

## Test plan

- [x] 11 unit tests added (5 for `sequence_find_value`, 6 for
`find_in_tuple_of_sequences`)
- [x] Compile-time benchmark with statistical significance (p < 0.01)
- [ ] Full CI

Tracking issue: #4229
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants