Skip to content

[mlir][spirv] Make ConvertToSPIRVPass into a test pass (non-public) #124301

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

This file was deleted.

1 change: 0 additions & 1 deletion mlir/include/mlir/Conversion/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include "mlir/Conversion/ControlFlowToSPIRV/ControlFlowToSPIRV.h"
#include "mlir/Conversion/ControlFlowToSPIRV/ControlFlowToSPIRVPass.h"
#include "mlir/Conversion/ConvertToLLVM/ToLLVMPass.h"
#include "mlir/Conversion/ConvertToSPIRV/ConvertToSPIRVPass.h"
#include "mlir/Conversion/FuncToEmitC/FuncToEmitCPass.h"
#include "mlir/Conversion/FuncToLLVM/ConvertFuncToLLVMPass.h"
#include "mlir/Conversion/FuncToSPIRV/FuncToSPIRVPass.h"
Expand Down
29 changes: 0 additions & 29 deletions mlir/include/mlir/Conversion/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -39,35 +39,6 @@ def ConvertToLLVMPass : Pass<"convert-to-llvm"> {
];
}

//===----------------------------------------------------------------------===//
// ToSPIRV
//===----------------------------------------------------------------------===//

def ConvertToSPIRVPass : Pass<"convert-to-spirv"> {
let summary = "Convert to SPIR-V";
let description = [{
This is a generic pass to convert to SPIR-V.
}];
let dependentDialects = [
"spirv::SPIRVDialect",
"vector::VectorDialect",
];
let options = [
Option<"runSignatureConversion", "run-signature-conversion", "bool",
/*default=*/"true",
"Run function signature conversion to convert vector types">,
Option<"runVectorUnrolling", "run-vector-unrolling", "bool",
/*default=*/"true",
"Run vector unrolling to convert vector types in function bodies">,
Option<"convertGPUModules", "convert-gpu-modules", "bool",
/*default=*/"false",
"Clone and convert GPU modules">,
Option<"nestInGPUModule", "nest-in-gpu-module", "bool",
/*default=*/"false",
"Put converted SPIR-V module inside the gpu.module instead of alongside it.">,
];
}

//===----------------------------------------------------------------------===//
// AffineToStandard
//===----------------------------------------------------------------------===//
Expand Down
1 change: 0 additions & 1 deletion mlir/lib/Conversion/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ add_subdirectory(ControlFlowToLLVM)
add_subdirectory(ControlFlowToSCF)
add_subdirectory(ControlFlowToSPIRV)
add_subdirectory(ConvertToLLVM)
add_subdirectory(ConvertToSPIRV)
add_subdirectory(FuncToEmitC)
add_subdirectory(FuncToLLVM)
add_subdirectory(FuncToSPIRV)
Expand Down
36 changes: 0 additions & 36 deletions mlir/lib/Conversion/ConvertToSPIRV/CMakeLists.txt

This file was deleted.

2 changes: 1 addition & 1 deletion mlir/test/Conversion/ConvertToSPIRV/argmax-kernel.mlir
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: mlir-opt -convert-to-spirv -cse %s | FileCheck %s
// RUN: mlir-opt -test-convert-to-spirv -cse %s | FileCheck %s

module attributes {
gpu.container_module,
Expand Down
2 changes: 1 addition & 1 deletion mlir/test/Conversion/ConvertToSPIRV/arith.mlir
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: mlir-opt -convert-to-spirv="run-signature-conversion=false run-vector-unrolling=false" -split-input-file %s | FileCheck %s
// RUN: mlir-opt -test-convert-to-spirv="run-signature-conversion=false run-vector-unrolling=false" -split-input-file %s | FileCheck %s

//===----------------------------------------------------------------------===//
// arithmetic ops
Expand Down
2 changes: 1 addition & 1 deletion mlir/test/Conversion/ConvertToSPIRV/combined.mlir
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: mlir-opt -convert-to-spirv="run-signature-conversion=false run-vector-unrolling=false" -split-input-file %s | FileCheck %s
// RUN: mlir-opt -test-convert-to-spirv="run-signature-conversion=false run-vector-unrolling=false" -split-input-file %s | FileCheck %s

// CHECK-LABEL: @combined
// CHECK: %[[C0_F32:.*]] = spirv.Constant 0.000000e+00 : f32
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: mlir-opt -convert-to-spirv="convert-gpu-modules=true nest-in-gpu-module=true run-signature-conversion=false run-vector-unrolling=false" %s | FileCheck %s
// RUN: mlir-opt -test-convert-to-spirv="convert-gpu-modules=true nest-in-gpu-module=true run-signature-conversion=false run-vector-unrolling=false" %s | FileCheck %s

module attributes {
gpu.container_module,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: mlir-opt -convert-to-spirv="convert-gpu-modules=true run-signature-conversion=false run-vector-unrolling=false" -split-input-file %s | FileCheck %s
// RUN: mlir-opt -test-convert-to-spirv="convert-gpu-modules=true run-signature-conversion=false run-vector-unrolling=false" -split-input-file %s | FileCheck %s

module attributes {
gpu.container_module,
Expand Down
2 changes: 1 addition & 1 deletion mlir/test/Conversion/ConvertToSPIRV/gpu.mlir
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: mlir-opt -convert-to-spirv -split-input-file %s | FileCheck %s
// RUN: mlir-opt -test-convert-to-spirv -split-input-file %s | FileCheck %s

module attributes {
gpu.container_module,
Expand Down
2 changes: 1 addition & 1 deletion mlir/test/Conversion/ConvertToSPIRV/index.mlir
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: mlir-opt -convert-to-spirv="run-signature-conversion=false run-vector-unrolling=false" -split-input-file %s | FileCheck %s
// RUN: mlir-opt -test-convert-to-spirv="run-signature-conversion=false run-vector-unrolling=false" -split-input-file %s | FileCheck %s

// CHECK-LABEL: @basic
func.func @basic(%a: index, %b: index) {
Expand Down
2 changes: 1 addition & 1 deletion mlir/test/Conversion/ConvertToSPIRV/memref.mlir
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: mlir-opt -convert-to-spirv="run-signature-conversion=false run-vector-unrolling=false" -cse %s | FileCheck %s
// RUN: mlir-opt -test-convert-to-spirv="run-signature-conversion=false run-vector-unrolling=false" -cse %s | FileCheck %s

module attributes {
spirv.target_env = #spirv.target_env<
Expand Down
2 changes: 1 addition & 1 deletion mlir/test/Conversion/ConvertToSPIRV/scf.mlir
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: mlir-opt -convert-to-spirv="run-signature-conversion=false run-vector-unrolling=false" -split-input-file %s | FileCheck %s
// RUN: mlir-opt -test-convert-to-spirv="run-signature-conversion=false run-vector-unrolling=false" -split-input-file %s | FileCheck %s

// CHECK-LABEL: @if_yield
// CHECK: %[[VAR:.*]] = spirv.Variable : !spirv.ptr<f32, Function>
Expand Down
2 changes: 1 addition & 1 deletion mlir/test/Conversion/ConvertToSPIRV/simple.mlir
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: mlir-opt -convert-to-spirv="run-signature-conversion=false run-vector-unrolling=false" -split-input-file %s | FileCheck %s
// RUN: mlir-opt -test-convert-to-spirv="run-signature-conversion=false run-vector-unrolling=false" -split-input-file %s | FileCheck %s

// CHECK-LABEL: @return_scalar
// CHECK-SAME: %[[ARG0:.*]]: i32
Expand Down
2 changes: 1 addition & 1 deletion mlir/test/Conversion/ConvertToSPIRV/ub.mlir
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: mlir-opt -convert-to-spirv="run-signature-conversion=false run-vector-unrolling=false" -split-input-file %s | FileCheck %s
// RUN: mlir-opt -test-convert-to-spirv="run-signature-conversion=false run-vector-unrolling=false" -split-input-file %s | FileCheck %s

// CHECK-LABEL: @ub
// CHECK: %[[UNDEF:.*]] = spirv.Undef : i32
Expand Down
2 changes: 1 addition & 1 deletion mlir/test/Conversion/ConvertToSPIRV/vector.mlir
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: mlir-opt -convert-to-spirv="run-signature-conversion=false run-vector-unrolling=false" -split-input-file %s | FileCheck %s
// RUN: mlir-opt -test-convert-to-spirv="run-signature-conversion=false run-vector-unrolling=false" -split-input-file %s | FileCheck %s

// CHECK-LABEL: @extract
// CHECK-SAME: %[[ARG:.+]]: vector<2xf32>
Expand Down
1 change: 1 addition & 0 deletions mlir/test/lib/Pass/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
# Exclude tests from libMLIR.so
add_mlir_library(MLIRTestPass
TestConvertToSPIRVPass.cpp
TestDynamicPipeline.cpp
TestPassManager.cpp
TestSPIRVCPURunnerPipeline.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//
//===----------------------------------------------------------------------===//

#include "mlir/Conversion/ConvertToSPIRV/ConvertToSPIRVPass.h"
#include "mlir/Conversion/ArithToSPIRV/ArithToSPIRV.h"
#include "mlir/Conversion/FuncToSPIRV/FuncToSPIRV.h"
#include "mlir/Conversion/GPUToSPIRV/GPUToSPIRV.h"
Expand All @@ -24,16 +23,12 @@
#include "mlir/Dialect/Vector/Transforms/VectorRewritePatterns.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Pass/PassOptions.h"
#include "mlir/Rewrite/FrozenRewritePatternSet.h"
#include "mlir/Transforms/DialectConversion.h"
#include <memory>

#define DEBUG_TYPE "convert-to-spirv"

namespace mlir {
#define GEN_PASS_DEF_CONVERTTOSPIRVPASS
#include "mlir/Conversion/Passes.h.inc"
} // namespace mlir
#define DEBUG_TYPE "test-convert-to-spirv"

using namespace mlir;

Expand Down Expand Up @@ -69,9 +64,44 @@ void populateConvertToSPIRVPatterns(const SPIRVTypeConverter &typeConverter,
}

/// A pass to perform the SPIR-V conversion.
struct ConvertToSPIRVPass final
: impl::ConvertToSPIRVPassBase<ConvertToSPIRVPass> {
using ConvertToSPIRVPassBase::ConvertToSPIRVPassBase;
struct TestConvertToSPIRVPass final
: PassWrapper<TestConvertToSPIRVPass, OperationPass<>> {
Option<bool> runSignatureConversion{
*this, "run-signature-conversion",
llvm::cl::desc(
"Run function signature conversion to convert vector types"),
llvm::cl::init(true)};
Option<bool> runVectorUnrolling{
*this, "run-vector-unrolling",
llvm::cl::desc(
"Run vector unrolling to convert vector types in function bodies"),
llvm::cl::init(true)};
Option<bool> convertGPUModules{
*this, "convert-gpu-modules",
llvm::cl::desc("Clone and convert GPU modules"), llvm::cl::init(false)};
Option<bool> nestInGPUModule{
*this, "nest-in-gpu-module",
llvm::cl::desc("Put converted SPIR-V module inside the gpu.module "
"instead of alongside it."),
llvm::cl::init(false)};

MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestConvertToSPIRVPass)

StringRef getArgument() const final { return "test-convert-to-spirv"; }
StringRef getDescription() const final {
return "Conversion to SPIR-V pass only used for internal tests.";
}
void getDependentDialects(DialectRegistry &registry) const override {
registry.insert<spirv::SPIRVDialect>();
registry.insert<vector::VectorDialect>();
}

TestConvertToSPIRVPass() = default;
TestConvertToSPIRVPass(bool convertGPUModules, bool nestInGPUModule) {
this->convertGPUModules = convertGPUModules;
this->nestInGPUModule = nestInGPUModule;
};
TestConvertToSPIRVPass(const TestConvertToSPIRVPass &) {}

void runOnOperation() override {
Operation *op = getOperation();
Expand Down Expand Up @@ -132,3 +162,14 @@ struct ConvertToSPIRVPass final
};

} // namespace

namespace mlir::test {
void registerTestConvertToSPIRVPass() {
PassRegistration<TestConvertToSPIRVPass>();
}
std::unique_ptr<Pass> createTestConvertToSPIRVPass(bool convertGPUModules,
bool nestInGPUModule) {
return std::make_unique<TestConvertToSPIRVPass>(convertGPUModules,
nestInGPUModule);
}
} // namespace mlir::test
13 changes: 8 additions & 5 deletions mlir/test/lib/Pass/TestVulkanRunnerPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
//
//===----------------------------------------------------------------------===//

#include "mlir/Conversion/ConvertToSPIRV/ConvertToSPIRVPass.h"
#include "mlir/Conversion/GPUCommon/GPUCommonPass.h"
#include "mlir/Conversion/GPUToSPIRV/GPUToSPIRVPass.h"
#include "mlir/Conversion/MemRefToLLVM/MemRefToLLVM.h"
Expand All @@ -26,6 +25,12 @@

using namespace mlir;

// Defined in the test directory, no public header.
namespace mlir::test {
std::unique_ptr<Pass> createTestConvertToSPIRVPass(bool convertGPUModules,
bool nestInGPUModule);
}

namespace {

struct VulkanRunnerPipelineOptions
Expand All @@ -47,10 +52,8 @@ void buildTestVulkanRunnerPipeline(OpPassManager &passManager,
"SPV_KHR_storage_buffer_storage_class");
passManager.addPass(createGpuSPIRVAttachTarget(attachTargetOptions));

ConvertToSPIRVPassOptions convertToSPIRVOptions{};
convertToSPIRVOptions.convertGPUModules = true;
convertToSPIRVOptions.nestInGPUModule = true;
passManager.addPass(createConvertToSPIRVPass(convertToSPIRVOptions));
passManager.addPass(test::createTestConvertToSPIRVPass(
/*convertGPUModules=*/true, /*nestInGPUModule=*/true));

OpPassManager &spirvModulePM =
passManager.nest<gpu::GPUModuleOp>().nest<spirv::ModuleOp>();
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 @@ -87,6 +87,7 @@ void registerTestComposeSubView();
void registerTestCompositePass();
void registerTestConstantFold();
void registerTestControlFlowSink();
void registerTestConvertToSPIRVPass();
void registerTestDataLayoutPropagation();
void registerTestDataLayoutQuery();
void registerTestDeadCodeAnalysisPass();
Expand Down Expand Up @@ -226,6 +227,7 @@ void registerTestPasses() {
mlir::test::registerTestCompositePass();
mlir::test::registerTestConstantFold();
mlir::test::registerTestControlFlowSink();
mlir::test::registerTestConvertToSPIRVPass();
mlir::test::registerTestDataLayoutPropagation();
mlir::test::registerTestDataLayoutQuery();
mlir::test::registerTestDeadCodeAnalysisPass();
Expand Down