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开发者_JAVA百科 the difference between these files?
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 APIcuda_runtime.h
defines everythingcuda_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.
A few observations in addition to @talonmies answer:
cuda_runtime.h
includescuda_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, whilecuda_runtime.h
will have it all (example:cudaEventCreate()
). However, all API calls definedcuda_runtime.h
are actually implemented, in the header file itself, using calls to functions incuda_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.
精彩评论