|
| 1 | +This file describes `cuda_pathfinder`, a Python sub-package of |
| 2 | +[cuda-python](https://github.com/NVIDIA/cuda-python). It locates and loads |
| 3 | +NVIDIA dynamic libraries (CTK, third-party, and driver) across Linux and |
| 4 | +Windows. |
| 5 | + |
| 6 | +## Scope and principles |
| 7 | + |
| 8 | +- **Language**: all implementation code in this package is pure Python. |
| 9 | +- **Public API**: keep user-facing imports stable via `cuda.pathfinder`. |
| 10 | + Internal modules should stay under `cuda.pathfinder._*`. |
| 11 | +- **Behavior**: loader behavior must remain deterministic and explicit. Avoid |
| 12 | + "best effort" silent fallbacks that mask why discovery/loading failed. |
| 13 | +- **Cross-platform**: preserve Linux and Windows behavior parity unless a change |
| 14 | + is explicitly platform-scoped. |
| 15 | + |
| 16 | +## Package architecture |
| 17 | + |
| 18 | +- **Descriptor source-of-truth**: `cuda/pathfinder/_dynamic_libs/descriptor_catalog.py` |
| 19 | + defines canonical metadata for known libraries. |
| 20 | +- **Registry layers**: |
| 21 | + - `lib_descriptor.py` builds the name-keyed runtime registry from the catalog. |
| 22 | + - `supported_nvidia_libs.py` keeps legacy exported tables derived from the |
| 23 | + catalog for compatibility. |
| 24 | +- **Search pipeline**: |
| 25 | + - `search_steps.py` implements composable find steps (`site-packages`, |
| 26 | + `CONDA_PREFIX`, `CUDA_HOME`/`CUDA_PATH`, canary-assisted CTK root flow). |
| 27 | + - `search_platform.py` and `platform_loader.py` isolate OS-specific logic. |
| 28 | +- **Load orchestration**: |
| 29 | + - `load_nvidia_dynamic_lib.py` coordinates find/load phases, dependency |
| 30 | + loading, driver-lib fast path, and cache semantics. |
| 31 | +- **Process isolation helper**: |
| 32 | + - `cuda/pathfinder/_utils/spawned_process_runner.py` is used where process |
| 33 | + global dynamic loader state would otherwise leak across tests. |
| 34 | + |
| 35 | +## Editing guidance |
| 36 | + |
| 37 | +- **Edit authored descriptors, not derived tables**: when adding/changing a |
| 38 | + library, update `descriptor_catalog.py` first; keep derived exports in sync |
| 39 | + through existing conversion logic and tests. |
| 40 | +- **Respect cache semantics**: `load_nvidia_dynamic_lib` is cached. Never add |
| 41 | + behavior that closes returned handles or assumes repeated fresh loads. |
| 42 | +- **Keep error contracts intact**: |
| 43 | + - unknown name -> `DynamicLibUnknownError` |
| 44 | + - known but unsupported on this OS -> `DynamicLibNotAvailableError` |
| 45 | + - known/supported but not found/loadable -> `DynamicLibNotFoundError` |
| 46 | +- **Do not hardcode host assumptions**: avoid baking in machine-local paths, |
| 47 | + shell-specific quoting, or environment assumptions. |
| 48 | +- **Prefer focused abstractions**: if a change is platform-specific, route it |
| 49 | + through existing platform abstraction points instead of branching in many call |
| 50 | + sites. |
| 51 | + |
| 52 | +## Testing expectations |
| 53 | + |
| 54 | +- **Primary command**: run `pytest tests/` from `cuda_pathfinder/`. |
| 55 | +- **Real-loading tests**: prefer spawned child-process tests for actual dynamic |
| 56 | + loading behavior; avoid in-process cross-test interference. |
| 57 | +- **Cache-aware tests**: if a test patches internals used by |
| 58 | + `load_nvidia_dynamic_lib`, call `load_nvidia_dynamic_lib.cache_clear()`. |
| 59 | +- **Negative-case names**: use obviously fake names (for example |
| 60 | + `"not_a_real_lib"`) in unknown/invalid-lib tests. |
| 61 | +- **INFO summary in CI logs**: use `info_summary_append` for useful |
| 62 | + test-context lines visible in terminal summaries. |
| 63 | +- **Strictness toggle**: |
| 64 | + `CUDA_PATHFINDER_TEST_LOAD_NVIDIA_DYNAMIC_LIB_STRICTNESS` controls whether |
| 65 | + missing libraries are tolerated (`see_what_works`) or treated as failures |
| 66 | + (`all_must_work`). |
| 67 | + |
| 68 | +## Useful commands |
| 69 | + |
| 70 | +- Run package tests: `pytest tests/` |
| 71 | +- Run package tests via orchestrator: `../scripts/run_tests.sh pathfinder` |
| 72 | +- Build package docs: `cd docs && ./build_docs.sh` |
0 commit comments