Skip to content

Commit 69046b4

Browse files
committed
[mlir] Skip scalar operands when tiling to linalg.tiled_loop.
We are interested only in tensors/memrefs when creating a TiledLoopOp. Differential Revision: https://reviews.llvm.org/D105059
1 parent 9d0bf76 commit 69046b4

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

mlir/lib/Dialect/Linalg/Utils/Utils.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,19 @@ void GenerateLoopNest<TiledLoopOp>::doit(
284284
SmallVector<Value, 4> lbs, ubs, steps;
285285
unpackRanges(loopRanges, lbs, ubs, steps);
286286

287+
auto dropNonShapedValues =
288+
[](ArrayRef<OpOperand *> operands) -> SmallVector<Value, 2> {
289+
SmallVector<Value, 2> filteredOperands;
290+
for (OpOperand *operand : operands) {
291+
Type type = operand->get().getType();
292+
if (type.isa<ShapedType>())
293+
filteredOperands.push_back(operand->get());
294+
}
295+
return filteredOperands;
296+
};
297+
auto inputOperands = dropNonShapedValues(linalgOp.getInputOperands());
298+
auto outputOperands = dropNonShapedValues(linalgOp.getOutputOperands());
299+
287300
auto wrappedBuilderFn = [&](OpBuilder &nestedBuilder, Location nestedLoc,
288301
ValueRange ivs, ValueRange inputs,
289302
ValueRange outputs) {
@@ -292,9 +305,6 @@ void GenerateLoopNest<TiledLoopOp>::doit(
292305
bodyBuilderFn(nestedBuilder, nestedLoc, ivs, outputTensors);
293306
nestedBuilder.create<linalg::YieldOp>(nestedLoc, results);
294307
};
295-
296-
SmallVector<Value> inputOperands = linalgOp.getInputOperands();
297-
SmallVector<Value> outputOperands = linalgOp.getOutputOperands();
298308
auto tiledLoop =
299309
b.create<TiledLoopOp>(loc, lbs, ubs, steps, inputOperands, outputOperands,
300310
b.getArrayAttr(iteratorTypes), wrappedBuilderFn);

mlir/test/Dialect/Linalg/tile-tensors.mlir

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,17 @@ func @generic_op_tensors(
130130
// TLOOP-SAME: ins (%{{.*}} = %[[ARG_0]]: [[TY]], %{{.*}} = %[[ARG_1]]: [[TY]])
131131
// TLOOP-SAME: outs (%{{.*}} = %[[INIT]]: [[TY]])
132132
// TLOOP-SAME: distribution["block_x", "block_y", "none"] {
133+
134+
135+
func @fill(%arg0 : tensor<?x?x?xf32>) -> tensor<?x?x?xf32> {
136+
%c0 = constant 0.0 : f32
137+
%0 = linalg.fill(%c0, %arg0) : f32, tensor<?x?x?xf32> -> tensor<?x?x?xf32>
138+
return %0 : tensor<?x?x?xf32>
139+
}
140+
// CHECK-LABEL: func @fill
141+
142+
// TLOOP-LABEL: func @fill
143+
// TLOOP-NOT: ins
144+
// TLOOP: tensor.extract_slice
145+
// TLOOP-NEXT: linalg.fill
146+
// TLOOP-NEXT: tensor.insert_slice

0 commit comments

Comments
 (0)