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};
90
91/// What a data runtime call is asked for besides mapping its operands.
94 /// Region flags, in the encoding of `ACCDataRegionFlags`.
96 /// Mapping operands whose device address the entry point returns.
98};
99
100/// The values that describe one object to the runtime, one for each argument
101/// array.
110
111/// Materialize \p values as a stack-allocated LLVM array.
112Value createACCDataArray(Location loc, Type elementType, ArrayRef<Value> values,
113 RewriterBase &rewriter);
114
115/// Materialize the argument arrays of \p objects into the `argNum` through
116/// `argDescs` fields of \p runtimeArgs. An `argNum` the caller already set is
117/// kept, so the count can be emitted before the object values.
120 ACCDataRuntimeArgs &runtimeArgs,
121 RewriterBase &rewriter);
122
123/// The address of \p operand as the runtime expects to receive it, given its
124/// type converted value \p converted and its \p mapFlags.
126 acc::MapFlags mapFlags,
127 ConversionPatternRewriter &rewriter);
128
129/// The host pointer slot the object \p mapOp maps is attached to, or a null
130/// pointer when it is not attached. \p mapOp may be null.
132 acc::MapFlags mapFlags,
133 ConversionPatternRewriter &rewriter);
134
135/// The size in bytes of \p operand, or zero where its descriptor or bounds
136/// state the extent instead. Fails, after reporting it, when \p operand is
137/// passed by value and the size of what is passed is not known.
138FailureOr<Value> createACCMappedObjectSize(Location loc, Value operand,
139 Value converted,
140 acc::MapFlags mapFlags,
141 acc::OpenACCSupport &accSupport,
142 ConversionPatternRewriter &rewriter);
143
144/// The name of \p operand for runtime diagnostics, or a null pointer when it
145/// has none. The name global is created as in acc::getOrCreateGlobalString.
147 acc::OpenACCSupport &accSupport,
148 Region &globalSymbolRegion,
149 SymbolTable *symbolTable,
150 ConversionPatternRewriter &rewriter);
151
152/// Wrap \p baseDescriptor in the OpenACC overlay that carries \p bounds.
153/// Field zero of \p baseDescriptor is set to \p version with the OpenACC
154/// descriptor bit added.
155Value createACCDataDescriptor(Location loc, Value baseDescriptor,
156 Type baseDescriptorType, uint32_t version,
157 ValueRange bounds, Value elementSize,
158 ConversionPatternRewriter &rewriter);
159
160/// Build the runtime argument descriptor wrapping an already converted memref.
161/// The memref descriptor itself is the one the memref-to-LLVM conversion
162/// produced; this points the runtime at it. When \p bounds is non-empty, the
163/// wrapper is nested in the OpenACC overlay that carries those bounds instead
164/// of being stored on its own.
165Value createACCMemRefDescriptorWrapperArg(Location loc, MemRefType memrefType,
166 Value convertedMemref,
167 ValueRange bounds, Value elementSize,
168 ConversionPatternRewriter &rewriter);
169
170/// Build the runtime argument descriptor for \p mapOp, or a null pointer when
171/// the mapping needs no descriptor.
172Value createACCArgumentDescriptor(Operation *mapOp, Value convertedOperand,
173 acc::OpenACCSupport &accSupport,
174 ConversionPatternRewriter &rewriter);
175
176/// Emit the OpenACC data runtime arguments for data-clause operands. The
177/// operands may be `acc.map_info` or the data-clause operations it replaces.
178/// The emitted arrays name globals after the mapped objects and the position
179/// of the directive; they are created in \p globalSymbolRegion, with \p
180/// symbolTable as in acc::getOrCreateGlobalString. \p options gives the region
181/// flags and the kind of call. Each of `options.returnAddressOperands` has
182/// `acc::MapFlags::return_param` set, and its slot is recorded in
183/// `returnAddressSlots`.
184LogicalResult emitACCDataRuntimeArgs(
185 Location loc, ValueRange mappingOperands, ValueRange convertedOperands,
186 ConversionPatternRewriter &rewriter, Region &globalSymbolRegion,
187 acc::OpenACCSupport &accSupport, const acc::ACCRuntimeCallConfig &config,
188 ACCDataRuntimeArgs &runtimeArgs, const ACCDataCallOptions &options = {},
189 SymbolTable *symbolTable = nullptr);
190
191/// Emit the call to the mapping entry point \p fn for \p mappingOperands,
192/// followed by \p trailingArguments. Emits nothing when there is no operand.
193/// Returns the device address of each of `options.returnAddressOperands`.
194FailureOr<SmallVector<Value>> emitACCDataRuntimeCall(
195 Location loc, acc::RuntimeFunction fn, ValueRange mappingOperands,
196 ValueRange convertedOperands, ConversionPatternRewriter &rewriter,
197 acc::OpenACCSupport &accSupport, Region &globalSymbolRegion,
198 SymbolTable &symbolTable, const acc::ACCRuntimeCallConfig &config,
199 ArrayRef<Value> trailingArguments, const ACCDataCallOptions &options = {});
200} // namespace mlir
201
202#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:389
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.
@ 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.