If there exists no CUDA Driver API CUcontext bound to the current thread at the time of a CUDA Runtime API call which requires a CUcontext then the CUDA Runtime will implicitly create a new CUcontext before executing the call.
If the CUDA Runtime creates a CUcontext then the CUcontext will be created using the parameters specified by the CUDA Runtime API functions cudaSetDevice, cudaSetValidDevices, cudaSetDeviceFlags, cudaGLSetGLDevice, cudaD3D9SetDirect3DDevice, cudaD3D10SetDirect3DDevice, and cudaD3D11SetDirect3DDevice. Note that these functions will fail with cudaErrorSetOnActiveProcess if they are called when a CUcontext is bound to the current host thread.
If a CUcontext is created by the CUDA Runtime, then the CUDA runtime will decrement the reference count of that CUcontext in the function cudaThreadExit. If a CUcontext is created by the CUDA Driver API (or is created by a separate instance of the CUDA Runtime API library), then the CUDA Runtime will not increment or decrement the reference count of that CUcontext.
All CUDA Runtime API state (e.g, global variables' addresses and values) travels with its underlying CUcontext. In particular, if a CUcontext is moved from one thread to another (using cuCtxPopCurrent and cuCtxPushCurrent) then all CUDA Runtime API state will move to that thread as well.
Please note that attaching to legacy contexts (those with a version of 3010 as returned by cuCtxGetApiVersion()) is not possible. The CUDA Runtime will return cudaErrorIncompatibleDriverContext in such cases.CUstream and cudaStream_t are identical and may be used interchangeably.CUevent and cudaEvent_t are identical and may be used interchangeably.CUarray and struct cudaArray * represent the same data type and may be used interchangeably by casting the two types between each other.CUgraphicsResource and struct cudaGraphicsResource * represent the same data type and may be used interchangeably by casting the two types between each other.
In order to use a CUgraphicsResource in a CUDA Runtime API function which takes a struct cudaGraphicsResource *, it is necessary to explicitly cast the CUgraphicsResource to a struct cudaGraphicsResource *.
In order to use a struct cudaGraphicsResource * in a CUDA Driver API function which takes a CUgraphicsResource, it is necessary to explicitly cast the struct cudaGraphicsResource * to a CUgraphicsResource .