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

Abierto
#3,447 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
45/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Cython
Estrellas
3.4k
Forks
353
Merge medio
2 d 3 h
PR fusionados (30 d)
163

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de NVIDIA/cuda-python

Todos los issues de NVIDIA/cuda-python

Issues similares

Más issues de Backend & API Design

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.