[Mlir-commits] [mlir] [GPUToLLVM] Support multiple async dependencies in gpu.launch_func lowering (PR #188987)

Fabian Mora llvmlistbot at llvm.org
Fri Mar 27 06:32:23 PDT 2026


================
@@ -965,8 +961,35 @@ LogicalResult LegalizeLaunchFuncOpPattern::matchAndRewrite(
   Location loc = launchOp.getLoc();
 
   Value stream = Value();
-  if (!adaptor.getAsyncDependencies().empty())
+  if (!adaptor.getAsyncDependencies().empty()) {
     stream = adaptor.getAsyncDependencies().front();
+    // Synchronize additional async dependencies onto the primary stream using
+    // events, following the same approach as gpu.wait async lowering.
+    if (adaptor.getAsyncDependencies().size() > 1) {
+      auto insertionPoint = rewriter.saveInsertionPoint();
+      SmallVector<Value, 4> events;
+      for (auto [origDep, convertedDep] :
+           llvm::zip(launchOp.getAsyncDependencies().drop_front(),
+                     adaptor.getAsyncDependencies().drop_front())) {
+        if (isDefinedByCallTo(convertedDep,
+                              streamCreateCallBuilder.functionName)) {
+          auto *defOp = origDep.getDefiningOp();
+          rewriter.setInsertionPointAfter(defOp);
+          auto event =
+              eventCreateCallBuilder.create(loc, rewriter, {}).getResult();
+          eventRecordCallBuilder.create(loc, rewriter, {event, convertedDep});
+          events.push_back(event);
+        } else {
+          events.push_back(convertedDep);
+        }
+      }
+      rewriter.restoreInsertionPoint(insertionPoint);
+      for (auto event : events)
+        streamWaitEventCallBuilder.create(loc, rewriter, {stream, event});
+      for (auto event : events)
----------------
fabianmcg wrote:

```suggestion
      for (Value event : events)
        streamWaitEventCallBuilder.create(loc, rewriter, {stream, event});
      for (Value event : events)
```

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


More information about the Mlir-commits mailing list