Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between cuda.h, cuda_runtime.h, cuda_runtime_api.h

I'm starting to program with CUDA, and in some examples I find the include files cuda.h, cuda_runtime.h and cuda_runtime_api.h included in the code. Can someone explain to me the difference between these files?

like image 905
Renan Avatar asked Jun 10 '11 06:06

Renan


People also ask

What is Cuda_runtime H?

The C++ API (cuda_runtime. h) is a C++-style interface built on top of the C API. It wraps some of the C API routines, using overloading, references and default arguments. These wrappers can be used from C++ code and can be compiled with any C++ compiler.

What is CUDA runtime?

The CUDA runtime makes it possible to compile and link your CUDA kernels into executables. This means that you don't have to distribute cubin files with your application, or deal with loading them through the driver API. As you have noted, it is generally easier to use.


2 Answers

In very broad terms:

  • cuda.h defines the public host functions and types for the CUDA driver API.
  • cuda_runtime_api.h defines the public host functions and types for the CUDA runtime API
  • cuda_runtime.h defines everything cuda_runtime_api.h does, as well as built-in type definitions and function overlays for the CUDA language extensions and device intrinsic functions.

If you were writing host code to be compiled with the host compiler which includes API calls, you would include either cuda.h or cuda_runtime_api.h. If you needed other CUDA language built-ins, like types, and were using the runtime API and compiling with the host compiler, you would include cuda_runtime.h. If you are writing code which will be compiled using nvcc, it is all irrelevant, because nvcc takes care of inclusion of all the required headers automatically without programmer intervention.

like image 141
talonmies Avatar answered Sep 28 '22 02:09

talonmies


A few observations in addition to @talonmies answer:

  • cuda_runtime.h includes cuda_runtime_api.h internally, but not the other way around. So: "runtime includes all of runtime_api" is a mnemonic to remember.
  • cuda_runtime_api.h does not have the entire runtime API functions you'll find in the official documentation, while cuda_runtime.h will have it all (example: cudaEventCreate()). However, all API calls defined cuda_runtime.h are actually implemented, in the header file itself, using calls to functions in cuda_runtime_api.h. These are the "function overlays" that @talonmies mentioned.
  • cuda_runtime_api.h is a C-language header (IIANM) with only C-language function declarations; cuda_runtime.h is a C++ header file, with some templated functions implemented.
like image 29
einpoklum Avatar answered Sep 28 '22 03:09

einpoklum