summaryrefslogtreecommitdiffstats
path: root/mlir/include
diff options
context:
space:
mode:
authorTres Popp <tpopp@google.com>2020-01-14 11:09:59 +0100
committerStephan Herhut <herhut@google.com>2020-01-14 12:05:47 +0100
commit4624a1e8ac8a3f69cc887403b976f538f587744a (patch)
tree13cb3b1371abedefbdbd7e09933633acc4aca44c /mlir/include
parent9492e9d8cfd356109276da5aa926b297db0e16db (diff)
downloadbcm5719-llvm-4624a1e8ac8a3f69cc887403b976f538f587744a.tar.gz
bcm5719-llvm-4624a1e8ac8a3f69cc887403b976f538f587744a.zip
[mlir] Create a gpu.module operation for the GPU Dialect.
Summary: This is based on the use of code constantly checking for an attribute on a model and instead represents the distinct operaion with a different op. Instead, this op can be used to provide better filtering. Reviewers: herhut, mravishankar, antiagainst, rriddle Reviewed By: herhut, antiagainst, rriddle Subscribers: liufengdb, aartbik, jholewinski, mgorny, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, nicolasvasilache, csigg, arpith-jacob, mgester, lucyrfox, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D72336
Diffstat (limited to 'mlir/include')
-rw-r--r--mlir/include/mlir/Conversion/GPUToCUDA/GPUToCUDAPass.h11
-rw-r--r--mlir/include/mlir/Conversion/GPUToNVVM/GPUToNVVMPass.h10
-rw-r--r--mlir/include/mlir/Dialect/GPU/GPUOps.td52
3 files changed, 67 insertions, 6 deletions
diff --git a/mlir/include/mlir/Conversion/GPUToCUDA/GPUToCUDAPass.h b/mlir/include/mlir/Conversion/GPUToCUDA/GPUToCUDAPass.h
index 4eb6379adf6..f61e40ef5f9 100644
--- a/mlir/include/mlir/Conversion/GPUToCUDA/GPUToCUDAPass.h
+++ b/mlir/include/mlir/Conversion/GPUToCUDA/GPUToCUDAPass.h
@@ -19,12 +19,17 @@ namespace mlir {
class Location;
class ModuleOp;
+template <typename T>
+class OpPassBase;
+
+namespace gpu {
+class GPUModuleOp;
+} // namespace gpu
+
namespace LLVM {
class LLVMDialect;
} // namespace LLVM
-template <typename T> class OpPassBase;
-
using OwnedCubin = std::unique_ptr<std::vector<char>>;
using CubinGenerator =
std::function<OwnedCubin(const std::string &, Location, StringRef)>;
@@ -38,7 +43,7 @@ using CubinGenerator =
/// attached as a string attribute named 'nvvm.cubin' to the kernel function.
/// After the transformation, the body of the kernel function is removed (i.e.,
/// it is turned into a declaration).
-std::unique_ptr<OpPassBase<ModuleOp>>
+std::unique_ptr<OpPassBase<gpu::GPUModuleOp>>
createConvertGPUKernelToCubinPass(CubinGenerator cubinGenerator);
/// Creates a pass to convert a gpu.launch_func operation into a sequence of
diff --git a/mlir/include/mlir/Conversion/GPUToNVVM/GPUToNVVMPass.h b/mlir/include/mlir/Conversion/GPUToNVVM/GPUToNVVMPass.h
index 75e4f7e374c..b3212279fab 100644
--- a/mlir/include/mlir/Conversion/GPUToNVVM/GPUToNVVMPass.h
+++ b/mlir/include/mlir/Conversion/GPUToNVVM/GPUToNVVMPass.h
@@ -14,15 +14,19 @@ namespace mlir {
class LLVMTypeConverter;
class OwningRewritePatternList;
-class ModuleOp;
-template <typename OpT> class OpPassBase;
+template <typename OpT>
+class OpPassBase;
+
+namespace gpu {
+class GPUModuleOp;
+}
/// Collect a set of patterns to convert from the GPU dialect to NVVM.
void populateGpuToNVVMConversionPatterns(LLVMTypeConverter &converter,
OwningRewritePatternList &patterns);
/// Creates a pass that lowers GPU dialect operations to NVVM counterparts.
-std::unique_ptr<OpPassBase<ModuleOp>> createLowerGpuOpsToNVVMOpsPass();
+std::unique_ptr<OpPassBase<gpu::GPUModuleOp>> createLowerGpuOpsToNVVMOpsPass();
} // namespace mlir
diff --git a/mlir/include/mlir/Dialect/GPU/GPUOps.td b/mlir/include/mlir/Dialect/GPU/GPUOps.td
index 766ddbf202c..3df6ff4be0c 100644
--- a/mlir/include/mlir/Dialect/GPU/GPUOps.td
+++ b/mlir/include/mlir/Dialect/GPU/GPUOps.td
@@ -588,4 +588,56 @@ def GPU_BarrierOp : GPU_Op<"barrier"> {
let printer = [{ p << getOperationName(); }];
}
+def GPU_GPUModuleOp : GPU_Op<"module", [
+ IsolatedFromAbove, SymbolTable, Symbol,
+ SingleBlockImplicitTerminator<"ModuleEndOp">
+]> {
+ let summary = "A top level compilation unit containing code to be run on a GPU.";
+ let description = [{
+ GPU module contains code that is intended to be run on a GPU. A host device
+ can launch this code through a gpu.launc_func that creates a fully
+ qualified symbol through the gpu.module's symbol and a gpu.func symbol
+ contained in the gpu.module.
+
+ The module's top-level scope is modeled by a single region with a single
+ block. GPU modules are required to have a name that is used for symbol
+ resolution by the gpu.launch_func operation.
+
+ Using an op with a region to define a GPU module enables "embedding" GPU
+ modules with SIMT execution models in other dialects in a clean manner and
+ allows filtering of code regions to execute passes on only code intended to
+ or not intended to be run on the separate device.
+
+ ```
+ gpu.module @symbol_name {
+ gpu.func {}
+ ...
+ gpu.module_end
+ }
+
+ ```
+ }];
+ let builders = [OpBuilder<"Builder *builder, OperationState &result, "
+ "StringRef name">];
+ let parser = [{ return ::parseGPUModuleOp(parser, result); }];
+ let printer = [{ return ::print(p, *this); }];
+ let regions = (region SizedRegion<1>:$body);
+
+ // We need to ensure the block inside the region is properly terminated;
+ // the auto-generated builders do not guarantee that.
+ let skipDefaultBuilders = 1;
+}
+
+def GPU_ModuleEndOp : GPU_Op<"module_end", [
+ Terminator, HasParent<"GPUModuleOp">
+]> {
+ let summary = "A pseudo op that marks the end of a gpu.module.";
+ let description = [{
+ This op terminates the only block inside the only region of a `gpu.module`.
+ }];
+
+ let parser = [{ return success(); }];
+ let printer = [{ p << getOperationName(); }];
+}
+
#endif // GPU_OPS
OpenPOWER on IntegriCloud