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 kHeight16[] = {16};
321 static const int kHeight32[] = {32};
322 static const int kHeight64[] = {64};
324 static const int kWidth64[] = {64};
325 static const int kWidth32[] = {32};
326 static const int kWidth16[] = {16};
327 static const int kWidth8[] = {8};
329 static const int32_t kCount1[] = {1};
330 static const int32_t kCount2[] = {1, 2};
331 static const int32_t kCount4[] = {1, 2, 4};
332 static const int32_t kCount4Only[] = {4};
334 using Key = std::tuple<int, uint8_t, uint8_t, uint8_t>;
342 {{8,
false,
false,
false}, {kWidth32, kHeightAtLeast1, kCount2}},
343 {{8,
false,
false,
true}, {kWidth16, kHeightAtLeast8, kCount4Only}},
344 {{16,
false,
false,
false}, {kWidth16, kHeightAtLeast1, kCount2}},
345 {{32,
false,
false,
false}, {kWidth16, kHeightAtLeast1, kCount1}},
347 {{8,
true,
false,
false}, {kWidth16, kHeight32, kCount4}},
348 {{16,
true,
false,
false}, {kWidth16, kHeightAtLeast16, kCount2}},
351 {{8,
false,
true,
false}, {kWidth32, kHeight16, kCount1}},
352 {{16,
false,
true,
false}, {kWidth16, kHeight16, kCount1}},
353 {{32,
false,
true,
false}, {kWidth8, kHeight16, kCount1}},
355 {{4,
false,
false,
false}, {kWidth64, kHeightAtLeast1, kCount2}},
356 {{4,
false,
false,
true}, {kWidth32, kHeightAtLeast8, kCount4Only}},
357 {{4,
true,
false,
false}, {kWidth16, kHeight64, kCount4}},
358 {{4,
false,
true,
false}, {kWidth64, kHeightAtLeast16, kCount1}}};
360 auto it = kMap.find({elemBitSize, hasTransform, hasTranspose, upConv});
361 if (it != kMap.end())
379 std::optional<BlockShapes>
382 bool )
const override {
383 static const int kHeightAtLeast1[] = {1, 2, 4, 8, 16, 32};
385 static const int kWidth32[] = {32};
386 static const int kWidth16[] = {16};
388 static const int32_t kCount1[] = {1};
389 static const int32_t kCount2[] = {1, 2};
396 {1, {kWidth32, kHeightAtLeast1, kCount2}},
397 {2, {kWidth16, kHeightAtLeast1, kCount2}},
398 {4, {kWidth16, kHeightAtLeast1, kCount1}},
401 auto it = kMap.find(elemByteSize);
402 if (it != kMap.end())
417 return B->getInstructionKind() ==
450 return B->getInstructionKind() ==
485 result.emplace_back(x, y);
496 switch (matrixType) {
511 Type bf16Type = BFloat16Type::get(&context);
512 Type f16Type = Float16Type::get(&context);
513 Type tf32Type = FloatTF32Type::get(&context);
514 Type f32Type = Float32Type::get(&context);
516 switch (matrixType) {
519 return {bf16Type, f16Type, tf32Type};
522 return {bf16Type, f16Type, f32Type};
529 return {1, 2, 3, 4, 5, 6, 7, 8};
534 assert(type.
isIntOrFloat() &&
"Matrix type must be int or float");
551 llvm_unreachable(
"Invalid int or float");
566 switch (matrixType) {
581 Type f8E4M3FNType = Float8E4M3FNType::get(&context);
582 Type f8E5M2Type = Float8E5M2Type::get(&context);
583 Type f4E2M1FNType = Float4E2M1FNType::get(&context);
584 Type bf16Type = BFloat16Type::get(&context);
585 Type f32Type = Float32Type::get(&context);
587 switch (matrixType) {
590 return {f8E4M3FNType, f8E5M2Type, f4E2M1FNType};
593 return {bf16Type, f32Type};
605 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)