cuda.bindings._v2.driver.import_external_memory#
- cuda.bindings._v2.driver.import_external_memory(mem_handle_desc) intptr_t#
Imports an external memory object.
Imports an externally allocated memory object and returns a handle to that in
ext_mem_out. The properties of the handle being imported must be described inmem_handle_desc. TheCUDA_EXTERNAL_MEMORY_HANDLE_DESCstructure is defined as follows:. **View CUDA Toolkit Documentation for a C++ code example**. whereCUDA_EXTERNAL_MEMORY_HANDLE_DESC.typespecifies the type of handle being imported.CUexternalMemoryHandleTypeis defined as:. **View CUDA Toolkit Documentation for a C++ code example**. IfCUDA_EXTERNAL_MEMORY_HANDLE_DESC.typeisCU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD, thenCUDA_EXTERNAL_MEMORY_HANDLE_DESC.handle.fdmust be a valid file descriptor referencing a memory object. Ownership of the file descriptor is transferred to the CUDA driver when the handle is imported successfully. Performing any operations on the file descriptor after it is imported results in undefined behavior. IfCUDA_EXTERNAL_MEMORY_HANDLE_DESC.typeisCU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32, then exactly one ofCUDA_EXTERNAL_MEMORY_HANDLE_DESC.handle.win32.handleandCUDA_EXTERNAL_MEMORY_HANDLE_DESC.handle.win32.namemust not be NULL. IfCUDA_EXTERNAL_MEMORY_HANDLE_DESC.handle.win32.handleis not NULL, then it must represent a valid shared NT handle that references a memory object. Ownership of this handle is not transferred to CUDA after the import operation, so the application must release the handle using the appropriate system call. IfCUDA_EXTERNAL_MEMORY_HANDLE_DESC.handle.win32.nameis not NULL, then it must point to a NULL-terminated array of UTF-16 characters that refers to a memory object. IfCUDA_EXTERNAL_MEMORY_HANDLE_DESC.typeisCU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT, thenCUDA_EXTERNAL_MEMORY_HANDLE_DESC.handle.win32.handlemust be non-NULL andCUDA_EXTERNAL_MEMORY_HANDLE_DESC.handle.win32.namemust be NULL. The handle specified must be a globally shared KMT handle. This handle does not hold a reference to the underlying object, and thus will be invalid when all references to the memory object are destroyed. IfCUDA_EXTERNAL_MEMORY_HANDLE_DESC.typeisCU_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_HEAP, then exactly one ofCUDA_EXTERNAL_MEMORY_HANDLE_DESC.handle.win32.handleandCUDA_EXTERNAL_MEMORY_HANDLE_DESC.handle.win32.namemust not be NULL. IfCUDA_EXTERNAL_MEMORY_HANDLE_DESC.handle.win32.handleis not NULL, then it must represent a valid shared NT handle that is returned by ID3D12Device::CreateSharedHandle when referring to a ID3D12Heap object. This handle holds a reference to the underlying object. IfCUDA_EXTERNAL_MEMORY_HANDLE_DESC.handle.win32.nameis not NULL, then it must point to a NULL-terminated array of UTF-16 characters that refers to a ID3D12Heap object. IfCUDA_EXTERNAL_MEMORY_HANDLE_DESC.typeisCU_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_RESOURCE, then exactly one ofCUDA_EXTERNAL_MEMORY_HANDLE_DESC.handle.win32.handleandCUDA_EXTERNAL_MEMORY_HANDLE_DESC.handle.win32.namemust not be NULL. IfCUDA_EXTERNAL_MEMORY_HANDLE_DESC.handle.win32.handleis not NULL, then it must represent a valid shared NT handle that is returned by ID3D12Device::CreateSharedHandle when referring to a ID3D12Resource object. This handle holds a reference to the underlying object. IfCUDA_EXTERNAL_MEMORY_HANDLE_DESC.handle.win32.nameis not NULL, then it must point to a NULL-terminated array of UTF-16 characters that refers to a ID3D12Resource object. IfCUDA_EXTERNAL_MEMORY_HANDLE_DESC.typeisCU_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_RESOURCE, thenCUDA_EXTERNAL_MEMORY_HANDLE_DESC.handle.win32.handlemust represent a valid shared NT handle that is returned by IDXGIResource1::CreateSharedHandle when referring to a ID3D11Resource object. IfCUDA_EXTERNAL_MEMORY_HANDLE_DESC.handle.win32.nameis not NULL, then it must point to a NULL-terminated array of UTF-16 characters that refers to a ID3D11Resource object. IfCUDA_EXTERNAL_MEMORY_HANDLE_DESC.typeisCU_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_RESOURCE_KMT, thenCUDA_EXTERNAL_MEMORY_HANDLE_DESC.handle.win32.handlemust represent a valid shared KMT handle that is returned by IDXGIResource::GetSharedHandle when referring to a ID3D11Resource object andCUDA_EXTERNAL_MEMORY_HANDLE_DESC.handle.win32.namemust be NULL. IfCUDA_EXTERNAL_MEMORY_HANDLE_DESC.typeisCU_EXTERNAL_MEMORY_HANDLE_TYPE_NVSCIBUF, thenCUDA_EXTERNAL_MEMORY_HANDLE_DESC.handle.nvSciBufObjectmust be non-NULL and reference a valid NvSciBuf object. If the NvSciBuf object imported into CUDA is also mapped by other drivers, then the application must usecuWaitExternalSemaphoresAsyncorcuSignalExternalSemaphoresAsyncas appropriate barriers to maintain coherence between CUDA and the other drivers. SeeCUDA_EXTERNAL_SEMAPHORE_SIGNAL_SKIP_NVSCIBUF_MEMSYNCandCUDA_EXTERNAL_SEMAPHORE_WAIT_SKIP_NVSCIBUF_MEMSYNCfor memory synchronization. IfCUDA_EXTERNAL_MEMORY_HANDLE_DESC.typeisCU_EXTERNAL_MEMORY_HANDLE_TYPE_DMABUF_FD, thenCUDA_EXTERNAL_MEMORY_HANDLE_DESC.handle.fdmust be a valid file descriptor referencing a dma_buf object andCUDA_EXTERNAL_MEMORY_HANDLE_DESC.flagsmust be zero. Importing a dma_buf object is supported only on Tegra platform starting with Thor series. Mapping an imported dma_buf object as CUDA mipmapped array usingcuExternalMemoryGetMappedMipmappedArrayis not supported. The size of the memory object must be specified inCUDA_EXTERNAL_MEMORY_HANDLE_DESC.size. Specifying the flagCUDA_EXTERNAL_MEMORY_DEDICATEDinCUDA_EXTERNAL_MEMORY_HANDLE_DESC.flagsindicates that the resource is a dedicated resource. The definition of what a dedicated resource is outside the scope of this extension. This flag must be set ifCUDA_EXTERNAL_MEMORY_HANDLE_DESC.typeis one of the following:CU_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_RESOURCECU_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_RESOURCECU_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_RESOURCE_KMT.- Parameters:
mem_handle_desc (intptr_t) – Memory import handle descriptor.
- Returns:
Returned handle to an external memory object.
- Return type:
intptr_t
Note
If the Vulkan memory imported into CUDA is mapped on the CPU then the application must use vkInvalidateMappedMemoryRanges/vkFlushMappedMemoryRanges as well as appropriate Vulkan pipeline barriers to maintain coherence between CPU and GPU. For more information on these APIs, please refer to “Synchronization and Cache Control” chapter from Vulkan specification.
See also
cuImportExternalMemory