8000 Fix virtual-memory allocation handle and property marshalling by RicheyWorks · Pull Request #58 · jcuda/jcuda · GitHub
[go: up one dir, main page]

Skip to content

Fix virtual-memory allocation handle and property marshalling - #58

Draft
RicheyWorks wants to merge 1 commit into
jcuda:masterfrom
RicheyWorks:fix/allocation-property-marshalling
Draft

RicheyWorks wants to merge 1 commit into
jcuda:masterfrom
RicheyWorks:fix/allocation-property-marshalling

Conversation

@RicheyWorks
Copy link
Copy Markdown

Fix the driver virtual-memory allocation/property workflow under JNI checking. Three related marshalling mistakes currently prevent this path from working correctly:

  • getCUmemAllocationProp reads the three nested allocFlags fields from the outer property object, causing a wrong-field-ID fatal error under -Xcheck:jni. Read them from the already obtained nested flag object and zero-initialize the native structure, including reserved bytes.
  • cuMemCreate returns its handle with setPointer, which also accesses Pointer.byteOffset. CUmemGenericAllocationHandle extends NativePointerObject, not Pointer; use the existing native-handle setter.
  • setCUmemAllocationProp creates a location object but never copies its native type/id. Populate it with the existing location helper.

These are one allocation-workflow contribution, not separate counted fixes. No Java/JNI signatures change. This is independent of the access-policy-window changes in #48 and the other pending JNI fixes; no overlap was found in issue/PR searches for allocation properties.

Add three real driver regression cases, each in a fresh child JVM with -Xcheck:jni, a 30-second timeout and captured diagnostics so a broken JNI build cannot terminate the JUnit runner. Exercise minimum/recommended granularity and allocation→property-query→release. Skip on a device explicitly reporting VMM unsupported. The allocation case verifies the location, allocation type, handle types and all three flag values; it never reserves/maps an address or launches a kernel, and caps allocation size at 16 MiB. Context and handle are released in finally on the working path.

Verification on Windows x86_64, RTX 4090/driver 617.42, Temurin JDK 22/JUnit 4.13.1:

  • Published 12.6.0 DLL: all three cases fail in isolated child JVMs with FATAL ERROR in native method: Wrong field ID passed to JNI during granularity queries, before allocating memory.
  • Intermediate property-input fix: both granularity cases pass; round-trip exposes the separate wrong-field-ID handle write in cuMemCreate.
  • Complete patch, rebuilt against pristine jcuda-common commit 9d41fb5: all three pass, zero failures/errors/skips. A direct logged run confirms the rebuilt DLL and successful 2 MiB allocation/property query/release. No JNI warnings.
  • Existing MSVC/CMake and checksum-verified official CUDA 12.6 workspace headers/import library; Java compilation uses proposed parent Target Java 8 in the parent compiler configuration jcuda-parent#2 installed normally. No software installation, device reset or other-workload pause.
  • No full CUDA suite, memory mapping/access tests, export/import, nonzero optional allocation flags, other OS or GPU model validated. Optional flags remain hardware/API dependent; the regression uses their zero defaults. This does not fix unrelated VMM wrappers.

CUDA contract: virtual memory management.

mvn -f JCudaJava/pom.xml -Dtest=JCudaDriverAllocationPropertyTest "-DargLine=-Djava.library.path=<rebuilt-driver-directory>" test

The test itself enables JNI checking in each child process and propagates java.library.path.

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.

1 participant

0