If you have control over the application build process, you can cause the linking to the CUDA runtime API to be done dynamically, in which case you can link the runtime API calls using the LD_PRELOAD trick. Therefore I conclude there is no reason to believe that I could hook a call into libcuda using the LD_PRELOAD trick, and I also observe that this restriction/limitation is not new or different in 11.4 compared to many previous versions of CUDA. Based on my observations, applications linked statically to libcudart also do not show a dependency on libcuda: $ ldd t1896 If not, there is no reason to assume we could hook calls into libcuda, if my linked application shows no dependency on libcuda. If it exposes a link to libcuda via ldd, then its reasonable to assume the routines might be intercepted with the LD_PRELOAD trick. The default usage of the CUDA runtime API (more properly, the default nvcc behavior) uses the static library, not the above dynamic ones, so here, to expect the LD_PRELOAD trick to work simply based on linking to the libcudart_static.a library, we would need to inspect an actual application. I’m fairly certain this observation can be made on CUDA versions prior to 11.4, here is the same output from 8.0: $ ldd /usr/local/cuda-8.0/lib64/libcudart.so Librt.so.1 => /lib64/librt.so.1 (0x00007fce3d118000)Īnd therefore there is no reason to presume that we could intercept calls to libcuda, originating from libcudart, via the LD_PRELOAD trick. We can observe that libcudart.so (and presumably, by extension, the runtime API, although this is not an exhaustive proof) does not link (using the formal/ldd-visible definition) to libcuda (note that it does link to libdl, a possible clue): $ ldd /usr/local/cuda-11.4/lib64/libcudart.so Such usage of a runtime-loaded library cannot be linked via the LD_PRELOAD trick. However a library can also be “manually” loaded and connections made “manually” to routine entry points. Such a mechanism will also show up as a dependency that can be inspected with the ldd tool. Using the usual method of a formal link, the link mechanism will be exposed at dynamic library load time (at application start-up, under the control of the dynamic loader, part of the linux OS), and these types of links can be hooked. A library, even a dynamically loaded one, can be “linked” to in more than one way.