1313#include " llvm/ADT/TypeSwitch.h"
1414#include < numeric>
1515
16+ using std::optional;
17+
1618namespace mlir {
1719namespace 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
0 commit comments