Loading...
Searching...
No Matches
CudaInterop.cpp File Reference

Driver-API-only impl of the CudaInterop C API. More...

Detailed Description

Driver-API-only impl of the CudaInterop C API.

Uses Gfx/Graph/interop/CudaFunctions.hpp for dlopen'd entry points; no link-time CUDAToolkit dependency. All cu* calls go through the shared CudaFunctions table.

Classes

struct  CudaInteropContext_t
 
struct  CudaInteropResource_t
 
struct  CudaInteropSemaphore_t
 
struct  CudaInteropImage_t
 

Macros

#define CU_CHECK(call, ctx, mapped, what)
 
#define CU_CHECK_INIT(call, ctx, mapped, what)
 

Functions

CudaInteropError cuda_interop_init (CudaInteropContextHandle *outCtx)
 
void cuda_interop_shutdown (CudaInteropContextHandle ctx)
 
bool cuda_interop_available (void)
 
const char * cuda_interop_get_error_string (CudaInteropContextHandle ctx)
 
CudaInteropError cuda_interop_import_d3d11_buffer (CudaInteropContextHandle ctx, void *d3d11_buffer, void *d3d11_device, uint32_t buffer_size, void **out_device_ptr, CudaInteropResourceHandle *out_handle)
 
CudaInteropError cuda_interop_import_d3d12_buffer (CudaInteropContextHandle ctx, void *shared_resource_handle, uint64_t buffer_size, void **out_device_ptr, CudaInteropResourceHandle *out_handle)
 
CudaInteropError cuda_interop_import_vulkan_buffer (CudaInteropContextHandle ctx, void *external_memory_handle, uint64_t buffer_size, void **out_device_ptr, CudaInteropResourceHandle *out_handle)
 
CudaInteropError cuda_interop_import_gl_buffer (CudaInteropContextHandle ctx, uint32_t gl_buffer_id, uint32_t buffer_size, void **out_device_ptr, CudaInteropResourceHandle *out_handle)
 
void cuda_interop_release_buffer (CudaInteropContextHandle ctx, CudaInteropResourceHandle h)
 
CudaInteropError cuda_interop_register_gl_buffer (CudaInteropContextHandle ctx, uint32_t gl_buffer_id, uint32_t buffer_size, CudaInteropResourceHandle *out_handle)
 
CudaInteropError cuda_interop_gl_write_buffer (CudaInteropContextHandle ctx, CudaInteropResourceHandle h, void *src_device_ptr, uint32_t size)
 
CudaInteropError cuda_interop_gl_read_buffer (CudaInteropContextHandle ctx, CudaInteropResourceHandle h, void *dst_device_ptr, uint32_t size)
 
CudaInteropError cuda_interop_register_gl_image (CudaInteropContextHandle ctx, uint32_t gl_texture_id, uint32_t gl_target, CudaInteropResourceHandle *out_handle)
 
CudaInteropError cuda_interop_gl_write_image (CudaInteropContextHandle ctx, CudaInteropResourceHandle h, void *src_device_ptr, uint32_t width_bytes, uint32_t height, uint32_t src_pitch_bytes)
 
CudaInteropError cuda_interop_import_vulkan_image (CudaInteropContextHandle ctx, void *external_memory_handle, uint64_t memory_size, const CudaInteropImageDesc *desc, uint64_t offset_in_memory, void **out_cuda_array, CudaInteropImageHandle *out_handle)
 
void cuda_interop_release_image (CudaInteropContextHandle ctx, CudaInteropImageHandle h)
 
CudaInteropError cuda_interop_import_d3d12_fence (CudaInteropContextHandle ctx, void *shared_fence_handle, CudaInteropSemaphoreHandle *sem)
 
CudaInteropError cuda_interop_import_vulkan_semaphore (CudaInteropContextHandle ctx, void *external_semaphore_handle, CudaInteropSemaphoreHandle *sem)
 
CudaInteropError cuda_interop_import_vulkan_semaphore_binary (CudaInteropContextHandle ctx, void *external_semaphore_handle, CudaInteropSemaphoreHandle *sem)
 
CudaInteropError cuda_interop_wait_semaphore (CudaInteropContextHandle ctx, CudaInteropSemaphoreHandle sem, uint64_t value)
 
void cuda_interop_release_semaphore (CudaInteropContextHandle ctx, CudaInteropSemaphoreHandle sem)
 
CudaInteropError cuda_interop_sync (CudaInteropContextHandle ctx)
 
CudaInteropError cuda_interop_copy_buffer_to_array (CudaInteropContextHandle ctx, void *src_device_ptr, void *dst_cuda_array, uint32_t width_bytes, uint32_t height, uint32_t src_pitch_bytes)
 
CudaInteropError cuda_interop_copy_array_to_buffer (CudaInteropContextHandle ctx, void *src_cuda_array, void *dst_device_ptr, uint32_t width_bytes, uint32_t height, uint32_t dst_pitch_bytes)
 
CudaInteropError cuda_interop_upload_buffer (CudaInteropContextHandle ctx, void *dst_device_ptr, const void *host_data, uint64_t size)
 
CudaInteropError cuda_interop_download_buffer (CudaInteropContextHandle ctx, void *host_data, void *src_device_ptr, uint64_t size)
 
CudaInteropError cuda_interop_alloc_buffer (CudaInteropContextHandle ctx, uint64_t size, void **out_device_ptr)
 
void cuda_interop_free_buffer (CudaInteropContextHandle ctx, void *device_ptr)
 
CudaInteropError cuda_interop_copy_dtod_2d (CudaInteropContextHandle ctx, void *dst_device_ptr, uint64_t dst_pitch_bytes, void *src_device_ptr, uint64_t src_pitch_bytes, uint64_t width_bytes, uint64_t height)
 
CudaInteropError cuda_interop_copy_dtod (CudaInteropContextHandle ctx, void *dst_device_ptr, void *src_device_ptr, uint64_t size)
 

Macro Definition Documentation

◆ CU_CHECK

#define CU_CHECK (   call,
  ctx,
  mapped,
  what 
)
Value:
do \
{ \
CUresult _r = (call); \
if(_r != CUDA_SUCCESS) \
return reportCuError((ctx), _r, (mapped), (what)); \
} while(0)

◆ CU_CHECK_INIT

#define CU_CHECK_INIT (   call,
  ctx,
  mapped,
  what 
)
Value:
do \
{ \
CUresult _r = (call); \
if(_r != CUDA_SUCCESS) \
{ \
const auto _e = reportCuError((ctx), _r, (mapped), (what)); \
destroyPartialContext((ctx)); \
return _e; \
} \
} while(0)

As CU_CHECK, but for the half-built context inside cuda_interop_init: there is no handle for the caller to shut down yet, so a failure has to undo what has been built so far itself. Otherwise a failure after cuDevicePrimaryCtxRetain leaks both the object and a permanent reference on the device's primary context, which keeps the whole CUDA context alive for the life of the process.