cuda.core 1.3.0 Release Notes#

New features#

  • Added the read-only ManagedBuffer.last_prefetch_location property, which reports the destination requested by the most recent explicit prefetch across the buffer. It returns a Device or Host, including NUMA-specific host locations on CUDA 13, and None if any page has never been prefetched or the pages do not share one last-prefetch location. This reports the requested target, not current residency or completion of the asynchronous prefetch operation. (#2109)

  • Added CUDAWarning, the warning category cuda.core uses for CUDA errors that cannot be raised, such as a failed driver call while a resource is released by the garbage collector. Filter on it with warnings.filterwarnings("error", category=cuda.core.CUDAWarning) to make such failures loud. The new error handling page documents what an exception from cuda.core guarantees, how failures that cannot be raised are reported, and how context restoration failures and sticky CUDA errors are handled.

Fixes and enhancements#

  • Device methods that create resources or synchronize now act on that device’s bound context, even when another device is current. They do not change which device is current. For example, dev1.sync() synchronizes device 1’s bound context even when device 0 is current, and no longer touches other contexts on device 1 (such as a green context). Device.set_current() now always returns a Context with the correct device ID; passing a context created on a different device than the receiver now delegates to that device’s own set_current() instead of raising, so a context this method returns can always be pushed back through any Device object. (#2311)

  • Stream.wait() given a stream now works when that stream belongs to a device that is not current. The temporary ordering event is created in the waited-on stream’s context rather than the current one, which cuEventRecord rejects when the two differ. The stream ordering applied when importing foreign arrays and tensors uses the producer stream’s context the same way. (#2311)

  • LegacyPinnedMemoryResource.device_id now returns -1, as documented for memory that is not bound to a device and as PinnedMemoryResource already does, instead of raising RuntimeError. Buffer.device_id on such a buffer returns -1 as well, which also lets a pinned buffer back a linear or pitched texture resource.

  • Cleanup failures are now reported as CUDAWarning instead of being written to stderr with print or fprintf, so they can be filtered, captured with warnings.catch_warnings(), and escalated. Failures of cuStreamDestroy, cuEventDestroy, cuMemFree, cuMemFreeAsync, cuMemFreeHost, cuMemPoolDestroy, cuGreenCtxDestroy, cuGraphDestroy, cuGraphExecDestroy, cuGraphicsUnregisterResource, cuLinkDestroy, cuArrayDestroy, cuMipmappedArrayDestroy, cuTexObjectDestroy, cuSurfObjectDestroy, user-object releases and the NVRTC, NVVM and nvJitLink destroy calls made from destructors were previously discarded; they are now reported. CUDA_ERROR_DEINITIALIZED (the driver is shutting down) is not reported. Test code that matched the old stderr text uses pytest.warns(CUDAWarning) instead.

  • When a Device method has to run in the device’s context and the caller’s context cannot be restored afterwards, the created resource is destroyed and the raised CUDAError now carries a note (Python 3.11+; appended to the message on 3.10) stating that the caller’s context could not be restored and which context is current. Previously the error named only the driver status of the failed cuCtxSetCurrent call. If the call itself failed as well, its error is raised and the restoration failure is the note. A restoration failure during resource cleanup is reported as CUDAWarning.

  • Updating a memcpy or memset graph node whose context differs from the current one no longer risks a dangling node parameter when the caller’s context cannot be restored after the update: the resources referenced by the new parameters are now retained before the restoration failure is raised.

  • Device.set_current() with an explicit Context now switches contexts with a single driver call, so a failure leaves the previous context current instead of leaving the thread with no context. It also works when no context is current, returning None.

  • A failed rollback of a partially embedded child graph node is now attached as a note to the exception that triggered the rollback (reported as CUDAWarning on Python 3.10), and a failed cuStreamEndCapture made when a still-building GraphBuilder is garbage collected is now reported as CUDAWarning; both were silent.

  • Stream.device and related queries on a stream whose context is not current now restore the caller’s context even when the device query fails.