Skip to content

Commit 5c6d054

Browse files
rparolinclaude
andcommitted
fix(cuda.core): restore CUDA_ERROR_NOT_INITIALIZED auto-init in _query_memory_attrs (R4)
Per Leo's review on PR #1775 (_buffer.pyx:455), restore the auto-init retry that was removed in 10de998. cuPointerGetAttributes is the first driver call _query_memory_attrs makes, and a NOT_INITIALIZED result here would otherwise propagate out of every is_managed / is_host_accessible / is_device_accessible query before the user has called any other Device API. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 2151e61 commit 5c6d054

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

cuda_core/cuda/core/_memory/_buffer.pyx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ else:
3636

3737
from cuda.core._dlpack import classify_dl_device, make_py_capsule
3838
from cuda.core._utils.cuda_utils import driver
39+
from cuda.core._device import Device
3940

4041

4142
# =============================================================================
@@ -452,6 +453,11 @@ cdef inline int _query_memory_attrs(
452453

453454
cdef cydriver.CUresult ret
454455
ret = cydriver.cuPointerGetAttributes(3, attrs, <void**>vals, ptr)
456+
if ret == cydriver.CUresult.CUDA_ERROR_NOT_INITIALIZED:
457+
with cython.gil:
458+
# Device class handles the cuInit call internally
459+
Device()
460+
ret = cydriver.cuPointerGetAttributes(3, attrs, <void**>vals, ptr)
455461
HANDLE_RETURN(ret)
456462

457463
# TODO: HMM/ATS-enabled sysmem should also report is_managed=True; the

0 commit comments

Comments
 (0)