NvSciBufObj as a CUDA Pointer / Array
The following section describes the steps required to use NvSciBufObj as a CUDA pointer/array.
- Allocate NvSciBufObj.
- The application creates NvSciBufAttrList and sets the
NvSciBufGeneralAttrKey_GpuId
attribute to specify the ID of the GPU that shares the buffer, along with other attributes. - If the same object is used by other UMDs, the corresponding attribute lists must
be created and reconciled. The reconciled list must be used to allocate the
NvSciBufObj.Note:
The attribute list and NvSciBuf objects must be maintained by the application.
- The application creates NvSciBufAttrList and sets the
- Query NvSciBufObj attributes to fill CUDA descriptors.
- The application must query the allocated NvSciBufObj for required attributes to fill the CUDA external memory descriptor.
- NvSciBuf object registration with CUDA.
-
cudaImportExternalMemory()
must be used to register the allocated NvSciBuf object with CUDA by filling up cudaExternalMemoryHandleDesc for type cudaExternalMemoryHandleTypeNvSciBuf. -
cudaDestroyExternalMemory()
API must be used to free the CUDA external memory. CUDA mappings created from external memory must be freed before invoking this API.
-
- Getting CUDA pointer/array from imported external memory.
-
cudaExternalMemoryGetMappedBuffer()
maps a buffer onto an imported memory object and returns a CUDA device pointer. The properties of the buffer must be described in the CUDA ExternalMemory buffer description by querying attributes from NvSciBufObj. The returned pointer device pointer must be freed using cudaFree. -
cudaExternalMemoryGetMappedMipmappedArray()
maps a CUDA mipmapped array onto an external object and returns a handle to it. The properties of the buffer must be described in the CUDA ExternalMemory MipmappedArray desc by querying attributes from NvSciBufObj. The returned CUDA mipmapped array must be freed using cudaFreeMipmappedArray.
-
Note:
All the APIs mentioned in the sections above are CUDA-runtime APIs. Each of them has an equivalent driver API. The syntax and usage of both versions are the same.