Skip to content

Apply __new__ approach to disabling __init__ #484

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

Merged
merged 3 commits into from
Mar 3, 2025

Conversation

rwgk
Copy link
Collaborator

@rwgk rwgk commented Mar 3, 2025

Contributes to #198

Make disabling __init__ uniform across cuda.core:

  • Use @classmethod as the only constructor: Best for strict enforcement.

  • Uniform raise RuntimeError() with a standardized message form.

The starting point for this change was extracted from PR #458:

The starting point for this change was extracted from PR NVIDIA#458:

* NVIDIA#458 (comment)

* NVIDIA#458 (comment)
Copy link
Contributor

copy-pr-bot bot commented Mar 3, 2025

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@rwgk
Copy link
Collaborator Author

rwgk commented Mar 3, 2025

/ok to test

This comment has been minimized.

@leofang
Copy link
Member

leofang commented Mar 3, 2025

Looks fine to me! Merge?

@rwgk
Copy link
Collaborator Author

rwgk commented Mar 3, 2025

I forgot that I wanted to add a couple more small tests. Doing that now.

@rwgk
Copy link
Collaborator Author

rwgk commented Mar 3, 2025

@leofang Test coverage is now systematically complete, covering "front doors" and "back doors"; see comments added with commit eda324f.

Testing that the back doors are locked is done through APIs that are unavoidably (for all practical purposes) visible through public APIs.

Recently I experienced pushback when testing private functionality under the CCCL repo, so I asked ChatGPT about it:

The lists of pros and cons are complex. I'm convinced it would be unproductive to be to pure one way or another, case-by-case judgement is important. That's how I decided to add tests that ensure the back doors are locked, and remain so.

@rwgk
Copy link
Collaborator Author

rwgk commented Mar 3, 2025

/ok to test

leofang
leofang previously approved these changes Mar 3, 2025
Copy link
Member

@leofang leofang left a comment

Choose a reason for hiding this comment

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

LGTM other than fixing one error message.

Comment on lines +88 to +89
self._device_id = None # delayed
self._ctx_handle = None # delayed
Copy link
Member

@leofang leofang Mar 3, 2025

Choose a reason for hiding this comment

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

IIUC this is actually a bug fix too! I wonder why it wasn't caught before...

Comment on lines +98 to +99
self._device_id = None # delayed
self._ctx_handle = None # delayed
Copy link
Member

Choose a reason for hiding this comment

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

ditto

NVIDIA#484 (comment)

Right now, if one wants to create a stream from a protocol-supported object, the intended way is to do `s = Device().create_stream(object_with_dunder_cuda_stream)`.
@leofang
Copy link
Member

leofang commented Mar 3, 2025

Since the previous run was green and the most recent change is comment-only, I suggest we admin-merge this without another CI run. @rwgk ready?

@rwgk
Copy link
Collaborator Author

rwgk commented Mar 3, 2025

Since the previous run was green and the most recent change is comment-only, I suggest we admin-merge this without another CI run. @rwgk ready?

Yes, please! :-)

@leofang leofang marked this pull request as ready for review March 3, 2025 17:49
Copy link
Contributor

copy-pr-bot bot commented Mar 3, 2025

Auto-sync is disabled for ready for review pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@leofang leofang merged commit 043669b into NVIDIA:main Mar 3, 2025
1 check passed
@leofang leofang added bug Something isn't working enhancement Any code-related improvements P0 High priority - Must do! cuda.core Everything related to the cuda.core module labels Mar 3, 2025
@leofang leofang added this to the cuda.core beta 3 milestone Mar 3, 2025
@rwgk rwgk deleted the uniform_init_disables branch March 3, 2025 17:51
Copy link

github-actions bot commented Mar 3, 2025

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
bug Something isn't working cuda.core Everything related to the cuda.core module enhancement Any code-related improvements P0 High priority - Must do!
2 participants