24#include "mlir/Dialect/X86/X86Interfaces.cpp.inc"
26#include "mlir/Dialect/X86/X86Dialect.cpp.inc"
32 return memRefDescriptor.
bufferPtr(rewriter, loc, typeConverter, type);
35LogicalResult x86::avx512::MaskCompressOp::verify() {
36 if (getSrc() && getConstantSrc())
37 return emitError(
"cannot use both src and constant_src");
40 return emitError(
"failed to verify that src and dst have same type");
42 if (getConstantSrc() && (getConstantSrc()->
getType() != getDst().
getType()))
44 "failed to verify that constant_src and dst have same type");
53 Adaptor adaptor(operands, *
this);
55 auto opType = adaptor.getA().getType();
57 if (adaptor.getSrc()) {
58 src = adaptor.getSrc();
59 }
else if (adaptor.getConstantSrc()) {
60 src = LLVM::ConstantOp::create(rewriter, loc, opType,
61 adaptor.getConstantSrcAttr());
64 src = LLVM::ConstantOp::create(rewriter, loc, opType, zeroAttr);
77 LLVM::ConstantOp::create(rewriter, getLoc(), rewriter.
getI8Type(), 0xff);
78 intrinsicOperands.push_back(scale);
80 return intrinsicOperands;
86 Adaptor adaptor(operands, *
this);
88 typeConverter, rewriter)};
94 Adaptor adaptor(operands, *
this);
96 typeConverter, rewriter)};
102 Adaptor adaptor(operands, *
this);
104 typeConverter, rewriter)};
109 const unsigned kMaxRows = 16;
110 const unsigned kBitsPerRow = 64 * 8;
111 unsigned col = tp.getDimSize(1) * tp.getElementType().getIntOrFloatBitWidth();
112 if (tp.getDimSize(0) > kMaxRows)
113 return op->
emitOpError(
"bad row height: ") << tp.getDimSize(0);
114 if (col > kBitsPerRow || col & 0x1f)
115 return op->
emitOpError(
"bad column width: ") << (col >> 3);
123 unsigned am = atp.getDimSize(0), ak = atp.getDimSize(1) >> scale;
124 unsigned bk = btp.getDimSize(0), bn = btp.getDimSize(1) >> scale;
125 unsigned cm = ctp.getDimSize(0), cn = ctp.getDimSize(1);
126 if (cm != am || cn != bn || ak != bk)
128 << cm <<
" x " << cn <<
" x " << ak;
138 unsigned width = tType.getElementType().getIntOrFloatBitWidth();
139 assert(llvm::isPowerOf2_64(width) && width >= 8);
140 unsigned bytes = width >> 3;
144 LLVM::ConstantOp::create(rewriter, loc, llvmInt16Type, mattr),
145 LLVM::ConstantOp::create(rewriter, loc, llvmInt16Type, nattr)};
153 unsigned bytes = mType.getElementType().getIntOrFloatBitWidth() / 8;
155 Value scale = LLVM::ConstantOp::create(rewriter, loc, llvmInt64Type, attr);
156 return LLVM::MulOp::create(rewriter, loc, llvmInt64Type, scale, elementStride)
164 assert(mType.getRank() >= 2 &&
"Invalid shape for AMX strides");
165 int64_t preLast = mType.getRank() - 2;
167 unsigned width = mType.getElementType().getIntOrFloatBitWidth();
168 assert(llvm::isPowerOf2_64(width) && width >= 8);
169 unsigned bytes = width >> 3;
170 auto [strides, offset] = mType.getStridesAndOffset();
171 if (strides[preLast] == ShapedType::kDynamic) {
175 loc, mType, memrefDescriptor.
stride(rewriter, loc, preLast), rewriter);
179 return LLVM::ConstantOp::create(rewriter, loc, llvmInt64Type, attr)
183LogicalResult x86::amx::TileZeroOp::verify() {
193template <
typename OpTy,
typename = std::enable_if_t<
194 std::is_same_v<OpTy, x86::amx::TileLoadOp> ||
195 std::is_same_v<OpTy, x86::amx::TileStoreOp>>>
197 MemRefType memrefTy = op.getMemRefType();
198 unsigned rank = memrefTy.getRank();
199 if (op.getIndices().size() != rank)
200 return op.emitOpError(
"requires ") << rank <<
" indices";
206 if (!op.getStride()) {
208 return op.emitOpError(
"requires at least 2D memref");
211 if (failed(memrefTy.getStridesAndOffset(strides, offset)) ||
213 return op.emitOpError(
"requires memref with unit innermost stride");
221 build(builder, state, res, base,
indices,
nullptr);
224LogicalResult x86::amx::TileLoadOp::verify() {
232 Adaptor adaptor(operands, *
this);
235 intrinsicOperands.append(
getTileSizes(loc, getTileType(), rewriter));
236 intrinsicOperands.push_back(
238 adaptor.getBase(), adaptor.getIndices()));
239 if (
Value stride = adaptor.getStride())
240 intrinsicOperands.push_back(
243 intrinsicOperands.push_back(
246 return intrinsicOperands;
251 build(builder, state, base,
indices, val,
nullptr);
254LogicalResult x86::amx::TileStoreOp::verify() {
262 Adaptor adaptor(operands, *
this);
265 intrinsicOperands.append(
getTileSizes(loc, getTileType(), rewriter));
266 intrinsicOperands.push_back(
268 adaptor.getBase(), adaptor.getIndices()));
269 if (
Value stride = adaptor.getStride())
270 intrinsicOperands.push_back(
273 intrinsicOperands.push_back(
275 intrinsicOperands.push_back(adaptor.getVal());
277 return intrinsicOperands;
280LogicalResult x86::amx::TileMulFOp::verify() {
285 if (aType.getElementType().isF8E4M3FN() || aType.getElementType().isF8E5M2())
292 Type ta = aType.getElementType();
293 Type tb = bType.getElementType();
294 Type tc = cType.getElementType();
299 if (flag1 || flag2 || !tc.
isF32())
300 return emitOpError(
"unsupported type combination");
308 Adaptor adaptor(operands, *
this);
316 tsza[1], adaptor.getAcc(),
317 adaptor.getLhs(), adaptor.getRhs()};
319 return intrinsicOperands;
322LogicalResult x86::amx::TileMulIOp::verify() {
331 Type ta = aType.getElementType();
332 Type tb = bType.getElementType();
333 Type tc = cType.getElementType();
335 return emitOpError(
"unsupported type combination");
343 Adaptor adaptor(operands, *
this);
351 tsza[1], adaptor.getAcc(),
352 adaptor.getLhs(), adaptor.getRhs()};
354 return intrinsicOperands;
372 return AMXTileType::getChecked(
377void x86::amx::TileType::print(
AsmPrinter &os)
const {
385#define GET_OP_CLASSES
386#include "mlir/Dialect/X86/X86.cpp.inc"
388#define GET_TYPEDEF_CLASSES
389#include "mlir/Dialect/X86/X86Types.cpp.inc"
false
Parses a map_entries map type from a string format back into its numeric value.
static Type getElementType(Type type, ArrayRef< int32_t > indices, function_ref< InFlightDiagnostic(StringRef)> emitErrorFn)
Walks the given type hierarchy with the given indices, potentially down to component granularity,...
static ArrayRef< int64_t > getShape(Type type)
Returns the shape of the given type.
static Value getMemrefBuffPtr(Location loc, MemRefType type, Value buffer, const LLVMTypeConverter &typeConverter, RewriterBase &rewriter)
static Value inferStride(Location loc, MemRefType mType, Value base, RewriterBase &rewriter)
Maps the 2-dim memref shape to the 64-bit stride.
static Value computeStrideInBytes(Location loc, MemRefType mType, Value elementStride, RewriterBase &rewriter)
Returns stride expressed in number of bytes for the given elementStride stride encoded in number of e...
static LogicalResult tileTransferVerifier(OpTy op)
static LogicalResult verifyMultShape(Operation *op, x86::amx::TileType atp, x86::amx::TileType btp, x86::amx::TileType ctp, unsigned scale)
Verify that AMX supports the multiplication.
static SmallVector< Value > getTileSizes(Location loc, x86::amx::TileType tType, RewriterBase &rewriter)
Maps the 2-dim vector shape to the two 16-bit tile sizes.
static LogicalResult verifyTileSize(Operation *op, x86::amx::TileType tp)
Verify that AMX supports the implied tile shape.
This base class exposes generic asm parser hooks, usable across the various derived parsers.
virtual InFlightDiagnostic emitError(SMLoc loc, const Twine &message={})=0
Emit a diagnostic at the specified location and return failure.
virtual ParseResult parseLess()=0
Parse a '<' token.
virtual ParseResult parseDimensionList(SmallVectorImpl< int64_t > &dimensions, bool allowDynamic=true, bool withTrailingX=true)=0
Parse a dimension list of a tensor or memref type.
virtual SMLoc getNameLoc() const =0
Return the location of the original name token.
virtual ParseResult parseGreater()=0
Parse a '>' token.
virtual ParseResult parseType(Type &result)=0
Parse a type.
This base class exposes generic asm printer hooks, usable across the various derived printers.
virtual void printType(Type type)
void printDimensionList(ArrayRef< int64_t > shape)
IntegerAttr getI16IntegerAttr(int16_t value)
IntegerAttr getI64IntegerAttr(int64_t value)
IntegerType getIntegerType(unsigned width)
TypedAttr getZeroAttr(Type type)
Conversion from types to the LLVM IR dialect.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Helper class to produce LLVM dialect operations extracting or inserting elements of a MemRef descript...
Value bufferPtr(OpBuilder &builder, Location loc, const LLVMTypeConverter &converter, MemRefType type)
Builds IR for getting the start address of the buffer represented by this memref: memref....
Value stride(OpBuilder &builder, Location loc, unsigned pos)
Builds IR extracting the pos-th size from the descriptor.
This class helps build Operations.
Operation is the basic unit of execution within MLIR.
InFlightDiagnostic emitOpError(const Twine &message={})
Emit an error with the op name prefixed, like "'dim' op " which is convenient for verifiers.
This class coordinates the application of a rewrite on a set of IR, providing a way for clients to tr...
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
bool isInteger() const
Return true if this is an integer type (with the specified width).
This class provides an abstraction over the different types of ranges over Values.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Value getStridedElementPtr(OpBuilder &builder, Location loc, const LLVMTypeConverter &converter, MemRefType type, Value memRefDesc, ValueRange indices, LLVM::GEPNoWrapFlags noWrapFlags=LLVM::GEPNoWrapFlags::none)
Performs the index computation to get to the element at indices of the memory pointed to by memRefDes...
MemRefType getMemRefType(T &&t)
Convenience method to abbreviate casting getType().
mlir::x86::AMXTileType TileType
Include the generated interface declarations.
Type getType(OpFoldResult ofr)
Returns the int type of the integer in ofr.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
This represents an operation in an abstracted form, suitable for use with the builder APIs.