33#include "llvm/ADT/ArrayRef.h"
41#define DEBUG_TYPE "nvgpu-transforms"
47void ApplyNVGPUToNVVMConversionPatternsOp::populatePatterns(
54 llvmTypeConverter.addConversion([&](DeviceAsyncTokenType type) ->
Type {
55 return llvmTypeConverter.convertType(
56 IntegerType::get(type.getContext(), 32));
58 llvmTypeConverter.addConversion([&](MBarrierTokenType type) ->
Type {
59 return llvmTypeConverter.convertType(
60 IntegerType::get(type.getContext(), 64));
62 llvmTypeConverter.addConversion([&](WarpgroupAccumulatorType type) ->
Type {
63 Type elemType = type.getFragmented().getElementType();
64 int64_t sizeM = type.getFragmented().getDimSize(0);
65 int64_t sizeN = type.getFragmented().getDimSize(1);
69 numMembers = sizeN / 2;
70 else if (elemType.
isF16())
71 numMembers = sizeN / 4;
73 llvm_unreachable(
"unsupported type for warpgroup accumulator");
76 for (
unsigned i = 0; i < numMembers; i++)
77 innerStructBody.push_back(elemType);
78 auto innerStructType =
79 LLVM::LLVMStructType::getLiteral(type.getContext(), innerStructBody);
83 structBody.push_back(innerStructType);
86 LLVM::LLVMStructType::getLiteral(type.getContext(), structBody);
87 return llvmTypeConverter.convertType(convertedType);
89 llvmTypeConverter.addConversion([&](MBarrierGroupType type) ->
Type {
90 return llvmTypeConverter.convertType(
93 llvmTypeConverter.addConversion(
94 [&](WarpgroupMatrixDescriptorType type) ->
Type {
95 return llvmTypeConverter.convertType(
96 IntegerType::get(type.getContext(), 64));
98 llvmTypeConverter.addConversion([&](TensorMapDescriptorType type) ->
Type {
99 return LLVM::LLVMPointerType::get(type.getContext());
104LogicalResult ApplyNVGPUToNVVMConversionPatternsOp::verifyTypeConverter(
105 TypeConverterBuilderOpInterface builder) {
106 if (builder.getTypeConverterType() !=
"LLVMTypeConverter")
107 return emitOpError(
"expected LLVMTypeConverter");
115void CreateAsyncGroupsOp::getEffects(
143 dyn_cast_if_present<gpu::AddressSpaceAttr>(type.
getMemorySpace());
145 space.getValue() == gpu::GPUDialect::getWorkgroupAddressSpace();
152 auto load = dyn_cast<vector::TransferReadOp>(op);
156 auto loadType = dyn_cast<MemRefType>(
load.getBase().getType());
165 auto store = dyn_cast<vector::TransferWriteOp>(op);
166 if (!store || store.getVector() != v)
169 auto storeType = dyn_cast<MemRefType>(store.getBase().getType());
199 if (op.getNumRegions() > 0)
202 if (isa<gpu::BarrierOp>(op)) {
203 barriers.insert(&op);
207 if (isa<DeviceAsyncCopyOp, DeviceAsyncCreateGroupOp>(op)) {
209 ops.insert(std::make_move_iterator(barriers.begin()),
210 std::make_move_iterator(barriers.end()));
211 assert(barriers.empty() &&
212 "expected to have moved the barriers into another set");
232 unsigned iteration,
unsigned depth) {
235 auto waitOp = dyn_cast<DeviceAsyncWaitOp>(op);
236 if (!waitOp || waitOp.getNumGroups())
239 int numGroupInFlight = 0;
242 numGroupInFlight = depth - 1;
249 numGroupInFlight = depth - 1 - iteration;
251 waitOp.setNumGroups(numGroupInFlight);
266 std::vector<std::pair<Operation *, unsigned>> &opsWithPipelineStages,
270 return visited->
getBlock() == forOp.getBody();
273 for (
Operation &op : forOp.getBody()->getOperations()) {
274 if (stage0Ops.contains(&op)) {
276 assert(
result.succeeded() &&
"expected a backward slice");
281 for (
Operation &op : forOp.getBody()->getOperations()) {
282 if (!dependencies.contains(&op) && !isa<scf::YieldOp>(op))
283 opsWithPipelineStages.emplace_back(&op, depth);
285 for (
Operation &op : forOp.getBody()->getOperations()) {
286 if (dependencies.contains(&op))
287 opsWithPipelineStages.emplace_back(&op, 0);
301 isa<gpu::BarrierOp, DeviceAsyncCreateGroupOp, DeviceAsyncWaitOp>(op)) {
306 auto asyncCopyOp = dyn_cast<DeviceAsyncCopyOp>(op);
315 Location loc = asyncCopyOp->getLoc();
316 Value dstElements = arith::ConstantOp::create(
317 rewriter, loc, asyncCopyOp.getDstElementsAttr());
318 Value originalSrcElement =
319 asyncCopyOp.getSrcElements() ? asyncCopyOp.getSrcElements() : dstElements;
321 auto srcElements = arith::SelectOp::create(rewriter, loc, predicate,
322 originalSrcElement, c0Index);
323 auto asyncCopyZeroFillOp = DeviceAsyncCopyOp::create(
324 rewriter, loc, DeviceAsyncTokenType::get(asyncCopyOp.getContext()),
325 asyncCopyOp.getDst(), asyncCopyOp.getDstIndices(), asyncCopyOp.getSrc(),
326 asyncCopyOp.getSrcIndices(), asyncCopyOp.getDstElements(), srcElements,
328 rewriter.
replaceOp(asyncCopyOp, asyncCopyZeroFillOp);
329 return asyncCopyZeroFillOp;
337static std::tuple<DiagnosedSilenceableFailure, scf::ForOp>
339 bool epiloguePeeling) {
342 return std::make_tuple(
346 if (stage0Ops.empty()) {
347 return std::make_tuple(
352 unsigned maxDepth = depth;
355 unsigned iteration) {
359 [&](scf::ForOp schedulingFor,
360 std::vector<std::pair<Operation *, unsigned>> &ops) {
361 if (schedulingFor != forOp)
365 options.annotateFn = setAnnotation;
366 if (!epiloguePeeling) {
374 FailureOr<scf::ForOp> maybePipelined =
375 pipelineForLoop(rewriter, forOp,
options, &modifiedIR);
376 if (succeeded(maybePipelined)) {
380 return std::make_tuple(
391 rewriter, forOp,
static_cast<int64_t>(getDepth()), getPeelEpilogue());
392 if (
diag.succeeded()) {
396 if (
diag.isDefiniteFailure()) {
398 if (!getPeelEpilogue()) {
399 diag.attachNote(forOp->getLoc()) <<
"couldn't predicate?";
400 diag.attachNote(getLoc()) <<
"try setting " << getPeelEpilogueAttrName();
405 return std::move(
diag);
421 void print(llvm::raw_ostream &os)
const {
422 os <<
"- indexing: " << first <<
", " << second;
431 : b(b), loc(loc), laneId(laneId) {}
434 std::function<SmallVector<RowColIndexing>(
MLIRContext *)>;
442 std::tuple<IndexCalculator, IndexCalculator, IndexCalculator> indexFns;
477 RowColIndexing{groupID + 8, threadIDInGroup}};
485 static SmallVector<RowColIndexing> m16n8k4tf32Rhs(MLIRContext *ctx) {
487 AffineExpr groupID = dim.
floorDiv(4);
488 AffineExpr threadIDInGroup = dim % 4;
489 return {RowColIndexing{threadIDInGroup, groupID}};
498 static SmallVector<RowColIndexing> m16n8k4tf32Res(MLIRContext *ctx) {
500 AffineExpr groupID = dim.
floorDiv(4);
501 AffineExpr threadIDInGroup = dim % 4;
502 return {RowColIndexing{groupID, threadIDInGroup * 2 + 0},
503 RowColIndexing{groupID, threadIDInGroup * 2 + 1},
504 RowColIndexing{groupID + 8, threadIDInGroup * 2 + 0},
505 RowColIndexing{groupID + 8, threadIDInGroup * 2 + 1}};
520 static SmallVector<RowColIndexing> m16n8k16f16Lhs(MLIRContext *ctx) {
522 AffineExpr groupID = dim.
floorDiv(4);
523 AffineExpr threadIDInGroup = dim % 4;
526 RowColIndexing{groupID, threadIDInGroup * 2 + 0},
527 RowColIndexing{groupID, threadIDInGroup * 2 + 1},
528 RowColIndexing{groupID + 8, threadIDInGroup * 2 + 0},
529 RowColIndexing{groupID + 8, threadIDInGroup * 2 + 1},
530 RowColIndexing{groupID, threadIDInGroup * 2 + 0 + 8},
531 RowColIndexing{groupID, threadIDInGroup * 2 + 1 + 8},
532 RowColIndexing{groupID + 8, threadIDInGroup * 2 + 0 + 8},
533 RowColIndexing{groupID + 8, threadIDInGroup * 2 + 1 + 8}
546 static SmallVector<RowColIndexing> m16n8k16f16Rhs(MLIRContext *ctx) {
548 AffineExpr groupID = dim.
floorDiv(4);
549 AffineExpr threadIDInGroup = dim % 4;
552 RowColIndexing{threadIDInGroup * 2 + 0, groupID},
553 RowColIndexing{threadIDInGroup * 2 + 1, groupID},
554 RowColIndexing{threadIDInGroup * 2 + 0 + 8, groupID},
555 RowColIndexing{threadIDInGroup * 2 + 1 + 8, groupID}
568 static SmallVector<RowColIndexing> m16n8k16f16Res(MLIRContext *ctx) {
570 AffineExpr groupID = dim.
floorDiv(4);
571 AffineExpr threadIDInGroup = dim % 4;
574 RowColIndexing{groupID, threadIDInGroup * 2 + 0},
575 RowColIndexing{groupID, threadIDInGroup * 2 + 1},
576 RowColIndexing{groupID + 8, threadIDInGroup * 2 + 0},
577 RowColIndexing{groupID + 8, threadIDInGroup * 2 + 1}
590 SmallVector<Value> buildMemRefLoads(OpBuilder &b, Location loc,
591 OpFoldResult laneId, Value memref,
600 Value buildMmaSyncMemRefLoadOperand(OpBuilder &b, Location loc,
601 OpFoldResult laneId, Value memref,
608 SmallVector<Operation *> buildMemRefStores(OpBuilder &b, Location loc,
610 OpFoldResult laneId, Value memref,
619 SmallVector<Operation *> buildMmaSyncMemRefStoreOperand(
620 OpBuilder &b, Location loc, Value vectorToStore, OpFoldResult laneId,
634template <
typename ApplyFn,
typename ReduceFn>
637 VectorType vectorType = cast<VectorType>(
vector.getType());
649 const IndexCalculator &indexFn) {
650 auto aff = [&](AffineExpr e) {
653 SmallVector<Value> res;
654 SmallVector<RowColIndexing> indexings = indexFn(b.getContext());
655 for (
auto indexing : indexings) {
658 auto load = memref::LoadOp::create(b, loc, memref,
ValueRange{row, col});
664Value MmaSyncBuilder::buildMmaSyncMemRefLoadOperand(
667 auto loads = buildMemRefLoads(b, loc, laneId, memref, indexFn);
670 auto vt = VectorType::get(
vectorShape, elementType);
671 Value res = vector::BroadcastOp::create(b, loc, vt, loads[0]);
675 [&](Value v, int64_t linearIdx, ArrayRef<int64_t>
indices) {
676 return loads[linearIdx];
679 [&](Value v, int64_t linearIdx, ArrayRef<int64_t>
indices) {
680 res = vector::InsertOp::create(b, loc, v, res,
indices);
689 auto aff = [&](AffineExpr e) {
692 SmallVector<Operation *> res;
693 for (
auto [indexing, val] :
694 llvm::zip_equal(indexFn(b.getContext()), toStore)) {
698 memref::StoreOp::create(b, loc, val, memref,
ValueRange{row, col});
699 res.push_back(store);
707 SmallVector<Value> toStore;
712 [&](Value v, int64_t linearIdx, ArrayRef<int64_t>
indices) {
713 return vector::ExtractOp::create(b, loc, vectorToStore,
indices);
716 [&](Value v, int64_t linearIdx, ArrayRef<int64_t>
indices) {
717 toStore.push_back(v);
719 return buildMemRefStores(b, loc, toStore, laneId, memref, indexFn);
729 return std::make_tuple(vlhs, vrhs, vres);
732FailureOr<MmaSyncBuilder::MmaSyncInfo>
736 Type f16 = b.getF16Type();
737 Type f32 = b.getF32Type();
738 if (opShape == ArrayRef<int64_t>{16, 8, 4} &&
739 elementalTypes ==
TypeRange{f32, f32, f32}) {
740 return MmaSyncInfo{std::make_tuple(&MmaSyncBuilder::m16n8k4tf32Lhs,
741 &MmaSyncBuilder::m16n8k4tf32Rhs,
742 &MmaSyncBuilder::m16n8k4tf32Res),
744 SmallVector<int64_t>{opShape},
749 if (opShape == ArrayRef<int64_t>{16, 8, 16} &&
750 elementalTypes ==
TypeRange{f16, f16, f16}) {
751 return MmaSyncInfo{std::make_tuple(&MmaSyncBuilder::m16n8k16f16Lhs,
752 &MmaSyncBuilder::m16n8k16f16Rhs,
753 &MmaSyncBuilder::m16n8k16f16Res),
755 SmallVector<int64_t>{opShape},
762 Value lhsMemRef = linalgOp.getDpsInputOperand(0)->get();
763 Value rhsMemRef = linalgOp.getDpsInputOperand(1)->get();
764 Value resMemRef = linalgOp.getDpsInitOperand(0)->get();
765 assert(cast<MemRefType>(lhsMemRef.
getType()).getRank() == 2 &&
766 "expected lhs to be a 2D memref");
767 assert(cast<MemRefType>(rhsMemRef.
getType()).getRank() == 2 &&
768 "expected rhs to be a 2D memref");
769 assert(cast<MemRefType>(resMemRef.
getType()).getRank() == 2 &&
770 "expected res to be a 2D memref");
779 FailureOr<MmaSyncInfo> maybeInfo =
780 getIndexCalculators({m, n, k}, {lhsType, rhsType, resType});
781 if (failed(maybeInfo))
784 const MmaSyncInfo &info = *maybeInfo;
785 auto [lhsIndexFn, rhsIndexFn, resIndexFn] = info.indexFns;
786 auto [lhsShape, rhsShape, resShape] = info.vectorShapes;
787 Value lhs = buildMmaSyncMemRefLoadOperand(b, loc, laneId, lhsMemRef,
788 lhsIndexFn, lhsShape);
789 Value rhs = buildMmaSyncMemRefLoadOperand(b, loc, laneId, rhsMemRef,
790 rhsIndexFn, rhsShape);
791 Value res = buildMmaSyncMemRefLoadOperand(b, loc, laneId, resMemRef,
792 resIndexFn, resShape);
794 MmaSyncOp::create(b, loc, lhs, rhs, res, info.mmaShape, info.tf32Enabled);
795 buildMmaSyncMemRefStoreOperand(b, loc, res, laneId, resMemRef, resIndexFn,
797 return res.getDefiningOp();
805 if (isa_and_nonnull<linalg::MatmulOp>(linalgOp.getOperation())) {
808 if (linalgOp.hasUserDefinedMaps()) {
809 return emitSilenceableError()
810 <<
"only matmul ops with non-extended semantics are supported";
814 Value laneId = gpu::ThreadIdOp::create(
815 rewriter, loc, rewriter.
getIndexType(), gpu::Dimension::x);
816 if (succeeded(
MmaSyncBuilder(rewriter, loc, laneId).buildMmaSync(linalgOp)))
822 <<
"unsupported target op: " << linalgOp;
823 diag.attachNote(linalgOp->getLoc()) <<
"target op";
848 gpu::LaunchOp launchOp);
889 sizes.reserve(globalDescriptors.size());
890 for (
auto [desc, shmem] : llvm::zip_equal(
891 globalDescriptors, sharedMemBuffers)) {
912 return gpu::AddressSpaceAttr::get(
913 b.getContext(), gpu::GPUDialect::getWorkgroupAddressSpace());
920 Value barrier = MBarrierCreateOp::create(
922 MBarrierGroupType::get(
rewriter.getContext(), sharedMemorySpace));
924 nvgpu::MBarrierInitOp::create(
929 return cast<TypedValue<MBarrierGroupType>>(barrier);
934 gpu::LaunchOp launchOp) {
936 rewriter.setInsertionPoint(launchOp);
937 Value unrankedMemRef = memref::CastOp::create(
939 UnrankedMemRefType::get(
memref.getType().getElementType(),
940 memref.getType().getMemorySpace()),
948 Value desc = TmaCreateDescriptorOp::create(
950 TensorMapDescriptorType::get(
rewriter.getContext(),
953 TensorMapSwizzleKind::SWIZZLE_NONE,
954 TensorMapL2PromoKind::L2PROMO_NONE,
955 TensorMapOOBKind::OOB_ZERO,
956 TensorMapInterleaveKind::INTERLEAVE_NONE),
957 unrankedMemRef, sizes);
958 return cast<TypedValue<TensorMapDescriptorType>>(desc);
969 TmaAsyncLoadOp::create(
rewriter,
loc, sharedMemref, barrier, globalDesc,
971 loadOps.push_back(loadOp);
977 (sharedMemref.getType().getElementTypeBitWidth() / 8);
979 prodExprInBytes, mixedSizes);
985 assert(!mixedSizes.empty() &&
"expecte non-empty sizes");
994 nvgpu::MBarrierArriveExpectTxOp::create(
rewriter,
loc, barrier, sizeVal, zero,
1004 Value ticksBeforeRetry =
1007 nvgpu::MBarrierTryWaitParityOp::create(
rewriter,
loc, barrier, parity,
1008 ticksBeforeRetry, zero);
1025 if (copyOps.empty())
1028 auto launchOp = copyOps.front()->getParentOfType<gpu::LaunchOp>();
1029 assert(launchOp &&
"expected launch op");
1033 rewriter.setInsertionPoint(copyOps.front());
1040 launchOp.getBlockSizeZ()});
1048 auto copyOp = cast<linalg::CopyOp>(op);
1050 cast<TypedValue<MemRefType>>(copyOp.getDpsInputOperand(0)->
get());
1051 assert(inMemRef.getType().getRank() == 2 &&
1052 "expected in to be a 2D memref");
1057 globalDescs.push_back(globalDesc);
1061 cast<TypedValue<MemRefType>>(copyOp.getDpsInitOperand(0)->
get());
1062 shmems.push_back(shmem);
1067 rewriter.setInsertionPoint(copyOps.front());
1085 gpu::LaunchOp commonLaunchOp;
1087 if (llvm::any_of(payloadOps, [&](
Operation *op) {
1088 if (!commonLaunchOp) {
1094 !isa<linalg::CopyOp>(op);
1100 emitSilenceableError()
1101 <<
"target ops must be linalg::CopyOp nested under a common "
1102 "gpu.LaunchOp to be rewritten because the tma descriptors need to "
1103 "be created on the host.\nBut got: "
1104 << *firstOp <<
"\nand " << *failingOp;
1119class NVGPUTransformDialectExtension
1124 NVGPUTransformDialectExtension() {
1125 declareGeneratedDialect<arith::ArithDialect>();
1126 declareGeneratedDialect<affine::AffineDialect>();
1127 declareGeneratedDialect<NVGPUDialect>();
1128 declareGeneratedDialect<NVVM::NVVMDialect>();
1129 declareGeneratedDialect<vector::VectorDialect>();
1130 registerTransformOps<
1132#include "mlir/Dialect/NVGPU/TransformOps/NVGPUTransformOps.cpp.inc"
1138#define GET_OP_CLASSES
1139#include "mlir/Dialect/NVGPU/TransformOps/NVGPUTransformOps.cpp.inc"
constexpr int kWgmmaSizeM
M size of wgmma.mma_async instruction.
static llvm::ManagedStatic< PassManagerOptions > options
static std::optional< VectorShape > vectorShape(Type type)
static LogicalResult fail(function_ref< InFlightDiagnostic()> emitError, const Twine &message)
Reports message through emitError if it is non-null, and returns failure.
Base type for affine expression.
AffineExpr floorDiv(uint64_t v) const
Attributes are known-constant values of operations.
This class provides a shared interface for ranked and unranked memref types.
Attribute getMemorySpace() const
Returns the memory space in which data referred to by this memref resides.
unsigned getMemorySpaceAsInt() const
[deprecated] Returns the memory space in old raw integer representation.
The result of a transform IR operation application.
static DiagnosedSilenceableFailure success()
Constructs a DiagnosedSilenceableFailure in the success state.
static DiagnosedSilenceableFailure definiteFailure()
Constructs a DiagnosedSilenceableFailure in the failure state.
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
void addExtensions()
Add the given extensions to the registry.
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...
MLIRContext is the top-level object for a collection of MLIR operations.
This is a builder type that keeps local references to arguments.
Builder & setMemorySpace(Attribute newMemorySpace)
RAII guard to reset the insertion point of the builder when destroyed.
This class helps build Operations.
void setInsertionPoint(Block *block, Block::iterator insertPoint)
Set the insertion point to the specified location.
This class represents a single result from folding an operation.
Operation is the basic unit of execution within MLIR.
Block * getBlock()
Returns the operation block that contains this operation.
OpTy getParentOfType()
Return the closest surrounding parent operation that is of type 'OpTy'.
This class coordinates the application of a rewrite on a set of IR, providing a way for clients to tr...
virtual void replaceOp(Operation *op, ValueRange newValues)
Replace the results of the given (original) operation with the specified list of values (replacements...
virtual void eraseOp(Operation *op)
This method erases an operation that is known to have no uses.
This class provides an abstraction over the various different ranges of value types.
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...
Type getType() const
Return the type of this value.
user_range getUsers() const
bool hasOneUse() const
Returns true if this value has exactly one use.
static ConstantIndexOp create(OpBuilder &builder, Location location, int64_t value)
Base class for extensions of the Transform dialect that supports injecting operations into the Transf...
OpFoldResult makeComposedFoldedAffineApply(OpBuilder &b, Location loc, AffineMap map, ArrayRef< OpFoldResult > operands, bool composeAffineMin=false)
Constructs an AffineApplyOp that applies map to operands after composing the map with the maps of any...
SmallVector< OpFoldResult > getMixedSizes(OpBuilder &builder, Location loc, Value value)
Return the dimensions of the given memref value.
void populateCommonGPUTypeAndAttributeConversions(TypeConverter &typeConverter)
Remap common GPU memory spaces (Workgroup, Private, etc) to LLVM address spaces.
MemRefType getMBarrierMemrefType(MLIRContext *context, MBarrierGroupType barrierType)
Return the memref type that can be used to represent an mbarrier object.
void registerTransformDialectExtension(DialectRegistry ®istry)
void createAsyncGroups(RewriterBase &rewriter, Operation *op, bool bypassL1)
Convert global->shared vector transfers to async device copies.
Include the generated interface declarations.
OpFoldResult getAsIndexOpFoldResult(MLIRContext *ctx, int64_t val)
Convert int64_t to integer attributes of index type and return them as OpFoldResult.
LogicalResult getBackwardSlice(Operation *op, SetVector< Operation * > *backwardSlice, const BackwardSliceOptions &options={})
Fills backwardSlice with the computed backward slice (i.e.
SmallVector< int64_t > computeStrides(ArrayRef< int64_t > sizes)
DiagnosedSilenceableFailure emitSilenceableFailure(Location loc, const Twine &message={})
Emits a silenceable failure with the given message.
SmallVector< int64_t > delinearize(int64_t linearIndex, ArrayRef< int64_t > strides)
Given the strides together with a linear index in the dimension space, return the vector-space offset...
AffineExpr computeSum(MLIRContext *ctx, ArrayRef< AffineExpr > basis)
Self-explicit.
bool isMemoryEffectFree(Operation *op)
Returns true if the given operation is free of memory effects.
int64_t computeProduct(ArrayRef< int64_t > basis)
Self-explicit.
llvm::SetVector< T, Vector, Set, N > SetVector
DiagnosedDefiniteFailure emitDefiniteFailure(Location loc, const Twine &message={})
Emits a definite failure with the given message.
void populateNVGPUToNVVMConversionPatterns(const LLVMTypeConverter &converter, RewritePatternSet &patterns)
Type getElementTypeOrSelf(Type type)
Return the element type or return the type itself.
std::conditional_t< std::is_same_v< Ty, mlir::Type >, mlir::Value, detail::TypedValue< Ty > > TypedValue
If Ty is mlir::Type this will select Value instead of having a wrapper around it.
void bindSymbols(MLIRContext *ctx, AffineExprTy &...exprs)
Bind a list of AffineExpr references to SymbolExpr at positions: [0 .
Value getValueOrCreateConstantIndexOp(OpBuilder &b, Location loc, OpFoldResult ofr)
Converts an OpFoldResult to a Value.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
AffineExpr getAffineDimExpr(unsigned position, MLIRContext *context)
These free functions allow clients of the API to not use classes in detail.
void bindSymbolsList(MLIRContext *ctx, MutableArrayRef< AffineExprTy > exprs)
Helper to create the tma operations corresponding to linalg::CopyOp.
SmallVector< Operation * > rewrite(ArrayRef< Operation * > copyOps)
CopyBuilder(RewriterBase &rewriter, Location loc)
void buildBarrierArriveTx(TypedValue< MBarrierGroupType > barrier, ArrayRef< OpFoldResult > sizes)
OpFoldResult buildTmaAsyncLoad(TypedValue< TensorMapDescriptorType > globalDesc, TypedValue< MemRefType > sharedMemref, TypedValue< MBarrierGroupType > barrier, SmallVectorImpl< Operation * > &loadOps)
Build a tma load from global memory to shared memory using barrier to synchronize.
TypedValue< TensorMapDescriptorType > buildGlobalMemRefDescriptor(TypedValue< MemRefType > memref, gpu::LaunchOp launchOp)
Create tma descriptor op to initiate transfer from global to shared memory.
void buildTryWaitParity(TypedValue< MBarrierGroupType > barrier)
TypedValue< MBarrierGroupType > buildAndInitBarrierInSharedMemory(OpFoldResult numThreads)
SmallVector< Operation * > buildPredicateLoadsOnThread0(ArrayRef< TypedValue< TensorMapDescriptorType > > globalDescriptors, ArrayRef< TypedValue< MemRefType > > sharedMemBuffers, TypedValue< MBarrierGroupType > barrier)
If threadIdx.x == 0 does TMA request + wait, else just wait.
HopperBuilder(RewriterBase &rewriter, Location loc)
Helper struct to provide a simple mapping from matmul operations to the corresponding mma....
MmaSyncBuilder(OpBuilder &b, Location loc, OpFoldResult laneId)
std::function< SmallVector< RowColIndexing >(MLIRContext *)> IndexCalculator
FailureOr< Operation * > buildMmaSync(LinalgOp linalgOp)
Create the mma.sync operation corresponding to linalgOp along with all the supporting load/store and ...
Helper struct to encode a pair of row/column indexings in the form of affine expressions.
RowColIndexing(AffineExpr row, AffineExpr col)
void print(llvm::raw_ostream &os) const
Options to dictate how loops should be pipelined.