24 using scf::ParallelOp;
33 for (
auto dimAttr : mapping) {
34 gpu::Processor processor = dimAttr.getProcessor();
35 if (processor != gpu::Processor::Sequential &&
36 specifiedMappings.count(processor))
37 return ploopOp.emitError(
38 "invalid mapping multiple loops to same processor");
42 ArrayAttr::get(ploopOp.getContext(), mappingAsAttrs));
55 static MappingLevel &
operator++(MappingLevel &mappingLevel) {
56 if (mappingLevel < Sequential) {
57 mappingLevel =
static_cast<MappingLevel
>(mappingLevel + 1);
70 if (dimension >= kNumHardwareIds || level == Sequential)
71 return Processor::Sequential;
76 return Processor::BlockX;
78 return Processor::BlockY;
80 return Processor::BlockZ;
82 return Processor::Sequential;
88 return Processor::ThreadX;
90 return Processor::ThreadY;
92 return Processor::ThreadZ;
94 return Processor::Sequential;
98 return Processor::Sequential;
105 MappingLevel mappingLevel = MapGrid) {
108 ((mappingLevel == MapGrid) && parallelOp->getParentOfType<ParallelOp>()))
114 attrs.reserve(parallelOp.getNumLoops());
115 for (
int i = 0, e = parallelOp.getNumLoops(); i < e; ++i) {
116 attrs.push_back(b.
getAttr<ParallelLoopDimMappingAttr>(
124 for (
Operation &op : *parallelOp.getBody()) {
125 if (ParallelOp nested = dyn_cast<ParallelOp>(op))
131 struct GpuMapParallelLoopsPass
132 :
public GpuMapParallelLoopsPassBase<GpuMapParallelLoopsPass> {
133 void runOnOperation()
override {
134 for (
Region ®ion : getOperation()->getRegions()) {
135 region.walk([](ParallelOp parallelOp) {
mapParallelOp(parallelOp); });
144 std::unique_ptr<mlir::OperationPass<mlir::func::FuncOp>>
146 return std::make_unique<gpu::GpuMapParallelLoopsPass>();
Include the generated interface declarations.
This class contains a list of basic blocks and a link to the parent operation it is attached to...
LogicalResult setMappingAttr(scf::ParallelOp ploopOp, ArrayRef< ParallelLoopDimMappingAttr > mapping)
Sets the mapping attribute of a scf.parallel operation.
Operation is a basic unit of execution within MLIR.
std::unique_ptr< OperationPass< func::FuncOp > > createGpuMapParallelLoopsPass()
Maps the parallel loops found in the given function to workgroups.
StringRef getMappingAttrName()
Name of the mapping attribute produced by loop mappers.
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
This class represents an efficient way to signal success or failure.
Attr getAttr(Args &&...args)
Get or construct an instance of the attribute Attr with provided arguments.
static void mapParallelOp(ParallelOp parallelOp, MappingLevel mappingLevel=MapGrid)
Add mapping information to the given parallel loop.
This class is a general helper class for creating context-global objects like types, attributes, and affine expressions.
AffineMap getDimIdentityMap()
static Processor getHardwareIdForMapping(MappingLevel level, int dimension)
Computed the hardware id to use for a given mapping level.
static constexpr int kNumHardwareIds
MLIRContext is the top-level object for a collection of MLIR operations.
static MappingLevel & operator++(MappingLevel &mappingLevel)
Bounded increment on MappingLevel.