Skip to content

Commit 951ab04

Browse files
[mlir][NVVM] Add no-rollback option to NVVM lowering passes (#168477)
Add pass options to run lowerings to NVVM without pattern rollback. This makes the dialect conversions easier to debug and improves performance/memory usage.
1 parent 35a95fe commit 951ab04

25 files changed

+32
-19
lines changed

mlir/include/mlir/Conversion/Passes.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,8 @@ def ConvertGpuOpsToNVVMOps : Pass<"convert-gpu-to-nvvm", "gpu::GPUModuleOp"> {
628628
/*default=*/"false",
629629
"Replace memref arguments in GPU functions with bare pointers. "
630630
"All memrefs must have static shape.">,
631+
Option<"allowPatternRollback", "allow-pattern-rollback", "bool", "true",
632+
"Experimental performance flag to disallow pattern rollback">,
631633
ListOption<"allowedDialects", "allowed-dialects", "std::string",
632634
"Run conversion patterns of only the specified dialects">,
633635
];

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ struct GPUToNVVMPipelineOptions
5858
"Whether to use the bareptr calling convention on the host (warning "
5959
"this should be false until the GPU layering is fixed)"),
6060
llvm::cl::init(false)};
61+
PassOptions::Option<bool> allowPatternRollback{
62+
*this, "allow-pattern-rollback",
63+
llvm::cl::desc("Allow pattern rollback during dialect conversion"),
64+
llvm::cl::init(true)};
6165
};
6266

6367
// Options for the gpu to xevm pipeline.

mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,10 @@ struct LowerGpuOpsToNVVMOpsPass final
419419
if (this->hasRedux)
420420
populateGpuSubgroupReduceOpLoweringPattern(converter, llvmPatterns);
421421
configureGpuToNVVMConversionLegality(target);
422-
if (failed(applyPartialConversion(m, target, std::move(llvmPatterns))))
422+
ConversionConfig config;
423+
config.allowPatternRollback = allowPatternRollback;
424+
if (failed(
425+
applyPartialConversion(m, target, std::move(llvmPatterns), config)))
423426
signalPassFailure();
424427
}
425428
};

mlir/lib/Dialect/GPU/Pipelines/GPUToNVVMPipeline.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ void buildGpuPassPipeline(OpPassManager &pm,
7272
ConvertGpuOpsToNVVMOpsOptions opt;
7373
opt.useBarePtrCallConv = options.kernelUseBarePtrCallConv;
7474
opt.indexBitwidth = options.indexBitWidth;
75+
opt.allowPatternRollback = options.allowPatternRollback;
7576
pm.addNestedPass<gpu::GPUModuleOp>(createConvertGpuOpsToNVVMOps(opt));
7677
pm.addNestedPass<gpu::GPUModuleOp>(createCanonicalizerPass());
7778
pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());

mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: mlir-opt %s -convert-gpu-to-nvvm='has-redux=1' -split-input-file | FileCheck %s
2+
// RUN: mlir-opt %s -convert-gpu-to-nvvm='has-redux=1 allow-pattern-rollback=0' -split-input-file | FileCheck %s
23
// RUN: mlir-opt %s -convert-gpu-to-nvvm='has-redux=1 allowed-dialects=func,arith,cf' -split-input-file | FileCheck %s
34
// RUN: mlir-opt %s -convert-gpu-to-nvvm='has-redux=1 use-bare-ptr-memref-call-conv=1' -split-input-file | FileCheck %s --check-prefix=CHECK-BARE
45
// RUN: mlir-opt %s -transform-interpreter | FileCheck %s

mlir/test/Conversion/GPUToNVVM/memref.mlir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: mlir-opt %s -convert-gpu-to-nvvm | FileCheck %s
2+
// RUN: mlir-opt %s -convert-gpu-to-nvvm="allow-pattern-rollback=0" | FileCheck %s
23
// RUN: mlir-opt %s -convert-gpu-to-nvvm='use-bare-ptr-memref-call-conv=1' \
34
// RUN: | FileCheck %s --check-prefix=BARE
45

mlir/test/Conversion/GPUToNVVM/wmma-ops-to-nvvm.mlir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: mlir-opt --convert-gpu-to-nvvm --split-input-file %s | FileCheck %s
2+
// RUN: mlir-opt --convert-gpu-to-nvvm="allow-pattern-rollback=0" --split-input-file %s | FileCheck %s
23
// RUN: mlir-opt --convert-gpu-to-nvvm="index-bitwidth=32" --split-input-file %s | FileCheck --check-prefix=CHECK32 %s
34

45
gpu.module @test_module {

mlir/test/Integration/GPU/CUDA/all-reduce-and.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: mlir-opt %s \
2-
// RUN: | mlir-opt -gpu-lower-to-nvvm-pipeline \
2+
// RUN: | mlir-opt -gpu-lower-to-nvvm-pipeline="allow-pattern-rollback=0" \
33
// RUN: | mlir-runner \
44
// RUN: --shared-libs=%mlir_cuda_runtime \
55
// RUN: --shared-libs=%mlir_runner_utils \

mlir/test/Integration/GPU/CUDA/all-reduce-maxsi.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: mlir-opt %s \
2-
// RUN: | mlir-opt -gpu-lower-to-nvvm-pipeline="cubin-format=%gpu_compilation_format" \
2+
// RUN: | mlir-opt -gpu-lower-to-nvvm-pipeline="cubin-format=%gpu_compilation_format allow-pattern-rollback=0" \
33
// RUN: | mlir-runner \
44
// RUN: --shared-libs=%mlir_cuda_runtime \
55
// RUN: --shared-libs=%mlir_runner_utils \

mlir/test/Integration/GPU/CUDA/all-reduce-minsi.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: mlir-opt %s \
2-
// RUN: | mlir-opt -gpu-lower-to-nvvm-pipeline="cubin-format=%gpu_compilation_format" \
2+
// RUN: | mlir-opt -gpu-lower-to-nvvm-pipeline="cubin-format=%gpu_compilation_format allow-pattern-rollback=0" \
33
// RUN: | mlir-runner \
44
// RUN: --shared-libs=%mlir_cuda_runtime \
55
// RUN: --shared-libs=%mlir_runner_utils \

0 commit comments

Comments
 (0)