Skip to content

Commit 6d36505

Browse files
committed
add lit tests for swizzle config
Made-with: Cursor Signed-off-by: Yu-Zhewen <zhewenyu@amd.com>
1 parent 219deee commit 6d36505

2 files changed

Lines changed: 52 additions & 15 deletions

File tree

compiler/src/iree/compiler/Codegen/Dialect/GPU/TargetUtils/ConfigUtils.cpp

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -916,22 +916,27 @@ getMatmulOrIGEMMLoweringConfigAndWorkgroupSize(
916916
if (!scaled && useDirectLoad) {
917917
Attribute lhsAttr = useGlobalDma;
918918
Attribute rhsAttr = useGlobalDma;
919-
// Apply XOR swizzle for bank conflict avoidance. Only swizzle operands
920-
// whose reduction dim is innermost (contiguous reads).
921-
if (!transposedLhs) {
922-
FailureOr<Attribute> lhsSwizzleAttr =
923-
getXorShuffleAttr(context, useGlobalDma, target, kind,
924-
schedule->kTileSizes, kMMAOperandLhs);
925-
if (succeeded(lhsSwizzleAttr)) {
926-
lhsAttr = *lhsSwizzleAttr;
919+
// Apply XOR swizzle for BF16 DMA operands whose reduction dim is
920+
// innermost (contiguous reads) to avoid LDS bank conflicts.
921+
SmallVector<Type> elemTypes;
922+
kind.getElementTypes(elemTypes);
923+
bool isBF16 = !elemTypes.empty() && elemTypes[0].isBF16();
924+
if (isBF16) {
925+
if (!transposedLhs) {
926+
FailureOr<Attribute> lhsSwizzleAttr =
927+
getXorShuffleAttr(context, useGlobalDma, target, kind,
928+
schedule->kTileSizes, kMMAOperandLhs);
929+
if (succeeded(lhsSwizzleAttr)) {
930+
lhsAttr = *lhsSwizzleAttr;
931+
}
927932
}
928-
}
929-
if (transposedRhs) {
930-
FailureOr<Attribute> rhsSwizzleAttr =
931-
getXorShuffleAttr(context, useGlobalDma, target, kind,
932-
schedule->kTileSizes, kMMAOperandRhs);
933-
if (succeeded(rhsSwizzleAttr)) {
934-
rhsAttr = *rhsSwizzleAttr;
933+
if (transposedRhs) {
934+
FailureOr<Attribute> rhsSwizzleAttr =
935+
getXorShuffleAttr(context, useGlobalDma, target, kind,
936+
schedule->kTileSizes, kMMAOperandRhs);
937+
if (succeeded(rhsSwizzleAttr)) {
938+
rhsAttr = *rhsSwizzleAttr;
939+
}
935940
}
936941
}
937942
promotionArray = {lhsAttr, rhsAttr};

compiler/src/iree/compiler/Codegen/LLVMGPU/test/ROCDL/config_tile_and_fuse_gfx950.mlir

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,38 @@ func.func @scaled_matmul_accumulate(
386386

387387
// -----
388388

389+
// BF16 matmul with direct-load DMA gets LHS XOR swizzle for bank conflict
390+
// avoidance. Only LHS is swizzled (reduction dim is innermost for A[M,K]).
391+
func.func @matmul_bf16(
392+
%arg0: tensor<4096x4096xbf16>,
393+
%arg1: tensor<4096x4096xbf16>,
394+
%arg2: tensor<4096x4096xf32>) -> tensor<4096x4096xf32> {
395+
%0 = linalg.matmul ins(%arg0, %arg1 : tensor<4096x4096xbf16>, tensor<4096x4096xbf16>)
396+
outs(%arg2 : tensor<4096x4096xf32>) -> tensor<4096x4096xf32>
397+
return %0 : tensor<4096x4096xf32>
398+
}
399+
// CHECK-LABEL: func.func @matmul_bf16
400+
// CHECK: lowering_config = #iree_gpu.lowering_config
401+
// CHECK-SAME: mma_kind = #iree_gpu.mma_layout<MFMA_F32_16x16x32_BF16>
402+
403+
// CHECK-REMARKS: [Analysis] SharedMemoryUsage
404+
// CHECK-REMARKS-SAME: Category:deduceMMASchedule
405+
// CHECK-REMARKS-SAME: Remark=16384
406+
407+
// CHECK-REMARKS-DIRECT-LOAD-2: [Analysis] SharedMemoryUsage
408+
// CHECK-REMARKS-DIRECT-LOAD-2-SAME: Category:deduceMMASchedule
409+
// CHECK-REMARKS-DIRECT-LOAD-2-SAME: Remark=32768
410+
411+
// CHECK-REMARKS-DIRECT-LOAD-3: [Analysis] SharedMemoryUsage
412+
// CHECK-REMARKS-DIRECT-LOAD-3-SAME: Category:deduceMMASchedule
413+
// CHECK-REMARKS-DIRECT-LOAD-3-SAME: Remark=49152
414+
415+
// CHECK-DIRECT-LOAD-LABEL: func.func @matmul_bf16
416+
// CHECK-DIRECT-LOAD: linalg.matmul {lowering_config = #iree_gpu.lowering_config
417+
// CHECK-DIRECT-LOAD-SAME: promotion_types = [#iree_gpu.swizzle_operand<copy_config = #iree_gpu.use_global_load_dma, swizzle = #iree_codegen.xor_shuffle<128, 8>>, #iree_gpu.use_global_load_dma]
418+
419+
// -----
420+
389421
// Very large f16 matmul — compute-bound, so picks 32x32x16 (higher compute per
390422
// instruction, lower VGPR pressure than 16x16x32).
391423
func.func @matmul_f16_compute_bound(

0 commit comments

Comments
 (0)