Skip to content

Commit

Permalink
[mlir][openacc] Add separate acc data operations for OpenACC data cla…
Browse files Browse the repository at this point in the history
…uses

As outlined in [1], data clauses are now implemented as separate operations
from the constructs that they belong to. Some of the highlighted benefits:
- Correctly represent dataflow of data operations
- Easier to track debugging information
- Friendlier to add attributes and to optimize operations

For now, all of the other operand lists are being kept until all references
to them in LLVM can be removed (such as those in flang lowering)

[1] https://discourse.llvm.org/t/rfc-openacc-dialect-data-operation-improvements/69825

Reviewed By: clementval, vzakhari

Differential Revision: https://reviews.llvm.org/D148389
  • Loading branch information
razvanlupusoru authored and Razvan Lupusoru committed Apr 18, 2023
1 parent 8350764 commit c184dcb
Show file tree
Hide file tree
Showing 10 changed files with 704 additions and 43 deletions.
12 changes: 8 additions & 4 deletions flang/lib/Lower/OpenACC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ createComputeOp(Fortran::lower::AbstractConverter &converter,
copyOperands, copyinOperands, copyinReadonlyOperands, copyoutOperands,
copyoutZeroOperands, createOperands, createZeroOperands, noCreateOperands,
presentOperands, devicePtrOperands, attachOperands, firstprivateOperands,
privateOperands;
privateOperands, dataClauseOperands;

// Async, wait and self clause have optional values but can be present with
// no value as well. When there is no value, the op has an attribute to
Expand Down Expand Up @@ -580,6 +580,7 @@ createComputeOp(Fortran::lower::AbstractConverter &converter,
addOperands(operands, operandSegments, privateOperands);
addOperands(operands, operandSegments, firstprivateOperands);
}
addOperands(operands, operandSegments, dataClauseOperands);

Op computeOp;
if constexpr (std::is_same_v<Op, mlir::acc::KernelsOp>)
Expand Down Expand Up @@ -608,7 +609,7 @@ static void genACCDataOp(Fortran::lower::AbstractConverter &converter,
llvm::SmallVector<mlir::Value> copyOperands, copyinOperands,
copyinReadonlyOperands, copyoutOperands, copyoutZeroOperands,
createOperands, createZeroOperands, noCreateOperands, presentOperands,
deviceptrOperands, attachOperands;
deviceptrOperands, attachOperands, dataClauseOperands;

fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();

Expand Down Expand Up @@ -680,6 +681,7 @@ static void genACCDataOp(Fortran::lower::AbstractConverter &converter,
addOperands(operands, operandSegments, presentOperands);
addOperands(operands, operandSegments, deviceptrOperands);
addOperands(operands, operandSegments, attachOperands);
addOperands(operands, operandSegments, dataClauseOperands);

createRegionOp<mlir::acc::DataOp, mlir::acc::TerminatorOp>(
firOpBuilder, currentLocation, operands, operandSegments);
Expand Down Expand Up @@ -761,7 +763,7 @@ genACCEnterDataOp(Fortran::lower::AbstractConverter &converter,
const Fortran::parser::AccClauseList &accClauseList) {
mlir::Value ifCond, async, waitDevnum;
llvm::SmallVector<mlir::Value> copyinOperands, createOperands,
createZeroOperands, attachOperands, waitOperands;
createZeroOperands, attachOperands, waitOperands, dataClauseOperands;

// Async, wait and self clause have optional values but can be present with
// no value as well. When there is no value, the op has an attribute to
Expand Down Expand Up @@ -821,6 +823,7 @@ genACCEnterDataOp(Fortran::lower::AbstractConverter &converter,
addOperands(operands, operandSegments, createOperands);
addOperands(operands, operandSegments, createZeroOperands);
addOperands(operands, operandSegments, attachOperands);
addOperands(operands, operandSegments, dataClauseOperands);

mlir::acc::EnterDataOp enterDataOp = createSimpleOp<mlir::acc::EnterDataOp>(
firOpBuilder, currentLocation, operands, operandSegments);
Expand All @@ -839,7 +842,7 @@ genACCExitDataOp(Fortran::lower::AbstractConverter &converter,
const Fortran::parser::AccClauseList &accClauseList) {
mlir::Value ifCond, async, waitDevnum;
llvm::SmallVector<mlir::Value> copyoutOperands, deleteOperands,
detachOperands, waitOperands;
detachOperands, waitOperands, dataClauseOperands;

// Async and wait clause have optional values but can be present with
// no value as well. When there is no value, the op has an attribute to
Expand Down Expand Up @@ -897,6 +900,7 @@ genACCExitDataOp(Fortran::lower::AbstractConverter &converter,
addOperands(operands, operandSegments, copyoutOperands);
addOperands(operands, operandSegments, deleteOperands);
addOperands(operands, operandSegments, detachOperands);
addOperands(operands, operandSegments, dataClauseOperands);

mlir::acc::ExitDataOp exitDataOp = createSimpleOp<mlir::acc::ExitDataOp>(
firOpBuilder, currentLocation, operands, operandSegments);
Expand Down
24 changes: 17 additions & 7 deletions mlir/include/mlir/Dialect/OpenACC/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,25 @@ set(LLVM_TARGET_DEFINITIONS ${LLVM_MAIN_INCLUDE_DIR}/llvm/Frontend/OpenACC/ACC.t
mlir_tablegen(AccCommon.td --gen-directive-decl --directives-dialect=OpenACC)
add_public_tablegen_target(acc_common_td)

add_mlir_dialect(OpenACCOps acc)

add_mlir_doc(OpenACCOps OpenACCDialect Dialects/ -gen-dialect-doc)
add_dependencies(OpenACCDialectDocGen acc_common_td)

set(LLVM_TARGET_DEFINITIONS OpenACCOps.td)
mlir_tablegen(OpenACCOpsDialect.h.inc -gen-dialect-decls -dialect=acc)
mlir_tablegen(OpenACCOpsDialect.cpp.inc -gen-dialect-defs -dialect=acc)
mlir_tablegen(OpenACCOps.h.inc -gen-op-decls)
mlir_tablegen(OpenACCOps.cpp.inc -gen-op-defs)
mlir_tablegen(OpenACCOpsEnums.h.inc -gen-enum-decls)
mlir_tablegen(OpenACCOpsEnums.cpp.inc -gen-enum-defs)
add_public_tablegen_target(MLIROpenACCEnumsIncGen)
add_dependencies(mlir-headers MLIROpenACCEnumsIncGen)

set(LLVM_TARGET_DEFINITIONS OpenACCOps.td)
mlir_tablegen(OpenACCOpsAttributes.h.inc -gen-attrdef-decls -attrdefs-dialect=acc)
mlir_tablegen(OpenACCOpsAttributes.cpp.inc -gen-attrdef-defs -attrdefs-dialect=acc)
add_mlir_doc(OpenACCOps OpenACCDialect Dialects/ -gen-dialect-doc)
add_public_tablegen_target(MLIROpenACCOpsIncGen)
add_dependencies(OpenACCDialectDocGen acc_common_td)
add_public_tablegen_target(MLIROpenACCAttributesIncGen)
add_dependencies(mlir-headers MLIROpenACCAttributesIncGen)

set(LLVM_TARGET_DEFINITIONS OpenACCTypeInterfaces.td)
mlir_tablegen(OpenACCTypeInterfaces.h.inc -gen-type-interface-decls)
mlir_tablegen(OpenACCTypeInterfaces.cpp.inc -gen-type-interface-defs)
add_public_tablegen_target(MLIROpenACCTypeInterfacesIncGen)
add_dependencies(mlir-headers MLIROpenACCTypeInterfacesIncGen)
6 changes: 6 additions & 0 deletions mlir/include/mlir/Dialect/OpenACC/OpenACC.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@
#ifndef MLIR_DIALECT_OPENACC_OPENACC_H_
#define MLIR_DIALECT_OPENACC_OPENACC_H_

#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/Dialect.h"
#include "mlir/IR/OpDefinition.h"

#include "mlir/Dialect/OpenACC/OpenACCOpsDialect.h.inc"
#include "mlir/Dialect/OpenACC/OpenACCOpsEnums.h.inc"
#include "mlir/Dialect/OpenACC/OpenACCTypeInterfaces.h.inc"
#include "mlir/Interfaces/SideEffectInterfaces.h"

#define GET_TYPEDEF_CLASSES
#include "mlir/Dialect/OpenACC/OpenACCOpsTypes.h.inc"

#define GET_ATTRDEF_CLASSES
#include "mlir/Dialect/OpenACC/OpenACCOpsAttributes.h.inc"
Expand Down
33 changes: 33 additions & 0 deletions mlir/include/mlir/Dialect/OpenACC/OpenACCBase.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//===- OpenACCBase.td - OpenACC dialect definition ---------*- tablegen -*-===//
//
// Part of the MLIR Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// =============================================================================
//
// Defines MLIR OpenACC dialect.
//
//===----------------------------------------------------------------------===//

#ifndef OPENACC_BASE
#define OPENACC_BASE

include "mlir/IR/AttrTypeBase.td"

def OpenACC_Dialect : Dialect {
let name = "acc";

let summary = "An OpenACC dialect for MLIR.";

let description = [{
This dialect models the construct from the OpenACC 3.1 directive language.
}];

let useDefaultAttributePrinterParser = 1;
let useDefaultTypePrinterParser = 1;
let cppNamespace = "::mlir::acc";
let dependentDialects = ["::mlir::memref::MemRefDialect","::mlir::LLVM::LLVMDialect"];
}

#endif // OPENACC_BASE

0 comments on commit c184dcb

Please sign in to comment.