MLIR 23.0.0git
OpenACCUtilsReduction.h
Go to the documentation of this file.
1//===- OpenACCUtilsReduction.h - OpenACC reduction utilities ----*- 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// This file defines utility functions for OpenACC reductions.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef MLIR_DIALECT_OPENACC_OPENACCUTILSREDUCTION_H_
14#define MLIR_DIALECT_OPENACC_OPENACCUTILSREDUCTION_H_
15
19#include "mlir/IR/Builders.h"
20#include "mlir/IR/Value.h"
21#include "llvm/ADT/SmallVector.h"
22
23#include <optional>
24
25namespace mlir {
26namespace acc {
27
28/// Returns the parallel dimensions that participate in \p op's combine step.
29///
30/// Used when lowering reductions to determine which GPU parallelism levels must
31/// be synchronized before combining partial results.
32SmallVector<GPUParallelDimAttr>
33getReductionCombineParDims(ReductionCombineOp op);
34
35/// Returns the parallel dimensions that participate in \p op's combine step.
36///
37/// Prefers dimensions from an `acc.reduction_accumulate` user of the source
38/// variable; otherwise falls back to \p op's `acc.par_dims` attribute.
39SmallVector<GPUParallelDimAttr>
40getReductionCombineParDims(ReductionCombineRegionOp op);
41
42/// Maps an `arith` atomic RMW kind to the corresponding acc reduction operator.
43ReductionOperator translateAtomicRMWKind(arith::AtomicRMWKind kind);
44
45/// Maps an acc reduction operator to the `arith` atomic RMW kind for \p type.
46///
47/// Returns `std::nullopt` when \p redOp is not supported for \p type.
48std::optional<arith::AtomicRMWKind>
49translateACCReductionOperator(ReductionOperator redOp, Type type);
50
51/// Creates the identity (neutral) value for a reduction of \p type and \p kind.
52///
53/// When \p useOnlyFiniteValue is true, floating-point identities avoid
54/// non-finite sentinel values where applicable.
55Value createIdentityValue(OpBuilder &b, Location loc, Type type,
56 arith::AtomicRMWKind kind,
57 bool useOnlyFiniteValue = true);
58
59/// Combines two reduction partial values using the operator for \p kind.
60Value generateReductionOp(OpBuilder &b, Location loc, Value lhs, Value rhs,
61 arith::AtomicRMWKind kind);
62
63} // namespace acc
64} // namespace mlir
65
66#endif // MLIR_DIALECT_OPENACC_OPENACCUTILSREDUCTION_H_
lhs
b
Return true if permutation is a valid permutation of the outer_dims_perm (case OuterOrInnerPerm::Oute...
SmallVector< GPUParallelDimAttr > getReductionCombineParDims(ReductionCombineOp op)
Returns the parallel dimensions that participate in op's combine step.
std::optional< arith::AtomicRMWKind > translateACCReductionOperator(ReductionOperator redOp, Type type)
Maps an acc reduction operator to the arith atomic RMW kind for type.
ReductionOperator translateAtomicRMWKind(arith::AtomicRMWKind kind)
Maps an arith atomic RMW kind to the corresponding acc reduction operator.
Value createIdentityValue(OpBuilder &b, Location loc, Type type, arith::AtomicRMWKind kind, bool useOnlyFiniteValue=true)
Creates the identity (neutral) value for a reduction of type and kind.
Value generateReductionOp(OpBuilder &b, Location loc, Value lhs, Value rhs, arith::AtomicRMWKind kind)
Combines two reduction partial values using the operator for kind.
Include the generated interface declarations.