[llvm] [Offload] Add support for measuring elapsed time between events (PR #186856)

Kevin Sala Penades via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 30 22:59:46 PDT 2026


================
@@ -1643,34 +1680,56 @@ struct AMDGPUStreamTy {
 
   const AMDGPUQueueTy *getQueue() const { return Queue; }
 
-  /// Record the state of the stream on an event.
-  Error recordEvent(AMDGPUEventTy &Event) const;
+  /// Record an event by enqueuing a barrier marker packet on the stream.
+  Error recordEvent(AMDGPUEventTy &Event);
 
   /// Make the stream wait on an event.
   Error waitEvent(const AMDGPUEventTy &Event);
 
   friend struct AMDGPUStreamManagerTy;
 };
 
-/// Class representing an event on AMDGPU. The event basically stores some
-/// information regarding the state of the recorded stream.
+/// Class representing an event on AMDGPU. The event stores the recorded stream
+/// point and retained timing state.
 struct AMDGPUEventTy {
   /// Create an empty event.
   AMDGPUEventTy(AMDGPUDeviceTy &Device)
-      : RecordedStream(nullptr), RecordedSlot(-1), RecordedSyncCycle(-1) {}
+      : Device(Device), RecordedStream(nullptr), RecordedSlot(-1),
+        RecordedSyncCycle(-1), TimingSignal(nullptr) {}
 
   /// Initialize and deinitialize.
-  Error init() { return Plugin::success(); }
-  Error deinit() { return Plugin::success(); }
+  Error init() { return resetState(); }
+  Error deinit() { return resetState(); }
 
-  /// Record the state of a stream on the event.
+  /// Clear the current recording and retained timing state.
+  Error resetState() {
+    RecordedStream = nullptr;
+    RecordedSlot = -1;
+    RecordedSyncCycle = -1;
+
+    if (auto Err = releaseTimingSignal())
+      return Err;
+
+    return Plugin::success();
+  }
+
+  /// Record the current stream point on the event.
   Error record(AMDGPUStreamTy &Stream) {
     std::lock_guard<std::mutex> Lock(Mutex);
 
-    // Ignore the last recorded stream.
+    // Discard the previous recording and retained timing state.
+    if (auto Err = resetState())
----------------
kevinsala wrote:

LGTM

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


More information about the llvm-commits mailing list