You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[FEA]: Support for finding libmathdx through pathfinder #776
conda create -y -n libmathdx python=3.12
conda activate libmathdx
conda install conda-forge::libmathdx
cd cuda_pathfinder
pip install .
python
Python 3.12.11 | packaged by conda-forge | (main, Jun 4 2025, 14:45:31) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from cuda.pathfinder import load_nvidia_dynamic_lib
>>> load_nvidia_dynamic_lib("mathdx")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/rgrossekunst/forked/cuda-python/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_nvidia_dynamic_lib.py", line 71, in load_nvidia_dynamic_lib
return _load_lib_no_cache(libname)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/rgrossekunst/forked/cuda-python/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_nvidia_dynamic_lib.py", line 44, in _load_lib_no_cache
found.raise_if_abs_path_is_None()
File "/home/rgrossekunst/forked/cuda-python/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/find_nvidia_dynamic_lib.py", line 194, in raise_if_abs_path_is_None
raise DynamicLibNotFoundError(f'Failure finding "{self.lib_searched_for}": {err}\n{att}')
cuda.pathfinder._dynamic_libs.load_dl_common.DynamicLibNotFoundError: Failure finding "libmathdx.so": No such file: libmathdx.so*
>>>
I.e. unfortunately PR #834 but itself does not work because conda does not create a libmathdx.so softlink:
(libmathdx) a1u1g-mil-0536.nvidia.com:~/forked/cuda-python/cuda_pathfinder $ python
Python 3.12.11 | packaged by conda-forge | (main, Jun 4 2025, 14:45:31) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from cuda.pathfinder import load_nvidia_dynamic_lib
>>> load_nvidia_dynamic_lib("mathdx")
LoadedDL(abs_path='/home/rgrossekunst/miniforge3/envs/libmathdx/lib/python3.12/lib-dynload/../../libmathdx.so', was_already_loaded_from_elsewhere=False, _handle_uint=95200120396080)
>>>
Detect that we're running with a condapython interpreter
Then use this simple trick to get the absolute path to the .so:
Look for the equivalent of $ORIGIN/../lib (RPATH of the condapython command), but starting with sys.executable:
(libmathdx) a1u1g-mil-0536.nvidia.com:~/forked/cuda-python/cuda_pathfinder $ python
Python 3.12.11 | packaged by conda-forge | (main, Jun 4 2025, 14:45:31) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import glob, os, sys
>>> glob.glob(os.path.join(os.path.join(os.path.dirname(os.path.dirname(sys.executable)), "lib"), "libmathdx.so*"))
['/home/rgrossekunst/miniforge3/envs/libmathdx/lib/libmathdx.so.0.2.2', '/home/rgrossekunst/miniforge3/envs/libmathdx/lib/libmathdx.so.0']
That wouldn't be very different from how we find .so files under site-packages.
I'm pretty sure it is intended behavior for all conda-forge libraries. Don't we have to link towards <libmaname>.so.<major> by default?
Only if there is no softlink. /usr/local/cuda has them (I just checked systematically, 13.0.0). At the moment I believe conda is the only situation we care about that needs the "simple trick" proposed above.
For site-packages, pathfinder is similarly searching for .so* files:
It's just that conda doesn't take the "next step down" to also provide lib/libavif.so. It surprised me a couple weeks ago. The fix at that time was this. Now I'm thinking we should handle this more generally with the "simple trick"; and maybe even undo that fix, but I'm not sure, maybe it'll be better to have both?
For the load_nvidia_dynamic_lib API we should really be trying to load based on the SONAME of the libraries that we're loading. I.E. if you compile something and link against a library, it will add a DT_NEEDED entry using the SONAME and will only find the library at runtime if there's a versioned file and won't try to load an unversioned one. If / when we introduce a find_nvidia_dynamic_lib API then trying to find an unversioned file would make more sense in my opinion.
Conda-forge packages are often split into runtime vs dev variants where the runtime variants only contain the versioned files that are referred to by the SONAME and the dev variants typically have the unversioned softlink to be used at build-time. For libmathdx there is a libmathdx package which is meant to be a runtime package, and a libmathdx-dev which is meant to be a dev package.
It's just that conda doesn't take the "next step down" to also provide lib/libavif.so. It surprised me a couple weeks ago. The fix at that time was this. Now I'm thinking we should handle this more generally with the "simple trick"; and maybe even undo that fix, but I'm not sure, maybe it'll be better to have both?
It is done on purpose, so users can install multiple major versions of the library in case they need multiple software in the env that depends on the same library, but different version.
I'm not sure for 100%, but it is python environment that is different, cause it is expected to use only python and as result only one runtime is allowed. And since we can't have multiple major ctks loaded in one process we simply can use libraries without soversion.
Given that cuda_pathfinder aims to support multiple methods of CUDA installation it still needs to be aware of the case where the user updates the minor version of the system CTK and expects everything to keep working, right? IOW you should still be using the SOVERSIONed binary?
Activity
rwgk commentedon Aug 13, 2025
I tried this using PR #834:
I.e. unfortunately PR #834 but itself does not work because
condadoes not create alibmathdx.sosoftlink:But after manually creating the softlink it works:
rwgk commentedon Aug 13, 2025
Idea: We could
condapythoninterpreter.so:Look for the equivalent of
$ORIGIN/../lib(RPATHof thecondapythoncommand), but starting withsys.executable:That wouldn't be very different from how we find
.sofiles undersite-packages.ZzEeKkAa commentedon Aug 14, 2025
I'm pretty sure it is intended behavior for all
conda-forgelibraries. Don't we have to link towards<libmaname>.so.<major>by default?https://github.com/conda-forge/cfep/pull/61/files#diff-9945e90feca9cf4f6cbccd6226992ff78ee4fc69f326455b933665813c46c7caR108-R119
https://github.com/conda-forge/libmathdx-feedstock/blob/main/recipe/meta.yaml#L59C47-L60
rwgk commentedon Aug 14, 2025
Only if there is no softlink.
/usr/local/cudahas them (I just checked systematically, 13.0.0). At the moment I believecondais the only situation we care about that needs the "simple trick" proposed above.For
site-packages,pathfinderis similarly searching for.so*files:cuda-python/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/find_nvidia_dynamic_lib.py
Lines 162 to 164 in b87c787
cuda-python/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/find_nvidia_dynamic_lib.py
Line 31 in b87c787
That looks pretty standard:
It's just that
condadoesn't take the "next step down" to also providelib/libavif.so. It surprised me a couple weeks ago. The fix at that time was this. Now I'm thinking we should handle this more generally with the "simple trick"; and maybe even undo that fix, but I'm not sure, maybe it'll be better to have both?kkraus14 commentedon Aug 14, 2025
For the
load_nvidia_dynamic_libAPI we should really be trying to load based on theSONAMEof the libraries that we're loading. I.E. if you compile something and link against a library, it will add aDT_NEEDEDentry using theSONAMEand will only find the library at runtime if there's a versioned file and won't try to load an unversioned one. If / when we introduce afind_nvidia_dynamic_libAPI then trying to find an unversioned file would make more sense in my opinion.Conda-forge packages are often split into
runtimevsdevvariants where theruntimevariants only contain the versioned files that are referred to by theSONAMEand thedevvariants typically have the unversioned softlink to be used at build-time. Forlibmathdxthere is alibmathdxpackage which is meant to be aruntimepackage, and alibmathdx-devwhich is meant to be adevpackage.ZzEeKkAa commentedon Aug 14, 2025
It is done on purpose, so users can install multiple major versions of the library in case they need multiple software in the env that depends on the same library, but different version.
Conda's convention is inherited from debian in some way. So it is pretty common for runtime libraries. https://www.debian.org/doc/debian-policy/ch-sharedlibs.html#run-time-shared-libraries
I'm not sure for 100%, but it is python environment that is different, cause it is expected to use only python and as result only one runtime is allowed. And since we can't have multiple major ctks loaded in one process we simply can use libraries without soversion.
vyasr commentedon Aug 14, 2025
Given that
cuda_pathfinderaims to support multiple methods of CUDA installation it still needs to be aware of the case where the user updates the minor version of the system CTK and expects everything to keep working, right? IOW you should still be using the SOVERSIONed binary?