1 | //===- OpenACC.h - MLIR OpenACC Dialect -------------------------*- C++ -*-===// |
2 | // |
3 | // Part of the MLIR Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | // ============================================================================ |
8 | // |
9 | // This file declares the OpenACC dialect in MLIR. |
10 | // |
11 | //===----------------------------------------------------------------------===// |
12 | |
13 | #ifndef MLIR_DIALECT_OPENACC_OPENACC_H_ |
14 | #define MLIR_DIALECT_OPENACC_OPENACC_H_ |
15 | |
16 | #include "mlir/IR/BuiltinTypes.h" |
17 | #include "mlir/IR/Dialect.h" |
18 | #include "mlir/IR/OpDefinition.h" |
19 | #include "mlir/IR/PatternMatch.h" |
20 | #include "mlir/IR/SymbolTable.h" |
21 | |
22 | #include "mlir/Bytecode/BytecodeOpInterface.h" |
23 | #include "mlir/Dialect/OpenACC/OpenACCOpsDialect.h.inc" |
24 | #include "mlir/Dialect/OpenACC/OpenACCOpsEnums.h.inc" |
25 | #include "mlir/Dialect/OpenACC/OpenACCTypeInterfaces.h.inc" |
26 | #include "mlir/Dialect/OpenACCMPCommon/Interfaces/AtomicInterfaces.h" |
27 | #include "mlir/Interfaces/ControlFlowInterfaces.h" |
28 | #include "mlir/Interfaces/LoopLikeInterface.h" |
29 | #include "mlir/Interfaces/SideEffectInterfaces.h" |
30 | |
31 | #define GET_TYPEDEF_CLASSES |
32 | #include "mlir/Dialect/OpenACC/OpenACCOpsTypes.h.inc" |
33 | |
34 | #define GET_ATTRDEF_CLASSES |
35 | #include "mlir/Dialect/OpenACC/OpenACCOpsAttributes.h.inc" |
36 | |
37 | #include "mlir/Dialect/OpenACC/OpenACCInterfaces.h" |
38 | |
39 | #define GET_OP_CLASSES |
40 | #include "mlir/Dialect/OpenACC/OpenACCOps.h.inc" |
41 | |
42 | #define ACC_DATA_ENTRY_OPS \ |
43 | mlir::acc::CopyinOp, mlir::acc::CreateOp, mlir::acc::PresentOp, \ |
44 | mlir::acc::NoCreateOp, mlir::acc::AttachOp, mlir::acc::DevicePtrOp, \ |
45 | mlir::acc::GetDevicePtrOp, mlir::acc::PrivateOp, \ |
46 | mlir::acc::FirstprivateOp, mlir::acc::UpdateDeviceOp, \ |
47 | mlir::acc::UseDeviceOp, mlir::acc::ReductionOp, \ |
48 | mlir::acc::DeclareDeviceResidentOp, mlir::acc::DeclareLinkOp, \ |
49 | mlir::acc::CacheOp |
50 | #define ACC_DATA_EXIT_OPS \ |
51 | mlir::acc::CopyoutOp, mlir::acc::DeleteOp, mlir::acc::DetachOp, \ |
52 | mlir::acc::UpdateHostOp |
53 | #define ACC_DATA_CLAUSE_OPS ACC_DATA_ENTRY_OPS, ACC_DATA_EXIT_OPS |
54 | #define ACC_COMPUTE_CONSTRUCT_OPS \ |
55 | mlir::acc::ParallelOp, mlir::acc::KernelsOp, mlir::acc::SerialOp |
56 | #define ACC_COMPUTE_CONSTRUCT_AND_LOOP_OPS \ |
57 | ACC_COMPUTE_CONSTRUCT_OPS, mlir::acc::LoopOp |
58 | #define OPENACC_DATA_CONSTRUCT_STRUCTURED_OPS \ |
59 | mlir::acc::DataOp, mlir::acc::DeclareOp |
60 | #define ACC_DATA_CONSTRUCT_UNSTRUCTURED_OPS \ |
61 | mlir::acc::EnterDataOp, mlir::acc::ExitDataOp, mlir::acc::UpdateOp, \ |
62 | mlir::acc::HostDataOp, mlir::acc::DeclareEnterOp, \ |
63 | mlir::acc::DeclareExitOp |
64 | #define ACC_DATA_CONSTRUCT_OPS \ |
65 | OPENACC_DATA_CONSTRUCT_STRUCTURED_OPS, ACC_DATA_CONSTRUCT_UNSTRUCTURED_OPS |
66 | #define ACC_COMPUTE_AND_DATA_CONSTRUCT_OPS \ |
67 | ACC_COMPUTE_CONSTRUCT_OPS, ACC_DATA_CONSTRUCT_OPS |
68 | #define ACC_COMPUTE_LOOP_AND_DATA_CONSTRUCT_OPS \ |
69 | ACC_COMPUTE_CONSTRUCT_AND_LOOP_OPS, ACC_DATA_CONSTRUCT_OPS |
70 | |
71 | namespace mlir { |
72 | namespace acc { |
73 | |
74 | /// Enumeration used to encode the execution mapping on a loop construct. |
75 | /// They refer directly to the OpenACC 3.3 standard: |
76 | /// 2.9.2. gang |
77 | /// 2.9.3. worker |
78 | /// 2.9.4. vector |
79 | /// |
80 | /// Value can be combined bitwise to reflect the mapping applied to the |
81 | /// construct. e.g. `acc.loop gang vector`, the `gang` and `vector` could be |
82 | /// combined and the final mapping value would be 5 (4 | 1). |
83 | enum OpenACCExecMapping { NONE = 0, VECTOR = 1, WORKER = 2, GANG = 4 }; |
84 | |
85 | /// Used to obtain the `varPtr` from a data clause operation. |
86 | /// Returns empty value if not a data clause operation or is a data exit |
87 | /// operation with no `varPtr`. |
88 | mlir::Value getVarPtr(mlir::Operation *accDataClauseOp); |
89 | |
90 | /// Used to obtain the `accPtr` from a data clause operation. |
91 | /// When a data entry operation, it obtains its result `accPtr` value. |
92 | /// If a data exit operation, it obtains its operand `accPtr` value. |
93 | /// Returns empty value if not a data clause operation. |
94 | mlir::Value getAccPtr(mlir::Operation *accDataClauseOp); |
95 | |
96 | /// Used to obtain the `varPtrPtr` from a data clause operation. |
97 | /// Returns empty value if not a data clause operation. |
98 | mlir::Value getVarPtrPtr(mlir::Operation *accDataClauseOp); |
99 | |
100 | /// Used to obtain `bounds` from an acc data clause operation. |
101 | /// Returns an empty vector if there are no bounds. |
102 | mlir::SmallVector<mlir::Value> getBounds(mlir::Operation *accDataClauseOp); |
103 | |
104 | /// Used to obtain the `name` from an acc operation. |
105 | std::optional<llvm::StringRef> getVarName(mlir::Operation *accOp); |
106 | |
107 | /// Used to obtain the `dataClause` from a data entry operation. |
108 | /// Returns empty optional if not a data entry operation. |
109 | std::optional<mlir::acc::DataClause> |
110 | getDataClause(mlir::Operation *accDataEntryOp); |
111 | |
112 | /// Used to find out whether data operation is implicit. |
113 | /// Returns false if not a data operation or if it is a data operation without |
114 | /// implicit flag. |
115 | bool getImplicitFlag(mlir::Operation *accDataEntryOp); |
116 | |
117 | /// Used to get an immutable range iterating over the data operands. |
118 | mlir::ValueRange getDataOperands(mlir::Operation *accOp); |
119 | |
120 | /// Used to get a mutable range iterating over the data operands. |
121 | mlir::MutableOperandRange getMutableDataOperands(mlir::Operation *accOp); |
122 | |
123 | /// Used to obtain the attribute name for declare. |
124 | static constexpr StringLiteral getDeclareAttrName() { |
125 | return StringLiteral("acc.declare" ); |
126 | } |
127 | |
128 | static constexpr StringLiteral getDeclareActionAttrName() { |
129 | return StringLiteral("acc.declare_action" ); |
130 | } |
131 | |
132 | static constexpr StringLiteral getRoutineInfoAttrName() { |
133 | return StringLiteral("acc.routine_info" ); |
134 | } |
135 | |
136 | static constexpr StringLiteral getCombinedConstructsAttrName() { |
137 | return CombinedConstructsTypeAttr::name; |
138 | } |
139 | |
140 | struct RuntimeCounters |
141 | : public mlir::SideEffects::Resource::Base<RuntimeCounters> { |
142 | mlir::StringRef getName() final { return "AccRuntimeCounters" ; } |
143 | }; |
144 | |
145 | struct ConstructResource |
146 | : public mlir::SideEffects::Resource::Base<ConstructResource> { |
147 | mlir::StringRef getName() final { return "AccConstructResource" ; } |
148 | }; |
149 | |
150 | } // namespace acc |
151 | } // namespace mlir |
152 | |
153 | #endif // MLIR_DIALECT_OPENACC_OPENACC_H_ |
154 | |