Skip to content

Commit

Permalink
Some more cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
SveSop committed Dec 27, 2024
1 parent 66dcfa0 commit a16ece9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 37 deletions.
2 changes: 1 addition & 1 deletion dlls/nvcuda/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ HANDLE open_shared_resource(HANDLE kmt_handle, LPCWSTR name)
return shared_resource;
}

int get_cuda_memory_fd(HANDLE win32_handle)
int get_shared_resource_fd(HANDLE win32_handle)
{
IO_STATUS_BLOCK iosb;
obj_handle_t unix_resource;
Expand Down
50 changes: 15 additions & 35 deletions dlls/nvcuda/nvcuda.c
Original file line number Diff line number Diff line change
Expand Up @@ -3910,41 +3910,21 @@ CUresult WINAPI wine_cuImportExternalMemory(void *extMem_out, const CUDA_EXTERNA
TRACE("(%p, %p)\n", extMem_out, memHandleDesc);

CUDA_EXTERNAL_MEMORY_HANDLE_DESC linuxHandleDesc = *memHandleDesc;
HANDLE handle;

/* Linux libcuda does not work win32 handles */
if (linuxHandleDesc.type == CU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT)
{
HANDLE handle = open_shared_resource(linuxHandleDesc.handle.win32.handle, linuxHandleDesc.handle.win32.name);
int unix_fd = get_cuda_memory_fd(handle);

if (unix_fd < 0)
{
ERR("Failed to retrieve Unix FD for Win32 KMT handle (%p)\n", linuxHandleDesc.handle.win32.handle);
return CUDA_ERROR_INVALID_HANDLE;
}

linuxHandleDesc.type = CU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD;
linuxHandleDesc.handle.fd = unix_fd;
}

if (linuxHandleDesc.type == CU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32)
{
int unix_fd = get_cuda_memory_fd(linuxHandleDesc.handle.win32.handle);

if (unix_fd < 0)
{
ERR("Failed to retrieve Unix FD for Win32 handle (%p)\n", linuxHandleDesc.handle.win32.handle);
return CUDA_ERROR_INVALID_HANDLE;
}

linuxHandleDesc.type = CU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD;
linuxHandleDesc.handle.fd = unix_fd;
}

if (linuxHandleDesc.type != CU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD)
switch (linuxHandleDesc.type)
{
ERR("MemoryType not supported!\n");
return CUDA_ERROR_INVALID_HANDLE;
case CU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32:
linuxHandleDesc.handle.fd = get_shared_resource_fd(linuxHandleDesc.handle.win32.handle);
linuxHandleDesc.type = CU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD;
break;
case CU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT:
handle = open_shared_resource(linuxHandleDesc.handle.win32.handle, linuxHandleDesc.handle.win32.name);
linuxHandleDesc.handle.fd = get_shared_resource_fd(handle);
linuxHandleDesc.type = CU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD;
default:
break;
}

CUresult ret = pcuImportExternalMemory(extMem_out, &linuxHandleDesc);
Expand Down Expand Up @@ -3980,16 +3960,16 @@ CUresult WINAPI wine_cuImportExternalSemaphore(void *extSem_out, const CUDA_EXTE
switch (linuxHandleDesc.type)
{
case CU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32:
linuxHandleDesc.handle.fd = get_cuda_memory_fd(linuxHandleDesc.handle.win32.handle);
linuxHandleDesc.handle.fd = get_shared_resource_fd(linuxHandleDesc.handle.win32.handle);
linuxHandleDesc.type = CU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD;
break;
case CU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT:
handle = open_shared_resource(linuxHandleDesc.handle.win32.handle, linuxHandleDesc.handle.win32.name);
linuxHandleDesc.handle.fd = get_cuda_memory_fd(handle);
linuxHandleDesc.handle.fd = get_shared_resource_fd(handle);
linuxHandleDesc.type = CU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD;
break;
case CU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_TIMELINE_SEMAPHORE_WIN32:
linuxHandleDesc.handle.fd = get_cuda_memory_fd(linuxHandleDesc.handle.win32.handle);
linuxHandleDesc.handle.fd = get_shared_resource_fd(linuxHandleDesc.handle.win32.handle);
linuxHandleDesc.type = CU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_TIMELINE_SEMAPHORE_FD;
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion dlls/nvcuda/nvcuda.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

void __attribute((visibility("hidden"))) cuda_process_tls_callbacks(DWORD reason);
CUresult __attribute((visibility("hidden"))) cuda_get_table(const void **table, const CUuuid *uuid, const void *orig_table, CUresult orig_result);
int __attribute((visibility("hidden"))) get_cuda_memory_fd(HANDLE win32_handle);
int __attribute((visibility("hidden"))) get_shared_resource_fd(HANDLE win32_handle);
HANDLE __attribute((visibility("hidden"))) open_shared_resource(HANDLE kmt_handle, LPCWSTR name);

#endif

0 comments on commit a16ece9

Please sign in to comment.