Skip to content

Commit 9735873

Browse files
authored
[mlir][mlir-vulkan-runner] Move part of device pass pipeline to mlir-opt (#119372)
Adds a new mlir-opt test-only pass, -test-vulkan-runner-pipeline, which runs a set of passes needed for mlir-vulkan-runner, and removes them from the runner. The tests are changed to invoke mlir-opt with this flag before invoking the runner. The passes moved are ones concerned with lowering of the device code prior to serialization to SPIR-V. This is an incremental step towards moving the entire pipeline to mlir-opt, to align with other runners (see #73457).
1 parent 8ca4aa5 commit 9735873

17 files changed

+102
-70
lines changed

mlir/test/lib/Pass/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ add_mlir_library(MLIRTestPass
44
TestDynamicPipeline.cpp
55
TestPassManager.cpp
66
TestSPIRVCPURunnerPipeline.cpp
7+
TestVulkanRunnerPipeline.cpp
78

89
EXCLUDE_FROM_LIBMLIR
910

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//===------------------ TestVulkanRunnerPipeline.cpp --------------------===//
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+
// Implements a pipeline for use by mlir-vulkan-runner tests.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "mlir/Conversion/ConvertToSPIRV/ConvertToSPIRVPass.h"
14+
#include "mlir/Conversion/GPUToSPIRV/GPUToSPIRVPass.h"
15+
#include "mlir/Dialect/GPU/Transforms/Passes.h"
16+
#include "mlir/Dialect/MemRef/Transforms/Passes.h"
17+
#include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
18+
#include "mlir/Dialect/SPIRV/Transforms/Passes.h"
19+
#include "mlir/Pass/PassManager.h"
20+
21+
using namespace mlir;
22+
23+
namespace {
24+
25+
void buildTestVulkanRunnerPipeline(OpPassManager &passManager) {
26+
passManager.addPass(createGpuKernelOutliningPass());
27+
passManager.addPass(memref::createFoldMemRefAliasOpsPass());
28+
29+
ConvertToSPIRVPassOptions convertToSPIRVOptions{};
30+
convertToSPIRVOptions.convertGPUModules = true;
31+
passManager.addPass(createConvertToSPIRVPass(convertToSPIRVOptions));
32+
OpPassManager &modulePM = passManager.nest<spirv::ModuleOp>();
33+
modulePM.addPass(spirv::createSPIRVLowerABIAttributesPass());
34+
modulePM.addPass(spirv::createSPIRVUpdateVCEPass());
35+
}
36+
37+
} // namespace
38+
39+
namespace mlir::test {
40+
void registerTestVulkanRunnerPipeline() {
41+
PassPipelineRegistration<>(
42+
"test-vulkan-runner-pipeline",
43+
"Runs a series of passes for lowering GPU-dialect MLIR to "
44+
"SPIR-V-dialect MLIR intended for mlir-vulkan-runner.",
45+
buildTestVulkanRunnerPipeline);
46+
}
47+
} // namespace mlir::test

mlir/test/mlir-vulkan-runner/addf.mlir

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: mlir-vulkan-runner %s --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils --entry-point-result=void | FileCheck %s
1+
// RUN: mlir-opt %s -test-vulkan-runner-pipeline \
2+
// RUN: | mlir-vulkan-runner - --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils --entry-point-result=void | FileCheck %s
23

34
// CHECK: [3.3, 3.3, 3.3, 3.3, 3.3, 3.3, 3.3, 3.3]
45
module attributes {

mlir/test/mlir-vulkan-runner/addf_if.mlir

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: mlir-vulkan-runner %s --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils --entry-point-result=void | FileCheck %s
1+
// RUN: mlir-opt %s -test-vulkan-runner-pipeline \
2+
// RUN: | mlir-vulkan-runner - --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils --entry-point-result=void | FileCheck %s
23

34
// CHECK: [3.3, 3.3, 3.3, 3.3, 0, 0, 0, 0]
45
module attributes {

mlir/test/mlir-vulkan-runner/addi.mlir

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: mlir-vulkan-runner %s --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils --entry-point-result=void | FileCheck %s
1+
// RUN: mlir-opt %s -test-vulkan-runner-pipeline \
2+
// RUN: | mlir-vulkan-runner - --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils --entry-point-result=void | FileCheck %s
23

34
// CHECK-COUNT-64: [3, 3, 3, 3, 3, 3, 3, 3]
45
module attributes {

mlir/test/mlir-vulkan-runner/addi8.mlir

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: mlir-vulkan-runner %s --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils --entry-point-result=void | FileCheck %s
1+
// RUN: mlir-opt %s -test-vulkan-runner-pipeline \
2+
// RUN: | mlir-vulkan-runner - --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils --entry-point-result=void | FileCheck %s
23

34
// CHECK-COUNT-64: [3, 3, 3, 3, 3, 3, 3, 3]
45
module attributes {

mlir/test/mlir-vulkan-runner/addui_extended.mlir

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
// Make sure that addition with carry produces expected results
22
// with and without expansion to primitive add/cmp ops for WebGPU.
33

4-
// RUN: mlir-vulkan-runner %s \
5-
// RUN: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
6-
// RUN: --entry-point-result=void | FileCheck %s
4+
// RUN: mlir-opt %s -test-vulkan-runner-pipeline \
5+
// RUN: | mlir-vulkan-runner - \
6+
// RUN: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
7+
// RUN: --entry-point-result=void | FileCheck %s
78

8-
// RUN: mlir-vulkan-runner %s --vulkan-runner-spirv-webgpu-prepare \
9-
// RUN: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
10-
// RUN: --entry-point-result=void | FileCheck %s
9+
// RUN: mlir-opt %s -test-vulkan-runner-pipeline -spirv-webgpu-prepare \
10+
// RUN: | mlir-vulkan-runner - \
11+
// RUN: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
12+
// RUN: --entry-point-result=void | FileCheck %s
1113

1214
// CHECK: [0, 42, 0, 42]
1315
// CHECK: [1, 0, 1, 1]

mlir/test/mlir-vulkan-runner/mulf.mlir

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: mlir-vulkan-runner %s --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils --entry-point-result=void | FileCheck %s
1+
// RUN: mlir-opt %s -test-vulkan-runner-pipeline \
2+
// RUN: | mlir-vulkan-runner - --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils --entry-point-result=void | FileCheck %s
23

34
// CHECK-COUNT-4: [6, 6, 6, 6]
45
module attributes {

mlir/test/mlir-vulkan-runner/smul_extended.mlir

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
// Make sure that signed extended multiplication produces expected results
22
// with and without expansion to primitive mul/add ops for WebGPU.
33

4-
// RUN: mlir-vulkan-runner %s \
5-
// RUN: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
6-
// RUN: --entry-point-result=void | FileCheck %s
4+
// RUN: mlir-opt %s -test-vulkan-runner-pipeline \
5+
// RUN: | mlir-vulkan-runner - \
6+
// RUN: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
7+
// RUN: --entry-point-result=void | FileCheck %s
78

8-
// RUN: mlir-vulkan-runner %s --vulkan-runner-spirv-webgpu-prepare \
9-
// RUN: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
10-
// RUN: --entry-point-result=void | FileCheck %s
9+
// RUN: mlir-opt %s -test-vulkan-runner-pipeline -spirv-webgpu-prepare \
10+
// RUN: | mlir-vulkan-runner - \
11+
// RUN: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
12+
// RUN: --entry-point-result=void | FileCheck %s
1113

1214
// CHECK: [0, 1, -2, 1, 1048560, -87620295, -131071, 560969770]
1315
// CHECK: [0, 0, -1, 0, 0, -1, 0, -499807318]

mlir/test/mlir-vulkan-runner/subf.mlir

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: mlir-vulkan-runner %s --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils --entry-point-result=void | FileCheck %s
1+
// RUN: mlir-opt %s -test-vulkan-runner-pipeline \
2+
// RUN: | mlir-vulkan-runner - --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils --entry-point-result=void | FileCheck %s
23

34
// CHECK-COUNT-32: [2.2, 2.2, 2.2, 2.2]
45
module attributes {

mlir/test/mlir-vulkan-runner/time.mlir

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: mlir-vulkan-runner %s --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils --entry-point-result=void | FileCheck %s
1+
// RUN: mlir-opt %s -test-vulkan-runner-pipeline \
2+
// RUN: | mlir-vulkan-runner - --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils --entry-point-result=void | FileCheck %s
23

34
// CHECK: Compute shader execution time
45
// CHECK: Command buffer submit time

mlir/test/mlir-vulkan-runner/umul_extended.mlir

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
// Make sure that unsigned extended multiplication produces expected results
22
// with and without expansion to primitive mul/add ops for WebGPU.
33

4-
// RUN: mlir-vulkan-runner %s \
5-
// RUN: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
6-
// RUN: --entry-point-result=void | FileCheck %s
4+
// RUN: mlir-opt %s -test-vulkan-runner-pipeline \
5+
// RUN: | mlir-vulkan-runner - \
6+
// RUN: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
7+
// RUN: --entry-point-result=void | FileCheck %s
78

8-
// RUN: mlir-vulkan-runner %s --vulkan-runner-spirv-webgpu-prepare \
9-
// RUN: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
10-
// RUN: --entry-point-result=void | FileCheck %s
9+
// RUN: mlir-opt %s -test-vulkan-runner-pipeline -spirv-webgpu-prepare \
10+
// RUN: | mlir-vulkan-runner - \
11+
// RUN: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
12+
// RUN: --entry-point-result=void | FileCheck %s
1113

1214
// CHECK: [0, 1, -2, 1, 1048560, -87620295, -131071, -49]
1315
// CHECK: [0, 0, 1, -2, 0, 65534, -131070, 6]

mlir/test/mlir-vulkan-runner/vector-deinterleave.mlir

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
// RUN: mlir-vulkan-runner %s \
2-
// RUN: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
3-
// RUN: --entry-point-result=void | FileCheck %s
1+
// RUN: mlir-opt %s -test-vulkan-runner-pipeline \
2+
// RUN: | mlir-vulkan-runner - \
3+
// RUN: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
4+
// RUN: --entry-point-result=void | FileCheck %s
45

56
// CHECK: [0, 2]
67
// CHECK: [1, 3]

mlir/test/mlir-vulkan-runner/vector-interleave.mlir

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
// RUN: mlir-vulkan-runner %s \
2-
// RUN: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
3-
// RUN: --entry-point-result=void | FileCheck %s
1+
// RUN: mlir-opt %s -test-vulkan-runner-pipeline \
2+
// RUN: | mlir-vulkan-runner - \
3+
// RUN: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
4+
// RUN: --entry-point-result=void | FileCheck %s
45

56
// CHECK: [0, 2, 1, 3]
67
module attributes {

mlir/test/mlir-vulkan-runner/vector-shuffle.mlir

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
// RUN: mlir-vulkan-runner %s \
2-
// RUN: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
3-
// RUN: --entry-point-result=void | FileCheck %s
1+
// RUN: mlir-opt %s -test-vulkan-runner-pipeline \
2+
// RUN: | mlir-vulkan-runner - \
3+
// RUN: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
4+
// RUN: --entry-point-result=void | FileCheck %s
45

56
// CHECK: [2, 1, 3, 3]
67
module attributes {

mlir/tools/mlir-opt/mlir-opt.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ void registerTestTransformDialectEraseSchedulePass();
153153
void registerTestPassStateExtensionCommunication();
154154
void registerTestVectorLowerings();
155155
void registerTestVectorReductionToSPIRVDotProd();
156+
void registerTestVulkanRunnerPipeline();
156157
void registerTestWrittenToPass();
157158
#if MLIR_ENABLE_PDL_IN_PATTERNMATCH
158159
void registerTestDialectConversionPasses();
@@ -291,6 +292,7 @@ void registerTestPasses() {
291292
mlir::test::registerTestPassStateExtensionCommunication();
292293
mlir::test::registerTestVectorLowerings();
293294
mlir::test::registerTestVectorReductionToSPIRVDotProd();
295+
mlir::test::registerTestVulkanRunnerPipeline();
294296
mlir::test::registerTestWrittenToPass();
295297
#if MLIR_ENABLE_PDL_IN_PATTERNMATCH
296298
mlir::test::registerTestDialectConversionPasses();

mlir/tools/mlir-vulkan-runner/mlir-vulkan-runner.cpp

+2-36
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
#include "mlir/Conversion/ConvertToSPIRV/ConvertToSPIRVPass.h"
1615
#include "mlir/Conversion/FuncToLLVM/ConvertFuncToLLVMPass.h"
17-
#include "mlir/Conversion/GPUToSPIRV/GPUToSPIRVPass.h"
1816
#include "mlir/Conversion/GPUToVulkan/ConvertGPUToVulkanPass.h"
1917
#include "mlir/Conversion/LLVMCommon/LoweringOptions.h"
2018
#include "mlir/Conversion/MemRefToLLVM/MemRefToLLVM.h"
@@ -30,8 +28,6 @@
3028
#include "mlir/Dialect/MemRef/Transforms/Passes.h"
3129
#include "mlir/Dialect/SCF/IR/SCF.h"
3230
#include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
33-
#include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
34-
#include "mlir/Dialect/SPIRV/Transforms/Passes.h"
3531
#include "mlir/Dialect/Vector/IR/VectorOps.h"
3632
#include "mlir/ExecutionEngine/JitRunner.h"
3733
#include "mlir/Pass/Pass.h"
@@ -43,37 +39,14 @@
4339

4440
using namespace mlir;
4541

46-
namespace {
47-
struct VulkanRunnerOptions {
48-
llvm::cl::OptionCategory category{"mlir-vulkan-runner options"};
49-
llvm::cl::opt<bool> spirvWebGPUPrepare{
50-
"vulkan-runner-spirv-webgpu-prepare",
51-
llvm::cl::desc("Run MLIR transforms used when targetting WebGPU"),
52-
llvm::cl::cat(category)};
53-
};
54-
} // namespace
55-
56-
static LogicalResult runMLIRPasses(Operation *op,
57-
VulkanRunnerOptions &options) {
42+
static LogicalResult runMLIRPasses(Operation *op, JitRunnerOptions &) {
5843
auto module = dyn_cast<ModuleOp>(op);
5944
if (!module)
6045
return op->emitOpError("expected a 'builtin.module' op");
6146
PassManager passManager(module.getContext());
6247
if (failed(applyPassManagerCLOptions(passManager)))
6348
return failure();
6449

65-
passManager.addPass(createGpuKernelOutliningPass());
66-
passManager.addPass(memref::createFoldMemRefAliasOpsPass());
67-
68-
ConvertToSPIRVPassOptions convertToSPIRVOptions{};
69-
convertToSPIRVOptions.convertGPUModules = true;
70-
passManager.addPass(createConvertToSPIRVPass(convertToSPIRVOptions));
71-
OpPassManager &modulePM = passManager.nest<spirv::ModuleOp>();
72-
modulePM.addPass(spirv::createSPIRVLowerABIAttributesPass());
73-
modulePM.addPass(spirv::createSPIRVUpdateVCEPass());
74-
if (options.spirvWebGPUPrepare)
75-
modulePM.addPass(spirv::createSPIRVWebGPUPreparePass());
76-
7750
passManager.addPass(createConvertGpuLaunchFuncToVulkanLaunchFuncPass());
7851
passManager.addPass(createFinalizeMemRefToLLVMConversionPass());
7952
passManager.addPass(createConvertVectorToLLVMPass());
@@ -96,15 +69,8 @@ int main(int argc, char **argv) {
9669
llvm::InitializeNativeTarget();
9770
llvm::InitializeNativeTargetAsmPrinter();
9871

99-
// Initialize runner-specific CLI options. These will be parsed and
100-
// initialzied in `JitRunnerMain`.
101-
VulkanRunnerOptions options;
102-
auto runPassesWithOptions = [&options](Operation *op, JitRunnerOptions &) {
103-
return runMLIRPasses(op, options);
104-
};
105-
10672
mlir::JitRunnerConfig jitRunnerConfig;
107-
jitRunnerConfig.mlirTransformer = runPassesWithOptions;
73+
jitRunnerConfig.mlirTransformer = runMLIRPasses;
10874

10975
mlir::DialectRegistry registry;
11076
registry.insert<mlir::arith::ArithDialect, mlir::LLVM::LLVMDialect,

0 commit comments

Comments
 (0)