Commit 54e897b8 authored by Andrey Filippov's avatar Andrey Filippov

CLAUDE: Stage 2 — JNA convert_direct binding + Stage2 validation driver

TpJna: add tp_convert_direct_selftest binding. Stage2: invoke it against the
tile_processor_gpu/clt golden, report num_active_tiles + max|CLT-golden|.
PASS on 5060 Ti: 5120 active tiles, relative error ~8.85e-6 vs golden (first
real kernel execution + CDP via the native shim, no JCuda).
Co-Authored-By: 's avatarClaude Opus 4.8 (1M context) <noreply@anthropic.com>
parent 7d19da1f
package com.elphel.imagej.gpu.jna;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
/**
* Stage-2 validation: the convert_direct milestone. Drive the full direct-CLT path natively
* (NVRTC module + driver-API launches, no JCuda) through the JNA boundary, and compare the
* computed CLT to the tile_processor_gpu golden (clt/aux_chnN.clt). This is the first real
* kernel-execution test and the first CDP (calculate_tiles_offsets) run on Blackwell via the shim.
*
* Run:
* java -Djna.library.path=&lt;dir with libtileproc.so&gt; -cp target/classes:&lt;jna.jar&gt; \
* com.elphel.imagej.gpu.jna.Stage2 [data_root] [lwir]
* data_root must contain clt/ (default /home/elphel/git/tile_processor_gpu); lwir default 1.
* By Claude on 2026-06-25.
*/
public class Stage2 {
public static void main(String[] args) {
String root = (args.length > 0) ? args[0] : "/home/elphel/git/tile_processor_gpu";
int lwir = (args.length > 1) ? Integer.parseInt(args[1]) : 1;
String srcdir = "/home/elphel/git/tile_processor_gpu/src";
String devrt = "/usr/local/cuda/targets/x86_64-linux/lib/libcudadevrt.a";
System.out.printf("Stage2 (convert_direct via JNA): root=%s lwir=%d%n", root, lwir);
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:\n" + lib.tp_last_error()); System.exit(1); }
double[] maxErr = new double[1];
int[] nActive = new int[1];
int rc = lib.tp_convert_direct_selftest(m, lwir, root, maxErr, nActive);
if (rc != 0) { System.out.printf("FAIL: selftest rc=%d: %s%n", rc, lib.tp_last_error()); System.exit(2); }
// CDP can reorder FP accumulation, and NVRTC vs the harness's offline nvcc may differ slightly,
// so this is a closeness check, not bitwise. Report the number; judge from it.
boolean ok = (maxErr[0] >= 0) && !Double.isNaN(maxErr[0]) && (maxErr[0] < 1.0) && (nActive[0] > 0);
System.out.printf(" convert_direct: num_active_tiles=%d max|CLT-golden|=%.6g %s%n",
nActive[0], maxErr[0], ok ? "PASS" : "REVIEW");
lib.tp_destroy_module(m);
System.out.println(ok ? "RESULT: PASS (convert_direct matches golden via JNA)" : "RESULT: REVIEW (see maxErr)");
System.exit(ok ? 0 : 3);
}
}
...@@ -36,4 +36,12 @@ public interface TpJna extends Library { ...@@ -36,4 +36,12 @@ public interface TpJna extends Library {
int tp_get_rot_deriv(Pointer instance, float[] out); int tp_get_rot_deriv(Pointer instance, float[] out);
/** Free the instance device buffers. */ /** Free the instance device buffers. */
void tp_destroy_instance(Pointer instance); void tp_destroy_instance(Pointer instance);
// ---- Stage 2: convert_direct selftest ----
/** Run the full convert_direct path (mirrors TpHostGpu allTests convert chain) against the
* tile_processor_gpu/clt golden data under data_root. lwir!=0 -> 16-cam LWIR set.
* Writes max |CLT-golden| into outMaxErr[0] and the kernel-computed active-tile count into
* outNumActive[0]. Returns 0 on success. */
int tp_convert_direct_selftest(Pointer module, int lwir, String data_root,
double[] outMaxErr, int[] outNumActive);
} }
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