Skip to content

Commit

Permalink
[openacc] Update acc.loop to expose data operands (#70954)
Browse files Browse the repository at this point in the history
The compute and data constructs implement getNumDataOperands and
getDataOperand. The acc.loop operation similarly has multiple data
operands - thus it makes sense to expose them the same way.

For loop, only private and reduction operands are exposed this way.
Technically, acc.loop also holds cache operands - but these are hints
not a data attribute.
  • Loading branch information
razvanlupusoru committed Nov 1, 2023
1 parent 5570d32 commit f5a5142
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion flang/lib/Lower/OpenACC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1592,9 +1592,9 @@ createLoopOp(Fortran::lower::AbstractConverter &converter,
addOperand(operands, operandSegments, workerNum);
addOperand(operands, operandSegments, vectorNum);
addOperands(operands, operandSegments, tileOperands);
addOperands(operands, operandSegments, cacheOperands);
addOperands(operands, operandSegments, privateOperands);
addOperands(operands, operandSegments, reductionOperands);
addOperands(operands, operandSegments, cacheOperands);

auto loopOp = createRegionOp<mlir::acc::LoopOp, mlir::acc::YieldOp>(
builder, currentLocation, eval, operands, operandSegments);
Expand Down
4 changes: 4 additions & 0 deletions mlir/include/mlir/Dialect/OpenACC/OpenACC.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,16 @@
mlir::acc::CacheOp
#define ACC_COMPUTE_CONSTRUCT_OPS \
mlir::acc::ParallelOp, mlir::acc::KernelsOp, mlir::acc::SerialOp
#define ACC_COMPUTE_CONSTRUCT_AND_LOOP_OPS \
ACC_COMPUTE_CONSTRUCT_OPS, mlir::acc::LoopOp
#define ACC_DATA_CONSTRUCT_OPS \
mlir::acc::DataOp, mlir::acc::EnterDataOp, mlir::acc::ExitDataOp, \
mlir::acc::UpdateOp, mlir::acc::HostDataOp, mlir::acc::DeclareEnterOp, \
mlir::acc::DeclareExitOp, mlir::acc::DeclareOp
#define ACC_COMPUTE_AND_DATA_CONSTRUCT_OPS \
ACC_COMPUTE_CONSTRUCT_OPS, ACC_DATA_CONSTRUCT_OPS
#define ACC_COMPUTE_LOOP_AND_DATA_CONSTRUCT_OPS \
ACC_COMPUTE_CONSTRUCT_AND_LOOP_OPS, ACC_DATA_CONSTRUCT_OPS

namespace mlir {
namespace acc {
Expand Down
11 changes: 9 additions & 2 deletions mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -1196,11 +1196,12 @@ def OpenACC_LoopOp : OpenACC_Op<"loop",
UnitAttr:$hasWorker,
UnitAttr:$hasVector,
Variadic<IntOrIndex>:$tileOperands,
Variadic<OpenACC_PointerLikeTypeInterface>:$cacheOperands,
Variadic<OpenACC_PointerLikeTypeInterface>:$privateOperands,
OptionalAttr<SymbolRefArrayAttr>:$privatizations,
Variadic<AnyType>:$reductionOperands,
OptionalAttr<SymbolRefArrayAttr>:$reductionRecipes,
Variadic<OpenACC_PointerLikeTypeInterface>:$cacheOperands);
OptionalAttr<SymbolRefArrayAttr>:$reductionRecipes
);

let results = (outs Variadic<AnyType>:$results);

Expand All @@ -1211,6 +1212,12 @@ def OpenACC_LoopOp : OpenACC_Op<"loop",
static StringRef getGangNumKeyword() { return "num"; }
static StringRef getGangDimKeyword() { return "dim"; }
static StringRef getGangStaticKeyword() { return "static"; }

/// The number of private and reduction operands.
unsigned getNumDataOperands();

/// The i-th data operand passed.
Value getDataOperand(unsigned i);
}];

let hasCustomAssemblyFormat = 1;
Expand Down
16 changes: 16 additions & 0 deletions mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,22 @@ LogicalResult acc::LoopOp::verify() {
return success();
}

unsigned LoopOp::getNumDataOperands() {
return getReductionOperands().size() + getPrivateOperands().size();
}

Value LoopOp::getDataOperand(unsigned i) {
unsigned numOptional = getGangNum() ? 1 : 0;
numOptional += getGangDim() ? 1 : 0;
numOptional += getGangStatic() ? 1 : 0;
numOptional += getVectorLength() ? 1 : 0;
numOptional += getWorkerNum() ? 1 : 0;
numOptional += getVectorLength() ? 1 : 0;
numOptional += getTileOperands().size();
numOptional += getCacheOperands().size();
return getOperand(numOptional + i);
}

//===----------------------------------------------------------------------===//
// DataOp
//===----------------------------------------------------------------------===//
Expand Down

0 comments on commit f5a5142

Please sign in to comment.