Skip to content

cuda.core: return CUmodule via as_py in ObjectCode.get_module - #2481

Merged
lijinf2 merged 5 commits into
NVIDIA:mainfrom
lijinf2:fix_2415
Aug 5, 2026
Merged

cuda.core: return CUmodule via as_py in ObjectCode.get_module#2481
lijinf2 merged 5 commits into
NVIDIA:mainfrom
lijinf2:fix_2415

Conversation

@lijinf2

@lijinf2 lijinf2 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Use the shared handle export path for legacy CUmodule interop instead of constructing driver.CUmodule directly.

Description

closes #2415

Add an as_py(const CUmodule&) overload and use it in ObjectCode.get_module() so legacy CUmodule export goes through the same handle→Python wrapper path as other CUDA resources.

CUmodule from cuLibraryGetModule is not an owning *Handle (shared_ptr); its lifetime is owned by the parent CUlibrary, so this overload takes the regular pointer and only wraps it as cuda.bindings.driver.CUmodule.

Checklist

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

@copy-pr-bot

copy-pr-bot Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the cuda.core Everything related to the cuda.core module label Aug 3, 2026
@lijinf2 lijinf2 self-assigned this Aug 3, 2026
@lijinf2 lijinf2 added this to the cuda.core 1.2.0 milestone Aug 3, 2026
Use the shared handle export path for legacy CUmodule interop instead of
constructing driver.CUmodule directly.

Signed-off-by: Jinfeng <jinfengl@nvidia.com>
@lijinf2 lijinf2 linked an issue Aug 3, 2026 that may be closed by this pull request
@lijinf2 lijinf2 added the enhancement Any code-related improvements label Aug 3, 2026
Satisfy cython-lint after switching get_module() to as_py().

Signed-off-by: Jinfeng <jinfengl@nvidia.com>
@lijinf2

lijinf2 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test a4c1e46

@github-actions

This comment has been minimized.

// Regular pointer (CUmodule), not a shared_ptr: lifetime is owned by the
// CUlibrary it was retrieved from.
inline PyObject* as_py(const CUmodule& h) noexcept {
return detail::make_py("cuda.bindings.driver", "CUmodule", reinterpret_cast<std::intptr_t>(h));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should extend the overload for as_intptr(h) for CUmodule above?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Route as_py(CUmodule) through as_intptr for consistency with other handle exports.
@lijinf2

lijinf2 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test edb609d

// Regular pointer (CUmodule), not a shared_ptr: lifetime is owned by the
// CUlibrary it was retrieved from.
inline std::intptr_t as_intptr(const CUmodule& h) noexcept {
return reinterpret_cast<std::intptr_t>(h);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah.. I think the agent is not quite smart here. There's a pretty obvious pattern here: as_cu -> as_intptr -> as_py, but the agent isn't smart enough to pick it up. Also the comment is not really needed here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, agents chose not to revise as_cu and as_intptr and it needs clear instructions in the prompt.
Just revised as_cu to support CUModule.

@lijinf2

lijinf2 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 869760b

@lijinf2
lijinf2 enabled auto-merge (squash) August 4, 2026 19:00
@lijinf2

lijinf2 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test ef8d8ab

@lijinf2
lijinf2 merged commit 8d4d072 into NVIDIA:main Aug 5, 2026
107 checks passed
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
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

cuda.core Everything related to the cuda.core module enhancement Any code-related improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create as_py function for CUModule type

2 participants