-
Notifications
You must be signed in to change notification settings - Fork 242
Add __eq__ and __hash__ to Buffer, LaunchConfig, Kernel, ObjectCode #1534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Make these classes hashable and comparable: - Buffer: identity based on (type, ptr, size) - LaunchConfig: uses _LAUNCH_CONFIG_ATTRS tuple for forward-compatible identity; also updates __repr__ to use the same attribute list - Kernel: identity based on (type, handle) - ObjectCode: identity based on (type, handle), triggers lazy load Stream, Event, Context, Device already had __eq__/__hash__.
Make these classes hashable and comparable: - Buffer: identity based on (ptr, size) - LaunchConfig: uses _LAUNCH_CONFIG_ATTRS tuple for forward-compatible identity; also updates __repr__ to use the same attribute list - Kernel: identity based on handle - ObjectCode: identity based on handle, triggers lazy load Remove type(self) from __hash__ in Event, Context, Buffer, LaunchConfig, Kernel, ObjectCode - CUDA handles are already unique, and removing type(self) maintains the hash/equality contract for subclasses. Add parameterized hash tests for all 8 core API classes. Stream, Device already had correct __eq__/__hash__ without type(self).
|
/ok to test e182f4c |
| def sample_device(init_cuda): | ||
| return Device() | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def sample_stream(sample_device): | ||
| return sample_device.create_stream() | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def sample_event(sample_device): | ||
| return sample_device.create_event() | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def sample_context(sample_device): | ||
| return sample_device.context |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once this change and the change adding __weakref__ members are both merged, I plan to revisit these fixtures (which overlap with test_weakref.py). There is an opportunity to rewrite and simplify test_hashable.py, test_comparable.py and test_weakref.py, possibly combining them.
|
Summary
Complete hashability support for core API classes by adding
__eq__and__hash__to Buffer, LaunchConfig, Kernel, and ObjectCode.Changes
__eq__and__hash__to Buffer, LaunchConfig, Kernel, ObjectCodetype(self)from__hash__in Event, Context (and the new classes) - CUDA handles are already unique, and this maintains the hash/equality contract for subclasses_LAUNCH_CONFIG_ATTRStuple for forward-compatible identity in LaunchConfig__repr__in LaunchConfig to use the same attribute listIdentity basis:
(ptr, size)(grid, cluster, block, shmem_size, cooperative_launch)handlehandle(triggers lazy load)Stream, Event, Context, Device already had
__eq__/__hash__.Test Plan
test_hashable.pycover all 8 core classes