MLIR 24.0.0git
DistributionUtils.h
Go to the documentation of this file.
1//===- DistributionUtils.h - Distribution 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#ifndef MLIR_DIALECT_GPU_TRANSFORMS_DISTRIBUTIONUTILS_H_
10#define MLIR_DIALECT_GPU_TRANSFORMS_DISTRIBUTIONUTILS_H_
11
15#include "mlir/IR/Value.h"
16
17namespace mlir::gpu {
18struct WarpDistributionPattern : OpRewritePattern<WarpExecuteOnLane0Op> {
21
22 virtual LogicalResult
23 matchAndRewrite(WarpExecuteOnLane0Op op,
24 PatternRewriter &rewriter) const override = 0;
25
26protected:
27 /// Return a value yielded by `warpOp` which statifies the filter lamdba
28 /// condition and is not dead.
29 OpOperand *getWarpResult(WarpExecuteOnLane0Op warpOp,
30 llvm::function_ref<bool(Operation *)> fn) const;
31
32 /// Helper to create a new WarpExecuteOnLane0Op with different signature.
33 WarpExecuteOnLane0Op moveRegionToNewWarpOpAndReplaceReturns(
34 RewriterBase &rewriter, WarpExecuteOnLane0Op warpOp,
35 ValueRange newYieldedValues, TypeRange newReturnTypes) const;
36
37 /// Helper to create a new WarpExecuteOnLane0Op region with extra outputs.
38 /// `indices` return the index of each new output.
39 WarpExecuteOnLane0Op moveRegionToNewWarpOpAndAppendReturns(
40 RewriterBase &rewriter, WarpExecuteOnLane0Op warpOp,
41 ValueRange newYieldedValues, TypeRange newReturnTypes,
43
44 /// Delinearize the given `laneId` into multiple dimensions, where each
45 /// dimension's size is determined by `originalShape` and `distributedShape`
46 /// together. This function expects the total numbers of threads needed for
47 /// distribution is equal to `warpSize`. Returns true and updates
48 /// `delinearizedIds` if so.
49 bool delinearizeLaneId(OpBuilder &builder, Location loc,
50 ArrayRef<int64_t> originalShape,
51 ArrayRef<int64_t> distributedShape, int64_t warpSize,
52 Value laneId,
53 SmallVectorImpl<Value> &delinearizedIds) const;
54};
55
56} // namespace mlir::gpu
57
58#endif // MLIR_DIALECT_GPU_TRANSFORMS_DISTRIBUTIONUTILS_H_
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition Location.h:76
This class helps build Operations.
Definition Builders.h:210
This class represents an operand of an operation.
Definition Value.h:254
Operation is the basic unit of execution within MLIR.
Definition Operation.h:87
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
This class coordinates the application of a rewrite on a set of IR, providing a way for clients to tr...
This class provides an abstraction over the various different ranges of value types.
Definition TypeRange.h:40
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
OpRewritePattern(MLIRContext *context, PatternBenefit benefit=1, ArrayRef< StringRef > generatedNames={})
Patterns must specify the root operation name they match against, and can also specify the benefit of...
WarpExecuteOnLane0Op moveRegionToNewWarpOpAndAppendReturns(RewriterBase &rewriter, WarpExecuteOnLane0Op warpOp, ValueRange newYieldedValues, TypeRange newReturnTypes, SmallVector< size_t > &indices) const
Helper to create a new WarpExecuteOnLane0Op region with extra outputs.
OpRewritePattern(MLIRContext *context, PatternBenefit benefit=1, ArrayRef< StringRef > generatedNames={})
Patterns must specify the root operation name they match against, and can also specify the benefit of...
bool delinearizeLaneId(OpBuilder &builder, Location loc, ArrayRef< int64_t > originalShape, ArrayRef< int64_t > distributedShape, int64_t warpSize, Value laneId, SmallVectorImpl< Value > &delinearizedIds) const
Delinearize the given laneId into multiple dimensions, where each dimension's size is determined by o...
WarpExecuteOnLane0Op moveRegionToNewWarpOpAndReplaceReturns(RewriterBase &rewriter, WarpExecuteOnLane0Op warpOp, ValueRange newYieldedValues, TypeRange newReturnTypes) const
Helper to create a new WarpExecuteOnLane0Op with different signature.
virtual LogicalResult matchAndRewrite(WarpExecuteOnLane0Op op, PatternRewriter &rewriter) const override=0
OpOperand * getWarpResult(WarpExecuteOnLane0Op warpOp, llvm::function_ref< bool(Operation *)> fn) const
Return a value yielded by warpOp which statifies the filter lamdba condition and is not dead.