Skip to content

Commit 36e2c3a

Browse files
committed
refactor
1 parent ddc42c2 commit 36e2c3a

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

mlir/include/mlir/Dialect/XeGPU/IR/XeGPU.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@
2222
namespace mlir {
2323
namespace xegpu {
2424
class TensorDescType;
25+
class LayoutAttr;
2526
} // namespace xegpu
2627
} // namespace mlir
2728

29+
#include <mlir/Dialect/XeGPU/IR/XeGPUDialect.h.inc>
2830
#include <mlir/Dialect/XeGPU/IR/XeGPUAttrInterface.h.inc>
2931
#include <mlir/Dialect/XeGPU/IR/XeGPUEnums.h.inc>
32+
3033
#define GET_ATTRDEF_CLASSES
3134
#include <mlir/Dialect/XeGPU/IR/XeGPUAttrs.h.inc>
3235
#define GET_TYPEDEF_CLASSES
3336
#include <mlir/Dialect/XeGPU/IR/XeGPUTypes.h.inc>
34-
35-
#include <mlir/Dialect/XeGPU/IR/XeGPUDialect.h.inc>
36-
3737
#define GET_OP_CLASSES
3838
#include <mlir/Dialect/XeGPU/IR/XeGPU.h.inc>
3939

mlir/include/mlir/Dialect/XeGPU/IR/XeGPUAttrs.td

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -396,24 +396,15 @@ def XeGPU_SliceAttr : XeGPUAttr<"Slice", "slice", [LayoutTrait]> {
396396
std::optional<llvm::SmallVector<int32_t>> getEffectiveSgLayout() const {
397397
if (DenseI32ArrayAttr layout = getParent().getSgLayout()) {
398398
llvm::ArrayRef<int64_t> dims = getDims().asArrayRef();
399-
llvm::SmallVector<int32_t> result;
400-
for (auto [i, v]: llvm::enumerate(layout.asArrayRef())) {
401-
if (!llvm::is_contained(dims, i))
402-
result.push_back(v);
403-
}
404-
return result;
399+
return XeGPUDialect::dropDims(layout.asArrayRef(), dims);
405400
}
406401
return std::nullopt;
407402
}
403+
408404
std::optional<llvm::SmallVector<int32_t>> getEffectiveSgData() const {
409405
if (DenseI32ArrayAttr data = getParent().getSgData()) {
410406
llvm::ArrayRef<int64_t> dims = getDims().asArrayRef();
411-
llvm::SmallVector<int32_t> result;
412-
for (auto [i, v]: llvm::enumerate(data.asArrayRef())) {
413-
if (!llvm::is_contained(dims, i))
414-
result.push_back(v);
415-
}
416-
return result;
407+
return XeGPUDialect::dropDims(data.asArrayRef(), dims);
417408
}
418409
return std::nullopt;
419410
}

mlir/include/mlir/Dialect/XeGPU/IR/XeGPUDialect.td

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ def XeGPU_Dialect : Dialect {
4141
/// Checks if the given shape can be evenly distributed based on the layout
4242
/// and data factors provided by the LayoutAttr.
4343
static bool isEvenlyDistributable(llvm::ArrayRef<int64_t> shape, xegpu::LayoutAttr attr);
44+
45+
/// drops the data in the specified dimension, and return the rest. e.g.,
46+
/// for data = [32, 64, 8], dropPositions = [0, 2], it will return [64]
47+
template<typename T, typename U>
48+
static llvm::SmallVector<T> dropDims(llvm::ArrayRef<T> data, llvm::ArrayRef<U> dropPositions) {
49+
llvm::SmallVector<T> result;
50+
for (auto [i, v]: llvm::enumerate(data)) {
51+
if (!llvm::is_contained(dropPositions, i))
52+
result.push_back(v);
53+
}
54+
return result;
55+
}
4456
}];
4557
}
4658

0 commit comments

Comments
 (0)