Skip to content

Commit 16d1980

Browse files
committed
fix the format
1 parent f8dda5c commit 16d1980

File tree

3 files changed

+40
-22
lines changed

3 files changed

+40
-22
lines changed

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include "llvm/ADT/TypeSwitch.h"
1414
#include <numeric>
1515

16+
using std::optional;
17+
1618
namespace mlir {
1719
namespace xegpu {
1820

@@ -37,18 +39,18 @@ bool XeGPUDialect::isEvenlyDistributable(llvm::ArrayRef<int64_t> shape,
3739
xegpu::LayoutAttr attr) {
3840
assert(attr && "Layout attribute is missing.");
3941

40-
// Checks whether the given shape can be evenly distributed using the specified
41-
// layout and data attributes. If successful, it returns the work size for each
42-
// compute unit; otherwise, it returns `std::nullopt`. The work size per compute
43-
// unit is calculated as follows:
42+
// Checks whether the given shape can be evenly distributed using the
43+
// specified layout and data attributes. If successful, it returns the work
44+
// size for each compute unit; otherwise, it returns `std::nullopt`. The work
45+
// size per compute unit is calculated as follows:
4446
// - If `data` is null: newShape[i] = shape[i] / layout[i]
4547
// - If `data` is not null: newShape[i] = data[i]
46-
// When round-robin distribution (`use_rr`) is enabled, `shape[i]` can be smaller
47-
// than `layout[i] * data[i]`, allowing multiple compute units to share the data.
48-
auto tryDistribute =
49-
[&](llvm::ArrayRef<int64_t> shape, DenseI32ArrayAttr layout,
50-
DenseI32ArrayAttr data,
51-
bool use_rr = true) -> std::optional<SmallVector<int64_t>> {
48+
// When round-robin distribution (`rr`) is enabled, `shape[i]` can be
49+
// smaller than `layout[i] * data[i]`, allowing multiple compute units to
50+
// share the data.
51+
auto tryDistribute = [&](llvm::ArrayRef<int64_t> shape,
52+
DenseI32ArrayAttr layout, DenseI32ArrayAttr data,
53+
bool rr = true) -> optional<SmallVector<int64_t>> {
5254
llvm::SmallVector<int64_t> newShape(shape);
5355
if (layout) {
5456
auto vec = llvm::to_vector_of<int64_t>(layout.asArrayRef());
@@ -65,7 +67,7 @@ bool XeGPUDialect::isEvenlyDistributable(llvm::ArrayRef<int64_t> shape,
6567
if (vec.size() != shape.size())
6668
return std::nullopt;
6769
auto ratio = computeShapeRatio(newShape, vec);
68-
if (!ratio.has_value() && use_rr)
70+
if (!ratio.has_value() && rr)
6971
ratio = computeShapeRatio(vec, newShape);
7072
if (!ratio.has_value())
7173
return std::nullopt;
@@ -91,8 +93,8 @@ bool XeGPUDialect::isEvenlyDistributable(llvm::ArrayRef<int64_t> shape,
9193
auto instShape = maybeInstShape.value();
9294

9395
// check LaneLayout and LaneData
94-
auto maybeLaneShape = tryDistribute(instShape, attr.getLaneLayout(),
95-
attr.getLaneData(), false);
96+
auto maybeLaneShape =
97+
tryDistribute(instShape, attr.getLaneLayout(), attr.getLaneData(), false);
9698
return maybeLaneShape.has_value();
9799
}
98100

mlir/test/Dialect/XeGPU/invalid.mlir

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,17 @@ func.func @test_load_nd_vc_3(%src: memref<8x16xf16>) {
9898
return
9999
}
100100

101+
// -----
102+
func.func @test_load_nd_vc_4(%src: memref<24x32xf32>) {
103+
%1 = xegpu.create_nd_tdesc %src[0, 0] : memref<24x32xf32> ->
104+
!xegpu.tensor_desc<8x16xf32>
105+
// expected-error@+1 {{Result shape [8, 1] is not consistent with tensor descriptor}}
106+
%2 = xegpu.load_nd %1 <{l1_hint = #xegpu.cache_hint<cached>,
107+
l2_hint = #xegpu.cache_hint<uncached>}>
108+
: !xegpu.tensor_desc<8x16xf32> -> vector<8x1xf32>
109+
return
110+
}
111+
101112
// -----
102113
func.func @test_load_nd_layout(%src: memref<24x32xf32>) {
103114
%1 = xegpu.create_nd_tdesc %src[0, 0] : memref<24x32xf32> -> !xegpu.tensor_desc<16xf32>
@@ -108,13 +119,10 @@ func.func @test_load_nd_layout(%src: memref<24x32xf32>) {
108119
}
109120

110121
// -----
111-
func.func @test_load_nd_vc_6(%src: memref<24x32xf32>) {
112-
%1 = xegpu.create_nd_tdesc %src[0, 0] : memref<24x32xf32> ->
113-
!xegpu.tensor_desc<8x16xf32>
114-
// expected-error@+1 {{Result shape [8, 1] is not consistent with tensor descriptor}}
115-
%2 = xegpu.load_nd %1 <{l1_hint = #xegpu.cache_hint<cached>,
116-
l2_hint = #xegpu.cache_hint<uncached>}>
117-
: !xegpu.tensor_desc<8x16xf32> -> vector<8x1xf32>
122+
func.func @test_load_nd_simt(%src: memref<24x32xf32>) {
123+
%1 = xegpu.create_nd_tdesc %src[0, 0] : memref<24x32xf32> -> !xegpu.tensor_desc<8x16xf32, #xegpu.layout<lane_layout = [1, 16], lane_data = [1, 1]>>
124+
// expected-error@+1 {{TensorDesc doesn't need LayoutAttr for SIMT code}}
125+
%2 = xegpu.load_nd %1 : !xegpu.tensor_desc<8x16xf32, #xegpu.layout<lane_layout = [1, 16], lane_data = [1, 1]>> -> vector<8xf32>
118126
return
119127
}
120128

@@ -156,6 +164,14 @@ func.func @test_store_nd_simt(%dst: memref<24x32xf32>, %data: vector<3xf32>) {
156164
return
157165
}
158166

167+
// -----
168+
func.func @test_store_nd_simt(%src: memref<24x32xf32>, %data: vector<8xf32>) {
169+
%1 = xegpu.create_nd_tdesc %src[0, 0] : memref<24x32xf32> -> !xegpu.tensor_desc<8x16xf32, #xegpu.layout<lane_layout = [1, 16], lane_data = [1, 1]>>
170+
// expected-error@+1 {{TensorDesc doesn't need LayoutAttr for SIMT code}}
171+
xegpu.store_nd %data, %1 : vector<8xf32>, !xegpu.tensor_desc<8x16xf32, #xegpu.layout<lane_layout = [1, 16], lane_data = [1, 1]>>
172+
return
173+
}
174+
159175
// -----
160176
func.func @test_store_nd_vc_5(%dst: memref<24x32xf32>, %data: vector<8x1xf32>) {
161177
%1 = xegpu.create_nd_tdesc %dst[0, 0] : memref<24x32xf32> ->

mlir/test/Dialect/XeGPU/ops.mlir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ gpu.func @test_load_nd_vc(%src: memref<8x16xf16>) {
148148
gpu.func @test_load_nd_simt(%src: memref<8x16xf16>) {
149149
// CHECK: %[[R0:.*]] = xegpu.create_nd_tdesc %arg0[0, 0] : memref<8x16xf16> -> !xegpu.tensor_desc<8x16xf16>
150150
%1 = xegpu.create_nd_tdesc %src[0, 0] : memref<8x16xf16> -> !xegpu.tensor_desc<8x16xf16>
151-
// CHECK: %[[R1:.*]] = xegpu.load_nd %[[R0]] <{l1_hint = #xegpu.cache_hint<cached>, l2_hint = #xegpu.cache_hint<uncached>, packed}> : !xegpu.tensor_desc<8x16xf16> -> vector<8xf16>
152-
%2 = xegpu.load_nd %1 <{packed, l1_hint = #xegpu.cache_hint<cached>, l2_hint = #xegpu.cache_hint<uncached>}>
151+
// CHECK: %[[R1:.*]] = xegpu.load_nd %[[R0]] <{l1_hint = #xegpu.cache_hint<cached>, l2_hint = #xegpu.cache_hint<uncached>}> : !xegpu.tensor_desc<8x16xf16> -> vector<8xf16>
152+
%2 = xegpu.load_nd %1 <{l1_hint = #xegpu.cache_hint<cached>, l2_hint = #xegpu.cache_hint<uncached>}>
153153
: !xegpu.tensor_desc<8x16xf16> -> vector<8xf16>
154154
gpu.return
155155
}

0 commit comments

Comments
 (0)