[Mlir-commits] [mlir] [mlir][mlir-vulkan-runner] Move part of device pass pipeline to mlir-opt (PR #119372)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Dec 10 05:00:05 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-spirv
Author: Andrea Faulds (andfau-amd)
<details>
<summary>Changes</summary>
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).
---
Full diff: https://github.com/llvm/llvm-project/pull/119372.diff
17 Files Affected:
- (modified) mlir/test/lib/Pass/CMakeLists.txt (+1)
- (added) mlir/test/lib/Pass/TestVulkanRunnerPipeline.cpp (+49)
- (modified) mlir/test/mlir-vulkan-runner/addf.mlir (+2-1)
- (modified) mlir/test/mlir-vulkan-runner/addf_if.mlir (+2-1)
- (modified) mlir/test/mlir-vulkan-runner/addi.mlir (+2-1)
- (modified) mlir/test/mlir-vulkan-runner/addi8.mlir (+2-1)
- (modified) mlir/test/mlir-vulkan-runner/addui_extended.mlir (+4-2)
- (modified) mlir/test/mlir-vulkan-runner/mulf.mlir (+2-1)
- (modified) mlir/test/mlir-vulkan-runner/smul_extended.mlir (+4-2)
- (modified) mlir/test/mlir-vulkan-runner/subf.mlir (+2-1)
- (modified) mlir/test/mlir-vulkan-runner/time.mlir (+2-1)
- (modified) mlir/test/mlir-vulkan-runner/umul_extended.mlir (+4-2)
- (modified) mlir/test/mlir-vulkan-runner/vector-deinterleave.mlir (+2-1)
- (modified) mlir/test/mlir-vulkan-runner/vector-interleave.mlir (+2-1)
- (modified) mlir/test/mlir-vulkan-runner/vector-shuffle.mlir (+2-1)
- (modified) mlir/tools/mlir-opt/mlir-opt.cpp (+2)
- (modified) mlir/tools/mlir-vulkan-runner/mlir-vulkan-runner.cpp (+2-36)
``````````diff
diff --git a/mlir/test/lib/Pass/CMakeLists.txt b/mlir/test/lib/Pass/CMakeLists.txt
index f489b7e51e5038..b474c1863f335b 100644
--- a/mlir/test/lib/Pass/CMakeLists.txt
+++ b/mlir/test/lib/Pass/CMakeLists.txt
@@ -4,6 +4,7 @@ add_mlir_library(MLIRTestPass
TestDynamicPipeline.cpp
TestPassManager.cpp
TestSPIRVCPURunnerPipeline.cpp
+ TestVulkanRunnerPipeline.cpp
EXCLUDE_FROM_LIBMLIR
diff --git a/mlir/test/lib/Pass/TestVulkanRunnerPipeline.cpp b/mlir/test/lib/Pass/TestVulkanRunnerPipeline.cpp
new file mode 100644
index 00000000000000..e2e1cc0c42b6f7
--- /dev/null
+++ b/mlir/test/lib/Pass/TestVulkanRunnerPipeline.cpp
@@ -0,0 +1,49 @@
+//===------------------ TestVulkanRunnerPipeline.cpp --------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Implements a pipeline for use by mlir-vulkan-runner tests.
+//
+//===----------------------------------------------------------------------===//
+
+#include "mlir/Conversion/ConvertToSPIRV/ConvertToSPIRVPass.h"
+#include "mlir/Conversion/GPUToSPIRV/GPUToSPIRVPass.h"
+#include "mlir/Dialect/GPU/Transforms/Passes.h"
+#include "mlir/Dialect/MemRef/Transforms/Passes.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
+#include "mlir/Dialect/SPIRV/Transforms/Passes.h"
+#include "mlir/Pass/PassManager.h"
+
+using namespace mlir;
+
+namespace {
+
+void buildTestVulkanRunnerPipeline(OpPassManager &passManager) {
+ passManager.addPass(createGpuKernelOutliningPass());
+ passManager.addPass(memref::createFoldMemRefAliasOpsPass());
+
+ ConvertToSPIRVPassOptions convertToSPIRVOptions{};
+ convertToSPIRVOptions.convertGPUModules = true;
+ passManager.addPass(createConvertToSPIRVPass(convertToSPIRVOptions));
+ OpPassManager &modulePM = passManager.nest<spirv::ModuleOp>();
+ modulePM.addPass(spirv::createSPIRVLowerABIAttributesPass());
+ modulePM.addPass(spirv::createSPIRVUpdateVCEPass());
+}
+
+} // namespace
+
+namespace mlir {
+namespace test {
+void registerTestVulkanRunnerPipeline() {
+ PassPipelineRegistration<>(
+ "test-vulkan-runner-pipeline",
+ "Runs a series of passes for lowering GPU-dialect MLIR to "
+ "SPIR-V-dialect MLIR intended for mlir-vulkan-runner.",
+ buildTestVulkanRunnerPipeline);
+}
+} // namespace test
+} // namespace mlir
diff --git a/mlir/test/mlir-vulkan-runner/addf.mlir b/mlir/test/mlir-vulkan-runner/addf.mlir
index f6162d1441e463..adff3754a50d35 100644
--- a/mlir/test/mlir-vulkan-runner/addf.mlir
+++ b/mlir/test/mlir-vulkan-runner/addf.mlir
@@ -1,4 +1,5 @@
-// RUN: mlir-vulkan-runner %s --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils --entry-point-result=void | FileCheck %s
+// RUN: mlir-opt %s -test-vulkan-runner-pipeline \
+// RUN: | mlir-vulkan-runner - --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils --entry-point-result=void | FileCheck %s
// CHECK: [3.3, 3.3, 3.3, 3.3, 3.3, 3.3, 3.3, 3.3]
module attributes {
diff --git a/mlir/test/mlir-vulkan-runner/addf_if.mlir b/mlir/test/mlir-vulkan-runner/addf_if.mlir
index 5638bd44682de6..cb1f4e5436a140 100644
--- a/mlir/test/mlir-vulkan-runner/addf_if.mlir
+++ b/mlir/test/mlir-vulkan-runner/addf_if.mlir
@@ -1,4 +1,5 @@
-// RUN: mlir-vulkan-runner %s --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils --entry-point-result=void | FileCheck %s
+// RUN: mlir-opt %s -test-vulkan-runner-pipeline \
+// RUN: | mlir-vulkan-runner - --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils --entry-point-result=void | FileCheck %s
// CHECK: [3.3, 3.3, 3.3, 3.3, 0, 0, 0, 0]
module attributes {
diff --git a/mlir/test/mlir-vulkan-runner/addi.mlir b/mlir/test/mlir-vulkan-runner/addi.mlir
index 79fefe0ab03f47..ece3acb3c23ed5 100644
--- a/mlir/test/mlir-vulkan-runner/addi.mlir
+++ b/mlir/test/mlir-vulkan-runner/addi.mlir
@@ -1,4 +1,5 @@
-// RUN: mlir-vulkan-runner %s --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils --entry-point-result=void | FileCheck %s
+// RUN: mlir-opt %s -test-vulkan-runner-pipeline \
+// RUN: | mlir-vulkan-runner - --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils --entry-point-result=void | FileCheck %s
// CHECK-COUNT-64: [3, 3, 3, 3, 3, 3, 3, 3]
module attributes {
diff --git a/mlir/test/mlir-vulkan-runner/addi8.mlir b/mlir/test/mlir-vulkan-runner/addi8.mlir
index 0672b48eed6a2f..8c9e8cf67b5f48 100644
--- a/mlir/test/mlir-vulkan-runner/addi8.mlir
+++ b/mlir/test/mlir-vulkan-runner/addi8.mlir
@@ -1,4 +1,5 @@
-// RUN: mlir-vulkan-runner %s --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils --entry-point-result=void | FileCheck %s
+// RUN: mlir-opt %s -test-vulkan-runner-pipeline \
+// RUN: | mlir-vulkan-runner - --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils --entry-point-result=void | FileCheck %s
// CHECK-COUNT-64: [3, 3, 3, 3, 3, 3, 3, 3]
module attributes {
diff --git a/mlir/test/mlir-vulkan-runner/addui_extended.mlir b/mlir/test/mlir-vulkan-runner/addui_extended.mlir
index 9b1f1964b3f953..a170efb602ab49 100644
--- a/mlir/test/mlir-vulkan-runner/addui_extended.mlir
+++ b/mlir/test/mlir-vulkan-runner/addui_extended.mlir
@@ -1,11 +1,13 @@
// Make sure that addition with carry produces expected results
// with and without expansion to primitive add/cmp ops for WebGPU.
-// RUN: mlir-vulkan-runner %s \
+// RUN: mlir-opt %s -test-vulkan-runner-pipeline \
+// RUN: | mlir-vulkan-runner - \
// RUN: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
// RUN: --entry-point-result=void | FileCheck %s
-// RUN: mlir-vulkan-runner %s --vulkan-runner-spirv-webgpu-prepare \
+// RUN: mlir-opt %s -test-vulkan-runner-pipeline -spirv-webgpu-prepare \
+// RUN: | mlir-vulkan-runner - \
// RUN: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
// RUN: --entry-point-result=void | FileCheck %s
diff --git a/mlir/test/mlir-vulkan-runner/mulf.mlir b/mlir/test/mlir-vulkan-runner/mulf.mlir
index 1399e30d38f574..4b551f2be1b826 100644
--- a/mlir/test/mlir-vulkan-runner/mulf.mlir
+++ b/mlir/test/mlir-vulkan-runner/mulf.mlir
@@ -1,4 +1,5 @@
-// RUN: mlir-vulkan-runner %s --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils --entry-point-result=void | FileCheck %s
+// RUN: mlir-opt %s -test-vulkan-runner-pipeline \
+// RUN: | mlir-vulkan-runner - --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils --entry-point-result=void | FileCheck %s
// CHECK-COUNT-4: [6, 6, 6, 6]
module attributes {
diff --git a/mlir/test/mlir-vulkan-runner/smul_extended.mlir b/mlir/test/mlir-vulkan-runner/smul_extended.mlir
index ccad49ecac6c44..91bdf291f0742f 100644
--- a/mlir/test/mlir-vulkan-runner/smul_extended.mlir
+++ b/mlir/test/mlir-vulkan-runner/smul_extended.mlir
@@ -1,11 +1,13 @@
// Make sure that signed extended multiplication produces expected results
// with and without expansion to primitive mul/add ops for WebGPU.
-// RUN: mlir-vulkan-runner %s \
+// RUN: mlir-opt %s -test-vulkan-runner-pipeline \
+// RUN: | mlir-vulkan-runner - \
// RUN: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
// RUN: --entry-point-result=void | FileCheck %s
-// RUN: mlir-vulkan-runner %s --vulkan-runner-spirv-webgpu-prepare \
+// RUN: mlir-opt %s -test-vulkan-runner-pipeline -spirv-webgpu-prepare \
+// RUN: | mlir-vulkan-runner - \
// RUN: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
// RUN: --entry-point-result=void | FileCheck %s
diff --git a/mlir/test/mlir-vulkan-runner/subf.mlir b/mlir/test/mlir-vulkan-runner/subf.mlir
index f19607bbed9bf9..acd7cfb6f03d0a 100644
--- a/mlir/test/mlir-vulkan-runner/subf.mlir
+++ b/mlir/test/mlir-vulkan-runner/subf.mlir
@@ -1,4 +1,5 @@
-// RUN: mlir-vulkan-runner %s --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils --entry-point-result=void | FileCheck %s
+// RUN: mlir-opt %s -test-vulkan-runner-pipeline \
+// RUN: | mlir-vulkan-runner - --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils --entry-point-result=void | FileCheck %s
// CHECK-COUNT-32: [2.2, 2.2, 2.2, 2.2]
module attributes {
diff --git a/mlir/test/mlir-vulkan-runner/time.mlir b/mlir/test/mlir-vulkan-runner/time.mlir
index 1e86f66877edfb..0bb986fdedbcc1 100644
--- a/mlir/test/mlir-vulkan-runner/time.mlir
+++ b/mlir/test/mlir-vulkan-runner/time.mlir
@@ -1,4 +1,5 @@
-// RUN: mlir-vulkan-runner %s --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils --entry-point-result=void | FileCheck %s
+// RUN: mlir-opt %s -test-vulkan-runner-pipeline \
+// RUN: | mlir-vulkan-runner - --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils --entry-point-result=void | FileCheck %s
// CHECK: Compute shader execution time
// CHECK: Command buffer submit time
diff --git a/mlir/test/mlir-vulkan-runner/umul_extended.mlir b/mlir/test/mlir-vulkan-runner/umul_extended.mlir
index 23c71be1c03259..a46cd8f578f03d 100644
--- a/mlir/test/mlir-vulkan-runner/umul_extended.mlir
+++ b/mlir/test/mlir-vulkan-runner/umul_extended.mlir
@@ -1,11 +1,13 @@
// Make sure that unsigned extended multiplication produces expected results
// with and without expansion to primitive mul/add ops for WebGPU.
-// RUN: mlir-vulkan-runner %s \
+// RUN: mlir-opt %s -test-vulkan-runner-pipeline \
+// RUN: | mlir-vulkan-runner - \
// RUN: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
// RUN: --entry-point-result=void | FileCheck %s
-// RUN: mlir-vulkan-runner %s --vulkan-runner-spirv-webgpu-prepare \
+// RUN: mlir-opt %s -test-vulkan-runner-pipeline -spirv-webgpu-prepare \
+// RUN: | mlir-vulkan-runner - \
// RUN: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
// RUN: --entry-point-result=void | FileCheck %s
diff --git a/mlir/test/mlir-vulkan-runner/vector-deinterleave.mlir b/mlir/test/mlir-vulkan-runner/vector-deinterleave.mlir
index f2214ebc10262b..acac070a891ebc 100644
--- a/mlir/test/mlir-vulkan-runner/vector-deinterleave.mlir
+++ b/mlir/test/mlir-vulkan-runner/vector-deinterleave.mlir
@@ -1,4 +1,5 @@
-// RUN: mlir-vulkan-runner %s \
+// RUN: mlir-opt %s -test-vulkan-runner-pipeline \
+// RUN: | mlir-vulkan-runner - \
// RUN: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
// RUN: --entry-point-result=void | FileCheck %s
diff --git a/mlir/test/mlir-vulkan-runner/vector-interleave.mlir b/mlir/test/mlir-vulkan-runner/vector-interleave.mlir
index 0846d52a45b110..c5f68af2cc0ea9 100644
--- a/mlir/test/mlir-vulkan-runner/vector-interleave.mlir
+++ b/mlir/test/mlir-vulkan-runner/vector-interleave.mlir
@@ -1,4 +1,5 @@
-// RUN: mlir-vulkan-runner %s \
+// RUN: mlir-opt %s -test-vulkan-runner-pipeline \
+// RUN: | mlir-vulkan-runner - \
// RUN: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
// RUN: --entry-point-result=void | FileCheck %s
diff --git a/mlir/test/mlir-vulkan-runner/vector-shuffle.mlir b/mlir/test/mlir-vulkan-runner/vector-shuffle.mlir
index 7cf53b54590bca..2ef939f564f3f8 100644
--- a/mlir/test/mlir-vulkan-runner/vector-shuffle.mlir
+++ b/mlir/test/mlir-vulkan-runner/vector-shuffle.mlir
@@ -1,4 +1,5 @@
-// RUN: mlir-vulkan-runner %s \
+// RUN: mlir-opt %s -test-vulkan-runner-pipeline \
+// RUN: | mlir-vulkan-runner - \
// RUN: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
// RUN: --entry-point-result=void | FileCheck %s
diff --git a/mlir/tools/mlir-opt/mlir-opt.cpp b/mlir/tools/mlir-opt/mlir-opt.cpp
index 94bc67a1e96093..960f7037a1b61f 100644
--- a/mlir/tools/mlir-opt/mlir-opt.cpp
+++ b/mlir/tools/mlir-opt/mlir-opt.cpp
@@ -153,6 +153,7 @@ void registerTestTransformDialectEraseSchedulePass();
void registerTestPassStateExtensionCommunication();
void registerTestVectorLowerings();
void registerTestVectorReductionToSPIRVDotProd();
+void registerTestVulkanRunnerPipeline();
void registerTestWrittenToPass();
#if MLIR_ENABLE_PDL_IN_PATTERNMATCH
void registerTestDialectConversionPasses();
@@ -291,6 +292,7 @@ void registerTestPasses() {
mlir::test::registerTestPassStateExtensionCommunication();
mlir::test::registerTestVectorLowerings();
mlir::test::registerTestVectorReductionToSPIRVDotProd();
+ mlir::test::registerTestVulkanRunnerPipeline();
mlir::test::registerTestWrittenToPass();
#if MLIR_ENABLE_PDL_IN_PATTERNMATCH
mlir::test::registerTestDialectConversionPasses();
diff --git a/mlir/tools/mlir-vulkan-runner/mlir-vulkan-runner.cpp b/mlir/tools/mlir-vulkan-runner/mlir-vulkan-runner.cpp
index 2dd539ef83481f..eab64c97e89e41 100644
--- a/mlir/tools/mlir-vulkan-runner/mlir-vulkan-runner.cpp
+++ b/mlir/tools/mlir-vulkan-runner/mlir-vulkan-runner.cpp
@@ -12,9 +12,7 @@
//
//===----------------------------------------------------------------------===//
-#include "mlir/Conversion/ConvertToSPIRV/ConvertToSPIRVPass.h"
#include "mlir/Conversion/FuncToLLVM/ConvertFuncToLLVMPass.h"
-#include "mlir/Conversion/GPUToSPIRV/GPUToSPIRVPass.h"
#include "mlir/Conversion/GPUToVulkan/ConvertGPUToVulkanPass.h"
#include "mlir/Conversion/LLVMCommon/LoweringOptions.h"
#include "mlir/Conversion/MemRefToLLVM/MemRefToLLVM.h"
@@ -30,8 +28,6 @@
#include "mlir/Dialect/MemRef/Transforms/Passes.h"
#include "mlir/Dialect/SCF/IR/SCF.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
-#include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
-#include "mlir/Dialect/SPIRV/Transforms/Passes.h"
#include "mlir/Dialect/Vector/IR/VectorOps.h"
#include "mlir/ExecutionEngine/JitRunner.h"
#include "mlir/Pass/Pass.h"
@@ -43,18 +39,7 @@
using namespace mlir;
-namespace {
-struct VulkanRunnerOptions {
- llvm::cl::OptionCategory category{"mlir-vulkan-runner options"};
- llvm::cl::opt<bool> spirvWebGPUPrepare{
- "vulkan-runner-spirv-webgpu-prepare",
- llvm::cl::desc("Run MLIR transforms used when targetting WebGPU"),
- llvm::cl::cat(category)};
-};
-} // namespace
-
-static LogicalResult runMLIRPasses(Operation *op,
- VulkanRunnerOptions &options) {
+static LogicalResult runMLIRPasses(Operation *op, JitRunnerOptions &) {
auto module = dyn_cast<ModuleOp>(op);
if (!module)
return op->emitOpError("expected a 'builtin.module' op");
@@ -62,18 +47,6 @@ static LogicalResult runMLIRPasses(Operation *op,
if (failed(applyPassManagerCLOptions(passManager)))
return failure();
- passManager.addPass(createGpuKernelOutliningPass());
- passManager.addPass(memref::createFoldMemRefAliasOpsPass());
-
- ConvertToSPIRVPassOptions convertToSPIRVOptions{};
- convertToSPIRVOptions.convertGPUModules = true;
- passManager.addPass(createConvertToSPIRVPass(convertToSPIRVOptions));
- OpPassManager &modulePM = passManager.nest<spirv::ModuleOp>();
- modulePM.addPass(spirv::createSPIRVLowerABIAttributesPass());
- modulePM.addPass(spirv::createSPIRVUpdateVCEPass());
- if (options.spirvWebGPUPrepare)
- modulePM.addPass(spirv::createSPIRVWebGPUPreparePass());
-
passManager.addPass(createConvertGpuLaunchFuncToVulkanLaunchFuncPass());
passManager.addPass(createFinalizeMemRefToLLVMConversionPass());
passManager.addPass(createConvertVectorToLLVMPass());
@@ -96,15 +69,8 @@ int main(int argc, char **argv) {
llvm::InitializeNativeTarget();
llvm::InitializeNativeTargetAsmPrinter();
- // Initialize runner-specific CLI options. These will be parsed and
- // initialzied in `JitRunnerMain`.
- VulkanRunnerOptions options;
- auto runPassesWithOptions = [&options](Operation *op, JitRunnerOptions &) {
- return runMLIRPasses(op, options);
- };
-
mlir::JitRunnerConfig jitRunnerConfig;
- jitRunnerConfig.mlirTransformer = runPassesWithOptions;
+ jitRunnerConfig.mlirTransformer = runMLIRPasses;
mlir::DialectRegistry registry;
registry.insert<mlir::arith::ArithDialect, mlir::LLVM::LLVMDialect,
``````````
</details>
https://github.com/llvm/llvm-project/pull/119372
More information about the Mlir-commits
mailing list