Commit a5519ce4 authored by Andrey Filippov's avatar Andrey Filippov

CLAUDE: Stage 0b - JNA boundary to libtileproc (com.elphel.imagej.gpu.jna)

Add JNA 5.14.0 dependency + com.elphel.imagej.gpu.jna (TpJna interface, Stage0 driver):
load libtileproc.so, NVRTC-compile+CDP-link+load the kernels, 19/19 functions on the 5060 Ti
from Java via JNA (no JCuda). First step of the GPU-layer migration; existing JCuda path untouched.
Co-Authored-By: 's avatarClaude Opus 4.8 (1M context) <noreply@anthropic.com>
parent 3dfe70ad
...@@ -40,6 +40,12 @@ ...@@ -40,6 +40,12 @@
</dependencyManagement> </dependencyManagement>
<dependencies> <dependencies>
<!-- JNA: call the native CUDA tile-processor shim (libtileproc.so) for the JCuda->JNA GPU-layer migration. By Claude on 2026-06-25 -->
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>5.14.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson --> <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency> <dependency>
<groupId>com.google.code.gson</groupId> <groupId>com.google.code.gson</groupId>
......
package com.elphel.imagej.gpu.jna;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
/**
* Stage-0b proof: from Java, load libtileproc.so via JNA, call tp_create_module, assert 19 kernels.
* Same result as the C++ probe but across the JNA boundary on the RTX 5060 Ti. By Claude on 2026-06-25.
* java -Djna.library.path=<dir with libtileproc.so> -cp target/classes:<jna.jar> \
* com.elphel.imagej.gpu.jna.Stage0 [kernel_src_dir] [libcudadevrt.a]
*/
public class Stage0 {
public static void main(String[] args) {
String srcdir = (args.length > 0) ? args[0] : "/home/elphel/git/tile_processor_gpu/src";
String devrt = (args.length > 1) ? args[1] : "/usr/local/cuda/targets/x86_64-linux/lib/libcudadevrt.a";
System.out.println("Stage0 (JNA): loading libtileproc, srcdir=" + srcdir);
TpJna lib = Native.load("tileproc", TpJna.class);
Pointer m = lib.tp_create_module(srcdir, devrt);
if (m == null) {
System.out.println("FAIL: tp_create_module returned null:\n" + lib.tp_last_error());
System.exit(1);
}
int n = lib.tp_module_num_functions(m);
String err = lib.tp_last_error();
System.out.println("Stage0 (JNA): module created, functions loaded = " + n + (err != null && !err.isEmpty() ? (" [warn: " + err + "]") : ""));
lib.tp_destroy_module(m);
System.out.println(n == 19 ? "RESULT: PASS (19/19 via JNA)" : ("RESULT: FAIL (" + n + "/19)"));
System.exit(n == 19 ? 0 : 2);
}
}
package com.elphel.imagej.gpu.jna;
import com.sun.jna.Library;
import com.sun.jna.Pointer;
/**
* JNA boundary to the native tile-processor library (libtileproc.so) for the JCuda->JNA migration.
* Stage-0b surface only: prove module compile/load across JNA. The full set (instances, set/exec/get)
* follows the design doc handoffs/2026-06-25_JCuda-to-JNA-migration-design.md. By Claude on 2026-06-25.
*/
public interface TpJna extends Library {
/** NVRTC-compile the kernels in srcdir (+ getTpDefines), cuLink(libcudadevrt), load the module.
* Returns an opaque module handle, or null on failure (see tp_last_error()). */
Pointer tp_create_module(String srcdir, String libcudadevrt);
/** Number of kernel functions resolved in the module (19 expected), or -1 if handle is null. */
int tp_module_num_functions(Pointer module);
/** Last error message (NVRTC/CUDA log), empty if none. */
String tp_last_error();
/** Free the module (cuModuleUnload + cuCtxDestroy). */
void tp_destroy_module(Pointer module);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment