Skip to content

Commit 65dbc98

Browse files
authored
[Backend] Support TMA lowering for arbitrary (swizzled) SMEM layout (#2380)
1 parent a4ab99e commit 65dbc98

11 files changed

Lines changed: 3560 additions & 216 deletions

File tree

examples/gemm/example_gemm_intrinsics.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ def make_swizzle_layout(shared_buf):
1717
return T.Layout(shape, lambda *args: args)
1818

1919
def transform_func(i, j):
20-
new_warp_i, new_warp_j = get_swizzle_layout(i, j, shape[-1], dtype)
21-
return [new_warp_i, new_warp_j]
20+
return list(get_swizzle_layout(i, j, shape[-1], dtype))
2221

2322
return T.Layout(shape, transform_func)
2423

src/cuda/op/copy.cc

Lines changed: 440 additions & 187 deletions
Large diffs are not rendered by default.

src/cuda/transform/producer_consumer_ws.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
#include "backend/common/target_utils.h"
3636
#include "cuda/op/copy.h"
37+
#include "layout/cute_layout.h"
3738
#include "multi_version_buffer_rewriter.h"
3839
#include "op/builtin.h"
3940
#include "op/copy.h"
@@ -2620,15 +2621,14 @@ class ManualWSDetector : public StmtExprVisitor {
26202621
/// swizzle modes (32B / 64B / 128B). Any other layout (e.g. padded,
26212622
/// Volta-style) cannot be used with TMA.
26222623
static bool IsTmaCompatibleLayout(const Layout &layout, const Buffer &buffer) {
2623-
// Recognised swizzle → TMA with swizzle.
2624-
if (DetectSwizzleMode(layout, buffer) != SwizzleMode::kNone) {
2625-
return true;
2626-
}
2627-
// Identity / row-major linear → TMA without swizzle.
2628-
if (StructuralEqual()(layout, makeLinearLayout(buffer->shape))) {
2629-
return true;
2630-
}
2631-
return false;
2624+
Optional<cute::ComposedLayout> composed =
2625+
cute::ComposedLayoutFromTileLang(layout);
2626+
if (!composed.defined())
2627+
return false;
2628+
// Recast to byte space (the swizzle atom is defined on byte addresses).
2629+
cute::ComposedLayout composed_bytes =
2630+
composed.value().Recast(buffer->dtype.bits(), /*new_bits=*/8);
2631+
return composed_bytes->swizzle->IsTMACompatible();
26322632
}
26332633

26342634
class TiledWSCandidate : public StmtExprVisitor {

0 commit comments

Comments
 (0)