CUDA Driver VS CUDA Runtime
Introduction
Sometimes, people were confused about CUDA (Driver) library and CUDA Runtime library when they were developing CUDA programs. In this blog post, I would like to discuss the differences between them quickly.
CUDA (Driver) Library VS CUDA Runtime Library
CUDA (Driver) Library
The CUDA (Driver) library was installed with NVIDIA Driver, and it is intended for low-level CUDA programming. The shared library name that we usually use for linking the CUDA program is libcuda.so
and its header file name is cuda.h
. Its API is sometimes called as “CUDA Driver API”. The documentation for CUDA Driver API could be found here.
1 | $ find / -name cuda.h |
1 | $ find / -name libcuda.* |
From the library filenames, we could see that the NVIDIA Driver version is 450.66
.
CUDA Runtime Library
The CUDA Runtime library was installed with NVIDIA CUDA Toolkit, and it is intended for high-level CUDA programming. If we install NVIDIA CUDA Toolkit, the NVIDIA driver will also be installed. The shared library name that we usually use for linking the CUDA program is libcudart.so
and its header file name is cuda_runtime.h
. The documentation for CUDA Runtime API could be found here.
1 | $ find / -name cuda_runtime.h |
1 | $ find / -name libcudart.* |
From the library filenames, we could see that the NVIDIA Runtime library version is 10.1.243
.
Differences Between CUDA Driver Library and CUDA Runtime Library
NVIDIA CUDA documentation has a specific chapter talking about the difference between CUDA Driver API and Runtime API. While the CUDA Driver API and Runtime API do share functionalities in common, in most of the scenarios, using CUDA Runtime API is sufficient to solve the problem and the code is much simpler.
Personally, I have never written any single line of CUDA code using the CUDA Driver API. All the CUDA code I have read and written were using CUDA Runtime API.
Using CUDA Runtime API
To use CUDA Runtime API, we just have to include the header the CUDA Runtime library header cuda_runtime.h
and link the program against libcudart.so
.
There is another header cuda_runtime_api.h
which is sometimes confused with the cuda_runtime.h
. The cuda_runtime_api.h
is just a subset of the cuda_runtime.h
. The cuda_runtime_api.h
is a pure C header, whereas the cuda_runtime.h
is a C++ header. The cuda_runtime_api.h
has host function and type declarations only.
1 | $ find / -name cuda_runtime_api.h |
Whichever CUDA Runtime header file we use, we always link the program against libcudart.so
.
CUDA Driver VS CUDA Runtime