MLIR 24.0.0git
Transforms.h
Go to the documentation of this file.
1//===- Transforms.h - NVGPU Dialect transformations --------------*- 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 declares functions that assist transformations for the nvgpu
10// dialect.
11//
12//===----------------------------------------------------------------------===//
13#ifndef MLIR_DIALECT_NVGPU_TRANSFORMS_TRANSFORMS_H_
14#define MLIR_DIALECT_NVGPU_TRANSFORMS_TRANSFORMS_H_
15
16#include "mlir/IR/Operation.h"
17
18namespace mlir {
19class MemRefType;
20class RewriterBase;
21
22namespace nvgpu {
23
24///
25/// Passes
26///
27
28/// Returns true if `optimizeSharedMemoryReadsAndWrites` can swizzle accesses to
29/// shared memory buffers of type `memRefType`. This does not guarantee that the
30/// memref will be swizzled, however: factors other than its type can prevent
31/// it, e.g., buffers with aliases are not swizzled.
32bool canSwizzleSharedMemoryType(MemRefType memRefType);
33
34/// Optimizes vectorized accesses to a shared memory buffer specified by
35/// memrefValue. This transformation assumes the following:
36/// 1) All relevant accesses to `memrefValue` are contained with `parentOp`.
37/// 2) The function will fail precondition checks if any subviews are
38/// taken of `memrefValue`. All reads/writes to `memrefValue` should occur
39/// through `memrefValue` directly.
40///
41/// Shared memory bank conflicts occur when multiple threads attempt to read or
42/// write locations assigned to the same shared memory bank. For `2^N` byte
43/// vectorized accesses, we need to be concerned with conflicts among threads
44/// identified as `(tid) -> tid.floordiv(2^{7-N})`. As such, this transformation
45/// changes any indexed memory access (vector.load, memref.load, nvgpu.ldmatrix,
46/// etc) such that the final dimension's index value is permuted such that
47/// `newColIndex = oldColIndex % vectorSize +
48/// perm[rowIndex](oldColIndex/vectorSize, rowIndex)` where `rowIndex` is the
49/// index for the second-to last dimension and `perm[rowIndex]` is a permutation
50/// function that depends on the row Index. The permutation function is chosen
51/// to ensure that sequential distributed+vectorized reads/writes down a single
52/// dimension of the memref have minimal conflicts.
53llvm::LogicalResult optimizeSharedMemoryReadsAndWrites(Operation *parentOp,
54 Value memrefValue);
55
56///
57/// Rewrites patterns
58///
59
60//===----------------------------------------------------------------------===//
61// NVGPU transformation options exposed as auxiliary structs.
62//===----------------------------------------------------------------------===//
63/// Enum to control the lowering of `nvgpu.mmasync`.
64enum class MmaSyncF32Lowering { TF32 = 0, TF32x3 = 1, Unkown = 2 };
65
66/// Collect patterns to convert mma.sync on f32 input and rewrite
67/// to use tensor cores with user provided level of accuracy:
68/// (a) tf32 (1 mma.sync per warp-level matrix-multiply-accumulate)
69/// (b) tf32x3 (3 mma.sync per warp-level matrix-multiply-accumulate)
70/// Typically, tf32 tensor core acceleration comes at a cost
71/// of accuracy from missing precision bits. While f32 has 23 precision
72/// bits, tf32 has only 10 precision bits. tf32x3 aims to recover the
73/// precision bits by spliting each operand into two tf32 values
74/// and issue three mma.sync tensor core operations.
76 RewritePatternSet &patterns,
78
79/// Convert global->shared vector transfers to async device copies. This
80/// function looks for suitable vector transfers within the specified op and
81/// converts them to "nvgpu.device_async_copy" ops. Consecutive copies are put
82/// into the same sync group. If `bypassL1` is set, the "bypassL1" attribute is
83/// set for suitable (i.e., transfer size 16 bytes) transfers.
84void createAsyncGroups(RewriterBase &rewriter, Operation *op, bool bypassL1);
85
86} // namespace nvgpu
87} // namespace mlir
88
89#endif // MLIR_DIALECT_NVGPU_TRANSFORMS_TRANSFORMS_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...
MmaSyncF32Lowering
Rewrites patterns.
Definition Transforms.h:64
bool canSwizzleSharedMemoryType(MemRefType memRefType)
Passes.
llvm::LogicalResult optimizeSharedMemoryReadsAndWrites(Operation *parentOp, Value memrefValue)
Optimizes vectorized accesses to a shared memory buffer specified by memrefValue.
void populateMmaSyncF32ToTF32Patterns(RewritePatternSet &patterns, nvgpu::MmaSyncF32Lowering precision=nvgpu::MmaSyncF32Lowering::TF32)
Collect patterns to convert mma.sync on f32 input and rewrite to use tensor cores with user provided ...
void createAsyncGroups(RewriterBase &rewriter, Operation *op, bool bypassL1)
Convert global->shared vector transfers to async device copies.
Include the generated interface declarations.