Skip to content

Commit 9f6c632

Browse files
authored
[mlir][mlir-spirv-cpu-runner] Move MLIR pass pipeline to mlir-opt (llvm#113594)
Adds a new mlir-opt test-only pass, -test-spirv-cpu-runner-pipeline, which runs the set of MLIR passes needed for the mlir-spirv-cpu-runner, and removes them from the runner. The tests are changed to invoke mlir-opt with this flag before running the runner. The eventual goal is to move all host/device code generation steps out of the runner, like with some of the other runners. Recommit of 17e9752. It was reverted due to a build failure, but the build failure had in fact already been fixed in e730231.
1 parent 577c7dd commit 9f6c632

File tree

6 files changed

+54
-26
lines changed

6 files changed

+54
-26
lines changed

mlir/test/lib/Pass/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
33
add_mlir_library(MLIRTestPass
44
TestDynamicPipeline.cpp
55
TestPassManager.cpp
6+
TestSPIRVCPURunnerPipeline.cpp
67

78
EXCLUDE_FROM_LIBMLIR
89

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//===------------------ TestSPIRVCPURunnerPipeline.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-spirv-cpu-runner tests.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "mlir/Conversion/GPUToSPIRV/GPUToSPIRVPass.h"
14+
#include "mlir/Conversion/SPIRVToLLVM/SPIRVToLLVMPass.h"
15+
#include "mlir/Dialect/GPU/Transforms/Passes.h"
16+
#include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
17+
#include "mlir/Dialect/SPIRV/Transforms/Passes.h"
18+
#include "mlir/Pass/PassManager.h"
19+
20+
using namespace mlir;
21+
22+
namespace {
23+
24+
void buildTestSPIRVCPURunnerPipeline(OpPassManager &passManager) {
25+
passManager.addPass(createGpuKernelOutliningPass());
26+
passManager.addPass(createConvertGPUToSPIRVPass(/*mapMemorySpace=*/true));
27+
28+
OpPassManager &nestedPM = passManager.nest<spirv::ModuleOp>();
29+
nestedPM.addPass(spirv::createSPIRVLowerABIAttributesPass());
30+
nestedPM.addPass(spirv::createSPIRVUpdateVCEPass());
31+
passManager.addPass(createLowerHostCodeToLLVMPass());
32+
passManager.addPass(createConvertSPIRVToLLVMPass());
33+
}
34+
35+
} // namespace
36+
37+
namespace mlir {
38+
namespace test {
39+
void registerTestSPIRVCPURunnerPipeline() {
40+
PassPipelineRegistration<>(
41+
"test-spirv-cpu-runner-pipeline",
42+
"Runs a series of passes for lowering SPIR-V-dialect MLIR to "
43+
"LLVM-dialect MLIR intended for mlir-spirv-cpu-runner.",
44+
buildTestSPIRVCPURunnerPipeline);
45+
}
46+
} // namespace test
47+
} // namespace mlir

mlir/test/mlir-spirv-cpu-runner/double.mlir

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: mlir-spirv-cpu-runner %s -e main --entry-point-result=void --shared-libs=%mlir_runner_utils,%mlir_test_spirv_cpu_runner_c_wrappers \
1+
// RUN: mlir-opt %s -test-spirv-cpu-runner-pipeline \
2+
// RUN: | mlir-spirv-cpu-runner - -e main --entry-point-result=void --shared-libs=%mlir_runner_utils,%mlir_test_spirv_cpu_runner_c_wrappers \
23
// RUN: | FileCheck %s
34

45
// CHECK: [8, 8, 8, 8, 8, 8]

mlir/test/mlir-spirv-cpu-runner/simple_add.mlir

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: mlir-spirv-cpu-runner %s -e main --entry-point-result=void --shared-libs=%mlir_runner_utils,%mlir_test_spirv_cpu_runner_c_wrappers \
1+
// RUN: mlir-opt %s -test-spirv-cpu-runner-pipeline \
2+
// RUN: | mlir-spirv-cpu-runner - -e main --entry-point-result=void --shared-libs=%mlir_runner_utils,%mlir_test_spirv_cpu_runner_c_wrappers \
23
// RUN: | FileCheck %s
34

45
// CHECK: data =

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ void registerTestSCFWhileOpBuilderPass();
142142
void registerTestSCFWrapInZeroTripCheckPasses();
143143
void registerTestShapeMappingPass();
144144
void registerTestSliceAnalysisPass();
145+
void registerTestSPIRVCPURunnerPipeline();
145146
void registerTestSPIRVFuncSignatureConversion();
146147
void registerTestSPIRVVectorUnrolling();
147148
void registerTestTensorCopyInsertionPass();
@@ -278,6 +279,7 @@ void registerTestPasses() {
278279
mlir::test::registerTestSCFWrapInZeroTripCheckPasses();
279280
mlir::test::registerTestShapeMappingPass();
280281
mlir::test::registerTestSliceAnalysisPass();
282+
mlir::test::registerTestSPIRVCPURunnerPipeline();
281283
mlir::test::registerTestSPIRVFuncSignatureConversion();
282284
mlir::test::registerTestSPIRVVectorUnrolling();
283285
mlir::test::registerTestTensorCopyInsertionPass();

mlir/tools/mlir-spirv-cpu-runner/mlir-spirv-cpu-runner.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,12 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
#include "mlir/Conversion/FuncToLLVM/ConvertFuncToLLVMPass.h"
16-
#include "mlir/Conversion/GPUToSPIRV/GPUToSPIRVPass.h"
17-
#include "mlir/Conversion/SPIRVToLLVM/SPIRVToLLVMPass.h"
1815
#include "mlir/Dialect/Arith/IR/Arith.h"
1916
#include "mlir/Dialect/Func/IR/FuncOps.h"
2017
#include "mlir/Dialect/GPU/IR/GPUDialect.h"
21-
#include "mlir/Dialect/GPU/Transforms/Passes.h"
2218
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
2319
#include "mlir/Dialect/MemRef/IR/MemRef.h"
2420
#include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
25-
#include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
26-
#include "mlir/Dialect/SPIRV/Transforms/Passes.h"
2721
#include "mlir/ExecutionEngine/JitRunner.h"
2822
#include "mlir/ExecutionEngine/OptUtils.h"
2923
#include "mlir/Pass/Pass.h"
@@ -75,31 +69,13 @@ convertMLIRModule(Operation *op, llvm::LLVMContext &context) {
7569
return mainModule;
7670
}
7771

78-
static LogicalResult runMLIRPasses(Operation *module,
79-
JitRunnerOptions &options) {
80-
PassManager passManager(module->getContext(),
81-
module->getName().getStringRef());
82-
if (failed(applyPassManagerCLOptions(passManager)))
83-
return failure();
84-
passManager.addPass(createGpuKernelOutliningPass());
85-
passManager.addPass(createConvertGPUToSPIRVPass(/*mapMemorySpace=*/true));
86-
87-
OpPassManager &nestedPM = passManager.nest<spirv::ModuleOp>();
88-
nestedPM.addPass(spirv::createSPIRVLowerABIAttributesPass());
89-
nestedPM.addPass(spirv::createSPIRVUpdateVCEPass());
90-
passManager.addPass(createLowerHostCodeToLLVMPass());
91-
passManager.addPass(createConvertSPIRVToLLVMPass());
92-
return passManager.run(module);
93-
}
94-
9572
int main(int argc, char **argv) {
9673
llvm::InitLLVM y(argc, argv);
9774

9875
llvm::InitializeNativeTarget();
9976
llvm::InitializeNativeTargetAsmPrinter();
10077

10178
mlir::JitRunnerConfig jitRunnerConfig;
102-
jitRunnerConfig.mlirTransformer = runMLIRPasses;
10379
jitRunnerConfig.llvmModuleBuilder = convertMLIRModule;
10480

10581
mlir::DialectRegistry registry;

0 commit comments

Comments
 (0)