[BUG]: `b" " * logSize` log buffers let nvrtcGetProgramLog overwrite the shared `b" "` object
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
The two unconditional log reads are in benchmarks/cuda_bindings/runner/runtime.py (compile_cubin()) and cuda_bindings_13/tests/legacy_api/test_legacy_kernelParams.py (common_nvrtc()); grep both for b" " * and check that the buffer is handed to nvrtcGetProgramLog. Reproduce by calling each function with a trivial kernel and printing b" " and b"a b".split(b" ") afterwards. Done looks like b" " unchanged, with bytearray(logSize) in place. Note the reporter already has a commit and asked to be assigned, so coordinate before starting.
由索引模型根據 Issue 內容生成。
描述
A few places in the repo allocate the NVRTC log buffer as log = b" " * logSize and pass it to nvrtcGetProgramLog. When a compile succeeds with an empty log, logSize is 1. b" " * 1 does not make a new object: it returns CPython's cached one-byte b" ", and NVRTC then writes its terminating NUL into that shared object. After that, every b" " in the process is b"\x00", including the literal, " ".encode() and bytes([32]), and b"a b".split(b" ") no longer splits.
These read the log after every compile, including successful ones:
benchmarks/cuda_bindings/runner/runtime.py,compile_cubin()cuda_bindings_13/tests/legacy_api/test_legacy_kernelParams.py,common_nvrtc()
The same line is also in cuda_bindings_12/tests/test_kernelParams.py (common_nvrtc()) and cuda_bindings_12/examples/extra/jit_program_test.py (main()). I have not run those two against cuda-bindings 12.9, so I left them out of the change below; I can add them if you want all four fixed together.
Not affected: cuda_bindings_12/examples/common/common.py only reads the log after a failed compile, where the log is longer than one byte. The cuda.core helpers in _utils/cuda_utils.pyx only allocate when logsize > 1. The b" " * n PTX/CUBIN and LTO-IR data buffers are never one byte long, so they always get a fresh object.
How I found it: I started from NVIDIA-NeMo/Speech#15790, which reports this pattern in NeMo's run_nvrtc(), and searched this repo for b" " * buffers handed to nvrtcGetProgramLog. The places above are the ones that read the log unconditionally.
Repro: I loaded each file unmodified (from main at 0f4983bf; the lines are the same on current main), called the function with a trivial kernel, extern "C" __global__ void k(int *p) { if (p) *p = 1; }, and printed the state of b" " before and after the call. nvrtcGetProgramLogSize returned 1 in every run.
| file | b" " after |
b"a b".split(b" ") after |
|---|---|---|
benchmarks/cuda_bindings/runner/runtime.py (compile_and_load()) |
b'\x00' |
[b'a b'] |
cuda_bindings_13/tests/legacy_api/test_legacy_kernelParams.py (common_nvrtc()) |
b'\x00' |
[b'a b'] |
same two files with bytearray(logSize) |
b' ' |
[b'a', b'b'] |
" ".encode() and bytes([32]) returned b'\x00' too after the unmodified calls.
Expected: b" " stays b" ", and b"a b".split(b" ") returns [b'a', b'b'].
Environment: Linux aarch64 with an H100-class GPU, driver 595.58.03, Python 3.12.3, cuda-bindings 13.5.0, cuda-pathfinder 1.9.0, numpy 2.5.5, NVRTC 13.2 from the CUDA 13.2 toolkit.
Where this can show up in practice (my estimate; I have not seen a field report):
common_nvrtc()is the kind of helper people copy into their own projects. In a copied version, whatever else that process does withb" "afterwards breaks silently: splitting or joining byte strings, padding, building protocol messages. Nothing raises; the results are just wrong.- In the test suite, every test that runs after a kernelParams test in the same pytest process sees the corrupted
b" ". A failure would then show up in an unrelated test, or a check that compares againstb" "could pass when it should not. - The benchmark runner compiles every benchmark kernel in one process, so anything later in a run that formats or parses bytes with
b" "is affected.
Fix: allocate the buffer with bytearray(logSize). nvrtcGetProgramLog accepts a bytearray, and log.decode() works the same. With that change b" " is unchanged in both runs above.
CONTRIBUTING asks contributors to coordinate before implementing, so I have not opened a PR. The two-line change is on a branch in my fork: https://github.com/0z5a/cuda-python/commit/3bc7c6da0f871dbc7b47117776e0f1abaa192792 (branch nvrtc-log-bytearray). If this direction looks right, could you assign this to me? I'll then open the PR.
- 主要語言
- Cython
- 星號
- 3.4k
- 分支
- 353
- 平均合併
- 2 天 3 小時
- 30 天內合併 PR
- 163
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
NVIDIA/cuda-python 的其他 Issue
-
[BUG]: the `__cuda_stream__` deprecation warning points to `Stream(obj)`, which always raises可能已有人在做 @Iamsohungrynow 於 5 天前認領。 未關閉bug cuda.core P1
難度 1/5 1 小時以內 新手友好度 86/100
NVIDIA/cuda-python#3505 · 3 則留言 · 1 個 reaction · 已指派 1 人 ·
維護者通常 1 天內回覆
-
[BUG]: ProcessInfo.used_gpu_memory returns the NVML_VALUE_NOT_AVAILABLE sentinel as a byte count未關閉triage
難度 2/5 1-3 小時 新手友好度 80/100
NVIDIA/cuda-python#3468 · 3 則留言 ·
維護者通常 1 天內回覆
-
triage
難度 2/5 1-3 小時 新手友好度 68/100
NVIDIA/cuda-python#3409 ·
維護者通常 1 天內回覆
-
[BUG]: cleanup-pr-previews never removes previews of deleted PRs可能重新可做 @rwgk 於 48 天前認領,目前沒有進行中的 PR。 未關閉
難度 2/5 1-3 小時 新手友好度 84/100
NVIDIA/cuda-python#2952 · 已指派 1 人 ·
維護者通常 1 天內回覆
-
[BUG]: LocatedHeaderDir is mutable, so callers can poison the cached header-directory lookup可能已有人在做 @rwgk 於 62 天前認領。 未關閉triage
難度 2/5 1-3 小時 新手友好度 82/100
NVIDIA/cuda-python#2646 · 1 個 reaction ·
維護者通常 1 天內回覆
查看 NVIDIA/cuda-python 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 78/100
TigreGotico/tugaphone#408 ·
維護者通常 1 天內回覆
-
area:testing bug effort:low model:light plan planner:gpt-6-2-sol tests
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
good first issue
難度 2/5 1-3 小時 新手友好度 72/100
laaielichter/Godotwright#250 ·
維護者通常 1 天內回覆
-
cleanup
難度 2/5 1-3 小時 新手友好度 72/100
CivicTechWR/accessible-housing-portal#637 ·
維護者通常 1 天內回覆
-
priority: low tests
難度 2/5 1-3 小時 新手友好度 75/100
LearningCircuit/local-deep-research#9161 ·
維護者通常 1 天內回覆