Skip to content

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

@leofang

Description

@leofang

Example:

def __hash__(self) -> int:
# Ensure context is initialized for hash consistency
Stream_ensure_ctx(self)
return hash((as_intptr(self._h_context), as_intptr(self._h_stream)))

@stiepan reported offline that this is problematic because at least for streams we do not always know the CUDA context associated with them (we could be wrapping a foreign stream), and triggering a lookup is expensive. Some of the objects are even independent of CUDA contexts.

We decided to follow cccl-rt and do a simple pointer comparison for __eq__. We should stick to this principle for __hash__ as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    cuda.coreEverything related to the cuda.core moduleenhancementAny code-related improvementstriageNeeds the team's attention

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions