[BUG]: Program.compile("ptx") fails on machines without a CUDA driver, although NVRTC does not need one
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
cuda/core/_program.pyx の _can_load_generated_ptx() (815 行目付近) と Program.compile のキャッシュヒット分岐 (~1192 行) から始めてください。例外を発生させている呼び出しは cuda/core/_utils/version.pyx の driver_version() で、これには libcuda が必要です。DynamicLibNotFoundError を捕捉し、失敗させる代わりにロード可能性の警告をスキップして、cubin パスを模倣してください。ドライバのないマシンでスニペットを使用して再現し、既存の cuda.core プログラムテストを確認してください。完了とは、PTX がドライバなしでコンパイルされ、警告 (またはサイレントスキップ) がエラーを置き換えることを意味します。
索引モデルが issue の本文から書いたものです。
説明
Is this a duplicate?
- I confirmed there appear to be no duplicate issues for this bug and that I agree to the Code of Conduct
Type of Bug
Runtime Error
Component
cuda.core
Describe the bug
On a Linux machine with no NVIDIA driver installed (a GitHub Actions ubuntu runner), compiling a Program to PTX with the NVRTC backend raises DynamicLibNotFoundError for libcuda.so.1. Compiling the same source to cubin with an explicit arch works on the same machine, so NVRTC itself is available.
The failure comes from the loadability check that runs before PTX compilation. _can_load_generated_ptx() calls driver_version(), which calls cuDriverGetVersion and needs libcuda. The check only decides whether to emit a RuntimeWarning, but when the driver library is missing it raises instead, and the whole compile fails. The same check is on the cache hit path in Program.compile.
This matters for CI jobs that compile kernels to PTX without a GPU, for example to inspect the generated PTX in tests. My workaround was to call cuda.bindings.nvrtc directly with the flags from ProgramOptions.as_bytes("nvrtc", "ptx"), which works without a driver.
How to Reproduce
On a machine without an NVIDIA driver. I used the ubuntu latest runner on GitHub Actions with Python 3.12.
pip install "cuda-core[cu12]==1.2.1"
from cuda.core import Program, ProgramOptions
src = 'extern "C" __global__ void k(float* x) { x[0] = 2.0f * x[0] + 1.0f; }'
# Works without a driver
Program(src, code_type="c++", options=ProgramOptions(arch="sm_75")).compile("cubin")
# Fails without a driver
Program(src, code_type="c++", options=ProgramOptions(arch="compute_75")).compile("ptx")
A public run on a runner with no libcuda shows both cases, the cubin compile passes and the ptx compile fails. https://github.com/VolodymyrLinuxovich/heat-risk-cuda/actions/runs/37217831804
Trimmed traceback from the failing run
cuda/core/_program.pyx:222: in cuda.core._program.Program.compile
cuda/core/_program.pyx:738: in cuda.core._program._program_compile_uncached
cuda/core/_program.pyx:1192: in cuda.core._program.Program_compile
cuda/core/_program.pyx:815: in cuda.core._program._can_load_generated_ptx
cuda/core/_utils/version.pyx:37: in cuda.core._utils.version.driver_version
cuda/bindings/driver.pyx:23154: in cuda.bindings.driver.cuDriverGetVersion
...
cuda.pathfinder._dynamic_libs.load_dl_common.DynamicLibNotFoundError: "cuda" is an NVIDIA driver library and can only be found via system search. Ensure the NVIDIA display driver is installed.
The _can_load_generated_ptx code on main looks the same as in 1.2.1, so I expect main behaves the same way, but I have only run 1.2.1.
Expected behavior
PTX compilation succeeds without a driver, the same as cubin compilation. When the driver version cannot be determined, the loadability check could skip the warning (or warn that loadability is unknown) instead of failing the compile.
I would be glad to open a PR for this if that approach sounds right to you.
Operating System
Ubuntu (GitHub Actions ubuntu latest runner), no NVIDIA driver
nvidia-smi output
Not available, no driver on that machine.
- 主要言語
- Cython
- スター
- 3.4k
- フォーク
- 334
- 平均マージ
- 1日 17時間
- マージ済み PR(30日)
- 136
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
NVIDIA/cuda-python のほかの issue
-
triage
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
NVIDIA/cuda-python#2952 ·
メンテナーはふだん 1 日以内に返信
-
[DOC]: cuda.core 1.1.1 note misstates program cache permissions対応中かも @leofang が 12 日前に担当しました。 オープンdocumentation P1
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
NVIDIA/cuda-python#2717 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
[DOC]: `PinnedMemoryResource.allocate` documents no parameters対応中かも @Andy-Jost が 12 日前に担当しました。 オープンcuda.core documentation P1
難易度 1/5 1〜3時間 初心者へのやさしさ 90/100
NVIDIA/cuda-python#2712 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
[BUG]: LocatedHeaderDir is mutable, so callers can poison the cached header-directory lookup対応中かも @rwgk が 12 日前に担当しました。 オープンtriage
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
NVIDIA/cuda-python#2646 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
[FEA]: Support inheritance from Buffer対応中かも @leofang が 12 日前に担当しました。 オープンcuda.core triage
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
NVIDIA/cuda-python#2435 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
NVIDIA/cuda-python の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
microsoft/TypeScript#64661 ·
メンテナーはふだん 1 日以内に返信
-
good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
Sim20004/teapot-lang#248 ·