3

Since newer drivers ship with the CUDA runtime (I can choose 9.1 or 9.2 in the drivers download page) my question is: should my library (which uses a CUDA kernel internally) be shipped with -lcudart_static?

I had issues launching kernels compiled with 9.2 on systems which used 9.1 CUDA drivers. What's the most 'compatible' way of ensuring my library will run everywhere a recent CUDA driver is installed? (I'm already compiling for a virtual architecture)

Dean
  • 6,610
  • 6
  • 40
  • 90

1 Answers1

7

Since newer drivers ship with the CUDA runtime (I can choose 9.1 or 9.2 in the drivers download page)

No, that's incorrect. That choice in the drivers download page is related to the fact that each CUDA version has a minimum required driver version associated with it. It does not mean that the driver ships with the CUDA runtime (stated another way, the driver does not install libcudart.so on linux and never has - with some careful experimentation on a clean install, you can prove this to yourself.)

Some additional comments:

-lcudart_static is actually the default for current/recent versions of nvcc. You can discover this by reading the nvcc manual. Therefore, by default, your executable, when compiled/built with nvcc should already be statically linked to the CUDA runtime library corresponding to the version of nvcc that you are using for compilation. The reason you might need to specify this or something like this is if you are building an application with e.g. the gnu toolchain (on linux) rather than nvcc.

The purpose of static linking to the CUDA runtime library is, as you surmise, so that an application can be built in such a way that it does not need an installation of the CUDA toolkit to run properly. It only needs a machine with a proper GPU driver install.

The most compatible way to ensure that an application will run on a range of machines with a range of GPU driver installs is to compile your application using the oldest CUDA toolkit required to meet the needs of the earliest GPU driver in the range you intend to cover. Again, you can refer to the table here.

Robert Crovella
  • 143,785
  • 11
  • 213
  • 257
  • Thanks, how can I then address issues arising when `kernel_launching<<<..>>>` an application compiled with CUDA 9.2 on drivers below 396.xx (which as you link is the minimum to support 9.2) ? – Dean Jul 02 '18 at 14:04
  • I've edited my answer. Quite simply, you need to build with an older CUDA toolkit version, as old as is necessary to support the oldest driver in the range you wish to support. CUDA has forward compatibility so that such an application (with static cudart linking) should run correctly on newer installs, but it does not have backward compatibility at this time for applications compiled against newer toolkits running on older drivers. – Robert Crovella Jul 02 '18 at 14:06