Skip to content

[BUG]: static and bitcode library finders return relative paths #3363

Open

Description

@0z5a

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

Silent Failure

Component

cuda.pathfinder

Describe the bug

find_bitcode_lib() and find_static_lib() document absolute return paths, but return relative paths when a selected search root is relative. The corresponding locate_* results also expose a relative abs_path. Since the find_* functions cache their results, changing the working directory can leave the cached paths pointing to nonexistent files.

I reproduced this on main at commit deb3d040b6d31b8514f19d026c298982c9b6260b. Relative Conda and site-packages roots have the same problem.

How to Reproduce

In a clean Python environment without NVIDIA wheel directories taking precedence, run:

import os
import tempfile
from pathlib import Path

from cuda.pathfinder import find_bitcode_lib, find_static_lib, get_cuda_path_or_home

os.environ.pop("CUDA_PATH", None)
os.environ.pop("CONDA_PREFIX", None)

with tempfile.TemporaryDirectory() as directory:
    os.chdir(directory)
    for path in (
        Path("toolkit/nvvm/libdevice/libdevice.10.bc"),
        Path("toolkit/lib64/libcudadevrt.a"),
    ):
        path.parent.mkdir(parents=True, exist_ok=True)
        path.touch()

    os.environ["CUDA_HOME"] = "toolkit"
    get_cuda_path_or_home.cache_clear()
    results = {
        "bitcode": find_bitcode_lib("device"),
        "static": find_static_lib("cudadevrt"),
    }
    for name, value in results.items():
        print(name, value, "absolute:", Path(value).is_absolute())

    os.chdir("/")
    for name, value in results.items():
        print(name, "exists after chdir:", Path(value).is_file())

Observed: both returned paths are relative and both exists after chdir values are false.

Expected behavior

Both paths are absolute and still identify the selected files after the working directory changes. Converting a path must also preserve POSIX symlink/.. traversal; lexical normalization before resolving the symlink can point at a different file.

Operating System

Linux aarch64, Python 3.12.3.

nvidia-smi output

Not GPU-dependent; reproduced with CUDA devices hidden.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    triageNeeds the team's attention

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions