6.21. Graphics Interoperability
This section describes the graphics interoperability functions of the CUDA runtime application programming interface.
Functions
- __host__ cudaError_t cudaGraphicsMapResources(int count, cudaGraphicsResource_t *resources, cudaStream_t stream=0)
Map graphics resources for access by CUDA.
- __host__ cudaError_t cudaGraphicsResourceGetMappedMipmappedArray(cudaMipmappedArray_t *mipmappedArray, cudaGraphicsResource_t resource)
Get a mipmapped array through which to access a mapped graphics resource.
- __host__ cudaError_t cudaGraphicsResourceGetMappedPointer(void **devPtr, size_t *size, cudaGraphicsResource_t resource)
Get an device pointer through which to access a mapped graphics resource.
- __host__ cudaError_t cudaGraphicsResourceSetMapFlags(cudaGraphicsResource_t resource, unsigned int flags)
Set usage flags for mapping a graphics resource.
- __host__ cudaError_t cudaGraphicsSubResourceGetMappedArray(cudaArray_t *array, cudaGraphicsResource_t resource, unsigned int arrayIndex, unsigned int mipLevel)
Get an array through which to access a subresource of a mapped graphics resource.
- __host__ cudaError_t cudaGraphicsUnmapResources(int count, cudaGraphicsResource_t *resources, cudaStream_t stream=0)
Unmap graphics resources.
- __host__ cudaError_t cudaGraphicsUnregisterResource(cudaGraphicsResource_t resource)
Unregisters a graphics resource for access by CUDA.
6.21.1. Functions
-
__host__ cudaError_t cudaGraphicsMapResources(int count, cudaGraphicsResource_t *resources, cudaStream_t stream = 0)
Map graphics resources for access by CUDA.
Maps the
countgraphics resources inresourcesfor access by CUDA.The resources in
resourcesmay be accessed by CUDA until they are unmapped. The graphics API from whichresourceswere registered should not access any resources while they are mapped by CUDA. If an application does so, the results are undefined.This function provides the synchronization guarantee that any graphics calls issued before cudaGraphicsMapResources() will complete before any subsequent CUDA work issued in
streambegins.If
resourcescontains any duplicate entries then cudaErrorInvalidResourceHandle is returned. If any ofresourcesare presently mapped for access by CUDA then cudaErrorUnknown is returned.See also
cudaGraphicsResourceGetMappedPointer, cudaGraphicsSubResourceGetMappedArray, cudaGraphicsUnmapResources, ::cuGraphicsMapResources
Note
This function uses standard default stream semantics.
Note
Note that this function may also return error codes from previous, asynchronous launches.
Note
Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficientDriver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note
Note that as specified by cudaStreamAddCallback no CUDA function may be called from callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in such case.
- Parameters
count – - Number of resources to map
resources – - Resources to map for CUDA
stream – - Stream for synchronization
- Returns
cudaSuccess, cudaErrorInvalidResourceHandle, cudaErrorUnknown
-
__host__ cudaError_t cudaGraphicsResourceGetMappedMipmappedArray(cudaMipmappedArray_t *mipmappedArray, cudaGraphicsResource_t resource)
Get a mipmapped array through which to access a mapped graphics resource.
Returns in
*mipmappedArraya mipmapped array through which the mapped graphics resourceresourcemay be accessed. The value set inmipmappedArraymay change every time thatresourceis mapped.If
resourceis not a texture then it cannot be accessed via an array and cudaErrorUnknown is returned. Ifresourceis not mapped then cudaErrorUnknown is returned.See also
cudaGraphicsResourceGetMappedPointer, ::cuGraphicsResourceGetMappedMipmappedArray
Note
Note that this function may also return error codes from previous, asynchronous launches.
Note
Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficientDriver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note
Note that as specified by cudaStreamAddCallback no CUDA function may be called from callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in such case.
- Parameters
mipmappedArray – - Returned mipmapped array through which
resourcemay be accessedresource – - Mapped resource to access
- Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorInvalidResourceHandle, cudaErrorUnknown
-
__host__ cudaError_t cudaGraphicsResourceGetMappedPointer(void **devPtr, size_t *size, cudaGraphicsResource_t resource)
Get an device pointer through which to access a mapped graphics resource.
Returns in
*devPtra pointer through which the mapped graphics resourceresourcemay be accessed. Returns in*sizethe size of the memory in bytes which may be accessed from that pointer. The value set indevPtrmay change every time thatresourceis mapped.If
resourceis not a buffer then it cannot be accessed via a pointer and cudaErrorUnknown is returned. Ifresourceis not mapped then cudaErrorUnknown is returned.See also
cudaGraphicsMapResources, cudaGraphicsSubResourceGetMappedArray, ::cuGraphicsResourceGetMappedPointer
Note
Note that this function may also return error codes from previous, asynchronous launches.
Note
Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficientDriver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note
Note that as specified by cudaStreamAddCallback no CUDA function may be called from callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in such case.
- Parameters
devPtr – - Returned pointer through which
resourcemay be accessedsize – - Returned size of the buffer accessible starting at
*devPtrresource – - Mapped resource to access
- Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorInvalidResourceHandle, cudaErrorUnknown
-
__host__ cudaError_t cudaGraphicsResourceSetMapFlags(cudaGraphicsResource_t resource, unsigned int flags)
Set usage flags for mapping a graphics resource.
Set
flagsfor mapping the graphics resourceresource.Changes to
flagswill take effect the next timeresourceis mapped. Theflagsargument may be any of the following:cudaGraphicsMapFlagsNone: Specifies no hints about how
resourcewill be used. It is therefore assumed that CUDA may read from or write toresource.cudaGraphicsMapFlagsReadOnly: Specifies that CUDA will not write to
resource.cudaGraphicsMapFlagsWriteDiscard: Specifies CUDA will not read from
resourceand will write over the entire contents ofresource, so none of the data previously stored inresourcewill be preserved.
If
resourceis presently mapped for access by CUDA then cudaErrorUnknown is returned. Ifflagsis not one of the above values then cudaErrorInvalidValue is returned.See also
cudaGraphicsMapResources, ::cuGraphicsResourceSetMapFlags
Note
Note that this function may also return error codes from previous, asynchronous launches.
Note
Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficientDriver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note
Note that as specified by cudaStreamAddCallback no CUDA function may be called from callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in such case.
- Parameters
resource – - Registered resource to set flags for
flags – - Parameters for resource mapping
- Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorInvalidResourceHandle, cudaErrorUnknown,
-
__host__ cudaError_t cudaGraphicsSubResourceGetMappedArray(cudaArray_t *array, cudaGraphicsResource_t resource, unsigned int arrayIndex, unsigned int mipLevel)
Get an array through which to access a subresource of a mapped graphics resource.
Returns in
*arrayan array through which the subresource of the mapped graphics resourceresourcewhich corresponds to array indexarrayIndexand mipmap levelmipLevelmay be accessed. The value set inarraymay change every time thatresourceis mapped.If
resourceis not a texture then it cannot be accessed via an array and cudaErrorUnknown is returned. IfarrayIndexis not a valid array index forresourcethen cudaErrorInvalidValue is returned. IfmipLevelis not a valid mipmap level forresourcethen cudaErrorInvalidValue is returned. Ifresourceis not mapped then cudaErrorUnknown is returned.See also
cudaGraphicsResourceGetMappedPointer, ::cuGraphicsSubResourceGetMappedArray
Note
Note that this function may also return error codes from previous, asynchronous launches.
Note
Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficientDriver 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
array – - Returned array through which a subresource of
resourcemay be accessedresource – - Mapped resource to access
arrayIndex – - Array index for array textures or cubemap face index as defined by cudaGraphicsCubeFace for cubemap textures for the subresource to access
mipLevel – - Mipmap level for the subresource to access
- Returns
cudaSuccess, cudaErrorInvalidValue, cudaErrorInvalidResourceHandle, cudaErrorUnknown
-
__host__ cudaError_t cudaGraphicsUnmapResources(int count, cudaGraphicsResource_t *resources, cudaStream_t stream = 0)
Unmap graphics resources.
Unmaps the
countgraphics resources inresources.Once unmapped, the resources in
resourcesmay not be accessed by CUDA until they are mapped again.This function provides the synchronization guarantee that any CUDA work issued in
streambefore cudaGraphicsUnmapResources() will complete before any subsequently issued graphics work begins.If
resourcescontains any duplicate entries then cudaErrorInvalidResourceHandle is returned. If any ofresourcesare not presently mapped for access by CUDA then cudaErrorUnknown is returned.See also
cudaGraphicsMapResources, ::cuGraphicsUnmapResources
Note
This function uses standard default stream semantics.
Note
Note that this function may also return error codes from previous, asynchronous launches.
Note
Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficientDriver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note
Note that as specified by cudaStreamAddCallback no CUDA function may be called from callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in such case.
- Parameters
count – - Number of resources to unmap
resources – - Resources to unmap
stream – - Stream for synchronization
- Returns
cudaSuccess, cudaErrorInvalidResourceHandle, cudaErrorUnknown
-
__host__ cudaError_t cudaGraphicsUnregisterResource(cudaGraphicsResource_t resource)
Unregisters a graphics resource for access by CUDA.
Unregisters the graphics resource
resourceso it is not accessible by CUDA unless registered again.If
resourceis invalid then cudaErrorInvalidResourceHandle is returned.See also
cudaGraphicsD3D9RegisterResource, cudaGraphicsD3D10RegisterResource, cudaGraphicsD3D11RegisterResource, cudaGraphicsGLRegisterBuffer, cudaGraphicsGLRegisterImage, ::cuGraphicsUnregisterResource
Note
Note that this function may also return error codes from previous, asynchronous launches.
Note
Note that this function may also return cudaErrorInitializationError, cudaErrorInsufficientDriver or cudaErrorNoDevice if this call tries to initialize internal CUDA RT state.
Note
Note that as specified by cudaStreamAddCallback no CUDA function may be called from callback. cudaErrorNotPermitted may, but is not guaranteed to, be returned as a diagnostic in such case.
Note
Use of the handle after this call is undefined behavior.
- Parameters
resource – - Resource to unregister
- Returns
cudaSuccess, cudaErrorInvalidResourceHandle, cudaErrorUnknown