Skip to content

refactor(pathfinder): static and bitcode finders share one search - #3608

Open
rparolin wants to merge 4 commits into
pathfinder-readability/6-search-steps-return-missesfrom
pathfinder-readability/7-share-static-bitcode-locate
Open

rparolin wants to merge 4 commits into
pathfinder-readability/6-search-steps-return-missesfrom
pathfinder-readability/7-share-static-bitcode-locate

Conversation

@rparolin

@rparolin rparolin commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

— codex on behalf of Ralf —

Description

Part 8 of 23 of a readability stack for cuda.pathfinder (stack: #3623 → #3602 → #3603 → #3604 → #3605 → #3606 → #3607 → #3608 → #3609 → #3610 → #3611 → #3613 → #3618 → #3619 → #3620 → #3621 → #3622 → #3627 → #3628 → #3629 → #3630 → #3631 → #3632). No behavior change.

find_static_lib.py was written as a copy of find_bitcode_lib.py (#1690). Each had its own finder class, its own copy of the three search steps, and its own error formatter, and later changes had to be made twice (#2493, #2708, #3418).

Both now call locate_file() in the new _static_libs/locate_file.py: site-packages, then $CONDA_PREFIX, then $CUDA_PATH. It returns the hit. On a miss it raises the caller's own documented error: each public function passes its error class. The two finder classes and their scratch lists are gone (379 -> 275 lines in _static_libs/).

An unreachable fallback message ("No search paths available") is dropped: the last search step always reported a reason.

Tests: the 15 monkeypatch.setattr(..., "find_sub_dirs_all_sitepackages") calls now patch locate_file, where that lookup lives. Nothing else changes.

No behavior change. Checked beyond the test suite: 831 scenarios (every supported name; Linux, Windows x64, Windows arm64; file in each search location or nowhere; CONDA_PREFIX set, unset, empty; CUDA_PATH, CUDA_HOME, unset, missing directory, relative path) give the same result, error type and error text as main, byte for byte.

Also in this PR: describe the shared static/bitcode search accurately.

The not-found message describes the first CUDA_PATH directory tried, not the last place searched; its docstring now says so. AGENTS.md names _static_libs/locate_file.py as the search both finders share.

Also in this PR: build the not-found error from the root that was searched.

A first version read get_cuda_path_or_home() twice: once to search and once to write the error. The original finders read it once. If two threads looked up at the same time on a cold cache while CUDA_HOME changed, the error could name a directory that was never searched. CodeRabbit found this.

locate_file now raises the finder's error itself, from the root it read. The message text is unchanged. A new test fails on the two-read version and passes now, and the 831 scenarios are still byte-identical to main.

Testing

  • Full cuda_pathfinder test suite at this commit: 1651 passed, 6 skipped (Linux, Python 3.14).
  • pre-commit clean, including mypy-pathfinder.
  • Not run on Windows. Windows rules are exercised by tests that simulate Windows on Linux.

PLC Local Security Evidence (Advisory)

Local advisory checks only, run over the whole stack. Not release-gate results.

Check Status Tool Details
Secrets SKIP Pulse Secret Scanner scanner image not available locally (registry login); the repo trufflehog pre-commit hook passed
SAST WARN Semgrep 1 finding, not from this stack: the existing subprocess.run call in the canary probe in load_nvidia_dynamic_lib.py
Dependencies WARN pip-audit / osv-scanner no manifest or lockfile in scope, so the local scan could not run; this stack changes no dependencies
License N/A - no dependencies changed
Container N/A - no container changed

Checklist

  • I have read the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

🤖 Generated with Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@rparolin
rparolin added this pull request to stack #3612 November 25, 2026 21:14
@github-actions github-actions Bot added the cuda.pathfinder Everything related to the cuda.pathfinder module label Nov 25, 2026
@rparolin rparolin added the enhancement Any code-related improvements label Nov 25, 2026
@rparolin rparolin added this to the cuda.pathfinder next milestone Nov 25, 2026
@rparolin
rparolin removed this pull request from stack #3612 November 25, 2026 22:28
@rparolin
rparolin added this pull request to stack #3616 November 25, 2026 22:29
@rparolin rparolin self-assigned this Nov 25, 2026
@rparolin
rparolin requested review from juenglin and rwgk November 25, 2026 23:06
@rparolin
rparolin marked this pull request as ready for review November 26, 2026 16:16
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

Commits

Reviewing files that changed from the base of the PR and between db618f7 and 358af9b.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Static and bitcode library discovery now use a consistent search order across package directories, Conda environments, and CUDA Toolkit paths, including Windows Conda installations.
    • When a library is not found, the error identifies the first CUDA directory searched or indicates that CUDA_HOME/CUDA_PATH is unset.

Static and bitcode library lookup now uses a shared helper to search site-packages, Conda, and CUDA Toolkit locations. The helper returns the resolved path and source label, or raises the caller’s configured error with a not-found diagnostic.

Changes: CUDA library lookup

Layer / File(s) Summary
Shared search and diagnostics
cuda_pathfinder/cuda/pathfinder/_static_libs/locate_file.py, cuda_pathfinder/AGENTS.md
Adds ordered file lookup and shared not-found diagnostics. The architecture documentation identifies the helper and its callers.
Static and bitcode lookup integration
cuda_pathfinder/cuda/pathfinder/_static_libs/find_static_lib.py, cuda_pathfinder/cuda/pathfinder/_static_libs/find_bitcode_lib.py, cuda_pathfinder/tests/test_find_static_lib.py, cuda_pathfinder/tests/test_find_bitcode_lib.py
Both lookup functions delegate searches to the shared helper. Tests patch site-packages discovery through the helper module. A bitcode test checks that the error reports the CUDA root used for the search.

Possibly related PRs

Suggested reviewers: abhilash1910, cpcloud

Change: Refactor

Merge Risk: Minimal · previous review db618

This refactor merges the static and bitcode library lookups into one shared search without changing behavior. Not-found errors now name the CUDA root that was actually searched, and a test covers this. No merge-blocking risk remains.

Security architecture risk: Minimal · up to db618

The refactor preserves where both finders look, which file they select, and how they report a miss. It does not give callers access to new search locations.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between ec43040 and db618f7.

Files selected for processing: 4

  • cuda_pathfinder/cuda/pathfinder/_static_libs/find_bitcode_lib.py
  • cuda_pathfinder/cuda/pathfinder/_static_libs/find_static_lib.py
  • cuda_pathfinder/cuda/pathfinder/_static_libs/locate_file.py
  • cuda_pathfinder/tests/test_find_bitcode_lib.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 0 remain after this review.

@github-actions

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comments: 1

cuda_pathfinder/cuda/pathfinder/_static_libs/find_bitcode_lib.py: 1

87-87: Minor · Functional Correctness · Low value

suggestion: Report the CUDA Toolkit root that locate_file searched.

When two lookups overlap on a cold get_cuda_path_or_home() cache, a CUDA_HOME change between their reads can replace the cached root. locate_file probes the root it read. not_found_message then reads the cache again. On a miss, the error can name a directory the lookup never searched, and it can list a file that exists there. The exception type stays the same. The base revision formatted the error from the root it searched.

The trigger is narrow. It needs overlapping cold-cache lookups and an environment change during them. A single-threaded change does not trigger it, because locate_file fills the cache before not_found_message runs.

Have locate_file return the searched root or the formatted diagnostic in its miss result. Use that value in each finder that raises a not-found error. Keep the early return on a hit. This also removes the second get_cuda_path_or_home() read on the miss path.

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 4bc2808 and ec43040.

Files selected for processing: 4

  • cuda_pathfinder/cuda/pathfinder/_static_libs/find_bitcode_lib.py
  • cuda_pathfinder/cuda/pathfinder/_static_libs/find_static_lib.py
  • cuda_pathfinder/tests/test_find_bitcode_lib.py
  • cuda_pathfinder/tests/test_find_static_lib.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 3 remain after this review.

rparolin and others added 4 commits November 26, 2026 11:17
`find_static_lib.py` was written as a copy of `find_bitcode_lib.py`
(#1690). Each had its own finder class, its own copy of the three
search steps, and its own error formatter, and later changes had to be
made twice (#2493, #2708, #3418).

Both now call `locate_file()` in the new `_static_libs/locate_file.py`:
site-packages, then `$CONDA_PREFIX`, then `$CUDA_PATH`. It returns the
hit or `None`, and each public function raises its own documented
error. The two finder classes and their scratch lists are gone
(379 -> 275 lines in `_static_libs/`).

An unreachable fallback message ("No search paths available") is
dropped: the last search step always reported a reason.

Tests: the 15 `monkeypatch.setattr(..., "find_sub_dirs_all_sitepackages")`
calls now patch `locate_file`, where that lookup lives. Nothing else
changes.

No behavior change. Checked beyond the test suite: 831 scenarios (every
supported name; Linux, Windows x64, Windows arm64; file in each search
location or nowhere; `CONDA_PREFIX` set, unset, empty; `CUDA_PATH`,
`CUDA_HOME`, unset, missing directory, relative path) give the same
result, error type and error text as `main`, byte for byte.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Rob Parolin <rparolin@nvidia.com>
`not_found_message` describes the first `CUDA_PATH` directory tried,
not the last place searched; its docstring now says so. `AGENTS.md`
names `_static_libs/locate_file.py` as the search both finders share.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Rob Parolin <rparolin@nvidia.com>
…d errors

`locate_file` read `get_cuda_path_or_home()` to search, and
`not_found_message` read it a second time to write the error. The
original finders read it once. If two threads looked up at the same
time on a cold cache while `CUDA_HOME` changed, the error could name a
directory that was never searched. A review bot found this.

`locate_file` now raises the finder's own error itself, from the root
it read. The callers pass their error class and lose their `if found is
None` branch. The message text is unchanged.

A new test fails on the old code and passes now. The static and bitcode
comparison against the original code is still byte-identical (831
scenarios).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Rob Parolin <rparolin@nvidia.com>
Signed-off-by: Ralf W. Grosse-Kunstleve <rgrossekunst@nvidia.com>
@rwgk
rwgk removed this pull request from stack #3616 November 26, 2026 19:19
@rwgk
rwgk force-pushed the pathfinder-readability/7-share-static-bitcode-locate branch from db618f7 to 358af9b Compare November 26, 2026 19:19
@copy-pr-bot

copy-pr-bot Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

This branch has not been deployed

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

Labels

cuda.pathfinder Everything related to the cuda.pathfinder module enhancement Any code-related improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants