runtime_v2#
See also
See the migration guide for the differences between this module and the legacy runtime module.
Data types used by CUDA Runtime#
|
Empty-initialize an instance of cudaChannelFormatDesc. |
|
Empty-initialize an instance of cudaArraySparseProperties. |
|
Empty-initialize an instance of cudaArrayMemoryRequirements. |
|
Empty-initialize an array of cudaPitchedPtr. |
|
Empty-initialize an instance of cudaExtent. |
|
Empty-initialize an instance of cudaPos. |
|
Empty-initialize an instance of cudaMemcpy3DParms. |
|
Empty-initialize an instance of cudaMemcpyNodeParams. |
|
Empty-initialize an instance of cudaMemcpy3DPeerParms. |
|
Empty-initialize an instance of cudaMemsetParams. |
|
Empty-initialize an instance of cudaMemsetParamsV2. |
|
Empty-initialize an instance of cudaAccessPolicyWindow. |
|
Empty-initialize an instance of cudaHostNodeParams. |
|
Empty-initialize an instance of cudaHostNodeParamsV2. |
|
Empty-initialize an instance of cudaResourceDesc. |
|
Empty-initialize an instance of cudaResourceViewDesc. |
|
Empty-initialize an instance of cudaPointerAttributes. |
|
Empty-initialize an instance of cudaFuncAttributes. |
|
Empty-initialize an array of cudaMemLocation. |
|
Empty-initialize an array of cudaMemAccessDesc. |
|
Empty-initialize an instance of cudaMemPoolProps. |
|
Empty-initialize an instance of cudaMemPoolPtrExportData. |
|
Empty-initialize an instance of cudaMemAllocNodeParams. |
|
Empty-initialize an instance of cudaMemAllocNodeParamsV2. |
|
Empty-initialize an instance of cudaMemFreeNodeParams. |
|
Empty-initialize an array of cudaMemcpyAttributes. |
|
Empty-initialize an instance of cudaOffset3D. |
|
Empty-initialize an instance of cudaMemcpy3DOperand. |
|
Empty-initialize an array of cudaMemcpy3DBatchOp. |
|
Empty-initialize an instance of cudaMemcpyBatchNodeParams. |
|
Empty-initialize an instance of cudaUUID_t. |
|
Empty-initialize an instance of cudaDeviceProp. |
|
Empty-initialize an instance of cudaIpcEventHandle_t. |
|
Empty-initialize an instance of cudaIpcMemHandle_t. |
|
Empty-initialize an instance of cudaMemFabricHandle_t. |
|
Empty-initialize an instance of cudaExternalMemoryHandleDesc. |
|
Empty-initialize an instance of cudaExternalMemoryBufferDesc. |
|
Empty-initialize an instance of cudaExternalMemoryMipmappedArrayDesc. |
|
Empty-initialize an instance of cudaExternalSemaphoreHandleDesc. |
|
Empty-initialize an array of cudaExternalSemaphoreSignalParams. |
|
Empty-initialize an array of cudaExternalSemaphoreWaitParams. |
|
Empty-initialize an instance of cudaDevSmResource. |
|
Empty-initialize an instance of cudaDevWorkqueueConfigResource. |
|
Empty-initialize an instance of cudaDevWorkqueueResource. |
|
Empty-initialize an array of cudaDevSmResourceGroupParams. |
|
Empty-initialize an array of cudaDevResource. |
|
Empty-initialize an instance of cudalibraryHostUniversalFunctionAndDataTable. |
|
Empty-initialize an instance of cudaKernelNodeParams. |
|
Empty-initialize an instance of cudaKernelNodeParamsV2. |
|
Empty-initialize an instance of cudaExternalSemaphoreSignalNodeParams. |
|
Empty-initialize an instance of cudaExternalSemaphoreSignalNodeParamsV2. |
|
Empty-initialize an instance of cudaExternalSemaphoreWaitNodeParams. |
|
Empty-initialize an instance of cudaExternalSemaphoreWaitNodeParamsV2. |
|
Empty-initialize an instance of cudaConditionalNodeParams. |
|
Empty-initialize an instance of cudaChildGraphNodeParams. |
|
Empty-initialize an instance of cudaEventRecordNodeParams. |
|
Empty-initialize an instance of cudaEventWaitNodeParams. |
|
Empty-initialize an instance of cudaGraphNodeParams. |
|
Empty-initialize an array of cudaGraphEdgeData. |
|
Empty-initialize an instance of cudaGraphInstantiateParams. |
|
Empty-initialize an instance of cudaGraphExecUpdateResultInfo. |
|
Empty-initialize an instance of cudaGraphKernelNodeUpdate. |
|
Empty-initialize an instance of cudaLaunchMemSyncDomainMap. |
|
Empty-initialize an instance of cudaLaunchAttributeValue. |
|
Empty-initialize an instance of cudaLaunchAttribute. |
|
Empty-initialize an instance of cudaAsyncNotificationInfo_t. |
|
Empty-initialize an instance of cudaTextureDesc. |
|
Empty-initialize an array of cudaEglPlaneDesc. |
|
Empty-initialize an instance of cudaEglFrame. |
|
CUDA error types |
|
Channel format kind |
|
CUDA memory types |
|
CUDA memory copy types |
|
Specifies performance hint with cudaAccessPolicyWindow for hitProp and missProp members. |
|
Possible stream capture statuses returned by cudaStreamIsCapturing |
|
Possible recapture statuses that can be returned to the user callback |
|
Possible modes for stream capture thread interactions. |
|
See cudaSynchronizationPolicy. |
|
Cluster scheduling policies. |
|
Flags for cudaStreamUpdateCaptureDependencies |
|
Flags for user objects for graphs |
|
Flags for retaining user object references for graphs |
|
Flags for host task sync mode |
|
CUDA graphics interop register flags |
|
CUDA graphics interop map flags |
|
CUDA graphics interop array indices for cube maps |
|
CUDA resource types |
|
CUDA texture resource view formats |
|
Shared memory related attributes for use with cuLaunchKernelEx |
|
CUDA function attributes that can be set using cudaFuncSetAttribute |
|
CUDA function cache configurations |
|
CUDA shared memory configuration [Deprecated] |
|
Shared memory carveout configurations. |
|
CUDA device compute modes |
|
CUDA Limits |
|
CUDA Memory Advise values |
|
CUDA range attributes |
|
CUDA GPUDirect RDMA flush writes APIs supported on the device |
|
CUDA GPUDirect RDMA flush writes ordering features of the device |
|
CUDA GPUDirect RDMA flush writes scopes |
|
CUDA GPUDirect RDMA flush writes targets |
|
CUDA device attributes |
|
CUDA memory pool attributes |
|
Specifies the type of location |
|
Specifies the memory protection flags for mapping. |
|
Defines the allocation types available |
|
Flags for specifying particular handle types |
|
Graph memory attributes |
|
Flags to specify for copies within a batch. |
|
See cudaMemcpySrcAccessOrder. |
|
These flags allow applications to convey the operand type for individual copies specified in cudaMemcpy3DBatchAsync. |
|
CUDA device P2P attributes |
|
CUDA-valid Atomic Operations |
|
CUDA-valid Atomic Operation capabilities |
|
External memory handle types |
|
External semaphore handle types |
|
Flags for a CUdevSmResource group |
|
See cudaDevSmResourceSplitByCount_flags. |
|
Type of resource |
|
Sharing scope for workqueues |
|
Online compiler and linker options |
|
Library options to be specified with cudaLibraryLoadData() or cudaLibraryLoadFromFile() |
|
Caching modes for dlcm |
|
Cubin matching fallback strategies |
|
CUDA cooperative group scope |
|
CUDA Kernel Function Handle Type |
|
See cudaGraphConditionalHandleFlags. |
|
CUDA conditional node types |
|
CUDA Graph node types |
|
Child graph node ownership |
|
Type annotations that can be applied to graph edges as part of cudaGraphEdgeData. |
|
CUDA Graph Update error types |
|
Graph instantiation results |
|
Specifies the field to update when performing multiple node updates from the device |
|
Flags to specify search options to be used with cudaGetDriverEntryPoint For more details see cuGetProcAddress |
|
Enum for status from obtaining driver entry points, used with cudaApiGetDriverEntryPoint |
|
CUDA Graph debug write options |
|
Flags for instantiating a graph |
|
Memory Synchronization Domain A kernel can be launched in a specified memory synchronization domain that affects all memory operations issued by that kernel. |
|
Enum for defining applicability of portable cluster size, used with cudaLaunchKernelEx |
|
Launch attributes enum; used as id field of cudaLaunchAttribute |
|
CUDA device NUMA config |
|
Types of async notification that can occur |
|
See cudaLogLevel. |
|
Fabric operation status source |
|
Fabric operation status info |
|
CUDA Surface boundary modes |
|
CUDA Surface format modes |
|
CUDA texture address modes |
|
CUDA texture filter modes |
|
CUDA texture read modes |
|
CUDA EglFrame type - array or pointer |
|
Resource location flags- sysmem or vidmem For CUDA context on iGPU, since video and system memory are equivalent - these flags will not have an effect on the execution. |
|
CUDA EGL Color Format - The different planar and multiplanar formats currently supported for CUDA_EGL interops. |
|
Flags for malloc_array, malloc_3d_array and malloc_mipmapped_array (cudaArray*). |
|
Flags in ArraySparseProperties.flags_ (cudaArraySparseProperties*). |
|
See cudaDataType. |
|
Flags for set_device_flags and init_device (cudaDevice*). |
|
Empty-initialize an instance of dim3. |
|
Enum to configure the mantissa related parameters for floating-point emulation algorithms |
|
Enum to configure how special floating-point values will be handled by emulation algorithms |
|
Enum for specifying how to leverage floating-point emulation algorithms |
|
Flags for event_create_with_flags (cudaEvent*). |
|
Flags for event_record_with_flags (cudaEventRecord*). |
|
Flags for stream_wait_event (cudaEventWait*). |
|
Flags for ExternalMemoryHandleDesc.flags_ (cudaExternalMemory*). |
|
Flags for ExternalSemaphoreSignalParams.flags_ (cudaExternalSemaphoreSignal*). |
|
Flags for ExternalSemaphoreWaitParams.flags_ (cudaExternalSemaphoreWait*). |
|
CUDA devices corresponding to the current OpenGL context |
|
CUDA GL Map Flags |
|
Outgoing ports of a kernel node, for GraphEdgeData.from_port (cudaGraphKernelNodePort*). |
|
Empty-initialize an instance of cudaGraphRecaptureCallbackData. |
|
Flags for host_alloc (cudaHostAlloc*). |
|
Flags for host_register (cudaHostRegister*). |
|
Flags for init_device (cudaInitDevice*). |
|
Flags for ipc_open_mem_handle (cudaIpcMem*). |
|
alias of |
|
alias of |
|
Flags for malloc_managed and stream_attach_mem_async (cudaMemAttach*). |
|
Usage hints for MemPoolProps.usage (cudaMemPoolCreateUsage*). |
|
NvSciSync attribute directions (cudaNvSciSyncAttr*). |
|
Flags for occupancy_max_active_blocks_per_multiprocessor_with_flags (cudaOccupancy*). |
|
Flags for device_enable_peer_access (cudaPeerAccess*). |
|
See cudaRoundMode. |
|
Special int device ordinals (cuda*DeviceId). |
|
Special streams, passed as a stream handle (cudaStream*). |
|
alias of |
|
alias of |
|
Flags for stream_create_with_flags (cudaStream*). |
|
Surface types, for ResourceDesc surfaces (cudaSurfaceType*). |
|
Texture types (cudaTextureType*). |
Device Management#
This section describes the device management functions of the CUDA runtime application programming interface.
|
Destroy all allocations and reset all state on the current device in the current process. |
|
Wait for compute device to finish. |
|
Set resource limits. |
|
Return resource limits. |
|
Returns the maximum number of elements allocatable in a 1D linear texture for a given element size. |
|
Returns the preferred cache configuration for the current device. |
|
Returns numerical values that correspond to the least and greatest stream priorities. |
|
Sets the preferred cache configuration for the current device. |
|
Returns a handle to a compute device. |
|
Returns a PCI Bus Id string for the device. |
|
Gets an interprocess handle for a previously allocated event. |
|
Opens an interprocess event handle for use in the current process. |
|
Gets an interprocess memory handle for an existing device memory allocation. |
|
Opens an interprocess memory handle exported from another process and returns a device pointer usable in the local process. |
|
Attempts to close memory mapped with cudaIpcOpenMemHandle. |
|
Blocks until remote writes are visible to the specified scope. |
|
Registers a callback function to receive async notifications. |
|
Unregisters an async notification callback. |
|
Returns the number of compute-capable devices. |
|
Returns information about the compute-device. |
|
Returns information about the device. |
|
Query atomic operation capabilities between host and device. |
|
Returns the default mempool of a device. |
|
Sets the current memory pool of a device. |
|
Gets the current mempool for a device. |
|
Fill in NvSciSync attributes for the given CUDA device. |
|
Queries attributes of the link between two devices. |
|
Query atomic operation capabilities between two devices. |
|
Select compute-device which best matches criteria. |
|
Initialize device to be used for GPU executions. |
|
Set device to be used for GPU executions. |
|
Returns which device is currently being used. |
|
Sets flags to be used for device executions. |
|
Gets the flags for the current device. |
Error Handling#
This section describes the error handling functions of the CUDA runtime application programming interface.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Returns the last error from a runtime call. |
|
Returns the last error from a runtime call. |
|
Returns the string representation of an error code enum name. |
|
Returns the description string for an error code. |
Stream Management#
This section describes the stream management functions of the CUDA runtime application programming interface.
|
Create an asynchronous stream. |
|
Create an asynchronous stream. |
|
Create an asynchronous stream with the specified priority. |
|
Query the priority of a stream. |
|
Query the flags of a stream. |
|
Query the Id of a stream. |
|
Query the device of a stream. |
|
Resets all persisting lines in cache to normal status. |
|
Copies attributes from source stream to destination stream. |
|
Queries stream attribute. |
|
Sets stream attribute. |
|
Destroys and cleans up an asynchronous stream. |
|
Make a compute stream wait on an event. |
|
Add a callback to a compute stream. |
|
Waits for stream tasks to complete. |
|
Queries an asynchronous stream for completion status. |
|
Queries an asynchronous stream for completion status. |
|
Attach memory to a stream asynchronously. |
|
Begins graph capture on a stream. |
|
Begin graph capture on a stream to an existing graph. |
|
Begins graph capture on a stream to an existing graph. |
|
Swap the stream capture interaction mode of the calling thread. |
|
Ends capture on a stream, returning the captured graph. |
|
Returns a stream's capture status. |
|
Query a stream's capture state. |
|
Update the set of dependencies in a capturing stream. |
Event Management#
This section describes the event management functions of the CUDA runtime application programming interface.
|
Creates an event object. |
|
Creates an event object with the specified flags. |
|
Records an event. |
|
Records an event. |
|
Queries an event's status. |
|
Queries an event's status. |
|
Waits for an event to complete. |
|
Destroys an event object. |
|
Computes the elapsed time between events. |
External Resource Interoperability#
This section describes the external resource interoperability functions of the CUDA runtime application programming interface.
|
Imports an external memory object. |
|
Maps a buffer onto an imported memory object. |
|
Maps a CUDA mipmapped array onto an external memory object. |
|
Destroys an external memory object. |
|
Imports an external semaphore. |
|
Signals a set of external semaphore objects. |
|
Waits on a set of external semaphore objects. |
|
Destroys an external semaphore. |
Execution Control#
This section describes the execution control functions of the CUDA runtime application programming interface.
Some functions have overloaded C++ API template versions documented separately in the C++ API Routines module.
|
Sets the preferred cache configuration for a device function. |
|
Find out attributes for a given function. |
|
Set attributes for a given function. |
|
Returns the number of parameters used by the function. |
|
Enqueues a host function call in a stream. |
|
Enqueues a host function call in a stream. |
|
Returns the function name for a device entry function pointer. |
|
Returns the offset and size of a kernel parameter in the device-side parameter layout. |
Occupancy#
This section describes the occupancy calculation functions of the CUDA runtime application programming interface.
Besides the occupancy calculator functions (cudaOccupancyMaxActiveBlocksPerMultiprocessor and cudaOccupancyMaxActiveBlocksPerMultiprocessorWithFlags), there are also C++ only occupancy-based launch configuration functions documented in C++ API Routines module.
See cudaOccupancyMaxPotentialBlockSize (C++ API), cudaOccupancyMaxPotentialBlockSize (C++ API), cudaOccupancyMaxPotentialBlockSizeVariableSMem (C++ API), cudaOccupancyMaxPotentialBlockSizeVariableSMem (C++ API) cudaOccupancyAvailableDynamicSMemPerBlock (C++ API),
|
Returns occupancy for a device function. |
|
Returns dynamic shared memory available per block when launching |
|
Returns occupancy for a device function with the specified flags. |
Memory Management#
This section describes the memory management functions of the CUDA runtime application programming interface.
Some functions have overloaded C++ API template versions documented separately in the C++ API Routines module.
|
Allocates memory that will be automatically managed by the Unified Memory system. |
|
Allocate memory on the device. |
|
Allocates page-locked memory on the host. |
|
Allocates pitched memory on the device. |
|
Allocate an array on the device. |
|
Frees memory on the device. |
|
Frees page-locked memory. |
|
Frees an array on the device. |
|
Frees a mipmapped array on the device. |
|
Allocates page-locked memory on the host. |
|
Registers an existing host memory range for use by CUDA. |
|
Unregisters a memory range that was registered with cudaHostRegister. |
|
Passes back device pointer of mapped host memory allocated by cudaHostAlloc or registered by cudaHostRegister. |
|
Passes back flags used to allocate pinned host memory allocated by cudaHostAlloc. |
|
Allocates logical 1D, 2D, or 3D memory objects on the device. |
|
Allocate an array on the device. |
|
Allocate a mipmapped array on the device. |
|
Gets a mipmap level of a CUDA mipmapped array. |
|
Copies data between 3D objects. |
|
Copies memory between devices. |
|
Copies data between 3D objects. |
|
Copies memory between devices asynchronously. |
|
Gets free and total device memory. |
|
Gets info about the specified cudaArray. |
|
Gets a CUDA array plane from a CUDA array. |
|
Returns the memory requirements of a CUDA array. |
|
Returns the memory requirements of a CUDA mipmapped array. |
|
Returns the layout properties of a sparse CUDA array. |
|
Returns the layout properties of a sparse CUDA mipmapped array. |
|
Copies data between host and device. |
|
Copies memory between two devices. |
|
Copies data between host and device. |
|
Copies data between host and device. |
|
Copies data between host and device. |
|
Copies data between host and device. |
|
Copies data between host and device. |
|
Copies memory between two devices asynchronously. |
|
Perform a batch of memory copies asynchronously. |
|
Performs a batch of 3D memory copies asynchronously. |
|
Performs asynchronous memory copy operation with the specified attributes. |
|
Performs 3D asynchronous memory copy with the specified attributes. |
|
Copies data between host and device. |
|
Copies data between host and device. |
|
Copies data between host and device. |
|
Initializes or sets device memory to a value. |
|
Initializes or sets device memory to a value. |
|
Initializes or sets device memory to a value. |
|
Initializes or sets device memory to a value. |
|
Initializes or sets device memory to a value. |
|
Initializes or sets device memory to a value. |
|
Prefetches memory to the specified destination location. |
|
Performs a batch of memory prefetches asynchronously. |
|
Performs a batch of memory discards asynchronously. |
|
Performs a batch of memory discards and prefetches asynchronously. |
|
Gets location information for a memory address range. |
|
Advise about the usage of a given memory range. |
|
Return an attribute of a memory range. |
|
Return several attributes of a memory range, in one call. |
|
Return a |
|
Return a |
|
Return an |
Stream Ordered Memory Allocator#
overview
The asynchronous allocator allows the user to allocate and free in stream order. All asynchronous accesses of the allocation must happen between the stream executions of the allocation and the free. If the memory is accessed outside of the promised stream order, a use before allocation / use after free error will cause undefined behavior.
The allocator is free to reallocate the memory as long as it can guarantee that compliant memory accesses will not overlap temporally. The allocator may refer to internal stream ordering as well as inter-stream dependencies (such as CUDA events and null stream dependencies) when establishing the temporal guarantee. The allocator may also insert inter-stream dependencies to establish the temporal guarantee.
Supported Platforms
Whether or not a device supports the integrated stream ordered memory allocator may be queried by calling cudaDeviceGetAttribute() with the device attribute cudaDevAttrMemoryPoolsSupported.
|
Allocates memory with stream ordered semantics. |
|
Frees memory with stream ordered semantics. |
|
Tries to release memory back to the OS. |
|
Set an attribute of a memory pool. |
|
Return an attribute of a memory pool (an |
|
Controls visibility of pools between devices. |
|
Returns the accessibility of a pool from a device. |
|
Creates a memory pool. |
|
Destroys the specified memory pool. |
|
Returns the default memory pool for a given location and allocation type. |
|
Gets the current memory pool for a given memory location and allocation type. |
|
Sets the current memory pool for a memory location and allocation type. |
|
Allocates memory from a specified pool with stream ordered semantics. |
|
Export a memory pool to an OS-specific shareable handle. |
|
imports a memory pool from a shared handle. |
|
Export data to share a memory pool allocation between processes. |
|
Import a memory pool allocation from another process. |
Unified Addressing#
This section describes the unified addressing functions of the CUDA runtime application programming interface.
Overview
CUDA devices can share a unified address space with the host.
For these devices there is no distinction between a device pointer and a host pointer – the same pointer value may be used to access memory from the host program and from a kernel running on the device (with exceptions enumerated below).
Supported Platforms
Whether or not a device supports unified addressing may be queried by calling cudaGetDeviceProperties() with the device property cudaDeviceProp::unifiedAddressing.
Unified addressing is automatically enabled in 64-bit processes .
Looking Up Information from Pointer Values
It is possible to look up information about the memory which backs a pointer value. For instance, one may want to know if a pointer points to host or device memory. As another example, in the case of device memory, one may want to know on which CUDA device the memory resides. These properties may be queried using the function cudaPointerGetAttributes()
Since pointers are unique, it is not necessary to specify information about the pointers specified to cudaMemcpy() and other copy functions.
The copy direction cudaMemcpyDefault may be used to specify that the CUDA runtime should infer the location of the pointer from its value.
Automatic Mapping of Host Allocated Host Memory
All host memory allocated through all devices using cudaMallocHost() and cudaHostAlloc() is always directly accessible from all devices that support unified addressing. This is the case regardless of whether or not the flags cudaHostAllocPortable and cudaHostAllocMapped are specified.
The pointer value through which allocated host memory may be accessed in kernels on all devices that support unified addressing is the same as the pointer value through which that memory is accessed on the host. It is not necessary to call cudaHostGetDevicePointer() to get the device pointer for these allocations.
Note that this is not the case for memory allocated using the flag cudaHostAllocWriteCombined, as discussed below.
Direct Access of Peer Memory
Upon enabling direct access from a device that supports unified addressing to another peer device that supports unified addressing using cudaDeviceEnablePeerAccess() all memory allocated in the peer device using cudaMalloc() and cudaMallocPitch() will immediately be accessible by the current device. The device pointer value through which any peer’s memory may be accessed in the current device is the same pointer value through which that memory may be accessed from the peer device.
Exceptions, Disjoint Addressing
Not all memory may be accessed on devices through the same pointer value through which they are accessed on the host. These exceptions are host memory registered using cudaHostRegister() and host memory allocated using the flag cudaHostAllocWriteCombined. For these exceptions, there exists a distinct host and device address for the memory. The device address is guaranteed to not overlap any valid host pointer range and is guaranteed to have the same value across all devices that support unified addressing.
This device address may be queried using cudaHostGetDevicePointer() when a device using unified addressing is current. Either the host or the unified device pointer value may be used to refer to this memory in cudaMemcpy() and similar functions using the cudaMemcpyDefault memory direction.
|
Returns attributes about a specified pointer. |
Peer Device Memory Access#
This section describes the peer device memory access functions of the CUDA runtime application programming interface.
|
Queries if a device may directly access a peer device's memory. |
|
Enables direct access to memory allocations on a peer device. |
|
Disables direct access to memory allocations on a peer device. |
OpenGL Interoperability#
This section describes the OpenGL interoperability functions of the CUDA runtime application programming interface. Note that mapping of OpenGL resources is performed with the graphics API agnostic, resource mapping interface described in Graphics Interopability.
- cudaGLDeviceList.cudaGLDeviceListAll = <cudaGLDeviceList.cudaGLDeviceListAll: 1>#
The CUDA devices for all GPUs used by the current OpenGL context
- cudaGLDeviceList.cudaGLDeviceListCurrentFrame = <cudaGLDeviceList.cudaGLDeviceListCurrentFrame: 2>#
The CUDA devices for the GPUs used by the current OpenGL context in its currently rendering frame
- cudaGLDeviceList.cudaGLDeviceListNextFrame = <cudaGLDeviceList.cudaGLDeviceListNextFrame: 3>#
The CUDA devices for the GPUs to be used by the current OpenGL context in the next frame
|
Gets the CUDA devices associated with the current OpenGL context. |
|
Register an OpenGL texture or renderbuffer object. |
|
Registers an OpenGL buffer object. |
VDPAU Interoperability#
This section describes the VDPAU interoperability functions of the CUDA runtime application programming interface.
|
Gets the CUDA device associated with a |
|
Sets a CUDA device to use VDPAU interoperability. |
|
Register a |
|
Register a |
EGL Interoperability#
This section describes the EGL interoperability functions of the CUDA runtime application programming interface.
|
Registers an EGL image. |
|
Connect CUDA to EGLStream as a consumer. |
|
Connect CUDA to EGLStream as a consumer with given flags. |
|
Disconnect CUDA as a consumer to EGLStream . |
|
Acquire an image frame from the EGLStream with CUDA as a consumer. |
|
Releases the last frame acquired from the EGLStream. |
|
Connect CUDA to EGLStream as a producer. |
|
Disconnect CUDA as a producer to EGLStream . |
|
Present a CUDA eglFrame to the EGLStream with CUDA as a producer. |
|
Return the CUDA eglFrame to the EGLStream last released by the consumer. |
|
Get an egl_frame through which to access a registered EGL graphics resource. |
|
Creates an event from EGLSync object. |
Graphics Interoperability#
This section describes the graphics interoperability functions of the CUDA runtime application programming interface.
|
Unregisters a graphics resource for access by CUDA. |
|
Set usage flags for mapping a graphics resource. |
|
Map graphics resources for access by CUDA. |
|
Unmap graphics resources. |
|
Get an device pointer through which to access a mapped graphics resource. |
|
Get an array through which to access a subresource of a mapped graphics resource. |
|
Get a mipmapped array through which to access a mapped graphics resource. |
Texture Object Management#
This section describes the low level texture object management functions of the CUDA runtime application programming interface. The texture object API is only supported on devices of compute capability 3.0 or higher.
|
Get the channel descriptor of an array. |
|
Return a channel format descriptor. |
|
Creates a texture object. |
|
Destroys a texture object. |
|
Returns a texture object's resource descriptor. |
|
Returns a texture object's texture descriptor. |
|
Returns a texture object's resource view descriptor. |
Surface Object Management#
This section describes the low level texture object management functions of the CUDA runtime application programming interface. The surface object API is only supported on devices of compute capability 3.0 or higher.
|
Creates a surface object. |
|
Destroys a surface object. |
|
Returns a surface object's resource descriptor Returns the resource descriptor for the surface object specified by |
Version Management#
|
Returns the latest version of CUDA supported by the driver. |
|
Returns the CUDA Runtime version. |
|
Return the version of the CUDA runtime this module was loaded against. |
Error Log Management Functions#
This section describes the error log management functions of the CUDA runtime application programming interface. The Error Log Management interface will operate on both the CUDA Driver and CUDA Runtime.
|
Register a callback function to receive error log messages. |
|
Unregister a log message callback. |
|
Sets log iterator to point to the end of log buffer, where the next message would be written. |
|
Dump the runtime's error log buffer to a file. |
|
Dump accumulated driver logs into a buffer. |
Graph Management#
This section describes the graph management functions of CUDA runtime application programming interface.
|
Creates a graph. |
|
Creates a kernel execution node and adds it to a graph. |
|
Returns a kernel node's parameters. |
|
Sets a kernel node's parameters. |
|
Copies attributes from source node to destination node. |
|
Queries node attribute. |
|
Sets node attribute. |
|
Creates a memcpy node and adds it to a graph. |
|
Creates a 1D memcpy node and adds it to a graph. |
|
Returns a memcpy node's parameters. |
|
Sets a memcpy node's parameters. |
|
Sets a memcpy node's parameters to perform a 1-dimensional copy. |
|
Creates a memset node and adds it to a graph. |
|
Returns a memset node's parameters. |
|
Sets a memset node's parameters. |
|
Creates a host execution node and adds it to a graph. |
|
Returns a host node's parameters. |
|
Sets a host node's parameters. |
|
Creates a child graph node and adds it to a graph. |
|
Gets a handle to the embedded graph of a child graph node. |
|
Creates an empty node and adds it to a graph. |
|
Creates an event record node and adds it to a graph. |
|
Returns the event associated with an event record node. |
|
Sets an event record node's event. |
|
Creates an event wait node and adds it to a graph. |
|
Returns the event associated with an event wait node. |
|
Sets an event wait node's event. |
|
Creates an external semaphore signal node and adds it to a graph. |
|
Returns an external semaphore signal node's parameters. |
|
Sets an external semaphore signal node's parameters. |
|
Creates an external semaphore wait node and adds it to a graph. |
|
Returns an external semaphore wait node's parameters. |
|
Sets an external semaphore wait node's parameters. |
|
Creates an allocation node and adds it to a graph. |
|
Returns a memory alloc node's parameters. |
|
Creates a memory free node and adds it to a graph. |
|
Return the device address freed by a memory free node. |
|
Free unused memory that was cached on the specified device for use with graphs back to the OS. |
|
Return a graph memory attribute of a device, in bytes. |
|
Set a graph memory attribute of a device. |
|
Clones a graph. |
|
Finds a cloned version of a node. |
|
Returns a node's type. |
|
Returns the graph that contains a given graph node. |
|
Returns the node id of a given graph node. |
|
Returns an id used by tools to identify a given node. |
|
Returns the id of a given graph. |
|
Returns the id of a given graph exec. |
|
Returns a graph's nodes. |
|
Returns a graph's root nodes. |
|
Returns a graph's dependency edges. |
|
Returns a node's dependencies. |
|
Returns a node's dependent nodes. |
|
Adds dependency edges to a graph. |
|
Removes dependency edges from a graph. |
|
Remove a node from the graph. |
|
Creates an executable graph from a graph. |
|
Creates an executable graph from a graph. |
|
Creates an executable graph from a graph. |
|
Query the instantiation flags of an executable graph. |
|
Sets the parameters for a kernel node in the given graphExec. |
|
Sets the parameters for a memcpy node in the given graphExec. |
|
Sets the parameters for a memcpy node in the given graphExec to perform a 1-dimensional copy. |
|
Sets the parameters for a memset node in the given graphExec. |
|
Sets the parameters for a host node in the given graphExec. |
|
Updates node parameters in the child graph node in the given graphExec. |
|
Sets the event for an event record node in the given graphExec. |
|
Sets the event for an event wait node in the given graphExec. |
|
Sets the parameters for an external semaphore signal node in the given graphExec. |
|
Sets the parameters for an external semaphore wait node in the given graphExec. |
|
Enables or disables the specified node in the given graphExec. |
|
Query whether a node in the given graphExec is enabled. |
|
Check whether an executable graph can be updated with a graph and perform the update if possible. |
|
Uploads an executable graph in a stream. |
|
Launches an executable graph in a stream. |
|
Destroys an executable graph. |
|
Destroys a graph. |
|
Write a DOT file describing graph structure. |
|
Create a user object. |
|
Retain a reference to a user object. |
|
Release a reference to a user object. |
|
Retain a reference to a user object from a graph. |
|
Release a user object reference from a graph. |
|
Adds a node of arbitrary type to a graph. |
|
Update a graph node's parameters. |
|
Returns a graph node's parameters. |
|
Update a graph node's parameters in an instantiated graph. |
|
Create a conditional handle. |
|
Create a conditional handle. |
Driver Entry Point Access#
This section describes the driver entry point access functions of CUDA runtime application programming interface.
|
Returns the requested driver API function pointer. |
|
Returns the requested driver API function pointer by CUDA version. |
|
Gets an internal export table. |
Library Management#
This section describes the library management functions of the CUDA runtime application programming interface.
|
Load a library with specified code and options. |
|
Load a library with specified file and options. |
|
Unloads a library. |
|
Returns a kernel handle. |
|
Returns a global device pointer. |
|
Returns a pointer to managed memory. |
|
Returns a pointer to a unified function. |
|
Returns the number of kernels within a library. |
|
Retrieve the kernel handles within a library. |
|
Sets information about a kernel. |
Execution Context Management#
This section describes the execution context management functions of the CUDA runtime application programming interface.
Overview
A CUDA execution context cudaExecutionContext_t serves as an abstraction for the contexts exposed by the CUDA Runtime, specifically green contexts and the primary context, and provides a unified programming model and API interface for contexts in the Runtime.
There are two primary ways today to obtain an execution context:
cudaDeviceGetExecutionCtx: Returns the execution context that corresponds to the primary context of the specified device.
cudaGreenCtxCreate: Creates a green context with the specified resources and returns an execution context.
Once you have an execution context at hand, you can perform context-level operations via the CUDA Runtime APIs. This includes:
Submitting work via streams created with cudaExecutionCtxStreamCreate.
Querying context via cudaExecutionCtxGetDevResource, cudaExecutionCtxGetDevice, etc.
Synchronizing and tracking context-level operations via cudaExecutionCtxSynchronize, cudaExecutionCtxRecordEvent, cudaExecutionCtxWaitEvent.
Performing context-level graph node operations via cudaGraphAddNode by specifying the context in
nodeParams. Note that individual node creation APIs, such as cudaGraphAddKernelNode, do not support specifying an execution context.
Note: The above APIs take in an explicit cudaExecutionContext_t handle and ignores the context that is current to the calling thread. This enables explicit context-based programming without relying on thread-local state. If no context is specified, the APIs return cudaErrorInvalidValue.
Note: Developers should treat cudaExecutionContext_t as an opaque handle and avoid assumptions about its underlying representation. The CUDA Runtime does not provide a way to convert this handle into driver-level contexts, such as ::CUcontext or ::CUgreenCtx.
Lifetime of CUDA Resources
The lifetime of CUDA resources (memory, streams, events, modules, etc) is not tied to the lifetime of the execution context. Their lifetime is tied to the device against which they were created. As such, usage of cudaDeviceReset() should be avoided to persist the lifetime of these resources.
APIs Operating on Current Context
The CUDA runtime does not provide a way to set an execution context as current. Since, the majority of the runtime APIs operate on the current context, we document below how the developer can work with these APIs.
APIs Operating on Device Resources
To work with these APIs (for example, cudaMalloc, cudaEventCreate, etc), developers are expected to call cudaSetDevice() prior to invoking them. Doing so does not impact functional correctness as these APIs operate on resources that are device-wide. If users have a context handle at hand, they can get the device handle from the context handle using cudaExecutionCtxGetDevice().
APIs Operating on Context Resources
These APIs (for example, cudaLaunchKernel, cudaMemcpyAsync, cudaMemsetAsync, etc) take in a stream and resources are inferred from the context bound to the stream at creation. See cudaExecutionCtxStreamCreate for more details. Developers are expected to use the stream-based APIs for context awareness and always pass an explicit stream handle to ensure context-awareness, and avoid reliance on the default NULL stream, which implicitly binds to the current context.
Green Contexts
Green contexts are a lightweight alternative to traditional contexts, that can be used to select a subset of device resources. This allows the developer to, for example, select SMs from distinct spatial partitions of the GPU and target them via CUDA stream operations, kernel launches, etc.
Here are the broad initial steps to follow to get started:
Start with an initial set of resources. For SM resources, they can be fetched via cudaDeviceGetDevResource. In case of workqueues, a new configuration can be used or an existing one queried via the cudaDeviceGetDevResource API.
Modify these resources by either partitioning them (in case of SMs) or changing the configuration (in case of workqueues). To partition SMs, we recommend cudaDevSmResourceSplit. Changing the workqueue configuration can be done directly in place.
Finalize the specification of resources by creating a descriptor via cudaDevResourceGenerateDesc.
Create a green context via cudaGreenCtxCreate. This provisions the resource, such as workqueues (until this step it was only a configuration specification).
Create a stream via cudaExecutionCtxStreamCreate, and use it throughout your application.
SMs
There are two possible partition operations - with cudaDevSmResourceSplitByCount the partitions created have to follow default SM count granularity requirements, so it will often be rounded up and aligned to a default value. On the other hand, cudaDevSmResourceSplit is explicit and allows for creation of non-equal groups. It will not round up automatically - instead it is the developer’s responsibility to query and set the correct values. These requirements can be queried with cudaDeviceGetDevResource to determine the alignment granularity (sm.smCoscheduledAlignment). A general guideline on the default values for each compute architecture:
On Compute Architecture 7.X, 8.X, and all Tegra SoC:
The smCount must be a multiple of 2.
The alignment (and default value of coscheduledSmCount) is 2.
On Compute Architecture 9.0+:
The smCount must be a multiple of 8, or coscheduledSmCount if provided.
The alignment (and default value of coscheduledSmCount) is 8. While the maximum value for coscheduled SM count is 32 on all Compute Architecture 9.0+, it’s recommended to follow cluster size requirements. The portable cluster size and the max cluster size should be used in order to benefit from this co-scheduling.
Workqueues
For cudaDevResourceTypeWorkqueueConfig, the resource specifies the expected maximum number of concurrent stream-ordered workloads via the wqConcurrencyLimit field. The sharingScope field determines how workqueue resources are shared:
cudaDevWorkqueueConfigScopeDeviceCtx:Use all shared workqueue resources across all contexts (default driver behavior).cudaDevWorkqueueConfigScopeGreenCtxBalanced:When possible, use non-overlapping workqueue resources with other balanced green contexts.
The maximum concurrency limit depends on ::CUDA_DEVICE_MAX_CONNECTIONS and can be queried from the device via cudaDeviceGetDevResource. Configurations may exceed this concurrency limit, but the driver will not guarantee that work submission remains non-overlapping.
For cudaDevResourceTypeWorkqueue, the resource represents a pre-existing workqueue that can be retrieved from existing execution contexts. This allows reusing workqueue resources across different execution contexts.
On Concurrency
Even if the green contexts have disjoint SM partitions, it is not guaranteed that the kernels launched in them will run concurrently or have forward progress guarantees. This is due to other resources that could cause a dependency. Using a combination of disjoint SMs and cudaDevWorkqueueConfigScopeGreenCtxBalanced workqueue configurations can provide the best chance of avoiding interference. More resources will be added in the future to provide stronger guarantees.
Additionally, there are two known scenarios, where its possible for the workload to run on more SMs than was provisioned (but never less).
On Volta+ MPS: When
CUDA_MPS_ACTIVE_THREAD_PERCENTAGEis used, the set of SMs that are used for running kernels can be scaled up to the value of SMs used for the MPS client.On Compute Architecture 9.x: When a module with dynamic parallelism (CDP) is loaded, all future kernels running under green contexts may use and share an additional set of 2 SMs.
Memory Copy Operations
Green context restrictions apply to memory copy operations only when the copy is performed using a green context. For cross-device copies, green context restrictions may not be applied.
|
Get device resources. |
|
Splits |
|
Splits a |
|
Generate a resource descriptor. |
|
Creates a green context with a specified set of resources. |
|
Destroy a execution context. |
|
Get context resources. |
|
Returns the device handle for the execution context. |
|
Returns the unique Id associated with the execution context supplied. |
|
Creates a stream and initializes it for the given execution context. |
|
Block for the specified execution context's tasks to complete. |
|
Get stream resources. |
|
Records an event for the specified execution context. |
|
Make an execution context wait on an event. |
|
Returns the execution context for a device. |
Interactions with the CUDA Driver API#
This section describes the interactions between the CUDA Driver API and the CUDA Runtime API
Execution Contexts
The CUDA Runtime provides cudaExecutionContext_t as an abstraction over driver-level contexts—specifically, green contexts and the primary context.
There are two primary ways to obtain an execution context:
cudaDeviceGetExecutionCtx: Returns the execution context that corresponds to the primary context of the specified device.
cudaGreenCtxCreate: Creates a green context with the specified resources and returns an execution context.
Note: Developers should treat cudaExecutionContext_t as an opaque handle and avoid assumptions about its underlying representation. The CUDA Runtime does not provide a way to convert this handle into a ::CUcontext or ::CUgreenCtx.
Primary Context (aka Device Execution Context)
The primary context is the default execution context associated with a device in the Runtime. It can be obtained via a call to cudaDeviceGetExecutionCtx(). There is a one-to-one mapping between CUDA devices in the runtime and their primary contexts within a process.
From the CUDA Runtime’s perspective, a device and its primary context are functionally synonymous.
Unless explicitly overridden, either by making a different context current via the Driver API (e.g., ::cuCtxSetCurrent()) or by using an explicit execution context handle, the Runtime will implicitly initialize and use the primary context for API calls as needed.
Initialization and Tear-Down
Unless an explicit execution context is specified (see “Execution Context Management” for APIs), CUDA Runtime API calls operate on the CUDA Driver ::CUcontext which is current to the calling host thread. If no ::CUcontext is current to the calling thread when a CUDA Runtime API call which requires an active context is made, then the primary context (device execution context) for a device will be selected, made current to the calling thread, and initialized. The context will be initialized using the parameters specified by the CUDA Runtime API functions cudaSetDeviceFlags(), ::cudaD3D9SetDirect3DDevice(), ::cudaD3D10SetDirect3DDevice(), ::cudaD3D11SetDirect3DDevice(), cudaGLSetGLDevice(), and cudaVDPAUSetVDPAUDevice(). Note that these functions will fail with cudaErrorSetOnActiveProcess if they are called when the primary context for the specified device has already been initialized, except for cudaSetDeviceFlags() which will simply overwrite the previous settings.
The function cudaInitDevice() ensures that the primary context is initialized for the requested device but does not make it current to the calling thread.
The function cudaSetDevice() initializes the primary context for the specified device and makes it current to the calling thread by calling ::cuCtxSetCurrent().
Primary contexts will remain active until they are explicitly deinitialized using cudaDeviceReset(). The function cudaDeviceReset() will deinitialize the primary context for the calling thread’s current device immediately. The context will remain current to all of the threads that it was current to. The next CUDA Runtime API call on any thread which requires an active context will trigger the reinitialization of that device’s primary context.
Note that primary contexts are shared resources. It is recommended that the primary context not be reset except just before exit or to recover from an unspecified launch failure.
CUcontext Interoperability
Note that the use of multiple ::CUcontext s per device within a single process will substantially degrade performance and is strongly discouraged. Instead, it is highly recommended to either use execution contexts cudaExecutionContext_t or the implicit one-to-one device-to-primary context mapping for the process provided by the CUDA Runtime API.
If a non-primary ::CUcontext created by the CUDA Driver API is current to a thread then the CUDA Runtime API calls to that thread will operate on that ::CUcontext, with some exceptions listed below. Interoperability between data types is discussed in the following sections.
The function cudaDeviceEnablePeerAccess() and the rest of the peer access API may not be called when a non-primary CUcontext is current. To use the peer access APIs with a context created using the CUDA Driver API, it is necessary that the CUDA Driver API be used to access these features.
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 then all CUDA Runtime API state will move to that thread as well.
Please note that attaching to legacy CUcontext (those with a version of 3010 as returned by ::cuCtxGetApiVersion()) is not possible. The CUDA Runtime will return cudaErrorIncompatibleDriverContext in such cases.
Interactions between CUstream and cudaStream_t
The types ::CUstream and cudaStream_t are identical and may be used interchangeably.
Interactions between CUevent and cudaEvent_t
The types ::CUevent and cudaEvent_t are identical and may be used interchangeably.
Interactions between CUarray and cudaArray_t
The types ::CUarray and struct ::cudaArray * represent the same data type and may be used interchangeably by casting the two types between each other.
In order to use a ::CUarray in a CUDA Runtime API function which takes a struct ::cudaArray *, it is necessary to explicitly cast the ::CUarray to a struct ::cudaArray *.
In order to use a struct ::cudaArray * in a CUDA Driver API function which takes a ::CUarray, it is necessary to explicitly cast the struct ::cudaArray * to a ::CUarray .
Interactions between CUgraphicsResource and cudaGraphicsResource_t
The types ::CUgraphicsResource and cudaGraphicsResource_t 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 cudaGraphicsResource_t, it is necessary to explicitly cast the ::CUgraphicsResource to a cudaGraphicsResource_t.
In order to use a cudaGraphicsResource_t in a CUDA Driver API function which takes a ::CUgraphicsResource, it is necessary to explicitly cast the cudaGraphicsResource_t to a ::CUgraphicsResource.
Interactions between CUtexObject and cudaTextureObject_t
The types ::CUtexObject and cudaTextureObject_t represent the same data type and may be used interchangeably by casting the two types between each other.
In order to use a ::CUtexObject in a CUDA Runtime API function which takes a cudaTextureObject_t, it is necessary to explicitly cast the ::CUtexObject to a cudaTextureObject_t.
In order to use a cudaTextureObject_t in a CUDA Driver API function which takes a ::CUtexObject, it is necessary to explicitly cast the cudaTextureObject_t to a ::CUtexObject.
Interactions between CUsurfObject and cudaSurfaceObject_t
The types ::CUsurfObject and cudaSurfaceObject_t represent the same data type and may be used interchangeably by casting the two types between each other.
In order to use a ::CUsurfObject in a CUDA Runtime API function which takes a cudaSurfaceObject_t, it is necessary to explicitly cast the ::CUsurfObject to a cudaSurfaceObject_t.
In order to use a cudaSurfaceObject_t in a CUDA Driver API function which takes a ::CUsurfObject, it is necessary to explicitly cast the cudaSurfaceObject_t to a ::CUsurfObject.
Interactions between CUfunction and cudaFunction_t
The types ::CUfunction and cudaFunction_t represent the same data type and may be used interchangeably by casting the two types between each other.
In order to use a cudaFunction_t in a CUDA Driver API function which takes a ::CUfunction, it is necessary to explicitly cast the cudaFunction_t to a ::CUfunction.
Interactions between CUkernel and cudaKernel_t
The types ::CUkernel and cudaKernel_t represent the same data type and may be used interchangeably by casting the two types between each other.
In order to use a cudaKernel_t in a CUDA Driver API function which takes a ::CUkernel, it is necessary to explicitly cast the cudaKernel_t to a ::CUkernel.
|
Get pointer to device kernel that matches entry function |
Profiler Control#
This section describes the profiler control functions of the CUDA runtime application programming interface.
|
Enable profiling. |
|
Disable profiling. |
Deprecated Device Management#
This section describes the deprecated device management functions of the CUDA runtime application programming interface.
|
Returns the shared memory configuration for the current device. |
|
Sets the shared memory configuration for the current device. |
Deprecated Execution Control#
This section describes the deprecated execution control functions of the CUDA runtime application programming interface.
|
Sets the shared memory configuration for a device function. |
Deprecated Memory Management#
This section describes the deprecated memory management functions of the CUDA runtime application programming interface.
|
Copies data between host and device. |
|
Copies data between host and device. |
|
Copies data between host and device. |
|
Copies data between host and device. |
|
Copies data between host and device. |