Skip to content

Fix #789: Remove cycle between c.b.cyruntime and c.b._lib.cyruntime.cyruntime - #914

Merged
leofang merged 9 commits into
NVIDIA:mainfrom
mdboom:issue789-4
Aug 28, 2025
Merged

Fix #789: Remove cycle between c.b.cyruntime and c.b._lib.cyruntime.cyruntime#914
leofang merged 9 commits into
NVIDIA:mainfrom
mdboom:issue789-4

Conversation

@mdboom

Copy link
Copy Markdown
Contributor

This now textually includes cuda.bindings._lib.cyruntime.cyruntime in cuda.bindings._bindings.cyruntime to remove the cycle.

Since this is only /adding/ symbols to cuda.bindings._bindings.cyruntime, I believe it isn't breaking ABI compatibility (but I admittedly am only now getting used to "Cython ABI compatibility"). The old cuda.bindings._lib.cyruntime.cyruntime and cuda.bindings._lib.cyruntime.utils are just removed, but since those were private, I think we ok for ABI there, too.

I also discovered a bug in the test for cycles that was finding erroneous cycles when ImportErrors were raised and caught.

Description

closes

Checklist

  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@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.

@mdboom

Copy link
Copy Markdown
ContributorAuthor

/ok to test

@github-actions

This comment has been minimized.

@leofangleofang added enhancement Any code-related improvements P0 High priority - Must do! cuda.bindings Everything related to the cuda.bindings module labels Aug 27, 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.

LGTM overall! Left a few questions. Is this still WIP (since it's in the draft state)?

Comment thread.gitignore
Comment threadcuda_bindings/setup.py Outdated
Comment threadcuda_bindings/cuda/bindings/_bindings/cyruntime.pyx.in Outdated
@mdboom
mdboom marked this pull request as ready for review August 27, 2025 20:24
@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.

@mdboom

Copy link
Copy Markdown
ContributorAuthor

LGTM overall! Left a few questions. Is this still WIP (since it's in the draft state)?

No, it's ready for review. I didn't notice I created a draft...

@mdboom

Copy link
Copy Markdown
ContributorAuthor

/ok to test

@kkraus14

Copy link
Copy Markdown
Collaborator

The old cuda.bindings._lib.cyruntime.cyruntime and cuda.bindings._lib.cyruntime.utils are just removed, but since those were private, I think we ok for ABI there, too.

I poked around the generated .cpp code from the Cython to get a better sense as to what's happening when using cimport and the potential ABI issues.

It looks like when you cimport something it adds a declaration, i.e. for cuda.bindings._lib.cyruntime.utils.getDriverEglFrame the generated .cpp code from something that cimports it contains the following:

  • A declaration statement that looks like:
staticcudaError_t (*__pyx_f_4cuda_8bindings_4_lib_9cyruntime_5utils_getDriverEglFrame)(__pyx_t_4cuda_8bindings_8cydriver_CUeglFrame *, __pyx_t_4cuda_8bindings_9cyruntime_cudaEglFrame); /*proto*/
  • Within a static int __Pyx_modinit_function_import_code function, a call that looks like:
if (__Pyx_ImportFunction_3_0_12(__pyx_t_1, "getDriverEglFrame", (void (**)(void))&__pyx_f_4cuda_8bindings_4_lib_9cyruntime_5utils_getDriverEglFrame, "cudaError_t (__pyx_t_4cuda_8bindings_8cydriver_CUeglFrame *, __pyx_t_4cuda_8bindings_9cyruntime_cudaEglFrame)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)

So there's zero linkage happening and everything is declared as static. The symbol resolution is happening via the __Pyx_ImportFunction_3_0_12 function and unless the cimport is redeclared in a .pxd file, it doesn't yield a corresponding __Pyx_ExportFunction call for it.

I think this effectively means we can treat Cython the same way we treat Python where we only need to worry about API compatibility, except for externed vs non-externed declarations in .pxd files in public modules where we have shown in the past that it causes ABI breakage.

@mdboom

Copy link
Copy Markdown
ContributorAuthor

/ok to test

kkraus14
kkraus14 previously approved these changes Aug 27, 2025
@mdboom

Copy link
Copy Markdown
ContributorAuthor

/ok to test

Comment threadcuda_bindings/tests/test_utils.py Outdated
@mdboom

Copy link
Copy Markdown
ContributorAuthor

/ok to test

@mdboom

Copy link
Copy Markdown
ContributorAuthor

/ok to test

@mdboom
mdboom requested a review from leofangAugust 28, 2025 14:15
Comment threadcuda_bindings/cuda/bindings/_lib/cyruntime/cyruntime.pxi
leofang
leofang previously approved these changes Aug 28, 2025
@leofang
leofang merged commit dd0ceef into NVIDIA:mainAug 28, 2025
1 check passed
@leofang

Copy link
Copy Markdown
Member

Thanks a lot @mdboom!

@github-actions

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

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

Labels

cuda.bindingsEverything related to the cuda.bindings moduleenhancementAny code-related improvementsP0High priority - Must do!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@mdboom@kkraus14@leofang