MLIR 24.0.0git
VectorToGPUUtils.h
Go to the documentation of this file.
1//===- VectorToGPUUtils.h - Shared vector-to-MMA helpers -------*- 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#ifndef MLIR_CONVERSION_VECTORTOGPUCOMMON_VECTORTOGPUUTILS_H
10#define MLIR_CONVERSION_VECTORTOGPUCOMMON_VECTORTOGPUUTILS_H
11
12#include "mlir/IR/Value.h"
14#include "llvm/ADT/DenseMap.h"
15#include <cstdint>
16#include <optional>
17
18namespace mlir {
19class Operation;
20class RewriterBase;
22
23namespace arith {
24class ConstantOp;
25class ExtSIOp;
26class ExtUIOp;
27} // namespace arith
28
29namespace gpu {
30enum class MMAElementwiseOp : uint32_t;
31} // namespace gpu
32
33namespace scf {
34class ForOp;
35class YieldOp;
36} // namespace scf
37
38namespace vector {
39class BroadcastOp;
40} // namespace vector
41
42/// Return true if the constant is a splat to a 2D vector so that it can be
43/// converted to an MMA constant matrix op.
44bool constantSupportsMMAMatrixType(arith::ConstantOp constantOp);
45
46/// Return true if this is a broadcast from scalar to a 2D vector.
47bool broadcastSupportsMMAMatrixType(vector::BroadcastOp broadcastOp);
48
49/// Return true if this integer extend op can be folded into a contract op.
50/// The operation must be arith.extsi or arith.extui.
51template <typename ExtOpTy>
52bool integerExtendSupportsMMAMatrixType(ExtOpTy extOp);
53
54extern template bool
56
57extern template bool
59
60/// Return the MMA elementwise enum associated with the operation if supported.
61/// Return std::nullopt otherwise.
62std::optional<gpu::MMAElementwiseOp> convertElementwiseOpToMMA(Operation *op);
63
64/// Return true if the operation is supported as elementwise on an MMA matrix.
66
67/// Extend loop-carried values with their converted counterparts.
68LogicalResult convertForOpForMMA(RewriterBase &rewriter, scf::ForOp op,
69 llvm::DenseMap<Value, Value> &valueMapping);
70
71/// Update a yield operation to yield the converted values.
72LogicalResult convertYieldOpForMMA(RewriterBase &rewriter, scf::YieldOp op,
73 llvm::DenseMap<Value, Value> &valueMapping);
74
75/// Populate patterns that fold vector.transpose into vector.transfer_read,
76/// including through arithmetic extension operations.
78} // namespace mlir
79
80#endif // MLIR_CONVERSION_VECTORTOGPUCOMMON_VECTORTOGPUUTILS_H
Operation is the basic unit of execution within MLIR.
Definition Operation.h:87
This class coordinates the application of a rewrite on a set of IR, providing a way for clients to tr...
Include the generated interface declarations.
LogicalResult convertYieldOpForMMA(RewriterBase &rewriter, scf::YieldOp op, llvm::DenseMap< Value, Value > &valueMapping)
Update a yield operation to yield the converted values.
bool broadcastSupportsMMAMatrixType(vector::BroadcastOp broadcastOp)
Return true if this is a broadcast from scalar to a 2D vector.
bool elementwiseSupportsMMAMatrixType(Operation *op)
Return true if the operation is supported as elementwise on an MMA matrix.
LogicalResult convertForOpForMMA(RewriterBase &rewriter, scf::ForOp op, llvm::DenseMap< Value, Value > &valueMapping)
Extend loop-carried values with their converted counterparts.
std::optional< gpu::MMAElementwiseOp > convertElementwiseOpToMMA(Operation *op)
Return the MMA elementwise enum associated with the operation if supported.
bool constantSupportsMMAMatrixType(arith::ConstantOp constantOp)
Return true if the constant is a splat to a 2D vector so that it can be converted to an MMA constant ...
void populateVectorTransferReadTransposePatterns(RewritePatternSet &patterns)
Populate patterns that fold vector.transpose into vector.transfer_read, including through arithmetic ...
template bool integerExtendSupportsMMAMatrixType< arith::ExtSIOp >(arith::ExtSIOp)
bool integerExtendSupportsMMAMatrixType(ExtOpTy extOp)
Return true if this integer extend op can be folded into a contract op.
template bool integerExtendSupportsMMAMatrixType< arith::ExtUIOp >(arith::ExtUIOp)