cuda.core 1.3.0 Release Notes#
New features#
Added the read-only
ManagedBuffer.last_prefetch_locationproperty, which reports the destination requested by the most recent explicit prefetch across the buffer. It returns aDeviceorHost, including NUMA-specific host locations on CUDA 13, andNoneif 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 categorycuda.coreuses 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 withwarnings.filterwarnings("error", category=cuda.core.CUDAWarning)to make such failures loud. The new error handling page documents what an exception fromcuda.coreguarantees, how failures that cannot be raised are reported, and how context restoration failures and sticky CUDA errors are handled.
Fixes and enhancements#
Devicemethods 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 aContextwith the correct device ID; passing a context created on a different device than the receiver now delegates to that device’s ownset_current()instead of raising, so a context this method returns can always be pushed back through anyDeviceobject. (#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, whichcuEventRecordrejects 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_idnow returns-1, as documented for memory that is not bound to a device and asPinnedMemoryResourcealready does, instead of raisingRuntimeError.Buffer.device_idon such a buffer returns-1as well, which also lets a pinned buffer back a linear or pitched texture resource.Cleanup failures are now reported as
CUDAWarninginstead of being written tostderrwithprintorfprintf, so they can be filtered, captured withwarnings.catch_warnings(), and escalated. Failures ofcuStreamDestroy,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 oldstderrtext usespytest.warns(CUDAWarning)instead.When a
Devicemethod has to run in the device’s context and the caller’s context cannot be restored afterwards, the created resource is destroyed and the raisedCUDAErrornow 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 failedcuCtxSetCurrentcall. 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 asCUDAWarning.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 explicitContextnow 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, returningNone.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
CUDAWarningon Python 3.10), and a failedcuStreamEndCapturemade when a still-buildingGraphBuilderis garbage collected is now reported asCUDAWarning; both were silent.Stream.deviceand related queries on a stream whose context is not current now restore the caller’s context even when the device query fails.