Skip to content

Conversation

@Andy-Jost
Copy link
Contributor

Summary

  • Simplify Stream.__hash__ and Stream.__eq__ to use pointer comparison only, removing expensive Stream_ensure_ctx calls
  • Fix Event.__hash__ to be consistent with Event.__eq__ by removing context from hash

Changes

  • _stream.pyx: Remove Stream_ensure_ctx calls and context comparison from __hash__ and __eq__
  • _event.pyx: Remove _h_context from __hash__ (was inconsistent with __eq__ which only compares event handle)

Motivation

As reported in #1480, requiring CUDA context for hash/equality is problematic because:

  1. For foreign streams, we may not know the associated CUDA context
  2. Triggering context lookup is expensive
  3. Some objects are independent of CUDA contexts

This follows the cccl-rt principle of simple pointer comparison.

Closes #1480

Simplify Stream and Event hash/equality to use pointer comparison only,
avoiding expensive context lookups. This follows the cccl-rt principle
and fixes issues with wrapping foreign streams where context is unknown.

Closes NVIDIA#1480
@copy-pr-bot
Copy link
Contributor

copy-pr-bot bot commented Jan 15, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@Andy-Jost Andy-Jost added this to the cuda.core beta 12 milestone Jan 15, 2026
@Andy-Jost Andy-Jost added enhancement Any code-related improvements cuda.core Everything related to the cuda.core module labels Jan 15, 2026
@Andy-Jost Andy-Jost self-assigned this Jan 15, 2026
@Andy-Jost
Copy link
Contributor Author

/ok to test c8e9bc7

@Andy-Jost
Copy link
Contributor Author

The associated issue only mentions streams, but I applied the same fix to events as well.

Copy link
Contributor

@cpcloud cpcloud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@github-actions

This comment has been minimized.

@kkraus14 kkraus14 enabled auto-merge (squash) January 15, 2026 19:36
Copy link
Collaborator

@rwgk rwgk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice simplification.

@kkraus14 kkraus14 merged commit 3e2bba7 into NVIDIA:main Jan 15, 2026
84 checks passed
@Andy-Jost Andy-Jost deleted the fix-hash-eq-context branch January 15, 2026 20:58
@github-actions
Copy link

Doc Preview CI
Preview removed because the pull request was closed or merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cuda.core Everything related to the cuda.core module enhancement Any code-related improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

__hash__, __eq__, ... should not require a CUDA context

4 participants