Interoperability

Both interoperate (primary context shared).

35.1 Runtime API vs Driver API

Runtime API (cuda*) Driver API (cu*) implicit context management explicit contexts (cuCtxCreate), modules, functions <<<>>> launch syntax easier, most common fine control, loading PTX/cubin at runtime, used by frameworks

Both interoperate (primary context shared).

35.2 Graphics interop (OpenGL, Vulkan, Direct3D)

Vulkan/D3D12 interop uses external memory and semaphores (cudaImportExternalMemory, cudaImportExternalSemaphore).

cudaGraphicsResource_t res;
cudaGraphicsGLRegisterBuffer(&res, vbo, cudaGraphicsMapFlagsWriteDiscard);
cudaGraphicsMapResources(1, &res, 0);
float4* d_ptr; size_t size;
cudaGraphicsResourceGetMappedPointer((void**)&d_ptr, &size, res);
animateVertices<<<grid, block>>>(d_ptr, time);          // CUDA writes directly into the OpenGL buffer
cudaGraphicsUnmapResources(1, &res, 0);

35.3 Inter-process communication (IPC)

cudaIpcMemHandle_t handle;
cudaIpcGetMemHandle(&handle, d_ptr);                    // process A: export
// send handle to process B (pipe, shared memory, socket)
cudaIpcOpenMemHandle(&d_ptr_b, handle, cudaIpcMemLazyEnablePeerAccess);   // process B: import

35.4 Sharing GPUs: MPS & MIG

MPS (Multi-Process Service): lets kernels from multiple processes run concurrently on one GPU (useful for MPI ranks).

MIG (Multi-Instance GPU, A100/H100+): partitions a GPU into isolated instances with dedicated SMs and memory (cloud/multi-tenant).

Time-slicing and vGPU in virtualized/Kubernetes environments.

35.5 Embedded & edge

Jetson (Orin, Thor) devices run CUDA with unified physical memory (zero-copy is efficient), JetPack SDK, DeepStream, TensorRT for edge AI.