Detecting CUDA RT presence at runtime


[this is my first post on NVidia forums. I have seen my question asked several times in 2008 and 2009 by other people, but could not find any positive answer. Maybe things have changed now in 2011].

I would like to develop a program that runs on Windows, and which optimizes computing with the Cuda Runtime API, IF AND ONLY IF a Cuda-enabled GPU is available.

My problem is that if Cuda is not available, the Cudart DLL cannot be loaded (because not found by the OS), and the program does not even start.

I have seen that the Driver API could make a delayed load of nvcuda.dll, but in 2008 or 2009, this apparently was not working with cudart.dll. And my code, using the Runtime API, is working fine (well, when Cuda is available only), so I would definitely prefer not to rewrite it on the Driver API.

So my questions are:

  1. is there a way to distribute a Cudart.dll file with my program, that would let the program start, and from which the cudaXxxx functions would return an error if Cuda is not available? (in which case I would branch execution to some CPU-based slower computing)

  2. or, is there a way to delay-load Cudart.dll and use the Cuda Runtime API?

Thanks in advance for your help,

The CUDART DLL in particular is to be distributed with your application, as there is no cross compatibility between CUDART versions.

So, (1): yes. do that.

Many thanks, I have just tested, and the program loads. Indeed, my program is a DLL loaded by a 3rd party EXE software…

I am wondering where to install the Cudart dll:

  1. if I put it in the directory of my DLL, it is not found
  2. I can’t assume anything about the place where the 3rd party EXE is installed
  3. if I put it in the Windows/System32 directory, it works great, but I am not sure it is a good idea to place it there (due to other Cudart versions for other software).

Any suggestion for this?

If it may help, I am using Cudart64_40_17.dll and Cudart32_40_17.Dll.

Thanks again,

Do not put it into system32. It should go in the same location as your application (presumably the same location as the DLL should work, but I don’t know enough about the Windows loader to say for sure).

hummm, ok I won’t. Too bad, it was so easy… However I don’t understand why I should not. The Cuda RT DLL name seems to have a version ID (40_17) in its name, so I would say it’s not a problem to put it in system32. Explanation will be welcome if possible…

Anyhow I will investigate another way with another location.

Thanks again! I have been looking for a way to detect Cuda for 2 days without any success before your help.


You could also embed the CUDART dll within your DLL as a binary resource, then load it at runtime with LoadLibrary().

In any case, the CUDART dll should be detected by your library when it’s placed in the same folder; if it’s not, that may be due to some security settings (are you on a domain?) or some other configuration problem with your system. In fact, this behavior (where Windows will resolve/load DLLs in the same folder as the referencing binary) is a security issue, since you can easily “inject” your own versions of binaries into an application – which is why Microsoft recently added some security controls for DLL-loading behavior (hence my suggestion above).

The embedded-DLL way is slightly complicated, but ensures that the CUDART will always be available to you, that it’s the correct version, etc.

Do you use Qt to load your plugins?