Skip to content

[mlir][mlir-vulkan-runner] Move part of device pass pipeline to mlir-opt #119372

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 @@ -4,6 +4,7 @@ add_mlir_library(MLIRTestPass
TestDynamicPipeline.cpp
TestPassManager.cpp
TestSPIRVCPURunnerPipeline.cpp
TestVulkanRunnerPipeline.cpp

EXCLUDE_FROM_LIBMLIR

Expand Down
47 changes: 47 additions & 0 deletions mlir/test/lib/Pass/TestVulkanRunnerPipeline.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//===------------------ 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::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 mlir::test
3 changes: 2 additions & 1 deletion mlir/test/mlir-vulkan-runner/addf.mlir
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion mlir/test/mlir-vulkan-runner/addf_if.mlir
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion mlir/test/mlir-vulkan-runner/addi.mlir
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion mlir/test/mlir-vulkan-runner/addi8.mlir
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
14 changes: 8 additions & 6 deletions mlir/test/mlir-vulkan-runner/addui_extended.mlir
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// 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: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
// RUN: --entry-point-result=void | FileCheck %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: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
// RUN: --entry-point-result=void | FileCheck %s
// 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

// CHECK: [0, 42, 0, 42]
// CHECK: [1, 0, 1, 1]
Expand Down
3 changes: 2 additions & 1 deletion mlir/test/mlir-vulkan-runner/mulf.mlir
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
14 changes: 8 additions & 6 deletions mlir/test/mlir-vulkan-runner/smul_extended.mlir
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// 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: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
// RUN: --entry-point-result=void | FileCheck %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: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
// RUN: --entry-point-result=void | FileCheck %s
// 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

// CHECK: [0, 1, -2, 1, 1048560, -87620295, -131071, 560969770]
// CHECK: [0, 0, -1, 0, 0, -1, 0, -499807318]
Expand Down
3 changes: 2 additions & 1 deletion mlir/test/mlir-vulkan-runner/subf.mlir
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion mlir/test/mlir-vulkan-runner/time.mlir
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 8 additions & 6 deletions mlir/test/mlir-vulkan-runner/umul_extended.mlir
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// 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: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
// RUN: --entry-point-result=void | FileCheck %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: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
// RUN: --entry-point-result=void | FileCheck %s
// 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

// CHECK: [0, 1, -2, 1, 1048560, -87620295, -131071, -49]
// CHECK: [0, 0, 1, -2, 0, 65534, -131070, 6]
Expand Down
7 changes: 4 additions & 3 deletions mlir/test/mlir-vulkan-runner/vector-deinterleave.mlir
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// RUN: mlir-vulkan-runner %s \
// RUN: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
// RUN: --entry-point-result=void | FileCheck %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

// CHECK: [0, 2]
// CHECK: [1, 3]
Expand Down
7 changes: 4 additions & 3 deletions mlir/test/mlir-vulkan-runner/vector-interleave.mlir
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// RUN: mlir-vulkan-runner %s \
// RUN: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
// RUN: --entry-point-result=void | FileCheck %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

// CHECK: [0, 2, 1, 3]
module attributes {
Expand Down
7 changes: 4 additions & 3 deletions mlir/test/mlir-vulkan-runner/vector-shuffle.mlir
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// RUN: mlir-vulkan-runner %s \
// RUN: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
// RUN: --entry-point-result=void | FileCheck %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

// CHECK: [2, 1, 3, 3]
module attributes {
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 @@ -153,6 +153,7 @@ void registerTestTransformDialectEraseSchedulePass();
void registerTestPassStateExtensionCommunication();
void registerTestVectorLowerings();
void registerTestVectorReductionToSPIRVDotProd();
void registerTestVulkanRunnerPipeline();
void registerTestWrittenToPass();
#if MLIR_ENABLE_PDL_IN_PATTERNMATCH
void registerTestDialectConversionPasses();
Expand Down Expand Up @@ -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();
Expand Down
38 changes: 2 additions & 36 deletions mlir/tools/mlir-vulkan-runner/mlir-vulkan-runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -43,37 +39,14 @@

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");
PassManager passManager(module.getContext());
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());
Expand All @@ -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,
Expand Down
Loading