MLIR 24.0.0git
ACCDataRuntime.h
Go to the documentation of this file.
1//===- ACCDataRuntime.h - OpenACC data runtime arguments --------*- C++ -*-===//
2//
3// Part of the LLVM 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// Arguments and descriptors the OpenACC data runtime entry points are called
10// with. A conversion that lowers its own construct to those entry points emits
11// them with these, rather than restating the argument layout.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef MLIR_CONVERSION_OPENACCTOLLVM_ACCDATARUNTIME_H
16#define MLIR_CONVERSION_OPENACCTOLLVM_ACCDATARUNTIME_H
17
19#include "mlir/IR/Value.h"
20#include "llvm/ADT/SmallVector.h"
21
22#include <cstdint>
23
24namespace mlir {
25class MemRefType;
26class Operation;
27class ConversionPatternRewriter;
28class RewriterBase;
29class Region;
30class SymbolTable;
31
32namespace acc {
33class OpenACCSupport;
34} // namespace acc
35
36/// The arguments every mapping entry point of the OpenACC runtime takes, in the
37/// order they are passed. An entry point that maps `argNum` objects reads one
38/// element from each of the arrays below per object; an entry point may also
39/// take further arguments of its own, which are not part of this set.
41 /// Source position and enclosing function name of the directive.
43 /// Region flags, in the encoding of `ACCDataRegionFlags`.
45 /// Device type the directive applies to, in the runtime encoding.
47 /// Number of mapped objects, that is, the length of each array below.
49 /// Array of pointer slots to attach a mapped object to, null when the object
50 /// is not attached to anything.
52 /// Array of addresses of the mapped objects themselves.
54 /// Array of object sizes in bytes; zero where the descriptor or the bounds
55 /// state the extent instead.
57 /// Array of map-type flags, in the runtime encoding of `acc::MapFlags`.
59 /// Array of variable names for runtime diagnostics, null where unknown.
61 /// Array of user-defined mappers. OpenACC has none, so this is always null.
63 /// Array of descriptors stating layout and bounds, null for whole objects of
64 /// a known size.
66
67 /// The `argBasePtrs` slot the entry point writes the device address of each
68 /// requested operand into, in the order the operands were requested.
70
71 /// Returns the fields above in the order the entry points take them, so that
72 /// a caller only appends the arguments specific to the one it calls.
74};
75
76/// Identifies how data runtime arguments will be consumed.
81
82/// Flags of `__tgt_acc_data_begin` and `__tgt_acc_data_end`. They describe the
83/// data region.
85 /// An explicit data construct.
86 None = 0,
87 /// The implicit data region of a compute construct.
89 /// The region of a structured declare directive in a local scope, which
90 /// lasts until that scope ends.
92};
93
94/// What a data runtime call is asked for besides mapping its operands.
97 /// Region flags, in the encoding of `ACCDataRegionFlags`.
99 /// Mapping operands whose device address the entry point returns.
101};
102
103/// The values that describe one object to the runtime, one for each argument
104/// array.
113
114/// Materialize \p values as a stack-allocated LLVM array.
115Value createACCDataArray(Location loc, Type elementType, ArrayRef<Value> values,
116 RewriterBase &rewriter);
117
118/// Materialize the argument arrays of \p objects into the `argNum` through
119/// `argDescs` fields of \p runtimeArgs. An `argNum` the caller already set is
120/// kept, so the count can be emitted before the object values.
123 ACCDataRuntimeArgs &runtimeArgs,
124 RewriterBase &rewriter);
125
126/// The address of \p operand as the runtime expects to receive it, given its
127/// type converted value \p converted and its \p mapFlags.
129 acc::MapFlags mapFlags,
130 ConversionPatternRewriter &rewriter);
131
132/// The host pointer slot the object \p mapOp maps is attached to, or a null
133/// pointer when it is not attached. \p mapOp may be null.
135 acc::MapFlags mapFlags,
136 ConversionPatternRewriter &rewriter);
137
138/// The size in bytes of \p operand, or zero where its descriptor or bounds
139/// state the extent instead. Fails, after reporting it, when \p operand is
140/// passed by value and the size of what is passed is not known.
141FailureOr<Value> createACCMappedObjectSize(Location loc, Value operand,
142 Value converted,
143 acc::MapFlags mapFlags,
144 acc::OpenACCSupport &accSupport,
145 ConversionPatternRewriter &rewriter);
146
147/// The name of \p operand for runtime diagnostics, or a null pointer when it
148/// has none. The name global is created as in acc::getOrCreateGlobalString.
150 acc::OpenACCSupport &accSupport,
151 Region &globalSymbolRegion,
152 SymbolTable *symbolTable,
153 ConversionPatternRewriter &rewriter);
154
155/// Wrap \p baseDescriptor in the OpenACC overlay that carries \p bounds.
156/// Field zero of \p baseDescriptor is set to \p version with the OpenACC
157/// descriptor bit added.
158Value createACCDataDescriptor(Location loc, Value baseDescriptor,
159 Type baseDescriptorType, uint32_t version,
160 ValueRange bounds, Value elementSize,
161 ConversionPatternRewriter &rewriter);
162
163/// Build the runtime argument descriptor wrapping an already converted memref.
164/// The memref descriptor itself is the one the memref-to-LLVM conversion
165/// produced; this points the runtime at it. When \p bounds is non-empty, the
166/// wrapper is nested in the OpenACC overlay that carries those bounds instead
167/// of being stored on its own.
168Value createACCMemRefDescriptorWrapperArg(Location loc, MemRefType memrefType,
169 Value convertedMemref,
170 ValueRange bounds, Value elementSize,
171 ConversionPatternRewriter &rewriter);
172
173/// Build the runtime argument descriptor for \p mapOp, or a null pointer when
174/// the mapping needs no descriptor.
175Value createACCArgumentDescriptor(Operation *mapOp, Value convertedOperand,
176 acc::OpenACCSupport &accSupport,
177 ConversionPatternRewriter &rewriter);
178
179/// Emit the OpenACC data runtime arguments for data-clause operands. The
180/// operands may be `acc.map_info` or the data-clause operations it replaces.
181/// The emitted arrays name globals after the mapped objects and the position
182/// of the directive; they are created in \p globalSymbolRegion, with \p
183/// symbolTable as in acc::getOrCreateGlobalString. \p options gives the region
184/// flags and the kind of call. Each of `options.returnAddressOperands` has
185/// `acc::MapFlags::return_param` set, and its slot is recorded in
186/// `returnAddressSlots`.
187LogicalResult emitACCDataRuntimeArgs(
188 Location loc, ValueRange mappingOperands, ValueRange convertedOperands,
189 ConversionPatternRewriter &rewriter, Region &globalSymbolRegion,
190 acc::OpenACCSupport &accSupport, const acc::ACCRuntimeCallConfig &config,
191 ACCDataRuntimeArgs &runtimeArgs, const ACCDataCallOptions &options = {},
192 SymbolTable *symbolTable = nullptr);
193
194/// Emit the call to the mapping entry point \p fn for \p mappingOperands,
195/// followed by \p trailingArguments. Emits nothing when there is no operand.
196/// Returns the device address of each of `options.returnAddressOperands`.
197FailureOr<SmallVector<Value>> emitACCDataRuntimeCall(
198 Location loc, acc::RuntimeFunction fn, ValueRange mappingOperands,
199 ValueRange convertedOperands, ConversionPatternRewriter &rewriter,
200 acc::OpenACCSupport &accSupport, Region &globalSymbolRegion,
201 SymbolTable &symbolTable, const acc::ACCRuntimeCallConfig &config,
202 ArrayRef<Value> trailingArguments, const ACCDataCallOptions &options = {});
203} // namespace mlir
204
205#endif // MLIR_CONVERSION_OPENACCTOLLVM_ACCDATARUNTIME_H
static llvm::ManagedStatic< PassManagerOptions > options
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition Location.h:76
Operation is the basic unit of execution within MLIR.
Definition Operation.h:87
This class contains a list of basic blocks and a link to the parent operation it is attached to.
Definition Region.h:26
This class coordinates the application of a rewrite on a set of IR, providing a way for clients to tr...
This class allows for representing and managing the symbol table used by operations with the 'SymbolT...
Definition SymbolTable.h:25
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:392
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition Value.h:96
Configuration for OpenACC to LLVM runtime lowering.
RuntimeFunction
IDs for OpenACC compiler-to-runtime entry points (__tgt_acc_*).
Include the generated interface declarations.
Value createACCDataArray(Location loc, Type elementType, ArrayRef< Value > values, RewriterBase &rewriter)
Materialize values as a stack-allocated LLVM array.
Value createACCDataDescriptor(Location loc, Value baseDescriptor, Type baseDescriptorType, uint32_t version, ValueRange bounds, Value elementSize, ConversionPatternRewriter &rewriter)
Wrap baseDescriptor in the OpenACC overlay that carries bounds.
Value createACCMappedObjectName(Location loc, Value operand, acc::OpenACCSupport &accSupport, Region &globalSymbolRegion, SymbolTable *symbolTable, ConversionPatternRewriter &rewriter)
The name of operand for runtime diagnostics, or a null pointer when it has none.
void createACCMappedObjectArrays(Location loc, ArrayRef< ACCMappedObjectArgs > objects, ACCDataRuntimeArgs &runtimeArgs, RewriterBase &rewriter)
Materialize the argument arrays of objects into the argNum through argDescs fields of runtimeArgs.
LogicalResult emitACCDataRuntimeArgs(Location loc, ValueRange mappingOperands, ValueRange convertedOperands, ConversionPatternRewriter &rewriter, Region &globalSymbolRegion, acc::OpenACCSupport &accSupport, const acc::ACCRuntimeCallConfig &config, ACCDataRuntimeArgs &runtimeArgs, const ACCDataCallOptions &options={}, SymbolTable *symbolTable=nullptr)
Emit the OpenACC data runtime arguments for data-clause operands.
FailureOr< SmallVector< Value > > emitACCDataRuntimeCall(Location loc, acc::RuntimeFunction fn, ValueRange mappingOperands, ValueRange convertedOperands, ConversionPatternRewriter &rewriter, acc::OpenACCSupport &accSupport, Region &globalSymbolRegion, SymbolTable &symbolTable, const acc::ACCRuntimeCallConfig &config, ArrayRef< Value > trailingArguments, const ACCDataCallOptions &options={})
Emit the call to the mapping entry point fn for mappingOperands, followed by trailingArguments.
FailureOr< Value > createACCMappedObjectSize(Location loc, Value operand, Value converted, acc::MapFlags mapFlags, acc::OpenACCSupport &accSupport, ConversionPatternRewriter &rewriter)
The size in bytes of operand, or zero where its descriptor or bounds state the extent instead.
ACCDataCallKind
Identifies how data runtime arguments will be consumed.
Value createACCMappedObjectBase(Location loc, Operation *mapOp, acc::MapFlags mapFlags, ConversionPatternRewriter &rewriter)
The host pointer slot the object mapOp maps is attached to, or a null pointer when it is not attached...
Value createACCArgumentDescriptor(Operation *mapOp, Value convertedOperand, acc::OpenACCSupport &accSupport, ConversionPatternRewriter &rewriter)
Build the runtime argument descriptor for mapOp, or a null pointer when the mapping needs no descript...
Value createACCMappedObjectPointer(Location loc, Value operand, Value converted, acc::MapFlags mapFlags, ConversionPatternRewriter &rewriter)
The address of operand as the runtime expects to receive it, given its type converted value converted...
Value createACCMemRefDescriptorWrapperArg(Location loc, MemRefType memrefType, Value convertedMemref, ValueRange bounds, Value elementSize, ConversionPatternRewriter &rewriter)
Build the runtime argument descriptor wrapping an already converted memref.
ACCDataRegionFlags
Flags of __tgt_acc_data_begin and __tgt_acc_data_end.
@ Implicit
The implicit data region of a compute construct.
@ Declare
The region of a structured declare directive in a local scope, which lasts until that scope ends.
@ None
An explicit data construct.
What a data runtime call is asked for besides mapping its operands.
int64_t flags
Region flags, in the encoding of ACCDataRegionFlags.
ValueRange returnAddressOperands
Mapping operands whose device address the entry point returns.
The arguments every mapping entry point of the OpenACC runtime takes, in the order they are passed.
Value argNames
Array of variable names for runtime diagnostics, null where unknown.
Value deviceType
Device type the directive applies to, in the runtime encoding.
Value argSizes
Array of object sizes in bytes; zero where the descriptor or the bounds state the extent instead.
Value argMappers
Array of user-defined mappers. OpenACC has none, so this is always null.
Value ident
Source position and enclosing function name of the directive.
Value argTypes
Array of map-type flags, in the runtime encoding of acc::MapFlags.
SmallVector< Value > getCallArgs() const
Returns the fields above in the order the entry points take them, so that a caller only appends the a...
SmallVector< unsigned > returnAddressSlots
The argBasePtrs slot the entry point writes the device address of each requested operand into,...
Value argBasePtrs
Array of pointer slots to attach a mapped object to, null when the object is not attached to anything...
Value argNum
Number of mapped objects, that is, the length of each array below.
Value argDescs
Array of descriptors stating layout and bounds, null for whole objects of a known size.
Value flags
Region flags, in the encoding of ACCDataRegionFlags.
Value argPtrs
Array of addresses of the mapped objects themselves.
The values that describe one object to the runtime, one for each argument array.