-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[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
[mlir][spirv] Make ConvertToSPIRVPass into a test pass (non-public) #124301
Conversation
@llvm/pr-subscribers-mlir-spirv @llvm/pr-subscribers-mlir-core Author: Andrea Faulds (andfau-amd) ChangesWith the removal of mlir-vulkan-runner (as part of #73457) in e7e3c45, this pass no longer has to be public (previously it had to be so the runner could use it). This commit makes it instead only available for use by mlir-opt. Full diff: https://github.com/llvm/llvm-project/pull/124301.diff 19 Files Affected:
diff --git a/mlir/include/mlir/Conversion/Passes.td b/mlir/include/mlir/Conversion/Passes.td
index b547839d76738c..f2841a1e879dbe 100644
--- a/mlir/include/mlir/Conversion/Passes.td
+++ b/mlir/include/mlir/Conversion/Passes.td
@@ -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
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/Conversion/CMakeLists.txt b/mlir/lib/Conversion/CMakeLists.txt
index a570978f03757c..0bd08ec6333e68 100644
--- a/mlir/lib/Conversion/CMakeLists.txt
+++ b/mlir/lib/Conversion/CMakeLists.txt
@@ -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)
diff --git a/mlir/lib/Conversion/ConvertToSPIRV/CMakeLists.txt b/mlir/lib/Conversion/ConvertToSPIRV/CMakeLists.txt
deleted file mode 100644
index 124a4c453e75c5..00000000000000
--- a/mlir/lib/Conversion/ConvertToSPIRV/CMakeLists.txt
+++ /dev/null
@@ -1,36 +0,0 @@
-set(LLVM_OPTIONAL_SOURCES
- ConvertToSPIRVPass.cpp
-)
-
-add_mlir_conversion_library(MLIRConvertToSPIRVPass
- ConvertToSPIRVPass.cpp
-
- ADDITIONAL_HEADER_DIRS
- ${MLIR_MAIN_INCLUDE_DIR}/mlir/Conversion/ConvertToSPIRV
-
- DEPENDS
- MLIRConversionPassIncGen
-
- LINK_LIBS PUBLIC
- MLIRArithToSPIRV
- MLIRArithTransforms
- MLIRFuncToSPIRV
- MLIRGPUDialect
- MLIRGPUToSPIRV
- MLIRIndexToSPIRV
- MLIRIR
- MLIRMemRefToSPIRV
- MLIRPass
- MLIRRewrite
- MLIRSCFToSPIRV
- MLIRSPIRVConversion
- MLIRSPIRVDialect
- MLIRSPIRVTransforms
- MLIRSupport
- MLIRTransforms
- MLIRTransformUtils
- MLIRUBToSPIRV
- MLIRVectorDialect
- MLIRVectorToSPIRV
- MLIRVectorTransforms
- )
diff --git a/mlir/test/Conversion/ConvertToSPIRV/argmax-kernel.mlir b/mlir/test/Conversion/ConvertToSPIRV/argmax-kernel.mlir
index 652f4472280869..81ac2a04f3362a 100644
--- a/mlir/test/Conversion/ConvertToSPIRV/argmax-kernel.mlir
+++ b/mlir/test/Conversion/ConvertToSPIRV/argmax-kernel.mlir
@@ -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,
diff --git a/mlir/test/Conversion/ConvertToSPIRV/arith.mlir b/mlir/test/Conversion/ConvertToSPIRV/arith.mlir
index 6418e931f74605..d9a33a1f7b6e8a 100644
--- a/mlir/test/Conversion/ConvertToSPIRV/arith.mlir
+++ b/mlir/test/Conversion/ConvertToSPIRV/arith.mlir
@@ -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
diff --git a/mlir/test/Conversion/ConvertToSPIRV/combined.mlir b/mlir/test/Conversion/ConvertToSPIRV/combined.mlir
index 311174bef15ed6..3039ed58463eae 100644
--- a/mlir/test/Conversion/ConvertToSPIRV/combined.mlir
+++ b/mlir/test/Conversion/ConvertToSPIRV/combined.mlir
@@ -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
diff --git a/mlir/test/Conversion/ConvertToSPIRV/convert-gpu-modules-nested.mlir b/mlir/test/Conversion/ConvertToSPIRV/convert-gpu-modules-nested.mlir
index 7562de17c606ee..5b12a656a2bf88 100644
--- a/mlir/test/Conversion/ConvertToSPIRV/convert-gpu-modules-nested.mlir
+++ b/mlir/test/Conversion/ConvertToSPIRV/convert-gpu-modules-nested.mlir
@@ -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,
diff --git a/mlir/test/Conversion/ConvertToSPIRV/convert-gpu-modules.mlir b/mlir/test/Conversion/ConvertToSPIRV/convert-gpu-modules.mlir
index 1fde6c34418fc5..00bbd1c27116a9 100644
--- a/mlir/test/Conversion/ConvertToSPIRV/convert-gpu-modules.mlir
+++ b/mlir/test/Conversion/ConvertToSPIRV/convert-gpu-modules.mlir
@@ -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,
diff --git a/mlir/test/Conversion/ConvertToSPIRV/gpu.mlir b/mlir/test/Conversion/ConvertToSPIRV/gpu.mlir
index 84f366e5874b03..3e197c076be6a2 100644
--- a/mlir/test/Conversion/ConvertToSPIRV/gpu.mlir
+++ b/mlir/test/Conversion/ConvertToSPIRV/gpu.mlir
@@ -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,
diff --git a/mlir/test/Conversion/ConvertToSPIRV/index.mlir b/mlir/test/Conversion/ConvertToSPIRV/index.mlir
index f4b116849fa93c..a7b892e358acbf 100644
--- a/mlir/test/Conversion/ConvertToSPIRV/index.mlir
+++ b/mlir/test/Conversion/ConvertToSPIRV/index.mlir
@@ -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) {
diff --git a/mlir/test/Conversion/ConvertToSPIRV/memref.mlir b/mlir/test/Conversion/ConvertToSPIRV/memref.mlir
index 5af8bfc842ea13..f7d17d1ad16da8 100644
--- a/mlir/test/Conversion/ConvertToSPIRV/memref.mlir
+++ b/mlir/test/Conversion/ConvertToSPIRV/memref.mlir
@@ -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<
diff --git a/mlir/test/Conversion/ConvertToSPIRV/scf.mlir b/mlir/test/Conversion/ConvertToSPIRV/scf.mlir
index 350ebcfe57b15b..fab45d47428501 100644
--- a/mlir/test/Conversion/ConvertToSPIRV/scf.mlir
+++ b/mlir/test/Conversion/ConvertToSPIRV/scf.mlir
@@ -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>
diff --git a/mlir/test/Conversion/ConvertToSPIRV/simple.mlir b/mlir/test/Conversion/ConvertToSPIRV/simple.mlir
index 00556140c3018b..aa4a963d1d69a0 100644
--- a/mlir/test/Conversion/ConvertToSPIRV/simple.mlir
+++ b/mlir/test/Conversion/ConvertToSPIRV/simple.mlir
@@ -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
diff --git a/mlir/test/Conversion/ConvertToSPIRV/ub.mlir b/mlir/test/Conversion/ConvertToSPIRV/ub.mlir
index f34ca01c94f00b..e8ffcd4237ed28 100644
--- a/mlir/test/Conversion/ConvertToSPIRV/ub.mlir
+++ b/mlir/test/Conversion/ConvertToSPIRV/ub.mlir
@@ -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
diff --git a/mlir/test/Conversion/ConvertToSPIRV/vector.mlir b/mlir/test/Conversion/ConvertToSPIRV/vector.mlir
index e369eadca57302..510f7a2d94c9ec 100644
--- a/mlir/test/Conversion/ConvertToSPIRV/vector.mlir
+++ b/mlir/test/Conversion/ConvertToSPIRV/vector.mlir
@@ -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>
diff --git a/mlir/test/lib/Pass/CMakeLists.txt b/mlir/test/lib/Pass/CMakeLists.txt
index 6698af86b8ae66..95e8e8d743f680 100644
--- a/mlir/test/lib/Pass/CMakeLists.txt
+++ b/mlir/test/lib/Pass/CMakeLists.txt
@@ -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
diff --git a/mlir/lib/Conversion/ConvertToSPIRV/ConvertToSPIRVPass.cpp b/mlir/test/lib/Pass/TestConvertToSPIRVPass.cpp
similarity index 72%
rename from mlir/lib/Conversion/ConvertToSPIRV/ConvertToSPIRVPass.cpp
rename to mlir/test/lib/Pass/TestConvertToSPIRVPass.cpp
index ab9c048f561069..68b7c0066a1dee 100644
--- a/mlir/lib/Conversion/ConvertToSPIRV/ConvertToSPIRVPass.cpp
+++ b/mlir/test/lib/Pass/TestConvertToSPIRVPass.cpp
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#include "mlir/Conversion/ConvertToSPIRV/ConvertToSPIRVPass.h"
#include "mlir/Conversion/ArithToSPIRV/ArithToSPIRV.h"
+#include "mlir/Conversion/ConvertToSPIRV/ConvertToSPIRVPass.h"
#include "mlir/Conversion/FuncToSPIRV/FuncToSPIRV.h"
#include "mlir/Conversion/GPUToSPIRV/GPUToSPIRV.h"
#include "mlir/Conversion/IndexToSPIRV/IndexToSPIRV.h"
@@ -25,12 +25,13 @@
#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 "mlir/Transforms/GreedyPatternRewriteDriver.h"
#include <memory>
-#define DEBUG_TYPE "convert-to-spirv"
+#define DEBUG_TYPE "test-convert-to-spirv"
namespace mlir {
#define GEN_PASS_DEF_CONVERTTOSPIRVPASS
@@ -71,9 +72,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 ®istry) const override {
+ registry.insert<spirv::SPIRVDialect>();
+ registry.insert<vector::VectorDialect>();
+ }
+
+ TestConvertToSPIRVPass() = default;
+ TestConvertToSPIRVPass(bool convertGPUModules, bool nestInGPUModule) {
+ this->convertGPUModules = std::move(convertGPUModules);
+ this->nestInGPUModule = std::move(nestInGPUModule);
+ };
+ TestConvertToSPIRVPass(const TestConvertToSPIRVPass &) {}
void runOnOperation() override {
Operation *op = getOperation();
@@ -134,3 +170,16 @@ struct ConvertToSPIRVPass final
};
} // namespace
+
+namespace mlir {
+namespace test {
+void registerTestConvertToSPIRVPass() {
+ PassRegistration<TestConvertToSPIRVPass>();
+}
+std::unique_ptr<Pass> createTestConvertToSPIRVPass(bool convertGPUModules,
+ bool nestInGPUModule) {
+ return std::make_unique<TestConvertToSPIRVPass>(convertGPUModules,
+ nestInGPUModule);
+}
+} // namespace test
+} // namespace mlir
diff --git a/mlir/test/lib/Pass/TestVulkanRunnerPipeline.cpp b/mlir/test/lib/Pass/TestVulkanRunnerPipeline.cpp
index e4cbbeb1f99bc4..333188b6911193 100644
--- a/mlir/test/lib/Pass/TestVulkanRunnerPipeline.cpp
+++ b/mlir/test/lib/Pass/TestVulkanRunnerPipeline.cpp
@@ -26,6 +26,14 @@
using namespace mlir;
+// Defined in the test directory, no public header.
+namespace mlir {
+namespace test {
+std::unique_ptr<Pass> createTestConvertToSPIRVPass(bool convertGPUModules,
+ bool nestInGPUModule);
+}
+} // namespace mlir
+
namespace {
struct VulkanRunnerPipelineOptions
@@ -47,10 +55,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>();
diff --git a/mlir/tools/mlir-opt/mlir-opt.cpp b/mlir/tools/mlir-opt/mlir-opt.cpp
index 960f7037a1b61f..74007d01347ae8 100644
--- a/mlir/tools/mlir-opt/mlir-opt.cpp
+++ b/mlir/tools/mlir-opt/mlir-opt.cpp
@@ -87,6 +87,7 @@ void registerTestComposeSubView();
void registerTestCompositePass();
void registerTestConstantFold();
void registerTestControlFlowSink();
+void registerTestConvertToSPIRVPass();
void registerTestDataLayoutPropagation();
void registerTestDataLayoutQuery();
void registerTestDeadCodeAnalysisPass();
@@ -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();
|
53fb2d9
to
82acfeb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just a few nits
f2f8ad6
to
d912d33
Compare
With the removal of mlir-vulkan-runner (as part of llvm#73457) in e7e3c45, this pass no longer has to be public (previously it had to be so the runner could use it). This commit makes it instead only available for use by mlir-opt.
d912d33
to
e6f0c99
Compare
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/89/builds/15482 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/138/builds/9605 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/80/builds/9342 Here is the relevant piece of the build log for the reference
|
Reverted in 4573c85, I must have missed some dependencies in the CMakeLists. |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/130/builds/9278 Here is the relevant piece of the build log for the reference
|
With the removal of mlir-vulkan-runner (as part of #73457) in e7e3c45, this pass no longer has to be public (previously it had to be so the runner could use it). This commit makes it instead only available for use by mlir-opt. This is a recommit of 058d183 (#124301) which had been reverted in 4573c85 due to a missing linker dependency on MLIRSPIRVTransforms in mlir/test/lib/Pass/CMakeLists.txt (fixed in this commit).
Recommitted as 25ae1a2. |
…s (non-public) (llvm#124301)"" This reverts commit 4573c85.
…ublic) (llvm#124301)" This reverts commit 058d183.
With the removal of mlir-vulkan-runner (as part of #73457) in e7e3c45, this pass no longer has to be public (previously it had to be so the runner could use it). This commit makes it instead only available for use by mlir-opt.