Skip to content

Commit f5bb397

Browse files
Jianhui-Liclaude
andauthored
[MLIR][XeGPU] Fix Layout collapse dims out of bounds (#193661)
Fix a bug in LayoutAttr::collapseDims() implementation. --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 6df5ced commit f5bb397

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

mlir/lib/Dialect/XeGPU/IR/XeGPUDialect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ DistributeLayoutAttr LayoutAttr::collapseDims(SmallVector<int64_t> dimGroup) {
615615
// say we have orderVec = {5, 3, 2, 1, 0}
616616
// Create indices [0, 1, 2, 3, 4]
617617
SmallVector<size_t> indices =
618-
llvm::to_vector(llvm::seq<size_t>(0, orderAttr.size()));
618+
llvm::to_vector(llvm::seq<size_t>(0, origOrder.size()));
619619

620620
// Sort indices based on corresponding values
621621
llvm::sort(indices,

mlir/test/Dialect/XeGPU/propagate-layout-inst-data.mlir

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,3 +373,29 @@ gpu.module @test{
373373
gpu.return
374374
}
375375
}
376+
377+
// -----
378+
// CHECK-LABEL: gpu.func @shape_cast_collapse_dims_with_order
379+
gpu.module @test_collapse_dims [#xevm.target<O = 3, chip = "pvc">] {
380+
gpu.func @shape_cast_collapse_dims_with_order(%arg0: memref<32x32xf32>) {
381+
// CHECK: %[[STEP:.*]] = vector.step {{.*}} : vector<1024xindex>
382+
%0 = vector.step : vector<1024xindex>
383+
384+
// Shape cast from 1D to 2D triggers collapseDims in layout propagation
385+
// CHECK: %[[CAST:.*]] = vector.shape_cast %[[STEP]] {{.*}} : vector<1024xindex> to vector<32x32xindex>
386+
%1 = vector.shape_cast %0 : vector<1024xindex> to vector<32x32xindex>
387+
388+
// Anchor the layout with a store operation
389+
%ptr = memref.extract_aligned_pointer_as_index %arg0 : memref<32x32xf32> -> index
390+
%ptr_i64 = arith.index_cast %ptr : index to i64
391+
%mask = arith.constant dense<true> : vector<32x32xi1>
392+
%data = arith.constant dense<0.0> : vector<32x32xf32>
393+
394+
// CHECK: xegpu.store {{.*}} <{{{.*}}layout = #xegpu.layout<inst_data = [32, 32]>{{.*}}}> :
395+
xegpu.store %data, %ptr_i64[%1], %mask {
396+
layout = #xegpu.layout<inst_data = [32, 32]>
397+
} : vector<32x32xf32>, i64, vector<32x32xindex>, vector<32x32xi1>
398+
399+
gpu.return
400+
}
401+
}

0 commit comments

Comments
 (0)