14#ifndef MLIR_DIALECT_XEGPU_UARCH_UARCHBASE_H
15#define MLIR_DIALECT_XEGPU_UARCH_UARCHBASE_H
25#include "llvm/ADT/DenseMap.h"
26#include "llvm/ADT/STLExtras.h"
27#include "llvm/ADT/SmallVector.h"
28#include "llvm/ADT/StringRef.h"
29#include "llvm/Support/Casting.h"
30#include "llvm/Support/DebugLog.h"
31#include "llvm/Support/ErrorHandling.h"
82 llvm_unreachable(
"Unknown InstructionKind");
134 this->instructionRegistry[instr->getInstructionKind()] = instr;
149 "Instruction not found in registry");
159 llvm::SmallDenseMap<InstructionKind, const Instruction *, 32>
215 std::optional<BlockShapes>
217 bool hasTranspose =
false,
218 bool upConv =
false)
const {
229 virtual std::optional<BlockShapes>
231 bool hasTranspose,
bool upConv)
const = 0;
241template <InstructionKind Kind>
245 "ScatterIO only supports LoadGather / StoreScatter");
250 return B->getInstructionKind() == Kind;
286 std::optional<BlockShapes>
289 bool )
const override {
290 static const int kHeight[] = {1, 2, 4, 8};
291 static const int kWidth16[] = {16};
292 static const int kCount[] = {1};
294 if (elemByteSize == 1 || elemByteSize == 2 || elemByteSize == 4)
314 std::optional<BlockShapes>
316 bool hasTranspose,
bool upConv)
const override {
317 static const int kHeightAtLeast1[] = {1, 2, 4, 8, 16, 32};
318 static const int kHeightAtLeast8[] = {8, 16, 32};
319 static const int kHeightAtLeast16[] = {16, 32};
320 static const int kHeight32[] = {32};
321 static const int kHeight64[] = {64};
323 static const int kWidth64[] = {64};
324 static const int kWidth32[] = {32};
325 static const int kWidth16[] = {16};
326 static const int kWidth8[] = {8};
328 static const int32_t kCount1[] = {1};
329 static const int32_t kCount2[] = {1, 2};
330 static const int32_t kCount4[] = {1, 2, 4};
331 static const int32_t kCount4Only[] = {4};
333 using Key = std::tuple<int, uint8_t, uint8_t, uint8_t>;
341 {{8,
false,
false,
false}, {kWidth32, kHeightAtLeast1, kCount2}},
342 {{8,
false,
false,
true}, {kWidth16, kHeightAtLeast8, kCount4Only}},
343 {{16,
false,
false,
false}, {kWidth16, kHeightAtLeast1, kCount2}},
344 {{32,
false,
false,
false}, {kWidth16, kHeightAtLeast1, kCount1}},
346 {{8,
true,
false,
false}, {kWidth16, kHeight32, kCount4}},
347 {{16,
true,
false,
false}, {kWidth16, kHeightAtLeast16, kCount2}},
349 {{8,
false,
true,
false}, {kWidth32, kHeightAtLeast16, kCount1}},
350 {{16,
false,
true,
false}, {kWidth16, kHeightAtLeast16, kCount1}},
351 {{32,
false,
true,
false}, {kWidth8, kHeightAtLeast16, kCount1}},
353 {{4,
false,
false,
false}, {kWidth64, kHeightAtLeast1, kCount2}},
354 {{4,
false,
false,
true}, {kWidth32, kHeightAtLeast8, kCount4Only}},
355 {{4,
true,
false,
false}, {kWidth16, kHeight64, kCount4}},
356 {{4,
false,
true,
false}, {kWidth64, kHeightAtLeast16, kCount1}}};
358 auto it = kMap.find({elemBitSize, hasTransform, hasTranspose, upConv});
359 if (it != kMap.end())
377 std::optional<BlockShapes>
380 bool )
const override {
381 static const int kHeightAtLeast1[] = {1, 2, 4, 8, 16, 32};
383 static const int kWidth32[] = {32};
384 static const int kWidth16[] = {16};
386 static const int32_t kCount1[] = {1};
387 static const int32_t kCount2[] = {1, 2};
394 {1, {kWidth32, kHeightAtLeast1, kCount2}},
395 {2, {kWidth16, kHeightAtLeast1, kCount2}},
396 {4, {kWidth16, kHeightAtLeast1, kCount1}},
399 auto it = kMap.find(elemByteSize);
400 if (it != kMap.end())
415 return B->getInstructionKind() ==
448 return B->getInstructionKind() ==
483 result.emplace_back(x, y);
494 switch (matrixType) {
509 Type bf16Type = BFloat16Type::get(&context);
510 Type f16Type = Float16Type::get(&context);
511 Type tf32Type = FloatTF32Type::get(&context);
512 Type f32Type = Float32Type::get(&context);
514 switch (matrixType) {
517 return {bf16Type, f16Type, tf32Type};
520 return {bf16Type, f16Type, f32Type};
527 return {1, 2, 3, 4, 5, 6, 7, 8};
532 assert(type.
isIntOrFloat() &&
"Matrix type must be int or float");
549 llvm_unreachable(
"Invalid int or float");
564 switch (matrixType) {
579 Type f8E4M3FNType = Float8E4M3FNType::get(&context);
580 Type f8E5M2Type = Float8E5M2Type::get(&context);
581 Type f4E2M1FNType = Float4E2M1FNType::get(&context);
582 Type bf16Type = BFloat16Type::get(&context);
583 Type f32Type = Float32Type::get(&context);
585 switch (matrixType) {
588 return {f8E4M3FNType, f8E5M2Type, f4E2M1FNType};
591 return {bf16Type, f32Type};
603 assert(type.
isIntOrFloat() &&
"Matrix type must be int or float");
MLIRContext is the top-level object for a collection of MLIR operations.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
bool isIntOrFloat() const
Return true if this is an integer (of any signedness) or a float type.
unsigned getIntOrFloatBitWidth() const
Return the bit width of an integer or a float type, assert failure on other types.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
llvm::SmallVector< std::pair< uint32_t, uint32_t >, 16 > crossProduct(const llvm::SmallVector< uint32_t, 8 > &a, const llvm::SmallVector< uint32_t, 8 > &b)
@ Subgroup2DBlockPrefetch
@ SubgroupMatrixMultiplyAcc
@ SubgroupScaledMatrixMultiplyAcc
Include the generated interface declarations.
std::tuple< llvm::ArrayRef< int >, llvm::ArrayRef< int >, llvm::ArrayRef< int > > BlockShapes
virtual ~BlockIOInstructionInterface()=default
virtual int32_t getPackedFormatBitSize() const =0
virtual std::optional< BlockShapes > computeBlockWidthHeightCount(Type elemTy, bool hasTransform, bool hasTranspose, bool upConv) const =0
BlockIOInstructionInterface(InstructionKind kind)
std::optional< BlockShapes > getBlockWidthHeightCount(Type elemTy, bool hasTransform=false, bool hasTranspose=false, bool upConv=false) const
static bool classof(const Instruction *B)
int32_t minBaseWidthBytes
int32_t baseAddressAlignmentBytes
int32_t basePitchAlignmentBytes
int32_t baseWidthAlignmentBytes
int32_t minBasePitchBytes
Instruction(InstructionKind kind, InstructionScope scope)
const InstructionScope scope
InstructionScope getScope() const
static llvm::StringRef toString(InstructionKind instKind)
InstructionKind getInstructionKind() const
const InstructionKind instKind
int32_t getMaxLaneAccessSizeBytes() const override
virtual llvm::SmallVector< std::pair< uint32_t, uint32_t >, 16 > getSupportedShapes(Type dataType, MMAOpndKind matrixType)=0
virtual llvm::SmallVector< uint32_t, 8 > getSupportedN(Type type) const =0
virtual bool isLaneLayoutRowMajorOrder() const =0
virtual ~MMAInstructionInterface()=default
virtual llvm::SmallVector< uint32_t, 8 > getSupportedK(Type type) const =0
virtual llvm::SmallVector< uint32_t, 8 > getSupportedM(Type type) const =0
virtual llvm::SmallVector< Type, 8 > getSupportedTypes(MLIRContext &context, MMAOpndKind matrixType)=0
ScatterIoInstructionInterface()
virtual ~ScatterIoInstructionInterface()=default
virtual int32_t getMaxLaneAccessSizeBytes() const =0
static bool classof(const Instruction *B)
int32_t getMaxLaneAccessSizeBytes() const override
int32_t getPackedFormatBitSize() const override
Subgroup2DBlockLoadInstruction()
std::optional< BlockShapes > computeBlockWidthHeightCount(Type elemTy, bool hasTransform, bool hasTranspose, bool upConv) const override
static bool classof(const Instruction *B)
static bool classof(const Instruction *B)
std::optional< BlockShapes > computeBlockWidthHeightCount(Type elemTy, bool, bool, bool) const override
int32_t getPackedFormatBitSize() const override
Subgroup2DBlockPrefetchInstruction()
static bool classof(const Instruction *B)
Subgroup2DBlockStoreInstruction()
std::optional< BlockShapes > computeBlockWidthHeightCount(Type elemTy, bool, bool, bool) const override
int32_t getPackedFormatBitSize() const override
llvm::SmallVector< uint32_t, 8 > getSupportedK(Type type) const override
bool isLaneLayoutRowMajorOrder() const override
llvm::SmallVector< std::pair< uint32_t, uint32_t >, 16 > getSupportedShapes(Type dataType, MMAOpndKind matrixType) override
llvm::SmallVector< Type, 8 > getSupportedTypes(MLIRContext &context, MMAOpndKind matrixType) override
llvm::SmallVector< uint32_t, 8 > getSupportedN(Type type) const override
const unsigned packedFormatBitSizeA
SubgroupMatrixMultiplyAcc(unsigned packedFormatBitSizeA, unsigned packedFormatBitSizeB)
static bool classof(const Instruction *B)
unsigned getPackedFormatBitSizeB() const
unsigned getPackedFormatBitSizeA() const
llvm::SmallVector< uint32_t, 8 > getSupportedM(Type type) const override
const unsigned packedFormatBitSizeB
unsigned getPackedFormatBitSizeB() const
unsigned getPackedFormatBitSizeA() const
bool isLaneLayoutRowMajorOrder() const override
llvm::SmallVector< uint32_t, 8 > getSupportedN(Type type) const override
llvm::SmallVector< uint32_t, 8 > getSupportedM(Type type) const override
SubgroupScaledMatrixMultiplyAcc(unsigned packedFormatBitSizeA, unsigned packedFormatBitSizeB)
static bool classof(const Instruction *B)
llvm::SmallVector< std::pair< uint32_t, uint32_t >, 16 > getSupportedShapes(Type dataType, MMAOpndKind matrixType) override
llvm::SmallVector< Type, 8 > getSupportedTypes(MLIRContext &context, MMAOpndKind matrixType) override
llvm::SmallVector< uint32_t, 8 > getSupportedK(Type type) const override
const unsigned packedFormatBitSizeB
const unsigned packedFormatBitSizeA
llvm::SmallDenseMap< InstructionKind, const Instruction *, 32 > instructionRegistry
virtual unsigned getGeneralPackedFormatBitSize() const =0
bool isSupportedInstruction(InstructionKind instr) const
virtual int getSubgroupSize() const =0
virtual const BlockIOMemoryRestrictions & getBlockIOMemoryRestrictions() const =0
const Instruction * getInstruction(InstructionKind instKind) const
uArch(Kind kind, llvm::ArrayRef< const Instruction * > instructionRegistry)