From 6a7cf126e79f85195d95d0d22d76494d96a24e26 Mon Sep 17 00:00:00 2001 From: Ralf Juengling Date: Thu, 30 Jul 2026 15:34:16 -0700 Subject: [PATCH] fix(cuda.core): surface real CUDA error in Device.set_current() --- cuda_core/cuda/core/_device.pyx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cuda_core/cuda/core/_device.pyx b/cuda_core/cuda/core/_device.pyx index 9c35fc9355b..29740cb466a 100644 --- a/cuda_core/cuda/core/_device.pyx +++ b/cuda_core/cuda/core/_device.pyx @@ -1289,7 +1289,10 @@ class Device: # use primary ctx h_context = get_primary_context(self._device_id) if h_context.get() == NULL: - raise ValueError("Cannot set NULL context as current") + HANDLE_RETURN(get_last_error()) + raise RuntimeError( + f"Failed to retain the primary context for device {self._device_id}" + ) with nogil: HANDLE_RETURN(cydriver.cuCtxSetCurrent(as_cu(h_context))) self._has_inited = True