MLIR 24.0.0git
GPUUtils.h
Go to the documentation of this file.
1//===- Passes.h - Pass Entrypoints ------------------------------*- 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 header file defines utility functions exposed by the GPU dialect
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef MLIR_DIALECT_GPU_TRANSFORMS_UTILS_H_
14#define MLIR_DIALECT_GPU_TRANSFORMS_UTILS_H_
15
18#include "mlir/Support/LLVM.h"
19
20#include <string>
21
22namespace mlir {
23class Operation;
24class Value;
25
26namespace gpu {
27class GPUFuncOp;
28class LaunchOp;
29
30/// Returns the matching vector combining kind.
31vector::CombiningKind convertReductionKind(gpu::AllReduceOperation mode);
32
33/// Lane layout of the clusters reduced by a `gpu.subgroup_reduce` op.
39
40/// Returns the cluster layout of `op` in a subgroup of `subgroupSize` lanes,
41/// which must be a power of two. Emits an op error and fails if the cluster
42/// size exceeds the subgroup size or the cluster stride is not less than it.
43FailureOr<SubgroupReduceClusterInfo>
44getSubgroupReduceClusterInfo(SubgroupReduceOp op, unsigned subgroupSize);
45} // namespace gpu
46
47/// Get a gpu.func created from outlining the region of a gpu.launch op with the
48/// given `kernelFnName`. The region of the `launchOp` can use values from
49/// above. These need to be captured and passed as arguments to the generated
50/// gpu.func. The generated function has arguments
51/// - corresponding to the values passed in as `operands`, in that order.
52/// - any additional values that might be used within the region of the
53/// `launchOp` and defined above it. These captured values are appended to the
54/// `operands` list.
55gpu::GPUFuncOp outlineKernelFunc(gpu::LaunchOp launchOp, StringRef kernelFnName,
56 SmallVectorImpl<Value> &operands);
57
58/// Sink operations into the `launchOp` to reduce the number of values that are
59/// used within the region of the operation, but defined outside of the
60/// region.
61LogicalResult sinkOperationsIntoLaunchOp(
62 gpu::LaunchOp launchOp,
63 llvm::function_ref<bool(Operation *)> isSinkingBeneficiary);
64
65} // namespace mlir
66#endif // MLIR_DIALECT_GPU_TRANSFORMS_UTILS_H_
Operation is the basic unit of execution within MLIR.
Definition Operation.h:87
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition Value.h:96
FailureOr< SubgroupReduceClusterInfo > getSubgroupReduceClusterInfo(SubgroupReduceOp op, unsigned subgroupSize)
Returns the cluster layout of op in a subgroup of subgroupSize lanes, which must be a power of two.
Definition Utils.cpp:48
vector::CombiningKind convertReductionKind(gpu::AllReduceOperation mode)
Returns the matching vector combining kind.
Definition Utils.cpp:19
Include the generated interface declarations.
LogicalResult sinkOperationsIntoLaunchOp(gpu::LaunchOp launchOp, llvm::function_ref< bool(Operation *)> isSinkingBeneficiary)
Sink operations into the launchOp to reduce the number of values that are used within the region of t...
gpu::GPUFuncOp outlineKernelFunc(gpu::LaunchOp launchOp, StringRef kernelFnName, SmallVectorImpl< Value > &operands)
Get a gpu.func created from outlining the region of a gpu.launch op with the given kernelFnName.
Lane layout of the clusters reduced by a gpu.subgroup_reduce op.
Definition GPUUtils.h:34