18#include "llvm/Support/FormatVariadic.h"
29 return spirv::Version::V_1_0;
33 return spirv::Version::V_1_6;
37 if (isa<BFloat16Type>(
getType())) {
38 static const auto extension = spirv::Extension::SPV_KHR_bfloat16;
45SmallVector<ArrayRef<spirv::Capability>, 1> DotOp::getCapabilities() {
46 if (isa<BFloat16Type>(
getType())) {
47 static const auto capability = spirv::Capability::BFloat16DotProductKHR;
54std::optional<spirv::Version> DotOp::getMinVersion() {
58std::optional<spirv::Version> DotOp::getMaxVersion() {
66template <
typename IntegerDotProductOpTy>
69 "Not an integer dot product op?");
70 assert(op->
getNumResults() == 1 &&
"Expected a single result");
75 auto dotOp = cast<IntegerDotProductOpTy>(op);
76 if (
auto intTy = dyn_cast<IntegerType>(factorTy)) {
77 spirv::PackedVectorFormatAttr packedVectorFormat = dotOp.getFormatAttr();
78 if (!packedVectorFormat)
79 return op->
emitOpError(
"requires Packed Vector Format attribute for "
80 "integer vector operands");
82 assert(packedVectorFormat.getValue() ==
83 spirv::PackedVectorFormat::PackedVectorFormat4x8Bit &&
84 "Unknown Packed Vector Format");
85 if (intTy.getWidth() != 32)
87 llvm::formatv(
"with specified Packed Vector Format ({0}) requires "
88 "integer vector operands to be 32-bits wide",
89 packedVectorFormat.getValue()));
91 if (dotOp.getFormatAttr())
93 "with invalid format attribute for vector operands of type '{0}'",
100 if (factorBitWidth > resultBitWidth)
102 llvm::formatv(
"result type has insufficient bit-width ({0} bits) "
103 "for the specified vector operand type ({1} bits)",
104 resultBitWidth, factorBitWidth));
113 static const auto extension = spirv::Extension::SPV_KHR_integer_dot_product;
117template <
typename IntegerDotProductOpTy>
122 static const auto dotProductCap = spirv::Capability::DotProduct;
123 static const auto dotProductInput4x8BitPackedCap =
124 spirv::Capability::DotProductInput4x8BitPacked;
125 static const auto dotProductInput4x8BitCap =
126 spirv::Capability::DotProductInput4x8Bit;
127 static const auto dotProductInputAllCap =
128 spirv::Capability::DotProductInputAll;
133 auto dotOp = cast<IntegerDotProductOpTy>(op);
134 if (
auto intTy = dyn_cast<IntegerType>(factorTy)) {
135 spirv::PackedVectorFormatAttr formatAttr = dotOp.getFormatAttr();
136 if (formatAttr.getValue() ==
137 spirv::PackedVectorFormat::PackedVectorFormat4x8Bit)
138 capabilities.push_back(dotProductInput4x8BitPackedCap);
143 auto vecTy = cast<VectorType>(factorTy);
144 if (vecTy.getElementTypeBitWidth() == 8) {
145 capabilities.push_back(dotProductInput4x8BitCap);
149 capabilities.push_back(dotProductInputAllCap);
153#define SPIRV_IMPL_INTEGER_DOT_PRODUCT_OP(OpName) \
154 LogicalResult OpName::verify() { \
155 return verifyIntegerDotProduct<OpName>(*this); \
157 SmallVector<ArrayRef<spirv::Extension>, 1> OpName::getExtensions() { \
158 return getIntegerDotProductExtensions(); \
160 SmallVector<ArrayRef<spirv::Capability>, 1> OpName::getCapabilities() { \
161 return getIntegerDotProductCapabilities<OpName>(*this); \
163 std::optional<spirv::Version> OpName::getMinVersion() { \
164 return getDotProductMinVersion(); \
166 std::optional<spirv::Version> OpName::getMaxVersion() { \
167 return getDotProductMaxVersion(); \
177#undef SPIRV_IMPL_INTEGER_DOT_PRODUCT_OP
#define SPIRV_IMPL_INTEGER_DOT_PRODUCT_OP(OpName)
Operation is the basic unit of execution within MLIR.
Value getOperand(unsigned idx)
unsigned getNumOperands()
result_type_range getResultTypes()
InFlightDiagnostic emitOpError(const Twine &message={})
Emit an error with the op name prefixed, like "'dim' op " which is convenient for verifiers.
unsigned getNumResults()
Return the number of results held by this operation.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Type front()
Return first type in the range.
Type getType() const
Return the type of this value.
static LogicalResult verifyIntegerDotProduct(Operation *op)
static SmallVector< ArrayRef< spirv::Capability >, 1 > getIntegerDotProductCapabilities(Operation *op)
static std::optional< spirv::Version > getDotProductMaxVersion()
static SmallVector< ArrayRef< spirv::Extension >, 1 > getIntegerDotProductExtensions()
static std::optional< spirv::Version > getDotProductMinVersion()
unsigned getBitWidth(Type type)
Returns the bit width of the type.
Type getType(OpFoldResult ofr)
Returns the int type of the integer in ofr.