Skip to content

[BUG]: compute-sanitzer finds CUDA_ERROR_INVALID_CONTEXT with default Device constructor #562

Closed
@carterbox

Description

@carterbox

Is this a duplicate?

Type of Bug

Silent Failure

Component

cuda.core v0.2.0 cuda-bindings v12.8.0

Describe the bug

Trying to initialize a Device with the current context when there is no current context causes an CUDA_ERROR_INVALID_CONTEXT.

How to Reproduce

Run the following script with compute-sanitizer:

import cuda.core.experimental as ccx

if __name__ == "__main__":
    d = ccx.Device(None)
    d.set_current()

Expected behavior

Device(None) should choose a default device (perhaps System.devices[0]?) to create a context if there is no existing current context.

Otherwise, if you are writing library code and you want to get the current device context but there is no guarantee that the user has already created one, then how do you get it without raising an error?

The error should be caught and invisible to compute-sanitizer.

Operating System

WSL2

nvidia-smi output

Mon Apr 21 21:09:28 2025
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 565.57.02              Driver Version: 566.03         CUDA Version: 12.7     |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA RTX 1000 Ada Gene...    On  |   00000000:01:00.0 Off |                  N/A |
| N/A   36C    P4              7W /   35W |       0MiB /   6141MiB |      0%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI        PID   Type   Process name                              GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|  No running processes found                                                             |
+-----------------------------------------------------------------------------------------+

Metadata

Metadata

Assignees

No one assigned

    Labels

    P0High priority - Must do!bugSomething isn't workingcuda.coreEverything related to the cuda.core module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions