23 #define GEN_PASS_DEF_GPUMAPPARALLELLOOPSPASS
24 #include "mlir/Dialect/GPU/Transforms/Passes.h.inc"
29 using scf::ParallelOp;
38 for (
auto dimAttr : mapping) {
39 gpu::Processor processor = dimAttr.getProcessor();
40 if (processor != gpu::Processor::Sequential &&
41 specifiedMappings.count(processor))
42 return ploopOp.emitError(
43 "invalid mapping multiple loops to same processor");
45 ArrayRef<Attribute> mappingAsAttrs(mapping.data(), mapping.size());
53 enum MappingLevel { MapGrid = 0, MapBlock = 1, Sequential = 2 };
60 static MappingLevel &
operator++(MappingLevel &mappingLevel) {
61 if (mappingLevel < Sequential) {
62 mappingLevel =
static_cast<MappingLevel
>(mappingLevel + 1);
76 return Processor::Sequential;
81 return Processor::BlockX;
83 return Processor::BlockY;
85 return Processor::BlockZ;
87 return Processor::Sequential;
93 return Processor::ThreadX;
95 return Processor::ThreadY;
97 return Processor::ThreadZ;
99 return Processor::Sequential;
103 return Processor::Sequential;
110 MappingLevel mappingLevel = MapGrid) {
113 ((mappingLevel == MapGrid) && parallelOp->getParentOfType<ParallelOp>()))
119 attrs.reserve(parallelOp.getNumLoops());
120 for (
int i = 0, e = parallelOp.getNumLoops(); i < e; ++i) {
121 attrs.push_back(b.
getAttr<ParallelLoopDimMappingAttr>(
129 for (
Operation &op : *parallelOp.getBody()) {
130 if (ParallelOp nested = dyn_cast<ParallelOp>(op))
136 struct GpuMapParallelLoopsPass
137 :
public impl::GpuMapParallelLoopsPassBase<GpuMapParallelLoopsPass> {
138 void runOnOperation()
override {
139 for (
Region ®ion : getOperation()->getRegions()) {
140 region.walk([](ParallelOp parallelOp) {
mapParallelOp(parallelOp); });
149 std::unique_ptr<mlir::OperationPass<mlir::func::FuncOp>>
151 return std::make_unique<gpu::GpuMapParallelLoopsPass>();
This class is a general helper class for creating context-global objects like types,...
AffineMap getDimIdentityMap()
Attr getAttr(Args &&...args)
Get or construct an instance of the attribute Attr with provided arguments.
MLIRContext is the top-level object for a collection of MLIR operations.
Operation is the basic unit of execution within MLIR.
This class contains a list of basic blocks and a link to the parent operation it is attached to.
static Processor getHardwareIdForMapping(MappingLevel level, int dimension)
Computed the hardware id to use for a given mapping level.
static MappingLevel & operator++(MappingLevel &mappingLevel)
Bounded increment on MappingLevel.
static void mapParallelOp(ParallelOp parallelOp, MappingLevel mappingLevel=MapGrid)
Add mapping information to the given parallel loop.
LogicalResult setMappingAttr(scf::ParallelOp ploopOp, ArrayRef< ParallelLoopDimMappingAttr > mapping)
Sets the mapping attribute of a scf.parallel operation.
static constexpr int kNumHardwareIds
StringRef getMappingAttrName()
Name of the mapping attribute produced by loop mappers.
This header declares functions that assist transformations in the MemRef dialect.
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
std::unique_ptr< OperationPass< func::FuncOp > > createGpuMapParallelLoopsPass()
Maps the parallel loops found in the given function to workgroups.
This class represents an efficient way to signal success or failure.