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");
44 specifiedMappings.insert(processor);
46 ArrayRef<Attribute> mappingAsAttrs(mapping.data(), mapping.size());
54 enum MappingLevel { MapGrid = 0, MapBlock = 1, Sequential = 2 };
61 static MappingLevel &
operator++(MappingLevel &mappingLevel) {
62 if (mappingLevel < Sequential) {
63 mappingLevel =
static_cast<MappingLevel
>(mappingLevel + 1);
77 return Processor::Sequential;
82 return Processor::BlockX;
84 return Processor::BlockY;
86 return Processor::BlockZ;
88 return Processor::Sequential;
94 return Processor::ThreadX;
96 return Processor::ThreadY;
98 return Processor::ThreadZ;
100 return Processor::Sequential;
104 return Processor::Sequential;
111 MappingLevel mappingLevel = MapGrid) {
114 ((mappingLevel == MapGrid) && parallelOp->getParentOfType<ParallelOp>()))
120 attrs.reserve(parallelOp.getNumLoops());
121 for (
int i = 0, e = parallelOp.getNumLoops(); i < e; ++i) {
122 attrs.push_back(b.
getAttr<ParallelLoopDimMappingAttr>(
130 for (
Operation &op : *parallelOp.getBody()) {
131 if (ParallelOp nested = dyn_cast<ParallelOp>(op))
137 struct GpuMapParallelLoopsPass
138 :
public impl::GpuMapParallelLoopsPassBase<GpuMapParallelLoopsPass> {
139 void runOnOperation()
override {
140 for (
Region ®ion : getOperation()->getRegions()) {
141 region.walk([](ParallelOp parallelOp) {
mapParallelOp(parallelOp); });
150 std::unique_ptr<mlir::OperationPass<mlir::func::FuncOp>>
152 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.
Include the generated interface declarations.
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.