Skip to content

[proof-of-concept] add MXFP8 pre-swizzling for gfx1250#568

Draft
matthiasdiener wants to merge 18 commits intodevfrom
mdiener/mxfp8-swizzle
Draft

[proof-of-concept] add MXFP8 pre-swizzling for gfx1250#568
matthiasdiener wants to merge 18 commits intodevfrom
mdiener/mxfp8-swizzle

Conversation

@matthiasdiener
Copy link
Copy Markdown
Contributor

@matthiasdiener matthiasdiener commented Apr 29, 2026

Description

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

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

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 Apr 29, 2026
@matthiasdiener matthiasdiener added the ci-level 1 CI test level 1 label Apr 29, 2026
@matthiasdiener matthiasdiener force-pushed the mdiener/mxfp8-swizzle branch from ddf19da to 313a6b7 Compare May 3, 2026 22:06
@matthiasdiener matthiasdiener requested a review from alextmagro May 4, 2026 16:33
Copy link
Copy Markdown
Contributor

@alextmagro alextmagro left a comment

Choose a reason for hiding this comment

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

Hi Matthias, a few comments. I also assume you are still planning on adding in the hooks to scale swizzle when we're on gfx1250? I believe there were hooks in all of common, pytorch and jax. These PRs removed them, so would be a partial revert.

#420
#424
#442

asm volatile("ds_swizzle_b32 %0, %1 offset:0x041F\n\t"
"s_waitcnt lgkmcnt(0)" : "=v"(r) : "v"(v));
return r;
return __shfl_xor(v, 1);
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.

Do we still need these helper functions now that we're just doing a __shfl_xor?

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.

This change is only inadvertently part of this PR, it is already part of #571. Will revert here.

// Col-wise: input is [K_scale, M] row-major (M contiguous), representing
// the column-wise scale matrix logically shaped [M, K_scale].
// Logical (m, k) maps to physical address k * original_M + m.
__global__ void __launch_bounds__(256)
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.

This function is almost identical to the rowwise scaling func, can we merge them and template? Ideally we could have 1 thread write both the colwise and rowwise scale if we are doing both.

const int k = idx % K_scale;

uint8_t val = 127;
if (m < original_M && k < original_K) {
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.

Could we move this check to the hostside, or remove it completely?

: public ::testing::TestWithParam<
std::tuple<std::pair<int, int>, bool>> {};

TEST_P(MxSwizzleTestSuite, TestMxSwizzle) {
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.

I think full GEMM tests should live in test_cublaslt.cu. Also, wondering if this is not already covered by the MXFP8 gemm tests present there, if we are always swizzling. Probably should limit tests here to just testing the swizzled scales, if needed at all.

#include <cstdint>

#include "../common.h"
#include "../util/cuda_runtime.h"
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.

Why is this include needed?

" (got shape=", shape, ")");
#ifdef USE_ROCM
// gfx1250 MX pre-swizzle (Tensile 3D) layout requires M padded to multiple of 4.
// Other ROCm architectures use 128x4 tiles but currently skip padding
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.

I'm not sure this is true regarding us using 128x4 tiles. 128x4 scaling is an upstream requirement. We also have padding expectations in pytorch, jax, and all 3 test dirs have padding that will probably need fixing.

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.

2 participants