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
2
3
4
5
6
7
$ find / -name cuda.h
/usr/include/cuda.h
/usr/include/linux/cuda.h
/usr/src/linux-headers-5.4.0-47/include/linux/cuda.h
/usr/src/linux-headers-5.4.0-47/include/uapi/linux/cuda.h
/usr/src/linux-headers-5.4.0-48/include/linux/cuda.h
/usr/src/linux-headers-5.4.0-48/include/uapi/linux/cuda.h
1
2
3
4
5
6
7
8
$ find / -name libcuda.*
/usr/lib/i386-linux-gnu/libcuda.so.1
/usr/lib/i386-linux-gnu/libcuda.so.450.66
/usr/lib/i386-linux-gnu/libcuda.so
/usr/lib/x86_64-linux-gnu/libcuda.so.1
/usr/lib/x86_64-linux-gnu/stubs/libcuda.so
/usr/lib/x86_64-linux-gnu/libcuda.so.450.66
/usr/lib/x86_64-linux-gnu/libcuda.so

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
2
$ find / -name cuda_runtime.h
/usr/include/cuda_runtime.h
1
2
3
4
$ find / -name libcudart.*
/usr/lib/x86_64-linux-gnu/libcudart.so.10.1
/usr/lib/x86_64-linux-gnu/libcudart.so
/usr/lib/x86_64-linux-gnu/libcudart.so.10.1.243

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
2
$ find / -name cuda_runtime_api.h
/usr/include/cuda_runtime_api.h

Whichever CUDA Runtime header file we use, we always link the program against libcudart.so.

Author

Lei Mao

Posted on

10-01-2020

Updated on

10-30-2020

Licensed under


Comments