Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions cuda_core/cuda/core/_cpp/resource_handles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ decltype(&cuLibraryUnload) p_cuLibraryUnload = nullptr;
decltype(&cuLibraryGetKernel) p_cuLibraryGetKernel = nullptr;

// GL interop pointers
decltype(&cuGraphicsUnmapResources) p_cuGraphicsUnmapResources = nullptr;
decltype(&cuGraphicsUnregisterResource) p_cuGraphicsUnregisterResource = nullptr;

// NVRTC function pointers
Expand Down Expand Up @@ -569,6 +570,23 @@ DevicePtrHandle deviceptr_create_with_owner(CUdeviceptr ptr, PyObject* owner) {
return DevicePtrHandle(box, &box->resource);
}

DevicePtrHandle deviceptr_create_mapped_graphics(
CUdeviceptr ptr,
const GraphicsResourceHandle& h_resource,
const StreamHandle& h_stream
) {
auto box = std::shared_ptr<DevicePtrBox>(
new DevicePtrBox{ptr, h_stream},
[h_resource](DevicePtrBox* b) {
GILReleaseGuard gil;
CUgraphicsResource resource = as_cu(h_resource);
p_cuGraphicsUnmapResources(1, &resource, as_cu(b->h_stream));
delete b;
}
);
return DevicePtrHandle(box, &box->resource);
}

// ============================================================================
// MemoryResource-owned Device Pointer Handles
// ============================================================================
Expand Down
11 changes: 11 additions & 0 deletions cuda_core/cuda/core/_cpp/resource_handles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ extern decltype(&cuLibraryUnload) p_cuLibraryUnload;
extern decltype(&cuLibraryGetKernel) p_cuLibraryGetKernel;

// Graphics interop
extern decltype(&cuGraphicsUnmapResources) p_cuGraphicsUnmapResources;
extern decltype(&cuGraphicsUnregisterResource) p_cuGraphicsUnregisterResource;

// ============================================================================
Expand Down Expand Up @@ -244,6 +245,16 @@ DevicePtrHandle deviceptr_create_ref(CUdeviceptr ptr);
// If owner is nullptr, equivalent to deviceptr_create_ref.
DevicePtrHandle deviceptr_create_with_owner(CUdeviceptr ptr, PyObject* owner);

// Create a device pointer handle for a mapped graphics resource.
// The pointer structurally depends on the provided graphics resource handle.
// When the last reference is released, cuGraphicsUnmapResources is called on
// the stored stream, then the graphics resource may be unregistered when its
// own handle is released.
DevicePtrHandle deviceptr_create_mapped_graphics(
CUdeviceptr ptr,
const GraphicsResourceHandle& h_resource,
const StreamHandle& h_stream);

// Callback type for MemoryResource deallocation.
// Called from the shared_ptr deleter when a handle created via
// deviceptr_create_with_mr is destroyed. The implementation is responsible
Expand Down
6 changes: 4 additions & 2 deletions cuda_core/cuda/core/_graphics.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ cdef class GraphicsResource:

cdef:
GraphicsResourceHandle _handle
bint _mapped
object _mapped_buffer
object _context_manager_stream
object _entered_buffer

cpdef close(self)
cpdef close(self, stream=*)
Loading
Loading