[Mlir-commits] [mlir] [mlir][gpu] Add optional attributes of kernelModule and kernelFunc for outlining kernels. (PR #118861)

Valentin Clement バレンタイン クレメン llvmlistbot at llvm.org
Thu Dec 5 21:21:51 PST 2024


================
@@ -395,16 +401,34 @@ class GpuKernelOutliningPass
 
 private:
   /// Returns a gpu.module containing kernelFunc and all callees (recursive).
-  gpu::GPUModuleOp createKernelModule(gpu::GPUFuncOp kernelFunc,
+  gpu::GPUModuleOp createKernelModule(gpu::LaunchOp gpuLaunchOp,
+                                      gpu::GPUFuncOp kernelFunc,
                                       const SymbolTable &parentSymbolTable) {
     // TODO: This code cannot use an OpBuilder because it must be inserted into
     // a SymbolTable by the caller. SymbolTable needs to be refactored to
     // prevent manual building of Ops with symbols in code using SymbolTables
     // and then this needs to use the OpBuilder.
     auto *context = getOperation().getContext();
     OpBuilder builder(context);
-    auto kernelModule = builder.create<gpu::GPUModuleOp>(kernelFunc.getLoc(),
-                                                         kernelFunc.getName());
+    std::string kernelModuleName;
+    gpu::GPUModuleOp kernelModule = nullptr;
+    if (gpuLaunchOp.getKernelModule()) {
+      kernelModuleName =
+          gpuLaunchOp.getKernelModule()->getRootReference().str();
+      if (auto existingModule =
+              parentSymbolTable.lookup<gpu::GPUModuleOp>(kernelModuleName)) {
+        kernelModule = existingModule;
+      }
----------------
clementval wrote:

```suggestion
        kernelModule = parentSymbolTable.lookup<gpu::GPUModuleOp>(kernelModuleName);
```

https://github.com/llvm/llvm-project/pull/118861


More information about the Mlir-commits mailing list