Skip to content

_cuda_bindings_redirector.py fix (made necessary by PR #773) - #780

Merged
leofang merged 2 commits into
NVIDIA:mainfrom
rwgk:cuda_bindings_redirector_fix
Jul 25, 2025
Merged

_cuda_bindings_redirector.py fix (made necessary by PR #773)#780
leofang merged 2 commits into
NVIDIA:mainfrom
rwgk:cuda_bindings_redirector_fix

Conversation

@rwgk

@rwgkrwgk commented Jul 24, 2025

Copy link
Copy Markdown
Contributor

Avoid premature import of cuda.bindings in redirector to fix startup noise (see here).

Previously, the _cuda_bindings_redirector.py file imported cuda.bindings at interpreter startup to ensure the cuda namespace was initialized. However, this triggered early loading of Cython modules that depend on win32api, which may not be available yet due to .pth file processing order.

This commit replaces import cuda.bindings with import cuda, which is sufficient to ensure the cuda namespace is in sys.modules. The version redirect via cuda.__version__ is preserved by assigning a custom LazyCudaModule type to sys.modules["cuda"].

As a result, cuda.__version__ continues to work (with a deprecation warning), while avoiding startup errors when win32api is not yet importable.

rwgk added 2 commits July 24, 2025 11:54
…p error
Previously, the `_cuda_bindings_redirector.py` file imported `cuda.bindings`
at interpreter startup to ensure the `cuda` namespace was initialized.
However, this triggered early loading of Cython modules that depend on
`win32api`, which may not be available yet due to `.pth` file processing order.
This commit replaces `import cuda.bindings` with `import cuda`, which is
sufficient to ensure the `cuda` namespace is in `sys.modules`. The version
redirect via `cuda.__version__` is preserved by assigning a custom
`LazyCudaModule` type to `sys.modules["cuda"]`.
As a result, `cuda.__version__` continues to work (with a deprecation warning),
while avoiding startup errors when `win32api` is not yet importable.
@copy-pr-bot

Copy link
Copy Markdown
Contributor

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

rwgk commented Jul 24, 2025

Copy link
Copy Markdown
ContributorAuthor

@leofang for visibility

@rwgk

rwgk commented Jul 24, 2025

Copy link
Copy Markdown
ContributorAuthor

/ok to test

@github-actions

Copy link
Copy Markdown

@rwgk
rwgk requested a review from leofangJuly 24, 2025 22:06
@rwgk

rwgk commented Jul 24, 2025

Copy link
Copy Markdown
ContributorAuthor

@kkraus14@oleksandr-pavlyk@leofang

I asked ChatGPT about import cuda vs import cuda.bindings, it's towards the end in this conversation:

Look for "Why might the original author have used import cuda.bindings"

The conclusion there:

In short: it was probably defensive but over-eager. A simpler import cuda achieves the intended effect without the cascading side effects.

All tests pass, so I think this super easy fix is all we need.

@rwgk
rwgk marked this pull request as ready for review July 24, 2025 22:11
@copy-pr-bot

Copy link
Copy Markdown
Contributor

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.

@rwgk

rwgk commented Jul 24, 2025

Copy link
Copy Markdown
ContributorAuthor

I forgot to add: I downloaded the CI logs and searched for win32api, there are no matches anymore.

@leofangleofang added bug Something isn't working P0 High priority - Must do! cuda.bindings Everything related to the cuda.bindings module labels Jul 24, 2025

@leofangleofang left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, Ralf. The fix looks reasonable to me. Unfortunately I can't reliably reproduce the issue, so if it fixes on your side it should be good enough, and let's merge and monitor the situation.

@github-project-automationgithub-project-automationBot moved this from Todo to In Review in CCCLJul 25, 2025
@leofang
leofang merged commit db67006 into NVIDIA:mainJul 25, 2025
56 checks passed
@github-project-automationgithub-project-automationBot moved this from In Review to Done in CCCLJul 25, 2025
@rwgk
rwgk deleted the cuda_bindings_redirector_fix branch July 27, 2025 06:41
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugSomething isn't workingcuda.bindingsEverything related to the cuda.bindings moduleP0High priority - Must do!

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants

@rwgk@leofang