8000 Allow null context in cuCtxSetCurrent by RicheyWorks · Pull Request #52 · jcuda/jcuda · GitHub
[go: up one dir, main page]

Skip to content

Allow null context in cuCtxSetCurrent - #52

Draft
RicheyWorks wants to merge 1 commit into
jcuda:masterfrom
RicheyWorks:fix/null-current-context
Draft

RicheyWorks wants to merge 1 commit into
jcuda:masterfrom
RicheyWorks:fix/null-current-context

Conversation

@RicheyWorks
Copy link
Copy Markdown

Fixes #16 for cuCtxSetCurrent: CUDA permits a null context to unbind the calling CPU thread's current context (or do nothing for an empty context stack), but the JNI wrapper throws NullPointerException before calling CUDA.

Remove that null rejection. The existing shared getNativePointerValue helper already maps a Java null to native zero, so the CUDA driver receives the documented null context. Other APIs' null handling is outside this change.

Add two driver regression tests on fresh CPU threads: passing null with an empty stack, and passing null after creating a temporary context, then verifying no context remains current. The created context is destroyed in finally; no kernels, transfers or device resets are performed and no test changes the caller thread's context.

Validation:

  • Both tests fail against the published 12.6.0 native JAR with NullPointerException: Parameter 'ctx' is null for cuCtxSetCurrent.
  • Built the changed complete JCudaDriver JNI DLL with CMake 3.31.0-rc3 and existing MSVC 19.44, using checksum-verified official CUDA 12.6 headers and import library in the task workspace. The machine's full installed toolkit was 11.6 and its 12.6 directory incomplete; no system-wide installation was performed. Build emitted existing deprecated-CUDA-API warnings.
  • Both tests pass under Maven/JUnit 4.13.1 with -Xcheck:jni. JVM library-load logging confirms it loaded the freshly built JCudaDriver-12.6.0-windows-x86_64.dll via java.library.path, rather than silently using the published JAR's DLL.
  • Test platform: Windows x86_64, RTX 4090, NVIDIA driver 617.42, Temurin JDK 22. As in Preserve direct buffer marks in Pointer.toBuffer #49–Support CharBuffer in Pointer.toBuffer #51, Java compilation used a separate task-local parent configured for Java 8 source/target; no POM change included.
  • These are scoped driver-context tests, not a full CUDA suite, native transfer test or performance benchmark. Other GPU workloads were not paused or reset.

CUDA 12.6 contract: https://docs.nvidia.com/cuda/archive/12.6.0/cuda-driver-api/group__CUDA__CTX.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow "null" to be passed to cuCtxSetCurrent

1 participant

0