[llvm] [Offload] `olLaunchHostFunction` (PR #152482)

Joseph Huber via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 7 07:47:35 PDT 2025


================
@@ -1495,6 +1509,31 @@ struct AMDGPUStreamTy {
                                    OutputSignal->get());
   }
 
+  Error pushHostCallback(void (*Callback)(void *), void *UserData) {
+    // Retrieve an available signal for the operation's output.
+    AMDGPUSignalTy *OutputSignal = nullptr;
+    if (auto Err = SignalManager.getResource(OutputSignal))
+      return Err;
+    OutputSignal->reset();
+    OutputSignal->increaseUseCount();
+
+    AMDGPUSignalTy *InputSignal;
+    {
+      std::lock_guard<std::mutex> Lock(Mutex);
+
+      // Consume stream slot and compute dependencies.
+      InputSignal = consume(OutputSignal).second;
+    }
+
+    // "Leaking" the thread here is consistent with other work added to the
+    // queue. The input and output signals will remain valid until the output is
+    // signaled.
+    std::thread(CallbackWrapper, InputSignal, OutputSignal, Callback, UserData)
----------------
jhuber6 wrote:

I thought we already had callback handling in the HSA signal handler. It's called `schedCallback`.

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


More information about the llvm-commits mailing list