Skip to content

cuda.bindings: Fix segfault when converting char*NULL to bytes - #497

Merged
leofang merged 9 commits into
NVIDIA:mainfrom
rwgk:fix_segfault_char_ptr_to_bytes
Mar 7, 2025
Merged

cuda.bindings: Fix segfault when converting char*NULL to bytes#497
leofang merged 9 commits into
NVIDIA:mainfrom
rwgk:fix_segfault_char_ptr_to_bytes

Conversation

@rwgk

@rwgkrwgk commented Mar 6, 2025

Copy link
Copy Markdown
Contributor

The segfault was discovered while working on PR #458.

Full test coverage for changed code.

@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 Mar 6, 2025

Copy link
Copy Markdown
ContributorAuthor

/ok to test

@github-actions

This comment has been minimized.

@rwgk

rwgk commented Mar 6, 2025

Copy link
Copy Markdown
ContributorAuthor

@leofang The two test failures are these flakes:

> assert delay_seconds * 1000 <= elapsed_time_ms < delay_seconds * 1000 + 2 # tolerance 2 ms
E assert 503.1598205566406 < ((0.5 * 1000) + 2)
> assert delay_seconds * 1000 <= elapsed_time_ms < delay_seconds * 1000 + 2 # tolerance 2 ms
E assert 505.0583190917969 < ((0.5 * 1000) + 2)

@vzhurba01

Copy link
Copy Markdown
Contributor

Changes LGTM at the moment but I see that this is still a draft

@rwgk

rwgk commented Mar 6, 2025

Copy link
Copy Markdown
ContributorAuthor

Changes LGTM at the moment

Thanks!

but I see that this is still a draft

I'm looking into adding more tests, to ideally cover all changes.

And we need to do something about the flakes, even though they are unrelated.

Observed failures:
```
> assert delay_seconds * 1000 <= elapsed_time_ms < delay_seconds * 1000 + 2 # tolerance 2 ms
E assert 503.1598205566406 < ((0.5 * 1000) + 2)
```
```
> assert delay_seconds * 1000 <= elapsed_time_ms < delay_seconds * 1000 + 2 # tolerance 2 ms
E assert 505.0583190917969 < ((0.5 * 1000) + 2)
```
@rwgk

rwgk commented Mar 6, 2025

Copy link
Copy Markdown
ContributorAuthor

@leofang I piggy-backed commit 9dd2630 here to resolve the problem with the flaky tests.

@rwgk

rwgk commented Mar 6, 2025

Copy link
Copy Markdown
ContributorAuthor

/ok to test

@rwgk
rwgk marked this pull request as ready for review March 6, 2025 23:46
@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 requested a review from leofangMarch 6, 2025 23:47
@leofangleofang added bug Something isn't working P0 High priority - Must do! cuda.bindings Everything related to the cuda.bindings module to-be-backported Trigger the bot to raise a backport PR upon merge labels Mar 6, 2025
@rwgk

rwgk commented Mar 7, 2025

Copy link
Copy Markdown
ContributorAuthor

Woah, looks like I'm good at generating segfaults ...

Fatal Python error: Segmentation fault
Current thread 0x0000ffff9f213020 (most recent call first):
File "/__w/cuda-python/cuda-python/cuda_bindings/tests/test_nvrtc.py", line 35 in test_nvrtcGetLoweredName_failure
...
File "/opt/hostedtoolcache/Python/3.9.21/arm64/lib/python3.9/site-packages/_pytest/config/__init__.py", line 201 in console_main
File "/opt/hostedtoolcache/Python/3.9.21/arm64/bin/pytest", line 8 in <module>
/__w/_temp/6c5a43e8-eaeb-4c41-8067-c06dcfabc91e.sh: line 12: 4545 Segmentation fault (core dumped) pytest -rxXs -v tests/
tests/test_nvrtc.py::test_nvrtcGetLoweredName_failure 

@leofang should I just remove that new test and leave that for another PR? I don't think I'll get to the bottom of the newly discovered segfault today. Tomorrow pretty sure.

@leofang

Copy link
Copy Markdown
Member

Just isolate out the cuda.core changes from those for bindings. Let's merge core-related things first; bindings can wait.

@rwgk

rwgk commented Mar 7, 2025

Copy link
Copy Markdown
ContributorAuthor

/ok to test

@rwgk

rwgk commented Mar 7, 2025

Copy link
Copy Markdown
ContributorAuthor

The cuda.core change is to resolve the flakes. (Without it I'd (maybe) have to hit rerun a few times to deflake.)

I just backed out the test that triggers the segfaults: commit a39720b

@leofang

Copy link
Copy Markdown
Member

The cuda.core change is to resolve the flakes

Ah, I meant we can separate it out and merge it first. Mainly if we want to auto-backport the fix, the cuda-11 branch does not have any cuda.core code, so the apto-backport would fail. I am curious if it could work without any cuda-core changes involved.

rwgk added a commit to rwgk/cuda-python that referenced this pull request Mar 7, 2025
rwgk added a commit to rwgk/cuda-python that referenced this pull request Mar 7, 2025
kkraus14
kkraus14 previously approved these changes Mar 7, 2025

@kkraus14kkraus14 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lgtm

@rwgk
rwgk dismissed stale reviews from kkraus14 and leofang via 7814469March 7, 2025 16:24
@rwgk

rwgk commented Mar 7, 2025

Copy link
Copy Markdown
ContributorAuthor

/ok to test

@leofang

leofang commented Mar 7, 2025

Copy link
Copy Markdown
Member

@rwgk could you update the commit message and avoid @someone? Last time you did that I ended up receiving a ton of notifications whenever someone rebased a branch that contains this commit lol

(I noticed this because of a notification 😂)

@rwgk
rwgkforce-pushed the fix_segfault_char_ptr_to_bytes branch from 7814469 to ab6db22CompareMarch 7, 2025 18:05
@rwgk

rwgk commented Mar 7, 2025

Copy link
Copy Markdown
ContributorAuthor

@rwgk could you update the commit message and avoid @someone? Last time you did that I ended up receiving a ton of notifications whenever someone rebased a branch that contains this commit lol

Oh ... sorry, done.

(I did this a lot in the pybind11 repo, wanting to give proper credit. I didn't realize this can lead to spammy notifications.)

@leofang

Copy link
Copy Markdown
Member

/ok to test

@leofang
leofang enabled auto-merge March 7, 2025 18:09
@rwgk

rwgk commented Mar 7, 2025

Copy link
Copy Markdown
ContributorAuthor

@leofang The tests passed previously with the exact same code. The only change was to the commit message. I.e. admin merge would be ideal.

@leofang

Copy link
Copy Markdown
Member

ok

@leofang
leofang disabled auto-merge March 7, 2025 18:18
@leofang
leofang merged commit 82df864 into NVIDIA:mainMar 7, 2025
@github-actions

Copy link
Copy Markdown

Backport failed because this pull request contains merge commits. You can either backport this pull request manually, or configure the action to skip merge commits.

@rwgk

rwgk commented Mar 7, 2025

Copy link
Copy Markdown
ContributorAuthor

Backport failed because this pull request contains merge commits. You can either backport this pull request manually, or configure the action to skip merge commits.

Should I take care of that? (Happy to.)

@rwgk
rwgk deleted the fix_segfault_char_ptr_to_bytes branch March 7, 2025 18:29
@github-actions

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

@leofang

Copy link
Copy Markdown
Member

Should I take care of that? (Happy to.)

Yes, please. My bad in updating your branch, sorry...

@rwgk

rwgk commented Mar 7, 2025

Copy link
Copy Markdown
ContributorAuthor

I'll backport this together with #499, after that is merged.

rwgk added a commit that referenced this pull request Mar 7, 2025
* PR #497 squash-merged
* Bring back test_nvrtcGetLoweredName_failure() (it was originally under PR #497).
* Add code for debugging
* test_all_CUresult_codes(): max_code = int(max(cuda.CUresult)) as suggested by at-leofang
* Change pytest options, mostly to disable output capturing (of both stdout and stderr)
* Undo debugging changes in nvrtc.pyx.in
* Revert "Change pytest options, mostly to disable output capturing (of both stdout and stderr)"
This reverts commit b0464e7.
* Skip new test if nvrtc version < 12.1
rwgk added a commit to rwgk/cuda-python that referenced this pull request Mar 8, 2025
@rwgkrwgk mentioned this pull request Mar 8, 2025
rwgk added a commit that referenced this pull request Mar 8, 2025
* Backport #497
* Backport #499
* Remove @pytest.mark.skipif(nvrtcVersionLessThan(12, 1), ...)
* Revert "Remove @pytest.mark.skipif(nvrtcVersionLessThan(12, 1), ...)"
This reverts commit 41160a8.
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!to-be-backportedTrigger the bot to raise a backport PR upon merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@rwgk@vzhurba01@leofang@kkraus14