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

 

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

 

Search            copyright infringement  

 

   

 

   

 

Content      ..     1      2      3      4      ..

 

 

 

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

 

 

CUDA Runtime API Reference Manual, Release 13.5
enumerator cudaJitWallTime = 2
Overwrites the option value with the total wall clock time, in milliseconds, spent in the com-
piler and linker
Option type: float
Applies to: compiler and linker.
enumerator cudaJitInfoLogBuffer = 3
Pointer to a buffer in which to print any log messages that are informational in nature (the
buffer size is specified via option cudaJitInfoLogBufferSizeBytes )
Option type: char *
Applies to: compiler and linker.
enumerator cudaJitInfoLogBufferSizeBytes = 4
IN: Log buffer size in bytes.
Log messages will be capped at this size (including null terminator)
OUT: Amount of log buffer filled with messages
Option type: unsigned int
Applies to: compiler and linker
enumerator cudaJitErrorLogBuffer = 5
Pointer to a buffer in which to print any log messages that reflect errors (the buffer size is
specified via option cudaJitErrorLogBufferSizeBytes )
Option type: char *
Applies to: compiler and linker.
enumerator cudaJitErrorLogBufferSizeBytes = 6
IN: Log buffer size in bytes.
Log messages will be capped at this size (including null terminator)
OUT: Amount of log buffer filled with messages
Option type: unsigned int
Applies to: compiler and linker
enumerator cudaJitOptimizationLevel = 7
Level of optimizations to apply to generated code (0 - 4), with 4 being the default and highest
level of optimizations.
Option type: unsigned int
Applies to: compiler only
6.2. Data types used by CUDA Runtime
147
CUDA Runtime API Reference Manual, Release 13.5
enumerator cudaJitFallbackStrategy = 10
Specifies choice of fallback strategy if matching cubin is not found.
Choice is based on supplied cudaJit_Fallback. Option type: unsigned int for enumerated
type cudaJit_Fallback Applies to: compiler only
enumerator cudaJitGenerateDebugInfo = 11
Specifies whether to create debug information in output (-g) (0: false, default)
Option type: int
Applies to: compiler and linker.
enumerator cudaJitLogVerbose = 12
Generate verbose log messages (0: false, default)
Option type: int
Applies to: compiler and linker.
enumerator cudaJitGenerateLineInfo = 13
Generate line number information (-lineinfo) (0: false, default)
Option type: int
Applies to: compiler only.
enumerator cudaJitCacheMode = 14
Specifies whether to enable caching explicitly (-dlcm)
Choice is based on supplied cudaJit_CacheMode.
Option type: unsigned int for enumerated type cudaJit_CacheMode Applies to: compiler
only
enumerator cudaJitPositionIndependentCode = 30
Generate position independent code (0: false)
Option type: int
Applies to: compiler only.
enumerator cudaJitMinCtaPerSm = 31
This option hints to the JIT compiler the minimum number of CTAs from the kernel’s grid to
be mapped to a SM.
This option is ignored when used together with cudaJitMaxRegisters or cudaJit-
ThreadsPerBlock. Optimizations based on this option need cudaJitMaxThreadsPerBlock to
be specified as well. For kernels already using PTX directive .minnctapersm, this option will
be ignored by default. Use cudaJitOverrideDirectiveValues to let this option take precedence
over the PTX directive. Option type: unsigned int
Applies to: compiler only
148
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
enumerator cudaJitMaxThreadsPerBlock = 32
Maximum number threads in a thread block, computed as the product of the maximum
extent specifed for each dimension of the block.
This limit is guaranteed not to be exeeded in any invocation of the kernel. Exceeding the the
maximum number of threads results in runtime error or kernel launch failure. For kernels
already using PTX directive .maxntid, this option will be ignored by default. Use cudaJitOver-
rideDirectiveValues to let this option take precedence over the PTX directive. Option type:
int
Applies to: compiler only
enumerator cudaJitOverrideDirectiveValues = 33
This option lets the values specified using cudaJitMaxRegisters, cudaJitThreadsPerBlock,
cudaJitMaxThreadsPerBlock and cudaJitMinCtaPerSm take precedence over any PTX direc-
tives.
(0: Disable, default; 1: Enable) Option type: int
Applies to: compiler only
enum cudaJit_CacheMode
Caching modes for dlcm.
Values:
enumerator cudaJitCacheOptionNone = 0
Compile with no -dlcm flag specified.
enumerator cudaJitCacheOptionCG
Compile with L1 cache disabled.
enumerator cudaJitCacheOptionCA
Compile with L1 cache enabled.
enum cudaJit_Fallback
Cubin matching fallback strategies.
Values:
enumerator cudaPreferPtx = 0
Prefer to compile ptx if exact binary match not found.
enumerator cudaPreferBinary
Prefer to fall back to compatible binary code if exact match not found.
enum cudaKernelFunctionType
CUDA Kernel Function Handle Type.
Values:
6.2. Data types used by CUDA Runtime
149
CUDA Runtime API Reference Manual, Release 13.5
enumerator cudaKernelFunctionTypeUnspecified = 0x00
CUDA will attempt to deduce the type of the function handle.
enumerator cudaKernelFunctionTypeDeviceEntry = 0x01
Function handle is a device-entry function pointer(i.e.
global function pointer)
enumerator cudaKernelFunctionTypeKernel = 0x02
Function handle is a cudaKernel_t.
enumerator cudaKernelFunctionTypeFunction = 0x03
Function handle is a cudaFunction_t.
enum cudaLaunchAttributeID
Launch attributes enum; used as id field of cudaLaunchAttribute.
Values:
enumerator cudaLaunchAttributeIgnore = 0
Ignored entry, for convenient composition.
enumerator cudaLaunchAttributeAccessPolicyWindow = 1
Valid for streams, graph nodes, launches.
See cudaLaunchAttributeValue::accessPolicyWindow.
enumerator cudaLaunchAttributeCooperative = 2
Valid for graph nodes, launches.
See cudaLaunchAttributeValue::cooperative.
enumerator cudaLaunchAttributeSynchronizationPolicy = 3
Valid for streams.
See cudaLaunchAttributeValue::syncPolicy.
enumerator cudaLaunchAttributeClusterDimension = 4
Valid for graph nodes, launches.
See cudaLaunchAttributeValue::clusterDim.
enumerator cudaLaunchAttributeClusterSchedulingPolicyPreference = 5
Valid for graph nodes, launches.
See cudaLaunchAttributeValue::clusterSchedulingPolicyPreference.
enumerator cudaLaunchAttributeProgrammaticStreamSerialization = 6
Valid for launches.
150
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
Setting cudaLaunchAttributeValue::programmaticStreamSerializationAllowed to non-0 sig-
nals that the kernel will use programmatic means to resolve its stream dependency, so that
the CUDA runtime should opportunistically allow the grid’s execution to overlap with the
previous kernel in the stream, if that kernel requests the overlap. The dependent launches
can choose to wait on the dependency using the programmatic sync (cudaGridDependen-
cySynchronize() or equivalent PTX instructions).
enumerator cudaLaunchAttributeProgrammaticEvent = 7
Valid for launches.
Set cudaLaunchAttributeValue::programmaticEvent to record the event. Event recorded
through this launch attribute is guaranteed to only trigger after all block in the associated
kernel trigger the event. A block can trigger the event programmatically in a future CUDA
release. A trigger can also be inserted at the beginning of each block’s execution if trigger-
AtBlockStart is set to non-0. The dependent launches can choose to wait on the depen-
dency using the programmatic sync (cudaGridDependencySynchronize() or equivalent PTX
instructions). Note that dependents (including the CPU thread calling cudaEventSynchro-
nize()) are not guaranteed to observe the release precisely when it is released. For example,
cudaEventSynchronize() may only observe the event trigger long after the associated ker-
nel has completed. This recording type is primarily meant for establishing programmatic
dependency between device tasks. Note also this type of dependency allows, but does not
guarantee, concurrent execution of tasks.
The event supplied must not be an interprocess or interop event. The event must disable
timing (i.e. must be created with the cudaEventDisableTiming flag set).
enumerator cudaLaunchAttributePriority = 8
Valid for streams, graph nodes, launches.
See cudaLaunchAttributeValue::priority.
enumerator cudaLaunchAttributeMemSyncDomainMap = 9
Valid for streams, graph nodes, launches.
See cudaLaunchAttributeValue::memSyncDomainMap.
enumerator cudaLaunchAttributeMemSyncDomain = 10
Valid for streams, graph nodes, launches.
See cudaLaunchAttributeValue::memSyncDomain.
enumerator cudaLaunchAttributePreferredClusterDimension = 11
Valid for graph nodes and launches.
Set cudaLaunchAttributeValue::preferredClusterDim to allow the kernel launch to specify a
preferred substitute cluster dimension. Blocks may be grouped according to either the di-
mensions specified with this attribute (grouped into a “preferred substitute cluster”), or the
one specified with cudaLaunchAttributeClusterDimension attribute (grouped into a “regular
cluster”). The cluster dimensions of a “preferred substitute cluster” shall be an integer mul-
tiple greater than zero of the regular cluster dimensions. The device will attempt - on a best-
effort basis - to group thread blocks into preferred clusters over grouping them into regular
clusters. When it deems necessary (primarily when the device temporarily runs out of phys-
ical resources to launch the larger preferred clusters), the device may switch to launch the
regular clusters instead to attempt to utilize as much of the physical device resources as
possible.
6.2. Data types used by CUDA Runtime
151
CUDA Runtime API Reference Manual, Release 13.5
Each type of cluster will have its enumeration / coordinate setup as if the grid consists solely
of its type of cluster. For example, if the preferred substitute cluster dimensions double
the regular cluster dimensions, there might be simultaneously a regular cluster indexed at
(1,0,0), and a preferred cluster indexed at (1,0,0). In this example, the preferred substitute
cluster (1,0,0) replaces regular clusters (2,0,0) and (3,0,0) and groups their blocks.
This attribute will only take effect when a regular cluster dimension has been specified.
The preferred substitute cluster dimension must be an integer multiple greater than zero
of the regular cluster dimension and must divide the grid. It must also be no more than
maxBlocksPerCluster, if it is set in the kernel’s __launch_bounds__. Otherwise it must
be less than the maximum value the driver can support. Otherwise, setting this attribute to
a value physically unable to fit on any particular device is permitted.
enumerator cudaLaunchAttributeLaunchCompletionEvent = 12
Valid for launches.
Set cudaLaunchAttributeValue::launchCompletionEvent to record the event.
Nominally, the event is triggered once all blocks of the kernel have begun execution. Cur-
rently this is a best effort. If a kernel B has a launch completion dependency on a kernel A,
B may wait until A is complete. Alternatively, blocks of B may begin before all blocks of A
have begun, for example if B can claim execution resources unavailable to A (e.g. they run
on different GPUs) or if B is a higher priority than A. Exercise caution if such an ordering
inversion could lead to deadlock.
A launch completion event is nominally similar to a programmatic event with triggerAt-
BlockStart set except that it is not visible to cudaGridDependencySynchronize() and
can be used with compute capability less than 9.0.
The event supplied must not be an interprocess or interop event. The event must disable
timing (i.e. must be created with the cudaEventDisableTiming flag set).
enumerator cudaLaunchAttributeDeviceUpdatableKernelNode = 13
Valid for graph nodes, launches.
This attribute is graphs-only, and passing it to a launch in a non-capturing stream will result
in an error.
:cudaLaunchAttributeValue::deviceUpdatableKernelNode::deviceUpdatable can only be set
to 0 or 1. Setting the field to 1 indicates that the corresponding kernel node should
be device-updatable. On success, a handle will be returned via ::cudaLaunchAttribute-
Value::deviceUpdatableKernelNode::devNode which can be passed to the various device-side
update functions to update the node’s kernel parameters from within another kernel. For
more information on the types of device updates that can be made, as well as the relevant
limitations thereof, see cudaGraphKernelNodeUpdatesApply .
Nodes which are device-updatable have additional restrictions compared to regular ker-
nel nodes. Firstly, device-updatable nodes cannot be removed from their graph via cuda-
GraphDestroyNode. Additionally, once opted-in to this functionality, a node cannot opt out,
and any attempt to set the deviceUpdatable attribute to 0 will result in an error. Device-
updatable kernel nodes also cannot have their attributes copied to/from another kernel node
via cudaGraphKernelNodeCopyAttributes. Graphs containing one or more device-updatable
nodes also do not allow multiple instantiation, and neither the graph nor its instantiated
version can be passed to cudaGraphExecUpdate .
152
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
If a graph contains device-updatable nodes and updates those nodes from the device from
within the graph, the graph must be uploaded with ::cuGraphUpload before it is launched.
For such a graph, if host-side executable graph updates are made to the device-updatable
nodes, the graph must be uploaded before it is launched again.
enumerator cudaLaunchAttributePreferredSharedMemoryCarveout = 14
Valid for launches.
On devices where the L1 cache and shared memory use the same hardware resources, set-
ting cudaLaunchAttributeValue::sharedMemCarveout to a percentage between 0-100 sig-
nals sets the shared memory carveout preference in percent of the total shared memory
for that kernel launch. This attribute takes precedence over cudaFuncAttributePreferred-
SharedMemoryCarveout. This is only a hint, and the driver can choose a different configura-
tion if required for the launch.
enumerator cudaLaunchAttributeNvlinkUtilCentricScheduling = 16
Valid for streams, graph nodes, launches.
This attribute is a hint to the CUDA runtime that the launch should attempt to make the
kernel maximize its NVLINK utilization.
When possible to honor this hint, CUDA will assume each block in the grid launch will carry
out an even amount of NVLINK traffic, and make a best-effort attempt to adjust the kernel
launch based on that assumption.
This attribute is a hint only. CUDA makes no functional or performance guarantee. Its appli-
cability can be affected by many different factors, including driver version (i.e. CUDA doesn’t
guarantee the performance characteristics will be maintained between driver versions or a
driver update could alter or regress previously observed perf characteristics.) It also doesn’t
guarantee a successful result, i.e. applying the attribute may not improve the performance
of either the targeted kernel or the encapsulating application.
Valid values for cudaLaunchAttributeValue::nvlinkUtilCentricScheduling are 0 (disabled) and
1 (enabled).
enumerator cudaLaunchAttributePortableClusterSizeMode = 17
Valid for graph nodes, launches.
This indicates whether the kernel launch is allowed to use a non-portable cluster size. Valid
values for cudaLaunchAttributeValue::portableClusterSizeMode are values for cudaLaun-
chAttributePortableClusterMode Any other value will return cudaErrorInvalidValue
enumerator cudaLaunchAttributeSharedMemoryMode = 18
Valid for graph nodes, launches.
This indicates that the kernel launch is allowed to use a non-portable shared memory mode.
enum cudaLaunchAttributePortableClusterMode
Enum for defining applicability of portable cluster size, used with cudaLaunchKernelEx.
Values:
enumerator cudaLaunchPortableClusterModeDefault = 0
6.2. Data types used by CUDA Runtime
153
CUDA Runtime API Reference Manual, Release 13.5
The default to use for allowing non-portable cluster size on launch - uses current function
attribute for cudaFuncAttributeNonPortableClusterSizeAllowed.
enumerator cudaLaunchPortableClusterModeRequirePortable = 1
Specifies that the cluster size requested must be a portable size.
enumerator cudaLaunchPortableClusterModeAllowNonPortable = 2
Specifies that the cluster size requested may be a non-portable size.
enum cudaLaunchMemSyncDomain
Memory Synchronization Domain.
A kernel can be launched in a specified memory synchronization domain that affects all memory
operations issued by that kernel. A memory barrier issued in one domain will only order mem-
ory operations in that domain, thus eliminating latency increase from memory barriers ordering
unrelated traffic.
By default, kernels are launched in domain 0. Kernel launched with cudaLaunchMemSyncDo-
mainRemote will have a different domain ID. User may also alter the domain ID with cudaLaunch-
MemSyncDomainMap for a specific stream / graph node / kernel launch. See cudaLaunchAt-
tributeMemSyncDomain, cudaStreamSetAttribute, cudaLaunchKernelEx, cudaGraphKernelNode-
SetAttribute.
Memory operations done in kernels launched in different domains are considered system-scope
distanced. In other words, a GPU scoped memory synchronization is not sufficient for memory
order to be observed by kernels in another memory synchronization domain even if they are on
the same GPU.
Values:
enumerator cudaLaunchMemSyncDomainDefault = 0
Launch kernels in the default domain.
enumerator cudaLaunchMemSyncDomainRemote = 1
Launch kernels in the remote domain.
enum cudaLibraryOption
Library options to be specified with cudaLibraryLoadData() or cudaLibraryLoadFromFile()
Values:
enumerator cudaLibraryHostUniversalFunctionAndDataTable = 0
enumerator cudaLibraryBinaryIsPreserved = 1
Specifes that the argument code passed to cudaLibraryLoadData() will be preserved.
Specifying this option will let the driver know that code can be accessed at any point un-
til cudaLibraryUnload(). The default behavior is for the driver to allocate and maintain its
own copy of code. Note that this is only a memory usage optimization hint and the driver
can choose to ignore it if required. Specifying this option with cudaLibraryLoadFromFile() is
invalid and will return cudaErrorInvalidValue.
154
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
enum cudaLimit
CUDA Limits.
Values:
enumerator cudaLimitStackSize = 0x00
GPU thread stack size.
enumerator cudaLimitPrintfFifoSize = 0x01
GPU printf FIFO size.
enumerator cudaLimitMallocHeapSize = 0x02
GPU malloc heap size.
enumerator cudaLimitDevRuntimeSyncDepth = 0x03
GPU device runtime synchronize depth.
enumerator cudaLimitDevRuntimePendingLaunchCount = 0x04
GPU device runtime pending launch count.
enumerator cudaLimitMaxL2FetchGranularity = 0x05
A value between 0 and 128 that indicates the maximum fetch granularity of L2 (in Bytes).
This is a hint
enumerator cudaLimitPersistingL2CacheSize = 0x06
A size in bytes for L2 persisting lines cache size.
enumerator cudaLimitPerBlockMemorySize = 0x0A
Per-block memory size.
enum cudaLogLevel
Values:
enumerator cudaLogLevelError = 0
enumerator cudaLogLevelWarning = 1
enum cudaMemAccessFlags
Specifies the memory protection flags for mapping.
Values:
enumerator cudaMemAccessFlagsProtNone = 0
Default, make the address range not accessible.
6.2. Data types used by CUDA Runtime
155
CUDA Runtime API Reference Manual, Release 13.5
enumerator cudaMemAccessFlagsProtRead = 1
Make the address range read accessible.
enumerator cudaMemAccessFlagsProtReadWrite = 3
Make the address range read-write accessible.
enum cudaMemAllocationHandleType
Flags for specifying particular handle types.
Values:
enumerator cudaMemHandleTypeNone = 0x0
Does not allow any export mechanism.
>
enumerator cudaMemHandleTypePosixFileDescriptor = 0x1
Allows a file descriptor to be used for exporting.
Permitted only on POSIX systems. (int)
enumerator cudaMemHandleTypeWin32 = 0x2
Allows a Win32 NT handle to be used for exporting.
(HANDLE)
enumerator cudaMemHandleTypeWin32Kmt = 0x4
Allows a Win32 KMT handle to be used for exporting.
(D3DKMT_HANDLE)
enumerator cudaMemHandleTypeFabric = 0x8
Allows a fabric handle to be used for exporting.
(cudaMemFabricHandle_t)
enum cudaMemAllocationType
Defines the allocation types available.
Values:
enumerator cudaMemAllocationTypeInvalid = 0x0
enumerator cudaMemAllocationTypePinned = 0x1
This allocation type is ‘pinned’, i.e.
cannot migrate from its current location while the application is actively using it
enumerator cudaMemAllocationTypeManaged = 0x2
This allocation type is managed memory.
156
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
enumerator cudaMemAllocationTypeMax = 0x7FFFFFFF
enum cudaMemLocationType
Specifies the type of location.
Values:
enumerator cudaMemLocationTypeInvalid = 0
enumerator cudaMemLocationTypeNone = 0
Location is unspecified.
This is used when creating a managed memory pool to indicate no preferred location for the
pool
enumerator cudaMemLocationTypeDevice = 1
Location is a device location, thus id is a device ordinal.
enumerator cudaMemLocationTypeHost = 2
Location is host, id is ignored.
enumerator cudaMemLocationTypeHostNuma = 3
Location is a host NUMA node, thus id is a host NUMA node id.
enumerator cudaMemLocationTypeHostNumaCurrent = 4
Location is the host NUMA node closest to the current thread’s CPU, id is ignored.
enumerator cudaMemLocationTypeInvisible = 5
Location is not visible but device is accessible, id is always cudaInvalidDeviceId.
enumerator cudaMemLocationTypeDeviceLocalityDomain = 6
Location is a portion of device memory, specified by the locality domain ID.
enum cudaMemPoolAttr
CUDA memory pool attributes.
Values:
enumerator cudaMemPoolReuseFollowEventDependencies = 0x1
(value type = int) Allow cuMemAllocAsync to use memory asynchronously freed in another
streams as long as a stream ordering dependency of the allocating stream on the free action
exists.
Cuda events and null stream interactions can create the required stream ordered depen-
dencies. (default enabled)
enumerator cudaMemPoolReuseAllowOpportunistic = 0x2
(value type = int) Allow reuse of already completed frees when there is no dependency be-
tween the free and allocation.
6.2. Data types used by CUDA Runtime
157
CUDA Runtime API Reference Manual, Release 13.5
(default enabled)
enumerator cudaMemPoolReuseAllowInternalDependencies = 0x3
(value type = int) Allow cuMemAllocAsync to insert new stream dependencies in order to
establish the stream ordering required to reuse a piece of memory released by cuFreeAsync
(default enabled).
enumerator cudaMemPoolAttrReleaseThreshold = 0x4
(value type = cuuint64_t) Amount of reserved memory in bytes to hold onto before trying to
release memory back to the OS.
When more than the release threshold bytes of memory are held by the memory pool, the
allocator will try to release memory back to the OS on the next call to stream, event or
context synchronize. (default 0)
enumerator cudaMemPoolAttrReservedMemCurrent = 0x5
(value type = cuuint64_t) Amount of backing memory currently allocated for the mempool.
enumerator cudaMemPoolAttrReservedMemHigh = 0x6
(value type = cuuint64_t) High watermark of backing memory allocated for the mempool
since the last time it was reset.
High watermark can only be reset to zero.
enumerator cudaMemPoolAttrUsedMemCurrent = 0x7
(value type = cuuint64_t) Amount of memory from the pool that is currently in use by the
application.
enumerator cudaMemPoolAttrUsedMemHigh = 0x8
(value type = cuuint64_t) High watermark of the amount of memory from the pool that was
in use by the application since the last time it was reset.
High watermark can only be reset to zero.
enumerator cudaMemPoolAttrAllocationType = 0x9
(value type = cudaMemAllocationType) The allocation type of the mempool
enumerator cudaMemPoolAttrExportHandleTypes = 0xA
(value type = cudaMemAllocationHandleType) Available export handle types for the mem-
pool.
For imported pools this value is always cudaMemHandleTypeNone as an imported pool can-
not be re-exported
enumerator cudaMemPoolAttrLocationId = 0xB
(value type = int) The location id for the mempool.
If the location type for this pool is cudaMemLocationTypeInvisible then ID will be cudaIn-
validDeviceId
158
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
enumerator cudaMemPoolAttrLocationType = 0xC
(value type = cudaMemLocationType) The location type for the mempool.
For imported memory pools where the device is not directly visible to the importing process
or pools imported via fabric handles across nodes this will be cudaMemLocationTypeInvisible
enumerator cudaMemPoolAttrMaxPoolSize = 0xD
(value type = cuuint64_t) Maximum size of the pool in bytes, this value may be higher than
what was initially passed to cudaMemPoolCreate due to alignment requirements.
A value of 0 indicates no maximum size. For cudaMemAllocationTypeManaged and IPC im-
ported pools this value will be system dependent.
enumerator cudaMemPoolAttrHwDecompressEnabled = 0xE
(value type = int) Indicates whether the pool has hardware compresssion enabled
enumerator cudaMemPoolAttrLocalityDomainId = 0xF
(value type = int) The locality domain id for the mempool, if the mempool is localized to a
locality domain.
A value of -1 indicates that the mempool is not localized to a locality domain.
enum cudaMemRangeAttribute
CUDA range attributes.
Values:
enumerator cudaMemRangeAttributeReadMostly = 1
Whether the range will mostly be read and only occassionally be written to.
enumerator cudaMemRangeAttributePreferredLocation = 2
The preferred location of the range.
enumerator cudaMemRangeAttributeAccessedBy = 3
Memory range has cudaMemAdviseSetAccessedBy set for specified device.
enumerator cudaMemRangeAttributeLastPrefetchLocation = 4
The last location to which the range was prefetched.
enumerator cudaMemRangeAttributePreferredLocationType = 5
The preferred location type of the range.
enumerator cudaMemRangeAttributePreferredLocationId = 6
The preferred location id of the range.
enumerator cudaMemRangeAttributeLastPrefetchLocationType = 7
The last location type to which the range was prefetched.
6.2. Data types used by CUDA Runtime
159
CUDA Runtime API Reference Manual, Release 13.5
enumerator cudaMemRangeAttributeLastPrefetchLocationId = 8
The last location id to which the range was prefetched.
enum cudaMemcpy3DOperandType
These flags allow applications to convey the operand type for individual copies specified in cud-
aMemcpy3DBatchAsync.
Values:
enumerator cudaMemcpyOperandTypePointer = 0x1
Memcpy operand is a valid pointer.
enumerator cudaMemcpyOperandTypeArray = 0x2
Memcpy operand is a CUarray.
enumerator cudaMemcpyOperandTypeMax = 0x7FFFFFFF
enum cudaMemcpyFlags
Flags to specify for copies within a batch.
For more details see cudaMemcpyBatchAsync.
Values:
enumerator cudaMemcpyFlagDefault = 0x0
enumerator cudaMemcpyFlagPreferOverlapWithCompute = 0x1
Hint to the driver to try and overlap the copy with compute work on the SMs.
enum cudaMemcpyKind
CUDA memory copy types.
Values:
enumerator cudaMemcpyHostToHost = 0
Host -> Host.
enumerator cudaMemcpyHostToDevice = 1
Host -> Device.
enumerator cudaMemcpyDeviceToHost = 2
Device -> Host.
enumerator cudaMemcpyDeviceToDevice = 3
Device -> Device.
160
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
enumerator cudaMemcpyDefault = 4
Direction of the transfer is inferred from the pointer values.
Requires unified virtual addressing
enum cudaMemcpySrcAccessOrder
Values:
enumerator cudaMemcpySrcAccessOrderInvalid = 0x0
Default invalid.
enumerator cudaMemcpySrcAccessOrderStream = 0x1
Indicates that access to the source pointer must be in stream order.
enumerator cudaMemcpySrcAccessOrderDuringApiCall = 0x2
Indicates that access to the source pointer can be out of stream order and all accesses must
be complete before the API call returns.
This flag is suited for ephemeral sources (ex., stack variables) when it’s known that no prior
operations in the stream can be accessing the memory and also that the lifetime of the
memory is limited to the scope that the source variable was declared in. Specifying this flag
allows the driver to optimize the copy and removes the need for the user to synchronize the
stream after the API call.
enumerator cudaMemcpySrcAccessOrderAny = 0x3
Indicates that access to the source pointer can be out of stream order and the accesses can
happen even after the API call returns.
This flag is suited for host pointers allocated outside CUDA (ex., via malloc) when it’s known
that no prior operations in the stream can be accessing the memory. Specifying this flag
allows the driver to optimize the copy on certain platforms.
enumerator cudaMemcpySrcAccessOrderMax = 0x7FFFFFFF
enum cudaMemoryAdvise
CUDA Memory Advise values.
Values:
enumerator cudaMemAdviseSetReadMostly = 1
Data will mostly be read and only occassionally be written to.
enumerator cudaMemAdviseUnsetReadMostly = 2
Undo the effect of cudaMemAdviseSetReadMostly.
enumerator cudaMemAdviseSetPreferredLocation = 3
Set the preferred location for the data as the specified device.
6.2. Data types used by CUDA Runtime
161
CUDA Runtime API Reference Manual, Release 13.5
enumerator cudaMemAdviseUnsetPreferredLocation = 4
Clear the preferred location for the data.
enumerator cudaMemAdviseSetAccessedBy = 5
Data will be accessed by the specified device, so prevent page faults as much as possible.
enumerator cudaMemAdviseUnsetAccessedBy = 6
Let the Unified Memory subsystem decide on the page faulting policy for the specified de-
vice.
enum cudaMemoryType
CUDA memory types.
Values:
enumerator cudaMemoryTypeUnregistered = 0
Unregistered memory.
enumerator cudaMemoryTypeHost = 1
Host memory.
enumerator cudaMemoryTypeDevice = 2
Device memory.
enumerator cudaMemoryTypeManaged = 3
Managed memory.
enum cudaResourceType
CUDA resource types.
Values:
enumerator cudaResourceTypeArray = 0x00
Array resource.
enumerator cudaResourceTypeMipmappedArray = 0x01
Mipmapped array resource.
enumerator cudaResourceTypeLinear = 0x02
Linear resource.
enumerator cudaResourceTypePitch2D = 0x03
Pitch 2D resource.
enum cudaResourceViewFormat
CUDA texture resource view formats.
Values:
162
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
enumerator cudaResViewFormatNone = 0x00
No resource view format (use underlying resource format)
enumerator cudaResViewFormatUnsignedChar1 = 0x01
1 channel unsigned 8-bit integers
enumerator cudaResViewFormatUnsignedChar2 = 0x02
2 channel unsigned 8-bit integers
enumerator cudaResViewFormatUnsignedChar4 = 0x03
4 channel unsigned 8-bit integers
enumerator cudaResViewFormatSignedChar1 = 0x04
1 channel signed 8-bit integers
enumerator cudaResViewFormatSignedChar2 = 0x05
2 channel signed 8-bit integers
enumerator cudaResViewFormatSignedChar4 = 0x06
4 channel signed 8-bit integers
enumerator cudaResViewFormatUnsignedShort1 = 0x07
1 channel unsigned 16-bit integers
enumerator cudaResViewFormatUnsignedShort2 = 0x08
2 channel unsigned 16-bit integers
enumerator cudaResViewFormatUnsignedShort4 = 0x09
4 channel unsigned 16-bit integers
enumerator cudaResViewFormatSignedShort1 = 0x0a
1 channel signed 16-bit integers
enumerator cudaResViewFormatSignedShort2 = 0x0b
2 channel signed 16-bit integers
enumerator cudaResViewFormatSignedShort4 = 0x0c
4 channel signed 16-bit integers
enumerator cudaResViewFormatUnsignedInt1 = 0x0d
1 channel unsigned 32-bit integers
enumerator cudaResViewFormatUnsignedInt2 = 0x0e
2 channel unsigned 32-bit integers
6.2. Data types used by CUDA Runtime
163
CUDA Runtime API Reference Manual, Release 13.5
enumerator cudaResViewFormatUnsignedInt4 = 0x0f
4 channel unsigned 32-bit integers
enumerator cudaResViewFormatSignedInt1 = 0x10
1 channel signed 32-bit integers
enumerator cudaResViewFormatSignedInt2 = 0x11
2 channel signed 32-bit integers
enumerator cudaResViewFormatSignedInt4 = 0x12
4 channel signed 32-bit integers
enumerator cudaResViewFormatHalf1 = 0x13
1 channel 16-bit floating point
enumerator cudaResViewFormatHalf2 = 0x14
2 channel 16-bit floating point
enumerator cudaResViewFormatHalf4 = 0x15
4 channel 16-bit floating point
enumerator cudaResViewFormatFloat1 = 0x16
1 channel 32-bit floating point
enumerator cudaResViewFormatFloat2 = 0x17
2 channel 32-bit floating point
enumerator cudaResViewFormatFloat4 = 0x18
4 channel 32-bit floating point
enumerator cudaResViewFormatUnsignedBlockCompressed1 = 0x19
Block compressed 1.
enumerator cudaResViewFormatUnsignedBlockCompressed2 = 0x1a
Block compressed 2.
enumerator cudaResViewFormatUnsignedBlockCompressed3 = 0x1b
Block compressed 3.
enumerator cudaResViewFormatUnsignedBlockCompressed4 = 0x1c
Block compressed 4 unsigned.
enumerator cudaResViewFormatSignedBlockCompressed4 = 0x1d
Block compressed 4 signed.
164
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
enumerator cudaResViewFormatUnsignedBlockCompressed5 = 0x1e
Block compressed 5 unsigned.
enumerator cudaResViewFormatSignedBlockCompressed5 = 0x1f
Block compressed 5 signed.
enumerator cudaResViewFormatUnsignedBlockCompressed6H = 0x20
Block compressed 6 unsigned half-float.
enumerator cudaResViewFormatSignedBlockCompressed6H = 0x21
Block compressed 6 signed half-float.
enumerator cudaResViewFormatUnsignedBlockCompressed7 = 0x22
Block compressed 7.
enum cudaSharedCarveout
Shared memory carveout configurations.
These may be passed to cudaFuncSetAttribute
Values:
enumerator cudaSharedmemCarveoutDefault = -1
No preference for shared memory or L1 (default)
enumerator cudaSharedmemCarveoutMaxShared = 100
Prefer maximum available shared memory, minimum L1 cache.
enumerator cudaSharedmemCarveoutMaxL1 = 0
Prefer maximum available L1 cache, minimum shared memory.
enum cudaSharedMemConfig
CUDA shared memory configuration.
Deprecated:
Values:
enumerator cudaSharedMemBankSizeDefault = 0
enumerator cudaSharedMemBankSizeFourByte = 1
enumerator cudaSharedMemBankSizeEightByte = 2
6.2. Data types used by CUDA Runtime
165
CUDA Runtime API Reference Manual, Release 13.5
enum cudaSharedMemoryMode
Shared memory related attributes for use with ::cuLaunchKernelEx.
Values:
enumerator cudaSharedMemoryModeDefault = 0
The default to use for allowing non-portable shared memory size on launch - uses current
function attributes for cudaFuncAttributeMaxDynamicSharedMemorySize.
enumerator cudaSharedMemoryModeRequirePortable = 1
Specifies that the shared memory size requested must be a portable size within cudaDevAt-
trMaxSharedMemoryPerBlock.
enumerator cudaSharedMemoryModeAllowNonPortable = 2
Specifies that the shared memory size requested may be a non-portable size up to cudaDe-
vAttrMaxSharedMemoryPerBlockOptin.
enumerator cudaSharedMemoryModeAllowOversizedSharedMemory = 3
Specifies that oversized shared memory configurations may be used (with the limitation of
only 8kB L1 cache)
enumerator cudaSharedMemoryModePreferOversizedSharedMemory = 4
Specifies that oversized shared memory configurations may be used (with the limitation of
only 8kB L1 cache), and prefer an oversized shared memory configuration.
enum cudaStreamCaptureMode
Possible modes for stream capture thread interactions.
For more details see cudaStreamBeginCapture and cudaThreadExchangeStreamCaptureMode
Values:
enumerator cudaStreamCaptureModeGlobal = 0
enumerator cudaStreamCaptureModeThreadLocal = 1
enumerator cudaStreamCaptureModeRelaxed = 2
enum cudaStreamCaptureStatus
Possible stream capture statuses returned by cudaStreamIsCapturing.
Values:
enumerator cudaStreamCaptureStatusNone = 0
Stream is not capturing.
enumerator cudaStreamCaptureStatusActive = 1
Stream is actively capturing.
166
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
enumerator cudaStreamCaptureStatusInvalidated = 2
Stream is part of a capture sequence that has been invalidated, but not terminated.
enum cudaStreamUpdateCaptureDependenciesFlags
Flags for cudaStreamUpdateCaptureDependencies.
Values:
enumerator cudaStreamAddCaptureDependencies = 0x0
Add new nodes to the dependency set.
enumerator cudaStreamSetCaptureDependencies = 0x1
Replace the dependency set with the new nodes.
enum cudaSurfaceBoundaryMode
CUDA Surface boundary modes.
Values:
enumerator cudaBoundaryModeZero = 0
Zero boundary mode.
enumerator cudaBoundaryModeClamp = 1
Clamp boundary mode.
enumerator cudaBoundaryModeTrap = 2
Trap boundary mode.
enum cudaSurfaceFormatMode
CUDA Surface format modes.
Values:
enumerator cudaFormatModeForced = 0
Forced format mode.
enumerator cudaFormatModeAuto = 1
Auto format mode.
enum cudaSynchronizationPolicy
Values:
enumerator cudaSyncPolicyAuto = 1
enumerator cudaSyncPolicySpin = 2
enumerator cudaSyncPolicyYield = 3
6.2. Data types used by CUDA Runtime
167
CUDA Runtime API Reference Manual, Release 13.5
enumerator cudaSyncPolicyBlockingSync = 4
enum cudaTextureAddressMode
CUDA texture address modes.
Values:
enumerator cudaAddressModeWrap = 0
Wrapping address mode.
enumerator cudaAddressModeClamp = 1
Clamp to edge address mode.
enumerator cudaAddressModeMirror = 2
Mirror address mode.
enumerator cudaAddressModeBorder = 3
Border address mode.
enum cudaTextureFilterMode
CUDA texture filter modes.
Values:
enumerator cudaFilterModePoint = 0
Point filter mode.
enumerator cudaFilterModeLinear = 1
Linear filter mode.
enum cudaTextureReadMode
CUDA texture read modes.
Values:
enumerator cudaReadModeElementType = 0
Read texture as specified element type.
enumerator cudaReadModeNormalizedFloat = 1
Read texture as normalized float.
enum cudaUserObjectFlags
Flags for user objects for graphs.
Values:
enumerator cudaUserObjectNoDestructorSync = 0x1
Indicates the destructor execution is not synchronized by any CUDA handle.
168
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
enum cudaUserObjectRetainFlags
Flags for retaining user object references for graphs.
Values:
enumerator cudaGraphUserObjectMove = 0x1
Transfer references from the caller rather than creating new references.
6.2.3. Typedefs
typedef const struct cudaArray *cudaArray_const_t
CUDA array (as source copy argument)
typedef struct cudaArray *cudaArray_t
CUDA array.
typedef void (*cudaAsyncCallback)(cudaAsyncNotificationInfo_t*, void*,
cudaAsyncCallbackHandle_t)
typedef struct cudaAsyncCallbackEntry *cudaAsyncCallbackHandle_t
CUDA async callback handle.
typedef struct CUdevResourceDesc_st *cudaDevResourceDesc_t
An opaque descriptor handle.
The descriptor encapsulates multiple created and configured resources. Created via ::cudaDe-
viceResourceGenerateDesc
typedef struct CUeglStreamConnection_st *cudaEglStreamConnection
CUDA EGLSream Connection.
typedef enum cudaError cudaError_t
CUDA Error types.
typedef struct CUevent_st *cudaEvent_t
CUDA event types.
typedef struct cudaExecutionContext_st *cudaExecutionContext_t
An opaque handle to a CUDA execution context.
It represents an execution context created via CUDA Runtime APIs such as cudaGreenCtxCreate.
typedef struct CUexternalMemory_st *cudaExternalMemory_t
CUDA external memory.
6.2. Data types used by CUDA Runtime
169
CUDA Runtime API Reference Manual, Release 13.5
typedef struct CUexternalSemaphore_st *cudaExternalSemaphore_t
CUDA external semaphore.
typedef struct CUfunc_st *cudaFunction_t
CUDA function.
typedef unsigned long long cudaGraphConditionalHandle
CUDA handle for conditional graph nodes.
typedef struct CUgraphDeviceUpdatableNode_st *cudaGraphDeviceNode_t
CUDA device node handle for device-side node update.
typedef struct CUgraphExec_st *cudaGraphExec_t
CUDA executable (launchable) graph.
typedef struct CUgraphNode_st *cudaGraphNode_t
CUDA graph node.
typedef struct CUgraph_st *cudaGraph_t
CUDA graph.
typedef struct cudaGraphicsResource *cudaGraphicsResource_t
CUDA graphics resource types.
void(__stdcall * cudaHostFn_t )(void *userData)
CUDA host function.
Param userData
Argument value passed to the function
typedef struct CUkern_st *cudaKernel_t
CUDA kernel.
typedef struct CUlib_st *cudaLibrary_t
CUDA library.
typedef unsigned int cudaLogIterator
typedef struct CUlogsCallbackEntry_st *cudaLogsCallbackHandle
typedef struct CUmemPoolHandle_st *cudaMemPool_t
CUDA memory pool.
typedef const struct cudaMipmappedArray *cudaMipmappedArray_const_t
CUDA mipmapped array (as source argument)
170
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
typedef struct cudaMipmappedArray *cudaMipmappedArray_t
CUDA mipmapped array.
typedef struct CUstream_st *cudaStream_t
CUDA stream.
typedef unsigned long long cudaSurfaceObject_t
An opaque value that represents a CUDA Surface object.
typedef unsigned long long cudaTextureObject_t
An opaque value that represents a CUDA texture object.
typedef struct CUuserObject_st *cudaUserObject_t
CUDA user object for graphs.
6.3. Device Management
impl_private
This section describes the device management functions of the CUDA runtime application program-
ming interface.
Functions
__host__ cudaError_t cudaChooseDevice(int *device, const struct cudaDeviceProp *prop)
Select compute-device which best matches criteria.
__host__ cudaError_t cudaDeviceFlushGPUDirectRDMAWrites(enum cudaFlushGPUDirectRD-
MAWritesTarget target, enum cudaFlushGPUDirectRDMAWritesScope scope)
Blocks until remote writes are visible to the specified scope.
__host__ cudaError_t cudaDeviceGetAttribute(int *value, enum cudaDeviceAttr attr, int device)
Returns information about the device.
__host__ cudaError_t cudaDeviceGetByPCIBusId(int *device, const char *pciBusId)
Returns a handle to a compute device.
__host__ cudaError_t cudaDeviceGetCacheConfig(enum cudaFuncCache *pCacheConfig)
Returns the preferred cache configuration for the current device.
__host__ cudaError_t cudaDeviceGetDefaultMemPool(cudaMemPool_t *memPool, int device)
Returns the default mempool of a device.
__host__ cudaError_t cudaDeviceGetHostAtomicCapabilities(unsigned int *capabilities, const enum
cudaAtomicOperation *operations, unsigned int count, int device)
Queries details about atomic operations supported between the device and host.
__host__ cudaError_t cudaDeviceGetLimit(size_t *pValue, enum cudaLimit limit)
Return resource limits.
__host__ cudaError_t cudaDeviceGetMemPool(cudaMemPool_t *memPool, int device)
Gets the current mempool for a device.
6.3. Device Management
171
CUDA Runtime API Reference Manual, Release 13.5
__host__ cudaError_t cudaDeviceGetNvSciSyncAttributes(void *nvSciSyncAttrList, int device, int
flags)
Return NvSciSync attributes that this device can support.
__host__ cudaError_t cudaDeviceGetP2PAtomicCapabilities(unsigned int *capabilities, const enum
cudaAtomicOperation *operations, unsigned int count, int srcDevice, int dstDevice)
Queries details about atomic operations supported between two devices.
__host__ cudaError_t cudaDeviceGetP2PAttribute(int *value, enum cudaDeviceP2PAttr attr, int sr-
cDevice, int dstDevice)
Queries attributes of the link between two devices.
__host__ cudaError_t cudaDeviceGetPCIBusId(char *pciBusId, int len, int device)
Returns a PCI Bus Id string for the device.
__host__ cudaError_t cudaDeviceGetStreamPriorityRange(int *leastPriority, int *greatestPriority)
Returns numerical values that correspond to the least and greatest stream priorities.
__host__ cudaError_t cudaDeviceGetTexture1DLinearMaxWidth(size_t *maxWidthInElements,
const struct cudaChannelFormatDesc *fmtDesc, int device)
Returns the maximum number of elements allocatable in a 1D linear texture for a given element
size.
__host__ cudaError_t cudaDeviceRegisterAsyncNotification(int device, cudaAsyncCallback callback-
Func, void *userData, cudaAsyncCallbackHandle_t *callback)
Registers a callback function to receive async notifications.
__host__ cudaError_t cudaDeviceReset(void)
Destroy all allocations and reset all state on the current device in the current process.
__host__ cudaError_t cudaDeviceSetCacheConfig(enum cudaFuncCache cacheConfig)
Sets the preferred cache configuration for the current device.
__host__ cudaError_t cudaDeviceSetLimit(enum cudaLimit limit, size_t value)
Set resource limits.
__host__ cudaError_t cudaDeviceSetMemPool(int device, cudaMemPool_t memPool)
Sets the current memory pool of a device.
__host__ cudaError_t cudaDeviceSynchronize(void)
Wait for compute device to finish.
__host__ cudaError_t cudaDeviceUnregisterAsyncNotification(int device, cudaAsyncCallbackHan-
dle_t callback)
Unregisters an async notification callback.
__host__ cudaError_t cudaGetDevice(int *device)
Returns which device is currently being used.
__host__ cudaError_t cudaGetDeviceCount(int *count)
Returns the number of compute-capable devices.
__host__ cudaError_t cudaGetDeviceFlags(unsigned int *flags)
Gets the flags for the current device.
__host__ cudaError_t cudaGetDeviceProperties(struct cudaDeviceProp *prop, int device)
Returns information about the compute-device.
__host__ cudaError_t cudaInitDevice(int device, unsigned int deviceFlags, unsigned int flags)
Initialize device to be used for GPU executions.
__host__ cudaError_t cudaIpcCloseMemHandle(void *devPtr)
Attempts to close memory mapped with cudaIpcOpenMemHandle.
172
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
__host__ cudaError_t cudaIpcGetEventHandle(cudaIpcEventHandle_t *handle, cudaEvent_t event)
Gets an interprocess handle for a previously allocated event.
__host__ cudaError_t cudaIpcGetMemHandle(cudaIpcMemHandle_t *handle, void *devPtr)
Gets an interprocess memory handle for an existing device memory allocation.
__host__ cudaError_t cudaIpcOpenEventHandle(cudaEvent_t *event, cudaIpcEventHandle_t handle)
Opens an interprocess event handle for use in the current process.
__host__ cudaError_t cudaIpcOpenMemHandle(void **devPtr, cudaIpcMemHandle_t handle, un-
signed int flags)
Opens an interprocess memory handle exported from another process and returns a device
pointer usable in the local process.
__host__ cudaError_t cudaSetDevice(int device)
Set device to be used for GPU executions.
__host__ cudaError_t cudaSetDeviceFlags(unsigned int flags)
Sets flags to be used for device executions.
__host__ cudaError_t cudaSetValidDevices(int *device_arr, int len)
Set a list of devices that can be used for CUDA.
6.3.1. Functions
__host__ cudaError_t cudaChooseDevice(int *device, const struct cudaDeviceProp *prop)
Select compute-device which best matches criteria.
Returns in *device the device which has properties that best match *prop.
See also:
cudaGetDeviceCount, cudaGetDevice, cudaSetDevice, cudaGetDeviceProperties, cudaInitDevice
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ device - - Device with best match
▶ prop - - Desired device properties
Returns
cudaSuccess, cudaErrorInvalidValue
6.3. Device Management
173
CUDA Runtime API Reference Manual, Release 13.5
__host__ cudaError_t cudaDeviceFlushGPUDirectRDMAWrites(enum cudaFlushGPUDirectRD-
MAWritesTarget target, enum
cudaFlushGPUDirectRD-
MAWritesScope scope)
Blocks until remote writes are visible to the specified scope.
Blocks until remote writes to the target context via mappings created through GPUDirect RDMA
APIs, like nvidia_p2p_get_pages (see https://docs.nvidia.com/cuda/gpudirect-rdma for more in-
formation), are visible to the specified scope.
If the scope equals or lies within the scope indicated by cudaDevAttrGPUDirectRDMAWritesOr-
dering, the call will be a no-op and can be safely omitted for performance. This can be determined
by comparing the numerical values between the two enums, with smaller scopes having smaller
values.
Users may query support for this API via cudaDevAttrGPUDirectRDMAFlushWritesOptions.
See also:
::cuFlushGPUDirectRDMAWrites
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
▶ target - - The target of the operation, see cudaFlushGPUDirectRDMAWrites-
Target
▶ scope - - The scope of the operation, see cudaFlushGPUDirectRDMAWritesS-
cope
Returns
cudaSuccess, cudaErrorNotSupported,
__host__ cudaError_t cudaDeviceGetAttribute(int *value, enum cudaDeviceAttr attr, int device)
Returns information about the device.
Returns in *value the integer value of the attribute attr on device device.
See also:
cudaGetDeviceCount, cudaGetDevice, cudaSetDevice, cudaChooseDevice, cudaGetDeviceProper-
ties, cudaInitDevice, ::cuDeviceGetAttribute
174
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ value - - Returned device attribute value
▶ attr - - Device attribute to query
▶ device - - Device number to query
Returns
cudaSuccess, cudaErrorInvalidDevice, cudaErrorInvalidValue
__host__ cudaError_t cudaDeviceGetByPCIBusId(int *device, const char *pciBusId)
Returns a handle to a compute device.
Returns in *device a device ordinal given a PCI bus ID string.
where domain, bus, device, and function are all hexadecimal values
See also:
cudaDeviceGetPCIBusId, ::cuDeviceGetByPCIBusId
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ device - - Returned device ordinal
6.3. Device Management
175
CUDA Runtime API Reference Manual, Release 13.5
▶ pciBusId - - String in one of the following forms:
Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorInvalidDevice
__host__ cudaError_t cudaDeviceGetCacheConfig(enum cudaFuncCache *pCacheConfig)
Returns the preferred cache configuration for the current device.
On devices where the L1 cache and shared memory use the same hardware resources, this re-
turns through pCacheConfig the preferred cache configuration for the current device. This is
only a preference. The runtime will use the requested configuration if possible, but it is free to
choose a different configuration if required to execute functions.
This will return a pCacheConfig of cudaFuncCachePreferNone on devices where the size of the
L1 cache and shared memory are fixed.
The supported cache configurations are:
▶ cudaFuncCachePreferNone: no preference for shared memory or L1 (default)
▶ cudaFuncCachePreferShared: prefer larger shared memory and smaller L1 cache
▶ cudaFuncCachePreferL1: prefer larger L1 cache and smaller shared memory
▶ cudaFuncCachePreferEqual: prefer equal size L1 cache and shared memory
See also:
cudaDeviceSetCacheConfig, cudaFuncSetCacheConfig (C API), cudaFuncSetCacheConfig (C++
API), ::cuCtxGetCacheConfig
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
pCacheConfig - - Returned cache configuration
Returns
cudaSuccess
__host__ cudaError_t cudaDeviceGetDefaultMemPool(cudaMemPool_t *memPool, int device)
Returns the default mempool of a device.
The default mempool of a device contains device memory from that device.
176
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
See also:
::cuDeviceGetDefaultMemPool, cudaMallocAsync, cudaMemPoolTrimTo, cudaMemPoolGetAt-
tribute, cudaDeviceSetMemPool, cudaMemPoolSetAttribute, cudaMemPoolSetAccess
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.
Returns
cudaSuccess, cudaErrorInvalidDevice, cudaErrorInvalidValue cudaErrorNotSupported
__host__ cudaError_t cudaDeviceGetHostAtomicCapabilities(unsigned int *capabilities, const
enum cudaAtomicOperation
*operations, unsigned int count,
int device)
Queries details about atomic operations supported between the device and host.
Returns in *capabilities the details about requested atomic *operations over the the link
between dev and the host. The allocated size of *operations and *capabilities must be
count.
For each cudaAtomicOperation in *operations, the corresponding result in *capabilities will
be a bitmask indicating which of cudaAtomicOperationCapability the link supports natively.
Returns cudaErrorInvalidDevice if dev is not valid.
Returns cudaErrorInvalidValue if *capabilities or *operations is NULL, if count is 0, or if any
of *operations is not valid.
See also:
cudaDeviceGetAttribute, cudaDeviceGetP2PAtomicCapabilities, ::cuDeviceGeHostAtomicCapabil-
ities
Note: Note that this function may also return error codes from previous, asynchronous launches.
Parameters
▶ capabilities - - Returned capability details of each requested operation
▶ operations - - Requested operations
▶ count - - Count of requested operations and size of capabilities
▶ dev - - Device handle
6.3. Device Management
177
CUDA Runtime API Reference Manual, Release 13.5
Returns
cudaSuccess, cudaErrorInvalidDevice, cudaErrorInvalidValue
__host__ cudaError_t cudaDeviceGetLimit(size_t *pValue, enum cudaLimit limit)
Return resource limits.
Returns in *pValue the current size of limit. The following cudaLimit values are supported.
▶ cudaLimitStackSize is the stack size in bytes of each GPU thread.
▶ cudaLimitPrintfFifoSize is the size in bytes of the shared FIFO used by the ::printf() device
system call.
▶ cudaLimitMallocHeapSize is the size in bytes of the heap used by the ::malloc() and ::free()
device system calls.
▶ cudaLimitDevRuntimeSyncDepth is the maximum grid depth at which a thread can isssue
the device runtime call cudaDeviceSynchronize() to wait on child grid launches to complete.
This functionality is removed for devices of compute capability >= 9.0, and hence will return
error cudaErrorUnsupportedLimit on such devices.
▶ cudaLimitDevRuntimePendingLaunchCount is the maximum number of outstanding device
runtime launches.
▶ cudaLimitMaxL2FetchGranularity is the L2 cache fetch granularity.
▶ cudaLimitPersistingL2CacheSize is the persisting L2 cache size in bytes.
See also:
cudaDeviceSetLimit, ::cuCtxGetLimit
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
▶ limit - - Limit to query
▶ pValue - - Returned size of the limit
Returns
cudaSuccess, cudaErrorUnsupportedLimit, cudaErrorInvalidValue
178
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
__host__ cudaError_t cudaDeviceGetMemPool(cudaMemPool_t *memPool, int device)
Gets the current mempool for a device.
Returns the last pool provided to cudaDeviceSetMemPool for this device or the device’s default
memory pool if cudaDeviceSetMemPool has never been called. By default the current mempool
is the default mempool for a device, otherwise the returned pool must have been set with ::cuD-
eviceSetMemPool or cudaDeviceSetMemPool.
See also:
::cuDeviceGetMemPool, cudaDeviceGetDefaultMemPool, cudaDeviceSetMemPool
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.
Returns
cudaSuccess, cudaErrorInvalidValue cudaErrorNotSupported
__host__ cudaError_t cudaDeviceGetNvSciSyncAttributes(void *nvSciSyncAttrList, int device,
int flags)
Return NvSciSync attributes that this device can support.
Returns in nvSciSyncAttrList, the properties of NvSciSync that this CUDA device, dev can
support. The returned nvSciSyncAttrList can be used to create an NvSciSync that matches
this device’s capabilities.
If NvSciSyncAttrKey_RequiredPerm field in nvSciSyncAttrList is already set this API will re-
turn cudaErrorInvalidValue.
The applications should set nvSciSyncAttrList to a valid NvSciSyncAttrList failing which this
API will return ::cudaErrorInvalidHandle.
The flags controls how applications intends to use the NvSciSync created from the nvSciSyn-
cAttrList. The valid flags are:
▶ cudaNvSciSyncAttrSignal, specifies that the applications intends to signal an NvSciSync on
this CUDA device.
▶ cudaNvSciSyncAttrWait, specifies that the applications intends to wait on an NvSciSync on
this CUDA device.
At least one of these flags must be set, failing which the API returns cudaErrorInvalidValue. Both
the flags are orthogonal to one another: a developer may set both these flags that allows to set
both wait and signal specific attributes in the same nvSciSyncAttrList.
Note that this API updates the input nvSciSyncAttrList with values equivalent to the following
public attribute key-values: NvSciSyncAttrKey_RequiredPerm is set to
6.3. Device Management
179
CUDA Runtime API Reference Manual, Release 13.5
▶ NvSciSyncAccessPerm_SignalOnly if cudaNvSciSyncAttrSignal is set in flags.
▶ NvSciSyncAccessPerm_WaitOnly if cudaNvSciSyncAttrWait is set in flags.
▶ NvSciSyncAccessPerm_WaitSignal if both cudaNvSciSyncAttrWait and cudaNvSciSyncAt-
trSignal are set in flags. NvSciSyncAttrKey_PrimitiveInfo is set to
▶ NvSciSyncAttrValPrimitiveType_SysmemSemaphore on any valid device.
▶ NvSciSyncAttrValPrimitiveType_Syncpoint if device is a Tegra device.
▶ NvSciSyncAttrValPrimitiveType_SysmemSemaphorePayload64b if device is GA10X+. NvS-
ciSyncAttrKey_GpuId is set to the same UUID that is returned in cudaDeviceProp.uuid
from ::cudaDeviceGetProperties for this device.
cudaSuccess, cudaErrorDeviceUninitialized, cudaErrorInvalidValue, ::cudaErrorInvalidHandle, cud-
aErrorInvalidDevice, cudaErrorNotSupported, cudaErrorMemoryAllocation
See also:
cudaImportExternalSemaphore, cudaDestroyExternalSemaphore, cudaSignalExternalSemaphore-
sAsync, cudaWaitExternalSemaphoresAsync
Parameters
▶ nvSciSyncAttrList - - Return NvSciSync attributes supported.
▶ device - - Valid Cuda Device to get NvSciSync attributes for.
▶ flags - - flags describing NvSciSync usage.
Returns
__host__ cudaError_t cudaDeviceGetP2PAtomicCapabilities(unsigned int *capabilities, const
enum cudaAtomicOperation
*operations, unsigned int count,
int srcDevice, int dstDevice)
Queries details about atomic operations supported between two devices.
Returns in *capabilities the details about requested atomic *operations over the the link
between srcDevice and dstDevice. The allocated size of *operations and *capabilities
must be count.
For each cudaAtomicOperation in *operations, the corresponding result in *capabilities will
be a bitmask indicating which of cudaAtomicOperationCapability the link supports natively.
Returns cudaErrorInvalidDevice if srcDevice or dstDevice are not valid or if they represent the
same device.
Returns cudaErrorInvalidValue if *capabilities or *operations is NULL, if count is 0, or if any
of *operations is not valid.
See also:
cudaDeviceGetP2PAttribute, ::cuDeviceGetP2PAttribute, ::cuDeviceGetP2PAtomicCapabilities
180
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
Note: Note that this function may also return error codes from previous, asynchronous launches.
Parameters
▶ capabilities - - Returned capability details of each requested operation
▶ operations - - Requested operations
▶ count - - Count of requested operations and size of capabilities
▶ srcDevice - - The source device of the target link
▶ dstDevice - - The destination device of the target link
Returns
cudaSuccess, cudaErrorInvalidDevice, cudaErrorInvalidValue
__host__ cudaError_t cudaDeviceGetP2PAttribute(int *value, enum cudaDeviceP2PAttr attr, int
srcDevice, int dstDevice)
Queries attributes of the link between two devices.
Returns in *value the value of the requested attribute attrib of the link between srcDevice
and dstDevice. The supported attributes are:
▶ cudaDevP2PAttrPerformanceRank: A relative value indicating the performance of the link
between two devices. Lower value means better performance (0 being the value used for
most performant link).
▶ cudaDevP2PAttrAccessSupported: 1 if peer access is enabled.
▶ cudaDevP2PAttrNativeAtomicSupported: 1 if all native atomic operations over the link are
supported.
▶ cudaDevP2PAttrCudaArrayAccessSupported: 1 if accessing CUDA arrays over the link is sup-
ported.
▶ cudaDevP2PAttrOnlyPartialNativeAtomicSupported: 1 if some CUDA-valid atomic operations
over the link are supported. Information about specific operations can be retrieved with
cudaDeviceGetP2PAtomicCapabilities.
Returns cudaErrorInvalidDevice if srcDevice or dstDevice are not valid or if they represent the
same device.
Returns cudaErrorInvalidValue if attrib is not valid or if value is a null pointer.
See also:
cudaDeviceEnablePeerAccess, cudaDeviceDisablePeerAccess, cudaDeviceCanAccessPeer, ::cuDe-
viceGetP2PAttribute cudaDeviceGetP2PAtomicCapabilities
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.3. Device Management
181
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
▶ value - - Returned value of the requested attribute
▶ attrib - - The requested attribute of the link between srcDevice and dst-
Device.
▶ srcDevice - - The source device of the target link.
▶ dstDevice - - The destination device of the target link.
Returns
cudaSuccess, cudaErrorInvalidDevice, cudaErrorInvalidValue
__host__ cudaError_t cudaDeviceGetPCIBusId(char *pciBusId, int len, int device)
Returns a PCI Bus Id string for the device.
Returns an ASCII string identifying the device dev in the NULL-terminated string pointed to by
pciBusId. len specifies the maximum length of the string that may be returned.
where domain, bus, device, and function are all hexadecimal values. pciBusId should be large
enough to store 13 characters including the NULL-terminator.
See also:
cudaDeviceGetByPCIBusId, ::cuDeviceGetPCIBusId
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
▶ pciBusId - - Returned identifier string for the device in the following format
▶ len - - Maximum length of string to store in name
▶ device - - Device to get identifier string for
182
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorInvalidDevice
__host__ cudaError_t cudaDeviceGetStreamPriorityRange(int *leastPriority, int
*greatestPriority)
Returns numerical values that correspond to the least and greatest stream priorities.
Returns in *leastPriority and *greatestPriority the numerical values that correspond
to the least and greatest stream priorities respectively. Stream priorities follow a convention
where lower numbers imply greater priorities. The range of meaningful stream priorities is given
by [*greatestPriority, *leastPriority]. If the user attempts to create a stream with a
priority value that is outside the the meaningful range as specified by this API, the priority is
automatically clamped down or up to either *leastPriority or *greatestPriority respec-
tively. See cudaStreamCreateWithPriority for details on creating a priority stream. A NULL may
be passed in for *leastPriority or *greatestPriority if the value is not desired.
This function will return ‘0’ in both *leastPriority and *greatestPriority if the current
context’s device does not support stream priorities (see cudaDeviceGetAttribute).
See also:
cudaStreamCreateWithPriority, cudaStreamGetPriority, ::cuCtxGetStreamPriorityRange
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
▶ leastPriority - - Pointer to an int in which the numerical value for least
stream priority is returned
▶ greatestPriority - - Pointer to an int in which the numerical value for great-
est stream priority is returned
Returns
cudaSuccess
__host__ cudaError_t cudaDeviceGetTexture1DLinearMaxWidth(size_t *maxWidthInElements,
const struct
cudaChannelFormatDesc
*fmtDesc, int device)
Returns the maximum number of elements allocatable in a 1D linear texture for a given element
size.
6.3. Device Management
183
CUDA Runtime API Reference Manual, Release 13.5
Returns in maxWidthInElements the maximum number of elements allocatable in a 1D linear
texture for given format descriptor fmtDesc.
See also:
::cuDeviceGetTexture1DLinearMaxWidth
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
▶ maxWidthInElements - - Returns maximum number of texture elements allo-
catable for given fmtDesc.
▶ fmtDesc - - Texture format description.
Returns
cudaSuccess, cudaErrorUnsupportedLimit, cudaErrorInvalidValue
__host__ cudaError_t cudaDeviceRegisterAsyncNotification(int device, cudaAsyncCallback
callbackFunc, void *userData,
cudaAsyncCallbackHandle_t
*callback)
Registers a callback function to receive async notifications.
Registers callbackFunc to receive async notifications.
The userData parameter is passed to the callback function at async notification time. Likewise,
callback is also passed to the callback function to distinguish between multiple registered call-
backs.
The callback function being registered should be designed to return quickly (~10ms). Any long
running tasks should be queued for execution on an application thread.
Callbacks may not call cudaDeviceRegisterAsyncNotification or cudaDeviceUnregisterAsyncNo-
tification. Doing so will result in cudaErrorNotPermitted. Async notification callbacks execute in
an undefined order and may be serialized.
Returns in *callback a handle representing the registered callback instance.
See also:
cudaDeviceUnregisterAsyncNotification
184
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
Note: Note that this function may also return error codes from previous, asynchronous launches.
Parameters
▶ device - - The device on which to register the callback
▶ callbackFunc - - The function to register as a callback
▶ userData - - A generic pointer to user data. This is passed into the callback
function.
▶ callback - - A handle representing the registered callback instance
Returns
cudaSuccess cudaErrorNotSupported cudaErrorInvalidDevice cudaErrorInvalidValue
cudaErrorNotPermitted cudaErrorUnknown
__host__ cudaError_t cudaDeviceReset(void)
Destroy all allocations and reset all state on the current device in the current process.
Explicitly destroys and cleans up all resources associated with the current device in the cur-
rent process. It is the caller’s responsibility to ensure that the resources are not accessed
or passed in subsequent API calls and doing so will result in undefined behavior. These re-
sources include CUDA types cudaStream_t, cudaEvent_t, cudaArray_t, cudaMipmappedArray_t,
cudaPitchedPtr, cudaTextureObject_t, cudaSurfaceObject_t, ::textureReference, ::surfaceRefer-
ence, cudaExternalMemory_t, cudaExternalSemaphore_t and cudaGraphicsResource_t. These re-
sources also include memory allocations by cudaMalloc, cudaMallocHost, cudaMallocManaged
and cudaMallocPitch. Any subsequent API call to this device will reinitialize the device.
Note that this function will reset the device immediately. It is the caller’s responsibility to ensure
that the device is not being accessed by any other host threads from the process when this
function is called.
See also:
cudaDeviceSynchronize
Note: cudaDeviceReset() will not destroy memory allocations by cudaMallocAsync() and cudaMal-
locFromPoolAsync(). These memory allocations need to be destroyed explicitly.
Note: If a non-primary ::CUcontext is current to the thread, cudaDeviceReset() will destroy only
the internal CUDA RT state for that ::CUcontext.
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.3. Device Management
185
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.
Returns
cudaSuccess
__host__ cudaError_t cudaDeviceSetCacheConfig(enum cudaFuncCache cacheConfig)
Sets the preferred cache configuration for the current device.
On devices where the L1 cache and shared memory use the same hardware resources, this sets
through cacheConfig the preferred cache configuration for the current device. This is only a
preference. The runtime will use the requested configuration if possible, but it is free to choose
a different configuration if required to execute the function. Any function preference set via
cudaFuncSetCacheConfig (C API) or cudaFuncSetCacheConfig (C++ API) will be preferred over this
device-wide setting. Setting the device-wide cache configuration to cudaFuncCachePreferNone
will cause subsequent kernel launches to prefer to not change the cache configuration unless
required to launch the kernel.
This setting does nothing on devices where the size of the L1 cache and shared memory are
fixed.
Launching a kernel with a different preference than the most recent preference setting may
insert a device-side synchronization point.
The supported cache configurations are:
▶ cudaFuncCachePreferNone: no preference for shared memory or L1 (default)
▶ cudaFuncCachePreferShared: prefer larger shared memory and smaller L1 cache
▶ cudaFuncCachePreferL1: prefer larger L1 cache and smaller shared memory
▶ cudaFuncCachePreferEqual: prefer equal size L1 cache and shared memory
See also:
cudaDeviceGetCacheConfig, cudaFuncSetCacheConfig (C API), cudaFuncSetCacheConfig (C++
API), ::cuCtxSetCacheConfig
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
cacheConfig - - Requested cache configuration
186
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
Returns
cudaSuccess
__host__ cudaError_t cudaDeviceSetLimit(enum cudaLimit limit, size_t value)
Set resource limits.
Setting limit to value is a request by the application to update the current limit maintained
by the device. The driver is free to modify the requested value to meet h/w requirements (this
could be clamping to minimum or maximum values, rounding up to nearest element size, etc).
The application can use cudaDeviceGetLimit() to find out exactly what the limit has been set to.
Setting each cudaLimit has its own specific restrictions, so each is discussed here.
▶ cudaLimitStackSize controls the stack size in bytes of each GPU thread.
▶ cudaLimitPrintfFifoSize controls the size in bytes of the shared FIFO used by the ::printf()
device system call. Setting cudaLimitPrintfFifoSize must not be performed after launching
any kernel that uses the ::printf() device system call - in such case cudaErrorInvalidValue will
be returned.
▶ cudaLimitMallocHeapSize controls the size in bytes of the heap used by the ::malloc() and
::free() device system calls. Setting cudaLimitMallocHeapSize must not be performed after
launching any kernel that uses the ::malloc() or ::free() device system calls - in such case
cudaErrorInvalidValue will be returned.
▶ cudaLimitDevRuntimeSyncDepth controls the maximum nesting depth of a grid at which a
thread can safely call cudaDeviceSynchronize(). Setting this limit must be performed be-
fore any launch of a kernel that uses the device runtime and calls cudaDeviceSynchronize()
above the default sync depth, two levels of grids. Calls to cudaDeviceSynchronize() will fail
with error code cudaErrorSyncDepthExceeded if the limitation is violated. This limit can be
set smaller than the default or up the maximum launch depth of 24. When setting this
limit, keep in mind that additional levels of sync depth require the runtime to reserve large
amounts of device memory which can no longer be used for user allocations. If these reser-
vations of device memory fail, cudaDeviceSetLimit will return cudaErrorMemoryAllocation,
and the limit can be reset to a lower value. This limit is only applicable to devices of com-
pute capability < 9.0. Attempting to set this limit on devices of other compute capability will
results in error cudaErrorUnsupportedLimit being returned.
▶ cudaLimitDevRuntimePendingLaunchCount controls the maximum number of outstanding
device runtime launches that can be made from the current device. A grid is outstanding
from the point of launch up until the grid is known to have been completed. Device run-
time launches which violate this limitation fail and return cudaErrorLaunchPendingCountEx-
ceeded when cudaGetLastError() is called after launch. If more pending launches than the
default (2048 launches) are needed for a module using the device runtime, this limit can
be increased. Keep in mind that being able to sustain additional pending launches will re-
quire the runtime to reserve larger amounts of device memory upfront which can no longer
be used for allocations. If these reservations fail, cudaDeviceSetLimit will return cudaEr-
rorMemoryAllocation, and the limit can be reset to a lower value. This limit is only applicable
to devices of compute capability 3.5 and higher. Attempting to set this limit on devices
of compute capability less than 3.5 will result in the error cudaErrorUnsupportedLimit being
returned.
▶ cudaLimitMaxL2FetchGranularity controls the L2 cache fetch granularity. Values can range
from 0B to 128B. This is purely a performance hint and it can be ignored or clamped depend-
ing on the platform.
6.3. Device Management
187
CUDA Runtime API Reference Manual, Release 13.5
▶ cudaLimitPersistingL2CacheSize controls size in bytes available for persisting L2 cache. This
is purely a performance hint and it can be ignored or clamped depending on the platform.
See also:
cudaDeviceGetLimit, ::cuCtxSetLimit
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
▶ limit - - Limit to set
▶ value - - Size of limit
Returns
cudaSuccess, cudaErrorUnsupportedLimit, cudaErrorInvalidValue, cudaErrorMemo-
ryAllocation
__host__ cudaError_t cudaDeviceSetMemPool(int device, cudaMemPool_t memPool)
Sets the current memory pool of a device.
The memory pool must be local to the specified device. Unless a mempool is specified in the cud-
aMallocAsync call, cudaMallocAsync allocates from the current mempool of the provided stream’s
device. By default, a device’s current memory pool is its default memory pool.
See also:
::cuDeviceSetMemPool, cudaDeviceGetMemPool, cudaDeviceGetDefaultMemPool, cudaMemPool-
Create, cudaMemPoolDestroy, cudaMallocFromPoolAsync
Note: Use cudaMallocFromPoolAsync to specify asynchronous allocations from a device different
than the one the stream runs on.
Note: Note that this function may also return error codes from previous, asynchronous launches.
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
188
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
such case.
Returns
cudaSuccess, cudaErrorInvalidValue cudaErrorInvalidDevice cudaErrorNotSupported
__host__ cudaError_t cudaDeviceSynchronize(void)
Wait for compute device to finish.
Blocks until the device has completed all preceding requested tasks. cudaDeviceSynchronize()
returns an error if one of the preceding tasks has failed. If the cudaDeviceScheduleBlockingSync
flag was set for this device, the host thread will block until the device has finished its work.
See also:
cudaDeviceReset, ::cuCtxSynchronize
Note: Use of cudaDeviceSynchronize in device code was deprecated in CUDA 11.6 and removed
for compute_90+ compilation. For compute capability < 9.0, compile-time opt-in by specifying
-D CUDA_FORCE_CDP1_IF_SUPPORTED is required to continue using cudaDeviceSynchronize() in
device code for now. Note that this is different from host-side cudaDeviceSynchronize, which is
still supported.
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.
Returns
cudaSuccess, cudaErrorStreamCaptureUnsupported
__host__ cudaError_t cudaDeviceUnregisterAsyncNotification(int device,
cudaAsyncCallbackHandle_t
callback)
Unregisters an async notification callback.
Unregisters callback so that the corresponding callback function will stop receiving async no-
tifications.
See also:
cudaDeviceRegisterAsyncNotification
6.3. Device Management
189
CUDA Runtime API Reference Manual, Release 13.5
Note: Note that this function may also return error codes from previous, asynchronous launches.
Parameters
▶ device - - The device from which to remove callback.
▶ callback - - The callback instance to unregister from receiving async notifica-
tions.
Returns
cudaSuccess cudaErrorNotSupported cudaErrorInvalidDevice cudaErrorInvalidValue
cudaErrorNotPermitted cudaErrorUnknown
__host__ cudaError_t cudaGetDevice(int *device)
Returns which device is currently being used.
Returns in *device the current device for the calling host thread.
See also:
cudaGetDeviceCount, cudaSetDevice, cudaGetDeviceProperties, cudaChooseDevice,
::cuC-
txGetCurrent
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
device - - Returns the device on which the active host thread executes the device
code.
Returns
cudaSuccess, cudaErrorInvalidValue, ::cudaErrorDeviceUnavailable,
__host__ cudaError_t cudaGetDeviceCount(int *count)
Returns the number of compute-capable devices.
Returns in *count the number of devices with compute capability greater or equal to 2.0 that
are available for execution.
190
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
See also:
cudaGetDevice, cudaSetDevice, cudaGetDeviceProperties, cudaChooseDevice, cudaInitDevice,
::cuDeviceGetCount
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 - - Returns the number of devices with compute capability greater or equal
to 2.0
Returns
cudaSuccess
__host__ cudaError_t cudaGetDeviceFlags(unsigned int *flags)
Gets the flags for the current device.
Returns in flags the flags for the current device. If there is a current device for the calling thread,
the flags for the device are returned. If there is no current device, the flags for the first device
are returned, which may be the default flags. Compare to the behavior of cudaSetDeviceFlags.
Typically, the flags returned should match the behavior that will be seen if the calling thread uses
a device after this call, without any change to the flags or current device inbetween by this or
another thread. Note that if the device is not initialized, it is possible for another thread to change
the flags for the current device before it is initialized. Additionally, when using exclusive mode, if
this thread has not requested a specific device, it may use a device other than the first device,
contrary to the assumption made by this function.
If a context has been created via the driver API and is current to the calling thread, the flags for
that context are always returned.
Flags returned by this function may specifically include cudaDeviceMapHost even though it is not
accepted by cudaSetDeviceFlags because it is implicit in runtime API flags. The reason for this is
that the current context may have been created via the driver API in which case the flag is not
implicit and may be unset.
See also:
cudaGetDevice, cudaGetDeviceProperties, cudaSetDevice, cudaSetDeviceFlags, cudaInitDevice,
::cuCtxGetFlags, ::cuDevicePrimaryCtxGetState
Note: Note that this function may also return error codes from previous, asynchronous launches.
6.3. Device Management
191
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
flags - - Pointer to store the device flags
Returns
cudaSuccess, cudaErrorInvalidDevice
__host__ cudaError_t cudaGetDeviceProperties(struct cudaDeviceProp *prop, int device)
Returns information about the compute-device.
Returns in *prop the properties of device dev.
See also:
cudaGetDeviceCount, cudaGetDevice, cudaSetDevice, cudaChooseDevice, cudaDeviceGetAt-
tribute, cudaInitDevice, ::cuDeviceGetAttribute, ::cuDeviceGetName
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
▶ prop - - Properties for the specified device
▶ device - - Device number to get properties for
Returns
cudaSuccess, cudaErrorInvalidDevice
__host__ cudaError_t cudaInitDevice(int device, unsigned int deviceFlags, unsigned int flags)
Initialize device to be used for GPU executions.
This function will initialize the CUDA Runtime structures and primary context on device when
called, but the context will not be made current to device.
192
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
When cudaInitDeviceFlagsAreValid is set in flags, deviceFlags are applied to the requested de-
vice. The values of deviceFlags match those of the flags parameters in cudaSetDeviceFlags. The
effect may be verified by cudaGetDeviceFlags.
This function will return an error if the device is in cudaComputeModeExclusiveProcess and is
occupied by another process or if the device is in cudaComputeModeProhibited.
See also:
cudaGetDeviceCount, cudaGetDevice, cudaGetDeviceProperties, cudaChooseDevice, cudaSetDe-
vice ::cuCtxSetCurrent
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ device - - Device on which the runtime will initialize itself.
▶ deviceFlags - - Parameters for device operation.
▶ flags - - Flags for controlling the device initialization.
Returns
cudaSuccess, cudaErrorInvalidDevice,
__host__ cudaError_t cudaIpcCloseMemHandle(void *devPtr)
Attempts to close memory mapped with cudaIpcOpenMemHandle.
Decrements the reference count of the memory returnd by cudaIpcOpenMemHandle by 1. When
the reference count reaches 0, this API unmaps the memory. The original allocation in the ex-
porting process as well as imported mappings in other processes will be unaffected.
Any resources used to enable peer access will be freed if this is the last mapping using them.
IPC functionality is restricted to devices with support for unified addressing on Linux and Win-
dows operating systems. IPC functionality on Windows is supported for compatibility purposes
but not recommended as it comes with performance cost. Users can test their device for IPC
functionality by calling cudaDeviceGetAttribute with cudaDevAttrIpcEventSupport
See also:
cudaMalloc, cudaFree, cudaIpcGetEventHandle, cudaIpcOpenEventHandle, cudaIpcGetMemHan-
dle, cudaIpcOpenMemHandle, ::cuIpcCloseMemHandle
6.3. Device Management
193
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
devPtr - - Device pointer returned by cudaIpcOpenMemHandle
Returns
cudaSuccess, cudaErrorMapBufferObjectFailed, cudaErrorNotSupported, cudaError-
InvalidValue
__host__ cudaError_t cudaIpcGetEventHandle(cudaIpcEventHandle_t *handle, cudaEvent_t event)
Gets an interprocess handle for a previously allocated event.
Takes as input a previously allocated event. This event must have been created with the cud-
aEventInterprocess and cudaEventDisableTiming flags set. This opaque handle may be copied
into other processes and opened with cudaIpcOpenEventHandle to allow efficient hardware syn-
chronization between GPU work in different processes.
After the event has been been opened in the importing process, cudaEventRecord, cudaEventSyn-
chronize, cudaStreamWaitEvent and cudaEventQuery may be used in either process. Performing
operations on the imported event after the exported event has been freed with cudaEventDe-
stroy will result in undefined behavior.
IPC functionality is restricted to devices with support for unified addressing on Linux and Win-
dows operating systems. IPC functionality on Windows is supported for compatibility purposes
but not recommended as it comes with performance cost. Users can test their device for IPC
functionality by calling cudaDeviceGetAttribute with cudaDevAttrIpcEventSupport
See also:
cudaEventCreate, cudaEventDestroy, cudaEventSynchronize, cudaEventQuery, cudaStreamWait-
Event, cudaIpcOpenEventHandle, cudaIpcGetMemHandle, cudaIpcOpenMemHandle, cudaIpc-
CloseMemHandle, ::cuIpcGetEventHandle
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
194
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
▶ handle - - Pointer to a user allocated cudaIpcEventHandle in which to return
the opaque event handle
▶ event - - Event allocated with cudaEventInterprocess and cudaEventDisableTim-
ing flags.
Returns
cudaSuccess, cudaErrorInvalidResourceHandle, cudaErrorMemoryAllocation, cud-
aErrorMapBufferObjectFailed, cudaErrorNotSupported, cudaErrorInvalidValue
__host__ cudaError_t cudaIpcGetMemHandle(cudaIpcMemHandle_t *handle, void *devPtr)
Gets an interprocess memory handle for an existing device memory allocation.
Takes a pointer to the base of an existing device memory allocation created with cudaMalloc and
exports it for use in another process. This is a lightweight operation and may be called multiple
times on an allocation without adverse effects.
If a region of memory is freed with cudaFree and a subsequent call to cudaMalloc returns memory
with the same device address, cudaIpcGetMemHandle will return a unique handle for the new
memory.
IPC functionality is restricted to devices with support for unified addressing on Linux and Win-
dows operating systems. IPC functionality on Windows is supported for compatibility purposes
but not recommended as it comes with performance cost. Users can test their device for IPC
functionality by calling cudaDeviceGetAttribute with cudaDevAttrIpcEventSupport
See also:
cudaMalloc, cudaFree, cudaIpcGetEventHandle, cudaIpcOpenEventHandle, cudaIpcOpenMemHan-
dle, cudaIpcCloseMemHandle, ::cuIpcGetMemHandle
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
▶ handle - - Pointer to user allocated ::cudaIpcMemHandle to return the handle
in.
▶ devPtr - - Base pointer to previously allocated device memory
Returns
cudaSuccess, cudaErrorMemoryAllocation, cudaErrorMapBufferObjectFailed, cud-
aErrorNotSupported, cudaErrorInvalidValue
__host__ cudaError_t cudaIpcOpenEventHandle(cudaEvent_t *event, cudaIpcEventHandle_t
handle)
Opens an interprocess event handle for use in the current process.
6.3. Device Management
195
CUDA Runtime API Reference Manual, Release 13.5
Opens an interprocess event handle exported from another process with cudaIpcGetEven-
tHandle. This function returns a cudaEvent_t that behaves like a locally created event with the
cudaEventDisableTiming flag specified. This event must be freed with cudaEventDestroy.
Performing operations on the imported event after the exported event has been freed with cu-
daEventDestroy will result in undefined behavior.
IPC functionality is restricted to devices with support for unified addressing on Linux and Win-
dows operating systems. IPC functionality on Windows is supported for compatibility purposes
but not recommended as it comes with performance cost. Users can test their device for IPC
functionality by calling cudaDeviceGetAttribute with cudaDevAttrIpcEventSupport
See also:
cudaEventCreate, cudaEventDestroy, cudaEventSynchronize, cudaEventQuery, cudaStreamWait-
Event, cudaIpcGetEventHandle, cudaIpcGetMemHandle, cudaIpcOpenMemHandle, cudaIpcClose-
MemHandle, ::cuIpcOpenEventHandle
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
▶ event - - Returns the imported event
▶ handle - - Interprocess handle to open
Returns
cudaSuccess, cudaErrorMapBufferObjectFailed, cudaErrorNotSupported, cudaError-
InvalidValue, cudaErrorDeviceUninitialized
__host__ cudaError_t cudaIpcOpenMemHandle(void **devPtr, cudaIpcMemHandle_t handle,
unsigned int flags)
Opens an interprocess memory handle exported from another process and returns a device
pointer usable in the local process.
Maps memory exported from another process with cudaIpcGetMemHandle into the current de-
vice address space. For contexts on different devices cudaIpcOpenMemHandle can attempt to
enable peer access between the devices as if the user called cudaDeviceEnablePeerAccess. This
behavior is controlled by the cudaIpcMemLazyEnablePeerAccess flag. cudaDeviceCanAccessPeer
can determine if a mapping is possible.
cudaIpcOpenMemHandle can open handles to devices that may not be visible in the process call-
ing the API.
Contexts that may open ::cudaIpcMemHandles are restricted in the following way.
::cud-
aIpcMemHandles from each device in a given process may only be opened by one context per
device per other process.
196
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
If the memory handle has already been opened by the current context, the reference count on
the handle is incremented by 1 and the existing device pointer is returned.
Memory returned from cudaIpcOpenMemHandle must be freed with cudaIpcCloseMemHandle.
Calling cudaFree on an exported memory region before calling cudaIpcCloseMemHandle in the
importing context will result in undefined behavior.
IPC functionality is restricted to devices with support for unified addressing on Linux and Win-
dows operating systems. IPC functionality on Windows is supported for compatibility purposes
but not recommended as it comes with performance cost. Users can test their device for IPC
functionality by calling cudaDeviceGetAttribute with cudaDevAttrIpcEventSupport
See also:
cudaMalloc, cudaFree, cudaIpcGetEventHandle, cudaIpcOpenEventHandle, cudaIpcGetMemHan-
dle, cudaIpcCloseMemHandle, cudaDeviceEnablePeerAccess, cudaDeviceCanAccessPeer, ::cuIp-
cOpenMemHandle
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: No guarantees are made about the address returned in *devPtr .
In particular, multiple processes may not receive the same address for the same handle.
Parameters
▶ devPtr - - Returned device pointer
▶ handle - - ::cudaIpcMemHandle to open
▶ flags - - Flags for this operation. Must be specified as cudaIpcMemLazyEn-
ablePeerAccess
Returns
cudaSuccess, cudaErrorMapBufferObjectFailed, cudaErrorInvalidResourceHandle,
cudaErrorDeviceUninitialized, cudaErrorTooManyPeers, cudaErrorNotSupported, cu-
daErrorInvalidValue
__host__ cudaError_t cudaSetDevice(int device)
Set device to be used for GPU executions.
Sets device as the current device for the calling host thread. Valid device id’s are 0 to (cudaGet-
DeviceCount() - 1).
Any device memory subsequently allocated from this host thread using cudaMalloc(), cudaMal-
locPitch() or cudaMallocArray() will be physically resident on device. Any host memory allocated
from this host thread using cudaMallocHost() or cudaHostAlloc() or cudaHostRegister() will have
6.3. Device Management
197
CUDA Runtime API Reference Manual, Release 13.5
its lifetime associated with device. Any streams or events created from this host thread will be
associated with device. Any kernels launched from this host thread using the <<<>>> operator
or cudaLaunchKernel() will be executed on device when using the NULL or per-thread streams
(otherwise, they will be executed on the device associated with the stream).
This call may be made from any host thread, to any device, and at any time. This function will do
no synchronization with the previous or new device, and should only take significant time when
it initializes the runtime’s context state. This call will bind the primary context of the specified
device to the calling thread and all the subsequent memory allocations, stream and event cre-
ations will be associated with the primary context. This function will also immediately initialize
the runtime state on the primary context, and the context will be current on device immedi-
ately. This function will return an error if the device is in cudaComputeModeExclusiveProcess and
is occupied by another process or if the device is in cudaComputeModeProhibited.
It is not required to call cudaInitDevice before using this function.
See also:
cudaGetDeviceCount, cudaGetDevice, cudaGetDeviceProperties, cudaChooseDevice, cudaInitDe-
vice, ::cuCtxSetCurrent
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
device - - Device on which the active host thread should execute the device code.
Returns
cudaSuccess, cudaErrorInvalidDevice, ::cudaErrorDeviceUnavailable,
__host__ cudaError_t cudaSetDeviceFlags(unsigned int flags)
Sets flags to be used for device executions.
Records flags as the flags for the current device. If the current device has been set and that
device has already been initialized, the previous flags are overwritten. If the current device has
not been initialized, it is initialized with the provided flags. If no device has been made current to
the calling thread, a default device is selected and initialized with the provided flags.
The three LSBs of the flags parameter can be used to control how the CPU thread interacts
with the OS scheduler when waiting for results from the device.
▶ cudaDeviceScheduleAuto: The default value if the flags parameter is zero, uses a heuristic
based on the number of active CUDA contexts in the process C and the number of logical
processors in the system P. If C > P, then CUDA will yield to other OS threads when waiting for
the device, otherwise CUDA will not yield while waiting for results and actively spin on the
processor. Additionally, on Tegra devices, cudaDeviceScheduleAuto uses a heuristic based
198
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
on the power profile of the platform and may choose cudaDeviceScheduleBlockingSync for
low-powered devices.
▶ cudaDeviceScheduleSpin: Instruct CUDA to actively spin when waiting for results from the
device. This can decrease latency when waiting for the device, but may lower the perfor-
mance of CPU threads if they are performing work in parallel with the CUDA thread.
▶ cudaDeviceScheduleYield: Instruct CUDA to yield its thread when waiting for results from
the device. This can increase latency when waiting for the device, but can increase the per-
formance of CPU threads performing work in parallel with the device.
▶ cudaDeviceScheduleBlockingSync: Instruct CUDA to block the CPU thread on a synchroniza-
tion primitive when waiting for the device to finish work.
▶ cudaDeviceBlockingSync: Instruct CUDA to block the CPU thread on a synchronization prim-
itive when waiting for the device to finish work. Deprecated: This flag was deprecated as of
CUDA 4.0 and replaced with cudaDeviceScheduleBlockingSync.
▶ cudaDeviceMapHost: This flag enables allocating pinned host memory that is accessible to
the device. It is implicit for the runtime but may be absent if a context is created using the
driver API. If this flag is not set, cudaHostGetDevicePointer() will always return a failure code.
▶ cudaDeviceLmemResizeToMax: Instruct CUDA to not reduce local memory after resizing
local memory for a kernel. This can prevent thrashing by local memory allocations when
launching many kernels with high local memory usage at the cost of potentially increased
memory usage. Deprecated: This flag is deprecated and the behavior enabled by this flag is
now the default and cannot be disabled.
▶ cudaDeviceSyncMemops: Ensures that synchronous memory operations initiated on this
context will always synchronize. See further documentation in the section titled “API Syn-
chronization behavior” to learn more about cases when synchronous memory operations
can exhibit asynchronous behavior.
See also:
cudaGetDeviceFlags, cudaGetDeviceCount, cudaGetDevice, cudaGetDeviceProperties, cudaSetDe-
vice, cudaSetValidDevices, cudaInitDevice, cudaChooseDevice, ::cuDevicePrimaryCtxSetFlags
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
flags - - Parameters for device operation
Returns
cudaSuccess, cudaErrorInvalidValue
6.3. Device Management
199
CUDA Runtime API Reference Manual, Release 13.5
__host__ cudaError_t cudaSetValidDevices(int *device_arr, int len)
Set a list of devices that can be used for CUDA.
Sets a list of devices for CUDA execution in priority order using device_arr. The parameter len
specifies the number of elements in the list. CUDA will try devices from the list sequentially until
it finds one that works. If this function is not called, or if it is called with a len of 0, then CUDA
will go back to its default behavior of trying devices sequentially from a default list containing
all of the available CUDA devices in the system. If a specified device ID in the list does not exist,
this function will return cudaErrorInvalidDevice. If len is not 0 and device_arr is NULL or if len
exceeds the number of devices in the system, then cudaErrorInvalidValue is returned.
See also:
cudaGetDeviceCount, cudaSetDevice, cudaGetDeviceProperties, cudaSetDeviceFlags, cuda-
ChooseDevice
Note: Note that this function may also return error codes from previous, asynchronous launches.
Note: Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficient-
Driver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note: Note that as specified by cudaStreamAddCallback no CUDA function may be called from
callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in
such case.
Parameters
▶ device_arr - - List of devices to try
▶ len - - Number of devices in specified list
Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorInvalidDevice
6.4. Device Management [DEPRECATED]
This section describes the deprecated device management functions of the CUDA runtime application
programming interface.
200
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
Functions
__host__ cudaError_t cudaDeviceGetSharedMemConfig(enum cudaSharedMemConfig *pConfig)
Returns the shared memory configuration for the current device.
__host__ cudaError_t cudaDeviceSetSharedMemConfig(enum cudaSharedMemConfig config)
Sets the shared memory configuration for the current device.
6.4.1. Functions
__host__ cudaError_t cudaDeviceGetSharedMemConfig(enum cudaSharedMemConfig *pConfig)
Returns the shared memory configuration for the current device.
Deprecated:
This function will return in pConfig the current size of shared memory banks on the current
device. On devices with configurable shared memory banks, cudaDeviceSetSharedMemConfig
can be used to change this setting, so that all subsequent kernel launches will by default use the
new bank size. When cudaDeviceGetSharedMemConfig is called on devices without configurable
shared memory, it will return the fixed bank size of the hardware.
The returned bank configurations can be either:
▶ cudaSharedMemBankSizeFourByte - shared memory bank width is four bytes.
▶ cudaSharedMemBankSizeEightByte - shared memory bank width is eight bytes.
See also:
cudaDeviceSetCacheConfig, cudaDeviceGetCacheConfig, cudaDeviceSetSharedMemConfig, cud-
aFuncSetCacheConfig, ::cuCtxGetSharedMemConfig
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
pConfig - - Returned cache configuration
Returns
cudaSuccess, cudaErrorInvalidValue
6.4. Device Management [DEPRECATED]
201
CUDA Runtime API Reference Manual, Release 13.5
__host__ cudaError_t cudaDeviceSetSharedMemConfig(enum cudaSharedMemConfig config)
Sets the shared memory configuration for the current device.
Deprecated:
On devices with configurable shared memory banks, this function will set the shared memory
bank size which is used for all subsequent kernel launches. Any per-function setting of shared
memory set via cudaFuncSetSharedMemConfig will override the device wide setting.
Changing the shared memory configuration between launches may introduce a device side syn-
chronization point.
Changing the shared memory bank size will not increase shared memory usage or affect oc-
cupancy of kernels, but may have major effects on performance. Larger bank sizes will allow for
greater potential bandwidth to shared memory, but will change what kinds of accesses to shared
memory will result in bank conflicts.
This function will do nothing on devices with fixed shared memory bank size.
The supported bank configurations are:
▶ cudaSharedMemBankSizeDefault: set bank width the device default (currently, four bytes)
▶ cudaSharedMemBankSizeFourByte: set shared memory bank width to be four bytes na-
tively.
▶ cudaSharedMemBankSizeEightByte: set shared memory bank width to be eight bytes na-
tively.
See also:
cudaDeviceSetCacheConfig, cudaDeviceGetCacheConfig, cudaDeviceGetSharedMemConfig, cud-
aFuncSetCacheConfig, ::cuCtxSetSharedMemConfig
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
config - - Requested cache configuration
Returns
cudaSuccess, cudaErrorInvalidValue
202
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
6.5. Direct3D 10 Interoperability
impl_private
impl_private
This section describes the Direct3D 10 interoperability functions of the CUDA runtime application
programming interface. Note that mapping of Direct3D 10 resources is performed with the graphics
API agnostic, resource mapping interface described in Graphics Interopability.
Enumerations
cudaD3D10DeviceList
CUDA devices corresponding to a D3D10 device.
Functions
__host__ cudaError_t cudaD3D10GetDevice(int *device, IDXGIAdapter *pAdapter)
Gets the device number for an adapter.
__host__ cudaError_t cudaD3D10GetDevices(unsigned int *pCudaDeviceCount, int *pCudaDevices,
unsigned int cudaDeviceCount, ID3D10Device *pD3D10Device, enum cudaD3D10DeviceList
deviceList)
Gets the CUDA devices corresponding to a Direct3D 10 device.
__host__ cudaError_t cudaGraphicsD3D10RegisterResource(struct cudaGraphicsResource
**re-
source, ID3D10Resource *pD3DResource, unsigned int flags)
Registers a Direct3D 10 resource for access by CUDA.
6.5.1. Enumerations
enum cudaD3D10DeviceList
CUDA devices corresponding to a D3D10 device.
Values:
enumerator cudaD3D10DeviceListAll = 1
The CUDA devices for all GPUs used by a D3D10 device.
enumerator cudaD3D10DeviceListCurrentFrame = 2
The CUDA devices for the GPUs used by a D3D10 device in its currently rendering frame.
enumerator cudaD3D10DeviceListNextFrame = 3
The CUDA devices for the GPUs to be used by a D3D10 device in the next frame
6.5. Direct3D 10 Interoperability
203
CUDA Runtime API Reference Manual, Release 13.5
6.5.2. Functions
__host__ cudaError_t cudaD3D10GetDevice(int *device, IDXGIAdapter *pAdapter)
Gets the device number for an adapter.
Returns in *device the CUDA-compatible device corresponding to the adapter pAdapter ob-
tained from ::IDXGIFactory::EnumAdapters. This call will succeed only if a device on adapter
pAdapter is CUDA-compatible.
See also:
cudaGraphicsD3D10RegisterResource, ::cuD3D10GetDevice
Note: Note that this function may also return error codes from previous, asynchronous launches.
Parameters
▶ device - - Returns the device corresponding to pAdapter
▶ pAdapter - - D3D10 adapter to get device for
Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorUnknown
__host__ cudaError_t cudaD3D10GetDevices(unsigned int *pCudaDeviceCount, int *pCudaDevices,
unsigned int cudaDeviceCount, ID3D10Device
*pD3D10Device, enum cudaD3D10DeviceList
deviceList)
Gets the CUDA devices corresponding to a Direct3D 10 device.
Returns in *pCudaDeviceCount the number of CUDA-compatible devices corresponding to the
Direct3D 10 device pD3D10Device. Also returns in *pCudaDevices at most cudaDeviceCount
of the the CUDA-compatible devices corresponding to the Direct3D 10 device pD3D10Device.
If any of the GPUs being used to render pDevice are not CUDA capable then the call will return
cudaErrorNoDevice.
See also:
cudaGraphicsUnregisterResource,
cudaGraphicsMapResources,
cudaGraphicsSubRe-
sourceGetMappedArray, cudaGraphicsResourceGetMappedPointer, ::cuD3D10GetDevices
Note: Note that this function may also return error codes from previous, asynchronous launches.
Parameters
▶ pCudaDeviceCount - - Returned number of CUDA devices corresponding to
pD3D10Device
▶ pCudaDevices - - Returned CUDA devices corresponding to pD3D10Device
204
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
▶ cudaDeviceCount - - The size of the output device array pCudaDevices
▶ pD3D10Device - - Direct3D 10 device to query for CUDA devices
▶ deviceList - - The set of devices to return.
This set may be cu-
daD3D10DeviceListAll for all devices, cudaD3D10DeviceListCurrentFrame
for the devices used to render the current frame (in SLI), or cu-
daD3D10DeviceListNextFrame for the devices used to render the next frame
(in SLI).
Returns
cudaSuccess, cudaErrorNoDevice, cudaErrorUnknown
__host__ cudaError_t cudaGraphicsD3D10RegisterResource(struct cudaGraphicsResource
**resource, ID3D10Resource
*pD3DResource, unsigned int
flags)
Registers a Direct3D 10 resource for access by CUDA.
Registers the Direct3D 10 resource pD3DResource for access by CUDA.
If this call is successful, then the application will be able to map and unmap this resource until it
is unregistered through cudaGraphicsUnregisterResource(). Also on success, this call will increase
the internal reference count on pD3DResource. This reference count will be decremented when
this resource is unregistered through cudaGraphicsUnregisterResource().
This call potentially has a high-overhead and should not be called every frame in interactive ap-
plications.
The type of pD3DResource must be one of the following.
▶ ::ID3D10Buffer: may be accessed via a device pointer
▶ ::ID3D10Texture1D: individual subresources of the texture may be accessed via arrays
▶ ::ID3D10Texture2D: individual subresources of the texture may be accessed via arrays
▶ ::ID3D10Texture3D: individual subresources of the texture may be accessed via arrays
The flags argument may be used to specify additional parameters at register time. The valid
values for this parameter are
▶ cudaGraphicsRegisterFlagsNone: Specifies no hints about how this resource will be used.
▶ cudaGraphicsRegisterFlagsSurfaceLoadStore: Specifies that CUDA will bind this resource to
a surface reference.
▶ cudaGraphicsRegisterFlagsTextureGather: Specifies that CUDA will perform texture gather
operations on this resource.
Not all Direct3D resources of the above types may be used for interoperability with CUDA. The
following are some limitations.
▶ The primary rendertarget may not be registered with CUDA.
▶ Textures which are not of a format which is 1, 2, or 4 channels of 8, 16, or 32-bit integer or
floating-point data cannot be shared.
▶ Surfaces of depth or stencil formats cannot be shared.
6.5. Direct3D 10 Interoperability
205
CUDA Runtime API Reference Manual, Release 13.5
A complete list of supported DXGI formats is as follows. For compactness the notation A_{B,C,D}
represents A_B, A_C, and A_D.
▶ DXGI_FORMAT_A8_UNORM
▶ DXGI_FORMAT_B8G8R8A8_UNORM
▶ DXGI_FORMAT_B8G8R8X8_UNORM
▶ DXGI_FORMAT_R16_FLOAT
▶ DXGI_FORMAT_R16G16B16A16_{FLOAT,SINT,SNORM,UINT,UNORM}
▶ DXGI_FORMAT_R16G16_{FLOAT,SINT,SNORM,UINT,UNORM}
▶ DXGI_FORMAT_R16_{SINT,SNORM,UINT,UNORM}
▶ DXGI_FORMAT_R32_FLOAT
▶ DXGI_FORMAT_R32G32B32A32_{FLOAT,SINT,UINT}
▶ DXGI_FORMAT_R32G32_{FLOAT,SINT,UINT}
▶ DXGI_FORMAT_R32_{SINT,UINT}
▶ DXGI_FORMAT_R8G8B8A8_{SINT,SNORM,UINT,UNORM,UNORM_SRGB}
▶ DXGI_FORMAT_R8G8_{SINT,SNORM,UINT,UNORM}
▶ DXGI_FORMAT_R8_{SINT,SNORM,UINT,UNORM}
If pD3DResource is of incorrect type or is already registered, then cudaErrorInvalidResourceHan-
dle is returned. If pD3DResource cannot be registered, then cudaErrorUnknown is returned.
See also:
cudaGraphicsUnregisterResource,
cudaGraphicsMapResources,
cudaGraphicsSub-
ResourceGetMappedArray,
cudaGraphicsResourceGetMappedPointer,
::cuGraph-
icsD3D10RegisterResource
Note: Note that this function may also return error codes from previous, asynchronous launches.
Parameters
▶ resource - - Pointer to returned resource handle
▶ pD3DResource - - Direct3D resource to register
▶ flags - - Parameters for resource registration
Returns
cudaSuccess,
cudaErrorInvalidDevice,
cudaErrorInvalidValue,
cudaErrorIn-
validResourceHandle, cudaErrorUnknown
206
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
6.6. Direct3D 10 Interoperability [DEPRECATED]
This section describes deprecated Direct3D 10 interoperability functions.
Enumerations
cudaD3D10MapFlags
CUDA D3D10 Map Flags.
cudaD3D10RegisterFlags
CUDA D3D10 Register Flags.
Functions
__host__ cudaError_t cudaD3D10GetDirect3DDevice(ID3D10Device **ppD3D10Device)
Gets the Direct3D device against which the current CUDA context was created.
__host__ cudaError_t cudaD3D10MapResources(int count, ID3D10Resource **ppResources)
Maps Direct3D Resources for access by CUDA.
__host__ cudaError_t cudaD3D10RegisterResource(ID3D10Resource *pResource, unsigned int flags)
Registers a Direct3D 10 resource for access by CUDA.
__host__ cudaError_t cudaD3D10ResourceGetMappedArray(cudaArray **ppArray, ID3D10Resource
*pResource, unsigned int subResource)
Gets an array through which to access a subresource of a Direct3D resource which has been
mapped for access by CUDA.
__host__ cudaError_t cudaD3D10ResourceGetMappedPitch(size_t *pPitch, size_t *pPitchSlice,
ID3D10Resource *pResource, unsigned int subResource)
Gets the pitch of a subresource of a Direct3D resource which has been mapped for access by
CUDA.
__host__ cudaError_t cudaD3D10ResourceGetMappedPointer(void
**pPointer, ID3D10Resource
*pResource, unsigned int subResource)
Gets a pointer through which to access a subresource of a Direct3D resource which has been
mapped for access by CUDA.
__host__ cudaError_t cudaD3D10ResourceGetMappedSize(size_t *pSize, ID3D10Resource *pRe-
source, unsigned int subResource)
Gets the size of a subresource of a Direct3D resource which has been mapped for access by
CUDA.
__host__ cudaError_t cudaD3D10ResourceGetSurfaceDimensions(size_t *pWidth, size_t *pHeight,
size_t *pDepth, ID3D10Resource *pResource, unsigned int subResource)
Gets the dimensions of a registered Direct3D surface.
__host__ cudaError_t cudaD3D10ResourceSetMapFlags(ID3D10Resource *pResource, unsigned int
flags)
Set usage flags for mapping a Direct3D resource.
__host__ cudaError_t cudaD3D10SetDirect3DDevice(ID3D10Device *pD3D10Device, int device=-1)
Sets the Direct3D 10 device to use for interoperability with a CUDA device.
__host__ cudaError_t cudaD3D10UnmapResources(int count, ID3D10Resource **ppResources)
Unmaps Direct3D resources.
6.6. Direct3D 10 Interoperability [DEPRECATED]
207
CUDA Runtime API Reference Manual, Release 13.5
__host__ cudaError_t cudaD3D10UnregisterResource(ID3D10Resource *pResource)
Unregisters a Direct3D resource.
6.6.1. Enumerations
enum cudaD3D10MapFlags
CUDA D3D10 Map Flags.
Values:
enumerator cudaD3D10MapFlagsNone = 0
Default; Assume resource can be read/written.
enumerator cudaD3D10MapFlagsReadOnly = 1
CUDA kernels will not write to this resource.
enumerator cudaD3D10MapFlagsWriteDiscard = 2
CUDA kernels will only write to and will not read from this resource.
enum cudaD3D10RegisterFlags
CUDA D3D10 Register Flags.
Values:
enumerator cudaD3D10RegisterFlagsNone = 0
Default; Resource can be accessed through a void*.
enumerator cudaD3D10RegisterFlagsArray = 1
Resource can be accessed through a CUarray*.
6.6.2. Functions
__host__ cudaError_t cudaD3D10GetDirect3DDevice(ID3D10Device **ppD3D10Device)
Gets the Direct3D device against which the current CUDA context was created.
Deprecated:
This function is deprecated as of CUDA 5.0.
This function is deprecated and should no longer be used. It is no longer necessary to associate
a CUDA device with a D3D10 device in order to achieve maximum interoperability performance.
See also:
cudaD3D10SetDirect3DDevice
208
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
Note: Note that this function may also return error codes from previous, asynchronous launches.
Parameters
ppD3D10Device - - Returns the Direct3D device for this thread
Returns
cudaSuccess, cudaErrorUnknown
__host__ cudaError_t cudaD3D10MapResources(int count, ID3D10Resource **ppResources)
Maps Direct3D Resources for access by CUDA.
Deprecated:
This function is deprecated as of CUDA 3.0.
Maps the count Direct3D resources in ppResources for access by CUDA.
The resources in ppResources may be accessed in CUDA kernels until they are unmapped. Di-
rect3D 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 Direct3D calls issued be-
fore cudaD3D10MapResources() will complete before any CUDA kernels issued after cu-
daD3D10MapResources() begin.
If any of ppResources have not been registered for use with CUDA or if ppResources contains
any duplicate entries then cudaErrorInvalidResourceHandle is returned. If any of ppResources
are presently mapped for access by CUDA then cudaErrorUnknown is returned.
See also:
cudaGraphicsMapResources
Note: Note that this function may also return error codes from previous, asynchronous launches.
Parameters
▶ count - - Number of resources to map for CUDA
▶ ppResources - - Resources to map for CUDA
Returns
cudaSuccess, cudaErrorInvalidResourceHandle, cudaErrorUnknown
__host__ cudaError_t cudaD3D10RegisterResource(ID3D10Resource *pResource, unsigned int
flags)
Registers a Direct3D 10 resource for access by CUDA.
Deprecated:
This function is deprecated as of CUDA 3.0.
6.6. Direct3D 10 Interoperability [DEPRECATED]
209
CUDA Runtime API Reference Manual, Release 13.5
Registers the Direct3D resource pResource for access by CUDA.
If this call is successful, then the application will be able to map and unmap this resource until it
is unregistered through cudaD3D10UnregisterResource(). Also on success, this call will increase
the internal reference count on pResource. This reference count will be decremented when this
resource is unregistered through cudaD3D10UnregisterResource().
This call potentially has a high-overhead and should not be called every frame in interactive ap-
plications.
The type of pResource must be one of the following:
▶ ::ID3D10Buffer: Cannot be used with flags set to cudaD3D10RegisterFlagsArray.
▶ ::ID3D10Texture1D: No restrictions.
▶ ::ID3D10Texture2D: No restrictions.
▶ ::ID3D10Texture3D: No restrictions.
The flags argument specifies the mechanism through which CUDA will access the Direct3D
resource. The following values are allowed.
▶ cudaD3D10RegisterFlagsNone: Specifies that CUDA will access this resource through a
void*. The pointer, size, and pitch for each subresource of this resource may be queried
through cudaD3D10ResourceGetMappedPointer(), cudaD3D10ResourceGetMappedSize(),
and cudaD3D10ResourceGetMappedPitch() respectively. This option is valid for all resource
types.
▶ cudaD3D10RegisterFlagsArray: Specifies that CUDA will access this resource through a
CUarray queried on a sub-resource basis through cudaD3D10ResourceGetMappedArray().
This option is only valid for resources of type ::ID3D10Texture1D, ::ID3D10Texture2D, and
::ID3D10Texture3D.
Not all Direct3D resources of the above types may be used for interoperability with CUDA. The
following are some limitations.
▶ The primary rendertarget may not be registered with CUDA.
▶ Resources allocated as shared may not be registered with CUDA.
▶ Textures which are not of a format which is 1, 2, or 4 channels of 8, 16, or 32-bit integer or
floating-point data cannot be shared.
▶ Surfaces of depth or stencil formats cannot be shared.
If Direct3D interoperability is not initialized on this context then cudaErrorInvalidDevice is re-
turned. If pResource is of incorrect type or is already registered then cudaErrorInvalidResource-
Handle is returned. If pResource cannot be registered then cudaErrorUnknown is returned.
See also:
cudaGraphicsD3D10RegisterResource
Note: Note that this function may also return error codes from previous, asynchronous launches.
210
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
Parameters
▶ pResource - - Resource to register
▶ flags - - Parameters for resource registration
Returns
cudaSuccess,
cudaErrorInvalidDevice,
cudaErrorInvalidValue,
cudaErrorIn-
validResourceHandle, cudaErrorUnknown
__host__ cudaError_t cudaD3D10ResourceGetMappedArray(cudaArray **ppArray, ID3D10Resource
*pResource, unsigned int
subResource)
Gets an array through which to access a subresource of a Direct3D resource which has been
mapped for access by CUDA.
Deprecated:
This function is deprecated as of CUDA 3.0.
Returns in *ppArray an array through which the subresource of the mapped Direct3D resource
pResource which corresponds to subResource may be accessed. The value set in ppArray may
change every time that pResource is mapped.
If pResource is not registered, then cudaErrorInvalidResourceHandle is returned. If pRe-
source was not registered with usage flags cudaD3D10RegisterFlagsArray, then cudaErrorIn-
validResourceHandle is returned. If pResource is not mapped then cudaErrorUnknown is re-
turned.
For
usage
requirements
of
the
subResource
parameter,
see
cu-
daD3D10ResourceGetMappedPointer().
See also:
cudaGraphicsSubResourceGetMappedArray
Note: Note that this function may also return error codes from previous, asynchronous launches.
Parameters
▶ ppArray - - Returned array corresponding to subresource
▶ pResource - - Mapped resource to access
▶ subResource - - Subresource of pResource to access
Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorInvalidResourceHandle, cudaErrorUn-
known
__host__ cudaError_t cudaD3D10ResourceGetMappedPitch(size_t *pPitch, size_t *pPitchSlice,
ID3D10Resource *pResource,
unsigned int subResource)
6.6. Direct3D 10 Interoperability [DEPRECATED]
211
CUDA Runtime API Reference Manual, Release 13.5
Gets the pitch of a subresource of a Direct3D resource which has been mapped for access by
CUDA.
Deprecated:
This function is deprecated as of CUDA 3.0.
Returns in *pPitch and *pPitchSlice the pitch and Z-slice pitch of the subresource of the
mapped Direct3D resource pResource, which corresponds to subResource. The values set in
pPitch and pPitchSlice may change every time that pResource is mapped.
The pitch and Z-slice pitch values may be used to compute the location of a sample on a surface
as follows.
For a 2D surface, the byte offset of the sample at position x, y from the base pointer of the
surface is:
y * pitch + (bytes per pixel) * x
For a 3D surface, the byte offset of the sample at position x, y, z from the base pointer of the
surface is:
z* slicePitch + y * pitch + (bytes per pixel) * x
Both parameters pPitch and pPitchSlice are optional and may be set to NULL.
If pResource is not of type ::ID3D10Texture1D, ::ID3D10Texture2D, or ::ID3D10Texture3D, or if
pResource has not been registered for use with CUDA, then cudaErrorInvalidResourceHandle is
returned. If pResource was not registered with usage flags cudaD3D10RegisterFlagsNone, then
cudaErrorInvalidResourceHandle is returned. If pResource is not mapped for access by CUDA
then cudaErrorUnknown is returned.
For
usage
requirements
of
the
subResource
parameter
see
cu-
daD3D10ResourceGetMappedPointer().
See also:
cudaGraphicsSubResourceGetMappedArray
Note: Note that this function may also return error codes from previous, asynchronous launches.
Parameters
▶ pPitch - - Returned pitch of subresource
▶ pPitchSlice - - Returned Z-slice pitch of subresource
▶ pResource - - Mapped resource to access
▶ subResource - - Subresource of pResource to access
Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorInvalidResourceHandle, cudaErrorUn-
known
212
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
__host__ cudaError_t cudaD3D10ResourceGetMappedPointer(void **pPointer, ID3D10Resource
*pResource, unsigned int
subResource)
Gets a pointer through which to access a subresource of a Direct3D resource which has been
mapped for access by CUDA.
Deprecated:
This function is deprecated as of CUDA 3.0.
Returns in *pPointer the base pointer of the subresource of the mapped Direct3D resource
pResource which corresponds to subResource. The value set in pPointer may change every
time that pResource is mapped.
If pResource is not registered, then cudaErrorInvalidResourceHandle is returned. If pResource
was not registered with usage flags cudaD3D9RegisterFlagsNone, then cudaErrorInvalidResource-
Handle is returned. If pResource is not mapped then cudaErrorUnknown is returned.
If pResource is of type ::ID3D10Buffer then subResource must be 0. If pResource is of any
other type, then the value of subResource must come from the subresource calculation in
::D3D10CalcSubResource().
See also:
cudaGraphicsResourceGetMappedPointer
Note: Note that this function may also return error codes from previous, asynchronous launches.
Parameters
▶ pPointer - - Returned pointer corresponding to subresource
▶ pResource - - Mapped resource to access
▶ subResource - - Subresource of pResource to access
Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorInvalidResourceHandle, cudaErrorUn-
known
__host__ cudaError_t cudaD3D10ResourceGetMappedSize(size_t *pSize, ID3D10Resource
*pResource, unsigned int subResource)
Gets the size of a subresource of a Direct3D resource which has been mapped for access by
CUDA.
Deprecated:
This function is deprecated as of CUDA 3.0.
Returns in *pSize the size of the subresource of the mapped Direct3D resource pResource
which corresponds to subResource. The value set in pSize may change every time that pRe-
source is mapped.
6.6. Direct3D 10 Interoperability [DEPRECATED]
213
CUDA Runtime API Reference Manual, Release 13.5
If pResource has not been registered for use with CUDA then ::cudaErrorInvalidHandle is re-
turned. If pResource was not registered with usage flags cudaD3D10RegisterFlagsNone, then
cudaErrorInvalidResourceHandle is returned. If pResource is not mapped for access by CUDA
then cudaErrorUnknown is returned.
For
usage
requirements
of
the
subResource
parameter
see
cu-
daD3D10ResourceGetMappedPointer().
See also:
cudaGraphicsResourceGetMappedPointer
Note: Note that this function may also return error codes from previous, asynchronous launches.
Parameters
▶ pSize - - Returned size of subresource
▶ pResource - - Mapped resource to access
▶ subResource - - Subresource of pResource to access
Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorInvalidResourceHandle, cudaErrorUn-
known
__host__ cudaError_t cudaD3D10ResourceGetSurfaceDimensions(size_t *pWidth, size_t
*pHeight, size_t *pDepth,
ID3D10Resource *pResource,
unsigned int subResource)
Gets the dimensions of a registered Direct3D surface.
Deprecated:
This function is deprecated as of CUDA 3.0.
Returns in *pWidth, *pHeight, and *pDepth the dimensions of the subresource of the mapped
Direct3D resource pResource which corresponds to subResource.
Since anti-aliased surfaces may have multiple samples per pixel, it is possible that the dimen-
sions of a resource will be an integer factor larger than the dimensions reported by the Direct3D
runtime.
The parameters pWidth, pHeight, and pDepth are optional. For 2D surfaces, the value returned
in *pDepth will be 0.
If pResource is not of type ::ID3D10Texture1D, ::ID3D10Texture2D, or ::ID3D10Texture3D, or if
pResource has not been registered for use with CUDA, then ::cudaErrorInvalidHandle is returned.
For
usage
requirements
of
subResource
parameters
see
cu-
daD3D10ResourceGetMappedPointer().
See also:
cudaGraphicsSubResourceGetMappedArray
214
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
Note: Note that this function may also return error codes from previous, asynchronous launches.
Parameters
▶ pWidth - - Returned width of surface
▶ pHeight - - Returned height of surface
▶ pDepth - - Returned depth of surface
▶ pResource - - Registered resource to access
▶ subResource - - Subresource of pResource to access
Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorInvalidResourceHandle,
__host__ cudaError_t cudaD3D10ResourceSetMapFlags(ID3D10Resource *pResource, unsigned
int flags)
Set usage flags for mapping a Direct3D resource.
Deprecated:
This function is deprecated as of CUDA 3.0.
Set usage flags for mapping the Direct3D resource pResource.
Changes to flags will take effect the next time pResource is mapped. The flags argument may
be any of the following:
▶ cudaD3D10MapFlagsNone: Specifies no hints about how this resource will be used. It is
therefore assumed that this resource will be read from and written to by CUDA kernels. This
is the default value.
▶ cudaD3D10MapFlagsReadOnly: Specifies that CUDA kernels which access this resource will
not write to this resource.
▶ cudaD3D10MapFlagsWriteDiscard: Specifies that CUDA kernels which access this resource
will not read from this resource and will write over the entire contents of the resource, so
none of the data previously stored in the resource will be preserved.
If pResource has not been registered for use with CUDA then ::cudaErrorInvalidHandle is re-
turned. If pResource is presently mapped for access by CUDA then cudaErrorUnknown is re-
turned.
See also:
cudaGraphicsResourceSetMapFlags
Note: Note that this function may also return error codes from previous, asynchronous launches.
Parameters
6.6. Direct3D 10 Interoperability [DEPRECATED]
215
CUDA Runtime API Reference Manual, Release 13.5
▶ pResource - - Registered resource to set flags for
▶ flags - - Parameters for resource mapping
Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorInvalidResourceHandle, cudaErrorUn-
known,
__host__ cudaError_t cudaD3D10SetDirect3DDevice(ID3D10Device *pD3D10Device, int device =
-1)
Sets the Direct3D 10 device to use for interoperability with a CUDA device.
Deprecated:
This function is deprecated as of CUDA 5.0.
This function is deprecated and should no longer be used. It is no longer necessary to associate
a CUDA device with a D3D10 device in order to achieve maximum interoperability performance.
This function will immediately initialize the primary context on device if needed.
See also:
cudaD3D10GetDevice, cudaGraphicsD3D10RegisterResource, cudaDeviceReset
Note: Note that this function may also return error codes from previous, asynchronous launches.
Parameters
▶ pD3D10Device - - Direct3D device to use for interoperability
▶ device - - The CUDA device to use. This device must be among the devices
returned when querying cudaD3D10DeviceListAll from cudaD3D10GetDevices,
may be set to -1 to automatically select an appropriate CUDA device.
Returns
cudaSuccess, cudaErrorInitializationError, cudaErrorInvalidValue, cudaErrorSetOn-
ActiveProcess
__host__ cudaError_t cudaD3D10UnmapResources(int count, ID3D10Resource **ppResources)
Unmaps Direct3D resources.
Deprecated:
This function is deprecated as of CUDA 3.0.
Unmaps the count Direct3D resource in ppResources.
This function provides the synchronization guarantee that any CUDA kernels issued be-
fore cudaD3D10UnmapResources() will complete before any Direct3D calls issued after cu-
daD3D10UnmapResources() begin.
If any of ppResources have not been registered for use with CUDA or if ppResources contains
any duplicate entries, then cudaErrorInvalidResourceHandle is returned. If any of ppResources
are not presently mapped for access by CUDA then cudaErrorUnknown is returned.
216
Chapter 6. APIs
CUDA Runtime API Reference Manual, Release 13.5
See also:
cudaGraphicsUnmapResources
Note: Note that this function may also return error codes from previous, asynchronous launches.
Parameters
▶ count - - Number of resources to unmap for CUDA
▶ ppResources - - Resources to unmap for CUDA
Returns
cudaSuccess, cudaErrorInvalidResourceHandle, cudaErrorUnknown
__host__ cudaError_t cudaD3D10UnregisterResource(ID3D10Resource *pResource)
Unregisters a Direct3D resource.
Deprecated:
This function is deprecated as of CUDA 3.0.
Unregisters the Direct3D resource resource so it is not accessible by CUDA unless registered
again.
If pResource is not registered, then cudaErrorInvalidResourceHandle is returned.
See also:
cudaGraphicsUnregisterResource
Note: Note that this function may also return error codes from previous, asynchronous launches.
Parameters
pResource - - Resource to unregister
Returns
cudaSuccess, cudaErrorInvalidResourceHandle, cudaErrorUnknown
6.7. Direct3D 11 Interoperability
impl_private
impl_private
This section describes the Direct3D 11 interoperability functions of the CUDA runtime application
programming interface. Note that mapping of Direct3D 11 resources is performed with the graphics
API agnostic, resource mapping interface described in Graphics Interopability.
6.7. Direct3D 11 Interoperability
217
CUDA Runtime API Reference Manual, Release 13.5
Enumerations
cudaD3D11DeviceList
CUDA devices corresponding to a D3D11 device.
Functions
__host__ cudaError_t cudaD3D11GetDevice(int *device, IDXGIAdapter *pAdapter)
Gets the device number for an adapter.
__host__ cudaError_t cudaD3D11GetDevices(unsigned int *pCudaDeviceCount, int *pCudaDevices,
unsigned int cudaDeviceCount, ID3D11Device *pD3D11Device, enum cudaD3D11DeviceList
deviceList)
Gets the CUDA devices corresponding to a Direct3D 11 device.
__host__ cudaError_t cudaGraphicsD3D11RegisterResource(struct cudaGraphicsResource
**re-
source, ID3D11Resource *pD3DResource, unsigned int flags)
Register a Direct3D 11 resource for access by CUDA.
6.7.1. Enumerations
enum cudaD3D11DeviceList
CUDA devices corresponding to a D3D11 device.
Values:
enumerator cudaD3D11DeviceListAll = 1
The CUDA devices for all GPUs used by a D3D11 device.
enumerator cudaD3D11DeviceListCurrentFrame = 2
The CUDA devices for the GPUs used by a D3D11 device in its currently rendering frame.
enumerator cudaD3D11DeviceListNextFrame = 3
The CUDA devices for the GPUs to be used by a D3D11 device in the next frame
6.7.2. Functions
__host__ cudaError_t cudaD3D11GetDevice(int *device, IDXGIAdapter *pAdapter)
Gets the device number for an adapter.
Returns in *device the CUDA-compatible device corresponding to the adapter pAdapter ob-
tained from ::IDXGIFactory::EnumAdapters. This call will succeed only if a device on adapter
pAdapter is CUDA-compatible.
See also:
cudaGraphicsUnregisterResource,
cudaGraphicsMapResources,
cudaGraphicsSubRe-
sourceGetMappedArray, cudaGraphicsResourceGetMappedPointer, ::cuD3D11GetDevice
218
Chapter 6. APIs

 

 

 

 

 

 

 

 

Content      ..     1      2      3      4      ..