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

 

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

 

Search            copyright infringement  

 

   

 

   

 

Content      ..     4      5      6      7     ..

 

 

 

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

 

 

CUDA Runtime API Reference Manual, Release 13.5
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 - - Memset node from the graph which was used to instantiate graphExec
▶ pNodeParams - - Updated Parameters to set
Returns
cudaSuccess, cudaErrorInvalidValue,
__host__ cudaError_t cudaGraphExecNodeSetParams(cudaGraphExec_t graphExec,
cudaGraphNode_t node, struct
cudaGraphNodeParams *nodeParams)
Update a graph node’s parameters in an instantiated graph.
Sets the parameters of a node in an executable graph graphExec. 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.
The modifications only affect future launches of graphExec. Already enqueued or running
launches of graphExec are not affected by this call. node is also not modified by this call.
Allowed changes to parameters on executable graphs are as follows:
366
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
Node type
Allowed changes
kernel
See cudaGraphExecKernelNodeSetParams
memcpy
Addresses for 1-dimensional copies if allocated in same context; see cud-
aGraphExecMemcpyNodeSetParams
memset
Addresses for 1-dimensional memsets if allocated in same context; see
cudaGraphExecMemsetNodeSetParams
host
Unrestricted
child graph
Topology must match and restrictions apply recursively; see cuda-
GraphExecUpdate
event wait
Unrestricted
event record
Unrestricted
external
Number of semaphore operations cannot change
semaphore
sig-
nal
external
Number of semaphore operations cannot change
semaphore wait
memory allocation
API unsupported
memory free
API unsupported
See also:
cudaGraphAddNode, cudaGraphNodeSetParams 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
▶ graphExec - - The executable graph in which to update the specified node
▶ node - - Corresponding node from the graph from which graphExec was instan-
tiated
6.20. Graph Management
367
CUDA Runtime API Reference Manual, Release 13.5
▶ nodeParams - - Updated Parameters to set
Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorInvalidDeviceFunction, cudaErrorNot-
Supported
__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.
Updates the node parameters in the instantiated graph specified by hGraphExec with the node
parameters in a topologically identical graph specified by hGraph.
Limitations:
▶ Kernel nodes:
▶ The owning context of the function cannot change.
▶ A node whose function originally did not use CUDA dynamic parallelism cannot be up-
dated to a function which uses CDP.
▶ A node whose function originally did not make device-side update calls cannot be up-
dated to a function which makes device-side update calls.
▶ A cooperative node cannot be updated to a non-cooperative node, and vice-versa.
▶ If the graph was instantiated with cudaGraphInstantiateFlagUseNodePriority, the pri-
ority attribute cannot change. Equality is checked on the originally requested priority
values, before they are clamped to the device’s supported range.
▶ 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 contained such calls at instantiate-time. If no such calls were present at instan-
tiation, these updates cannot be performed at all.
▶ Neither hGraph nor hGraphExec may contain device-updatable kernel nodes.
▶ Memset and memcpy nodes:
▶ The CUDA device(s) to which the operand(s) was allocated/mapped cannot change.
▶ The source/destination memory must be allocated from the same contexts as the orig-
inal source/destination memory.
▶ For 2d memsets, only address and assigned value may be updated.
▶ For 1d memsets, updating dimensions is also allowed, but may fail if the resulting oper-
ation doesn’t map onto the work resources already allocated for the node.
▶ Additional memcpy node restrictions:
▶ Changing either the source or destination memory type(i.e. CU_MEMORYTYPE_DEVICE,
CU_MEMORYTYPE_ARRAY, etc.) is not supported.
▶ Conditional nodes:
▶ Changing node parameters is not supported.
▶ Changing parameters of nodes within the conditional body graph is subject to the rules
above.
368
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
▶ Conditional handle flags and default values are updated as part of the graph update.
Note: The API may add further restrictions in future releases. The return code should always be
checked.
cudaGraphExecUpdate sets the result member of resultInfo to cudaGraphExecUpdateError-
TopologyChanged under the following conditions:
▶ The count of nodes directly in hGraphExec and hGraph differ, in which case resultInfo-
>errorNode is set to NULL.
▶ hGraph has more exit nodes than hGraph, in which case resultInfo->errorNode is set to one
of the exit nodes in hGraph.
▶ A node in hGraph has a different number of dependencies than the node from hGraphExec
it is paired with, in which case resultInfo->errorNode is set to the node from hGraph.
▶ A node in hGraph has a dependency that does not match with the corresponding depen-
dency of the paired node from hGraphExec. resultInfo->errorNode will be set to the node
from hGraph. resultInfo->errorFromNode will be set to the mismatched dependency. The
dependencies are paired based on edge order and a dependency does not match when the
nodes are already paired based on other edges examined in the graph.
cudaGraphExecUpdate sets the result member of resultInfo to:
▶ cudaGraphExecUpdateError if passed an invalid value.
▶ cudaGraphExecUpdateErrorTopologyChanged if the graph topology changed
▶ cudaGraphExecUpdateErrorNodeTypeChanged if the type of a node changed, in which case
hErrorNode_out is set to the node from hGraph.
▶ cudaGraphExecUpdateErrorFunctionChanged if the function of a kernel node changed
(CUDA driver < 11.2)
▶ cudaGraphExecUpdateErrorUnsupportedFunctionChange if the func field of a kernel
changed in an unsupported way(see note above), in which case hErrorNode_out is set to
the node from hGraph
▶ cudaGraphExecUpdateErrorParametersChanged if any parameters to a node changed in a
way that is not supported, in which case hErrorNode_out is set to the node from hGraph
▶ cudaGraphExecUpdateErrorAttributesChanged if any attributes of a node changed in a way
that is not supported, in which case hErrorNode_out is set to the node from hGraph
▶ cudaGraphExecUpdateErrorNotSupported if something about a node is unsupported, like
the node’s type or configuration, in which case hErrorNode_out is set to the node from
hGraph
If the update fails for a reason not listed above, the result member of resultInfo will be set
to cudaGraphExecUpdateError. If the update succeeds, the result member will be set to cuda-
GraphExecUpdateSuccess.
cudaGraphExecUpdate returns cudaSuccess when the updated was performed successfully. It
returns cudaErrorGraphExecUpdateFailure if the graph update was not performed because it in-
cluded changes which violated constraints specific to instantiated graph update.
See also:
cudaGraphInstantiate
6.20. Graph Management
369
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 instantiated graph to be updated
▶ hGraph - The graph containing the updated parameters
▶ resultInfo - the error info structure
Returns
cudaSuccess, cudaErrorGraphExecUpdateFailure,
__host__ cudaError_t cudaGraphExternalSemaphoresSignalNodeGetParams(cudaGraphNode_t
hNode, struct
cudaExter-
nalSemaphoreSig-
nalNodeParams
*params_out)
Returns an external semaphore signal node’s parameters.
Returns the parameters of an external semaphore signal node hNode in params_out. The
extSemArray and paramsArray returned in params_out, are owned by the node. This memory
remains valid until the node is destroyed or its parameters are modified, and should not be modi-
fied directly. Use cudaGraphExternalSemaphoresSignalNodeSetParams to update the parameters
of this node.
See also:
cudaGraphNodeGetParams, cudaLaunchKernel, cudaGraphAddExternalSemaphoresSignalNode,
cudaGraphExternalSemaphoresSignalNodeSetParams, cudaGraphAddExternalSemaphoresWaitN-
ode, cudaSignalExternalSemaphoresAsync, cudaWaitExternalSemaphoresAsync
Warning: This function will be deprecated in a future CUDA release. Please migrate to cuda-
GraphNodeGetParams.
370
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
▶ hNode - - Node to get the parameters for
▶ params_out - - Pointer to return the parameters
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphExternalSemaphoresSignalNodeSetParams(cudaGraphNode_t
hNode, const
struct cudaExter-
nalSemaphoreSig-
nalNodeParams
*nodeParams)
Sets an external semaphore signal node’s parameters.
Sets the parameters of an external semaphore signal node hNode to nodeParams.
See also:
cudaGraphNodeSetParams,
cudaGraphAddExternalSemaphoresSignalNode,
cudaGraphExter-
nalSemaphoresSignalNodeSetParams, cudaGraphAddExternalSemaphoresWaitNode, cudaSig-
nalExternalSemaphoresAsync, cudaWaitExternalSemaphoresAsync
Warning: This function will be deprecated in a future CUDA release. Please migrate to cuda-
GraphNodeSetParams.
Note: Graph objects are not threadsafe. More here.
6.20. Graph Management
371
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
▶ hNode - - Node to set the parameters for
▶ nodeParams - - Parameters to copy
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphExternalSemaphoresWaitNodeGetParams(cudaGraphNode_t
hNode, struct cud-
aExternalSemaphore-
WaitNodeParams
*params_out)
Returns an external semaphore wait node’s parameters.
Returns the parameters of an external semaphore wait node hNode in params_out. The extSe-
mArray and paramsArray returned in params_out, are owned by the node. This memory re-
mains valid until the node is destroyed or its parameters are modified, and should not be modified
directly. Use cudaGraphExternalSemaphoresSignalNodeSetParams to update the parameters of
this node.
See also:
cudaGraphNodeGetParams, cudaLaunchKernel, cudaGraphAddExternalSemaphoresWaitNode,
cudaGraphExternalSemaphoresWaitNodeSetParams, cudaGraphAddExternalSemaphoresWaitN-
ode, cudaSignalExternalSemaphoresAsync, cudaWaitExternalSemaphoresAsync
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.
372
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
▶ hNode - - Node to get the parameters for
▶ params_out - - Pointer to return the parameters
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphExternalSemaphoresWaitNodeSetParams(cudaGraphNode_t
hNode, const struct
cudaExter-
nalSemaphoreWaitN-
odeParams
*nodeParams)
Sets an external semaphore wait node’s parameters.
Sets the parameters of an external semaphore wait node hNode to nodeParams.
See also:
cudaGraphNodeSetParams,
cudaGraphAddExternalSemaphoresWaitNode,
cudaGraphExter-
nalSemaphoresWaitNodeSetParams, cudaGraphAddExternalSemaphoresWaitNode, cudaSignalEx-
ternalSemaphoresAsync, cudaWaitExternalSemaphoresAsync
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.
6.20. Graph Management
373
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 set the parameters for
▶ nodeParams - - Parameters to copy
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphGetEdges(cudaGraph_t graph, cudaGraphNode_t *from,
cudaGraphNode_t *to, cudaGraphEdgeData *edgeData,
size_t *numEdges)
Returns a graph’s dependency edges.
Returns a list of graph's dependency edges. Edges are returned via corresponding indices in
from, to and edgeData; that is, the node in to[i] has a dependency on the node in from[i] with
data edgeData[i]. from and to may both be NULL, in which case this function only returns the
number of edges in numEdges. Otherwise, numEdges entries will be filled in. If numEdges is
higher than the actual number of edges, the remaining entries in from and to will be set to
NULL, and the number of edges actually returned will be written to numEdges. edgeData may
alone be NULL, in which case the edges must all have default (zeroed) edge data. Attempting a
losst query via NULL edgeData will result in cudaErrorLossyQuery. If edgeData is non-NULL then
from and to must be as well.
See also:
cudaGraphGetNodes, cudaGraphGetRootNodes, cudaGraphAddDependencies, cudaGraphRe-
moveDependencies, cudaGraphNodeGetDependencies, cudaGraphNodeGetDependentNodes
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
374
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
▶ graph - - Graph to get the edges from
▶ from - - Location to return edge endpoints
▶ to - - Location to return edge endpoints
▶ edgeData - - Optional location to return edge data
▶ numEdges - - See description
Returns
cudaSuccess, cudaErrorLossyQuery, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphGetId(cudaGraph_t hGraph, unsigned int *graphID)
Returns the id of a given graph.
Returns the id of hGraph in *graphId. The value in *graphId matches that referenced by cud-
aGraphDebugDotPrint.
See also:
cudaGraphGetNodes,
cudaGraphDebugDotPrint cudaGraphNodeGetContainingGraph cuda-
GraphNodeGetLocalId cudaGraphNodeGetToolsId cudaGraphExecGetId
Parameters
▶ hGraph - - Graph to query
▶ graphId - - Pointer to return the graphId
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphGetNodes(cudaGraph_t graph, cudaGraphNode_t *nodes, size_t
*numNodes)
Returns a graph’s nodes.
Returns a list of graph's nodes. nodes may be NULL, in which case this function will return
the number of nodes in numNodes. Otherwise, numNodes entries will be filled in. If numNodes is
higher than the actual number of nodes, the remaining entries in nodes will be set to NULL, and
the number of nodes actually obtained will be returned in numNodes.
See also:
cudaGraphCreate, cudaGraphGetRootNodes, cudaGraphGetEdges, cudaGraphNodeGetType, cuda-
GraphNodeGetDependencies, cudaGraphNodeGetDependentNodes
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
6.20. Graph Management
375
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
▶ graph - - Graph to query
▶ nodes - - Pointer to return the nodes
▶ numNodes - - See description
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphGetRootNodes(cudaGraph_t graph, cudaGraphNode_t
*pRootNodes, size_t *pNumRootNodes)
Returns a graph’s root nodes.
Returns a list of graph's root nodes. pRootNodes may be NULL, in which case this function will
return the number of root nodes in pNumRootNodes. Otherwise, pNumRootNodes entries will be
filled in. If pNumRootNodes is higher than the actual number of root nodes, the remaining entries
in pRootNodes will be set to NULL, and the number of nodes actually obtained will be returned
in pNumRootNodes.
See also:
cudaGraphCreate, cudaGraphGetNodes, cudaGraphGetEdges, cudaGraphNodeGetType, cuda-
GraphNodeGetDependencies, cudaGraphNodeGetDependentNodes
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.
376
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
Parameters
▶ graph - - Graph to query
▶ pRootNodes - - Pointer to return the root nodes
▶ pNumRootNodes - - See description
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphHostNodeGetParams(cudaGraphNode_t node, struct
cudaHostNodeParams *pNodeParams)
Returns a host node’s parameters.
Returns the parameters of host node node in pNodeParams.
See also:
cudaGraphNodeGetParams, cudaLaunchHostFunc, cudaGraphAddHostNode, cudaGraphHostN-
odeSetParams
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 parameters for
▶ pNodeParams - - Pointer to return the parameters
Returns
cudaSuccess, cudaErrorInvalidValue
6.20. Graph Management
377
CUDA Runtime API Reference Manual, Release 13.5
__host__ cudaError_t cudaGraphHostNodeSetParams(cudaGraphNode_t node, const struct
cudaHostNodeParams *pNodeParams)
Sets a host node’s parameters.
Sets the parameters of host node node to nodeParams.
See also:
cudaGraphNodeSetParams, cudaLaunchHostFunc, cudaGraphAddHostNode, cudaGraphHostN-
odeGetParams
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
▶ node - - Node to set the parameters for
▶ pNodeParams - - Parameters to copy
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphInstantiate(cudaGraphExec_t *pGraphExec, cudaGraph_t graph,
unsigned long long flags = 0)
Creates an executable graph from a graph.
Instantiates graph as an executable graph. The graph is validated for any structural constraints
or intra-node constraints which were not previously validated. If instantiation is successful, a
handle to the instantiated graph is returned in pGraphExec.
The flags parameter controls the behavior of instantiation and subsequent graph launches.
Valid flags are:
378
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
▶ cudaGraphInstantiateFlagAutoFreeOnLaunch, which configures a graph containing memory
allocation nodes to automatically free any unfreed memory allocations before the graph is
relaunched.
▶ cudaGraphInstantiateFlagDeviceLaunch, which configures the graph for launch from the de-
vice. If this flag is passed, the executable graph handle returned can be used to launch the
graph from both the host and device. This flag cannot be used in conjunction with cuda-
GraphInstantiateFlagAutoFreeOnLaunch.
▶ cudaGraphInstantiateFlagUseNodePriority, which causes the graph to use the priorities from
the per-node attributes rather than the priority of the launch stream during execution. Note
that priorities are only available on kernel nodes, and are copied from stream priority during
stream capture.
If graph contains any allocation or free nodes, there can be at most one executable graph in
existence for that graph at a time. An attempt to instantiate a second executable graph before
destroying the first with cudaGraphExecDestroy will result in an error. The same also applies if
graph contains any device-updatable kernel nodes.
Graphs instantiated for launch on the device have additional restrictions which do not apply to
host graphs:
▶ The graph’s nodes must reside on a single device.
▶ The graph can only contain kernel nodes, memcpy nodes, memset nodes, and child graph
nodes.
▶ The graph cannot be empty and must contain at least one kernel, memcpy, or memset node.
Operation-specific restrictions are outlined below.
▶ Kernel nodes:
▶ Use of CUDA Dynamic Parallelism is not permitted.
▶ Cooperative launches are permitted as long as MPS is not in use.
▶ Memcpy nodes:
▶ Only copies involving device memory and/or pinned device-mapped host memory are
permitted.
▶ Copies involving CUDA arrays are not permitted.
▶ Both operands must be accessible from the current device, and the current device must
match the device of other nodes in the graph.
If graph is not instantiated for launch on the device but contains kernels which call device-side
cudaGraphLaunch() from multiple devices, this will result in an error.
See also:
cudaGraphInstantiateWithFlags, cudaGraphCreate, cudaGraphUpload, cudaGraphLaunch, cuda-
GraphExecDestroy
Note: Graph objects are not threadsafe. More here.
6.20. Graph Management
379
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
▶ pGraphExec - - Returns instantiated graph
▶ graph - - Graph to instantiate
▶ flags - - Flags to control instantiation. See ::CUgraphInstantiate_flags.
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphInstantiateWithFlags(cudaGraphExec_t *pGraphExec,
cudaGraph_t graph, unsigned long long
flags = 0)
Creates an executable graph from a graph.
Instantiates graph as an executable graph. The graph is validated for any structural constraints
or intra-node constraints which were not previously validated. If instantiation is successful, a
handle to the instantiated graph is returned in pGraphExec.
The flags parameter controls the behavior of instantiation and subsequent graph launches.
Valid flags are:
▶ cudaGraphInstantiateFlagAutoFreeOnLaunch, which configures a graph containing memory
allocation nodes to automatically free any unfreed memory allocations before the graph is
relaunched.
▶ cudaGraphInstantiateFlagDeviceLaunch, which configures the graph for launch from the de-
vice. If this flag is passed, the executable graph handle returned can be used to launch the
graph from both the host and device. This flag can only be used on platforms which support
unified addressing. This flag cannot be used in conjunction with cudaGraphInstantiateFla-
gAutoFreeOnLaunch.
▶ cudaGraphInstantiateFlagUseNodePriority, which causes the graph to use the priorities from
the per-node attributes rather than the priority of the launch stream during execution. Note
that priorities are only available on kernel nodes, and are copied from stream priority during
stream capture.
If graph contains any allocation or free nodes, there can be at most one executable graph in
existence for that graph at a time. An attempt to instantiate a second executable graph before
destroying the first with cudaGraphExecDestroy will result in an error. The same also applies if
graph contains any device-updatable kernel nodes.
380
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
If graph contains kernels which call device-side cudaGraphLaunch() from multiple devices, this
will result in an error.
Graphs instantiated for launch on the device have additional restrictions which do not apply to
host graphs:
▶ The graph’s nodes must reside on a single device.
▶ The graph can only contain kernel nodes, memcpy nodes, memset nodes, and child graph
nodes.
▶ The graph cannot be empty and must contain at least one kernel, memcpy, or memset node.
Operation-specific restrictions are outlined below.
▶ Kernel nodes:
▶ Use of CUDA Dynamic Parallelism is not permitted.
▶ Cooperative launches are permitted as long as MPS is not in use.
▶ Memcpy nodes:
▶ Only copies involving device memory and/or pinned device-mapped host memory are
permitted.
▶ Copies involving CUDA arrays are not permitted.
▶ Both operands must be accessible from the current device, and the current device must
match the device of other nodes in the graph.
See also:
cudaGraphInstantiate, cudaGraphCreate, cudaGraphUpload, cudaGraphLaunch, cudaGraphEx-
ecDestroy
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
▶ pGraphExec - - Returns instantiated graph
▶ graph - - Graph to instantiate
6.20. Graph Management
381
CUDA Runtime API Reference Manual, Release 13.5
▶ flags - - Flags to control instantiation. See ::CUgraphInstantiate_flags.
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphInstantiateWithParams(cudaGraphExec_t *pGraphExec,
cudaGraph_t graph,
cudaGraphInstantiateParams
*instantiateParams)
Creates an executable graph from a graph.
Instantiates graph as an executable graph according to the instantiateParams structure. The
graph is validated for any structural constraints or intra-node constraints which were not previ-
ously validated. If instantiation is successful, a handle to the instantiated graph is returned in
pGraphExec.
instantiateParams controls the behavior of instantiation and subsequent graph launches, as
well as returning more detailed information in the event of an error. cudaGraphInstantiateParams
is defined as:
typedef struct {
unsigned long long flags;
cudaStream_t uploadStream;
cudaGraphNode_t errNode_out;
cudaGraphInstantiateResult result_out;
} cudaGraphInstantiateParams;
The flags field controls the behavior of instantiation and subsequent graph launches. Valid flags
are:
▶ cudaGraphInstantiateFlagAutoFreeOnLaunch, which configures a graph containing memory
allocation nodes to automatically free any unfreed memory allocations before the graph is
relaunched.
▶ cudaGraphInstantiateFlagUpload, which will perform an upload of the graph into upload-
Stream once the graph has been instantiated.
▶ cudaGraphInstantiateFlagDeviceLaunch, which configures the graph for launch from the de-
vice. If this flag is passed, the executable graph handle returned can be used to launch the
graph from both the host and device. This flag can only be used on platforms which support
unified addressing. This flag cannot be used in conjunction with cudaGraphInstantiateFla-
gAutoFreeOnLaunch.
▶ cudaGraphInstantiateFlagUseNodePriority, which causes the graph to use the priorities from
the per-node attributes rather than the priority of the launch stream during execution. Note
that priorities are only available on kernel nodes, and are copied from stream priority during
stream capture.
If graph contains any allocation or free nodes, there can be at most one executable graph in
existence for that graph at a time. An attempt to instantiate a second executable graph before
destroying the first with cudaGraphExecDestroy will result in an error. The same also applies if
graph contains any device-updatable kernel nodes.
If graph contains kernels which call device-side cudaGraphLaunch() from multiple devices, this
will result in an error.
382
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
Graphs instantiated for launch on the device have additional restrictions which do not apply to
host graphs:
▶ The graph’s nodes must reside on a single device.
▶ The graph can only contain kernel nodes, memcpy nodes, memset nodes, and child graph
nodes.
▶ The graph cannot be empty and must contain at least one kernel, memcpy, or memset node.
Operation-specific restrictions are outlined below.
▶ Kernel nodes:
▶ Use of CUDA Dynamic Parallelism is not permitted.
▶ Cooperative launches are permitted as long as MPS is not in use.
▶ Memcpy nodes:
▶ Only copies involving device memory and/or pinned device-mapped host memory are
permitted.
▶ Copies involving CUDA arrays are not permitted.
▶ Both operands must be accessible from the current device, and the current device must
match the device of other nodes in the graph.
In the event of an error, the result_out and errNode_out fields will contain more information
about the nature of the error. Possible error reporting includes:
▶ cudaGraphInstantiateError, if passed an invalid value or if an unexpected error occurred
which is described by the return value of the function. errNode_out will be set to NULL.
▶ cudaGraphInstantiateInvalidStructure, if the graph structure is invalid. errNode_out will be
set to one of the offending nodes.
▶ cudaGraphInstantiateNodeOperationNotSupported, if the graph is instantiated for device
launch but contains a node of an unsupported node type, or a node which performs un-
supported operations, such as use of CUDA dynamic parallelism within a kernel node. er-
rNode_out will be set to this node.
▶ cudaGraphInstantiateMultipleDevicesNotSupported, if the graph is instantiated for device
launch but a node’s device differs from that of another node. This error can also be returned
if a graph is not instantiated for device launch and it contains kernels which call device-side
cudaGraphLaunch() from multiple devices. errNode_out will be set to this node.
If instantiation is successful, result_out will be set to cudaGraphInstantiateSuccess, and hEr-
rNode_out will be set to NULL.
See also:
cudaGraphCreate, cudaGraphInstantiate, cudaGraphInstantiateWithFlags, cudaGraphExecDestroy
Note: Graph objects are not threadsafe. More here.
6.20. Graph Management
383
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
▶ pGraphExec - - Returns instantiated graph
▶ graph - - Graph to instantiate
▶ instantiateParams - - Instantiation parameters
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphKernelNodeCopyAttributes(cudaGraphNode_t hDst,
cudaGraphNode_t hSrc)
Copies attributes from source node to destination node.
Copies attributes from source node hSrc to destination node hDst. Both node must have the
same context.
See also:
cudaAccessPolicyWindow
Note: Note that this function may also return error codes from previous, asynchronous launches.
Parameters
▶ hDst - [out] Destination node
▶ hSrc - [in] Source node For list of attributes see cudaKernelNodeAttrID
Returns
cudaSuccess, ::cudaErrorInvalidContext
__host__ cudaError_t cudaGraphKernelNodeGetAttribute(cudaGraphNode_t hNode,
cudaLaunchAttributeID attr,
cudaLaunchAttributeValue
*value_out)
Queries node attribute.
Queries attribute attr from node hNode and stores it in corresponding member of value_out.
384
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
See also:
cudaAccessPolicyWindow
Note: Note that this function may also return error codes from previous, asynchronous launches.
Parameters
▶ hNode - [in]
▶ attr - [in]
▶ value_out -
Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorInvalidResourceHandle
__host__ cudaError_t cudaGraphKernelNodeGetParams(cudaGraphNode_t node, struct
cudaKernelNodeParams *pNodeParams)
Returns a kernel node’s parameters.
Returns the parameters of kernel node node in pNodeParams. The kernelParams or extra
array returned in pNodeParams, as well as the argument values it points to, are owned by the
node. This memory remains valid until the node is destroyed or its parameters are modified, and
should not be modified directly. Use cudaGraphKernelNodeSetParams to update the parameters
of this node.
The params will contain either kernelParams or extra, according to which of these was most
recently set on the node.
See also:
cudaGraphNodeGetParams, cudaLaunchKernel, cudaGraphAddKernelNode, cudaGraphKernelN-
odeSetParams
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
385
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
▶ node - - Node to get the parameters for
▶ pNodeParams - - Pointer to return the parameters
Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorInvalidDeviceFunction
__host__ cudaError_t cudaGraphKernelNodeSetAttribute(cudaGraphNode_t hNode,
cudaLaunchAttributeID attr, const
cudaLaunchAttributeValue *value)
Sets node attribute.
Sets attribute attr on node hNode from corresponding attribute of value.
See also:
cudaAccessPolicyWindow
Note: Note that this function may also return error codes from previous, asynchronous launches.
Parameters
▶ hNode - [out]
▶ attr - [in]
▶ value -
Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorInvalidResourceHandle
__device__ cudaError_t cudaGraphKernelNodeSetEnabled(cudaGraphDeviceNode_t node, bool
enable)
Enables or disables the given kernel node.
Enables or disables node based upon enable. If enable is true, the node will be enabled; if it is
false, the node will be disabled. Disabled nodes will act as a NOP during execution. node must
be device-updatable, and must reside upon the same device as the calling kernel.
If this function is called for the node’s immediate dependent and that dependent is configured
for programmatic dependent launch, then a memory fence must be invoked via __threadfence()
before kickoff of the dependent is triggered via cudaTriggerProgrammaticLaunchCompletion() to
ensure that the update is visible to that dependent node before it is launched.
386
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
See also:
cudaGraphKernelNodeSetParam, cudaGraphKernelNodeSetGridDim, cudaGraphKernelNodeUp-
datesApply
Note: Note that this function may also return error codes from previous, asynchronous launches.
Parameters
▶ node - - The node to update
▶ enable - - Whether to enable or disable the node
Returns
cudaSuccess, cudaErrorInvalidValue
__device__ cudaError_t cudaGraphKernelNodeSetGridDim(cudaGraphDeviceNode_t node, dim3
gridDim)
Updates the grid dimensions of the given kernel node.
Sets the grid dimensions of node to gridDim. node must be device-updatable, and must reside
upon the same device as thecalling kernel.
If this function is called for the node’s immediate dependent and that dependent is configured
for programmatic dependent launch, then a memory fence must be invoked via __threadfence()
before kickoff of the dependent is triggered via cudaTriggerProgrammaticLaunchCompletion() to
ensure that the update is visible to that dependent node before it is launched.
See also:
cudaGraphKernelNodeSetParam, cudaGraphKernelNodeSetEnabled, cudaGraphKernelNodeUp-
datesApply
Note: Note that this function may also return error codes from previous, asynchronous launches.
Parameters
▶ node - - The node to update
▶ gridDim - - The grid dimensions to set
Returns
cudaSuccess, cudaErrorInvalidValue
template<typename T>
__device__ cudaError_t cudaGraphKernelNodeSetParam(cudaGraphDeviceNode_t node, size_t
offset, const T &value)
Updates the kernel parameters of the given kernel node.
Updates the kernel parameters of node at offset to value. node must be device-updatable,
and must reside upon the same device as the calling kernel.
6.20. Graph Management
387
CUDA Runtime API Reference Manual, Release 13.5
If this function is called for the node’s immediate dependent and that dependent is configured
for programmatic dependent launch, then a memory fence must be invoked via __threadfence()
before kickoff of the dependent is triggered via cudaTriggerProgrammaticLaunchCompletion() to
ensure that the update is visible to that dependent node before it is launched.
See also:
cudaGraphKernelNodeSetEnabled, cudaGraphKernelNodeSetGridDim, cudaGraphKernelNodeUp-
datesApply
Note: Note that this function may also return error codes from previous, asynchronous launches.
Parameters
▶ node - - The node to update
▶ offset - - The offset into the params at which to make the update
▶ value - - Parameter value to write
Returns
cudaSuccess, cudaErrorInvalidValue
__device__ cudaError_t cudaGraphKernelNodeSetParam(cudaGraphDeviceNode_t node, size_t
offset, const void *value, size_t size)
Updates the kernel parameters of the given kernel node.
Updates size bytes in the kernel parameters of node at offset to the contents of value. node
must be device-updatable, and must reside upon the same device as the calling kernel.
If this function is called for the node’s immediate dependent and that dependent is configured
for programmatic dependent launch, then a memory fence must be invoked via __threadfence()
before kickoff of the dependent is triggered via cudaTriggerProgrammaticLaunchCompletion() to
ensure that the update is visible to that dependent node before it is launched.
See also:
cudaGraphKernelNodeSetEnabled, cudaGraphKernelNodeSetGridDim, cudaGraphKernelNodeUp-
datesApply
Note: Note that this function may also return error codes from previous, asynchronous launches.
Parameters
▶ node - - The node to update
▶ offset - - The offset into the params at which to make the update
▶ value - - Buffer containing the params to write
▶ size - - Size in bytes to update
388
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphKernelNodeSetParams(cudaGraphNode_t node, const struct
cudaKernelNodeParams *pNodeParams)
Sets a kernel node’s parameters.
Sets the parameters of kernel node node to pNodeParams.
See also:
cudaGraphNodeSetParams, cudaLaunchKernel, cudaGraphAddKernelNode, cudaGraphKernelN-
odeGetParams
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.
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
▶ node - - Node to set the parameters for
6.20. Graph Management
389
CUDA Runtime API Reference Manual, Release 13.5
▶ pNodeParams - - Parameters to copy
Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorInvalidResourceHandle, cudaEr-
rorMemoryAllocation
__device__ cudaError_t cudaGraphKernelNodeUpdatesApply(const cudaGraphKernelNodeUpdate
*updates, size_t updateCount)
Batch applies multiple kernel node updates.
Batch applies one or more kernel node updates based on the information provided in updates.
updateCount specifies the number of updates to apply. Each entry in updates must specify a
node to update, the type of update to apply, and the parameters for that type of update. See
the documentation for cudaGraphKernelNodeUpdate for more detail.
If this function is called for the node’s immediate dependent and that dependent is configured
for programmatic dependent launch, then a memory fence must be invoked via __threadfence()
before kickoff of the dependent is triggered via cudaTriggerProgrammaticLaunchCompletion() to
ensure that the update is visible to that dependent node before it is launched.
See also:
cudaGraphKernelNodeSetParam, cudaGraphKernelNodeSetEnabled, cudaGraphKernelNodeSet-
GridDim
Note: Note that this function may also return error codes from previous, asynchronous launches.
Parameters
▶ updates - - The updates to apply
▶ updateCount - - The number of updates to apply
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphLaunch(cudaGraphExec_t graphExec, cudaStream_t stream)
Launches an executable graph in a stream.
Executes graphExec in stream. Only one instance of graphExec may be executing at a time.
Each launch is ordered behind both any previous work in stream and any previous launches of
graphExec. To execute a graph concurrently, it must be instantiated multiple times into multiple
executable graphs.
If any allocations created by graphExec remain unfreed (from a previous launch) and graphExec
was not instantiated with cudaGraphInstantiateFlagAutoFreeOnLaunch, the launch will fail with
cudaErrorInvalidValue.
See also:
cudaGraphInstantiate, cudaGraphUpload, cudaGraphExecDestroy
390
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
▶ graphExec - - Executable graph to launch
▶ stream - - Stream in which to launch the graph
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphMemAllocNodeGetParams(cudaGraphNode_t node, struct
cudaMemAllocNodeParams
*params_out)
Returns a memory alloc node’s parameters.
Returns the parameters of a memory alloc node hNode in params_out. The poolProps and
accessDescs returned in params_out, are owned by the node. This memory remains valid until
the node is destroyed. The returned parameters must not be modified.
See also:
cudaGraphNodeGetParams, cudaGraphAddMemAllocNode, cudaGraphMemFreeNodeGetParams
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.
6.20. Graph Management
391
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
▶ node - - Node to get the parameters for
▶ params_out - - Pointer to return the parameters
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphMemFreeNodeGetParams(cudaGraphNode_t node, void *dptr_out)
Returns a memory free node’s parameters.
Returns the address of a memory free node hNode in dptr_out.
See also:
cudaGraphNodeGetParams, cudaGraphAddMemFreeNode, cudaGraphMemFreeNodeGetParams
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
392
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
▶ node - - Node to get the parameters for
▶ dptr_out - - Pointer to return the device address
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphMemcpyNodeGetParams(cudaGraphNode_t node, struct
cudaMemcpy3DParms *pNodeParams)
Returns a memcpy node’s parameters.
Returns the parameters of memcpy node node in pNodeParams.
See also:
cudaGraphNodeGetParams, cudaMemcpy3D, cudaGraphAddMemcpyNode, cudaGraphMemcpyN-
odeSetParams
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 parameters for
▶ pNodeParams - - Pointer to return the parameters
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphMemcpyNodeSetParams(cudaGraphNode_t node, const struct
cudaMemcpy3DParms *pNodeParams)
Sets a memcpy node’s parameters.
6.20. Graph Management
393
CUDA Runtime API Reference Manual, Release 13.5
Sets the parameters of memcpy node node to pNodeParams.
See also:
cudaGraphNodeSetParams,
cudaMemcpy3D,
cudaGraphMemcpyNodeSetParamsToSymbol,
cudaGraphMemcpyNodeSetParamsFromSymbol, cudaGraphMemcpyNodeSetParams1D, cuda-
GraphAddMemcpyNode, cudaGraphMemcpyNodeGetParams
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
▶ node - - Node to set the parameters for
▶ pNodeParams - - Parameters to copy
Returns
cudaSuccess, cudaErrorInvalidValue,
__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.
Sets the parameters of memcpy node node to the copy described by the provided parameters.
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.
394
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
See also:
cudaMemcpy, cudaGraphMemcpyNodeSetParams, cudaGraphAddMemcpyNode, cudaGraphMem-
cpyNodeGetParams
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 set the parameters for
▶ dst - - Destination memory address
▶ src - - Source memory address
▶ count - - Size in bytes to copy
▶ kind - - Type of transfer
Returns
cudaSuccess, cudaErrorInvalidValue
__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.
Sets the parameters of memcpy node node to the copy described by the provided parameters.
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.
6.20. Graph Management
395
CUDA Runtime API Reference Manual, Release 13.5
See also:
cudaMemcpyFromSymbol,
cudaGraphMemcpyNodeSetParams,
cudaGraphMemcpyNodeSet-
ParamsToSymbol, cudaGraphAddMemcpyNode, cudaGraphMemcpyNodeGetParams
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 set the parameters for
▶ 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 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.
Sets the parameters of memcpy node node to the copy described by the provided parameters.
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.
396
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
See also:
cudaMemcpyToSymbol, cudaGraphMemcpyNodeSetParams, cudaGraphMemcpyNodeSetParams-
FromSymbol, cudaGraphAddMemcpyNode, cudaGraphMemcpyNodeGetParams
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 set the parameters for
▶ 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 cudaGraphMemsetNodeGetParams(cudaGraphNode_t node, struct
cudaMemsetParams *pNodeParams)
Returns a memset node’s parameters.
Returns the parameters of memset node node in pNodeParams.
See also:
cudaGraphNodeGetParams, cudaMemset2D, cudaGraphAddMemsetNode, cudaGraphMemsetN-
odeSetParams
Warning: This function will be deprecated in a future CUDA release. Please migrate to cuda-
GraphNodeGetParams.
6.20. Graph Management
397
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
▶ node - - Node to get the parameters for
▶ pNodeParams - - Pointer to return the parameters
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphMemsetNodeSetParams(cudaGraphNode_t node, const struct
cudaMemsetParams *pNodeParams)
Sets a memset node’s parameters.
Sets the parameters of memset node node to pNodeParams.
See also:
cudaGraphNodeSetParams, cudaMemset2D, cudaGraphAddMemsetNode, cudaGraphMemsetN-
odeGetParams
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.
398
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
▶ node - - Node to set the parameters for
▶ pNodeParams - - Parameters to copy
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphNodeFindInClone(cudaGraphNode_t *pNode, cudaGraphNode_t
originalNode, cudaGraph_t clonedGraph)
Finds a cloned version of a node.
This function returns the node in clonedGraph corresponding to originalNode in the original
graph.
clonedGraph must have been cloned from originalGraph via cudaGraphClone. originalN-
ode must have been in originalGraph at the time of the call to cudaGraphClone, and the cor-
responding cloned node in clonedGraph must not have been removed. The cloned node is then
returned via pClonedNode.
See also:
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
▶ pNode - - Returns handle to the cloned node
▶ originalNode - - Handle to the original node
▶ clonedGraph - - Cloned graph to query
6.20. Graph Management
399
CUDA Runtime API Reference Manual, Release 13.5
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphNodeGetContainingGraph(cudaGraphNode_t hNode,
cudaGraph_t *phGraph)
Returns the graph that contains a given graph node.
Returns the graph that contains hNode in *phGraph. If hNode is in a child graph, the child graph
it is in is returned.
See also:
cudaGraphGetNodes, cudaGraphDebugDotPrint cudaGraphNodeGetLocalId cudaGraphNodeGet-
ToolsId cudaGraphGetId cudaGraphExecGetId
Parameters
▶ hNode - - Node to query
▶ phGraph - - Pointer to return the containing graph
Returns
cudaSuccess cudaErrorInvalidValue
__host__ cudaError_t cudaGraphNodeGetDependencies(cudaGraphNode_t node, cudaGraphNode_t
*pDependencies, cudaGraphEdgeData
*edgeData, size_t *pNumDependencies)
Returns a node’s dependencies.
Returns a list of node's dependencies. pDependencies may be NULL, in which case this func-
tion will return the number of dependencies in pNumDependencies. Otherwise, pNumDepen-
dencies entries will be filled in. If pNumDependencies is higher than the actual number of
dependencies, the remaining entries in pDependencies will be set to NULL, and the number of
nodes actually obtained will be returned in pNumDependencies.
Note that if an edge has non-zero (non-default) edge data and edgeData is NULL, this API will
return cudaErrorLossyQuery. If edgeData is non-NULL, then pDependencies must be as well.
See also:
cudaGraphNodeGetDependentNodes, cudaGraphGetNodes, cudaGraphGetRootNodes, cuda-
GraphGetEdges, cudaGraphAddDependencies, cudaGraphRemoveDependencies
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.
400
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
▶ node - - Node to query
▶ pDependencies - - Pointer to return the dependencies
▶ edgeData - - Optional array to return edge data for each dependency
▶ pNumDependencies - - See description
Returns
cudaSuccess, cudaErrorLossyQuery, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphNodeGetDependentNodes(cudaGraphNode_t node,
cudaGraphNode_t *pDependentNodes,
cudaGraphEdgeData *edgeData, size_t
*pNumDependentNodes)
Returns a node’s dependent nodes.
Returns a list of node's dependent nodes. pDependentNodes may be NULL, in which case
this function will return the number of dependent nodes in pNumDependentNodes. Otherwise,
pNumDependentNodes entries will be filled in. If pNumDependentNodes is higher than the actual
number of dependent nodes, the remaining entries in pDependentNodes will be set to NULL, and
the number of nodes actually obtained will be returned in pNumDependentNodes.
Note that if an edge has non-zero (non-default) edge data and edgeData is NULL, this API will
return cudaErrorLossyQuery. If edgeData is non-NULL, then pDependentNodes must be as well.
See also:
cudaGraphNodeGetDependencies,
cudaGraphGetNodes,
cudaGraphGetRootNodes,
cuda-
GraphGetEdges, cudaGraphAddDependencies, cudaGraphRemoveDependencies
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
401
CUDA Runtime API Reference Manual, Release 13.5
Parameters
▶ node - - Node to query
▶ pDependentNodes - - Pointer to return the dependent nodes
▶ edgeData - - Optional pointer to return edge data for dependent nodes
▶ pNumDependentNodes - - See description
Returns
cudaSuccess, cudaErrorLossyQuery, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphNodeGetEnabled(cudaGraphExec_t hGraphExec, cudaGraphNode_t
hNode, unsigned int *isEnabled)
Query whether a node in the given graphExec is enabled.
Sets isEnabled to 1 if hNode is enabled, or 0 if hNode is disabled.
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.
See also:
cudaGraphNodeSetEnabled, cudaGraphExecUpdate, cudaGraphInstantiate cudaGraphLaunch
Note: Currently only kernel, memset and memcpy nodes are supported.
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 - - Node from the graph from which graphExec was instantiated
▶ isEnabled - - Location to return the enabled status of the node
402
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
Returns
cudaSuccess, cudaErrorInvalidValue,
__host__ cudaError_t cudaGraphNodeGetLocalId(cudaGraphNode_t hNode, unsigned int *nodeId)
Returns the node id of a given graph node.
Returns the node id of hNode in *nodeId. The nodeId matches that referenced by cudaGraphDe-
bugDotPrint. The local nodeId and graphId together can uniquely identify the node.
See also:
cudaGraphGetNodes,
cudaGraphDebugDotPrint cudaGraphNodeGetContainingGraph cuda-
GraphNodeGetToolsId cudaGraphGetId cudaGraphExecGetId
Parameters
▶ hNode - - Node to query
▶ nodeId - - Pointer to return the nodeId
Returns
cudaSuccess cudaErrorInvalidValue
__host__ cudaError_t cudaGraphNodeGetParams(cudaGraphNode_t node, struct
cudaGraphNodeParams *nodeParams)
Returns a graph node’s parameters.
Returns the parameters of graph node node in *nodeParams.
Any pointers returned in *nodeParams point to driver-owned memory associated with the node.
This memory remains valid until the node is destroyed. Any memory pointed to from *node-
Params must not be modified.
The returned parameters are a description of the node, but may not be identical to the struct
provided at creation and may not be suitable for direct creation of identical nodes. This is because
parameters may be partially unspecified and filled in by the driver at creation, may reference
non-copyable handles, or may describe ownership semantics or other parameters that govern
behavior of node creation but are not part of the final functional descriptor.
See also:
cudaGraphNodeGetParams, cudaGraphNodeSetParams, cudaGraphAddNode, cudaGraphExecN-
odeSetParams
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
403
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
▶ node - - Node to get the parameters for
▶ nodeParams - - Pointer to return the parameters
Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorNotSupported
__host__ cudaError_t cudaGraphNodeGetToolsId(cudaGraphNode_t hNode, unsigned long long
*toolsNodeId)
Returns an id used by tools to identify a given node.
See also:
cudaGraphGetNodes,
cudaGraphDebugDotPrint cudaGraphNodeGetContainingGraph cuda-
GraphNodeGetLocalId cudaGraphGetId cudaGraphExecGetId
Parameters
▶ hNode - - Node to query
▶ *toolsNodeId - - Pointer to return the id used by tools
Returns
::CUDA_SUCCESS cudaErrorInvalidValue
__host__ cudaError_t cudaGraphNodeGetType(cudaGraphNode_t node, enum cudaGraphNodeType
*pType)
Returns a node’s type.
Returns the node type of node in pType.
See also:
cudaGraphGetNodes, cudaGraphGetRootNodes, cudaGraphChildGraphNodeGetGraph, cuda-
GraphKernelNodeGetParams, cudaGraphKernelNodeSetParams, cudaGraphHostNodeGetParams,
cudaGraphHostNodeSetParams, cudaGraphMemcpyNodeGetParams, cudaGraphMemcpyNode-
SetParams, cudaGraphMemsetNodeGetParams, cudaGraphMemsetNodeSetParams
Note: Graph objects are not threadsafe. More here.
Note: Note that this function may also return error codes from previous, asynchronous launches.
404
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
▶ node - - Node to query
▶ pType - - Pointer to return the node type
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphNodeSetEnabled(cudaGraphExec_t hGraphExec, cudaGraphNode_t
hNode, unsigned int isEnabled)
Enables or disables the specified node in the given graphExec.
Sets hNode to be either enabled or disabled. Disabled nodes are functionally equivalent to empty
nodes until they are reenabled. Existing node parameters are not affected by disabling/enabling
the node.
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.
See also:
cudaGraphNodeGetEnabled, cudaGraphExecUpdate, cudaGraphInstantiate cudaGraphLaunch
Note: Currently only kernel, memset and memcpy nodes are supported.
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
405
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
▶ hNode - - Node from the graph from which graphExec was instantiated
▶ isEnabled - - Node is enabled if != 0, otherwise the node is disabled
Returns
cudaSuccess, cudaErrorInvalidValue,
__host__ cudaError_t cudaGraphNodeSetParams(cudaGraphNode_t node, struct
cudaGraphNodeParams *nodeParams)
Update a graph node’s parameters.
Sets the parameters of graph node node to nodeParams. The node type specified by
nodeParams->type must match the type of node. nodeParams must be fully initialized and
all unused bytes (reserved, padding) zeroed.
Modifying parameters is not supported for node types cudaGraphNodeTypeMemAlloc and cud-
aGraphNodeTypeMemFree.
See also:
cudaGraphNodeGetParams, cudaGraphAddNode, 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
▶ node - - Node to set the parameters for
▶ nodeParams - - Parameters to copy
406
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorInvalidDeviceFunction, cudaErrorNot-
Supported
__host__ cudaError_t cudaGraphReleaseUserObject(cudaGraph_t graph, cudaUserObject_t
object, unsigned int count = 1)
Release a user object reference from a graph.
Releases user object references owned by a graph.
See CUDA User Objects in the CUDA C++ Programming Guide for more information on user ob-
jects.
See also:
cudaUserObjectCreate cudaUserObjectRetain, cudaUserObjectRelease, cudaGraphRetainUserOb-
ject, cudaGraphCreate
Parameters
▶ graph - - The graph that will release the reference
▶ object - - The user object to release a reference for
▶ count - - The number of references to release, typically 1. Must be nonzero and
not larger than INT_MAX.
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaGraphRemoveDependencies(cudaGraph_t graph, const
cudaGraphNode_t *from, const
cudaGraphNode_t *to, const
cudaGraphEdgeData *edgeData, size_t
numDependencies)
Removes dependency edges from a graph.
The number of pDependencies to be removed 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 edge that
does not exist in the graph, with data matching edgeData, results in an error. edgeData is nul-
lable, which is equivalent to passing default (zeroed) data for each edge.
See also:
cudaGraphAddDependencies, cudaGraphGetEdges, cudaGraphNodeGetDependencies, cuda-
GraphNodeGetDependentNodes
Note: Graph objects are not threadsafe. More here.
6.20. Graph Management
407
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
▶ graph - - Graph from which to remove dependencies
▶ from - - Array of nodes that provide the dependencies
▶ to - - Array of dependent nodes
▶ edgeData - - Optional array of edge data. If NULL, edge data is assumed to be
default (zeroed).
▶ numDependencies - - Number of dependencies to be removed
Returns
cudaSuccess, cudaErrorInvalidValue
__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.
Creates or moves user object references that will be owned by a CUDA graph.
See CUDA User Objects in the CUDA C++ Programming Guide for more information on user ob-
jects.
See also:
cudaUserObjectCreate cudaUserObjectRetain, cudaUserObjectRelease, cudaGraphReleaseUser-
Object, cudaGraphCreate
Parameters
▶ graph - - The graph to associate the reference with
▶ object - - The user object to retain a reference for
▶ count - - The number of references to add to the graph, typically 1. Must be
nonzero and not larger than INT_MAX.
▶ flags - - The optional flag cudaGraphUserObjectMove transfers references
from the calling thread, rather than create new references. Pass 0 to create
new references.
408
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
Returns
cudaSuccess, cudaErrorInvalidValue
__device__ void cudaGraphSetConditional(cudaGraphConditionalHandle handle, unsigned int
value)
Sets the condition value associated with a conditional node.
Sets the condition value associated with a conditional node.
Note: handle must be associated with the same context as the kernel calling this function. Note:
It is undefined behavior to have racing / possibly concurrent calls to cudaGraphSetConditional.
See also:
cudaGraphConditionalHandleCreate
__host__ cudaError_t cudaGraphUpload(cudaGraphExec_t graphExec, cudaStream_t stream)
Uploads an executable graph in a stream.
Uploads graphExec to the device in stream without executing it. Uploads of the same
graphExec will be serialized. Each upload is ordered behind both any previous work in stream
and any previous launches of graphExec. Uses memory cached by stream to back the alloca-
tions owned by graphExec.
See also:
cudaGraphInstantiate, cudaGraphLaunch, cudaGraphExecDestroy
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.
Parameters
▶ graphExec - - Executable graph to upload
▶ stream - - Stream in which to upload the graph
Returns
cudaSuccess, cudaErrorInvalidValue,
__host__ cudaError_t cudaUserObjectCreate(cudaUserObject_t *object_out, void *ptr,
cudaHostFn_t destroy, unsigned int initialRefcount,
unsigned int flags)
Create a user object.
Create a user object with the specified destructor callback and initial reference count. The initial
references are owned by the caller.
Destructor callbacks cannot make CUDA API calls and should avoid blocking behavior, as they are
executed by a shared internal thread. Another thread may be signaled to perform such actions,
if it does not block forward progress of tasks scheduled through CUDA.
6.20. Graph Management
409
CUDA Runtime API Reference Manual, Release 13.5
See CUDA User Objects in the CUDA C++ Programming Guide for more information on user ob-
jects.
See also:
cudaUserObjectRetain, cudaUserObjectRelease, cudaGraphRetainUserObject, cudaGraphRe-
leaseUserObject, cudaGraphCreate
Parameters
▶ object_out - - Location to return the user object handle
▶ ptr - - The pointer to pass to the destroy function
▶ destroy - - Callback to free the user object when it is no longer in use
▶ initialRefcount - - The initial refcount to create the object with, typically 1.
The initial references are owned by the calling thread.
▶ flags - - Currently it is required to pass cudaUserObjectNoDestructorSync,
which is the only defined flag. This indicates that the destroy callback cannot
be waited on by any CUDA API. Users requiring synchronization of the callback
should signal its completion manually.
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaUserObjectRelease(cudaUserObject_t object, unsigned int count = 1)
Release a reference to a user object.
Releases user object references owned by the caller. The object’s destructor is invoked if the
reference count reaches zero.
It is undefined behavior to release references not owned by the caller, or to use a user object
handle after all references are released.
See CUDA User Objects in the CUDA C++ Programming Guide for more information on user ob-
jects.
See also:
cudaUserObjectCreate, cudaUserObjectRetain, cudaGraphRetainUserObject, cudaGraphRe-
leaseUserObject, cudaGraphCreate
Parameters
▶ object - - The object to release
▶ count - - The number of references to release, typically 1. Must be nonzero and
not larger than INT_MAX.
Returns
cudaSuccess, cudaErrorInvalidValue
410
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
__host__ cudaError_t cudaUserObjectRetain(cudaUserObject_t object, unsigned int count = 1)
Retain a reference to a user object.
Retains new references to a user object. The new references are owned by the caller.
See CUDA User Objects in the CUDA C++ Programming Guide for more information on user ob-
jects.
See also:
cudaUserObjectCreate, cudaUserObjectRelease, cudaGraphRetainUserObject, cudaGraphRe-
leaseUserObject, cudaGraphCreate
Parameters
▶ object - - The object to retain
▶ count - - The number of references to retain, typically 1. Must be nonzero and
not larger than INT_MAX.
Returns
cudaSuccess, cudaErrorInvalidValue
6.21. Graphics Interoperability
This section describes the graphics interoperability functions of the CUDA runtime application pro-
gramming interface.
Functions
__host__ cudaError_t cudaGraphicsMapResources(int count, cudaGraphicsResource_t *resources,
cudaStream_t stream=0)
Map graphics resources for access by CUDA.
__host__ cudaError_t cudaGraphicsResourceGetMappedMipmappedArray(cudaMipmappedArray_t
*mipmappedArray, cudaGraphicsResource_t resource)
Get a mipmapped array through which to access a mapped graphics resource.
__host__ cudaError_t cudaGraphicsResourceGetMappedPointer(void **devPtr, size_t *size, cuda-
GraphicsResource_t resource)
Get an device pointer through which to access a mapped graphics resource.
__host__ cudaError_t cudaGraphicsResourceSetMapFlags(cudaGraphicsResource_t resource, un-
signed int flags)
Set usage flags for mapping a graphics resource.
__host__ cudaError_t cudaGraphicsSubResourceGetMappedArray(cudaArray_t *array, cudaGraphic-
sResource_t resource, unsigned int arrayIndex, unsigned int mipLevel)
Get an array through which to access a subresource of a mapped graphics resource.
__host__ cudaError_t cudaGraphicsUnmapResources(int count, cudaGraphicsResource_t *re-
sources, cudaStream_t stream=0)
Unmap graphics resources.
6.21. Graphics Interoperability
411
CUDA Runtime API Reference Manual, Release 13.5
__host__ cudaError_t cudaGraphicsUnregisterResource(cudaGraphicsResource_t resource)
Unregisters a graphics resource for access by CUDA.
6.21.1. Functions
__host__ cudaError_t cudaGraphicsMapResources(int count, cudaGraphicsResource_t *resources,
cudaStream_t stream = 0)
Map graphics resources for access by CUDA.
Maps the count graphics resources in resources for access by CUDA.
The resources in resources may be accessed by CUDA until they are unmapped. The graph-
ics API from which resources were registered should not access any resources while they are
mapped by CUDA. If an application does so, the results are undefined.
This function provides the synchronization guarantee that any graphics calls issued before cud-
aGraphicsMapResources() will complete before any subsequent CUDA work issued in stream be-
gins.
If resources contains any duplicate entries then cudaErrorInvalidResourceHandle is returned. If
any of resources are presently mapped for access by CUDA then cudaErrorUnknown is returned.
See also:
cudaGraphicsResourceGetMappedPointer, cudaGraphicsSubResourceGetMappedArray, cuda-
GraphicsUnmapResources, ::cuGraphicsMapResources
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
▶ count - - Number of resources to map
▶ resources - - Resources to map for CUDA
▶ stream - - Stream for synchronization
Returns
cudaSuccess, cudaErrorInvalidResourceHandle, cudaErrorUnknown
412
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
__host__ cudaError_t cudaGraphicsResourceGetMappedMipmappedArray(cudaMipmappedArray_t
*mipmappedArray,
cudaGraphicsRe-
source_t resource)
Get a mipmapped array through which to access a mapped graphics resource.
Returns in *mipmappedArray a mipmapped array through which the mapped graphics resource
resource may be accessed. The value set in mipmappedArray may change every time that
resource is mapped.
If resource is not a texture then it cannot be accessed via an array and cudaErrorUnknown is
returned. If resource is not mapped then cudaErrorUnknown is returned.
See also:
cudaGraphicsResourceGetMappedPointer, ::cuGraphicsResourceGetMappedMipmappedArray
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
▶ mipmappedArray - - Returned mipmapped array through which resource may
be accessed
▶ resource - - Mapped resource to access
Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorInvalidResourceHandle, cudaErrorUn-
known
__host__ cudaError_t cudaGraphicsResourceGetMappedPointer(void **devPtr, size_t *size,
cudaGraphicsResource_t
resource)
Get an device pointer through which to access a mapped graphics resource.
Returns in *devPtr a pointer through which the mapped graphics resource resource may be
accessed. Returns in *size the size of the memory in bytes which may be accessed from that
pointer. The value set in devPtr may change every time that resource is mapped.
If resource is not a buffer then it cannot be accessed via a pointer and cudaErrorUnknown is
returned. If resource is not mapped then cudaErrorUnknown is returned.
▶
6.21. Graphics Interoperability
413
CUDA Runtime API Reference Manual, Release 13.5
See also:
cudaGraphicsMapResources, cudaGraphicsSubResourceGetMappedArray,
::cuGraphicsRe-
sourceGetMappedPointer
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 pointer through which resource may be accessed
▶ size - - Returned size of the buffer accessible starting at *devPtr
▶ resource - - Mapped resource to access
Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorInvalidResourceHandle, cudaErrorUn-
known
__host__ cudaError_t cudaGraphicsResourceSetMapFlags(cudaGraphicsResource_t resource,
unsigned int flags)
Set usage flags for mapping a graphics resource.
Set flags for mapping the graphics resource resource.
Changes to flags will take effect the next time resource is mapped. The flags argument may
be any of the following:
▶ cudaGraphicsMapFlagsNone: Specifies no hints about how resource will be used. It is there-
fore assumed that CUDA may read from or write to resource.
▶ cudaGraphicsMapFlagsReadOnly: Specifies that CUDA will not write to resource.
▶ cudaGraphicsMapFlagsWriteDiscard: Specifies CUDA will not read from resource and will
write over the entire contents of resource, so none of the data previously stored in re-
source will be preserved.
If resource is presently mapped for access by CUDA then cudaErrorUnknown is returned. If
flags is not one of the above values then cudaErrorInvalidValue is returned.
See also:
cudaGraphicsMapResources, ::cuGraphicsResourceSetMapFlags
Note: Note that this function may also return error codes from previous, asynchronous launches.
414
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
▶ resource - - Registered resource to set flags for
▶ flags - - Parameters for resource mapping
Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorInvalidResourceHandle, cudaErrorUn-
known,
__host__ cudaError_t cudaGraphicsSubResourceGetMappedArray(cudaArray_t *array,
cudaGraphicsResource_t
resource, unsigned int
arrayIndex, unsigned int
mipLevel)
Get an array through which to access a subresource of a mapped graphics resource.
Returns in *array an array through which the subresource of the mapped graphics resource
resource which corresponds to array index arrayIndex and mipmap level mipLevel may be
accessed. The value set in array may change every time that resource is mapped.
If resource is not a texture then it cannot be accessed via an array and cudaErrorUnknown is
returned. If arrayIndex is not a valid array index for resource then cudaErrorInvalidValue is
returned. If mipLevel is not a valid mipmap level for resource then cudaErrorInvalidValue is
returned. If resource is not mapped then cudaErrorUnknown is returned.
See also:
cudaGraphicsResourceGetMappedPointer, ::cuGraphicsSubResourceGetMappedArray
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.21. Graphics Interoperability
415
CUDA Runtime API Reference Manual, Release 13.5
Parameters
▶ array - - Returned array through which a subresource of resource may be
accessed
▶ resource - - Mapped resource to access
▶ arrayIndex - - Array index for array textures or cubemap face index as defined
by cudaGraphicsCubeFace for cubemap textures for the subresource to access
▶ mipLevel - - Mipmap level for the subresource to access
Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorInvalidResourceHandle, cudaErrorUn-
known
__host__ cudaError_t cudaGraphicsUnmapResources(int count, cudaGraphicsResource_t
*resources, cudaStream_t stream = 0)
Unmap graphics resources.
Unmaps the count graphics resources in resources.
Once unmapped, the resources in resources may not be accessed by CUDA until they are
mapped again.
This function provides the synchronization guarantee that any CUDA work issued in stream be-
fore cudaGraphicsUnmapResources() will complete before any subsequently issued graphics work
begins.
If resources contains any duplicate entries then cudaErrorInvalidResourceHandle is returned.
If any of resources are not presently mapped for access by CUDA then cudaErrorUnknown is
returned.
See also:
cudaGraphicsMapResources, ::cuGraphicsUnmapResources
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
416
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
▶ count - - Number of resources to unmap
▶ resources - - Resources to unmap
▶ stream - - Stream for synchronization
Returns
cudaSuccess, cudaErrorInvalidResourceHandle, cudaErrorUnknown
__host__ cudaError_t cudaGraphicsUnregisterResource(cudaGraphicsResource_t resource)
Unregisters a graphics resource for access by CUDA.
Unregisters the graphics resource resource so it is not accessible by CUDA unless registered
again.
If resource is invalid then cudaErrorInvalidResourceHandle is returned.
See also:
cudaGraphicsD3D9RegisterResource,
cudaGraphicsD3D10RegisterResource,
cudaGraph-
icsD3D11RegisterResource,
cudaGraphicsGLRegisterBuffer,
cudaGraphicsGLRegisterImage,
::cuGraphicsUnregisterResource
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
resource - - Resource to unregister
Returns
cudaSuccess, cudaErrorInvalidResourceHandle, cudaErrorUnknown
6.21. Graphics Interoperability
417
CUDA Runtime API Reference Manual, Release 13.5
6.22. Interactions with the CUDA Driver API
This section describes the interactions between the CUDA Driver API and the CUDA Runtime API.
6.22.1. Execution Contexts
The CUDA Runtime provides cudaExecutionContext_t as an abstraction over driver-level contexts-
specifically, green contexts and the primary context.
There are two primary ways to obtain an execution context:
▶ cudaDeviceGetExecutionCtx: Returns the execution context that corresponds to the primary
context of the specified device.
▶ cudaGreenCtxCreate: Creates a green context with the specified resources and returns an exe-
cution context.
Note: Developers should treat cudaExecutionContext_t as an opaque handle and avoid assumptions
about its underlying representation. The CUDA Runtime does not provide a way to convert this handle
into a ::CUcontext or ::CUgreenCtx.
6.22.2. Primary Context (aka Device Execution Context)
The primary context is the default execution context associated with a device in the Runtime. It can
be obtained via a call to cudaDeviceGetExecutionCtx(). There is a one-to-one mapping between CUDA
devices in the runtime and their primary contexts within a process.
From the CUDA Runtime’s perspective, a device and its primary context are functionally synonymous.
Unless explicitly overridden, either by making a different context current via the Driver API (e.g., ::cuC-
txSetCurrent()) or by using an explicit execution context handle, the Runtime will implicitly initialize
and use the primary context for API calls as needed.
6.22.3. Initialization and Tear-Down
Unless an explicit execution context is specified (see “Execution Context Management” for APIs), CUDA
Runtime API calls operate on the CUDA Driver ::CUcontext which is current to the calling host thread.
If no ::CUcontext is current to the calling thread when a CUDA Runtime API call which requires an ac-
tive context is made, then the primary context (device execution context) for a device will be selected,
made current to the calling thread, and initialized. The context will be initialized using the parameters
specified by the CUDA Runtime API functions cudaSetDeviceFlags(), cudaD3D9SetDirect3DDevice(),
cudaD3D10SetDirect3DDevice(), cudaD3D11SetDirect3DDevice(), cudaGLSetGLDevice(), and cudaVD-
PAUSetVDPAUDevice(). Note that these functions will fail with cudaErrorSetOnActiveProcess if they
are called when the primary context for the specified device has already been initialized, except for
cudaSetDeviceFlags() which will simply overwrite the previous settings.
The function cudaInitDevice() ensures that the primary context is initialized for the requested device
but does not make it current to the calling thread.
418
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
The function cudaSetDevice() initializes the primary context for the specified device and makes it cur-
rent to the calling thread by calling ::cuCtxSetCurrent().
Primary contexts will remain active until they are explicitly deinitialized using cudaDeviceReset(). The
function cudaDeviceReset() will deinitialize the primary context for the calling thread’s current device
immediately. The context will remain current to all of the threads that it was current to. The next CUDA
Runtime API call on any thread which requires an active context will trigger the reinitialization of that
device’s primary context.
Note that primary contexts are shared resources. It is recommended that the primary context not be
reset except just before exit or to recover from an unspecified launch failure.
6.22.4. CUcontext Interoperability
Note that the use of multiple ::CUcontext s per device within a single process will substantially degrade
performance and is strongly discouraged. Instead, it is highly recommended to either use execution
contexts cudaExecutionContext_t or the implicit one-to-one device-to-primary context mapping for
the process provided by the CUDA Runtime API.
If a non-primary ::CUcontext created by the CUDA Driver API is current to a thread then the CUDA
Runtime API calls to that thread will operate on that ::CUcontext, with some exceptions listed below.
Interoperability between data types is discussed in the following sections.
The function cudaDeviceEnablePeerAccess() and the rest of the peer access API may not be called
when a non-primary CUcontext is current. To use the peer access APIs with a context created using
the CUDA Driver API, it is necessary that the CUDA Driver API be used to access these features.
All CUDA Runtime API state (e.g, global variables’ addresses and values) travels with its underlying
::CUcontext. In particular, if a ::CUcontext is moved from one thread to another then all CUDA Runtime
API state will move to that thread as well.
Please note that attaching to legacy CUcontext (those with a version of 3010 as returned by ::cuC-
txGetApiVersion()) is not possible. The CUDA Runtime will return cudaErrorIncompatibleDriverContext
in such cases.
6.22.5. Interactions between CUstream and cudaStream_t
The types ::CUstream and cudaStream_t are identical and may be used interchangeably.
6.22.6. Interactions between CUevent and cudaEvent_t
The types ::CUevent and cudaEvent_t are identical and may be used interchangeably.
6.22. Interactions with the CUDA Driver API
419
CUDA Runtime API Reference Manual, Release 13.5
6.22.7. Interactions between CUarray and cudaArray_t
The types ::CUarray and struct ::cudaArray * represent the same data type and may be used inter-
changeably by casting the two types between each other.
In order to use a ::CUarray in a CUDA Runtime API function which takes a struct ::cudaArray *, it is
necessary to explicitly cast the ::CUarray to a struct ::cudaArray *.
In order to use a struct ::cudaArray * in a CUDA Driver API function which takes a ::CUarray, it is neces-
sary to explicitly cast the struct ::cudaArray * to a ::CUarray .
6.22.8. Interactions between CUgraphicsResource and
cudaGraphicsResource_t
The types ::CUgraphicsResource and cudaGraphicsResource_t represent the same data type and may
be used interchangeably by casting the two types between each other.
In order to use a ::CUgraphicsResource in a CUDA Runtime API function which takes a cudaGraphic-
sResource_t, it is necessary to explicitly cast the ::CUgraphicsResource to a cudaGraphicsResource_t.
In order to use a cudaGraphicsResource_t in a CUDA Driver API function which takes a ::CUgraphicsRe-
source, it is necessary to explicitly cast the cudaGraphicsResource_t to a ::CUgraphicsResource.
6.22.9. Interactions between CUtexObject and
cudaTextureObject_t
The types ::CUtexObject and cudaTextureObject_t represent the same data type and may be used in-
terchangeably by casting the two types between each other.
In order to use a ::CUtexObject in a CUDA Runtime API function which takes a cudaTextureObject_t, it
is necessary to explicitly cast the ::CUtexObject to a cudaTextureObject_t.
In order to use a cudaTextureObject_t in a CUDA Driver API function which takes a ::CUtexObject, it is
necessary to explicitly cast the cudaTextureObject_t to a ::CUtexObject.
6.22.10. Interactions between CUsurfObject and
cudaSurfaceObject_t
The types ::CUsurfObject and cudaSurfaceObject_t represent the same data type and may be used
interchangeably by casting the two types between each other.
In order to use a ::CUsurfObject in a CUDA Runtime API function which takes a cudaSurfaceObject_t,
it is necessary to explicitly cast the ::CUsurfObject to a cudaSurfaceObject_t.
In order to use a cudaSurfaceObject_t in a CUDA Driver API function which takes a ::CUsurfObject, it is
necessary to explicitly cast the cudaSurfaceObject_t to a ::CUsurfObject.
420
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
6.22.11. Interactions between CUfunction and
cudaFunction_t
The types ::CUfunction and cudaFunction_t represent the same data type and may be used inter-
changeably by casting the two types between each other.
In order to use a cudaFunction_t in a CUDA Driver API function which takes a ::CUfunction, it is neces-
sary to explicitly cast the cudaFunction_t to a ::CUfunction.
6.22.12. Interactions between CUkernel and cudaKernel_t
The types ::CUkernel and cudaKernel_t represent the same data type and may be used interchangeably
by casting the two types between each other.
In order to use a cudaKernel_t in a CUDA Driver API function which takes a ::CUkernel, it is necessary
to explicitly cast the cudaKernel_t to a ::CUkernel.
Functions
__host__ cudaError_t cudaGetFuncBySymbol(cudaFunction_t *functionPtr, const void *symbolPtr)
Get pointer to device entry function that matches entry function symbolPtr .
__host__ cudaError_t cudaGetKernel(cudaKernel_t *kernelPtr, const void *entryFuncAddr)
Get pointer to device kernel that matches entry function entryFuncAddr .
6.22.13. Functions
__host__ cudaError_t cudaGetFuncBySymbol(cudaFunction_t *functionPtr, const void *symbolPtr)
Get pointer to device entry function that matches entry function symbolPtr.
Returns in functionPtr the device entry function corresponding to the symbol symbolPtr.
Parameters
▶ functionPtr - - Returns the device entry function
▶ symbolPtr - - Pointer to device entry function to search for
Returns
cudaSuccess
__host__ cudaError_t cudaGetKernel(cudaKernel_t *kernelPtr, const void *entryFuncAddr)
Get pointer to device kernel that matches entry function entryFuncAddr.
Returns in kernelPtr the device kernel corresponding to the entry function entryFuncAddr.
Note that it is possible that there are multiple symbols belonging to different translation units
with the same entryFuncAddr registered with this CUDA Runtime and so the order which the
translation units are loaded and registered with the CUDA Runtime can lead to differing return
pointers in kernelPtr . Suggested methods of ensuring uniqueness are to limit visibility of
6.22. Interactions with the CUDA Driver API
421
CUDA Runtime API Reference Manual, Release 13.5
global device functions by using static or hidden visibility attribute in the respective translation
units.
See also:
cudaGetKernel (C++ API)
Parameters
▶ kernelPtr - - Returns the device kernel
▶ entryFuncAddr - - Address of device entry function to search kernel for
Returns
cudaSuccess
6.23. Library Management
This section describes the library management functions of the CUDA runtime application program-
ming interface.
Functions
__host__ cudaError_t cudaKernelSetAttributeForDevice(cudaKernel_t kernel, enum cudaFuncAt-
tribute attr, int value, int device)
Sets information about a kernel.
__host__ cudaError_t cudaLibraryEnumerateKernels(cudaKernel_t *kernels, unsigned int numKer-
nels, cudaLibrary_t lib)
Retrieve the kernel handles within a library.
__host__ cudaError_t cudaLibraryGetGlobal(void **dptr, size_t *bytes, cudaLibrary_t library, const
char *name)
Returns a global device pointer.
__host__ cudaError_t cudaLibraryGetKernel(cudaKernel_t *pKernel, cudaLibrary_t library, const char
*name)
Returns a kernel handle.
__host__ cudaError_t cudaLibraryGetKernelCount(unsigned int *count, cudaLibrary_t lib)
Returns the number of kernels within a library.
__host__ cudaError_t cudaLibraryGetManaged(void **dptr, size_t *bytes, cudaLibrary_t library, const
char *name)
Returns a pointer to managed memory.
__host__ cudaError_t cudaLibraryGetUnifiedFunction(void **fptr, cudaLibrary_t library, const char
*symbol)
Returns a pointer to a unified function.
__host__ cudaError_t cudaLibraryLoadData(cudaLibrary_t *library, const void *code, enum cudaJi-
tOption *jitOptions, void **jitOptionsValues, unsigned int numJitOptions, enum cudaLibrary-
Option *libraryOptions, void **libraryOptionValues, unsigned int numLibraryOptions)
Load a library with specified code and options.
422
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
__host__ cudaError_t cudaLibraryLoadFromFile(cudaLibrary_t *library, const char *fileName, enum
cudaJitOption *jitOptions, void **jitOptionsValues, unsigned int numJitOptions, enum cudaL-
ibraryOption *libraryOptions, void **libraryOptionValues, unsigned int numLibraryOptions)
Load a library with specified file and options.
__host__ cudaError_t cudaLibraryUnload(cudaLibrary_t library)
Unloads a library.
6.23.1. Functions
__host__ cudaError_t cudaKernelSetAttributeForDevice(cudaKernel_t kernel, enum
cudaFuncAttribute attr, int value, int
device)
Sets information about a kernel.
This call sets the value of a specified attribute attr on the kernel kernel for the requested
device device to an integer value specified by value. This function returns cudaSuccess if the
new value of the attribute could be successfully set. If the set fails, this call will return an error.
Not all attributes can have values set. Attempting to set a value on a read-only attribute will
result in an error (cudaErrorInvalidValue)
Note that attributes set using cudaFuncSetAttribute() will override the attribute set by this API
irrespective of whether the call to cudaFuncSetAttribute() is made before or after this API call.
Because of this and the stricter locking requirements mentioned below it is suggested that this
call be used during the initialization path and not on each thread accessing kernel such as on
kernel launches or on the critical path.
Valid values for attr are:
▶ cudaFuncAttributeMaxDynamicSharedMemorySize - The requested maximum size in bytes
of dynamically-allocated shared memory. The sum of this value and the function attribute
::sharedSizeBytes cannot exceed the device attribute cudaDevAttrMaxSharedMemoryPer-
BlockOptin. The maximal size of requestable dynamic shared memory may differ by GPU
architecture.
▶ cudaFuncAttributePreferredSharedMemoryCarveout - On devices where the L1 cache and
shared memory use the same hardware resources, this sets the shared memory carveout
preference, in percent of the total shared memory. See cudaDevAttrMaxSharedMemoryPer-
Multiprocessor. This is only a hint, and the driver can choose a different ratio if required to
execute the function.
▶ cudaFuncAttributeRequiredClusterWidth: The required cluster width in blocks. The width,
height, and depth values must either all be 0 or all be positive. The validity of the cluster
dimensions is checked at launch time. If the value is set during compile time, it cannot be
set at runtime. Setting it at runtime will return cudaErrorNotPermitted.
▶ cudaFuncAttributeRequiredClusterHeight: The required cluster height in blocks. The width,
height, and depth values must either all be 0 or all be positive. The validity of the cluster
dimensions is checked at launch time. If the value is set during compile time, it cannot be
set at runtime. Setting it at runtime will return cudaErrorNotPermitted.
▶ cudaFuncAttributeRequiredClusterDepth: The required cluster depth in blocks. The width,
height, and depth values must either all be 0 or all be positive. The validity of the cluster
dimensions is checked at launch time. If the value is set during compile time, it cannot be
set at runtime. Setting it at runtime will return cudaErrorNotPermitted.
6.23. Library Management
423
CUDA Runtime API Reference Manual, Release 13.5
▶ cudaFuncAttributeNonPortableClusterSizeAllowed: Indicates whether the function can be
launched with non-portable cluster size. 1 is allowed, 0 is disallowed.
▶ cudaFuncAttributeClusterSchedulingPolicyPreference: The block scheduling policy of a func-
tion. The value type is cudaClusterSchedulingPolicy.
See also:
cudaLibraryLoadData, cudaLibraryLoadFromFile, cudaLibraryUnload, cudaLibraryGetKernel, cud-
aLaunchKernel, cudaFuncSetAttribute, ::cuKernelSetAttribute
Note: The API has stricter locking requirements in comparison to its legacy counterpart cuda-
FuncSetAttribute() due to device-wide semantics. If multiple threads are trying to set the same
attribute on the same device simultaneously, the attribute setting will depend on the interleav-
ings chosen by the OS scheduler and memory consistency.
Parameters
▶ kernel - - Kernel to set attribute of
▶ attr - - Attribute requested
▶ value - - Value to set
▶ device - - Device to set attribute of
Returns
cudaSuccess, cudaErrorInvalidDeviceFunction, cudaErrorInvalidValue
__host__ cudaError_t cudaLibraryEnumerateKernels(cudaKernel_t *kernels, unsigned int
numKernels, cudaLibrary_t lib)
Retrieve the kernel handles within a library.
Returns in kernels a maximum number of numKernels kernel handles within lib. The returned
kernel handle becomes invalid when the library is unloaded.
See also:
cudaLibraryGetKernelCount, ::cuLibraryEnumerateKernels
Parameters
▶ kernels - - Buffer where the kernel handles are returned to
▶ numKernels - - Maximum number of kernel handles may be returned to the
buffer
▶ lib - - Library to query from
Returns
cudaSuccess, cudaErrorCudartUnloading, cudaErrorInitializationError, cudaErrorIn-
validValue, cudaErrorInvalidResourceHandle
424
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
__host__ cudaError_t cudaLibraryGetGlobal(void **dptr, size_t *bytes, cudaLibrary_t library, const
char *name)
Returns a global device pointer.
Returns in *dptr and *bytes the base pointer and size of the global with name name for the re-
quested library library and the current device. If no global for the requested name name exists,
the call returns cudaErrorSymbolNotFound. One of the parameters dptr or bytes (not both) can
be NULL in which case it is ignored. The returned dptr cannot be passed to the Symbol APIs such
as cudaMemcpyToSymbol, cudaMemcpyFromSymbol, cudaGetSymbolAddress, or cudaGetSymbol-
Size.
See also:
cudaLibraryLoadData, cudaLibraryLoadFromFile, cudaLibraryUnload, cudaLibraryGetManaged,
::cuLibraryGetGlobal
Parameters
▶ dptr - - Returned global device pointer for the requested library
▶ bytes - - Returned global size in bytes
▶ library - - Library to retrieve global from
▶ name - - Name of global to retrieve
Returns
cudaSuccess, cudaErrorCudartUnloading, cudaErrorInitializationError, cudaError-
InvalidValue, cudaErrorInvalidResourceHandle, cudaErrorSymbolNotFound cudaEr-
rorDeviceUninitialized, cudaErrorContextIsDestroyed
__host__ cudaError_t cudaLibraryGetKernel(cudaKernel_t *pKernel, cudaLibrary_t library, const
char *name)
Returns a kernel handle.
Returns in pKernel the handle of the kernel with name name located in library library. If kernel
handle is not found, the call returns cudaErrorSymbolNotFound.
See also:
cudaLibraryLoadData, cudaLibraryLoadFromFile, cudaLibraryUnload, ::cuLibraryGetKernel
Parameters
▶ pKernel - - Returned kernel handle
▶ library - - Library to retrieve kernel from
▶ name - - Name of kernel to retrieve
Returns
cudaSuccess, cudaErrorCudartUnloading, cudaErrorInitializationError, cudaErrorIn-
validValue, cudaErrorInvalidResourceHandle, cudaErrorSymbolNotFound
6.23. Library Management
425
CUDA Runtime API Reference Manual, Release 13.5
__host__ cudaError_t cudaLibraryGetKernelCount(unsigned int *count, cudaLibrary_t lib)
Returns the number of kernels within a library.
Returns in count the number of kernels in lib.
See also:
cudaLibraryEnumerateKernels, cudaLibraryLoadFromFile, cudaLibraryLoadData, ::cuLibraryGetK-
ernelCount
Parameters
▶ count - - Number of kernels found within the library
▶ lib - - Library to query
Returns
cudaSuccess, cudaErrorCudartUnloading, cudaErrorInitializationError, cudaErrorIn-
validValue, cudaErrorInvalidResourceHandle
__host__ cudaError_t cudaLibraryGetManaged(void **dptr, size_t *bytes, cudaLibrary_t library,
const char *name)
Returns a pointer to managed memory.
Returns in *dptr and *bytes the base pointer and size of the managed memory with name name
for the requested library library. If no managed memory with the requested name name exists,
the call returns cudaErrorSymbolNotFound. One of the parameters dptr or bytes (not both) can
be NULL in which case it is ignored. Note that managed memory for library library is shared
across devices and is registered when the library is loaded. The returned dptr cannot be passed
to the Symbol APIs such as cudaMemcpyToSymbol, cudaMemcpyFromSymbol, cudaGetSymbolAd-
dress, or cudaGetSymbolSize.
See also:
cudaLibraryLoadData, cudaLibraryLoadFromFile, cudaLibraryUnload, cudaLibraryGetGlobal, ::cuLi-
braryGetManaged
Parameters
▶ dptr - - Returned pointer to the managed memory
▶ bytes - - Returned memory size in bytes
▶ library - - Library to retrieve managed memory from
▶ name - - Name of managed memory to retrieve
Returns
cudaSuccess, cudaErrorCudartUnloading, cudaErrorInitializationError, cudaErrorIn-
validValue, cudaErrorInvalidResourceHandle, cudaErrorSymbolNotFound
__host__ cudaError_t cudaLibraryGetUnifiedFunction(void **fptr, cudaLibrary_t library, const
char *symbol)
Returns a pointer to a unified function.
426
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
Returns in *fptr the function pointer to a unified function denoted by symbol. If no unified
function with name symbol exists, the call returns cudaErrorSymbolNotFound. If there is no de-
vice with attribute cudaDeviceProp::unifiedFunctionPointers present in the system, the call may
return cudaErrorSymbolNotFound.
See also:
cudaLibraryLoadData, cudaLibraryLoadFromFile, cudaLibraryUnload, ::cuLibraryGetUnifiedFunc-
tion
Parameters
▶ fptr - - Returned pointer to a unified function
▶ library - - Library to retrieve function pointer memory from
▶ symbol - - Name of function pointer to retrieve
Returns
cudaSuccess, cudaErrorCudartUnloading, cudaErrorInitializationError, cudaErrorIn-
validValue, cudaErrorInvalidResourceHandle, cudaErrorSymbolNotFound
__host__ cudaError_t cudaLibraryLoadData(cudaLibrary_t *library, const void *code, enum
cudaJitOption *jitOptions, void **jitOptionsValues,
unsigned int numJitOptions, enum cudaLibraryOption
*libraryOptions, void **libraryOptionValues, unsigned
int numLibraryOptions)
Load a library with specified code and options.
Takes a pointer code and loads the corresponding library library based on the application de-
fined library loading mode:
▶ If module loading is set to EAGER, via the environment variables described in “Module load-
ing”, library is loaded eagerly into all contexts at the time of the call and future contexts
at the time of creation until the library is unloaded with cudaLibraryUnload().
▶ If the environment variables are set to LAZY, library is not immediately loaded onto all
existent contexts and will only be loaded when a function is needed for that context, such
as a kernel launch.
These environment variables are described in the CUDA programming guide under the “CUDA
environment variables” section.
The code may be a cubin or fatbin as output by nvcc, or a NULL-terminated PTX, either as output
by nvcc or hand-written, or Tile IR data. A fatbin should also contain relocatable code when do-
ing separate compilation. Please also see the documentation for nvrtc (https://docs.nvidia.com/
cuda/nvrtc/index.html), nvjitlink (https://docs.nvidia.com/cuda/nvjitlink/index.html ), and nvfatbin
(https://docs.nvidia.com/cuda/nvfatbin/index.html ) for more information on generating loadable
code at runtime.
Options are passed as an array via jitOptions and any corresponding parameters are passed
in jitOptionsValues. The number of total JIT options is supplied via numJitOptions. Any
outputs will be returned via jitOptionsValues.
Library load options are passed as an array via libraryOptions and any corresponding param-
eters are passed in libraryOptionValues. The number of total library load options is supplied
via numLibraryOptions.
6.23. Library Management
427
CUDA Runtime API Reference Manual, Release 13.5
See also:
cudaLibraryLoadFromFile, cudaLibraryUnload, ::cuLibraryLoadData
Parameters
▶ library - - Returned library
▶ code - - Code to load
▶ jitOptions - - Options for JIT
▶ jitOptionsValues - - Option values for JIT
▶ numJitOptions - - Number of options
▶ libraryOptions - - Options for loading
▶ libraryOptionValues - - Option values for loading
▶ numLibraryOptions - - Number of options for loading
Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorMemoryAllocation, cudaErrorInitial-
izationError, cudaErrorCudartUnloading, cudaErrorInvalidPtx, cudaErrorUnsupport-
edPtxVersion, cudaErrorNoKernelImageForDevice, cudaErrorSharedObjectSymbol-
NotFound, cudaErrorSharedObjectInitFailed, cudaErrorJitCompilerNotFound
__host__ cudaError_t cudaLibraryLoadFromFile(cudaLibrary_t *library, const char *fileName,
enum cudaJitOption *jitOptions, void
**jitOptionsValues, unsigned int numJitOptions,
enum cudaLibraryOption *libraryOptions, void
**libraryOptionValues, unsigned int
numLibraryOptions)
Load a library with specified file and options.
Takes a pointer code and loads the corresponding library library based on the application de-
fined library loading mode:
▶ If module loading is set to EAGER, via the environment variables described in “Module load-
ing”, library is loaded eagerly into all contexts at the time of the call and future contexts
at the time of creation until the library is unloaded with cudaLibraryUnload().
▶ If the environment variables are set to LAZY, library is not immediately loaded onto all
existent contexts and will only be loaded when a function is needed for that context, such
as a kernel launch.
These environment variables are described in the CUDA programming guide under the “CUDA
environment variables” section.
The file should be a cubin file as output by nvcc, or a PTX file either as output by nvcc or hand-
written, or a fatbin file as output by nvcc or hand-written, or Tile IR file. A fatbin should also
contain relocatable code when doing separate compilation. Please also see the documenta-
cuda/nvjitlink/index.html), and nvfatbin (https://docs.nvidia.com/cuda/nvfatbin/index.html ) for
more information on generating loadable code at runtime.
428
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
Options are passed as an array via jitOptions and any corresponding parameters are passed in
jitOptionsValues. The number of total options is supplied via numJitOptions. Any outputs
will be returned via jitOptionsValues.
Library load options are passed as an array via libraryOptions and any corresponding param-
eters are passed in libraryOptionValues. The number of total library load options is supplied
via numLibraryOptions.
See also:
cudaLibraryLoadData, cudaLibraryUnload, ::cuLibraryLoadFromFile
Parameters
▶ library - - Returned library
▶ fileName - - File to load from
▶ jitOptions - - Options for JIT
▶ jitOptionsValues - - Option values for JIT
▶ numJitOptions - - Number of options
▶ libraryOptions - - Options for loading
▶ libraryOptionValues - - Option values for loading
▶ numLibraryOptions - - Number of options for loading
Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorMemoryAllocation, cudaErrorInitial-
izationError, cudaErrorCudartUnloading, cudaErrorInvalidPtx, cudaErrorUnsupport-
edPtxVersion, cudaErrorNoKernelImageForDevice, cudaErrorSharedObjectSymbol-
NotFound, cudaErrorSharedObjectInitFailed, cudaErrorJitCompilerNotFound
__host__ cudaError_t cudaLibraryUnload(cudaLibrary_t library)
Unloads a library.
Unloads the library specified with library
See also:
cudaLibraryLoadData, cudaLibraryLoadFromFile, ::cuLibraryUnload
Parameters
library - - Library to unload
Returns
cudaSuccess, cudaErrorCudartUnloading, cudaErrorInitializationError, cudaErrorIn-
validValue
6.23. Library Management
429
CUDA Runtime API Reference Manual, Release 13.5
6.24. Logical Endpoint
This section describes the functions for Logical Endpoint operations management.
Functions
__device__ cudaError_t cudaFabricOpErrorStatusCount(void *status, cudaFabricOpStatusSource
statusSource, unsigned int *count)
Get the number of errors for a fabric operation.
__device__ cudaError_t cudaFabricOpErrorStatusGet(void *status, cudaFabricOpStatusSource sta-
tusSource, unsigned int statusIndex, cudaFabricOpStatusInfo *statusInfo)
Get the error status of a fabric operation.
6.24.1. Functions
__device__ cudaError_t cudaFabricOpErrorStatusCount(void *status, cudaFabricOpStatusSource
statusSource, unsigned int *count)
Get the number of errors for a fabric operation.
Given the pointer to the status field obtained from fabric operation completion object, return
the total count of errors.
Parameters
▶ status - - The pointer to the status field obtained from fabric operation com-
pletion object
▶ statusSource - - The type of the fabric operation completion object
▶ count - - The number of errors in the decoded status field
Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorNotSupported
__device__ cudaError_t cudaFabricOpErrorStatusGet(void *status, cudaFabricOpStatusSource
statusSource, unsigned int statusIndex,
cudaFabricOpStatusInfo *statusInfo)
Get the error status of a fabric operation.
Given a pointer to the status field obtained from a fabric operation completion object, retrieves
the error at index statusIndex in the decoded status field and writes it to statusInfo.
statusIndex must be in the range [0, statusCount), where statusCount is the value returned
via the count parameter of cudaFabricOpErrorStatusCount.
Parameters
▶ status - - Pointer to the status field from the fabric operation completion ob-
ject
▶ statusSource - - The type of the fabric operation completion object
430
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
▶ statusIndex - - Index of the error to retrieve (0-based; selects which of the
decoded errors to return)
▶ statusInfo - - Pointer to cudaFabricOpStatusInfo where the decoded er-
ror information is returned
Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorNotSupported
6.25. Memory Management
This section describes the memory management functions of the CUDA runtime application program-
ming interface.
Some functions have overloaded C++ API template versions documented separately in the C++ API
Routines module.
Functions
__host__ cudaError_t cudaArrayGetInfo(struct cudaChannelFormatDesc *desc, struct cudaExtent
*extent, unsigned int *flags, cudaArray_t array)
Gets info about the specified cudaArray.
__host__ cudaError_t cudaArrayGetMemoryRequirements(struct cudaArrayMemoryRequirements
*memoryRequirements, cudaArray_t array, int device)
Returns the memory requirements of a CUDA array.
__host__ cudaError_t cudaArrayGetPlane(cudaArray_t *pPlaneArray, cudaArray_t hArray, unsigned
int planeIdx)
Gets a CUDA array plane from a CUDA array.
__host__ cudaError_t cudaArrayGetSparseProperties(struct cudaArraySparseProperties *sparse-
Properties, cudaArray_t array)
Returns the layout properties of a sparse CUDA array.
__host__ cudaError_t cudaFree(void *devPtr)
Frees memory on the device.
__host__ cudaError_t cudaFreeArray(cudaArray_t array)
Frees an array on the device.
__host__ cudaError_t cudaFreeHost(void *ptr)
Frees page-locked memory.
__host__ cudaError_t cudaFreeMipmappedArray(cudaMipmappedArray_t mipmappedArray)
Frees a mipmapped array on the device.
__host__ cudaError_t cudaGetMipmappedArrayLevel(cudaArray_t *levelArray, cudaMipmappedAr-
ray_const_t mipmappedArray, unsigned int level)
Gets a mipmap level of a CUDA mipmapped array.
__host__ cudaError_t cudaGetSymbolAddress(void **devPtr, const void *symbol)
Finds the address associated with a CUDA symbol.
__host__ cudaError_t cudaGetSymbolSize(size_t *size, const void *symbol)
Finds the size of the object associated with a CUDA symbol.
6.25. Memory Management
431
CUDA Runtime API Reference Manual, Release 13.5
__host__ cudaError_t cudaHostAlloc(void **pHost, size_t size, unsigned int flags)
Allocates page-locked memory on the host.
__host__ cudaError_t cudaHostGetDevicePointer(void **pDevice, void *pHost, unsigned int flags)
Passes back device pointer of mapped host memory allocated by cudaHostAlloc or registered by
cudaHostRegister.
__host__ cudaError_t cudaHostGetFlags(unsigned int *pFlags, void *pHost)
Passes back flags used to allocate pinned host memory allocated by cudaHostAlloc.
__host__ cudaError_t cudaHostRegister(void *ptr, size_t size, unsigned int flags)
Registers an existing host memory range for use by CUDA.
__host__ cudaError_t cudaHostUnregister(void *ptr)
Unregisters a memory range that was registered with cudaHostRegister.
__host__ cudaError_t cudaMalloc(void **devPtr, size_t size)
Allocate memory on the device.
__host__ cudaError_t cudaMalloc3D(struct cudaPitchedPtr *pitchedDevPtr, struct cudaExtent ex-
tent)
Allocates logical 1D, 2D, or 3D memory objects on the device.
__host__ cudaError_t cudaMalloc3DArray(cudaArray_t *array, const struct cudaChannelFormatDesc
*desc, struct cudaExtent extent, unsigned int flags=0)
Allocate an array on the device.
__host__ cudaError_t cudaMallocArray(cudaArray_t *array, const struct cudaChannelFormatDesc
*desc, size_t width, size_t height=0, unsigned int flags=0)
Allocate an array on the device.
__host__ cudaError_t cudaMallocHost(void **ptr, size_t size)
Allocates page-locked memory on the host.
__host__ cudaError_t cudaMallocManaged(void **devPtr, size_t size, unsigned int flags=0x01)
Allocates memory that will be automatically managed by the Unified Memory system.
__host__ cudaError_t cudaMallocMipmappedArray(cudaMipmappedArray_t *mipmappedArray,
const struct cudaChannelFormatDesc *desc, struct cudaExtent extent, unsigned int num-
Levels, unsigned int flags=0)
Allocate a mipmapped array on the device.
__host__ cudaError_t cudaMallocPitch(void **devPtr, size_t *pitch, size_t width, size_t height)
Allocates pitched memory on the device.
__host__ cudaError_t cudaMemAdvise(const void *devPtr, size_t count, enum cudaMemoryAdvise
advice, struct cudaMemLocation location)
Advise about the usage of a given memory range.
__host__ cudaError_t cudaMemDiscardAndPrefetchBatchAsync(void
**dptrs,
size_t *sizes,
size_t count, struct cudaMemLocation *prefetchLocs, size_t *prefetchLocIdxs, size_t
numPrefetchLocs, unsigned long long flags, cudaStream_t stream)
Performs a batch of memory discards and prefetches asynchronously.
__host__ cudaError_t cudaMemDiscardBatchAsync(void **dptrs, size_t *sizes, size_t count, unsigned
long long flags, cudaStream_t stream)
Performs a batch of memory discards asynchronously.
__host__ cudaError_t cudaMemGetInfo(size_t *free, size_t *total)
Gets free and total device memory.
432
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
__host__ cudaError_t cudaMemGetLocationInfo(void *devPtr, size_t size, size_t summaryGranularity,
size_t samplingGranularity, struct cudaMemLocation *location_out)
Gets location information for a memory address range.
__host__ cudaError_t cudaMemPrefetchAsync(const void *devPtr, size_t count, struct cudaMemLo-
cation location, unsigned int flags, cudaStream_t stream=0)
Prefetches memory to the specified destination location.
__host__ cudaError_t cudaMemPrefetchBatchAsync(void **dptrs, size_t *sizes, size_t count, struct
cudaMemLocation *prefetchLocs, size_t *prefetchLocIdxs, size_t numPrefetchLocs, unsigned
long long flags, cudaStream_t stream)
Performs a batch of memory prefetches asynchronously.
__host__ cudaError_t cudaMemRangeGetAttribute(void *data, size_t dataSize, enum cudaMem-
RangeAttribute attribute, const void *devPtr, size_t count)
Query an attribute of a given memory range.
__host__ cudaError_t cudaMemRangeGetAttributes(void **data, size_t *dataSizes, enum cudaMem-
RangeAttribute *attributes, size_t numAttributes, const void *devPtr, size_t count)
Query attributes of a given memory range.
__host__ cudaError_t cudaMemcpy(void *dst, const void *src, size_t count, enum cudaMemcpyKind
kind)
Copies data between host and device.
__host__ cudaError_t cudaMemcpy2D(void *dst, size_t dpitch, const void *src, size_t spitch, size_t
width, size_t height, enum cudaMemcpyKind kind)
Copies data between host and device.
__host__ cudaError_t cudaMemcpy2DArrayToArray(cudaArray_t dst, size_t wOffsetDst, size_t hOff-
setDst, cudaArray_const_t src, size_t wOffsetSrc, size_t hOffsetSrc, size_t width, size_t
height, enum cudaMemcpyKind kind=cudaMemcpyDeviceToDevice)
Copies data between host and device.
__host__ cudaError_t cudaMemcpy2DAsync(void *dst, size_t dpitch, const void *src, size_t spitch,
size_t width, size_t height, enum cudaMemcpyKind kind, cudaStream_t stream=0)
Copies data between host and device.
__host__ cudaError_t cudaMemcpy2DFromArray(void *dst, size_t dpitch, cudaArray_const_t src,
size_t wOffset, size_t hOffset, size_t width, size_t height, enum cudaMemcpyKind kind)
Copies data between host and device.
__host__ cudaError_t cudaMemcpy2DFromArrayAsync(void *dst, size_t dpitch, cudaArray_const_t
src, size_t wOffset, size_t hOffset, size_t width, size_t height, enum cudaMemcpyKind kind,
cudaStream_t stream=0)
Copies data between host and device.
__host__ cudaError_t cudaMemcpy2DToArray(cudaArray_t dst, size_t wOffset, size_t hOffset, const
void *src, size_t spitch, size_t width, size_t height, enum cudaMemcpyKind kind)
Copies data between host and device.
__host__ cudaError_t cudaMemcpy2DToArrayAsync(cudaArray_t dst, size_t wOffset, size_t hOffset,
const void *src, size_t spitch, size_t width, size_t height, enum cudaMemcpyKind kind, cudaS-
tream_t stream=0)
Copies data between host and device.
__host__ cudaError_t cudaMemcpy3D(const struct cudaMemcpy3DParms *p)
Copies data between 3D objects.
__host__ cudaError_t cudaMemcpy3DAsync(const struct cudaMemcpy3DParms *p, cudaStream_t
stream=0)
6.25. Memory Management
433
CUDA Runtime API Reference Manual, Release 13.5
Copies data between 3D objects.
__host__ cudaError_t cudaMemcpy3DBatchAsync(size_t numOps, struct cudaMemcpy3DBatchOp
*opList, unsigned long long flags, cudaStream_t stream)
Performs a batch of 3D memory copies asynchronously.
__host__ cudaError_t cudaMemcpy3DPeer(const struct cudaMemcpy3DPeerParms *p)
Copies memory between devices.
__host__ cudaError_t cudaMemcpy3DPeerAsync(const struct cudaMemcpy3DPeerParms *p, cudaS-
tream_t stream=0)
Copies memory between devices asynchronously.
__host__ cudaError_t cudaMemcpy3DWithAttributesAsync(struct cudaMemcpy3DBatchOp *op, un-
signed long long flags, cudaStream_t stream)
Performs 3D asynchronous memory copy with the specified attributes.
__host__ cudaError_t cudaMemcpyAsync(void *dst, const void *src, size_t count, enum cudaMem-
cpyKind kind, cudaStream_t stream=0)
Copies data between host and device.
__host__ cudaError_t cudaMemcpyBatchAsync(void *const *dsts, const void *const *srcs, const
size_t *sizes, size_t count, struct cudaMemcpyAttributes *attrs, size_t *attrsIdxs, size_t nu-
mAttrs, cudaStream_t stream)
Performs a batch of memory copies asynchronously.
__host__ cudaError_t cudaMemcpyFromSymbol(void *dst, const void *symbol, size_t count, size_t
offset=0, enum cudaMemcpyKind kind=cudaMemcpyDeviceToHost)
Copies data from the given symbol on the device.
__host__ cudaError_t cudaMemcpyFromSymbolAsync(void *dst, const void *symbol, size_t count,
size_t offset, enum cudaMemcpyKind kind, cudaStream_t stream=0)
Copies data from the given symbol on the device.
__host__ cudaError_t cudaMemcpyPeer(void *dst, int dstDevice, const void *src, int srcDevice, size_t
count)
Copies memory between two devices.
__host__ cudaError_t cudaMemcpyPeerAsync(void *dst, int dstDevice, const void *src, int srcDevice,
size_t count, cudaStream_t stream=0)
Copies memory between two devices asynchronously.
__host__ cudaError_t cudaMemcpyToSymbol(const void *symbol, const void *src, size_t count, size_t
offset=0, enum cudaMemcpyKind kind=cudaMemcpyHostToDevice)
Copies data to the given symbol on the device.
__host__ cudaError_t cudaMemcpyToSymbolAsync(const void *symbol, const void *src, size_t count,
size_t offset, enum cudaMemcpyKind kind, cudaStream_t stream=0)
Copies data to the given symbol on the device.
__host__ cudaError_t cudaMemcpyWithAttributesAsync(void *dst, const void *src, size_t size, struct
cudaMemcpyAttributes *attr, cudaStream_t stream)
Performs asynchronous memory copy operation with the specified attributes.
__host__ cudaError_t cudaMemset(void *devPtr, int value, size_t count)
Initializes or sets device memory to a value.
__host__ cudaError_t cudaMemset2D(void *devPtr, size_t pitch, int value, size_t width, size_t height)
Initializes or sets device memory to a value.
434
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
__host__ cudaError_t cudaMemset2DAsync(void *devPtr, size_t pitch, int value, size_t width, size_t
height, cudaStream_t stream=0)
Initializes or sets device memory to a value.
__host__ cudaError_t cudaMemset3D(struct cudaPitchedPtr pitchedDevPtr, int value, struct cud-
aExtent extent)
Initializes or sets device memory to a value.
__host__ cudaError_t cudaMemset3DAsync(struct cudaPitchedPtr pitchedDevPtr, int value, struct
cudaExtent extent, cudaStream_t stream=0)
Initializes or sets device memory to a value.
__host__ cudaError_t cudaMemsetAsync(void *devPtr, int value, size_t count, cudaStream_t
stream=0)
Initializes or sets device memory to a value.
__host__ cudaError_t cudaMipmappedArrayGetMemoryRequirements(struct cudaArrayMemoryRe-
quirements *memoryRequirements, cudaMipmappedArray_t mipmap, int device)
Returns the memory requirements of a CUDA mipmapped array.
__host__ cudaError_t cudaMipmappedArrayGetSparseProperties(struct cudaArraySparseProperties
*sparseProperties, cudaMipmappedArray_t mipmap)
Returns the layout properties of a sparse CUDA mipmapped array.
__host__ struct cudaExtent make_cudaExtent(size_t w, size_t h, size_t d)
Returns a cudaExtent based on input parameters.
__host__ struct cudaPitchedPtr make_cudaPitchedPtr(void *d, size_t p, size_t xsz, size_t ysz)
Returns a cudaPitchedPtr based on input parameters.
__host__ struct cudaPos make_cudaPos(size_t x, size_t y, size_t z)
Returns a cudaPos based on input parameters.
6.25.1. Functions
__host__ cudaError_t cudaArrayGetInfo(struct cudaChannelFormatDesc *desc, struct cudaExtent
*extent, unsigned int *flags, cudaArray_t array)
Gets info about the specified cudaArray.
Returns in *desc, *extent and *flags respectively, the type, shape and flags of array.
Any of *desc, *extent and *flags may be specified as NULL.
See also:
::cuArrayGetDescriptor, ::cuArray3DGetDescriptor
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.25. Memory Management
435
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
▶ desc - - Returned array type
▶ extent - - Returned array shape. 2D arrays will have depth of zero
▶ flags - - Returned array flags
▶ array - - The ::cudaArray to get info for
Returns
cudaSuccess, cudaErrorInvalidValue
__host__ cudaError_t cudaArrayGetMemoryRequirements(struct cudaArrayMemoryRequirements
*memoryRequirements, cudaArray_t
array, int device)
Returns the memory requirements of a CUDA array.
Returns the memory requirements of a CUDA array in memoryRequirements If the CUDA array
is not allocated with flag cudaArrayDeferredMapping cudaErrorInvalidValue will be returned.
The returned value in cudaArrayMemoryRequirements::size represents the total size of the CUDA
array. The returned value in cudaArrayMemoryRequirements::alignment represents the alignment
necessary for mapping the CUDA array.
See also:
cudaMipmappedArrayGetMemoryRequirements
Parameters
▶ memoryRequirements - [out] - Pointer to cudaArrayMemoryRequirements
▶ array - [in] - CUDA array to get the memory requirements of
▶ device - [in] - Device to get the memory requirements for
Returns
cudaSuccess cudaErrorInvalidValue
__host__ cudaError_t cudaArrayGetPlane(cudaArray_t *pPlaneArray, cudaArray_t hArray, unsigned
int planeIdx)
Gets a CUDA array plane from a CUDA array.
Returns in pPlaneArray a CUDA array that represents a single format plane of the CUDA array
hArray.
If planeIdx is greater than the maximum number of planes in this array or if the array does
not have a multi-planar format e.g: cudaChannelFormatKindNV12, then cudaErrorInvalidValue is
returned.
436
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
Note that if the hArray has format cudaChannelFormatKindNV12, then passing in 0 for
planeIdx returns a CUDA array of the same size as hArray but with one 8-bit channel and cud-
aChannelFormatKindUnsigned as its format kind. If 1 is passed for planeIdx, then the returned
CUDA array has half the height and width of hArray with two 8-bit channels and cudaChan-
nelFormatKindUnsigned as its format kind.
See also:
::cuArrayGetPlane
Note: Note that this function may also return error codes from previous, asynchronous launches.
Parameters
▶ pPlaneArray - - Returned CUDA array referenced by the planeIdx
▶ hArray - - CUDA array
▶ planeIdx - - Plane index
Returns
cudaSuccess, cudaErrorInvalidValue cudaErrorInvalidResourceHandle
__host__ cudaError_t cudaArrayGetSparseProperties(struct cudaArraySparseProperties
*sparseProperties, cudaArray_t array)
Returns the layout properties of a sparse CUDA array.
Returns the layout properties of a sparse CUDA array in sparseProperties. If the CUDA array
is not allocated with flag cudaArraySparse cudaErrorInvalidValue will be returned.
If the returned value in cudaArraySparseProperties::flags contains cudaArraySparsePropertiesS-
ingleMipTail, then cudaArraySparseProperties::miptailSize represents the total size of the array.
Otherwise, it will be zero. Also, the returned value in cudaArraySparseProperties::miptailFirstLevel
is always zero. Note that the array must have been allocated using cudaMallocArray or cud-
aMalloc3DArray. For CUDA arrays obtained using ::cudaMipmappedArrayGetLevel, cudaErrorIn-
validValue will be returned. Instead, cudaMipmappedArrayGetSparseProperties must be used to
obtain the sparse properties of the entire CUDA mipmapped array to which array belongs to.
See also:
cudaMipmappedArrayGetSparseProperties, ::cuMemMapArrayAsync
Parameters
▶ sparseProperties - [out] - Pointer to return the cudaArraySparseProperties
▶ array - [in] - The CUDA array to get the sparse properties of
Returns
cudaSuccess cudaErrorInvalidValue
6.25. Memory Management
437

 

 

 

 

 

 

 

Content      ..     4      5      6      7     ..