17#ifndef MLIR_DIALECT_OPENACC_OPENACCPARMAPPING_H_
18#define MLIR_DIALECT_OPENACC_OPENACCPARMAPPING_H_
22#include "llvm/Support/ErrorHandling.h"
34 assert((gangDimValue >= 1 && gangDimValue <= 3) &&
35 "gang dimension must be 1, 2, or 3");
36 switch (gangDimValue) {
38 return ParLevel::gang_dim1;
40 return ParLevel::gang_dim2;
42 return ParLevel::gang_dim3;
44 llvm_unreachable(
"validated gang dimension");
63template <
typename ParDimAttrT>
77 assert((level == ParLevel::gang_dim1 || level == ParLevel::gang_dim2 ||
78 level == ParLevel::gang_dim3) &&
79 "gangDim requires a gang parallelism level");
80 return map(ctx, level);
83 return map(ctx, ParLevel::worker);
86 return map(ctx, ParLevel::vector);
95 virtual bool isVector(ParDimAttrT attr)
const = 0;
98 virtual bool isWorker(ParDimAttrT attr)
const = 0;
101 virtual bool isGang(ParDimAttrT attr)
const = 0;
104 virtual bool isSeq(ParDimAttrT attr)
const = 0;
122 ParLevel level)
const override {
124 case ParLevel::gang_dim1:
125 return mlir::acc::GPUParallelDimAttr::blockXDim(ctx);
126 case ParLevel::gang_dim2:
127 return mlir::acc::GPUParallelDimAttr::blockYDim(ctx);
128 case ParLevel::gang_dim3:
129 return mlir::acc::GPUParallelDimAttr::blockZDim(ctx);
130 case ParLevel::worker:
131 return mlir::acc::GPUParallelDimAttr::threadYDim(ctx);
132 case ParLevel::vector:
133 return mlir::acc::GPUParallelDimAttr::threadXDim(ctx);
135 return mlir::acc::GPUParallelDimAttr::seqDim(ctx);
137 llvm_unreachable(
"Unknown ParLevel");
140 bool isVector(mlir::acc::GPUParallelDimAttr attr)
const override {
141 return attr.isThreadX();
144 bool isWorker(mlir::acc::GPUParallelDimAttr attr)
const override {
145 return attr.isThreadY();
148 bool isGang(mlir::acc::GPUParallelDimAttr attr)
const override {
149 return attr.isAnyBlock();
152 bool isSeq(mlir::acc::GPUParallelDimAttr attr)
const override {
MLIRContext is the top-level object for a collection of MLIR operations.
Policy class that defines how OpenACC parallelism levels map to target-specific parallel dimension at...
ParDimAttrT seqDim(MLIRContext *ctx) const
virtual ParDimAttrT map(MLIRContext *ctx, ParLevel level) const =0
Map an OpenACC parallelism level to target dimension.
virtual bool isWorker(ParDimAttrT attr) const =0
Check if the attribute represents worker parallelism.
ParDimAttrT vectorDim(MLIRContext *ctx) const
virtual bool isSeq(ParDimAttrT attr) const =0
Check if the attribute represents sequential execution.
ParDimAttrT workerDim(MLIRContext *ctx) const
ParDimAttrT gangDim(MLIRContext *ctx, ParLevel level) const
Convenience methods for specific parallelism levels.
virtual bool isVector(ParDimAttrT attr) const =0
Check if the attribute represents vector parallelism.
virtual bool isGang(ParDimAttrT attr) const =0
Check if the attribute represents gang parallelism (any gang dimension).
virtual ~ACCParMappingPolicy()=default
Default policy that provides the standard GPU mapping: gang(dim:1) -> BlockX (gridDim....
mlir::acc::GPUParallelDimAttr map(MLIRContext *ctx, ParLevel level) const override
Map an OpenACC parallelism level to target dimension.
bool isGang(mlir::acc::GPUParallelDimAttr attr) const override
Check if the attribute represents gang parallelism (any gang dimension).
bool isSeq(mlir::acc::GPUParallelDimAttr attr) const override
Check if the attribute represents sequential execution.
bool isWorker(mlir::acc::GPUParallelDimAttr attr) const override
Check if the attribute represents worker parallelism.
bool isVector(mlir::acc::GPUParallelDimAttr attr) const override
Check if the attribute represents vector parallelism.
ParLevel getGangParLevel(int64_t gangDimValue)
Convert a gang dimension value (1, 2, or 3) to the corresponding ParLevel.
ACCParMappingPolicy< mlir::acc::GPUParallelDimAttr > ACCToGPUMappingPolicy
Type alias for the GPU-specific mapping policy.
Include the generated interface declarations.