Changeset View
Changeset View
Standalone View
Standalone View
mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
Show First 20 Lines • Show All 860 Lines • ▼ Show 20 Lines | static LogicalResult verify(ConvOp op) { | ||||
if (auto dilations = op.dilations()) { | if (auto dilations = op.dilations()) { | ||||
if (failed(verifyStrideOrDilation(op, dilations->getValue(), | if (failed(verifyStrideOrDilation(op, dilations->getValue(), | ||||
/*isStride=*/false))) | /*isStride=*/false))) | ||||
return failure(); | return failure(); | ||||
} | } | ||||
return success(); | return success(); | ||||
} | } | ||||
static AffineMap extractOrIdentityMap(Optional<AffineMap> maybeMap, | |||||
unsigned rank, MLIRContext *context) { | |||||
if (maybeMap) | |||||
return maybeMap.getValue(); | |||||
if (rank == 0) | |||||
return AffineMap(); | |||||
return AffineMap::getMultiDimIdentityMap(rank, context); | |||||
} | |||||
namespace mlir { | namespace mlir { | ||||
namespace linalg { | namespace linalg { | ||||
#include "mlir/Dialect/Linalg/IR/LinalgStructuredOpsInterfaces.cpp.inc" | #include "mlir/Dialect/Linalg/IR/LinalgStructuredOpsInterfaces.cpp.inc" | ||||
#define GET_OP_CLASSES | #define GET_OP_CLASSES | ||||
#include "mlir/Dialect/Linalg/IR/LinalgOps.cpp.inc" | #include "mlir/Dialect/Linalg/IR/LinalgOps.cpp.inc" | ||||
#define GET_OP_CLASSES | #define GET_OP_CLASSES | ||||
#include "mlir/Dialect/Linalg/IR/LinalgStructuredOps.cpp.inc" | #include "mlir/Dialect/Linalg/IR/LinalgStructuredOps.cpp.inc" | ||||
} // namespace linalg | } // namespace linalg | ||||
} // namespace mlir | } // namespace mlir | ||||
static AffineMap extractOrIdentityMap(Optional<AffineMap> maybeMap, | |||||
unsigned rank, MLIRContext *context) { | |||||
if (maybeMap) | |||||
return maybeMap.getValue(); | |||||
if (rank == 0) | |||||
return AffineMap(); | |||||
return AffineMap::getMultiDimIdentityMap(rank, context); | |||||
} | |||||
// Returns `num` AffineDimExpr dimensions at positions [curIdx, curIdx + num) | // Returns `num` AffineDimExpr dimensions at positions [curIdx, curIdx + num) | ||||
// and increments `curIdx` to `curIdx + num`. | // and increments `curIdx` to `curIdx + num`. | ||||
static SmallVector<AffineExpr, 4> | static SmallVector<AffineExpr, 4> | ||||
makeAffineDimExprs(unsigned num, unsigned &curIdx, MLIRContext *context) { | makeAffineDimExprs(unsigned num, unsigned &curIdx, MLIRContext *context) { | ||||
SmallVector<AffineExpr, 4> res; | SmallVector<AffineExpr, 4> res; | ||||
res.reserve(num); | res.reserve(num); | ||||
for (unsigned i = 0; i < num; ++i) | for (unsigned i = 0; i < num; ++i) | ||||
res.push_back(getAffineDimExpr(curIdx++, context)); | res.push_back(getAffineDimExpr(curIdx++, context)); | ||||
▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | return SmallVector<AffineMap, 4>{ | ||||
// filter[z[0], ..., z[N-1], q, k] | // filter[z[0], ..., z[N-1], q, k] | ||||
AffineMap::get(idx, 0, concat(concat(zs, qs), ks)), | AffineMap::get(idx, 0, concat(concat(zs, qs), ks)), | ||||
// input[b, | // input[b, | ||||
// x[0]*s[0] + d[0]*z[0], ..., x[N-1]*s[N-1] + d[N-1]*z[N-1], | // x[0]*s[0] + d[0]*z[0], ..., x[N-1]*s[N-1] + d[N-1]*z[N-1], | ||||
// q] | // q] | ||||
AffineMap::get(idx, 0, concat(concat(bs, ws), qs)), | AffineMap::get(idx, 0, concat(concat(bs, ws), qs)), | ||||
// output[b, x[0], ..., x[N-1], k] | // output[b, x[0], ..., x[N-1], k] | ||||
AffineMap::get(idx, 0, concat(concat(bs, xs), ks))}; | AffineMap::get(idx, 0, concat(concat(bs, xs), ks))}; | ||||
} else if (auto genericOp = dyn_cast<GenericOp>(op)) { | |||||
SmallVector<AffineMap, 4> res; | |||||
unsigned nViews = genericOp.getNumInputsAndOutputs(); | |||||
res.reserve(nViews); | |||||
for (unsigned i = 0, e = nViews; i < e; ++i) { | |||||
res.push_back(genericOp.getIndexingMap(i)); | |||||
} | } | ||||
return res; | |||||
} else if (auto indexedGenericOp = dyn_cast<IndexedGenericOp>(op)) { | |||||
SmallVector<AffineMap, 4> res; | SmallVector<AffineMap, 4> res; | ||||
unsigned nViews = indexedGenericOp.getNumInputsAndOutputs(); | auto linalgOp = cast<LinalgOp>(op); | ||||
unsigned nViews = linalgOp.getNumInputsAndOutputs(); | |||||
res.reserve(nViews); | res.reserve(nViews); | ||||
for (unsigned i = 0, e = nViews; i < e; ++i) | for (unsigned i = 0, e = nViews; i < e; ++i) | ||||
res.push_back(indexedGenericOp.getIndexingMap(i)); | res.push_back(linalgOp.getIndexingMap(i)); | ||||
assert(nViews == linalgOp.indexing_maps().size()); | |||||
return res; | return res; | ||||
} | } | ||||
llvm_unreachable("Missing loopToOperandRangesMaps for op"); | |||||
} | |||||
static void appendMangledType(llvm::raw_string_ostream &ss, Type t) { | static void appendMangledType(llvm::raw_string_ostream &ss, Type t) { | ||||
if (auto memref = t.dyn_cast<MemRefType>()) { | if (auto memref = t.dyn_cast<MemRefType>()) { | ||||
ss << "view"; | ss << "view"; | ||||
for (auto size : memref.getShape()) | for (auto size : memref.getShape()) | ||||
if (size < 0) | if (size < 0) | ||||
ss << "sx"; | ss << "sx"; | ||||
else | else | ||||
▲ Show 20 Lines • Show All 105 Lines • Show Last 20 Lines |