Skip to content

Commit 49c272d

Browse files
committed
forgot to include event changes
1 parent 5622608 commit 49c272d

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

cuda_core/cuda/core/experimental/_event.pyx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ cdef class Event:
166166
raise RuntimeError(explanation)
167167

168168
def __hash__(self) -> int:
169-
"""Return hash based on the underlying CUevent handle address.
169+
"""Return hash based on the underlying CUevent handle address and context.
170170

171171
This enables Event objects to be used as dictionary keys and in sets.
172172
Two Event objects wrapping the same underlying CUDA event will hash
@@ -175,15 +175,23 @@ cdef class Event:
175175
Returns
176176
-------
177177
int
178-
Hash value based on the event handle address.
178+
Hash value based on the event handle address and context handle.
179+
180+
Notes
181+
-----
182+
Includes the context handle in the hash to prevent collisions when
183+
handles are reused across different contexts. While handles are
184+
context-scoped and typically not reused across contexts, including
185+
the context provides defense-in-depth against hash collisions.
179186

180187
Warning
181188
-------
182189
Using a closed or destroyed event as a dictionary key or in a set
183190
results in undefined behavior. The event handle may be reused by
184191
the CUDA driver for new events.
185192
"""
186-
return hash((type(self), <uintptr_t>(self._handle)))
193+
# Context should always be set as a post-condition of Event construction
194+
return hash((type(self), <uintptr_t>(int(self._ctx_handle)), <uintptr_t>(self._handle)))
187195

188196
def __eq__(self, other) -> bool:
189197
"""Check equality based on the underlying CUevent handle address.

0 commit comments

Comments
 (0)