Skip to content

fix(cuda.core): write NVRTC source to a temp file when debug or lineinfo is enabled - #2679

Merged
rparolin merged 6 commits into
NVIDIA:mainfrom
lijinf2:fix_2422
Aug 21, 2026
Merged

fix(cuda.core): write NVRTC source to a temp file when debug or lineinfo is enabled#2679
rparolin merged 6 commits into
NVIDIA:mainfrom
lijinf2:fix_2422

Conversation

@lijinf2

@lijinf2 lijinf2 commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Description

closes #2422

When Program compiles C++ with debug=True or lineinfo=True and the caller
does not pass name=, NVRTC recorded the label default_program. That path
does not exist on disk, so cuda-gdb reported No such file or directory.

This change writes the in-memory source to a unique temp file
(caller_py__kernel_XXXXXXXX.cu, mkstemp, mode 0600) and passes that real
path to nvrtcCreateProgram. ProgramOptions.name is left unchanged so the
program cache key is unaffected. An explicit name= still wins. Write
failures fall back to the old label-only behavior. The temp file is removed
on close() / deallocation.

No public API or signature changes.

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 20, 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 20, 2026
@lijinf2 lijinf2 self-assigned this Aug 20, 2026
@lijinf2 lijinf2 added the bug Something isn't working label Aug 20, 2026
@lijinf2 lijinf2 added this to the cuda.core 1.3.0 milestone Aug 20, 2026
Keep materialize/unlink next to the Program lifetime that owns the temp file,
instead of as module-level functions.
…urce

Skip when cuda-gdb is missing, and use shorter {caller}_{kernel}_ temp names.
@lijinf2

lijinf2 commented Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 7a5877c

@github-actions

This comment has been minimized.

@rparolin
rparolin merged commit 2ecbca6 into NVIDIA:main Aug 21, 2026
110 checks passed
@github-actions

This comment has been minimized.

1 similar comment
@github-actions

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

@lijinf2

lijinf2 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

Thank you @rparolin!

@lijinf2
lijinf2 deleted the fix_2422 branch August 24, 2026 18:57
brandon-b-miller added a commit to brandon-b-miller/cuda-python that referenced this pull request Aug 31, 2026
NVIDIAgh-2385 and NVIDIAgh-2422 were filed for the same NVBug (6420444) and assigned to two
people. NVIDIA#2679 landed the temp-file fix from NVIDIAgh-2422 first, so this branch's
parallel implementation is dropped in favor of the one on main: keeping both
would have left two mechanisms writing a source file on every debug compile,
with the NVRTC name deciding which one was actually used.

Resolved by taking main's side for every overlapping file and removing
_jit_source.py, leaving this branch identical to main. What remains of NVIDIAgh-2385
is handled in follow-up commits.
brandon-b-miller added a commit to brandon-b-miller/cuda-python that referenced this pull request Aug 31, 2026
Redirecting the NVRTC program name at a temp .cu (NVIDIA#2679) left two problems.

Quoted includes stopped resolving. NVRTC searches the directory of the name it
is handed for #include "...", so moving that name into the temp dir moved the
search with it, and merely enabling debug or lineinfo broke a compile that
worked without it. The directory the name used to denote is now passed back as
--include-path. It is added to the compile options only, never to
ProgramOptions, so the program cache key is unchanged; the cwd was already an
unkeyed input to these compiles before the redirect.

Teardown deleted files it did not create. The name given to NVRTC doubled as
the cleanup target, but that slot still holds the caller's options.name
whenever the source was not redirected, so a name like "matmul.cu" matching a
real file meant close() or collection deleted the caller's own source. The temp
path is tracked separately now and is the only path unlinked.

Removal on close() is left as it was, since NVIDIAgh-2422 asked for it and the tests
added with NVIDIA#2679 assert it.
lijinf2 pushed a commit that referenced this pull request Sep 1, 2026
…2678)

* test and a narrowish fix

* marker

* switch to pyelftools so we dont require a new ctk component

* fix(cuda.core): repair two regressions in the NVRTC debug source path

Redirecting the NVRTC program name at a temp .cu (#2679) left two problems.

Quoted includes stopped resolving. NVRTC searches the directory of the name it
is handed for #include "...", so moving that name into the temp dir moved the
search with it, and merely enabling debug or lineinfo broke a compile that
worked without it. The directory the name used to denote is now passed back as
--include-path. It is added to the compile options only, never to
ProgramOptions, so the program cache key is unchanged; the cwd was already an
unkeyed input to these compiles before the redirect.

Teardown deleted files it did not create. The name given to NVRTC doubled as
the cleanup target, but that slot still holds the caller's options.name
whenever the source was not redirected, so a name like "matmul.cu" matching a
real file meant close() or collection deleted the caller's own source. The temp
path is tracked separately now and is the only path unlinked.

Removal on close() is left as it was, since gh-2422 asked for it and the tests
added with #2679 assert it.

* address reviews
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cuda.core: materialize NVRTC source to a real path when debug info is enabled

2 participants