[BUG]: Program.compile(cache=...) returns another directory's binary when the source has a quoted #include

Offen
#3,447 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
45/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
python
Bereich
backend, databases

Rechercherichtung

Start with make_program_cache_key and the tests in test_program_cache.py; trace how quoted includes and extra_digest affect cache keys, including the debug and lineinfo path that adds the working directory as an include path. Then review test_program_compile_cache.py and run the reported cases with and without caching. Done means the cache cannot return a binary compiled against another working directory's header, while source without quoted includes remains unaffected.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

triage

For a name without a directory component (the default "default_program"), NVRTC resolves #include "x.h" against the current working directory. make_program_cache_key does not account for that header. The docstring of test_make_program_cache_key_accepts_nvrtc_name_without_dir_component says relative includes don't reach outside the in-memory program, but they do. So two projects that compile the same kernel text through the default FileStreamProgramCache() (shared per user) can get each other's binaries.

The #1912 review raised this case. The guard was scoped to names with a directory component on the premise that the working directory is "the same search root every NVRTC compile sees". But the default cache is per user and outlives any one working directory, so that premise does not hold.

Repro (cuda-core 1.2.2 wheel and a main 303fbdac source build, NVRTC 13.5, x86_64 Linux, compile only):

# run once in dir A with val.h = "#define VAL 111", then in dir B with "#define VAL 222"
import sys
from cuda.core import Program, ProgramOptions
from cuda.core.utils import FileStreamProgramCache
src = '#include "val.h"\nextern "C" __global__ void k(int *p){ *p = VAL; }\n'
for cache in (None, FileStreamProgramCache(sys.argv[1])):
    obj = Program(src, "c++", options=ProgramOptions(arch="sm_90")).compile("ptx", cache=cache)
    print([l.strip() for l in bytes(obj.code).decode().splitlines() if "mov.u32" in l])

Results:

  • Dir A: 111 both uncached and cached.
  • Dir B: 222 uncached, but 111 cached.
  • Same result in a single process when val.h is edited between two cached compiles.

debug=True / lineinfo=True hit the same problem through a second path. For default_program, Program adds --include-path=<cwd>, which is not part of the key, so even <val.h> and no_source_include=True resolve from the working directory there.

Possible fix, mirroring the existing directory-component guard: make_program_cache_key raises ValueError for NVRTC source containing a quoted #include when there is no extra_digest. no_source_include=True is accepted, except for that debug/lineinfo case. Source without quoted includes is unaffected. I have this with unit tests in test_program_cache.py and an integration test in test_program_compile_cache.py: they fail before (5 tests) and pass after. The rest of both files has the same results before and after; I ran them without a GPU, so the 3 GPU tests were not exercised. I can share the patch if that direction is acceptable.

Vorherrschende Sprache
Cython
Sterne
3.4k
Forks
353
Ø Merge
2 T. 3 Std.
Gemergte PRs (30 T.)
163

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus NVIDIA/cuda-python

Alle Issues in NVIDIA/cuda-python

Ähnliche Issues

Weitere Issues zu Backend & API Design

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.