An application compiled using `nvcc` does not show its dependency on the `libcuda.so` library with `ldd` linux command

Suppose I have a program say toy.cu and I compile it using nvcc as follows:

$ nvcc -o toy toy.cu

The executable that is created does not seem to have a dependency on the CUDA driver API: libcuda.so (found at /usr/lib/x86_64-linux-gnu/libcuda.so)

As reported by ldd:

$ ldd toy
        linux-vdso.so.1 (0x00007fff99554000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fa42a200000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fa429fe1000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fa429ddd000)
        libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fa429a54000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fa42983c000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa42944b000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fa42a67d000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fa4290ad000)

There is no mention of libcuda.so

However, when I compile the same program using nvcc but with cudart (CUDA runtime API library) as shared:

$ nvcc -o toy toy.cu --cudart shared

and try to do ldd, the dependency on cudart.so is reported:

$ ldd toy
       linux-vdso.so.1 (0x00007ffd09d7c000)
        libcudart.so.10.1 => /usr/local/cuda-10.1/targets/x86_64-linux/lib/libcudart.so.10.1 (0x00007f1a11829000)
        libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f1a114a0000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f1a11288000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f1a10e97000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f1a10c78000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f1a10a70000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f1a106d2000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f1a11e8e000)

If the CUDA runtime API (when linked dynamically) dependency is shown in ldd, why isn’t the dependency on the CUDA driver API shown?

this is expected behavior.

Runtime API applications generally do not show a runtime-linker dependency on libcuda.so (regardless of whether you link statically or dynamically against cudart - there is no dependence on libcuda.so reported by ldd in either of your cases).

Also, libcudart.so and libcuda.so are not the same thing.

libcudart provides the runtime API.
libcuda provides the driver API.

Although the runtime API (usage) might use the driver API “under the hood” in some cases, such dependency is not evident using the linux runtime-dynamic-linking method, because apparently libcudart uses a different method to load and make use of that library (libcuda.so)

You can find various other related questions on these forums. Such as here

1 Like

Runtime API applications generally do not show a dependency on libcuda.so

@Robert_Crovella is this behavior specific to libcuda.so?

I don’t really understand the question. The statement you excerpted from my answer is most definitely specific to libcuda.so - it states “on libucuda.so” directly in the excerpt.

1 Like

@Robert_Crovella Thanks got the point.