Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions mlir/include/mlir/IR/AffineMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,9 @@ class AffineMap {
/// Returns true if the AffineMap represents a symbol-less permutation map.
bool isPermutation() const;

/// Returns true if the AffineMap contains non-positive coefficients
bool isNonPositiveCoefficients() const;

/// Returns the map consisting of the `resultPos` subset.
AffineMap getSubMap(ArrayRef<unsigned> resultPos) const;

Expand Down
8 changes: 8 additions & 0 deletions mlir/lib/Dialect/Linalg/Transforms/TilingInterfaceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ struct LinalgOpTilingInterface
// specified could lead to out of bounds accesses.
Location loc = op->getLoc();
LinalgOp linalgOp = cast<LinalgOp>(op);
SmallVector<AffineMap> indexingMaps = linalgOp.getIndexingMapsArray();
if (llvm::any_of(linalgOp.getIndexingMapsArray(), [](AffineMap m) {
return m.isNonPositiveCoefficients();
})) {
return linalgOp.emitOpError(
"tiling not supported because op has a non positive coefficient");
}

SmallVector<Value> valuesToTile = linalgOp->getOperands();
SmallVector<Value> tiledOperands = makeTiledShapes(
b, loc, linalgOp, valuesToTile, offsets, sizes, {}, true);
Expand Down
23 changes: 23 additions & 0 deletions mlir/lib/IR/AffineMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "mlir/IR/AffineMap.h"
#include "AffineMapDetail.h"
#include "mlir/IR/AffineExpr.h"
#include "mlir/IR/AffineExprVisitor.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinAttributes.h"
#include "mlir/IR/BuiltinTypes.h"
Expand Down Expand Up @@ -651,6 +652,28 @@ bool AffineMap::isPermutation() const {
return isProjectedPermutation();
}

struct CheckCoefficients : public AffineExprVisitor<CheckCoefficients> {
CheckCoefficients() {}

void visitAffineBinaryOpExpr(AffineBinaryOpExpr expr) {
visit(expr.getLHS());
visit(expr.getRHS());
if (expr.getKind() == mlir::AffineExprKind::Mul)
isNonPositiveCoefficients |=
cast<AffineConstantExpr>(expr.getRHS()).getValue() <= 0;
}
bool isNonPositiveCoefficients = false;
};

bool AffineMap::isNonPositiveCoefficients() const {

return llvm::any_of(getResults(), [](AffineExpr e) {
CheckCoefficients t;
t.visit(e);
return t.isNonPositiveCoefficients;
});
}

AffineMap AffineMap::getSubMap(ArrayRef<unsigned> resultPos) const {
SmallVector<AffineExpr, 4> exprs;
exprs.reserve(resultPos.size());
Expand Down
29 changes: 29 additions & 0 deletions mlir/test/Dialect/Linalg/tile-invalid.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// RUN: mlir-opt %s -transform-interpreter -split-input-file -verify-diagnostics

#map1 = affine_map<(d0) -> (d0)>
#map2 = affine_map<(d0) -> (-d0 + 7)>

func.func @test(%arg0: tensor<8xi8>, %arg1: tensor<8xi8>) -> tensor<8xi8> {
// expected-error @below{{tiling not supported because op has a non positive coefficient}}
// expected-error @below{{op faild to tile operation}}
// expected-error @below{{op failed to generate tiling loops}}
%0 = linalg.generic {
indexing_maps = [#map2, #map1],
iterator_types = ["parallel"]}
ins(%arg0 : tensor<8xi8>)
outs(%arg1 : tensor<8xi8>) {
^bb0(%in: i8, %out: i8):
linalg.yield %in : i8
} -> tensor<8xi8>
return %0 : tensor<8xi8>
}


module attributes {transform.with_named_sequence} {
transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) {
%0 = transform.structured.match ops{["linalg.generic"]} in %arg1 : (!transform.any_op) -> !transform.any_op
%1:2 = transform.structured.tile_using_for
%0 tile_sizes [2] : (!transform.any_op) -> (!transform.any_op, !transform.any_op)
transform.yield
}
}
Loading