CUDA Runtime API Reference Manual (Release 13.5, 2026) - page 5

 

  Index      Manuals     CUDA Runtime API Reference Manual (Release 13.5, 2026)

 

Search            copyright infringement  

 

   

 

   

 

Content      ..     3      4      5      6     ..

 

 

 

CUDA Runtime API Reference Manual (Release 13.5, 2026) - page 5

 

 

CUDA Runtime API Reference Manual, Release 13.5
Note: This function uses standard default stream semantics.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ stream - - Stream to enqueue function call in
▶ fn - - The function to call once preceding stream operations are complete
▶ userData - - User-specified data to be passed to the function
Returns
cudaSuccess, cudaErrorInvalidResourceHandle, cudaErrorInvalidValue, cudaEr-
rorNotSupported
__host__ cudaError_t cudaLaunchHostFunc_v2(cudaStream_t stream, cudaHostFn_t fn, void
*userData, unsigned int syncMode)
Enqueues a host function call in a stream.
Enqueues a host function to run in a stream. The function will be called after currently enqueued
work and will block work added after it.
The host function must not make any CUDA API calls. Attempting to use a CUDA API may re-
sult in cudaErrorNotPermitted, but this is not required. The host function must not perform any
synchronization that may depend on outstanding CUDA work not mandated to run earlier. Host
functions without a mandated order (such as in independent streams) execute in undefined or-
der and may be serialized.
For the purposes of Unified Memory, execution makes a number of guarantees:
▶ The stream is considered idle for the duration of the function’s execution. Thus, for example,
the function may always use memory attached to the stream it was enqueued in.
▶ The start of execution of the function has the same effect as synchronizing an event
recorded in the same stream immediately prior to the function. It thus synchronizes streams
which have been “joined” prior to the function.
▶ Adding device work to any stream does not have the effect of making the stream active
until all preceding host functions and stream callbacks have executed. Thus, for example, a
function might use global attached memory even if work has been added to another stream,
if the work has been ordered behind the function call with an event.
▶ Completion of the function does not cause a stream to become active except as described
above. The stream will remain idle if no device work follows the function, and will remain
292
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
idle across consecutive host functions or stream callbacks without device work in between.
Thus, for example, stream synchronization can be done by signaling from a host function at
the end of the stream.
Note that, in constrast to ::cuStreamAddCallback, the function will not be called in the event of
an error in the CUDA context.
See also:
cudaStreamCreate, cudaStreamQuery, cudaStreamSynchronize, cudaStreamWaitEvent, cudaS-
treamDestroy, cudaMallocManaged, cudaStreamAttachMemAsync, cudaStreamAddCallback, ::cu-
LaunchHostFunc
Note: This function uses standard default stream semantics.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ stream - - Stream to enqueue function call in
▶ fn - - The function to call once preceding stream operations are complete
▶ userData - - User-specified data to be passed to the function
▶ syncMode - - Sync mode for the host function
Returns
cudaSuccess, cudaErrorInvalidResourceHandle, cudaErrorInvalidValue, cudaEr-
rorNotSupported
__host__ cudaError_t cudaLaunchKernel(const void *func, dim3 gridDim, dim3 blockDim, void
**args, size_t sharedMem, cudaStream_t stream)
Launches a device function.
The function invokes kernel func on gridDim (gridDim.xgridDim.ygridDim.z) grid of blocks.
Each block contains blockDim (blockDim.xblockDim.yblockDim.z) threads.
If the kernel has N parameters the args should point to array of N pointers. Each pointer, from
args[0] to args[N - 1], point to the region of memory from which the actual parameter will
be copied.
For
templated
functions,
pass
the
function
symbol
as
follows:
func_name<template_arg_0,…,template_arg_N>
6.17. Execution Control
293
CUDA Runtime API Reference Manual, Release 13.5
sharedMem sets the amount of dynamic shared memory that will be available to each thread
block.
stream specifies a stream the invocation is associated to.
See also:
cudaLaunchKernel (C++ API), ::cuLaunchKernel
Note: This function uses standard default stream semantics.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Note: The API can also be used with a kernel cudaKernel_t by querying the handle using cudaLi-
braryGetKernel() or cudaGetKernel and then passing it to the API by casting to void*. The symbol
entryFuncAddr passed to cudaGetKernel should be a symbol that is registered with the same
CUDA Runtime instance.
Note: Passing a symbol that belongs that belongs to a different runtime instance will result in
undefined behavior. The only type that can be reliably passed to a different runtime instance is
cudaKernel_t
Parameters
▶ func - - Device function symbol
▶ gridDim - - Grid dimentions
▶ blockDim - - Block dimentions
▶ args - - Arguments
▶ sharedMem - - Shared memory
▶ stream - - Stream identifier
Returns
cudaSuccess, cudaErrorInvalidDeviceFunction, cudaErrorInvalidConfiguration, cud-
aErrorLaunchFailure, cudaErrorLaunchTimeout, cudaErrorLaunchOutOfResources,
294
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
cudaErrorSharedObjectInitFailed, cudaErrorInvalidPtx, cudaErrorUnsupportedP-
txVersion,
cudaErrorNoKernelImageForDevice,
cudaErrorJitCompilerNotFound,
cudaErrorJitCompilationDisabled
__host__ cudaError_t cudaLaunchKernelExC(const cudaLaunchConfig_t *config, const void *func,
void **args)
Launches a CUDA function with launch-time configuration.
Note that the functionally equivalent variadic template cudaLaunchKernelEx is available for
C++11 and newer.
Invokes the kernel func on config->gridDim (config->gridDim.xconfig->gridDim.
yconfig->gridDim.z) grid of blocks.
Each block contains config->blockDim
(config->blockDim.xconfig->blockDim.yconfig->blockDim.z) threads.
config->dynamicSmemBytes sets the amount of dynamic shared memory that will be available
to each thread block.
config->stream specifies a stream the invocation is associated to.
Configuration beyond grid and block dimensions, dynamic shared memory size, and stream can
be provided with the following two fields of config:
config->attrs is an array of config->numAttrs contiguous cudaLaunchAttribute elements.
The value of this pointer is not considered if config->numAttrs is zero. However, in that case,
it is recommended to set the pointer to NULL. config->numAttrs is the number of attributes
populating the first config->numAttrs positions of the config->attrs array.
If the kernel has N parameters the args should point to array of N pointers. Each pointer, from
args[0] to args[N - 1], point to the region of memory from which the actual parameter will
be copied.
N.B. This function is so named to avoid unintentionally invoking the templated version, cud-
aLaunchKernelEx, for kernels taking a single void** or void* parameter.
See also:
cudaLaunchKernelEx(const cudaLaunchConfig_t *config, void (*kernel)(ExpTypes…), ActTypes
&&… args) “cudaLaunchKernelEx (C++ API)”, ::cuLaunchKernelEx
Note: This function uses standard default stream semantics.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
6.17. Execution Control
295
CUDA Runtime API Reference Manual, Release 13.5
Note: The API can also be used with a kernel cudaKernel_t by querying the handle using cudaLi-
braryGetKernel() or cudaGetKernel and then passing it to the API by casting to void*. The symbol
entryFuncAddr passed to cudaGetKernel should be a symbol that is registered with the same
CUDA Runtime instance.
Note: Passing a symbol that belongs that belongs to a different runtime instance will result in
undefined behavior. The only type that can be reliably passed to a different runtime instance is
cudaKernel_t
Parameters
▶ config - - Launch configuration
▶ func - - Kernel to launch
▶ args - - Array of pointers to kernel parameters
Returns
cudaSuccess, cudaErrorInvalidDeviceFunction, cudaErrorInvalidConfiguration, cud-
aErrorLaunchFailure, cudaErrorLaunchTimeout, cudaErrorLaunchOutOfResources,
cudaErrorSharedObjectInitFailed, cudaErrorInvalidPtx, cudaErrorUnsupportedP-
txVersion,
cudaErrorNoKernelImageForDevice,
cudaErrorJitCompilerNotFound,
cudaErrorJitCompilationDisabled
__device__ inline void cudaTriggerProgrammaticLaunchCompletion(void)
Programmatic dependency trigger.
This device function ensures the programmatic launch completion edges / events are fulfilled.
See ::cudaLaunchAttributeID::cudaLaunchAttributeProgrammaticStreamSerialization and ::cud-
aLaunchAttributeID::cudaLaunchAttributeProgrammaticEvent for more information. The event /
edge kick off only happens when every CTAs in the grid has either exited or called this function
at least once, otherwise the kick off happens automatically after all warps finishes execution but
before the grid completes. The kick off only enables scheduling of the secondary kernel. It pro-
vides no memory visibility guarantee itself. The user could enforce memory visibility by inserting
a memory fence of the correct scope.
6.18. Execution Control [DEPRECATED]
This section describes the deprecated 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.
296
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
Functions
__host__ cudaError_t cudaFuncSetSharedMemConfig(const void *func, enum cudaSharedMemCon-
fig config)
Sets the shared memory configuration for a device function.
6.18.1. Functions
__host__ cudaError_t cudaFuncSetSharedMemConfig(const void *func, enum
cudaSharedMemConfig config)
Sets the shared memory configuration for a device function.
Deprecated:
On devices with configurable shared memory banks, this function will force all subsequent
launches of the specified device function to have the given shared memory bank size config-
uration. On any given launch of the function, the shared memory configuration of the device
will be temporarily changed if needed to suit the function’s preferred configuration. Changes
in shared memory configuration between subsequent launches of functions, may introduce a
device side synchronization point.
Any per-function setting of shared memory bank size set via cudaFuncSetSharedMemConfig will
override the device wide setting set by cudaDeviceSetSharedMemConfig.
Changing the shared memory bank size will not increase shared memory usage or affect oc-
cupancy of kernels, but may have major effects on performance. Larger bank sizes will allow for
greater potential bandwidth to shared memory, but will change what kinds of accesses to shared
memory will result in bank conflicts.
This function will do nothing on devices with fixed shared memory bank size.
For
templated
functions,
pass
the
function
symbol
as
follows:
func_name<template_arg_0,…,template_arg_N>
The supported bank configurations are:
▶ cudaSharedMemBankSizeDefault: use the device’s shared memory configuration when
launching this function.
▶ cudaSharedMemBankSizeFourByte: set shared memory bank width to be four bytes na-
tively when launching this function.
▶ cudaSharedMemBankSizeEightByte: set shared memory bank width to be eight bytes na-
tively when launching this function.
See also:
cudaDeviceSetSharedMemConfig, cudaDeviceGetSharedMemConfig, cudaDeviceSetCacheConfig,
cudaDeviceGetCacheConfig, cudaFuncSetCacheConfig, ::cuFuncSetSharedMemConfig
Note: Note that this function may also return error codes from previous, asynchronous launches.
6.18. Execution Control [DEPRECATED]
297
CUDA Runtime API Reference Manual, Release 13.5
Note: Use of a string naming a function as the func parameter was deprecated in CUDA 4.1
and removed in CUDA 5.0.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ func - - Device function symbol
▶ config - - Requested shared memory configuration
Returns
cudaSuccess, cudaErrorInvalidDeviceFunction, cudaErrorInvalidValue,
6.19. External Resource Interoperability
This section describes the external resource interoperability functions of the CUDA runtime applica-
tion programming interface.
Functions
__host__ cudaError_t cudaDestroyExternalMemory(cudaExternalMemory_t extMem)
Destroys an external memory object.
__host__ cudaError_t cudaDestroyExternalSemaphore(cudaExternalSemaphore_t extSem)
Destroys an external semaphore.
__host__ cudaError_t cudaExternalMemoryGetMappedBuffer(void **devPtr, cudaExternalMemory_t
extMem, const struct cudaExternalMemoryBufferDesc *bufferDesc)
Maps a buffer onto an imported memory object.
__host__ cudaError_t cudaExternalMemoryGetMappedMipmappedArray(cudaMipmappedArray_t
*mipmap, cudaExternalMemory_t extMem, const struct cudaExternalMemoryMipmappedAr-
rayDesc *mipmapDesc)
Maps a CUDA mipmapped array onto an external memory object.
__host__ cudaError_t cudaImportExternalMemory(cudaExternalMemory_t *extMem_out, const
struct cudaExternalMemoryHandleDesc *memHandleDesc)
Imports an external memory object.
__host__ cudaError_t cudaImportExternalSemaphore(cudaExternalSemaphore_t *extSem_out,
const struct cudaExternalSemaphoreHandleDesc *semHandleDesc)
Imports an external semaphore.
298
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
__host__ cudaError_t cudaSignalExternalSemaphoresAsync(const cudaExternalSemaphore_t
*extSemArray, const struct cudaExternalSemaphoreSignalParams *paramsArray, unsigned
int numExtSems, cudaStream_t stream=0)
Signals a set of external semaphore objects.
__host__ cudaError_t cudaWaitExternalSemaphoresAsync(const cudaExternalSemaphore_t *extSe-
mArray, const struct cudaExternalSemaphoreWaitParams *paramsArray, unsigned int nu-
mExtSems, cudaStream_t stream=0)
Waits on a set of external semaphore objects.
6.19.1. Functions
__host__ cudaError_t cudaDestroyExternalMemory(cudaExternalMemory_t extMem)
Destroys an external memory object.
Destroys the specified external memory object. Any existing buffers and CUDA mipmapped ar-
rays mapped onto this object must no longer be used and must be explicitly freed using cudaFree
and cudaFreeMipmappedArray respectively.
See also:
cudaImportExternalMemory,
cudaExternalMemoryGetMappedBuffer,
cudaExternalMemo-
ryGetMappedMipmappedArray
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Note: Use of the handle after this call is undefined behavior.
Parameters
extMem - - External memory object to be destroyed
Returns
cudaSuccess, cudaErrorInvalidResourceHandle
__host__ cudaError_t cudaDestroyExternalSemaphore(cudaExternalSemaphore_t extSem)
Destroys an external semaphore.
Destroys an external semaphore object and releases any references to the underlying resource.
Any outstanding signals or waits must have completed before the semaphore is destroyed.
6.19. External Resource Interoperability
299
CUDA Runtime API Reference Manual, Release 13.5
See also:
cudaImportExternalSemaphore,
cudaSignalExternalSemaphoresAsync,
cudaWaitExter-
nalSemaphoresAsync
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Note: Use of the handle after this call is undefined behavior.
Parameters
extSem - - External semaphore to be destroyed
Returns
cudaSuccess, cudaErrorInvalidResourceHandle
__host__ cudaError_t cudaExternalMemoryGetMappedBuffer(void **devPtr,
cudaExternalMemory_t extMem,
const struct
cudaExternalMemoryBufferDesc
*bufferDesc)
Maps a buffer onto an imported memory object.
Maps a buffer onto an imported memory object and returns a device pointer in devPtr.
The properties of the buffer being mapped must be described in bufferDesc. The cudaExter-
nalMemoryBufferDesc structure is defined as follows:
typedef struct cudaExternalMemoryBufferDesc_st {
unsigned long long offset;
unsigned long long size;
unsigned int flags;
} cudaExternalMemoryBufferDesc;
where cudaExternalMemoryBufferDesc::offset is the offset in the memory object where the
buffer’s base address is. cudaExternalMemoryBufferDesc::size is the size of the buffer. cudaEx-
ternalMemoryBufferDesc::flags must be zero.
The offset and size have to be suitably aligned to match the requirements of the external API.
Mapping two buffers whose ranges overlap may or may not result in the same virtual address
being returned for the overlapped portion. In such cases, the application must ensure that all
accesses to that region from the GPU are volatile. Otherwise writes made via one address are
300
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
not guaranteed to be visible via the other address, even if they’re issued by the same thread. It is
recommended that applications map the combined range instead of mapping separate buffers
and then apply the appropriate offsets to the returned pointer to derive the individual buffers.
The returned pointer devPtr must be freed using cudaFree.
See also:
cudaImportExternalMemory, cudaDestroyExternalMemory, cudaExternalMemoryGetMapped-
MipmappedArray
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ devPtr - - Returned device pointer to buffer
▶ extMem - - Handle to external memory object
▶ bufferDesc - - Buffer descriptor
Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorInvalidResourceHandle
__host__ cudaError_t cudaExternalMemoryGetMappedMipmappedArray(cudaMipmappedArray_t
*mipmap,
cudaExternalMemory_t
extMem, const struct
cudaExternalMemo-
ryMipmappedArrayDesc
*mipmapDesc)
Maps a CUDA mipmapped array onto an external memory object.
Maps a CUDA mipmapped array onto an external object and returns a handle to it in mipmap.
The properties of the CUDA mipmapped array being mapped must be described in mipmapDesc.
The structure cudaExternalMemoryMipmappedArrayDesc is defined as follows:
typedef struct cudaExternalMemoryMipmappedArrayDesc_st {
unsigned long long offset;
cudaChannelFormatDesc formatDesc;
cudaExtent extent;
(continues on next page)
6.19. External Resource Interoperability
301
CUDA Runtime API Reference Manual, Release 13.5
(continued from previous page)
unsigned int flags;
unsigned int numLevels;
} cudaExternalMemoryMipmappedArrayDesc;
where cudaExternalMemoryMipmappedArrayDesc::offset is the offset in the memory ob-
ject where the base level of the mipmap chain is. cudaExternalMemoryMipmappedArray-
Desc::formatDesc describes the format of the data. cudaExternalMemoryMipmappedArray-
Desc::extent specifies the dimensions of the base level of the mipmap chain. cudaExter-
nalMemoryMipmappedArrayDesc::flags are flags associated with CUDA mipmapped arrays. For
further details, please refer to the documentation for cudaMalloc3DArray. Note that if the
mipmapped array is bound as a color target in the graphics API, then the flag cudaArrayCol-
orAttachment must be specified in cudaExternalMemoryMipmappedArrayDesc::flags. cudaExter-
nalMemoryMipmappedArrayDesc::numLevels specifies the total number of levels in the mipmap
chain.
The returned CUDA mipmapped array must be freed using cudaFreeMipmappedArray.
See also:
cudaImportExternalMemory, cudaDestroyExternalMemory, cudaExternalMemoryGetMapped-
Buffer
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Note:
If cudaExternalMemoryHandleDesc::type is cudaExternalMemoryHandleTypeNvSciBuf,
then cudaExternalMemoryMipmappedArrayDesc::numLevels must not be greater than 1.
Parameters
▶ mipmap - - Returned CUDA mipmapped array
▶ extMem - - Handle to external memory object
▶ mipmapDesc - - CUDA array descriptor
Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorInvalidResourceHandle
__host__ cudaError_t cudaImportExternalMemory(cudaExternalMemory_t *extMem_out, const
struct cudaExternalMemoryHandleDesc
*memHandleDesc)
302
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
Imports an external memory object.
Imports an externally allocated memory object and returns a handle to that in extMem_out.
The properties of the handle being imported must be described in memHandleDesc. The cudaEx-
ternalMemoryHandleDesc structure is defined as follows:
typedef struct cudaExternalMemoryHandleDesc_st {
cudaExternalMemoryHandleType type;
union {
int fd;
struct {
void *handle;
const void *name;
} win32;
const void *nvSciBufObject;
} handle;
unsigned long long size;
unsigned int flags;
} cudaExternalMemoryHandleDesc;
where cudaExternalMemoryHandleDesc::type specifies the type of handle being imported. cud-
aExternalMemoryHandleType is defined as:
typedef enum cudaExternalMemoryHandleType_enum {
cudaExternalMemoryHandleTypeOpaqueFd
= 1,
cudaExternalMemoryHandleTypeOpaqueWin32
= 2,
cudaExternalMemoryHandleTypeOpaqueWin32Kmt
= 3,
cudaExternalMemoryHandleTypeD3D12Heap
= 4,
cudaExternalMemoryHandleTypeD3D12Resource
= 5,
cudaExternalMemoryHandleTypeD3D11Resource
= 6,
cudaExternalMemoryHandleTypeD3D11ResourceKmt = 7,
cudaExternalMemoryHandleTypeNvSciBuf
= 8
} cudaExternalMemoryHandleType;
If cudaExternalMemoryHandleDesc::type is cudaExternalMemoryHandleTypeOpaqueFd, then ::cu-
daExternalMemoryHandleDesc::handle::fd must be a valid file descriptor referencing a memory
object. Ownership of the file descriptor is transferred to the CUDA driver when the handle is im-
ported successfully. Performing any operations on the file descriptor after it is imported results
in undefined behavior.
If
cudaExternalMemoryHandleDesc::type is cudaExternalMemoryHandleTypeOpaqueWin32,
then exactly one of ::cudaExternalMemoryHandleDesc::handle::win32::handle and ::cudaExter-
nalMemoryHandleDesc::handle::win32::name must not be NULL. If ::cudaExternalMemoryHan-
dleDesc::handle::win32::handle is not NULL, then it must represent a valid shared NT handle that
references a memory object. Ownership of this handle is not transferred to CUDA after the
import operation, so the application must release the handle using the appropriate system call.
If ::cudaExternalMemoryHandleDesc::handle::win32::name is not NULL, then it must point to a
NULL-terminated array of UTF-16 characters that refers to a memory object.
If cudaExternalMemoryHandleDesc::type is cudaExternalMemoryHandleTypeOpaqueWin32Kmt,
then ::cudaExternalMemoryHandleDesc::handle::win32::handle must be non-NULL and ::cudaEx-
ternalMemoryHandleDesc::handle::win32::name must be NULL. The handle specified must be a
globally shared KMT handle. This handle does not hold a reference to the underlying object, and
6.19. External Resource Interoperability
303
CUDA Runtime API Reference Manual, Release 13.5
thus will be invalid when all references to the memory object are destroyed.
If cudaExternalMemoryHandleDesc::type is cudaExternalMemoryHandleTypeD3D12Heap, then
exactly one of
::cudaExternalMemoryHandleDesc::handle::win32::handle and
::cudaExter-
nalMemoryHandleDesc::handle::win32::name must not be NULL. If ::cudaExternalMemoryHan-
dleDesc::handle::win32::handle is not NULL, then it must represent a valid shared NT handle
that is returned by ID3D12Device::CreateSharedHandle when referring to a ID3D12Heap
object. This handle holds a reference to the underlying object. If ::cudaExternalMemoryHan-
dleDesc::handle::win32::name is not NULL, then it must point to a NULL-terminated array of
UTF-16 characters that refers to a ID3D12Heap object.
If cudaExternalMemoryHandleDesc::type is cudaExternalMemoryHandleTypeD3D12Resource,
then exactly one of ::cudaExternalMemoryHandleDesc::handle::win32::handle and ::cudaExter-
nalMemoryHandleDesc::handle::win32::name must not be NULL. If ::cudaExternalMemoryHan-
dleDesc::handle::win32::handle is not NULL, then it must represent a valid shared NT handle
that is returned by ID3D12Device::CreateSharedHandle when referring to a ID3D12Resource
object. This handle holds a reference to the underlying object. If ::cudaExternalMemoryHan-
dleDesc::handle::win32::name is not NULL, then it must point to a NULL-terminated array of
UTF-16 characters that refers to a ID3D12Resource object.
If cudaExternalMemoryHandleDesc::type is cudaExternalMemoryHandleTypeD3D11Resource
,then exactly one of ::cudaExternalMemoryHandleDesc::handle::win32::handle and ::cudaExter-
nalMemoryHandleDesc::handle::win32::name must not be NULL. If ::cudaExternalMemoryHan-
dleDesc::handle::win32::handle is
not NULL, then it must represent a valid shared NT handle that is
returned by IDXGIResource1::CreateSharedHandle when referring to a ID3D11Resource object.
If ::cudaExternalMemoryHandleDesc::handle::win32::name is not NULL, then it must point to a
NULL-terminated array of UTF-16 characters that refers to a ID3D11Resource object.
If cudaExternalMemoryHandleDesc::type is cudaExternalMemoryHandleTypeD3D11ResourceKmt,
then ::cudaExternalMemoryHandleDesc::handle::win32::handle must be non-NULL and ::cudaEx-
ternalMemoryHandleDesc::handle::win32::name must be NULL. The handle specified must be a
valid shared KMT handle that is returned by IDXGIResource::GetSharedHandle when referring to
a ID3D11Resource object.
If cudaExternalMemoryHandleDesc::type is cudaExternalMemoryHandleTypeNvSciBuf, then ::cud-
aExternalMemoryHandleDesc::handle::nvSciBufObject must be NON-NULL and reference a valid
NvSciBuf object. If the NvSciBuf object imported into CUDA is also mapped by other drivers, then
the application must use cudaWaitExternalSemaphoresAsync or cudaSignalExternalSemaphore-
sAsync as approprriate barriers to maintain coherence between CUDA and the other drivers.
See cudaExternalSemaphoreWaitSkipNvSciBufMemSync and cudaExternalSemaphoreSignalSkip-
NvSciBufMemSync for memory synchronization.
The size of the memory object must be specified in cudaExternalMemoryHandleDesc::size.
Specifying the flag cudaExternalMemoryDedicated in cudaExternalMemoryHandleDesc::flags in-
dicates that the resource is a dedicated resource. The definition of what a dedicated re-
source is outside the scope of this extension. This flag must be set if cudaExternalMemoryHan-
dleDesc::type is one of the following: cudaExternalMemoryHandleTypeD3D12Resource cudaExter-
nalMemoryHandleTypeD3D11Resource cudaExternalMemoryHandleTypeD3D11ResourceKmt
See also:
cudaDestroyExternalMemory,
cudaExternalMemoryGetMappedBuffer,
cudaExternalMemo-
ryGetMappedMipmappedArray
304
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Note:
If the Vulkan memory imported into CUDA is mapped on the CPU then the application must
use vkInvalidateMappedMemoryRanges/vkFlushMappedMemoryRanges as well as appropriate
Vulkan pipeline barriers to maintain coherence between CPU and GPU. For more information on
these APIs, please refer to “Synchronization
and Cache Control” chapter from Vulkan specification.
Parameters
▶ extMem_out - - Returned handle to an external memory object
▶ memHandleDesc - - Memory import handle descriptor
Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorInvalidResourceHandle, cudaErrorOp-
eratingSystem
__host__ cudaError_t cudaImportExternalSemaphore(cudaExternalSemaphore_t *extSem_out,
const struct
cudaExternalSemaphoreHandleDesc
*semHandleDesc)
Imports an external semaphore.
Imports an externally allocated synchronization object and returns a handle to that in
extSem_out.
The properties of the handle being imported must be described in semHandleDesc. The cudaEx-
ternalSemaphoreHandleDesc is defined as follows:
typedef struct cudaExternalSemaphoreHandleDesc_st {
cudaExternalSemaphoreHandleType type;
union {
int fd;
struct {
void *handle;
const void *name;
} win32;
(continues on next page)
6.19. External Resource Interoperability
305
CUDA Runtime API Reference Manual, Release 13.5
(continued from previous page)
const void* NvSciSyncObj;
} handle;
unsigned int flags;
} cudaExternalSemaphoreHandleDesc;
where cudaExternalSemaphoreHandleDesc::type specifies the type of handle being imported. cu-
daExternalSemaphoreHandleType is defined as:
typedef enum cudaExternalSemaphoreHandleType_enum {
cudaExternalSemaphoreHandleTypeOpaqueFd
= 1,
cudaExternalSemaphoreHandleTypeOpaqueWin32
= 2,
cudaExternalSemaphoreHandleTypeOpaqueWin32Kmt
= 3,
cudaExternalSemaphoreHandleTypeD3D12Fence
= 4,
cudaExternalSemaphoreHandleTypeD3D11Fence
= 5,
cudaExternalSemaphoreHandleTypeNvSciSync
= 6,
cudaExternalSemaphoreHandleTypeKeyedMutex
= 7,
cudaExternalSemaphoreHandleTypeKeyedMutexKmt
= 8,
cudaExternalSemaphoreHandleTypeTimelineSemaphoreFd
= 9,
cudaExternalSemaphoreHandleTypeTimelineSemaphoreWin32
= 10
} cudaExternalSemaphoreHandleType;
If cudaExternalSemaphoreHandleDesc::type is cudaExternalSemaphoreHandleTypeOpaqueFd,
then ::cudaExternalSemaphoreHandleDesc::handle::fd must be a valid file descriptor referencing
a synchronization object. Ownership of the file descriptor is transferred to the CUDA driver
when the handle is imported successfully. Performing any operations on the file descriptor after
it is imported results in undefined behavior.
If cudaExternalSemaphoreHandleDesc::type is cudaExternalSemaphoreHandleTypeOpaqueWin32,
then exactly one of ::cudaExternalSemaphoreHandleDesc::handle::win32::handle and ::cudaExter-
nalSemaphoreHandleDesc::handle::win32::name must not be NULL. If ::cudaExternalSemaphore-
HandleDesc::handle::win32::handle is not NULL, then it must represent a valid shared NT handle
that references a synchronization object. Ownership of this handle is not transferred to CUDA
after the import operation, so the application must release the handle using the appropriate sys-
tem call. If ::cudaExternalSemaphoreHandleDesc::handle::win32::name is not NULL, then it must
name a valid synchronization object.
If cudaExternalSemaphoreHandleDesc::type is cudaExternalSemaphoreHandleTypeOpaque-
Win32Kmt, then ::cudaExternalSemaphoreHandleDesc::handle::win32::handle must be non-
NULL and ::cudaExternalSemaphoreHandleDesc::handle::win32::name must be NULL. The handle
specified must be a globally shared KMT handle. This handle does not hold a reference to the
underlying object, and thus will be invalid when all references to the synchronization object are
destroyed.
If cudaExternalSemaphoreHandleDesc::type is cudaExternalSemaphoreHandleTypeD3D12Fence,
then exactly one of ::cudaExternalSemaphoreHandleDesc::handle::win32::handle and ::cudaExter-
nalSemaphoreHandleDesc::handle::win32::name must not be NULL. If ::cudaExternalSemaphore-
HandleDesc::handle::win32::handle is not NULL, then it must represent a valid shared NT handle
that is returned by ID3D12Device::CreateSharedHandle when referring to a ID3D12Fence ob-
ject. This handle holds a reference to the underlying object. If ::cudaExternalSemaphoreHan-
dleDesc::handle::win32::name is not NULL, then it must name a valid synchronization object that
refers to a valid ID3D12Fence object.
If cudaExternalSemaphoreHandleDesc::type is cudaExternalSemaphoreHandleTypeD3D11Fence,
then exactly one of ::cudaExternalSemaphoreHandleDesc::handle::win32::handle and ::cudaExter-
nalSemaphoreHandleDesc::handle::win32::name must not be NULL. If ::cudaExternalSemaphore-
306
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
HandleDesc::handle::win32::handle is not NULL, then it must represent a valid shared NT han-
dle that is returned by ID3D11Fence::CreateSharedHandle. If ::cudaExternalSemaphoreHan-
dleDesc::handle::win32::name is not NULL, then it must name a valid synchronization object that
refers to a valid ID3D11Fence object.
If cudaExternalSemaphoreHandleDesc::type is cudaExternalSemaphoreHandleTypeNvSciSync,
then ::cudaExternalSemaphoreHandleDesc::handle::nvSciSyncObj represents a valid NvSciSyn-
cObj.
cudaExternalSemaphoreHandleTypeKeyedMutex,
then
exactly
one
of
::cudaExter-
nalSemaphoreHandleDesc::handle::win32::handle
and
::cudaExternalSemaphoreHan-
dleDesc::handle::win32::name
must
not
be
NULL.
If
::cudaExternalSemaphoreHan-
dleDesc::handle::win32::handle is not NULL, then it represent a valid shared NT handle that
is returned by IDXGIResource1::CreateSharedHandle when referring to a IDXGIKeyedMutex
object.
If cudaExternalSemaphoreHandleDesc::type is cudaExternalSemaphoreHandleTypeKeyedMu-
texKmt, then ::cudaExternalSemaphoreHandleDesc::handle::win32::handle must be non-NULL
and ::cudaExternalSemaphoreHandleDesc::handle::win32::name must be NULL. The handle spec-
ified must represent a valid KMT handle that is returned by IDXGIResource::GetSharedHandle
when referring to a IDXGIKeyedMutex object.
If cudaExternalSemaphoreHandleDesc::type is cudaExternalSemaphoreHandleTypeTimeline-
SemaphoreFd, then
::cudaExternalSemaphoreHandleDesc::handle::fd must be a valid file
descriptor referencing a synchronization object. Ownership of the file descriptor is transferred
to the CUDA driver when the handle is imported successfully. Performing any operations on the
file descriptor after it is imported results in undefined behavior.
If
cudaExternalSemaphoreHandleDesc::type
is
cudaExternalSemaphoreHandleType-
TimelineSemaphoreWin32,
then
exactly
one
of
::cudaExternalSemaphoreHan-
dleDesc::handle::win32::handle and ::cudaExternalSemaphoreHandleDesc::handle::win32::name
must not be NULL. If ::cudaExternalSemaphoreHandleDesc::handle::win32::handle is not NULL,
then it must represent a valid shared NT handle that references a synchronization object. Own-
ership of this handle is not transferred to CUDA after the import operation, so the application
must release the handle using the appropriate system call. If ::cudaExternalSemaphoreHan-
dleDesc::handle::win32::name is not NULL, then it must name a valid synchronization object.
See also:
cudaDestroyExternalSemaphore,
cudaSignalExternalSemaphoresAsync,
cudaWaitExter-
nalSemaphoresAsync
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
6.19. External Resource Interoperability
307
CUDA Runtime API Reference Manual, Release 13.5
Parameters
▶ extSem_out - - Returned handle to an external semaphore
▶ semHandleDesc - - Semaphore import handle descriptor
Returns
cudaSuccess, cudaErrorInvalidResourceHandle, cudaErrorOperatingSystem
__host__ cudaError_t cudaSignalExternalSemaphoresAsync(const cudaExternalSemaphore_t
*extSemArray, const struct cudaEx-
ternalSemaphoreSignalParams
*paramsArray, unsigned int
numExtSems, cudaStream_t
stream = 0)
Signals a set of external semaphore objects.
Enqueues a signal operation on a set of externally allocated semaphore object in the specified
stream. The operations will be executed when all prior operations in the stream complete.
The exact semantics of signaling a semaphore depends on the type of the object.
If the semaphore object is any one of the following types: cudaExternalSemaphoreHandle-
TypeOpaqueFd, cudaExternalSemaphoreHandleTypeOpaqueWin32, cudaExternalSemaphoreHan-
dleTypeOpaqueWin32Kmt then signaling the semaphore will set it to the signaled state.
If the semaphore object is any one of the following types: cudaExternalSemaphoreHan-
dleTypeD3D12Fence, cudaExternalSemaphoreHandleTypeD3D11Fence, cudaExternalSemaphore-
HandleTypeTimelineSemaphoreFd, cudaExternalSemaphoreHandleTypeTimelineSemaphoreWin32
then the semaphore will be set to the value specified in ::cudaExternalSemaphoreSignal-
Params::params::fence::value.
If the semaphore object is of the type cudaExternalSemaphoreHandleTypeNvSciSync this API
sets ::cudaExternalSemaphoreSignalParams::params::nvSciSync::fence to a value that can be
used by subsequent waiters of the same NvSciSync object to order operations with those cur-
rently submitted in stream. Such an update will overwrite previous contents of ::cudaExter-
nalSemaphoreSignalParams::params::nvSciSync::fence. By default, signaling such an external
semaphore object causes appropriate memory synchronization operations to be performed over
all the external memory objects that are imported as cudaExternalMemoryHandleTypeNvSciBuf.
This ensures that any subsequent accesses made by other importers of the same set of NvSciBuf
memory object(s) are coherent. These operations can be skipped by specifying the flag cudaEx-
ternalSemaphoreSignalSkipNvSciBufMemSync, which can be used as a performance optimization
when data coherency is not required. But specifying this flag in scenarios where data coherency
is required results in undefined behavior. Also, for semaphore object of the type cudaExter-
nalSemaphoreHandleTypeNvSciSync, if the NvSciSyncAttrList used to create the NvSciSyncObj
had not set the flags in cudaDeviceGetNvSciSyncAttributes to cudaNvSciSyncAttrSignal, this API
will return cudaErrorNotSupported.
::cudaExternalSemaphoreSignalParams::params::nvSciSync::fence associated with semaphore
object of the type cudaExternalSemaphoreHandleTypeNvSciSync can be deterministic. For this
the NvSciSyncAttrList used to create the semaphore object must have value of NvSciSyncAt-
trKey_RequireDeterministicFences key set to true. Deterministic fences allow users to enqueue
a wait over the semaphore object even before corresponding signal is enqueued. For such a
semaphore object, CUDA guarantees that each signal operation will increment the fence value
by ‘1’. Users are expected to track count of signals enqueued on the semaphore object and in-
sert waits accordingly. When such a semaphore object is signaled from multiple streams, due to
concurrent stream execution, it is possible that the order in which the semaphore gets signaled
308
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
is indeterministic. This could lead to waiters of the semaphore getting unblocked incorrectly.
Users are expected to handle such situations, either by not using the same semaphore object
with deterministic fence support enabled in different streams or by adding explicit dependency
amongst such streams so that the semaphore is signaled in order. ::cudaExternalSemaphoreS-
ignalParams::params::nvSciSync::fence associated with semaphore object of the type cudaExter-
nalSemaphoreHandleTypeNvSciSync can be timestamp enabled. For this the NvSciSyncAttrList
used to create the object must have the value of NvSciSyncAttrKey_WaiterRequireTimestamps
key set to true. Timestamps are emitted asynchronously by the GPU and CUDA saves the GPU
timestamp in the corresponding NvSciSyncFence at the time of signal on GPU. Users are ex-
pected to convert GPU clocks to CPU clocks using appropriate scaling functions. Users are ex-
pected to wait for the completion of the fence before extracting timestamp using appropriate
NvSciSync APIs. Users are expected to ensure that there is only one outstanding timestamp
enabled fence per Cuda-NvSciSync object at any point of time, failing which leads to undefined
behavior. Extracting the timestamp before the corresponding fence is signalled could lead to
undefined behaviour. Timestamp extracted via appropriate NvSciSync API would be in microsec-
onds.
If the semaphore object is any one of the following types:
cudaExternalSemaphore-
HandleTypeKeyedMutex,
cudaExternalSemaphoreHandleTypeKeyedMutexKmt,
then
the
keyed mutex will be released with the key specified in ::cudaExternalSemaphoreSignal-
Params::params::keyedmutex::key.
See also:
cudaImportExternalSemaphore, cudaDestroyExternalSemaphore, cudaWaitExternalSemaphore-
sAsync
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ extSemArray - - Set of external semaphores to be signaled
▶ paramsArray - - Array of semaphore parameters
▶ numExtSems - - Number of semaphores to signal
▶ stream - - Stream to enqueue the signal operations in
Returns
cudaSuccess, cudaErrorInvalidResourceHandle
6.19. External Resource Interoperability
309
CUDA Runtime API Reference Manual, Release 13.5
__host__ cudaError_t cudaWaitExternalSemaphoresAsync(const cudaExternalSemaphore_t
*extSemArray, const struct
cudaExternalSemaphoreWaitParams
*paramsArray, unsigned int
numExtSems, cudaStream_t stream =
0)
Waits on a set of external semaphore objects.
Enqueues a wait operation on a set of externally allocated semaphore object in the specified
stream. The operations will be executed when all prior operations in the stream complete.
The exact semantics of waiting on a semaphore depends on the type of the object.
If the semaphore object is any one of the following types: cudaExternalSemaphoreHandle-
TypeOpaqueFd, cudaExternalSemaphoreHandleTypeOpaqueWin32, cudaExternalSemaphoreHan-
dleTypeOpaqueWin32Kmt then waiting on the semaphore will wait until the semaphore reaches
the signaled state. The semaphore will then be reset to the unsignaled state. Therefore for every
signal operation, there can only be one wait operation.
If the semaphore object is any one of the following types: cudaExternalSemaphoreHan-
dleTypeD3D12Fence, cudaExternalSemaphoreHandleTypeD3D11Fence, cudaExternalSemaphore-
HandleTypeTimelineSemaphoreFd, cudaExternalSemaphoreHandleTypeTimelineSemaphoreWin32
then waiting on the semaphore will wait until the value of the semaphore is greater than or equal
to ::cudaExternalSemaphoreWaitParams::params::fence::value.
If the semaphore object is of the type cudaExternalSemaphoreHandleTypeNvSciSync
then, waiting on the semaphore will wait until the
::cudaExternalSemaphoreSignal-
Params::params::nvSciSync::fence is signaled by the signaler of the NvSciSyncObj that was
associated with this semaphore object. By default, waiting on such an external semaphore
object causes appropriate memory synchronization operations to be performed over all external
memory objects that are imported as cudaExternalMemoryHandleTypeNvSciBuf. This ensures
that any subsequent accesses made by other importers of the same set of NvSciBuf memory
object(s) are coherent. These operations can be skipped by specifying the flag cudaExter-
nalSemaphoreWaitSkipNvSciBufMemSync, which can be used as a performance optimization
when data coherency is not required. But specifying this flag in scenarios where data coherency
is required results in undefined behavior. Also, for semaphore object of the type cudaExter-
nalSemaphoreHandleTypeNvSciSync, if the NvSciSyncAttrList used to create the NvSciSyncObj
had not set the flags in cudaDeviceGetNvSciSyncAttributes to cudaNvSciSyncAttrWait, this API
will return cudaErrorNotSupported.
If the semaphore object is any one of the following types: cudaExternalSemaphoreHandle-
TypeKeyedMutex, cudaExternalSemaphoreHandleTypeKeyedMutexKmt, then the keyed mutex
will be acquired when it is released with the key specified in ::cudaExternalSemaphoreSignal-
Params::params::keyedmutex::key or until the timeout specified by ::cudaExternalSemaphoreS-
ignalParams::params::keyedmutex::timeoutMs has lapsed. The timeout interval can either be a
finite value specified in milliseconds or an infinite value. In case an infinite value is specified the
timeout never elapses. The windows INFINITE macro must be used to specify infinite timeout
See also:
cudaImportExternalSemaphore, cudaDestroyExternalSemaphore, cudaSignalExternalSemaphore-
sAsync
Note: Note that this function may also return error codes from previous, asynchronous launches.
310
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ extSemArray - - External semaphores to be waited on
▶ paramsArray - - Array of semaphore parameters
▶ numExtSems - - Number of semaphores to wait on
▶ stream - - Stream to enqueue the wait operations in
Returns
cudaSuccess, cudaErrorInvalidResourceHandle cudaErrorTimeout
6.20. Graph Management
This section describes the graph management functions of CUDA runtime application programming
interface.
Functions
__host__ cudaError_t cudaDeviceGetGraphMemAttribute(int device, enum cudaGraphMemAt-
tributeType attr, void *value)
Query asynchronous allocation attributes related to graphs.
__host__ cudaError_t cudaDeviceGraphMemTrim(int device)
Free unused memory that was cached on the specified device for use with graphs back to the
OS.
__host__ cudaError_t cudaDeviceSetGraphMemAttribute(int device, enum cudaGraphMemAt-
tributeType attr, void *value)
Set asynchronous allocation attributes related to graphs.
__device__ cudaGraphExec_t cudaGetCurrentGraphExec(void)
Get the currently running device graph id.
__host__ cudaError_t cudaGraphAddChildGraphNode(cudaGraphNode_t *pGraphNode, cudaGraph_t
graph, const cudaGraphNode_t *pDependencies, size_t numDependencies, cudaGraph_t child-
Graph)
Creates a child graph node and adds it to a graph.
__host__ cudaError_t cudaGraphAddDependencies(cudaGraph_t graph, const cudaGraphNode_t
*from, const cudaGraphNode_t *to, const cudaGraphEdgeData *edgeData, size_t numDepen-
dencies)
Adds dependency edges to a graph.
6.20. Graph Management
311
CUDA Runtime API Reference Manual, Release 13.5
__host__ cudaError_t cudaGraphAddEmptyNode(cudaGraphNode_t *pGraphNode, cudaGraph_t
graph, const cudaGraphNode_t *pDependencies, size_t numDependencies)
Creates an empty node and adds it to a graph.
__host__ cudaError_t cudaGraphAddEventRecordNode(cudaGraphNode_t *pGraphNode, cuda-
Graph_t graph, const cudaGraphNode_t *pDependencies, size_t numDependencies, cud-
aEvent_t event)
Creates an event record node and adds it to a graph.
__host__ cudaError_t cudaGraphAddEventWaitNode(cudaGraphNode_t *pGraphNode, cudaGraph_t
graph, const cudaGraphNode_t *pDependencies, size_t numDependencies, cudaEvent_t event)
Creates an event wait node and adds it to a graph.
__host__ cudaError_t cudaGraphAddExternalSemaphoresSignalNode(cudaGraphNode_t *pGraphN-
ode, cudaGraph_t graph, const cudaGraphNode_t *pDependencies, size_t numDependencies,
const struct cudaExternalSemaphoreSignalNodeParams *nodeParams)
Creates an external semaphore signal node and adds it to a graph.
__host__ cudaError_t cudaGraphAddExternalSemaphoresWaitNode(cudaGraphNode_t *pGraphN-
ode, cudaGraph_t graph, const cudaGraphNode_t *pDependencies, size_t numDependencies,
const struct cudaExternalSemaphoreWaitNodeParams *nodeParams)
Creates an external semaphore wait node and adds it to a graph.
__host__ cudaError_t cudaGraphAddHostNode(cudaGraphNode_t *pGraphNode, cudaGraph_t
graph, const cudaGraphNode_t *pDependencies, size_t numDependencies, const struct
cudaHostNodeParams *pNodeParams)
Creates a host execution node and adds it to a graph.
__host__ cudaError_t cudaGraphAddKernelNode(cudaGraphNode_t *pGraphNode, cudaGraph_t
graph, const cudaGraphNode_t *pDependencies, size_t numDependencies, const struct cu-
daKernelNodeParams *pNodeParams)
Creates a kernel execution node and adds it to a graph.
__host__ cudaError_t cudaGraphAddMemAllocNode(cudaGraphNode_t *pGraphNode, cudaGraph_t
graph, const cudaGraphNode_t *pDependencies, size_t numDependencies, struct cud-
aMemAllocNodeParams *nodeParams)
Creates an allocation node and adds it to a graph.
__host__ cudaError_t cudaGraphAddMemFreeNode(cudaGraphNode_t *pGraphNode, cudaGraph_t
graph, const cudaGraphNode_t *pDependencies, size_t numDependencies, void *dptr)
Creates a memory free node and adds it to a graph.
__host__ cudaError_t cudaGraphAddMemcpyNode(cudaGraphNode_t *pGraphNode, cudaGraph_t
graph, const cudaGraphNode_t *pDependencies, size_t numDependencies, const struct cu-
daMemcpy3DParms *pCopyParams)
Creates a memcpy node and adds it to a graph.
__host__ cudaError_t cudaGraphAddMemcpyNode1D(cudaGraphNode_t *pGraphNode, cudaGraph_t
graph, const cudaGraphNode_t *pDependencies, size_t numDependencies, void *dst, const
void *src, size_t count, enum cudaMemcpyKind kind)
Creates a 1D memcpy node and adds it to a graph.
__host__ cudaError_t cudaGraphAddMemcpyNodeFromSymbol(cudaGraphNode_t *pGraphNode,
cudaGraph_t graph, const cudaGraphNode_t *pDependencies, size_t numDependencies, void
*dst, const void *symbol, size_t count, size_t offset, enum cudaMemcpyKind kind)
Creates a memcpy node to copy from a symbol on the device and adds it to a graph.
__host__ cudaError_t cudaGraphAddMemcpyNodeToSymbol(cudaGraphNode_t *pGraphNode, cuda-
Graph_t graph, const cudaGraphNode_t *pDependencies, size_t numDependencies, const void
312
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
*symbol, const void *src, size_t count, size_t offset, enum cudaMemcpyKind kind)
Creates a memcpy node to copy to a symbol on the device and adds it to a graph.
__host__ cudaError_t cudaGraphAddMemsetNode(cudaGraphNode_t *pGraphNode, cudaGraph_t
graph, const cudaGraphNode_t *pDependencies, size_t numDependencies, const struct cu-
daMemsetParams *pMemsetParams)
Creates a memset node and adds it to a graph.
__host__ cudaError_t cudaGraphAddNode(cudaGraphNode_t *pGraphNode, cudaGraph_t graph,
const cudaGraphNode_t *pDependencies, const cudaGraphEdgeData *dependencyData, size_t
numDependencies, struct cudaGraphNodeParams *nodeParams)
Adds a node of arbitrary type to a graph.
__host__ cudaError_t cudaGraphChildGraphNodeGetGraph(cudaGraphNode_t node, cudaGraph_t
*pGraph)
Gets a handle to the embedded graph of a child graph node.
__host__ cudaError_t cudaGraphClone(cudaGraph_t *pGraphClone, cudaGraph_t originalGraph)
Clones a graph.
__host__ cudaError_t cudaGraphConditionalHandleCreate(cudaGraphConditionalHandle *pHan-
dle_out, cudaGraph_t graph, unsigned int defaultLaunchValue=0, unsigned int flags=0)
Create a conditional handle.
__host__ cudaError_t cudaGraphConditionalHandleCreate_v2(cudaGraphConditionalHandle *pHan-
dle_out, cudaGraph_t graph, cudaExecutionContext_t ctx=NULL, unsigned int defaultLaunch-
Value=0, unsigned int flags=0)
Create a conditional handle.
__host__ cudaError_t cudaGraphCreate(cudaGraph_t *pGraph, unsigned int flags=0)
Creates a graph.
__host__ cudaError_t cudaGraphDebugDotPrint(cudaGraph_t graph, const char *path, unsigned int
flags)
Write a DOT file describing graph structure.
__host__ cudaError_t cudaGraphDestroy(cudaGraph_t graph)
Destroys a graph.
__host__ cudaError_t cudaGraphDestroyNode(cudaGraphNode_t node)
Remove a node from the graph.
__host__ cudaError_t cudaGraphEventRecordNodeGetEvent(cudaGraphNode_t node, cudaEvent_t
*event_out)
Returns the event associated with an event record node.
__host__ cudaError_t cudaGraphEventRecordNodeSetEvent(cudaGraphNode_t node, cudaEvent_t
event)
Sets an event record node's event.
__host__ cudaError_t cudaGraphEventWaitNodeGetEvent(cudaGraphNode_t node, cudaEvent_t
*event_out)
Returns the event associated with an event wait node.
__host__ cudaError_t cudaGraphEventWaitNodeSetEvent(cudaGraphNode_t node, cudaEvent_t
event)
Sets an event wait node's event.
__host__ cudaError_t cudaGraphExecChildGraphNodeSetParams(cudaGraphExec_t hGraphExec,
cudaGraphNode_t node, cudaGraph_t childGraph)
Updates node parameters in the child graph node in the given graphExec.
6.20. Graph Management
313
CUDA Runtime API Reference Manual, Release 13.5
__host__ cudaError_t cudaGraphExecDestroy(cudaGraphExec_t graphExec)
Destroys an executable graph.
__host__ cudaError_t cudaGraphExecEventRecordNodeSetEvent(cudaGraphExec_t hGraphExec,
cudaGraphNode_t hNode, cudaEvent_t event)
Sets the event for an event record node in the given graphExec.
__host__ cudaError_t cudaGraphExecEventWaitNodeSetEvent(cudaGraphExec_t hGraphExec, cuda-
GraphNode_t hNode, cudaEvent_t event)
Sets the event for an event wait node in the given graphExec.
__host__ cudaError_t cudaGraphExecExternalSemaphoresSignalNodeSetParams(cudaGraphExec_t
hGraphExec, cudaGraphNode_t hNode, const struct cudaExternalSemaphoreSignalNode-
Params *nodeParams)
Sets the parameters for an external semaphore signal node in the given graphExec.
__host__ cudaError_t cudaGraphExecExternalSemaphoresWaitNodeSetParams(cudaGraphExec_t
hGraphExec, cudaGraphNode_t hNode, const struct cudaExternalSemaphoreWaitNode-
Params *nodeParams)
Sets the parameters for an external semaphore wait node in the given graphExec.
__host__ cudaError_t cudaGraphExecGetFlags(cudaGraphExec_t graphExec, unsigned long long
*flags)
Query the instantiation flags of an executable graph.
__host__ cudaError_t cudaGraphExecGetId(cudaGraphExec_t hGraphExec, unsigned int *graphID)
Returns the id of a given graph exec.
__host__ cudaError_t cudaGraphExecHostNodeSetParams(cudaGraphExec_t hGraphExec, cuda-
GraphNode_t node, const struct cudaHostNodeParams *pNodeParams)
Sets the parameters for a host node in the given graphExec.
__host__ cudaError_t cudaGraphExecKernelNodeSetParams(cudaGraphExec_t hGraphExec, cuda-
GraphNode_t node, const struct cudaKernelNodeParams *pNodeParams)
Sets the parameters for a kernel node in the given graphExec.
__host__ cudaError_t cudaGraphExecMemcpyNodeSetParams(cudaGraphExec_t hGraphExec, cuda-
GraphNode_t node, const struct cudaMemcpy3DParms *pNodeParams)
Sets the parameters for a memcpy node in the given graphExec.
__host__ cudaError_t cudaGraphExecMemcpyNodeSetParams1D(cudaGraphExec_t hGraphExec,
cudaGraphNode_t node, void *dst, const void *src, size_t count, enum cudaMemcpyKind kind)
Sets the parameters for a memcpy node in the given graphExec to perform a 1-dimensional
copy.
__host__
cudaError_t
cudaGraphExecMemcpyNodeSetParamsFromSymbol(cudaGraphExec_t
hGraphExec, cudaGraphNode_t node, void *dst, const void *symbol, size_t count, size_t
offset, enum cudaMemcpyKind kind)
Sets the parameters for a memcpy node in the given graphExec to copy from a symbol on the
device.
__host__
cudaError_t
cudaGraphExecMemcpyNodeSetParamsToSymbol(cudaGraphExec_t
hGraphExec, cudaGraphNode_t node, const void *symbol, const void *src, size_t count,
size_t offset, enum cudaMemcpyKind kind)
Sets the parameters for a memcpy node in the given graphExec to copy to a symbol on the
device.
__host__ cudaError_t cudaGraphExecMemsetNodeSetParams(cudaGraphExec_t hGraphExec, cuda-
GraphNode_t node, const struct cudaMemsetParams *pNodeParams)
Sets the parameters for a memset node in the given graphExec.
314
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
__host__ cudaError_t cudaGraphExecNodeSetParams(cudaGraphExec_t graphExec, cudaGraphN-
ode_t node, struct cudaGraphNodeParams *nodeParams)
Update a graph node's parameters in an instantiated graph.
__host__ cudaError_t cudaGraphExecUpdate(cudaGraphExec_t hGraphExec, cudaGraph_t hGraph,
cudaGraphExecUpdateResultInfo *resultInfo)
Check whether an executable graph can be updated with a graph and perform the update if
possible.
__host__ cudaError_t cudaGraphExternalSemaphoresSignalNodeGetParams(cudaGraphNode_t hN-
ode, struct cudaExternalSemaphoreSignalNodeParams *params_out)
Returns an external semaphore signal node's parameters.
__host__ cudaError_t cudaGraphExternalSemaphoresSignalNodeSetParams(cudaGraphNode_t hN-
ode, const struct cudaExternalSemaphoreSignalNodeParams *nodeParams)
Sets an external semaphore signal node's parameters.
__host__ cudaError_t cudaGraphExternalSemaphoresWaitNodeGetParams(cudaGraphNode_t hN-
ode, struct cudaExternalSemaphoreWaitNodeParams *params_out)
Returns an external semaphore wait node's parameters.
__host__ cudaError_t cudaGraphExternalSemaphoresWaitNodeSetParams(cudaGraphNode_t hN-
ode, const struct cudaExternalSemaphoreWaitNodeParams *nodeParams)
Sets an external semaphore wait node's parameters.
__host__ cudaError_t cudaGraphGetEdges(cudaGraph_t graph, cudaGraphNode_t *from, cuda-
GraphNode_t *to, cudaGraphEdgeData *edgeData, size_t *numEdges)
Returns a graph's dependency edges.
__host__ cudaError_t cudaGraphGetId(cudaGraph_t hGraph, unsigned int *graphID)
Returns the id of a given graph.
__host__ cudaError_t cudaGraphGetNodes(cudaGraph_t graph, cudaGraphNode_t *nodes, size_t
*numNodes)
Returns a graph's nodes.
__host__ cudaError_t cudaGraphGetRootNodes(cudaGraph_t graph, cudaGraphNode_t *pRootN-
odes, size_t *pNumRootNodes)
Returns a graph's root nodes.
__host__ cudaError_t cudaGraphHostNodeGetParams(cudaGraphNode_t node, struct cudaHostN-
odeParams *pNodeParams)
Returns a host node's parameters.
__host__ cudaError_t cudaGraphHostNodeSetParams(cudaGraphNode_t node, const struct cuda-
HostNodeParams *pNodeParams)
Sets a host node's parameters.
__host__ cudaError_t cudaGraphInstantiate(cudaGraphExec_t *pGraphExec, cudaGraph_t graph,
unsigned long long flags=0)
Creates an executable graph from a graph.
__host__ cudaError_t cudaGraphInstantiateWithFlags(cudaGraphExec_t *pGraphExec, cudaGraph_t
graph, unsigned long long flags=0)
Creates an executable graph from a graph.
__host__ cudaError_t cudaGraphInstantiateWithParams(cudaGraphExec_t *pGraphExec, cuda-
Graph_t graph, cudaGraphInstantiateParams *instantiateParams)
Creates an executable graph from a graph.
6.20. Graph Management
315
CUDA Runtime API Reference Manual, Release 13.5
__host__ cudaError_t cudaGraphKernelNodeCopyAttributes(cudaGraphNode_t hDst, cudaGraphN-
ode_t hSrc)
Copies attributes from source node to destination node.
__host__ cudaError_t cudaGraphKernelNodeGetAttribute(cudaGraphNode_t hNode, cudaLaunchAt-
tributeID attr, cudaLaunchAttributeValue *value_out)
Queries node attribute.
__host__ cudaError_t cudaGraphKernelNodeGetParams(cudaGraphNode_t node, struct cudaKer-
nelNodeParams *pNodeParams)
Returns a kernel node's parameters.
__host__ cudaError_t cudaGraphKernelNodeSetAttribute(cudaGraphNode_t hNode, cudaLaunchAt-
tributeID attr, const cudaLaunchAttributeValue *value)
Sets node attribute.
__device__ cudaError_t cudaGraphKernelNodeSetEnabled(cudaGraphDeviceNode_t node, bool en-
able)
Enables or disables the given kernel node.
__device__ cudaError_t cudaGraphKernelNodeSetGridDim(cudaGraphDeviceNode_t node, dim3
gridDim)
Updates the grid dimensions of the given kernel node.
__device__ cudaError_t cudaGraphKernelNodeSetParam(cudaGraphDeviceNode_t node, size_t off-
set, const T &value)
Updates the kernel parameters of the given kernel node.
__device__ cudaError_t cudaGraphKernelNodeSetParam(cudaGraphDeviceNode_t node, size_t off-
set, const void *value, size_t size)
Updates the kernel parameters of the given kernel node.
__host__ cudaError_t cudaGraphKernelNodeSetParams(cudaGraphNode_t node, const struct cud-
aKernelNodeParams *pNodeParams)
Sets a kernel node's parameters.
__device__ cudaError_t cudaGraphKernelNodeUpdatesApply(const cudaGraphKernelNodeUpdate
*updates, size_t updateCount)
Batch applies multiple kernel node updates.
__host__ cudaError_t cudaGraphLaunch(cudaGraphExec_t graphExec, cudaStream_t stream)
Launches an executable graph in a stream.
__host__ cudaError_t cudaGraphMemAllocNodeGetParams(cudaGraphNode_t node, struct cud-
aMemAllocNodeParams *params_out)
Returns a memory alloc node's parameters.
__host__ cudaError_t cudaGraphMemFreeNodeGetParams(cudaGraphNode_t node, void *dptr_out)
Returns a memory free node's parameters.
__host__ cudaError_t cudaGraphMemcpyNodeGetParams(cudaGraphNode_t node, struct cud-
aMemcpy3DParms *pNodeParams)
Returns a memcpy node's parameters.
__host__ cudaError_t cudaGraphMemcpyNodeSetParams(cudaGraphNode_t node, const struct cu-
daMemcpy3DParms *pNodeParams)
Sets a memcpy node's parameters.
__host__ cudaError_t cudaGraphMemcpyNodeSetParams1D(cudaGraphNode_t node, void *dst,
const void *src, size_t count, enum cudaMemcpyKind kind)
Sets a memcpy node's parameters to perform a 1-dimensional copy.
316
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
__host__ cudaError_t cudaGraphMemcpyNodeSetParamsFromSymbol(cudaGraphNode_t node, void
*dst, const void *symbol, size_t count, size_t offset, enum cudaMemcpyKind kind)
Sets a memcpy node's parameters to copy from a symbol on the device.
__host__ cudaError_t cudaGraphMemcpyNodeSetParamsToSymbol(cudaGraphNode_t node, const
void *symbol, const void *src, size_t count, size_t offset, enum cudaMemcpyKind kind)
Sets a memcpy node's parameters to copy to a symbol on the device.
__host__ cudaError_t cudaGraphMemsetNodeGetParams(cudaGraphNode_t node, struct cudaMem-
setParams *pNodeParams)
Returns a memset node's parameters.
__host__ cudaError_t cudaGraphMemsetNodeSetParams(cudaGraphNode_t node, const struct cu-
daMemsetParams *pNodeParams)
Sets a memset node's parameters.
__host__ cudaError_t cudaGraphNodeFindInClone(cudaGraphNode_t *pNode, cudaGraphNode_t
originalNode, cudaGraph_t clonedGraph)
Finds a cloned version of a node.
__host__ cudaError_t cudaGraphNodeGetContainingGraph(cudaGraphNode_t hNode, cudaGraph_t
*phGraph)
Returns the graph that contains a given graph node.
__host__ cudaError_t cudaGraphNodeGetDependencies(cudaGraphNode_t node, cudaGraphNode_t
*pDependencies, cudaGraphEdgeData *edgeData, size_t *pNumDependencies)
Returns a node's dependencies.
__host__ cudaError_t cudaGraphNodeGetDependentNodes(cudaGraphNode_t node, cudaGraphN-
ode_t *pDependentNodes, cudaGraphEdgeData *edgeData, size_t *pNumDependentNodes)
Returns a node's dependent nodes.
__host__ cudaError_t cudaGraphNodeGetEnabled(cudaGraphExec_t hGraphExec, cudaGraphNode_t
hNode, unsigned int *isEnabled)
Query whether a node in the given graphExec is enabled.
__host__ cudaError_t cudaGraphNodeGetLocalId(cudaGraphNode_t hNode, unsigned int *nodeId)
Returns the node id of a given graph node.
__host__ cudaError_t cudaGraphNodeGetParams(cudaGraphNode_t node, struct cudaGraphNode-
Params *nodeParams)
Returns a graph node's parameters.
__host__ cudaError_t cudaGraphNodeGetToolsId(cudaGraphNode_t hNode, unsigned long long
*toolsNodeId)
Returns an id used by tools to identify a given node.
__host__ cudaError_t cudaGraphNodeGetType(cudaGraphNode_t node, enum cudaGraphNodeType
*pType)
Returns a node's type.
__host__ cudaError_t cudaGraphNodeSetEnabled(cudaGraphExec_t hGraphExec, cudaGraphNode_t
hNode, unsigned int isEnabled)
Enables or disables the specified node in the given graphExec.
__host__ cudaError_t cudaGraphNodeSetParams(cudaGraphNode_t node, struct cudaGraphNode-
Params *nodeParams)
Update a graph node's parameters.
__host__ cudaError_t cudaGraphReleaseUserObject(cudaGraph_t graph, cudaUserObject_t object,
unsigned int count=1)
6.20. Graph Management
317
CUDA Runtime API Reference Manual, Release 13.5
Release a user object reference from a graph.
__host__ cudaError_t cudaGraphRemoveDependencies(cudaGraph_t graph, const cudaGraphNode_t
*from, const cudaGraphNode_t *to, const cudaGraphEdgeData *edgeData, size_t numDepen-
dencies)
Removes dependency edges from a graph.
__host__ cudaError_t cudaGraphRetainUserObject(cudaGraph_t graph, cudaUserObject_t object,
unsigned int count=1, unsigned int flags=0)
Retain a reference to a user object from a graph.
__device__ void cudaGraphSetConditional(cudaGraphConditionalHandle handle, unsigned int value)
Sets the condition value associated with a conditional node.
__host__ cudaError_t cudaGraphUpload(cudaGraphExec_t graphExec, cudaStream_t stream)
Uploads an executable graph in a stream.
__host__ cudaError_t cudaUserObjectCreate(cudaUserObject_t *object_out, void *ptr, cuda-
HostFn_t destroy, unsigned int initialRefcount, unsigned int flags)
Create a user object.
__host__ cudaError_t cudaUserObjectRelease(cudaUserObject_t object, unsigned int count=1)
Release a reference to a user object.
__host__ cudaError_t cudaUserObjectRetain(cudaUserObject_t object, unsigned int count=1)
Retain a reference to a user object.
6.20.1. Functions
__host__ cudaError_t cudaDeviceGetGraphMemAttribute(int device, enum
cudaGraphMemAttributeType attr, void
*value)
Query asynchronous allocation attributes related to graphs.
Valid attributes are:
▶ cudaGraphMemAttrUsedMemCurrent: Amount of memory, in bytes, currently associated
with graphs
▶ cudaGraphMemAttrUsedMemHigh: High watermark of memory, in bytes, associated with
graphs since the last time it was reset. High watermark can only be reset to zero.
▶ cudaGraphMemAttrReservedMemCurrent: Amount of memory, in bytes, currently allocated
for use by the CUDA graphs asynchronous allocator.
▶ cudaGraphMemAttrReservedMemHigh: High watermark of memory, in bytes, currently allo-
cated for use by the CUDA graphs asynchronous allocator.
See also:
cudaDeviceSetGraphMemAttribute, cudaGraphAddMemAllocNode, cudaGraphAddMemFreeNode,
cudaDeviceGraphMemTrim, cudaMallocAsync, cudaFreeAsync
Note: Graph objects are not threadsafe. More here.
318
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ device - - Specifies the scope of the query
▶ attr - - attribute to get
▶ value - - retrieved value
Returns
cudaSuccess, cudaErrorInvalidDevice
__host__ cudaError_t cudaDeviceGraphMemTrim(int device)
Free unused memory that was cached on the specified device for use with graphs back to the
OS.
Blocks which are not in use by a graph that is either currently executing or scheduled to execute
are freed back to the operating system.
See also:
cudaGraphAddMemAllocNode, cudaGraphAddMemFreeNode, cudaDeviceGetGraphMemAttribute,
cudaDeviceSetGraphMemAttribute, cudaMallocAsync, cudaFreeAsync
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
6.20. Graph Management
319
CUDA Runtime API Reference Manual, Release 13.5
Parameters
device - - The device for which cached memory should be freed.
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaDeviceSetGraphMemAttribute(int device, enum
cudaGraphMemAttributeType attr, void
*value)
Set asynchronous allocation attributes related to graphs.
Valid attributes are:
▶ cudaGraphMemAttrUsedMemHigh: High watermark of memory, in bytes, associated with
graphs since the last time it was reset. High watermark can only be reset to zero.
▶ cudaGraphMemAttrReservedMemHigh: High watermark of memory, in bytes, currently allo-
cated for use by the CUDA graphs asynchronous allocator.
See also:
cudaDeviceGetGraphMemAttribute, cudaGraphAddMemAllocNode, cudaGraphAddMemFreeNode,
cudaDeviceGraphMemTrim, cudaMallocAsync, cudaFreeAsync
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ device - - Specifies the scope of the query
▶ attr - - attribute to get
▶ value - - pointer to value to set
Returns
cudaSuccess, cudaErrorInvalidDevice
320
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
__device__ inline cudaGraphExec_t cudaGetCurrentGraphExec(void)
Get the currently running device graph id.
Get the currently running device graph id.
See also:
cudaGraphLaunch
Returns
Returns the current device graph id, 0 if the call is outside of a device graph.
__host__ cudaError_t cudaGraphAddChildGraphNode(cudaGraphNode_t *pGraphNode,
cudaGraph_t graph, const cudaGraphNode_t
*pDependencies, size_t numDependencies,
cudaGraph_t childGraph)
Creates a child graph node and adds it to a graph.
Creates a new node which executes an embedded graph, and adds it to graph with numDepen-
dencies dependencies specified via pDependencies. It is possible for numDependencies to be
0, in which case the node will be placed at the root of the graph. pDependencies may not have
any duplicate entries. A handle to the new node will be returned in pGraphNode.
If childGraph contains allocation nodes, free nodes, or conditional nodes, this call will return an
error.
The node executes an embedded child graph. The child graph is cloned in this call.
See also:
cudaGraphAddNode, cudaGraphChildGraphNodeGetGraph, cudaGraphCreate, cudaGraphDe-
stroyNode, cudaGraphAddEmptyNode, cudaGraphAddKernelNode, cudaGraphAddHostNode,
cudaGraphAddMemcpyNode, cudaGraphAddMemsetNode, cudaGraphClone
Warning: This function will be deprecated in a future CUDA release. Please migrate to cuda-
GraphAddNode.
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
6.20. Graph Management
321
CUDA Runtime API Reference Manual, Release 13.5
Parameters
▶ pGraphNode - - Returns newly created node
▶ graph - - Graph to which to add the node
▶ pDependencies - - Dependencies of the node
▶ numDependencies - - Number of dependencies
▶ childGraph - - The graph to clone into this node
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphAddDependencies(cudaGraph_t graph, const cudaGraphNode_t
*from, const cudaGraphNode_t *to, const
cudaGraphEdgeData *edgeData, size_t
numDependencies)
Adds dependency edges to a graph.
The number of dependencies to be added is defined by numDependencies Elements in pFrom
and pTo at corresponding indices define a dependency. Each node in pFrom and pTo must belong
to graph.
If numDependencies is 0, elements in pFrom and pTo will be ignored. Specifying an existing
dependency will return an error.
See also:
cudaGraphRemoveDependencies, cudaGraphGetEdges, cudaGraphNodeGetDependencies, cuda-
GraphNodeGetDependentNodes
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ graph - - Graph to which dependencies are added
▶ from - - Array of nodes that provide the dependencies
▶ to - - Array of dependent nodes
322
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
▶ edgeData - - Optional array of edge data. If NULL, default (zeroed) edge data is
assumed.
▶ numDependencies - - Number of dependencies to be added
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphAddEmptyNode(cudaGraphNode_t *pGraphNode, cudaGraph_t
graph, const cudaGraphNode_t *pDependencies,
size_t numDependencies)
Creates an empty node and adds it to a graph.
Creates a new node which performs no operation, and adds it to graph with numDependencies
dependencies specified via pDependencies. It is possible for numDependencies to be 0, in
which case the node will be placed at the root of the graph. pDependencies may not have any
duplicate entries. A handle to the new node will be returned in pGraphNode.
An empty node performs no operation during execution, but can be used for transitive ordering.
For example, a phased execution graph with 2 groups of n nodes with a barrier between them
can be represented using an empty node and 2*n dependency edges, rather than no empty node
and n^2 dependency edges.
See also:
cudaGraphAddNode, cudaGraphCreate, cudaGraphDestroyNode, cudaGraphAddChildGraphNode,
cudaGraphAddKernelNode, cudaGraphAddHostNode, cudaGraphAddMemcpyNode, cudaGraphAd-
dMemsetNode
Warning: This function will be deprecated in a future CUDA release. Please migrate to cuda-
GraphAddNode.
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ pGraphNode - - Returns newly created node
▶ graph - - Graph to which to add the node
▶ pDependencies - - Dependencies of the node
6.20. Graph Management
323
CUDA Runtime API Reference Manual, Release 13.5
▶ numDependencies - - Number of dependencies
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphAddEventRecordNode(cudaGraphNode_t *pGraphNode,
cudaGraph_t graph, const
cudaGraphNode_t *pDependencies, size_t
numDependencies, cudaEvent_t event)
Creates an event record node and adds it to a graph.
Creates a new event record node and adds it to hGraph with numDependencies dependencies
specified via dependencies and event specified in event. It is possible for numDependencies
to be 0, in which case the node will be placed at the root of the graph. dependencies may not
have any duplicate entries. A handle to the new node will be returned in phGraphNode.
Each launch of the graph will record event to capture execution of the node’s dependencies.
These nodes may not be used in loops or conditionals.
See also:
cudaGraphAddNode,
cudaGraphAddEventWaitNode,
cudaEventRecordWithFlags,
cudaS-
treamWaitEvent, cudaGraphCreate, cudaGraphDestroyNode, cudaGraphAddChildGraphNode,
cudaGraphAddEmptyNode,
cudaGraphAddKernelNode,
cudaGraphAddMemcpyNode,
cuda-
GraphAddMemsetNode
Warning: This function will be deprecated in a future CUDA release. Please migrate to cuda-
GraphAddNode.
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ phGraphNode - - Returns newly created node
▶ hGraph - - Graph to which to add the node
324
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
▶ dependencies - - Dependencies of the node
▶ numDependencies - - Number of dependencies
▶ event - - Event for the node
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphAddEventWaitNode(cudaGraphNode_t *pGraphNode, cudaGraph_t
graph, const cudaGraphNode_t
*pDependencies, size_t numDependencies,
cudaEvent_t event)
Creates an event wait node and adds it to a graph.
Creates a new event wait node and adds it to hGraph with numDependencies dependencies
specified via dependencies and event specified in event. It is possible for numDependencies
to be 0, in which case the node will be placed at the root of the graph. dependencies may not
have any duplicate entries. A handle to the new node will be returned in phGraphNode.
The graph node will wait for all work captured in event. See ::cuEventRecord() for details on what
is captured by an event. The synchronization will be performed efficiently on the device when
applicable. event may be from a different context or device than the launch stream.
These nodes may not be used in loops or conditionals.
See also:
cudaGraphAddNode,
cudaGraphAddEventRecordNode,
cudaEventRecordWithFlags,
cudaS-
treamWaitEvent, cudaGraphCreate, cudaGraphDestroyNode, cudaGraphAddChildGraphNode,
cudaGraphAddEmptyNode,
cudaGraphAddKernelNode,
cudaGraphAddMemcpyNode,
cuda-
GraphAddMemsetNode
Warning: This function will be deprecated in a future CUDA release. Please migrate to cuda-
GraphAddNode.
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
6.20. Graph Management
325
CUDA Runtime API Reference Manual, Release 13.5
Parameters
▶ phGraphNode - - Returns newly created node
▶ hGraph - - Graph to which to add the node
▶ dependencies - - Dependencies of the node
▶ numDependencies - - Number of dependencies
▶ event - - Event for the node
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphAddExternalSemaphoresSignalNode(cudaGraphNode_t
*pGraphNode,
cudaGraph_t graph, const
cudaGraphNode_t
*pDependencies, size_t
numDependencies, const
struct
cudaExternalSemaphoreS-
ignalNodeParams
*nodeParams)
Creates an external semaphore signal node and adds it to a graph.
Creates a new external semaphore signal node and adds it to graph with numDependencies de-
pendencies specified via dependencies and arguments specified in nodeParams. It is possible
for numDependencies to be 0, in which case the node will be placed at the root of the graph.
dependencies may not have any duplicate entries. A handle to the new node will be returned in
pGraphNode.
Performs a signal operation on a set of externally allocated semaphore objects when the node is
launched. The operation(s) will occur after all of the node’s dependencies have completed.
See also:
cudaGraphAddNode, cudaGraphExternalSemaphoresSignalNodeGetParams, cudaGraphExter-
nalSemaphoresSignalNodeSetParams,
cudaGraphExecExternalSemaphoresSignalNodeSet-
Params,
cudaGraphAddExternalSemaphoresWaitNode,
cudaImportExternalSemaphore,
cu-
daSignalExternalSemaphoresAsync,
cudaWaitExternalSemaphoresAsync,
cudaGraphCreate,
cudaGraphDestroyNode, cudaGraphAddEventRecordNode, cudaGraphAddEventWaitNode, cuda-
GraphAddChildGraphNode, cudaGraphAddEmptyNode, cudaGraphAddKernelNode, cudaGraphAd-
dMemcpyNode, cudaGraphAddMemsetNode
Warning: This function will be deprecated in a future CUDA release. Please migrate to cuda-
GraphAddNode.
Note: Graph objects are not threadsafe. More here.
326
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ pGraphNode - - Returns newly created node
▶ graph - - Graph to which to add the node
▶ pDependencies - - Dependencies of the node
▶ numDependencies - - Number of dependencies
▶ nodeParams - - Parameters for the node
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphAddExternalSemaphoresWaitNode(cudaGraphNode_t
*pGraphNode, cudaGraph_t
graph, const
cudaGraphNode_t
*pDependencies, size_t
numDependencies, const
struct
cudaExternalSemaphore-
WaitNodeParams
*nodeParams)
Creates an external semaphore wait node and adds it to a graph.
Creates a new external semaphore wait node and adds it to graph with numDependencies de-
pendencies specified via dependencies and arguments specified in nodeParams. It is possible
for numDependencies to be 0, in which case the node will be placed at the root of the graph.
dependencies may not have any duplicate entries. A handle to the new node will be returned in
pGraphNode.
Performs a wait operation on a set of externally allocated semaphore objects when the node is
launched. The node’s dependencies will not be launched until the wait operation has completed.
See also:
cudaGraphAddNode,
cudaGraphExternalSemaphoresWaitNodeGetParams,
cudaGraphExter-
nalSemaphoresWaitNodeSetParams,
cudaGraphExecExternalSemaphoresWaitNodeSetParams,
6.20. Graph Management
327
CUDA Runtime API Reference Manual, Release 13.5
cudaGraphAddExternalSemaphoresSignalNode, cudaImportExternalSemaphore, cudaSignalEx-
ternalSemaphoresAsync, cudaWaitExternalSemaphoresAsync, cudaGraphCreate, cudaGraphDe-
stroyNode, cudaGraphAddEventRecordNode, cudaGraphAddEventWaitNode, cudaGraphAddChild-
GraphNode, cudaGraphAddEmptyNode, cudaGraphAddKernelNode, cudaGraphAddMemcpyNode,
cudaGraphAddMemsetNode
Warning: This function will be deprecated in a future CUDA release. Please migrate to cuda-
GraphAddNode.
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ pGraphNode - - Returns newly created node
▶ graph - - Graph to which to add the node
▶ pDependencies - - Dependencies of the node
▶ numDependencies - - Number of dependencies
▶ nodeParams - - Parameters for the node
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphAddHostNode(cudaGraphNode_t *pGraphNode, cudaGraph_t graph,
const cudaGraphNode_t *pDependencies, size_t
numDependencies, const struct
cudaHostNodeParams *pNodeParams)
Creates a host execution node and adds it to a graph.
Creates a new CPU execution node and adds it to graph with numDependencies dependen-
cies specified via pDependencies and arguments specified in pNodeParams. It is possible for
numDependencies to be 0, in which case the node will be placed at the root of the graph. pDe-
pendencies may not have any duplicate entries. A handle to the new node will be returned in
pGraphNode.
328
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
When the graph is launched, the node will invoke the specified CPU function. Host nodes are not
supported under MPS with pre-Volta GPUs.
See also:
cudaGraphAddNode, cudaLaunchHostFunc, cudaGraphHostNodeGetParams, cudaGraphHostN-
odeSetParams, cudaGraphCreate, cudaGraphDestroyNode, cudaGraphAddChildGraphNode, cud-
aGraphAddEmptyNode, cudaGraphAddKernelNode, cudaGraphAddMemcpyNode, cudaGraphAd-
dMemsetNode
Warning: This function will be deprecated in a future CUDA release. Please migrate to cuda-
GraphAddNode.
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ pGraphNode - - Returns newly created node
▶ graph - - Graph to which to add the node
▶ pDependencies - - Dependencies of the node
▶ numDependencies - - Number of dependencies
▶ pNodeParams - - Parameters for the host node
Returns
cudaSuccess, cudaErrorNotSupported, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphAddKernelNode(cudaGraphNode_t *pGraphNode, cudaGraph_t
graph, const cudaGraphNode_t *pDependencies,
size_t numDependencies, const struct
cudaKernelNodeParams *pNodeParams)
Creates a kernel execution node and adds it to a graph.
6.20. Graph Management
329
CUDA Runtime API Reference Manual, Release 13.5
Creates a new kernel execution node and adds it to graph with numDependencies dependen-
cies specified via pDependencies and arguments specified in pNodeParams. It is possible for
numDependencies to be 0, in which case the node will be placed at the root of the graph. pDe-
pendencies may not have any duplicate entries. A handle to the new node will be returned in
pGraphNode.
The cudaKernelNodeParams structure is defined as:
struct cudaKernelNodeParams
{
void* func;
dim3 gridDim;
dim3 blockDim;
unsigned int sharedMemBytes;
void **kernelParams;
void **extra;
};
When the graph is launched, the node will invoke kernel func on a (gridDim.x x gridDim.y
x gridDim.z) grid of blocks. Each block contains (blockDim.x x blockDim.y x blockDim.z)
threads.
sharedMem sets the amount of dynamic shared memory that will be available to each thread
block.
Kernel parameters to func can be specified in one of two ways:
1) Kernel parameters can be specified via kernelParams. If the kernel has N parameters, then
kernelParams needs to be an array of N pointers. Each pointer, from kernelParams[0] to
kernelParams[N-1], points to the region of memory from which the actual parameter will be
copied. The number of kernel parameters and their offsets and sizes do not need to be specified
as that information is retrieved directly from the kernel’s image.
2) Kernel parameters can also be packaged by the application into a single buffer that is passed
in via extra. This places the burden on the application of knowing each kernel parameter’s size
and alignment/padding within the buffer. The extra parameter exists to allow this function to
take additional less commonly used arguments. extra specifies a list of names of extra settings
and their corresponding values. Each extra setting name is immediately followed by the corre-
sponding value. The list must be terminated with either NULL or CU_LAUNCH_PARAM_END.
▶ ::CU_LAUNCH_PARAM_END, which indicates the end of the extra array;
▶ ::CU_LAUNCH_PARAM_BUFFER_POINTER, which specifies that the next value in extra will
be a pointer to a buffer containing all the kernel parameters for launching kernel func;
▶ ::CU_LAUNCH_PARAM_BUFFER_SIZE, which specifies that the next value in extra
will be a pointer to a size_t containing the size of the buffer specified with
::CU_LAUNCH_PARAM_BUFFER_POINTER;
The error cudaErrorInvalidValue will be returned if kernel parameters are specified with both ker-
nelParams and extra (i.e. both kernelParams and extra are non-NULL).
The kernelParams or extra array, as well as the argument values it points to, are copied during
this call.
330
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
See also:
cudaGraphAddNode, cudaLaunchKernel, cudaGraphKernelNodeGetParams, cudaGraphKernelN-
odeSetParams, cudaGraphCreate, cudaGraphDestroyNode, cudaGraphAddChildGraphNode, cud-
aGraphAddEmptyNode, cudaGraphAddHostNode, cudaGraphAddMemcpyNode, cudaGraphAd-
dMemsetNode
Warning: This function will be deprecated in a future CUDA release. Please migrate to cuda-
GraphAddNode.
Note: Kernels launched using graphs must not use texture and surface references. Reading or
writing through any texture or surface reference is undefined behavior. This restriction does not
apply to texture and surface objects.
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Note: The API can also be used with a kernel cudaKernel_t by querying the handle using cudaLi-
braryGetKernel() or cudaGetKernel and then passing it to the API by casting to void*. The symbol
entryFuncAddr passed to cudaGetKernel should be a symbol that is registered with the same
CUDA Runtime instance.
Note: Passing a symbol that belongs that belongs to a different runtime instance will result in
undefined behavior. The only type that can be reliably passed to a different runtime instance is
cudaKernel_t
Parameters
▶ pGraphNode - - Returns newly created node
▶ graph - - Graph to which to add the node
▶ pDependencies - - Dependencies of the node
▶ numDependencies - - Number of dependencies
6.20. Graph Management
331
CUDA Runtime API Reference Manual, Release 13.5
▶ pNodeParams - - Parameters for the GPU execution node
Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorInvalidDeviceFunction
__host__ cudaError_t cudaGraphAddMemAllocNode(cudaGraphNode_t *pGraphNode, cudaGraph_t
graph, const cudaGraphNode_t
*pDependencies, size_t numDependencies,
struct cudaMemAllocNodeParams
*nodeParams)
Creates an allocation node and adds it to a graph.
Creates a new allocation node and adds it to graph with numDependencies dependencies spec-
ified via pDependencies and arguments specified in nodeParams. It is possible for numDepen-
dencies to be 0, in which case the node will be placed at the root of the graph. pDependencies
may not have any duplicate entries. A handle to the new node will be returned in pGraphNode.
When cudaGraphAddMemAllocNode creates an allocation node, it returns the address of the al-
location in nodeParams.dptr. The allocation’s address remains fixed across instantiations and
launches.
If the allocation is freed in the same graph, by creating a free node using cudaGraphAddMem-
FreeNode, the allocation can be accessed by nodes ordered after the allocation node but before
the free node. These allocations cannot be freed outside the owning graph, and they can only be
freed once in the owning graph.
If the allocation is not freed in the same graph, then it can be accessed not only by nodes in the
graph which are ordered after the allocation node, but also by stream operations ordered after
the graph’s execution but before the allocation is freed.
Allocations which are not freed in the same graph can be freed by:
▶ passing the allocation to ::cudaMemFreeAsync or ::cudaMemFree;
▶ launching a graph with a free node for that allocation; or
▶ specifying cudaGraphInstantiateFlagAutoFreeOnLaunch during instantiation, which makes
each launch behave as though it called ::cudaMemFreeAsync for every unfreed allocation.
It is not possible to free an allocation in both the owning graph and another graph. If the allocation
is freed in the same graph, a free node cannot be added to another graph. If the allocation is freed
in another graph, a free node can no longer be added to the owning graph.
The following restrictions apply to graphs which contain allocation and/or memory free nodes:
▶ Nodes and edges of the graph cannot be deleted.
▶ The graph can only be used in a child node if the ownership is moved to the parent.
▶ Only one instantiation of the graph may exist at any point in time.
▶ The graph cannot be cloned.
See also:
cudaGraphAddNode, cudaGraphAddMemFreeNode, cudaGraphMemAllocNodeGetParams, cu-
daDeviceGraphMemTrim,
cudaDeviceGetGraphMemAttribute,
cudaDeviceSetGraphMemAt-
tribute, cudaMallocAsync, cudaFreeAsync, cudaGraphCreate, cudaGraphDestroyNode, cuda-
332
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
GraphAddChildGraphNode, cudaGraphAddEmptyNode, cudaGraphAddEventRecordNode, cuda-
GraphAddEventWaitNode, cudaGraphAddExternalSemaphoresSignalNode, cudaGraphAddExter-
nalSemaphoresWaitNode, cudaGraphAddKernelNode, cudaGraphAddMemcpyNode, cudaGraphAd-
dMemsetNode
Warning: This function will be deprecated in a future CUDA release. Please migrate to cuda-
GraphAddNode.
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Parameters
▶ pGraphNode - - Returns newly created node
▶ graph - - Graph to which to add the node
▶ pDependencies - - Dependencies of the node
▶ numDependencies - - Number of dependencies
▶ nodeParams - - Parameters for the node
Returns
cudaSuccess, cudaErrorCudartUnloading, cudaErrorInitializationError, cudaEr-
rorNotSupported, cudaErrorInvalidValue, ::cudaErrorOutOfMemory
__host__ cudaError_t cudaGraphAddMemFreeNode(cudaGraphNode_t *pGraphNode, cudaGraph_t
graph, const cudaGraphNode_t *pDependencies,
size_t numDependencies, void *dptr)
Creates a memory free node and adds it to a graph.
Creates a new memory free node and adds it to graph with numDependencies dependencies
specified via pDependencies and address specified in dptr. It is possible for numDependencies
to be 0, in which case the node will be placed at the root of the graph. pDependencies may not
have any duplicate entries. A handle to the new node will be returned in pGraphNode.
cudaGraphAddMemFreeNode will return cudaErrorInvalidValue if the user attempts to free:
▶ an allocation twice in the same graph.
▶ an address that was not returned by an allocation node.
▶ an invalid address.
The following restrictions apply to graphs which contain allocation and/or memory free nodes:
▶ Nodes and edges of the graph cannot be deleted.
▶ The graph can only be used in a child node if the ownership is moved to the parent.
▶ Only one instantiation of the graph may exist at any point in time.
6.20. Graph Management
333
CUDA Runtime API Reference Manual, Release 13.5
▶ The graph cannot be cloned.
See also:
cudaGraphAddNode, cudaGraphAddMemAllocNode, cudaGraphMemFreeNodeGetParams, cu-
daDeviceGraphMemTrim,
cudaDeviceGetGraphMemAttribute,
cudaDeviceSetGraphMemAt-
tribute, cudaMallocAsync, cudaFreeAsync, cudaGraphCreate, cudaGraphDestroyNode, cuda-
GraphAddChildGraphNode, cudaGraphAddEmptyNode, cudaGraphAddEventRecordNode, cuda-
GraphAddEventWaitNode, cudaGraphAddExternalSemaphoresSignalNode, cudaGraphAddExter-
nalSemaphoresWaitNode, cudaGraphAddKernelNode, cudaGraphAddMemcpyNode, cudaGraphAd-
dMemsetNode
Warning: This function will be deprecated in a future CUDA release. Please migrate to cuda-
GraphAddNode.
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Parameters
▶ pGraphNode - - Returns newly created node
▶ graph - - Graph to which to add the node
▶ pDependencies - - Dependencies of the node
▶ numDependencies - - Number of dependencies
▶ dptr - - Address of memory to free
Returns
cudaSuccess, cudaErrorCudartUnloading, cudaErrorInitializationError, cudaEr-
rorNotSupported, cudaErrorInvalidValue, ::cudaErrorOutOfMemory
__host__ cudaError_t cudaGraphAddMemcpyNode(cudaGraphNode_t *pGraphNode, cudaGraph_t
graph, const cudaGraphNode_t *pDependencies,
size_t numDependencies, const struct
cudaMemcpy3DParms *pCopyParams)
Creates a memcpy node and adds it to a graph.
Creates a new memcpy node and adds it to graph with numDependencies dependencies spec-
ified via pDependencies. It is possible for numDependencies to be 0, in which case the node
will be placed at the root of the graph. pDependencies may not have any duplicate entries. A
handle to the new node will be returned in pGraphNode.
When the graph is launched, the node will perform the memcpy described by pCopyParams. See
cudaMemcpy3D() for a description of the structure and its restrictions.
334
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
Memcpy nodes have some additional restrictions with regards to managed memory, if the system
contains at least one device which has a zero value for the device attribute cudaDevAttrConcur-
rentManagedAccess.
See also:
cudaGraphAddNode, cudaMemcpy3D, cudaGraphAddMemcpyNodeToSymbol, cudaGraphAd-
dMemcpyNodeFromSymbol, cudaGraphAddMemcpyNode1D, cudaGraphMemcpyNodeGetParams,
cudaGraphMemcpyNodeSetParams, cudaGraphCreate, cudaGraphDestroyNode, cudaGraphAdd-
ChildGraphNode, cudaGraphAddEmptyNode, cudaGraphAddKernelNode, cudaGraphAddHostNode,
cudaGraphAddMemsetNode
Warning: This function will be deprecated in a future CUDA release. Please migrate to cuda-
GraphAddNode.
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ pGraphNode - - Returns newly created node
▶ graph - - Graph to which to add the node
▶ pDependencies - - Dependencies of the node
▶ numDependencies - - Number of dependencies
▶ pCopyParams - - Parameters for the memory copy
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphAddMemcpyNode1D(cudaGraphNode_t *pGraphNode, cudaGraph_t
graph, const cudaGraphNode_t
*pDependencies, size_t numDependencies,
void *dst, const void *src, size_t count, enum
cudaMemcpyKind kind)
Creates a 1D memcpy node and adds it to a graph.
6.20. Graph Management
335
CUDA Runtime API Reference Manual, Release 13.5
Creates a new 1D memcpy node and adds it to graph with numDependencies dependencies
specified via pDependencies. It is possible for numDependencies to be 0, in which case the
node will be placed at the root of the graph. pDependencies may not have any duplicate entries.
A handle to the new node will be returned in pGraphNode.
When the graph is launched, the node will copy count bytes from the memory area pointed to
by src to the memory area pointed to by dst, where kind specifies the direction of the copy,
and must be one of cudaMemcpyHostToHost, cudaMemcpyHostToDevice, cudaMemcpyDeviceTo-
Host, cudaMemcpyDeviceToDevice, or cudaMemcpyDefault. Passing cudaMemcpyDefault is rec-
ommended, in which case the type of transfer is inferred from the pointer values. However,
cudaMemcpyDefault is only allowed on systems that support unified virtual addressing. Launch-
ing a memcpy node with dst and src pointers that do not match the direction of the copy results
in an undefined behavior.
Memcpy nodes have some additional restrictions with regards to managed memory, if the system
contains at least one device which has a zero value for the device attribute cudaDevAttrConcur-
rentManagedAccess.
See also:
cudaMemcpy, cudaGraphAddMemcpyNode, cudaGraphMemcpyNodeGetParams, cudaGraphMem-
cpyNodeSetParams, cudaGraphMemcpyNodeSetParams1D, cudaGraphCreate, cudaGraphDe-
stroyNode, cudaGraphAddChildGraphNode, cudaGraphAddEmptyNode, cudaGraphAddKernelN-
ode, cudaGraphAddHostNode, cudaGraphAddMemsetNode
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ pGraphNode - - Returns newly created node
▶ graph - - Graph to which to add the node
▶ pDependencies - - Dependencies of the node
▶ numDependencies - - Number of dependencies
▶ dst - - Destination memory address
▶ src - - Source memory address
▶ count - - Size in bytes to copy
336
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
▶ kind - - Type of transfer
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphAddMemcpyNodeFromSymbol(cudaGraphNode_t *pGraphNode,
cudaGraph_t graph, const
cudaGraphNode_t *pDependencies,
size_t numDependencies, void *dst,
const void *symbol, size_t count,
size_t offset, enum
cudaMemcpyKind kind)
Creates a memcpy node to copy from a symbol on the device and adds it to a graph.
Creates a new memcpy node to copy from symbol and adds it to graph with numDependencies
dependencies specified via pDependencies. It is possible for numDependencies to be 0, in
which case the node will be placed at the root of the graph. pDependencies may not have any
duplicate entries. A handle to the new node will be returned in pGraphNode.
When the graph is launched, the node will copy count bytes from the memory area pointed to
by offset bytes from the start of symbol symbol to the memory area pointed to by dst. The
memory areas may not overlap. symbol is a variable that resides in global or constant memory
space. kind can be either cudaMemcpyDeviceToHost, cudaMemcpyDeviceToDevice, or cudaMem-
cpyDefault. Passing cudaMemcpyDefault is recommended, in which case the type of transfer is
inferred from the pointer values. However, cudaMemcpyDefault is only allowed on systems that
support unified virtual addressing.
Memcpy nodes have some additional restrictions with regards to managed memory, if the system
contains at least one device which has a zero value for the device attribute cudaDevAttrConcur-
rentManagedAccess.
See also:
cudaMemcpyFromSymbol, cudaGraphAddMemcpyNode, cudaGraphAddMemcpyNodeToSymbol,
cudaGraphMemcpyNodeGetParams, cudaGraphMemcpyNodeSetParams, cudaGraphMemcpyN-
odeSetParamsFromSymbol, cudaGraphMemcpyNodeSetParamsToSymbol, cudaGraphCreate, cud-
aGraphDestroyNode, cudaGraphAddChildGraphNode, cudaGraphAddEmptyNode, cudaGraphAdd-
KernelNode, cudaGraphAddHostNode, cudaGraphAddMemsetNode
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
6.20. Graph Management
337
CUDA Runtime API Reference Manual, Release 13.5
Parameters
▶ pGraphNode - - Returns newly created node
▶ graph - - Graph to which to add the node
▶ pDependencies - - Dependencies of the node
▶ numDependencies - - Number of dependencies
▶ dst - - Destination memory address
▶ symbol - - Device symbol address
▶ count - - Size in bytes to copy
▶ offset - - Offset from start of symbol in bytes
▶ kind - - Type of transfer
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphAddMemcpyNodeToSymbol(cudaGraphNode_t *pGraphNode,
cudaGraph_t graph, const
cudaGraphNode_t *pDependencies,
size_t numDependencies, const void
*symbol, const void *src, size_t count,
size_t offset, enum cudaMemcpyKind
kind)
Creates a memcpy node to copy to a symbol on the device and adds it to a graph.
Creates a new memcpy node to copy to symbol and adds it to graph with numDependencies
dependencies specified via pDependencies. It is possible for numDependencies to be 0, in
which case the node will be placed at the root of the graph. pDependencies may not have any
duplicate entries. A handle to the new node will be returned in pGraphNode.
When the graph is launched, the node will copy count bytes from the memory area pointed to
by src to the memory area pointed to by offset bytes from the start of symbol symbol. The
memory areas may not overlap. symbol is a variable that resides in global or constant memory
space. kind can be either cudaMemcpyHostToDevice, cudaMemcpyDeviceToDevice, or cudaMem-
cpyDefault. Passing cudaMemcpyDefault is recommended, in which case the type of transfer is
inferred from the pointer values. However, cudaMemcpyDefault is only allowed on systems that
support unified virtual addressing.
Memcpy nodes have some additional restrictions with regards to managed memory, if the system
contains at least one device which has a zero value for the device attribute cudaDevAttrConcur-
rentManagedAccess.
See also:
cudaMemcpyToSymbol, cudaGraphAddMemcpyNode, cudaGraphAddMemcpyNodeFromSymbol,
cudaGraphMemcpyNodeGetParams, cudaGraphMemcpyNodeSetParams, cudaGraphMemcpyN-
odeSetParamsToSymbol, cudaGraphMemcpyNodeSetParamsFromSymbol, cudaGraphCreate, cud-
aGraphDestroyNode, cudaGraphAddChildGraphNode, cudaGraphAddEmptyNode, cudaGraphAdd-
KernelNode, cudaGraphAddHostNode, cudaGraphAddMemsetNode
338
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ pGraphNode - - Returns newly created node
▶ graph - - Graph to which to add the node
▶ pDependencies - - Dependencies of the node
▶ numDependencies - - Number of dependencies
▶ symbol - - Device symbol address
▶ src - - Source memory address
▶ count - - Size in bytes to copy
▶ offset - - Offset from start of symbol in bytes
▶ kind - - Type of transfer
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphAddMemsetNode(cudaGraphNode_t *pGraphNode, cudaGraph_t
graph, const cudaGraphNode_t *pDependencies,
size_t numDependencies, const struct
cudaMemsetParams *pMemsetParams)
Creates a memset node and adds it to a graph.
Creates a new memset node and adds it to graph with numDependencies dependencies spec-
ified via pDependencies. It is possible for numDependencies to be 0, in which case the node
will be placed at the root of the graph. pDependencies may not have any duplicate entries. A
handle to the new node will be returned in pGraphNode.
The element size must be 1, 2, or 4 bytes. When the graph is launched, the node will perform the
memset described by pMemsetParams.
6.20. Graph Management
339
CUDA Runtime API Reference Manual, Release 13.5
See also:
cudaGraphAddNode, cudaMemset2D, cudaGraphMemsetNodeGetParams, cudaGraphMemsetN-
odeSetParams, cudaGraphCreate, cudaGraphDestroyNode, cudaGraphAddChildGraphNode, cuda-
GraphAddEmptyNode, cudaGraphAddKernelNode, cudaGraphAddHostNode, cudaGraphAddMem-
cpyNode
Warning: This function will be deprecated in a future CUDA release. Please migrate to cuda-
GraphAddNode.
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ pGraphNode - - Returns newly created node
▶ graph - - Graph to which to add the node
▶ pDependencies - - Dependencies of the node
▶ numDependencies - - Number of dependencies
▶ pMemsetParams - - Parameters for the memory set
Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorInvalidDevice
__host__ cudaError_t cudaGraphAddNode(cudaGraphNode_t *pGraphNode, cudaGraph_t graph,
const cudaGraphNode_t *pDependencies, const
cudaGraphEdgeData *dependencyData, size_t
numDependencies, struct cudaGraphNodeParams
*nodeParams)
Adds a node of arbitrary type to a graph.
Creates a new node in graph described by nodeParams with numDependencies dependencies
specified via pDependencies. numDependencies may be 0. pDependencies may be null if
numDependencies is 0. pDependencies may not have any duplicate entries.
nodeParams is a tagged union. The node type should be specified in the type field, and type-
specific parameters in the corresponding union member. All unused bytes - that is, reserved0
340
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
and all bytes past the utilized union member - must be set to zero. It is recommended to use
brace initialization or memset to ensure all bytes are initialized.
Note that for some node types, nodeParams may contain “out parameters” which are modified
during the call, such as nodeParams->alloc.dptr.
A handle to the new node will be returned in phGraphNode.
See also:
cudaGraphCreate, cudaGraphNodeSetParams, cudaGraphExecNodeSetParams
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ pGraphNode - - Returns newly created node
▶ graph - - Graph to which to add the node
▶ pDependencies - - Dependencies of the node
▶ dependencyData - - Optional edge data for the dependencies. If NULL, the
data is assumed to be default (zeroed) for all dependencies.
▶ numDependencies - - Number of dependencies
▶ nodeParams - - Specification of the node
Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorInvalidDeviceFunction, cudaErrorNot-
Supported
__host__ cudaError_t cudaGraphChildGraphNodeGetGraph(cudaGraphNode_t node, cudaGraph_t
*pGraph)
Gets a handle to the embedded graph of a child graph node.
Gets a handle to the embedded graph in a child graph node. This call does not clone the graph.
Changes to the graph will be reflected in the node, and the node retains ownership of the graph.
6.20. Graph Management
341
CUDA Runtime API Reference Manual, Release 13.5
Allocation and free nodes cannot be added to the returned graph. Attempting to do so will return
an error.
See also:
cudaGraphAddChildGraphNode, cudaGraphNodeFindInClone
Warning: This function will be deprecated in a future CUDA release. Please migrate to cuda-
GraphNodeGetParams.
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ node - - Node to get the embedded graph for
▶ pGraph - - Location to store a handle to the graph
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphClone(cudaGraph_t *pGraphClone, cudaGraph_t originalGraph)
Clones a graph.
This function creates a copy of originalGraph and returns it in pGraphClone. All parameters
are copied into the cloned graph. The original graph may be modified after this call without
affecting the clone.
Child graph nodes in the original graph are recursively copied into the clone.
See also:
cudaGraphCreate, cudaGraphNodeFindInClone
Note: : Cloning is not supported for graphs which contain memory allocation nodes, memory
free nodes, or conditional nodes.
342
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ pGraphClone - - Returns newly created cloned graph
▶ originalGraph - - Graph to clone
Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorMemoryAllocation
__host__ cudaError_t cudaGraphConditionalHandleCreate(cudaGraphConditionalHandle
*pHandle_out, cudaGraph_t graph,
unsigned int defaultLaunchValue =
0, unsigned int flags = 0)
Create a conditional handle.
Creates a conditional handle associated with hGraph.
The conditional handle must be associated with a conditional node in this graph or one of its
children.
Handles not associated with a conditional node may cause graph instantiation to fail.
See also:
::cuGraphAddNode,
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Parameters
▶ pHandle_out - - Pointer used to return the handle to the caller.
▶ graph - - Graph which will contain the conditional node using this handle.
6.20. Graph Management
343
CUDA Runtime API Reference Manual, Release 13.5
▶ defaultLaunchValue - - Optional initial value for the conditional variable. Ap-
plied at the beginning of each graph execution if cudaGraphCondAssignDefault
is set in flags.
▶ flags - - Currently must be cudaGraphCondAssignDefault or 0.
Returns
::CUDA_SUCCESS, ::CUDA_ERROR_INVALID_VALUE, ::CUDA_ERROR_NOT_SUPPORTED
__host__ cudaError_t cudaGraphConditionalHandleCreate_v2(cudaGraphConditionalHandle
*pHandle_out, cudaGraph_t
graph, cudaExecutionContext_t
ctx = NULL, unsigned int
defaultLaunchValue = 0,
unsigned int flags = 0)
Create a conditional handle.
Creates a conditional handle associated with hGraph.
The conditional handle must be associated with a conditional node in this graph or one of its
children.
Handles not associated with a conditional node may cause graph instantiation to fail.
See also:
::cuGraphAddNode,
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Parameters
▶ pHandle_out - - Pointer used to return the handle to the caller.
▶ graph - - Graph which will contain the conditional node using this handle.
▶ ctx - - Execution context for the handle and associated conditional node. If
NULL, current context will be used.
▶ defaultLaunchValue - - Optional initial value for the conditional variable. Ap-
plied at the beginning of each graph execution if cudaGraphCondAssignDefault
is set in flags.
▶ flags - - Currently must be cudaGraphCondAssignDefault or 0.
Returns
::CUDA_SUCCESS, ::CUDA_ERROR_INVALID_VALUE, ::CUDA_ERROR_NOT_SUPPORTED
__host__ cudaError_t cudaGraphCreate(cudaGraph_t *pGraph, unsigned int flags = 0)
Creates a graph.
Creates an empty graph, which is returned via pGraph.
344
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
See also:
cudaGraphAddChildGraphNode, cudaGraphAddEmptyNode, cudaGraphAddKernelNode, cuda-
GraphAddHostNode, cudaGraphAddMemcpyNode, cudaGraphAddMemsetNode, cudaGraphInstan-
tiate, cudaGraphDestroy, cudaGraphGetNodes, cudaGraphGetRootNodes, cudaGraphGetEdges,
cudaGraphClone
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ pGraph - - Returns newly created graph
▶ flags - - Graph creation flags, must be 0
Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorMemoryAllocation
__host__ cudaError_t cudaGraphDebugDotPrint(cudaGraph_t graph, const char *path, unsigned
int flags)
Write a DOT file describing graph structure.
Using the provided graph, write to path a DOT formatted description of the graph. By default
this includes the graph topology, node types, node id, kernel names and memcpy direction. flags
can be specified to write more detailed information about each node type such as parameter
values, kernel attributes, node and function handles.
Parameters
▶ graph - - The graph to create a DOT file from
▶ path - - The path to write the DOT file to
▶ flags - - Flags from cudaGraphDebugDotFlags for specifying which additional
node information to write
Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorOperatingSystem
6.20. Graph Management
345
CUDA Runtime API Reference Manual, Release 13.5
__host__ cudaError_t cudaGraphDestroy(cudaGraph_t graph)
Destroys a graph.
Destroys the graph specified by graph, as well as all of its nodes.
See also:
cudaGraphCreate
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Note: Use of the handle after this call is undefined behavior.
Parameters
graph - - Graph to destroy
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphDestroyNode(cudaGraphNode_t node)
Remove a node from the graph.
Removes node from its graph. This operation also severs any dependencies of other nodes on
node and vice versa.
Dependencies cannot be removed from graphs which contain allocation or free nodes. Any at-
tempt to do so will return an error.
See also:
cudaGraphAddChildGraphNode, cudaGraphAddEmptyNode, cudaGraphAddKernelNode, cuda-
GraphAddHostNode, cudaGraphAddMemcpyNode, cudaGraphAddMemsetNode
Note: Graph objects are not threadsafe. More here.
346
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Note: Use of the handle after this call is undefined behavior.
Parameters
node - - Node to remove
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphEventRecordNodeGetEvent(cudaGraphNode_t node, cudaEvent_t
*event_out)
Returns the event associated with an event record node.
Returns the event of event record node hNode in event_out.
See also:
cudaGraphAddEventRecordNode, cudaGraphEventRecordNodeSetEvent, cudaGraphEventWaitN-
odeGetEvent, cudaEventRecordWithFlags, cudaStreamWaitEvent
Warning: This function will be deprecated in a future CUDA release. Please migrate to cuda-
GraphNodeGetParams.
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
6.20. Graph Management
347
CUDA Runtime API Reference Manual, Release 13.5
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ hNode - - Node to get the event for
▶ event_out - - Pointer to return the event
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphEventRecordNodeSetEvent(cudaGraphNode_t node, cudaEvent_t
event)
Sets an event record node’s event.
Sets the event of event record node hNode to event.
See also:
cudaGraphNodeSetParams,
cudaGraphAddEventRecordNode,
cudaGraphEven-
tRecordNodeGetEvent, cudaGraphEventWaitNodeSetEvent, cudaEventRecordWithFlags, cud-
aStreamWaitEvent
Warning: This function will be deprecated in a future CUDA release. Please migrate to cuda-
GraphNodeSetParams.
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ hNode - - Node to set the event for
348
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
▶ event - - Event to use
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphEventWaitNodeGetEvent(cudaGraphNode_t node, cudaEvent_t
*event_out)
Returns the event associated with an event wait node.
Returns the event of event wait node hNode in event_out.
See also:
cudaGraphAddEventWaitNode,
cudaGraphEventWaitNodeSetEvent,
cudaGraphEven-
tRecordNodeGetEvent, cudaEventRecordWithFlags, cudaStreamWaitEvent
Warning: This function will be deprecated in a future CUDA release. Please migrate to cuda-
GraphNodeGetParams.
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ hNode - - Node to get the event for
▶ event_out - - Pointer to return the event
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphEventWaitNodeSetEvent(cudaGraphNode_t node, cudaEvent_t
event)
Sets an event wait node’s event.
Sets the event of event wait node hNode to event.
6.20. Graph Management
349
CUDA Runtime API Reference Manual, Release 13.5
See also:
cudaGraphNodeSetParams, cudaGraphAddEventWaitNode, cudaGraphEventWaitNodeGetEvent,
cudaGraphEventRecordNodeSetEvent, cudaEventRecordWithFlags, cudaStreamWaitEvent
Warning: This function will be deprecated in a future CUDA release. Please migrate to cuda-
GraphNodeSetParams.
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ hNode - - Node to set the event for
▶ event - - Event to use
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphExecChildGraphNodeSetParams(cudaGraphExec_t hGraphExec,
cudaGraphNode_t node,
cudaGraph_t childGraph)
Updates node parameters in the child graph node in the given graphExec.
Updates the work represented by node in hGraphExec as though the nodes contained in node's
graph had the parameters contained in childGraph's nodes at instantiation. node must remain
in the graph which was used to instantiate hGraphExec. Changed edges to and from node are
ignored.
The modifications only affect future launches of hGraphExec. Already enqueued or running
launches of hGraphExec are not affected by this call. node is also not modified by this call.
The topology of childGraph, as well as the node insertion order, must match that of the graph
contained in node. See cudaGraphExecUpdate() for a list of restrictions on what can be updated
in an instantiated graph. The update is recursive, so child graph nodes contained within the top
level child graph will also be updated.
350
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
See also:
cudaGraphExecNodeSetParams, cudaGraphAddChildGraphNode, cudaGraphChildGraphNodeGet-
Graph, cudaGraphExecKernelNodeSetParams, cudaGraphExecMemcpyNodeSetParams, cud-
aGraphExecMemsetNodeSetParams,
cudaGraphExecHostNodeSetParams,
cudaGraphExe-
cEventRecordNodeSetEvent,
cudaGraphExecEventWaitNodeSetEvent,
cudaGraphExecExter-
nalSemaphoresSignalNodeSetParams, cudaGraphExecExternalSemaphoresWaitNodeSetParams,
cudaGraphExecUpdate, cudaGraphInstantiate
Warning: This function will be deprecated in a future CUDA release. Please migrate to cuda-
GraphExecNodeSetParams.
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ hGraphExec - - The executable graph in which to set the specified node
▶ node - - Host node from the graph which was used to instantiate graphExec
▶ childGraph - - The graph supplying the updated parameters
Returns
cudaSuccess, cudaErrorInvalidValue,
__host__ cudaError_t cudaGraphExecDestroy(cudaGraphExec_t graphExec)
Destroys an executable graph.
Destroys the executable graph specified by graphExec.
See also:
cudaGraphInstantiate, cudaGraphUpload, cudaGraphLaunch
Note: Graph objects are not threadsafe. More here.
6.20. Graph Management
351
CUDA Runtime API Reference Manual, Release 13.5
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Note: Use of the handle after this call is undefined behavior.
Parameters
graphExec - - Executable graph to destroy
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphExecEventRecordNodeSetEvent(cudaGraphExec_t hGraphExec,
cudaGraphNode_t hNode,
cudaEvent_t event)
Sets the event for an event record node in the given graphExec.
Sets the event of an event record node in an executable graph hGraphExec. The node is identi-
fied by the corresponding node hNode in the non-executable graph, from which the executable
graph was instantiated.
The modifications only affect future launches of hGraphExec. Already enqueued or running
launches of hGraphExec are not affected by this call. hNode is also not modified by this call.
See also:
cudaGraphExecNodeSetParams,
cudaGraphAddEventRecordNode,
cudaGraphEven-
tRecordNodeGetEvent, cudaGraphEventWaitNodeSetEvent, cudaEventRecordWithFlags, cudaS-
treamWaitEvent, cudaGraphExecKernelNodeSetParams, cudaGraphExecMemcpyNodeSetParams,
cudaGraphExecMemsetNodeSetParams,
cudaGraphExecHostNodeSetParams,
cudaGraphEx-
ecChildGraphNodeSetParams, cudaGraphExecEventWaitNodeSetEvent, cudaGraphExecExter-
nalSemaphoresSignalNodeSetParams, cudaGraphExecExternalSemaphoresWaitNodeSetParams,
cudaGraphExecUpdate, cudaGraphInstantiate
Warning: This function will be deprecated in a future CUDA release. Please migrate to cuda-
GraphExecNodeSetParams.
Note: Graph objects are not threadsafe. More here.
352
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ hGraphExec - - The executable graph in which to set the specified node
▶ hNode - - Event record node from the graph from which graphExec was instan-
tiated
▶ event - - Updated event to use
Returns
cudaSuccess, cudaErrorInvalidValue,
__host__ cudaError_t cudaGraphExecEventWaitNodeSetEvent(cudaGraphExec_t hGraphExec,
cudaGraphNode_t hNode,
cudaEvent_t event)
Sets the event for an event wait node in the given graphExec.
Sets the event of an event wait node in an executable graph hGraphExec. The node is identified
by the corresponding node hNode in the non-executable graph, from which the executable graph
was instantiated.
The modifications only affect future launches of hGraphExec. Already enqueued or running
launches of hGraphExec are not affected by this call. hNode is also not modified by this call.
See also:
cudaGraphExecNodeSetParams,
cudaGraphAddEventWaitNode,
cudaGraphEventWaitN-
odeGetEvent,
cudaGraphEventRecordNodeSetEvent,
cudaEventRecordWithFlags,
cudaS-
treamWaitEvent, cudaGraphExecKernelNodeSetParams, cudaGraphExecMemcpyNodeSetParams,
cudaGraphExecMemsetNodeSetParams, cudaGraphExecHostNodeSetParams, cudaGraphExec-
ChildGraphNodeSetParams, cudaGraphExecEventRecordNodeSetEvent, cudaGraphExecExter-
nalSemaphoresSignalNodeSetParams, cudaGraphExecExternalSemaphoresWaitNodeSetParams,
cudaGraphExecUpdate, cudaGraphInstantiate
Warning: This function will be deprecated in a future CUDA release. Please migrate to cuda-
GraphExecNodeSetParams.
6.20. Graph Management
353
CUDA Runtime API Reference Manual, Release 13.5
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ hGraphExec - - The executable graph in which to set the specified node
▶ hNode - - Event wait node from the graph from which graphExec was instanti-
ated
▶ event - - Updated event to use
Returns
cudaSuccess, cudaErrorInvalidValue,
__host__ cudaError_t cudaGraphExecExternalSemaphoresSignalNodeSetParams(cudaGraphExec_t
hGraphExec,
cudaGraphN-
ode_t hNode,
const struct
cudaExter-
nalSemaphoreS-
ignalNode-
Params
*node-
Params)
Sets the parameters for an external semaphore signal node in the given graphExec.
Sets the parameters of an external semaphore signal node in an executable graph hGraphExec.
The node is identified by the corresponding node hNode in the non-executable graph, from which
the executable graph was instantiated.
hNode must not have been removed from the original graph.
The modifications only affect future launches of hGraphExec. Already enqueued or running
launches of hGraphExec are not affected by this call. hNode is also not modified by this call.
Changing nodeParams->numExtSems is not supported.
354
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
See also:
cudaGraphExecNodeSetParams, cudaGraphAddExternalSemaphoresSignalNode, cudaImportEx-
ternalSemaphore, cudaSignalExternalSemaphoresAsync, cudaWaitExternalSemaphoresAsync,
cudaGraphExecKernelNodeSetParams, cudaGraphExecMemcpyNodeSetParams, cudaGraphEx-
ecMemsetNodeSetParams, cudaGraphExecHostNodeSetParams, cudaGraphExecChildGraphN-
odeSetParams,
cudaGraphExecEventRecordNodeSetEvent,
cudaGraphExecEventWaitNode-
SetEvent,
cudaGraphExecExternalSemaphoresWaitNodeSetParams,
cudaGraphExecUpdate,
cudaGraphInstantiate
Warning: This function will be deprecated in a future CUDA release. Please migrate to cuda-
GraphExecNodeSetParams.
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ hGraphExec - - The executable graph in which to set the specified node
▶ hNode - - semaphore signal node from the graph from which graphExec was
instantiated
▶ nodeParams - - Updated Parameters to set
Returns
cudaSuccess, cudaErrorInvalidValue,
__host__ cudaError_t cudaGraphExecExternalSemaphoresWaitNodeSetParams(cudaGraphExec_t
hGraphExec,
cudaGraphN-
ode_t hNode,
const struct
cudaExter-
nalSemaphore-
WaitNode-
Params
*nodeParams)
Sets the parameters for an external semaphore wait node in the given graphExec.
6.20. Graph Management
355
CUDA Runtime API Reference Manual, Release 13.5
Sets the parameters of an external semaphore wait node in an executable graph hGraphExec.
The node is identified by the corresponding node hNode in the non-executable graph, from which
the executable graph was instantiated.
hNode must not have been removed from the original graph.
The modifications only affect future launches of hGraphExec. Already enqueued or running
launches of hGraphExec are not affected by this call. hNode is also not modified by this call.
Changing nodeParams->numExtSems is not supported.
See also:
cudaGraphExecNodeSetParams, cudaGraphAddExternalSemaphoresWaitNode, cudaImportEx-
ternalSemaphore, cudaSignalExternalSemaphoresAsync, cudaWaitExternalSemaphoresAsync,
cudaGraphExecKernelNodeSetParams, cudaGraphExecMemcpyNodeSetParams, cudaGraphEx-
ecMemsetNodeSetParams, cudaGraphExecHostNodeSetParams, cudaGraphExecChildGraphN-
odeSetParams,
cudaGraphExecEventRecordNodeSetEvent,
cudaGraphExecEventWaitNode-
SetEvent,
cudaGraphExecExternalSemaphoresSignalNodeSetParams,
cudaGraphExecUpdate,
cudaGraphInstantiate
Warning: This function will be deprecated in a future CUDA release. Please migrate to cuda-
GraphExecNodeSetParams.
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ hGraphExec - - The executable graph in which to set the specified node
▶ hNode - - semaphore wait node from the graph from which graphExec was in-
stantiated
▶ nodeParams - - Updated Parameters to set
Returns
cudaSuccess, cudaErrorInvalidValue,
356
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
__host__ cudaError_t cudaGraphExecGetFlags(cudaGraphExec_t graphExec, unsigned long long
*flags)
Query the instantiation flags of an executable graph.
Returns the flags that were passed to instantiation for the given executable graph. cudaGraphIn-
stantiateFlagUpload will not be returned by this API as it does not affect the resulting executable
graph.
See also:
cudaGraphInstantiate, cudaGraphInstantiateWithFlags, cudaGraphInstantiateWithParams
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ graphExec - - The executable graph to query
▶ flags - - Returns the instantiation flags
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphExecGetId(cudaGraphExec_t hGraphExec, unsigned int *graphID)
Returns the id of a given graph exec.
Returns the id of hGraphExec in *graphId. The value in *graphId matches that referenced by
cudaGraphDebugDotPrint.
See also:
cudaGraphGetNodes,
cudaGraphDebugDotPrint cudaGraphNodeGetContainingGraph cuda-
GraphNodeGetLocalId cudaGraphNodeGetToolsId cudaGraphGetId
Parameters
▶ hGraphExec - - Graph to query
▶ graphId - - Pointer to return the graphId
6.20. Graph Management
357
CUDA Runtime API Reference Manual, Release 13.5
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphExecHostNodeSetParams(cudaGraphExec_t hGraphExec,
cudaGraphNode_t node, const struct
cudaHostNodeParams *pNodeParams)
Sets the parameters for a host node in the given graphExec.
Updates the work represented by node in hGraphExec as though node had contained pN-
odeParams at instantiation. node must remain in the graph which was used to instantiate
hGraphExec. Changed edges to and from node are ignored.
The modifications only affect future launches of hGraphExec. Already enqueued or running
launches of hGraphExec are not affected by this call. node is also not modified by this call.
See also:
cudaGraphExecNodeSetParams,
cudaGraphAddHostNode,
cudaGraphHostNodeSetParams,
cudaGraphExecKernelNodeSetParams, cudaGraphExecMemcpyNodeSetParams, cudaGraphEx-
ecMemsetNodeSetParams,
cudaGraphExecChildGraphNodeSetParams,
cudaGraphExe-
cEventRecordNodeSetEvent,
cudaGraphExecEventWaitNodeSetEvent,
cudaGraphExecExter-
nalSemaphoresSignalNodeSetParams, cudaGraphExecExternalSemaphoresWaitNodeSetParams,
cudaGraphExecUpdate, cudaGraphInstantiate
Warning: This function will be deprecated in a future CUDA release. Please migrate to cuda-
GraphExecNodeSetParams.
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ hGraphExec - - The executable graph in which to set the specified node
▶ node - - Host node from the graph which was used to instantiate graphExec
▶ pNodeParams - - Updated Parameters to set
358
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
Returns
cudaSuccess, cudaErrorInvalidValue,
__host__ cudaError_t cudaGraphExecKernelNodeSetParams(cudaGraphExec_t hGraphExec,
cudaGraphNode_t node, const struct
cudaKernelNodeParams
*pNodeParams)
Sets the parameters for a kernel node in the given graphExec.
Sets the parameters of a kernel node in an executable graph hGraphExec. The node is identified
by the corresponding node node in the non-executable graph, from which the executable graph
was instantiated.
node must not have been removed from the original graph. All nodeParams fields may change,
but the following restrictions apply to func updates:
▶ The owning device of the function cannot change.
▶ A node whose function originally did not use CUDA dynamic parallelism cannot be updated
to a function which uses CDP
▶ A node whose function originally did not make device-side update calls cannot be updated
to a function which makes device-side update calls.
▶ If hGraphExec was not instantiated for device launch, a node whose function originally did
not use device-side cudaGraphLaunch() cannot be updated to a function which uses device-
side cudaGraphLaunch() unless the node resides on the same device as nodes which con-
tained such calls at instantiate-time. If no such calls were present at instantiation, these
updates cannot be performed at all.
The modifications only affect future launches of hGraphExec. Already enqueued or running
launches of hGraphExec are not affected by this call. node is also not modified by this call.
If node is a device-updatable kernel node, the next upload/launch of hGraphExec will overwrite
any previous device-side updates. Additionally, applying host updates to a device-updatable ker-
nel node while it is being updated from the device will result in undefined behavior.
See also:
cudaGraphExecNodeSetParams, cudaGraphAddKernelNode, cudaGraphKernelNodeSetParams,
cudaGraphExecMemcpyNodeSetParams,
cudaGraphExecMemsetNodeSetParams,
cuda-
GraphExecHostNodeSetParams,
cudaGraphExecChildGraphNodeSetParams,
cudaGraphExe-
cEventRecordNodeSetEvent,
cudaGraphExecEventWaitNodeSetEvent,
cudaGraphExecExter-
nalSemaphoresSignalNodeSetParams, cudaGraphExecExternalSemaphoresWaitNodeSetParams,
cudaGraphExecUpdate, cudaGraphInstantiate
Warning: This function will be deprecated in a future CUDA release. Please migrate to cuda-
GraphExecNodeSetParams.
Note: Graph objects are not threadsafe. More here.
6.20. Graph Management
359
CUDA Runtime API Reference Manual, Release 13.5
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Note: The API can also be used with a kernel cudaKernel_t by querying the handle using cudaLi-
braryGetKernel() or cudaGetKernel and then passing it to the API by casting to void*. The symbol
entryFuncAddr passed to cudaGetKernel should be a symbol that is registered with the same
CUDA Runtime instance.
Note: Passing a symbol that belongs that belongs to a different runtime instance will result in
undefined behavior. The only type that can be reliably passed to a different runtime instance is
cudaKernel_t
Parameters
▶ hGraphExec - - The executable graph in which to set the specified node
▶ node - - kernel node from the graph from which graphExec was instantiated
▶ pNodeParams - - Updated Parameters to set
Returns
cudaSuccess, cudaErrorInvalidValue,
__host__ cudaError_t cudaGraphExecMemcpyNodeSetParams(cudaGraphExec_t hGraphExec,
cudaGraphNode_t node, const struct
cudaMemcpy3DParms
*pNodeParams)
Sets the parameters for a memcpy node in the given graphExec.
Updates the work represented by node in hGraphExec as though node had contained pN-
odeParams at instantiation. node must remain in the graph which was used to instantiate
hGraphExec. Changed edges to and from node are ignored.
The source and destination memory in pNodeParams must be allocated from the same contexts
as the original source and destination memory. Both the instantiation-time memory operands
and the memory operands in pNodeParams must be 1-dimensional. Zero-length operations are
not supported.
The modifications only affect future launches of hGraphExec. Already enqueued or running
launches of hGraphExec are not affected by this call. node is also not modified by this call.
360
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
Returns cudaErrorInvalidValue if the memory operands’ mappings changed or either the original
or new memory operands are multidimensional.
See also:
cudaGraphExecNodeSetParams,
cudaGraphAddMemcpyNode,
cudaGraphMemcpyNodeSet-
Params,
cudaGraphExecMemcpyNodeSetParamsToSymbol,
cudaGraphExecMemcpyNodeSet-
ParamsFromSymbol,
cudaGraphExecMemcpyNodeSetParams1D, cudaGraphExecKernelNode-
SetParams,
cudaGraphExecMemsetNodeSetParams,
cudaGraphExecHostNodeSetParams,
cudaGraphExecChildGraphNodeSetParams,
cudaGraphExecEventRecordNodeSetEvent,
cuda-
GraphExecEventWaitNodeSetEvent,
cudaGraphExecExternalSemaphoresSignalNodeSetParams,
cudaGraphExecExternalSemaphoresWaitNodeSetParams, cudaGraphExecUpdate, cudaGraphIn-
stantiate
Warning: This function will be deprecated in a future CUDA release. Please migrate to cuda-
GraphExecNodeSetParams.
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ hGraphExec - - The executable graph in which to set the specified node
▶ node - - Memcpy node from the graph which was used to instantiate graphExec
▶ pNodeParams - - Updated Parameters to set
Returns
cudaSuccess, cudaErrorInvalidValue,
__host__ cudaError_t cudaGraphExecMemcpyNodeSetParams1D(cudaGraphExec_t hGraphExec,
cudaGraphNode_t node, void *dst,
const void *src, size_t count,
enum cudaMemcpyKind kind)
Sets the parameters for a memcpy node in the given graphExec to perform a 1-dimensional copy.
6.20. Graph Management
361
CUDA Runtime API Reference Manual, Release 13.5
Updates the work represented by node in hGraphExec as though node had contained the
given params at instantiation. node must remain in the graph which was used to instantiate
hGraphExec. Changed edges to and from node are ignored.
src and dst must be allocated from the same contexts as the original source and destination
memory. The instantiation-time memory operands must be 1-dimensional. Zero-length opera-
tions are not supported.
The modifications only affect future launches of hGraphExec. Already enqueued or running
launches of hGraphExec are not affected by this call. node is also not modified by this call.
Returns cudaErrorInvalidValue if the memory operands’ mappings changed or the original mem-
ory operands are multidimensional.
See also:
cudaGraphAddMemcpyNode,
cudaGraphAddMemcpyNode1D,
cudaGraphMemcpyNodeSet-
Params,
cudaGraphMemcpyNodeSetParams1D,
cudaGraphExecMemcpyNodeSetParams,
cudaGraphExecKernelNodeSetParams,
cudaGraphExecMemsetNodeSetParams,
cuda-
GraphExecHostNodeSetParams,
cudaGraphExecChildGraphNodeSetParams,
cudaGraphExe-
cEventRecordNodeSetEvent,
cudaGraphExecEventWaitNodeSetEvent,
cudaGraphExecExter-
nalSemaphoresSignalNodeSetParams, cudaGraphExecExternalSemaphoresWaitNodeSetParams,
cudaGraphExecUpdate, cudaGraphInstantiate
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ hGraphExec - - The executable graph in which to set the specified node
▶ node - - Memcpy node from the graph which was used to instantiate graphExec
▶ dst - - Destination memory address
▶ src - - Source memory address
▶ count - - Size in bytes to copy
▶ kind - - Type of transfer
Returns
cudaSuccess, cudaErrorInvalidValue
362
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
__host__ cudaError_t cudaGraphExecMemcpyNodeSetParamsFromSymbol(cudaGraphExec_t
hGraphExec,
cudaGraphNode_t node,
void *dst, const void
*symbol, size_t count,
size_t offset, enum
cudaMemcpyKind kind)
Sets the parameters for a memcpy node in the given graphExec to copy from a symbol on the
device.
Updates the work represented by node in hGraphExec as though node had contained the
given params at instantiation. node must remain in the graph which was used to instantiate
hGraphExec. Changed edges to and from node are ignored.
symbol and dst must be allocated from the same contexts as the original source and desti-
nation memory. The instantiation-time memory operands must be 1-dimensional. Zero-length
operations are not supported.
The modifications only affect future launches of hGraphExec. Already enqueued or running
launches of hGraphExec are not affected by this call. node is also not modified by this call.
Returns cudaErrorInvalidValue if the memory operands’ mappings changed or the original mem-
ory operands are multidimensional.
See also:
cudaGraphAddMemcpyNode, cudaGraphAddMemcpyNodeFromSymbol, cudaGraphMemcpyN-
odeSetParams,
cudaGraphMemcpyNodeSetParamsFromSymbol,
cudaGraphExecMemcpyN-
odeSetParams,
cudaGraphExecMemcpyNodeSetParamsToSymbol,
cudaGraphExecKernelN-
odeSetParams, cudaGraphExecMemsetNodeSetParams, cudaGraphExecHostNodeSetParams,
cudaGraphExecChildGraphNodeSetParams,
cudaGraphExecEventRecordNodeSetEvent,
cuda-
GraphExecEventWaitNodeSetEvent,
cudaGraphExecExternalSemaphoresSignalNodeSetParams,
cudaGraphExecExternalSemaphoresWaitNodeSetParams, cudaGraphExecUpdate, cudaGraphIn-
stantiate
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ hGraphExec - - The executable graph in which to set the specified node
6.20. Graph Management
363
CUDA Runtime API Reference Manual, Release 13.5
▶ node - - Memcpy node from the graph which was used to instantiate graphExec
▶ dst - - Destination memory address
▶ symbol - - Device symbol address
▶ count - - Size in bytes to copy
▶ offset - - Offset from start of symbol in bytes
▶ kind - - Type of transfer
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphExecMemcpyNodeSetParamsToSymbol(cudaGraphExec_t
hGraphExec,
cudaGraphNode_t node,
const void *symbol, const
void *src, size_t count,
size_t offset, enum
cudaMemcpyKind kind)
Sets the parameters for a memcpy node in the given graphExec to copy to a symbol on the device.
Updates the work represented by node in hGraphExec as though node had contained the
given params at instantiation. node must remain in the graph which was used to instantiate
hGraphExec. Changed edges to and from node are ignored.
src and symbol must be allocated from the same contexts as the original source and desti-
nation memory. The instantiation-time memory operands must be 1-dimensional. Zero-length
operations are not supported.
The modifications only affect future launches of hGraphExec. Already enqueued or running
launches of hGraphExec are not affected by this call. node is also not modified by this call.
Returns cudaErrorInvalidValue if the memory operands’ mappings changed or the original mem-
ory operands are multidimensional.
See also:
cudaGraphAddMemcpyNode, cudaGraphAddMemcpyNodeToSymbol, cudaGraphMemcpyNodeSet-
Params, cudaGraphMemcpyNodeSetParamsToSymbol, cudaGraphExecMemcpyNodeSetParams,
cudaGraphExecMemcpyNodeSetParamsFromSymbol, cudaGraphExecKernelNodeSetParams, cud-
aGraphExecMemsetNodeSetParams, cudaGraphExecHostNodeSetParams, cudaGraphExecChild-
GraphNodeSetParams, cudaGraphExecEventRecordNodeSetEvent, cudaGraphExecEventWaitN-
odeSetEvent, cudaGraphExecExternalSemaphoresSignalNodeSetParams, cudaGraphExecExter-
nalSemaphoresWaitNodeSetParams, cudaGraphExecUpdate, cudaGraphInstantiate
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
364
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ hGraphExec - - The executable graph in which to set the specified node
▶ node - - Memcpy node from the graph which was used to instantiate graphExec
▶ symbol - - Device symbol address
▶ src - - Source memory address
▶ count - - Size in bytes to copy
▶ offset - - Offset from start of symbol in bytes
▶ kind - - Type of transfer
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphExecMemsetNodeSetParams(cudaGraphExec_t hGraphExec,
cudaGraphNode_t node, const struct
cudaMemsetParams *pNodeParams)
Sets the parameters for a memset node in the given graphExec.
Updates the work represented by node in hGraphExec as though node had contained pN-
odeParams at instantiation. node must remain in the graph which was used to instantiate
hGraphExec. Changed edges to and from node are ignored.
Zero sized operations are not supported.
The new destination pointer in pNodeParams must be to the same kind of allocation as the origi-
nal destination pointer and have the same context association and device mapping as the original
destination pointer.
Both the value and pointer address may be updated.
Changing other aspects of the memset (width, height, element size or pitch) may cause the up-
date to be rejected. Specifically, for 2d memsets, all dimension changes are rejected. For 1d
memsets, changes in height are explicitly rejected and other changes are opportunistically al-
lowed if the resulting work maps onto the work resources already allocated for the node.
The modifications only affect future launches of hGraphExec. Already enqueued or running
launches of hGraphExec are not affected by this call. node is also not modified by this call.
See also:
cudaGraphExecNodeSetParams,
cudaGraphAddMemsetNode,
cudaGraphMemsetNodeSet-
Params, cudaGraphExecKernelNodeSetParams, cudaGraphExecMemcpyNodeSetParams, cud-
aGraphExecHostNodeSetParams,
cudaGraphExecChildGraphNodeSetParams,
cudaGraphExe-
cEventRecordNodeSetEvent,
cudaGraphExecEventWaitNodeSetEvent,
cudaGraphExecExter-
6.20. Graph Management
365

 

 

 

 

 

 

 

Content      ..     3      4      5      6     ..