MLIR  20.0.0git
OpenACC.h
Go to the documentation of this file.
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 
23 #include "mlir/Dialect/OpenACC/OpenACCOpsDialect.h.inc"
24 #include "mlir/Dialect/OpenACC/OpenACCOpsEnums.h.inc"
25 #include "mlir/Dialect/OpenACC/OpenACCOpsInterfaces.h.inc"
26 #include "mlir/Dialect/OpenACC/OpenACCTypeInterfaces.h.inc"
31 
32 #define GET_TYPEDEF_CLASSES
33 #include "mlir/Dialect/OpenACC/OpenACCOpsTypes.h.inc"
34 
35 #define GET_ATTRDEF_CLASSES
36 #include "mlir/Dialect/OpenACC/OpenACCOpsAttributes.h.inc"
37 
39 
40 #define GET_OP_CLASSES
41 #include "mlir/Dialect/OpenACC/OpenACCOps.h.inc"
42 
43 #define ACC_DATA_ENTRY_OPS \
44  mlir::acc::CopyinOp, mlir::acc::CreateOp, mlir::acc::PresentOp, \
45  mlir::acc::NoCreateOp, mlir::acc::AttachOp, mlir::acc::DevicePtrOp, \
46  mlir::acc::GetDevicePtrOp, mlir::acc::PrivateOp, \
47  mlir::acc::FirstprivateOp, mlir::acc::UpdateDeviceOp, \
48  mlir::acc::UseDeviceOp, mlir::acc::ReductionOp, \
49  mlir::acc::DeclareDeviceResidentOp, mlir::acc::DeclareLinkOp, \
50  mlir::acc::CacheOp
51 #define ACC_DATA_EXIT_OPS \
52  mlir::acc::CopyoutOp, mlir::acc::DeleteOp, mlir::acc::DetachOp, \
53  mlir::acc::UpdateHostOp
54 #define ACC_DATA_CLAUSE_OPS ACC_DATA_ENTRY_OPS, ACC_DATA_EXIT_OPS
55 #define ACC_COMPUTE_CONSTRUCT_OPS \
56  mlir::acc::ParallelOp, mlir::acc::KernelsOp, mlir::acc::SerialOp
57 #define ACC_COMPUTE_CONSTRUCT_AND_LOOP_OPS \
58  ACC_COMPUTE_CONSTRUCT_OPS, mlir::acc::LoopOp
59 #define ACC_DATA_CONSTRUCT_STRUCTURED_OPS \
60  mlir::acc::DataOp, mlir::acc::DeclareOp
61 #define ACC_DATA_CONSTRUCT_UNSTRUCTURED_OPS \
62  mlir::acc::EnterDataOp, mlir::acc::ExitDataOp, mlir::acc::UpdateOp, \
63  mlir::acc::HostDataOp, mlir::acc::DeclareEnterOp, \
64  mlir::acc::DeclareExitOp
65 #define ACC_DATA_CONSTRUCT_OPS \
66  ACC_DATA_CONSTRUCT_STRUCTURED_OPS, ACC_DATA_CONSTRUCT_UNSTRUCTURED_OPS
67 #define ACC_COMPUTE_AND_DATA_CONSTRUCT_OPS \
68  ACC_COMPUTE_CONSTRUCT_OPS, ACC_DATA_CONSTRUCT_OPS
69 #define ACC_COMPUTE_LOOP_AND_DATA_CONSTRUCT_OPS \
70  ACC_COMPUTE_CONSTRUCT_AND_LOOP_OPS, ACC_DATA_CONSTRUCT_OPS
71 
72 namespace mlir {
73 namespace acc {
74 
75 /// Enumeration used to encode the execution mapping on a loop construct.
76 /// They refer directly to the OpenACC 3.3 standard:
77 /// 2.9.2. gang
78 /// 2.9.3. worker
79 /// 2.9.4. vector
80 ///
81 /// Value can be combined bitwise to reflect the mapping applied to the
82 /// construct. e.g. `acc.loop gang vector`, the `gang` and `vector` could be
83 /// combined and the final mapping value would be 5 (4 | 1).
84 enum OpenACCExecMapping { NONE = 0, VECTOR = 1, WORKER = 2, GANG = 4 };
85 
86 /// Used to obtain the `varPtr` from a data clause operation.
87 /// Returns empty value if not a data clause operation or is a data exit
88 /// operation with no `varPtr`.
89 mlir::Value getVarPtr(mlir::Operation *accDataClauseOp);
90 
91 /// Used to obtain the `accPtr` from a data clause operation.
92 /// When a data entry operation, it obtains its result `accPtr` value.
93 /// If a data exit operation, it obtains its operand `accPtr` value.
94 /// Returns empty value if not a data clause operation.
95 mlir::Value getAccPtr(mlir::Operation *accDataClauseOp);
96 
97 /// Used to obtain the `varPtrPtr` from a data clause operation.
98 /// Returns empty value if not a data clause operation.
99 mlir::Value getVarPtrPtr(mlir::Operation *accDataClauseOp);
100 
101 /// Used to obtain `bounds` from an acc data clause operation.
102 /// Returns an empty vector if there are no bounds.
104 
105 /// Used to obtain `async` operands from an acc data clause operation.
106 /// Returns an empty vector if there are no such operands.
108 getAsyncOperands(mlir::Operation *accDataClauseOp);
109 
110 /// Returns an array of acc:DeviceTypeAttr attributes attached to
111 /// an acc data clause operation, that correspond to the device types
112 /// associated with the async clauses with an async-value.
113 mlir::ArrayAttr getAsyncOperandsDeviceType(mlir::Operation *accDataClauseOp);
114 
115 /// Returns an array of acc:DeviceTypeAttr attributes attached to
116 /// an acc data clause operation, that correspond to the device types
117 /// associated with the async clauses without an async-value.
118 mlir::ArrayAttr getAsyncOnly(mlir::Operation *accDataClauseOp);
119 
120 /// Used to obtain the `name` from an acc operation.
121 std::optional<llvm::StringRef> getVarName(mlir::Operation *accOp);
122 
123 /// Used to obtain the `dataClause` from a data entry operation.
124 /// Returns empty optional if not a data entry operation.
125 std::optional<mlir::acc::DataClause>
126 getDataClause(mlir::Operation *accDataEntryOp);
127 
128 /// Used to find out whether data operation is implicit.
129 /// Returns false if not a data operation or if it is a data operation without
130 /// implicit flag.
131 bool getImplicitFlag(mlir::Operation *accDataEntryOp);
132 
133 /// Used to get an immutable range iterating over the data operands.
135 
136 /// Used to get a mutable range iterating over the data operands.
138 
139 /// Used to obtain the attribute name for declare.
140 static constexpr StringLiteral getDeclareAttrName() {
141  return StringLiteral("acc.declare");
142 }
143 
144 static constexpr StringLiteral getDeclareActionAttrName() {
145  return StringLiteral("acc.declare_action");
146 }
147 
148 static constexpr StringLiteral getRoutineInfoAttrName() {
149  return StringLiteral("acc.routine_info");
150 }
151 
152 static constexpr StringLiteral getCombinedConstructsAttrName() {
153  return CombinedConstructsTypeAttr::name;
154 }
155 
157  : public mlir::SideEffects::Resource::Base<RuntimeCounters> {
158  mlir::StringRef getName() final { return "AccRuntimeCounters"; }
159 };
160 
162  : public mlir::SideEffects::Resource::Base<ConstructResource> {
163  mlir::StringRef getName() final { return "AccConstructResource"; }
164 };
165 
167  : public mlir::SideEffects::Resource::Base<CurrentDeviceIdResource> {
168  mlir::StringRef getName() final { return "AccCurrentDeviceIdResource"; }
169 };
170 
171 } // namespace acc
172 } // namespace mlir
173 
174 #endif // MLIR_DIALECT_OPENACC_OPENACC_H_
This class provides a mutable adaptor for a range of operands.
Definition: ValueRange.h:115
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
This base class is used for derived effects that are non-parametric.
This class provides an abstraction over the different types of ranges over Values.
Definition: ValueRange.h:381
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition: Value.h:96
mlir::Value getVarPtr(mlir::Operation *accDataClauseOp)
Used to obtain the varPtr from a data clause operation.
Definition: OpenACC.cpp:2876
std::optional< mlir::acc::DataClause > getDataClause(mlir::Operation *accDataEntryOp)
Used to obtain the dataClause from a data entry operation.
Definition: OpenACC.cpp:2959
mlir::MutableOperandRange getMutableDataOperands(mlir::Operation *accOp)
Used to get a mutable range iterating over the data operands.
Definition: OpenACC.cpp:2987
mlir::SmallVector< mlir::Value > getBounds(mlir::Operation *accDataClauseOp)
Used to obtain bounds from an acc data clause operation.
Definition: OpenACC.cpp:2904
OpenACCExecMapping
Enumeration used to encode the execution mapping on a loop construct.
Definition: OpenACC.h:84
@ WORKER
Definition: OpenACC.h:84
@ NONE
Definition: OpenACC.h:84
@ GANG
Definition: OpenACC.h:84
@ VECTOR
Definition: OpenACC.h:84
mlir::ValueRange getDataOperands(mlir::Operation *accOp)
Used to get an immutable range iterating over the data operands.
Definition: OpenACC.cpp:2977
std::optional< llvm::StringRef > getVarName(mlir::Operation *accOp)
Used to obtain the name from an acc operation.
Definition: OpenACC.cpp:2948
static constexpr StringLiteral getRoutineInfoAttrName()
Definition: OpenACC.h:148
bool getImplicitFlag(mlir::Operation *accDataEntryOp)
Used to find out whether data operation is implicit.
Definition: OpenACC.cpp:2969
mlir::SmallVector< mlir::Value > getAsyncOperands(mlir::Operation *accDataClauseOp)
Used to obtain async operands from an acc data clause operation.
Definition: OpenACC.cpp:2919
static constexpr StringLiteral getCombinedConstructsAttrName()
Definition: OpenACC.h:152
mlir::Value getVarPtrPtr(mlir::Operation *accDataClauseOp)
Used to obtain the varPtrPtr from a data clause operation.
Definition: OpenACC.cpp:2894
mlir::Value getAccPtr(mlir::Operation *accDataClauseOp)
Used to obtain the accPtr from a data clause operation.
Definition: OpenACC.cpp:2886
mlir::ArrayAttr getAsyncOnly(mlir::Operation *accDataClauseOp)
Returns an array of acc:DeviceTypeAttr attributes attached to an acc data clause operation,...
Definition: OpenACC.cpp:2941
static constexpr StringLiteral getDeclareAttrName()
Used to obtain the attribute name for declare.
Definition: OpenACC.h:140
static constexpr StringLiteral getDeclareActionAttrName()
Definition: OpenACC.h:144
mlir::ArrayAttr getAsyncOperandsDeviceType(mlir::Operation *accDataClauseOp)
Returns an array of acc:DeviceTypeAttr attributes attached to an acc data clause operation,...
Definition: OpenACC.cpp:2933
Include the generated interface declarations.
mlir::StringRef getName() final
Return a string name of the resource.
Definition: OpenACC.h:163
mlir::StringRef getName() final
Return a string name of the resource.
Definition: OpenACC.h:168
mlir::StringRef getName() final
Return a string name of the resource.
Definition: OpenACC.h:158