feat(pathfinder): opt-in diagnostic logging for load_nvidia_dynamic_lib - #2513
Draft
u7k4rs6 wants to merge 1 commit into
Draft
feat(pathfinder): opt-in diagnostic logging for load_nvidia_dynamic_lib#2513u7k4rs6 wants to merge 1 commit into
u7k4rs6 wants to merge 1 commit into
Conversation
Adds a `cuda.pathfinder` logger, disabled by default, enabled by setting CUDA_PATHFINDER_LOG_LEVEL to a standard level name or an integer. `logging` is imported only when the variable is set. Importing it pulls in seven additional modules and measurably slows `import cuda.pathfinder`, which sits on the import hot path of every consumer, so the disabled path imports nothing and costs one module-global lookup plus an identity check (~5 ns) at each call site. No message string or `extra` dict is built when logging is off. Instruments the dynamic-library search only: each find step reports whether it matched, a successful load reports the resolved path and `found_via`, and the failure path emits the accumulated candidate list as structured fields. Records carry `pathfinder_*` fields so consumers can filter without parsing messages. The logger attaches a NullHandler, never calls basicConfig, and never touches the root logger. Invalid CUDA_PATHFINDER_LOG_LEVEL values warn once and leave logging disabled rather than raising. The environment variable is read once at import, matching the documented read-once policy of get_cuda_path_or_home(). Signed-off-by: Utkarsh Bahuguna <utkarshbahuguna10@gmail.com>
Contributor
u7k4rs6
marked this pull request as draft
August 5, 2026 17:12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Implements the interface proposed in #650. Opening as a draft: the direction was
proposed on 4 Jun and pinged since without a reply, so this is a concrete shape to
react to rather than a request to merge. Naming (logger name, env var) and level
choices are open to whatever the maintainers prefer.
Scoped to
load_nvidia_dynamic_libonly. The same pattern extends to the otherfour finder families --
find_nvidia_binary_utility,find_nvidia_header_directory,find_static_lib,find_bitcode_lib-- and I'll extend it if you like the shape.What
cuda.pathfinderlogger, disabled by default, enabled viaCUDA_PATHFINDER_LOG_LEVEL(level name or integer).path and
found_via; the failure path logs the accumulated candidate list.pathfinder_*fields (pathfinder_libname,pathfinder_found_via,pathfinder_abs_path,pathfinder_step,pathfinder_matched, ...) so consumerscan filter structurally instead of regexing messages.
found_viaalready existedon
FindResultandLoadedDL; this surfaces it rather than inventing a field.basicConfig, no root-logger configuration.On off-by-default
@rwgk argued against opt-in diagnostics in #1034, and that concern is worth
answering directly rather than leaving implicit.
SearchContext.raise_not_found()already formats the full candidate list intoDynamicLibNotFoundError, always on. The case being protected there -- someonehits a failure and then needs a second run with a flag to diagnose it -- is
already covered today, and this PR does not change it. What is off by default is
success-path telemetry, where by definition nothing needs diagnosing. Because
loggingis imported lazily, the disabled path costs nothing at all, sooff-by-default is not a tradeoff being made against visibility.
There is one real gap, and I don't want to gloss it: a load that succeeds but
resolves the wrong library.
found_viabeing off by default does cost somethingthere.
I looked at whether
warnings.warn-- already the house idiom, perenv_vars.py:96andload_dl_windows.py:90-- would fit a genuinely suspicioussuccess better than a log line. I don't think it does. Both existing uses signal
an actionable anomaly, and neither shape applies:
that a conda copy shadowed a site-packages copy would mean continuing the search
after a hit -- real filesystem work on every successful load.
was_already_loaded_from_elsewhere. Warning on it would be wrong: it is thenormal case whenever two NVIDIA libraries share a dependency, so it would fire
constantly on correct usage.
So it stays a log field. If you'd rather have an always-on warning for some
narrower condition, I'm happy to add it -- I just couldn't find one that is both
cheap to detect and reliably suspicious.
Import cost
import loggingpulls in seven modules (logging,atexit,string,_string,textwrap,traceback,_colorize). Measured on this branch:sys.modulesafterimport cuda.pathfinderFalseTruePer call site, disabled: 29.7 ns vs 24.7 ns baseline over 500k iterations.
Provenance
Written with AI assistance. The new tests carry
@pytest.mark.agent_authored(model="claude-opus-5"), the convention documentedin
AGENTS.md; flagging it here too since that marker only covers tests, andthis PR also adds source under
cuda/pathfinder/_utils/.Checklist
Docs box unticked deliberately: nothing user-facing is documented yet, and where
it belongs (
docs/source/, the env-var list, or underload_nvidia_dynamic_lib)is worth a steer first.