Repository navigation
[BUG]: compute-sanitzer finds CUDA_ERROR_INVALID_CONTEXT with default Device constructor #562
Copy link
Copy link
Closed
Labels
P0High priority - Must do!High priority - Must do!bugSomething isn't workingSomething isn't workingcuda.coreEverything related to the cuda.core moduleEverything related to the cuda.core module
Description
Is this a duplicate?
- I confirmed there appear to be no duplicate issues for this bug and that I agree to the Code of Conduct
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 |
+-----------------------------------------------------------------------------------------+
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P0High priority - Must do!High priority - Must do!bugSomething isn't workingSomething isn't workingcuda.coreEverything related to the cuda.core moduleEverything related to the cuda.core module
Activity
carterbox commentedon Apr 22, 2025
I think this bug may have been fixed on
mainalready in thecuda.bindingspackage. I tried to explore a fix, but when I compiledcuda-bindingsfrom main locally, my reproducer didn't reproduce. When I reverted thecuda-bindingspackage to thev12.8.0tag, I was able to reproduce.leofang commentedon Apr 22, 2025
I actually don't understand what happens and need to look into it.
cuda.corecode hasn't changed much since you worked on it last time... Are you suggesting the bug is incuda.bindingsnotcuda.core?carterbox commentedon Apr 22, 2025
Yes. I definitely should have included the log output from this error. Here:
carterbox commentedon Apr 25, 2025
We need to figure out what changes were made to the main branch that fixed this error and backport them to the
11.8.xbranch.carterbox commentedon Apr 25, 2025
In offline discussion with @leofang, we decided that it's too much effort to backport the fixes to CTK11 because the appropriate backport is probably #517.
leofang commentedon Apr 26, 2025
This is the minimal reproducer based on the traceback that Daniel provided above:
$ compute-sanitizer python -c "import cuda.bindings.runtime as runtime; runtime.cudaGetDevice()"This happens because in the public releases
cuda.bindings.runtimeis implemented on top of the driver bindings, whereas after #517 it's no longer the case. We are seeing a bug in the cudart re-implementation (cc @vzhurba01 for vis). I suggested to document this as a bug fix in 12.9.0 and a known issue / won't fix in 11.8.7.ZzEeKkAa commentedon Jun 26, 2025
I'm hitting exact the same error with 0.3.0 version:
leofang commentedon Jun 26, 2025
As discussed offline, we need to run the sanitizer with the option
--report-api-errors=no(see #687). It is not possible to fix it on our side without the compute sanitizer offering us a more fine-grained, localized control.leofang commentedon Jun 26, 2025
A documentation PR to mention this would be welcomed @ZzEeKkAa 😉