Skip to content

[mlir][mlir-spirv-cpu-runner] Move MLIR pass pipeline to mlir-opt #111575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mlir/test/lib/Pass/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
add_mlir_library(MLIRTestPass
TestDynamicPipeline.cpp
TestPassManager.cpp
TestSPIRVCPURunnerPipeline.cpp

EXCLUDE_FROM_LIBMLIR

Expand Down
47 changes: 47 additions & 0 deletions mlir/test/lib/Pass/TestSPIRVCPURunnerPipeline.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//===------------------ TestSPIRVCPURunnerPipeline.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-spirv-cpu-runner tests.
//
//===----------------------------------------------------------------------===//

#include "mlir/Conversion/GPUToSPIRV/GPUToSPIRVPass.h"
#include "mlir/Conversion/SPIRVToLLVM/SPIRVToLLVMPass.h"
#include "mlir/Dialect/GPU/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 buildTestSPIRVCPURunnerPipeline(OpPassManager &passManager) {
passManager.addPass(createGpuKernelOutliningPass());
passManager.addPass(createConvertGPUToSPIRVPass(/*mapMemorySpace=*/true));

OpPassManager &nestedPM = passManager.nest<spirv::ModuleOp>();
nestedPM.addPass(spirv::createSPIRVLowerABIAttributesPass());
nestedPM.addPass(spirv::createSPIRVUpdateVCEPass());
passManager.addPass(createLowerHostCodeToLLVMPass());
passManager.addPass(createConvertSPIRVToLLVMPass());
}

} // namespace

namespace mlir {
namespace test {
void registerTestSPIRVCPURunnerPipeline() {
PassPipelineRegistration<>(
"test-spirv-cpu-runner-pipeline",
"Runs a series of passes for lowering SPIR-V-dialect MLIR to "
"LLVM-dialect MLIR intended for mlir-spirv-cpu-runner.",
buildTestSPIRVCPURunnerPipeline);
}
} // namespace test
} // namespace mlir
3 changes: 2 additions & 1 deletion mlir/test/mlir-spirv-cpu-runner/double.mlir
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: mlir-spirv-cpu-runner %s -e main --entry-point-result=void --shared-libs=%mlir_runner_utils,%mlir_test_spirv_cpu_runner_c_wrappers \
// RUN: mlir-opt %s -test-spirv-cpu-runner-pipeline \
// RUN: | mlir-spirv-cpu-runner - -e main --entry-point-result=void --shared-libs=%mlir_runner_utils,%mlir_test_spirv_cpu_runner_c_wrappers \
// RUN: | FileCheck %s

// CHECK: [8, 8, 8, 8, 8, 8]
Expand Down
3 changes: 2 additions & 1 deletion mlir/test/mlir-spirv-cpu-runner/simple_add.mlir
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: mlir-spirv-cpu-runner %s -e main --entry-point-result=void --shared-libs=%mlir_runner_utils,%mlir_test_spirv_cpu_runner_c_wrappers \
// RUN: mlir-opt %s -test-spirv-cpu-runner-pipeline \
// RUN: | mlir-spirv-cpu-runner - -e main --entry-point-result=void --shared-libs=%mlir_runner_utils,%mlir_test_spirv_cpu_runner_c_wrappers \
// RUN: | FileCheck %s

// CHECK: data =
Expand Down
2 changes: 2 additions & 0 deletions mlir/tools/mlir-opt/mlir-opt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ void registerTestSCFWhileOpBuilderPass();
void registerTestSCFWrapInZeroTripCheckPasses();
void registerTestShapeMappingPass();
void registerTestSliceAnalysisPass();
void registerTestSPIRVCPURunnerPipeline();
void registerTestSPIRVFuncSignatureConversion();
void registerTestSPIRVVectorUnrolling();
void registerTestTensorCopyInsertionPass();
Expand Down Expand Up @@ -278,6 +279,7 @@ void registerTestPasses() {
mlir::test::registerTestSCFWrapInZeroTripCheckPasses();
mlir::test::registerTestShapeMappingPass();
mlir::test::registerTestSliceAnalysisPass();
mlir::test::registerTestSPIRVCPURunnerPipeline();
mlir::test::registerTestSPIRVFuncSignatureConversion();
mlir::test::registerTestSPIRVVectorUnrolling();
mlir::test::registerTestTensorCopyInsertionPass();
Expand Down
24 changes: 0 additions & 24 deletions mlir/tools/mlir-spirv-cpu-runner/mlir-spirv-cpu-runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,12 @@
//
//===----------------------------------------------------------------------===//

#include "mlir/Conversion/FuncToLLVM/ConvertFuncToLLVMPass.h"
#include "mlir/Conversion/GPUToSPIRV/GPUToSPIRVPass.h"
#include "mlir/Conversion/SPIRVToLLVM/SPIRVToLLVMPass.h"
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/GPU/IR/GPUDialect.h"
#include "mlir/Dialect/GPU/Transforms/Passes.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
#include "mlir/Dialect/SPIRV/Transforms/Passes.h"
#include "mlir/ExecutionEngine/JitRunner.h"
#include "mlir/ExecutionEngine/OptUtils.h"
#include "mlir/Pass/Pass.h"
Expand Down Expand Up @@ -75,31 +69,13 @@ convertMLIRModule(Operation *op, llvm::LLVMContext &context) {
return mainModule;
}

static LogicalResult runMLIRPasses(Operation *module,
JitRunnerOptions &options) {
PassManager passManager(module->getContext(),
module->getName().getStringRef());
if (failed(applyPassManagerCLOptions(passManager)))
return failure();
passManager.addPass(createGpuKernelOutliningPass());
passManager.addPass(createConvertGPUToSPIRVPass(/*mapMemorySpace=*/true));

OpPassManager &nestedPM = passManager.nest<spirv::ModuleOp>();
nestedPM.addPass(spirv::createSPIRVLowerABIAttributesPass());
nestedPM.addPass(spirv::createSPIRVUpdateVCEPass());
passManager.addPass(createLowerHostCodeToLLVMPass());
passManager.addPass(createConvertSPIRVToLLVMPass());
return passManager.run(module);
}

int main(int argc, char **argv) {
llvm::InitLLVM y(argc, argv);

llvm::InitializeNativeTarget();
llvm::InitializeNativeTargetAsmPrinter();

mlir::JitRunnerConfig jitRunnerConfig;
jitRunnerConfig.mlirTransformer = runMLIRPasses;
jitRunnerConfig.llvmModuleBuilder = convertMLIRModule;

mlir::DialectRegistry registry;
Expand Down
Loading