MLIR 23.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
17#include "mlir/IR/Dialect.h"
20#include "mlir/IR/SymbolTable.h"
21
24#include "mlir/Dialect/OpenACC/OpenACCOpsDialect.h.inc"
25#include "mlir/Dialect/OpenACC/OpenACCOpsEnums.h.inc"
26#include "mlir/Dialect/OpenACC/OpenACCOpsInterfaces.h.inc"
27#include "mlir/Dialect/OpenACC/OpenACCTypeInterfaces.h.inc"
29#include "mlir/IR/Value.h"
33#include <variant>
34
35#define GET_TYPEDEF_CLASSES
36#include "mlir/Dialect/OpenACC/OpenACCOpsTypes.h.inc"
37
38#define GET_ATTRDEF_CLASSES
39#include "mlir/Dialect/OpenACC/OpenACCOpsAttributes.h.inc"
40
42
43#define GET_OP_CLASSES
44#include "mlir/Dialect/OpenACC/OpenACCOps.h.inc"
45
46#define ACC_DATA_ENTRY_OPS \
47 mlir::acc::CopyinOp, mlir::acc::CreateOp, mlir::acc::PresentOp, \
48 mlir::acc::NoCreateOp, mlir::acc::AttachOp, mlir::acc::DevicePtrOp, \
49 mlir::acc::GetDevicePtrOp, mlir::acc::PrivateOp, \
50 mlir::acc::FirstprivateOp, mlir::acc::FirstprivateMapInitialOp, \
51 mlir::acc::UpdateDeviceOp, mlir::acc::UseDeviceOp, \
52 mlir::acc::ReductionOp, mlir::acc::DeclareDeviceResidentOp, \
53 mlir::acc::DeclareLinkOp, mlir::acc::CacheOp
54#define ACC_DATA_EXIT_OPS \
55 mlir::acc::CopyoutOp, mlir::acc::DeleteOp, mlir::acc::DetachOp, \
56 mlir::acc::UpdateHostOp
57#define ACC_DATA_CLAUSE_OPS ACC_DATA_ENTRY_OPS, ACC_DATA_EXIT_OPS
58#define ACC_COMPUTE_CONSTRUCT_OPS \
59 mlir::acc::ParallelOp, mlir::acc::KernelsOp, mlir::acc::SerialOp
60#define ACC_COMPUTE_CONSTRUCT_AND_LOOP_OPS \
61 ACC_COMPUTE_CONSTRUCT_OPS, mlir::acc::LoopOp
62#define ACC_DATA_CONSTRUCT_STRUCTURED_OPS \
63 mlir::acc::DataOp, mlir::acc::DeclareOp, mlir::acc::HostDataOp
64#define ACC_DATA_CONSTRUCT_UNSTRUCTURED_OPS \
65 mlir::acc::EnterDataOp, mlir::acc::ExitDataOp, mlir::acc::UpdateOp, \
66 mlir::acc::DeclareEnterOp, mlir::acc::DeclareExitOp
67#define ACC_DATA_CONSTRUCT_OPS \
68 ACC_DATA_CONSTRUCT_STRUCTURED_OPS, ACC_DATA_CONSTRUCT_UNSTRUCTURED_OPS
69#define ACC_COMPUTE_AND_DATA_CONSTRUCT_OPS \
70 ACC_COMPUTE_CONSTRUCT_OPS, ACC_DATA_CONSTRUCT_OPS
71#define ACC_COMPUTE_LOOP_AND_DATA_CONSTRUCT_OPS \
72 ACC_COMPUTE_CONSTRUCT_AND_LOOP_OPS, ACC_DATA_CONSTRUCT_OPS
73
74namespace mlir {
75namespace acc {
76
77/// Enumeration used to encode the execution mapping on a loop construct.
78/// They refer directly to the OpenACC 3.3 standard:
79/// 2.9.2. gang
80/// 2.9.3. worker
81/// 2.9.4. vector
82///
83/// Value can be combined bitwise to reflect the mapping applied to the
84/// construct. e.g. `acc.loop gang vector`, the `gang` and `vector` could be
85/// combined and the final mapping value would be 5 (4 | 1).
86enum OpenACCExecMapping { NONE = 0, VECTOR = 1, WORKER = 2, GANG = 4 };
87
88/// Used to obtain the `var` from a data clause operation.
89/// Returns empty value if not a data clause operation or is a data exit
90/// operation with no `var`.
91mlir::Value getVar(mlir::Operation *accDataClauseOp);
92
93/// Used to obtain the `var` from a data clause operation if it implements
94/// `PointerLikeType`.
96getVarPtr(mlir::Operation *accDataClauseOp);
97
98/// Used to obtains the `varType` from a data clause operation which records
99/// the type of variable. When `var` is `PointerLikeType`, this returns
100/// the type of the pointer target.
101mlir::Type getVarType(mlir::Operation *accDataClauseOp);
102
103/// Used to obtain the `accVar` from a data clause operation.
104/// When a data entry operation, it obtains its result `accVar` value.
105/// If a data exit operation, it obtains its operand `accVar` value.
106/// Returns empty value if not a data clause operation.
107mlir::Value getAccVar(mlir::Operation *accDataClauseOp);
108
109/// Used to obtain the `accVar` from a data clause operation if it implements
110/// `PointerLikeType`.
112getAccPtr(mlir::Operation *accDataClauseOp);
113
114/// Used to obtain the `varPtrPtr` from a data clause operation.
115/// Returns empty value if not a data clause operation.
117
118/// Used to obtain `bounds` from an acc data clause operation.
119/// Returns an empty vector if there are no bounds.
121
122/// Used to obtain `async` operands from an acc data clause operation.
123/// Returns an empty vector if there are no such operands.
125getAsyncOperands(mlir::Operation *accDataClauseOp);
126
127/// Returns an array of acc:DeviceTypeAttr attributes attached to
128/// an acc data clause operation, that correspond to the device types
129/// associated with the async clauses with an async-value.
130mlir::ArrayAttr getAsyncOperandsDeviceType(mlir::Operation *accDataClauseOp);
131
132/// Returns an array of acc:DeviceTypeAttr attributes attached to
133/// an acc data clause operation, that correspond to the device types
134/// associated with the async clauses without an async-value.
135mlir::ArrayAttr getAsyncOnly(mlir::Operation *accDataClauseOp);
136
137/// Used to obtain the `name` from an acc operation.
138std::optional<llvm::StringRef> getVarName(mlir::Operation *accOp);
139
140/// Used to obtain the `dataClause` from a data entry operation.
141/// Returns empty optional if not a data entry operation.
142std::optional<mlir::acc::DataClause>
143getDataClause(mlir::Operation *accDataEntryOp);
144
145/// Used to find out whether data operation is implicit.
146/// Returns false if not a data operation or if it is a data operation without
147/// implicit flag.
148bool getImplicitFlag(mlir::Operation *accDataEntryOp);
149
150/// Used to get an immutable range iterating over the data operands.
152
153/// Used to get a mutable range iterating over the data operands.
155
156/// Used to get the recipe attribute from a data clause operation.
157mlir::SymbolRefAttr getRecipe(mlir::Operation *accOp);
158
159/// Used to check whether the provided `type` implements the `PointerLikeType`
160/// interface.
161inline bool isPointerLikeType(mlir::Type type) {
162 return mlir::isa<mlir::acc::PointerLikeType>(type);
163}
164
165/// Used to check whether the provided `type` implements the `MappableType`
166/// interface.
167inline bool isMappableType(mlir::Type type) {
168 return mlir::isa<mlir::acc::MappableType>(type);
169}
170
171/// Used to obtain the attribute name for declare.
172static constexpr StringLiteral getDeclareAttrName() {
173 return StringLiteral("acc.declare");
174}
175
176static constexpr StringLiteral getDeclareActionAttrName() {
177 return StringLiteral("acc.declare_action");
178}
179
180static constexpr StringLiteral getRoutineInfoAttrName() {
181 return RoutineInfoAttr::name;
182}
183
184static constexpr StringLiteral getSpecializedRoutineAttrName() {
185 return SpecializedRoutineAttr::name;
186}
187
188/// Used to check whether the current operation is marked with
189/// `acc routine`. The operation passed in should be a function.
193
194/// Used to check whether this is a specialized accelerator version of
195/// `acc routine` function.
199
200static constexpr StringLiteral getFromDefaultClauseAttrName() {
201 return StringLiteral("acc.from_default");
202}
203
204static constexpr StringLiteral getVarNameAttrName() {
205 return VarNameAttr::name;
206}
207
208static constexpr StringLiteral getCombinedConstructsAttrName() {
209 return CombinedConstructsTypeAttr::name;
210}
211
213 : public mlir::SideEffects::Resource::Base<RuntimeCounters> {
214 mlir::StringRef getName() final { return "AccRuntimeCounters"; }
215};
216
218 : public mlir::SideEffects::Resource::Base<ConstructResource> {
219 mlir::StringRef getName() final { return "AccConstructResource"; }
220};
221
223 : public mlir::SideEffects::Resource::Base<CurrentDeviceIdResource> {
224 mlir::StringRef getName() final { return "AccCurrentDeviceIdResource"; }
225};
226
227} // namespace acc
228} // namespace mlir
229
230#endif // MLIR_DIALECT_OPENACC_OPENACC_H_
This class provides a mutable adaptor for a range of operands.
Definition ValueRange.h:118
Operation is the basic unit of execution within MLIR.
Definition Operation.h:88
bool hasAttr(StringAttr name)
Return true if the operation has an attribute with the provided name, false otherwise.
Definition Operation.h:560
This base class is used for derived effects that are non-parametric.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
This class provides an abstraction over the different types of ranges over Values.
Definition ValueRange.h:387
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition Value.h:96
static constexpr StringLiteral getFromDefaultClauseAttrName()
Definition OpenACC.h:200
mlir::Value getAccVar(mlir::Operation *accDataClauseOp)
Used to obtain the accVar from a data clause operation.
Definition OpenACC.cpp:4927
mlir::Value getVar(mlir::Operation *accDataClauseOp)
Used to obtain the var from a data clause operation.
Definition OpenACC.cpp:4896
bool isAccRoutine(mlir::Operation *op)
Used to check whether the current operation is marked with acc routine.
Definition OpenACC.h:190
mlir::TypedValue< mlir::acc::PointerLikeType > getAccPtr(mlir::Operation *accDataClauseOp)
Used to obtain the accVar from a data clause operation if it implements PointerLikeType.
Definition OpenACC.cpp:4915
static constexpr StringLiteral getSpecializedRoutineAttrName()
Definition OpenACC.h:184
std::optional< mlir::acc::DataClause > getDataClause(mlir::Operation *accDataEntryOp)
Used to obtain the dataClause from a data entry operation.
Definition OpenACC.cpp:5000
bool isPointerLikeType(mlir::Type type)
Used to check whether the provided type implements the PointerLikeType interface.
Definition OpenACC.h:161
mlir::MutableOperandRange getMutableDataOperands(mlir::Operation *accOp)
Used to get a mutable range iterating over the data operands.
Definition OpenACC.cpp:5028
mlir::SmallVector< mlir::Value > getBounds(mlir::Operation *accDataClauseOp)
Used to obtain bounds from an acc data clause operation.
Definition OpenACC.cpp:4945
OpenACCExecMapping
Enumeration used to encode the execution mapping on a loop construct.
Definition OpenACC.h:86
bool isSpecializedAccRoutine(mlir::Operation *op)
Used to check whether this is a specialized accelerator version of acc routine function.
Definition OpenACC.h:196
mlir::ValueRange getDataOperands(mlir::Operation *accOp)
Used to get an immutable range iterating over the data operands.
Definition OpenACC.cpp:5018
std::optional< llvm::StringRef > getVarName(mlir::Operation *accOp)
Used to obtain the name from an acc operation.
Definition OpenACC.cpp:4989
static constexpr StringLiteral getRoutineInfoAttrName()
Definition OpenACC.h:180
bool getImplicitFlag(mlir::Operation *accDataEntryOp)
Used to find out whether data operation is implicit.
Definition OpenACC.cpp:5010
mlir::SymbolRefAttr getRecipe(mlir::Operation *accOp)
Used to get the recipe attribute from a data clause operation.
Definition OpenACC.cpp:5037
mlir::SmallVector< mlir::Value > getAsyncOperands(mlir::Operation *accDataClauseOp)
Used to obtain async operands from an acc data clause operation.
Definition OpenACC.cpp:4960
bool isMappableType(mlir::Type type)
Used to check whether the provided type implements the MappableType interface.
Definition OpenACC.h:167
static constexpr StringLiteral getCombinedConstructsAttrName()
Definition OpenACC.h:208
mlir::Value getVarPtrPtr(mlir::Operation *accDataClauseOp)
Used to obtain the varPtrPtr from a data clause operation.
Definition OpenACC.cpp:4935
static constexpr StringLiteral getVarNameAttrName()
Definition OpenACC.h:204
mlir::ArrayAttr getAsyncOnly(mlir::Operation *accDataClauseOp)
Returns an array of acc:DeviceTypeAttr attributes attached to an acc data clause operation,...
Definition OpenACC.cpp:4982
static constexpr StringLiteral getDeclareAttrName()
Used to obtain the attribute name for declare.
Definition OpenACC.h:172
static constexpr StringLiteral getDeclareActionAttrName()
Definition OpenACC.h:176
mlir::Type getVarType(mlir::Operation *accDataClauseOp)
Used to obtains the varType from a data clause operation which records the type of variable.
Definition OpenACC.cpp:4904
mlir::TypedValue< mlir::acc::PointerLikeType > getVarPtr(mlir::Operation *accDataClauseOp)
Used to obtain the var from a data clause operation if it implements PointerLikeType.
Definition OpenACC.cpp:4882
mlir::ArrayAttr getAsyncOperandsDeviceType(mlir::Operation *accDataClauseOp)
Returns an array of acc:DeviceTypeAttr attributes attached to an acc data clause operation,...
Definition OpenACC.cpp:4974
Include the generated interface declarations.
std::conditional_t< std::is_same_v< Ty, mlir::Type >, mlir::Value, detail::TypedValue< Ty > > TypedValue
If Ty is mlir::Type this will select Value instead of having a wrapper around it.
Definition Value.h:497
mlir::StringRef getName() final
Return a string name of the resource.
Definition OpenACC.h:219
mlir::StringRef getName() final
Return a string name of the resource.
Definition OpenACC.h:224
mlir::StringRef getName() final
Return a string name of the resource.
Definition OpenACC.h:214