Skip to content

Library bindings are not importable if the underlying library is not installed #951

Description

@leofang

During the investigation of #920 I noticed that if I remove nvJitLink from my current environment, cuda.core cannot fall back to use the cuLink* driver APIs because the pathfinder error is not caught:

Traceback (mostrecentcalllast):
File"/local/home/leof/dev/debug_920.py", line94, in<module>program=Program(code, code_type="ptx", options=options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File"/local/home/leof/dev/cuda-python/cuda_core/cuda/core/experimental/_program.py", line411, in__init__ObjectCode._init(code.encode(), code_type), options=self._translate_program_options(options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File"/local/home/leof/dev/cuda-python/cuda_core/cuda/core/experimental/_program.py", line420, in_translate_program_optionsreturnLinkerOptions(
^^^^^^^^^^^^^^File"<string>", line24, in__init__File"/local/home/leof/dev/cuda-python/cuda_core/cuda/core/experimental/_linker.py", line189, in__post_init___lazy_init()
File"/local/home/leof/dev/cuda-python/cuda_core/cuda/core/experimental/_linker.py", line69, in_lazy_init_decide_nvjitlink_or_driver()
File"/local/home/leof/dev/cuda-python/cuda_core/cuda/core/experimental/_linker.py", line47, in_decide_nvjitlink_or_driverifinner_nvjitlink._inspect_function_pointer("__nvJitLinkVersion") ==0:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File"cuda/bindings/_internal/nvjitlink.pyx", line247, incuda.bindings._internal.nvjitlink._inspect_function_pointerFile"cuda/bindings/_internal/nvjitlink.pyx", line250, incuda.bindings._internal.nvjitlink._inspect_function_pointerFile"cuda/bindings/_internal/nvjitlink.pyx", line198, incuda.bindings._internal.nvjitlink._inspect_function_pointersFile"cuda/bindings/_internal/nvjitlink.pyx", line70, incuda.bindings._internal.nvjitlink._check_or_init_nvjitlinkFile"cuda/bindings/_internal/nvjitlink.pyx", line92, incuda.bindings._internal.nvjitlink._check_or_init_nvjitlinkFile"cuda/bindings/_internal/nvjitlink.pyx", line58, incuda.bindings._internal.nvjitlink.load_libraryFile"/local/home/leof/miniforge3/envs/py312_cu129/lib/python3.12/site-packages/cuda/pathfinder/_dynamic_libs/load_nvidia_dynamic_lib.py", line120, inload_nvidia_dynamic_libreturn_load_lib_no_cache(libname)
^^^^^^^^^^^^^^^^^^^^^^^^^^^File"/local/home/leof/miniforge3/envs/py312_cu129/lib/python3.12/site-packages/cuda/pathfinder/_dynamic_libs/load_nvidia_dynamic_lib.py", line48, in_load_lib_no_cachefound.raise_if_abs_path_is_None()
File"/local/home/leof/miniforge3/envs/py312_cu129/lib/python3.12/site-packages/cuda/pathfinder/_dynamic_libs/find_nvidia_dynamic_lib.py", line199, inraise_if_abs_path_is_NoneraiseDynamicLibNotFoundError(f'Failure finding "{self.lib_searched_for}": {err}\n{att}')
cuda.pathfinder._dynamic_libs.load_dl_common.DynamicLibNotFoundError: Failurefinding"libnvJitLink.so": Nosuchfile: libnvJitLink.so*, Nosuchfile: libnvJitLink.so*

This echos @kkraus14's concern earlier (#728). We want to be able to catch errors at run time when the underlying library (including the driver) does not provide the needed symbol, which implies that the exception raising should be deferred to as late as when it's actually needed.

Metadata

Metadata

Assignees

Labels

P0High priority - Must do!bugSomething isn't workingcuda.coreEverything related to the cuda.core module

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions