Skip to content

Commit 00c3c73

Browse files
spaceotterEric Eaton
andauthored
[mlir][gpu] Separate the barrier elimination code from transform ops (#71762)
Allows the barrier elimination code to be run from C++ as well. The code from transforms dialect is copied as-is, the pass and populate functions have beed added at the end. Co-authored-by: Eric Eaton <[email protected]>
1 parent bdd396f commit 00c3c73

File tree

6 files changed

+645
-569
lines changed

6 files changed

+645
-569
lines changed

mlir/include/mlir/Dialect/GPU/Transforms/Passes.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ void populateGpuDecomposeMemrefsPatterns(RewritePatternSet &patterns);
165165
/// Pass decomposes memref ops inside `gpu.launch` body.
166166
std::unique_ptr<Pass> createGpuDecomposeMemrefsPass();
167167

168+
/// Erase barriers that do not enforce conflicting memory side effects.
169+
void populateGpuEliminateBarriersPatterns(RewritePatternSet &patterns);
170+
168171
/// Generate the code for registering passes.
169172
#define GEN_PASS_REGISTRATION
170173
#include "mlir/Dialect/GPU/Transforms/Passes.h.inc"

mlir/include/mlir/Dialect/GPU/Transforms/Passes.td

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,24 @@ def GpuMapParallelLoopsPass
3737
let dependentDialects = ["mlir::gpu::GPUDialect"];
3838
}
3939

40+
def GpuEliminateBarriers
41+
: Pass<"gpu-eliminate-barriers", "mlir::func::FuncOp"> {
42+
let summary = "Erase unnecessary barriers";
43+
let description = [{
44+
Barrier elimination pass. If a barrier does not enforce any conflicting
45+
pair of memory effects, including a pair that is enforced by another
46+
barrier, it is unnecessary and can be removed. Adapted from
47+
"High-Performance GPU-to-CPU Transpilation and Optimization via High-Level
48+
Parallel Constructs" by Moses, Ivanov, Domke, Endo, Doerfert, and Zinenko in
49+
PPoPP 2023 and implementation in Polygeist.
50+
}];
51+
let dependentDialects = [
52+
"mlir::gpu::GPUDialect",
53+
"mlir::memref::MemRefDialect",
54+
"mlir::scf::SCFDialect"
55+
];
56+
}
57+
4058
def GpuDecomposeMemrefsPass : Pass<"gpu-decompose-memrefs"> {
4159
let summary = "Decomposes memref index computation into explicit ops.";
4260
let description = [{

mlir/lib/Dialect/GPU/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ add_mlir_dialect_library(MLIRGPUTransforms
6262
Transforms/ShuffleRewriter.cpp
6363
Transforms/SPIRVAttachTarget.cpp
6464
Transforms/ROCDLAttachTarget.cpp
65+
Transforms/EliminateBarriers.cpp
6566

6667
ADDITIONAL_HEADER_DIRS
6768
${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/GPU

0 commit comments

Comments
 (0)