@@ -76,32 +76,6 @@ getSgShapeAndCount(ArrayRef<int64_t> shape,
7676 return std::make_pair (sgShape, count);
7777}
7878
79- // / Generates element-wise addition ops of two arrays with automatic alignment.
80- // / When the input arrays have different sizes, the shorter array is
81- // / right-aligned with the longer array, and the unmatched leading elements from
82- // / the longer array are preserved unchanged. This is commonly used for offset
83- // / computation where higher-dimensional offsets need to be added to
84- // / lower-dimensional adjustments.
85- // /
86- // / Example:
87- // / lhs = [10, 20, 30], rhs = [5, 7]
88- // / Result: [10, 25, 37] (20+5, 30+7, with 10 preserved)
89- static SmallVector<OpFoldResult>
90- genIndexAdds (ConversionPatternRewriter &rewriter, Location loc,
91- ArrayRef<OpFoldResult> lhs, ArrayRef<OpFoldResult> rhs) {
92- // ensure a is longer than b
93- ArrayRef<OpFoldResult> a = lhs.size () >= rhs.size () ? lhs : rhs;
94- ArrayRef<OpFoldResult> b = lhs.size () >= rhs.size () ? rhs : lhs;
95- SmallVector<OpFoldResult> results (a.take_front (a.size () - b.size ()));
96- a = a.slice (a.size () - b.size ());
97- for (auto [l, r] : llvm::zip (a, b)) {
98- auto lval = getValueOrCreateConstantIndexOp (rewriter, loc, l);
99- auto rval = getValueOrCreateConstantIndexOp (rewriter, loc, r);
100- results.push_back (rewriter.createOrFold <index::AddOp>(loc, lval, rval));
101- }
102- return results;
103- }
104-
10579// / Utility helper for deriving a list of offsets for each sub-TensorDescs
10680// / or sub-MemDescs to be accessed by current subgroup (sgId) based on the
10781// / associated distribute layout attribute, the shape, subgroup id and the
@@ -150,8 +124,8 @@ genOffsetsList(ConversionPatternRewriter &rewriter, OpType op,
150124 // or sub-memory descriptor.
151125 // SmallVector<SmallVector<OpFoldResult>> offsetsList;
152126 for (const auto &sgOffsets : *maybeDescOffsets) {
153- SmallVector<OpFoldResult> newOffsets =
154- genIndexAdds ( rewriter, loc, getAsOpFoldResult (sgOffsets), origOffsets);
127+ SmallVector<OpFoldResult> newOffsets = xegpu::addWithRightAligned (
128+ rewriter, loc, getAsOpFoldResult (sgOffsets), origOffsets);
155129 offsetsList.push_back (std::move (newOffsets));
156130 }
157131
0 commit comments