summaryrefslogtreecommitdiffstats
path: root/mlir/lib/Conversion/GPUToSPIRV
diff options
context:
space:
mode:
Diffstat (limited to 'mlir/lib/Conversion/GPUToSPIRV')
-rw-r--r--mlir/lib/Conversion/GPUToSPIRV/CMakeLists.txt7
-rw-r--r--mlir/lib/Conversion/GPUToSPIRV/ConvertGPUToSPIRV.cpp55
-rw-r--r--mlir/lib/Conversion/GPUToSPIRV/ConvertGPUToSPIRVPass.cpp15
-rw-r--r--mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRV.td22
4 files changed, 50 insertions, 49 deletions
diff --git a/mlir/lib/Conversion/GPUToSPIRV/CMakeLists.txt b/mlir/lib/Conversion/GPUToSPIRV/CMakeLists.txt
index be82894461d..adeb4e099ab 100644
--- a/mlir/lib/Conversion/GPUToSPIRV/CMakeLists.txt
+++ b/mlir/lib/Conversion/GPUToSPIRV/CMakeLists.txt
@@ -1,8 +1,15 @@
+set(LLVM_TARGET_DEFINITIONS GPUToSPIRV.td)
+mlir_tablegen(GPUToSPIRV.cpp.inc -gen-rewriters)
+add_public_tablegen_target(MLIRGPUToSPIRVIncGen)
+
add_llvm_library(MLIRGPUtoSPIRVTransforms
ConvertGPUToSPIRV.cpp
ConvertGPUToSPIRVPass.cpp
)
+add_dependencies(MLIRGPUtoSPIRVTransforms
+ MLIRGPUToSPIRVIncGen)
+
target_link_libraries(MLIRGPUtoSPIRVTransforms
MLIRGPU
MLIRIR
diff --git a/mlir/lib/Conversion/GPUToSPIRV/ConvertGPUToSPIRV.cpp b/mlir/lib/Conversion/GPUToSPIRV/ConvertGPUToSPIRV.cpp
index 2fd8cedfd63..a90cea99be4 100644
--- a/mlir/lib/Conversion/GPUToSPIRV/ConvertGPUToSPIRV.cpp
+++ b/mlir/lib/Conversion/GPUToSPIRV/ConvertGPUToSPIRV.cpp
@@ -63,27 +63,13 @@ private:
SmallVector<int32_t, 3> workGroupSizeAsInt32;
};
-/// Pattern to convert a module with gpu.kernel_module attribute to a
-/// spv.module.
-class KernelModuleConversion final : public SPIRVOpLowering<ModuleOp> {
+/// Pattern to convert a gpu.module to a spv.module.
+class GPUModuleConversion final : public SPIRVOpLowering<gpu::GPUModuleOp> {
public:
- using SPIRVOpLowering<ModuleOp>::SPIRVOpLowering;
+ using SPIRVOpLowering<gpu::GPUModuleOp>::SPIRVOpLowering;
PatternMatchResult
- matchAndRewrite(ModuleOp moduleOp, ArrayRef<Value> operands,
- ConversionPatternRewriter &rewriter) const override;
-};
-
-/// Pattern to convert a module terminator op to a terminator of spv.module op.
-// TODO: Move this into DRR, but that requires ModuleTerminatorOp to be defined
-// in ODS.
-class KernelModuleTerminatorConversion final
- : public SPIRVOpLowering<ModuleTerminatorOp> {
-public:
- using SPIRVOpLowering<ModuleTerminatorOp>::SPIRVOpLowering;
-
- PatternMatchResult
- matchAndRewrite(ModuleTerminatorOp terminatorOp, ArrayRef<Value> operands,
+ matchAndRewrite(gpu::GPUModuleOp moduleOp, ArrayRef<Value> operands,
ConversionPatternRewriter &rewriter) const override;
};
@@ -284,16 +270,12 @@ KernelFnConversion::matchAndRewrite(gpu::GPUFuncOp funcOp,
}
//===----------------------------------------------------------------------===//
-// ModuleOp with gpu.kernel_module.
+// ModuleOp with gpu.module.
//===----------------------------------------------------------------------===//
-PatternMatchResult KernelModuleConversion::matchAndRewrite(
- ModuleOp moduleOp, ArrayRef<Value> operands,
+PatternMatchResult GPUModuleConversion::matchAndRewrite(
+ gpu::GPUModuleOp moduleOp, ArrayRef<Value> operands,
ConversionPatternRewriter &rewriter) const {
- if (!moduleOp.getAttrOfType<UnitAttr>(
- gpu::GPUDialect::getKernelModuleAttrName())) {
- return matchFailure();
- }
// TODO : Generalize this to account for different extensions,
// capabilities, extended_instruction_sets, other addressing models
// and memory models.
@@ -302,8 +284,8 @@ PatternMatchResult KernelModuleConversion::matchAndRewrite(
spirv::MemoryModel::GLSL450, spirv::Capability::Shader,
spirv::Extension::SPV_KHR_storage_buffer_storage_class);
// Move the region from the module op into the SPIR-V module.
- Region &spvModuleRegion = spvModule.getOperation()->getRegion(0);
- rewriter.inlineRegionBefore(moduleOp.getBodyRegion(), spvModuleRegion,
+ Region &spvModuleRegion = spvModule.body();
+ rewriter.inlineRegionBefore(moduleOp.body(), spvModuleRegion,
spvModuleRegion.begin());
// The spv.module build method adds a block with a terminator. Remove that
// block. The terminator of the module op in the remaining block will be
@@ -314,17 +296,6 @@ PatternMatchResult KernelModuleConversion::matchAndRewrite(
}
//===----------------------------------------------------------------------===//
-// ModuleTerminatorOp for gpu.kernel_module.
-//===----------------------------------------------------------------------===//
-
-PatternMatchResult KernelModuleTerminatorConversion::matchAndRewrite(
- ModuleTerminatorOp terminatorOp, ArrayRef<Value> operands,
- ConversionPatternRewriter &rewriter) const {
- rewriter.replaceOpWithNewOp<spirv::ModuleEndOp>(terminatorOp);
- return matchSuccess();
-}
-
-//===----------------------------------------------------------------------===//
// GPU return inside kernel functions to SPIR-V return.
//===----------------------------------------------------------------------===//
@@ -342,14 +313,18 @@ PatternMatchResult GPUReturnOpConversion::matchAndRewrite(
// GPU To SPIRV Patterns.
//===----------------------------------------------------------------------===//
+namespace {
+#include "GPUToSPIRV.cpp.inc"
+}
+
void mlir::populateGPUToSPIRVPatterns(MLIRContext *context,
SPIRVTypeConverter &typeConverter,
OwningRewritePatternList &patterns,
ArrayRef<int64_t> workGroupSize) {
+ populateWithGenerated(context, &patterns);
patterns.insert<KernelFnConversion>(context, typeConverter, workGroupSize);
patterns.insert<
- GPUReturnOpConversion, ForOpConversion, KernelModuleConversion,
- KernelModuleTerminatorConversion,
+ GPUReturnOpConversion, ForOpConversion, GPUModuleConversion,
LaunchConfigConversion<gpu::BlockDimOp, spirv::BuiltIn::WorkgroupSize>,
LaunchConfigConversion<gpu::BlockIdOp, spirv::BuiltIn::WorkgroupId>,
LaunchConfigConversion<gpu::GridDimOp, spirv::BuiltIn::NumWorkgroups>,
diff --git a/mlir/lib/Conversion/GPUToSPIRV/ConvertGPUToSPIRVPass.cpp b/mlir/lib/Conversion/GPUToSPIRV/ConvertGPUToSPIRVPass.cpp
index 68392c36765..bc8273ec2a9 100644
--- a/mlir/lib/Conversion/GPUToSPIRV/ConvertGPUToSPIRVPass.cpp
+++ b/mlir/lib/Conversion/GPUToSPIRV/ConvertGPUToSPIRVPass.cpp
@@ -60,15 +60,12 @@ void GPUToSPIRVPass::runOnModule() {
SmallVector<Operation *, 1> kernelModules;
OpBuilder builder(context);
- module.walk([&builder, &kernelModules](ModuleOp moduleOp) {
- if (moduleOp.getAttrOfType<UnitAttr>(
- gpu::GPUDialect::getKernelModuleAttrName())) {
- // For each kernel module (should be only 1 for now, but that is not a
- // requirement here), clone the module for conversion because the
- // gpu.launch function still needs the kernel module.
- builder.setInsertionPoint(moduleOp.getOperation());
- kernelModules.push_back(builder.clone(*moduleOp.getOperation()));
- }
+ module.walk([&builder, &kernelModules](gpu::GPUModuleOp moduleOp) {
+ // For each kernel module (should be only 1 for now, but that is not a
+ // requirement here), clone the module for conversion because the
+ // gpu.launch function still needs the kernel module.
+ builder.setInsertionPoint(moduleOp.getOperation());
+ kernelModules.push_back(builder.clone(*moduleOp.getOperation()));
});
SPIRVTypeConverter typeConverter;
diff --git a/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRV.td b/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRV.td
new file mode 100644
index 00000000000..cfe9d26273c
--- /dev/null
+++ b/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRV.td
@@ -0,0 +1,22 @@
+//===-- GPUToSPIRV.td - GPU to SPIR-V Dialect Lowerings ----*- tablegen -*-===//
+//
+// Part of the MLIR 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
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains patterns to lower GPU dialect ops to to SPIR-V ops.
+//
+//===----------------------------------------------------------------------===//
+
+
+#ifndef CONVERT_GPU_TO_SPIRV
+#define CONVERT_GPU_TO_SPIRV
+
+include "mlir/Dialect/GPU/GPUOps.td"
+include "mlir/Dialect/SPIRV/SPIRVStructureOps.td"
+
+def : Pat<(GPU_ModuleEndOp), (SPV_ModuleEndOp)>;
+
+#endif // CONVERT_GPU_TO_SPIRV
OpenPOWER on IntegriCloud