How to detect CUDA devices in an application ...also when there is no CUDA drivers/runtime present o

Hi,

We want to develop an application that at startup detects whether there are any CUDA capable devices present. The application must be able to run on systems without any CUDA GPU drivers present. We use the CUDA Runtime API for our calculations. If there is no CUDA support we would like to fallback on the CPU.

Since we cannot assume that libcudart is present on the users systems, how do achieve this?

(1) Is it possible to statically link in libcudart? (the deviceQuery example shows “CUDART static linking” but is still dependent on libcudart, though)

(2) Is it possible to distribute the libcudart.so library together with the application, preferably in the application installation folder? (do you have to modify the executables RPATH to a relative location, or set LD_LIBRARY_PATH when running the app? Are these practices acceptable?)

(3) Do you have to rely on dynamically loading the library with ‘dlopen’?

I have seen this questions asked several times on the forum, but I can’t find any answers. Any help is appreciated!

I did manage to get a working solution by distributing ‘libcudart.so.3.2.16’ (and the symbolic link to it: ‘libcudart.so.3’) along with the executable in the same directory.

In order for the executable to be able to find the library located in the directory, I used the command: chrpath -r ‘$ORIGIN’ myAppName

(Notice this overwrites any existing RPATHS’s in the executable).

This seems to work. I can now query for CUDA devices and fallback to CPU.

(Although when I query cudaGetDeviceCount() I get a ‘[35] CUDA driver version is insufficient for CUDA runtime version’, which seems to be a slightly misleading error, since there is no driver)

However, I’m still not sure if this is the preferred approach (I can see there are some discussions about unsafe RPATH’s on the net).