diff options
| author | Alex Zinenko <zinenko@google.com> | 2019-10-08 04:29:58 -0700 |
|---|---|---|
| committer | A. Unique TensorFlower <gardener@tensorflow.org> | 2019-10-08 04:30:32 -0700 |
| commit | 90d65d32d69ca46f52a9a744eafdad0d97b4a185 (patch) | |
| tree | 405063572a964c854039bbb6d1554cae98b7bd0a /mlir/lib/Dialect/GPU/Transforms | |
| parent | 780f107a57113706a4551e32c32fcd60006d9263 (diff) | |
| download | bcm5719-llvm-90d65d32d69ca46f52a9a744eafdad0d97b4a185.tar.gz bcm5719-llvm-90d65d32d69ca46f52a9a744eafdad0d97b4a185.zip | |
Use named modules for gpu.launch_func
The kernel function called by gpu.launch_func is now placed into an isolated
nested module during the outlining stage to simplify separate compilation.
Until recently, modules did not have names and could not be referenced. This
limitation was circumvented by introducing a stub kernel at the same name at
the same nesting level as the module containing the actual kernel. This
relation is only effective in one direction: from actual kernel function to its
launch_func "caller".
Leverage the recently introduced symbol name attributes on modules to refer to
a specific nested module from `gpu.launch_func`. This removes the implicit
connection between the identically named stub and kernel functions. It also
enables support for `gpu.launch_func`s to call different kernels located in the
same module.
PiperOrigin-RevId: 273491891
Diffstat (limited to 'mlir/lib/Dialect/GPU/Transforms')
| -rw-r--r-- | mlir/lib/Dialect/GPU/Transforms/KernelOutlining.cpp | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/mlir/lib/Dialect/GPU/Transforms/KernelOutlining.cpp b/mlir/lib/Dialect/GPU/Transforms/KernelOutlining.cpp index f38a2e81986..e2b0e463de0 100644 --- a/mlir/lib/Dialect/GPU/Transforms/KernelOutlining.cpp +++ b/mlir/lib/Dialect/GPU/Transforms/KernelOutlining.cpp @@ -144,27 +144,30 @@ class GpuKernelOutliningPass : public ModulePass<GpuKernelOutliningPass> { public: void runOnModule() override { ModuleManager moduleManager(getModule()); + bool modified = false; for (auto func : getModule().getOps<FuncOp>()) { // Insert just after the function. Block::iterator insertPt(func.getOperation()->getNextNode()); func.walk([&](gpu::LaunchOp op) { FuncOp outlinedFunc = outlineKernelFunc(op); - // Potentially renames outlinedFunc to make symbol unique. - moduleManager.insert(insertPt, outlinedFunc); + // Create nested module and insert outlinedFunc. The module will + // originally get the same name as the function, but may be renamed on + // insertion into the parent module. + auto kernelModule = createKernelModule(outlinedFunc, moduleManager); + moduleManager.insert(insertPt, kernelModule); // Potentially changes signature, pulling in constants. convertToLaunchFuncOp(op, outlinedFunc); - - // Create clone and move body from outlinedFunc. - auto kernelFunc = outlinedFunc.cloneWithoutRegions(); - kernelFunc.getBody().takeBody(outlinedFunc.getBody()); - - // Create nested module and insert kernelFunc. - auto kernelModule = createKernelModule(kernelFunc, moduleManager); - getModule().insert(insertPt, kernelModule); + modified = true; }); } + + // If any new module was inserted in this module, annotate this module as + // a container module. + if (modified) + getModule().setAttr(gpu::GPUDialect::getContainerModuleAttrName(), + UnitAttr::get(&getContext())); } private: @@ -172,9 +175,11 @@ private: ModuleOp createKernelModule(FuncOp kernelFunc, const ModuleManager &parentModuleManager) { auto context = getModule().getContext(); - auto kernelModule = ModuleOp::create(UnknownLoc::get(context)); + Builder builder(context); + auto kernelModule = + ModuleOp::create(builder.getUnknownLoc(), kernelFunc.getName()); kernelModule.setAttr(gpu::GPUDialect::getKernelModuleAttrName(), - UnitAttr::get(context)); + builder.getUnitAttr()); ModuleManager moduleManager(kernelModule); llvm::SmallVector<FuncOp, 8> funcsToInsert = {kernelFunc}; |

