Skip to content

speed up nvte_multi_padding / nvte_multi_unpadding#592

Open
matthiasdiener wants to merge 8 commits into
devfrom
mdiener/speedup-pad-unpad
Open

speed up nvte_multi_padding / nvte_multi_unpadding#592
matthiasdiener wants to merge 8 commits into
devfrom
mdiener/speedup-pad-unpad

Conversation

@matthiasdiener
Copy link
Copy Markdown
Contributor

@matthiasdiener matthiasdiener commented May 20, 2026

Description

Please include a brief summary of the changes, relevant motivation and context.

Fixes https://github.com/ROCm/frameworks-internal/issues/16530

See https://github.com/ROCm/frameworks-internal/issues/16530#issuecomment-4502138388 for performance.

Type of change

  • Documentation change (change only to the documentation, either a fix or a new content)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Infra/Build change
  • Code refactoring

Changes

Please list the changes introduced in this PR:

  • Change A
  • Change B

Checklist:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@matthiasdiener matthiasdiener self-assigned this May 20, 2026
@matthiasdiener matthiasdiener added the ci-level 1 CI test level 1 label May 20, 2026
@matthiasdiener matthiasdiener marked this pull request as ready for review May 20, 2026 20:01
for (int i2 = 0; i2 < nvec; ++i2) {
const int row = tile_row + i1 * nvec + i2;
const int col = tile_col + j1 * nvec;
const int remaining = row_length - col;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we factor out these lines since they don't depend on i2? This also lets us compute valid_cols once per iter instead of repeating the ternary in both load/store calls:

const int col = tile_col + j1 * nvec;
const int remaining = row_length - col;
const int valid_cols = remaining > 0 ? min(remaining, nvec) : 0;
#pragma unroll
for (int i2 = 0; i2 < nvec; ++i2)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in cb9221d. Does not really affect performance; I suspect the compiler is able to factor these out by itself.

Comment on lines 26 to 30
// Parameters to tune
constexpr int n_warps_per_tile = 4;
constexpr int threads_per_block = THREADS_PER_WARP * n_warps_per_tile;
constexpr int desired_load_store_size = 8;
constexpr int kMaxTensorsPerKernel = 64; // Args must be <4 KB
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try tuning any of these parameters by chance? The current block size seems small. I am also wondering if you can squeeze out any more performance by tuning the load/store size

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, thanks. Bumping n_warps_per_tile (in dc708c6) does lead to a significant performance increase. Increasing desired_load_store_size reduced performance.

Copy link
Copy Markdown
Contributor

@alextmagro alextmagro Jun 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if templating out load and store separately would help -- previously I found that 16 outperformed for some kernels for loads, but store was well optimized at 8. This was for FP8 though so may be different here. Also non-temporal stores may be a potential improvement, check out rocm device utils for reference

Copy link
Copy Markdown
Contributor Author

@matthiasdiener matthiasdiener Jun 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if templating out load and store separately would help -- previously I found that 16 outperformed for some kernels for loads, but store was well optimized at 8. This was for FP8 though so may be different here.

No, that also seems to reduce performance in this case.

Also non-temporal stores may be a potential improvement, check out rocm device utils for reference

This did help with performance, done in 84b7d09

#pragma unroll
for (int i2 = 0; i2 < nvec; ++i2) {
const int row = tile_row + i1 * nvec + i2;
const int col = tile_col + j1 * nvec;
Copy link
Copy Markdown
Contributor

@aris134 aris134 Jun 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: similar to above for the multi_padding_kernel, I think col and the ternary op can be hoisted up

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in cb9221d.

@matthiasdiener matthiasdiener requested a review from aris134 June 1, 2026 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-level 1 CI test level 1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants