6.21. Graphics Interoperability
This section describes the graphics interoperability functions of the low-level CUDA driver application programming interface.
Functions
- CUresult cuGraphicsMapResources(unsigned int count, CUgraphicsResource *resources, CUstream hStream)
Map graphics resources for access by CUDA.
- CUresult cuGraphicsResourceGetMappedMipmappedArray(CUmipmappedArray *pMipmappedArray, CUgraphicsResource resource)
Get a mipmapped array through which to access a mapped graphics resource.
- CUresult cuGraphicsResourceGetMappedPointer(CUdeviceptr *pDevPtr, size_t *pSize, CUgraphicsResource resource)
Get a device pointer through which to access a mapped graphics resource.
- CUresult cuGraphicsResourceSetMapFlags(CUgraphicsResource resource, unsigned int flags)
Set usage flags for mapping a graphics resource.
- CUresult cuGraphicsSubResourceGetMappedArray(CUarray *pArray, CUgraphicsResource resource, unsigned int arrayIndex, unsigned int mipLevel)
Get an array through which to access a subresource of a mapped graphics resource.
- CUresult cuGraphicsUnmapResources(unsigned int count, CUgraphicsResource *resources, CUstream hStream)
Unmap graphics resources.
- CUresult cuGraphicsUnregisterResource(CUgraphicsResource resource)
Unregisters a graphics resource for access by CUDA.
6.21.1. Functions
-
CUresult cuGraphicsMapResources(unsigned int count, CUgraphicsResource *resources, CUstream hStream)
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 cuGraphicsMapResources() will complete before any subsequent CUDA work issued in
streambegins.If
resourcesincludes any duplicate entries then CUDA_ERROR_INVALID_HANDLE is returned. If any ofresourcesare presently mapped for access by CUDA then CUDA_ERROR_ALREADY_MAPPED is returned.See also
cuGraphicsResourceGetMappedPointer, cuGraphicsSubResourceGetMappedArray, cuGraphicsUnmapResources, ::cudaGraphicsMapResources
Note
This function uses standard default stream semantics.
Note
Note that this function may also return error codes from previous, asynchronous launches.
- Parameters
count – - Number of resources to map
resources – - Resources to map for CUDA usage
hStream – - Stream with which to synchronize
- Returns
CUDA_SUCCESS, CUDA_ERROR_DEINITIALIZED, CUDA_ERROR_NOT_INITIALIZED, CUDA_ERROR_INVALID_CONTEXT, CUDA_ERROR_INVALID_HANDLE, CUDA_ERROR_ALREADY_MAPPED, CUDA_ERROR_UNKNOWN
-
CUresult cuGraphicsResourceGetMappedMipmappedArray(CUmipmappedArray *pMipmappedArray, CUgraphicsResource resource)
Get a mipmapped array through which to access a mapped graphics resource.
Returns in
*pMipmappedArraya mipmapped array through which the mapped graphics resourceresource. The value set in*pMipmappedArraymay change every time thatresourceis mapped.If
resourceis not a texture then it cannot be accessed via a mipmapped array and CUDA_ERROR_NOT_MAPPED_AS_ARRAY is returned. Ifresourceis not mapped then CUDA_ERROR_NOT_MAPPED is returned.See also
cuGraphicsResourceGetMappedPointer, ::cudaGraphicsResourceGetMappedMipmappedArray
Note
Note that this function may also return error codes from previous, asynchronous launches.
- Parameters
pMipmappedArray – - Returned mipmapped array through which
resourcemay be accessedresource – - Mapped resource to access
- Returns
CUDA_SUCCESS, CUDA_ERROR_DEINITIALIZED, CUDA_ERROR_NOT_INITIALIZED, CUDA_ERROR_INVALID_CONTEXT, CUDA_ERROR_INVALID_VALUE, CUDA_ERROR_INVALID_HANDLE, CUDA_ERROR_NOT_MAPPED, CUDA_ERROR_NOT_MAPPED_AS_ARRAY
-
CUresult cuGraphicsResourceGetMappedPointer(CUdeviceptr *pDevPtr, size_t *pSize, CUgraphicsResource resource)
Get a device pointer through which to access a mapped graphics resource.
Returns in
*pDevPtra pointer through which the mapped graphics resourceresourcemay be accessed. Returns inpSizethe size of the memory in bytes which may be accessed from that pointer. The value set inpPointermay change every time thatresourceis mapped.If
resourceis not a buffer then it cannot be accessed via a pointer and CUDA_ERROR_NOT_MAPPED_AS_POINTER is returned. Ifresourceis not mapped then CUDA_ERROR_NOT_MAPPED is returned.See also
cuGraphicsMapResources, cuGraphicsSubResourceGetMappedArray, ::cudaGraphicsResourceGetMappedPointer
Note
Note that this function may also return error codes from previous, asynchronous launches.
- Parameters
pDevPtr – - Returned pointer through which
resourcemay be accessedpSize – - Returned size of the buffer accessible starting at
*pPointerresource – - Mapped resource to access
- Returns
CUDA_SUCCESS, CUDA_ERROR_DEINITIALIZED, CUDA_ERROR_NOT_INITIALIZED, CUDA_ERROR_INVALID_CONTEXT, CUDA_ERROR_INVALID_VALUE, CUDA_ERROR_INVALID_HANDLE, CUDA_ERROR_NOT_MAPPED, CUDA_ERROR_NOT_MAPPED_AS_POINTER
-
CUresult cuGraphicsResourceSetMapFlags(CUgraphicsResource 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:CU_GRAPHICS_MAP_RESOURCE_FLAGS_NONE: 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.
::CU_GRAPHICS_MAP_RESOURCE_FLAGS_READONLY: Specifies that CUDA kernels which access this resource will not write to this resource.
::CU_GRAPHICS_MAP_RESOURCE_FLAGS_WRITEDISCARD: 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
resourceis presently mapped for access by CUDA then CUDA_ERROR_ALREADY_MAPPED is returned. Ifflagsis not one of the above values then CUDA_ERROR_INVALID_VALUE is returned.See also
cuGraphicsMapResources, ::cudaGraphicsResourceSetMapFlags
Note
Note that this function may also return error codes from previous, asynchronous launches.
- Parameters
resource – - Registered resource to set flags for
flags – - Parameters for resource mapping
- Returns
CUDA_SUCCESS, CUDA_ERROR_DEINITIALIZED, CUDA_ERROR_NOT_INITIALIZED, CUDA_ERROR_INVALID_CONTEXT, CUDA_ERROR_INVALID_VALUE, CUDA_ERROR_INVALID_HANDLE, CUDA_ERROR_ALREADY_MAPPED
-
CUresult cuGraphicsSubResourceGetMappedArray(CUarray *pArray, CUgraphicsResource resource, unsigned int arrayIndex, unsigned int mipLevel)
Get an array through which to access a subresource of a mapped graphics resource.
Returns in
*pArrayan array through which the subresource of the mapped graphics resourceresourcewhich corresponds to array indexarrayIndexand mipmap levelmipLevelmay be accessed. The value set in*pArraymay change every time thatresourceis mapped.If
resourceis not a texture then it cannot be accessed via an array and CUDA_ERROR_NOT_MAPPED_AS_ARRAY is returned. IfarrayIndexis not a valid array index forresourcethen CUDA_ERROR_INVALID_VALUE is returned. IfmipLevelis not a valid mipmap level forresourcethen CUDA_ERROR_INVALID_VALUE is returned. Ifresourceis not mapped then CUDA_ERROR_NOT_MAPPED is returned.See also
cuGraphicsResourceGetMappedPointer, ::cudaGraphicsSubResourceGetMappedArray
Note
Note that this function may also return error codes from previous, asynchronous launches.
- Parameters
pArray – - 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 CUarray_cubemap_face for cubemap textures for the subresource to access
mipLevel – - Mipmap level for the subresource to access
- Returns
CUDA_SUCCESS, CUDA_ERROR_DEINITIALIZED, CUDA_ERROR_NOT_INITIALIZED, CUDA_ERROR_INVALID_CONTEXT, CUDA_ERROR_INVALID_VALUE, CUDA_ERROR_INVALID_HANDLE, CUDA_ERROR_NOT_MAPPED, CUDA_ERROR_NOT_MAPPED_AS_ARRAY
-
CUresult cuGraphicsUnmapResources(unsigned int count, CUgraphicsResource *resources, CUstream hStream)
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 cuGraphicsUnmapResources() will complete before any subsequently issued graphics work begins.If
resourcesincludes any duplicate entries then CUDA_ERROR_INVALID_HANDLE is returned. If any ofresourcesare not presently mapped for access by CUDA then CUDA_ERROR_NOT_MAPPED is returned.See also
cuGraphicsMapResources, ::cudaGraphicsUnmapResources
Note
This function uses standard default stream semantics.
Note
Note that this function may also return error codes from previous, asynchronous launches.
- Parameters
count – - Number of resources to unmap
resources – - Resources to unmap
hStream – - Stream with which to synchronize
- Returns
CUDA_SUCCESS, CUDA_ERROR_DEINITIALIZED, CUDA_ERROR_NOT_INITIALIZED, CUDA_ERROR_INVALID_CONTEXT, CUDA_ERROR_INVALID_HANDLE, CUDA_ERROR_NOT_MAPPED, CUDA_ERROR_UNKNOWN
-
CUresult cuGraphicsUnregisterResource(CUgraphicsResource 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 CUDA_ERROR_INVALID_HANDLE is returned.See also
cuGraphicsD3D9RegisterResource, cuGraphicsD3D10RegisterResource, cuGraphicsD3D11RegisterResource, cuGraphicsGLRegisterBuffer, cuGraphicsGLRegisterImage, ::cudaGraphicsUnregisterResource
Note
Note that this function may also return error codes from previous, asynchronous launches.
- Parameters
resource – - Resource to unregister
- Returns
CUDA_SUCCESS, CUDA_ERROR_DEINITIALIZED, CUDA_ERROR_NOT_INITIALIZED, CUDA_ERROR_INVALID_CONTEXT, CUDA_ERROR_INVALID_HANDLE, CUDA_ERROR_UNKNOWN