Commit f7939cc0 authored by Andrey Filippov's avatar Andrey Filippov

CODEX: Compare resident pose candidate RMS

Co-authored-by: 's avatarCodex <codex@elphel.com>
parent 9bdef093
......@@ -1042,9 +1042,8 @@ public class CuasPoseRT {
numTiles, capturePrepared);
if ((result != null) && !pose_lma_step_path_reported) {
pose_lma_step_path_reported = true;
System.out.println("CuasPoseRT: resident CUDA float LMA candidate active "+
"(raw fx/J reused; Java-double candidate is debug/fallback only; "+
"Java RMS/acceptance retained)");
System.out.println("CuasPoseRT: resident CUDA float LMA candidate/RMS oracle active "+
"(separate candidate fx/J buffers; Java acceptance authoritative)");
}
return result;
}); // production candidate: resident raw fx/J -> parallel prepare/reduce -> fixed 3x3 tail // By Codex on 07/15/2026
......
......@@ -592,7 +592,11 @@ public class GpuQuadJna extends GpuQuad {
packed[IntersceneLmaFloat.LMA_RESULT_FLOATS],
packed[IntersceneLmaFloat.LMA_RESULT_FLOATS + 1]) : null;
return new IntersceneLmaFloat.ResidentLmaStepResult(
unpackPoseLmaStep(packed), prepared);
unpackPoseLmaStep(packed), prepared,
packed[IntersceneLmaFloat.LMA_RESULT_FLOATS],
packed[IntersceneLmaFloat.LMA_RESULT_FLOATS + 1],
packed[IntersceneLmaFloat.LMA_RESULT_FLOATS + 2],
packed[IntersceneLmaFloat.LMA_RESULT_FLOATS + 3]);
}
private static IntersceneLmaFloat.LmaStepResult unpackPoseLmaStep(final float[] packed) {
......
......@@ -10,7 +10,7 @@ import com.sun.jna.Pointer;
* com.elphel.imagej.gpu.jna.Stage0 [kernel_src_dir] [libcudadevrt.a]
*/
public class Stage0 {
private static final int EXPECTED_KERNELS = 32; // 19 base + 2 conditioning + 4 consolidate + 2 peak + pose fx/J + 3 pose LMA + products
private static final int EXPECTED_KERNELS = 33; // 19 base + 2 conditioning + 4 consolidate + 2 peak + pose fx/J + 4 pose LMA + products
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";
......
......@@ -12,8 +12,8 @@ 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 (32 expected:
* 19 base + 2 conditioning + 4 consolidation + 2 peak + pose-fx/J + 3 pose-LMA + LMA-products),
/** Number of kernel functions resolved in the module (33 expected:
* 19 base + 2 conditioning + 4 consolidation + 2 peak + pose-fx/J + 4 pose-LMA + LMA-products),
* or -1 if handle is null. */
int tp_module_num_functions(Pointer module);
/** Last error message (NVRTC/CUDA log), empty if none. */
......@@ -155,7 +155,7 @@ public interface TpJna extends Library {
float[] ymfxWeighted, float[] vector,
int numValues, float[] result);
/** Continue from raw fx/J left by the most recent pose kernel. Result has
* the 19 candidate floats followed by current full/pure RMS. Prepared
* the 19 candidate floats followed by current and candidate full/pure RMS. Prepared
* arrays are nullable unless capturePrepared is nonzero. */
int tp_proc_exec_pose_lma_resident_step(Pointer proc,
float lambda, float[] weights, float[] y,
......
......@@ -126,6 +126,7 @@ public class IntersceneLma {
}
private PoseLmaResidentStepProvider poseLmaResidentStepProvider = null;
private static boolean poseLmaStepOracleReported = false;
private static boolean poseLmaAcceptanceOracleReported = false;
private IntersceneLmaFloat.Camera poseFloatReference = null;
private IntersceneLmaFloat.Camera poseFloatScene = null;
private float [] poseFloatCenters = null;
......@@ -1046,6 +1047,11 @@ public class IntersceneLma {
if (last_ymfx == null) {
return null; // need to re-init/restart LMA
}
if (residentCandidateValid && (residentResult != null) && (debug_level >= 1) &&
!poseLmaAcceptanceOracleReported) {
reportPoseRmsDecision(residentResult, this.last_rms, rms, rms_diff);
poseLmaAcceptanceOracleReported = true;
}
this.good_or_bad_rms = rms.clone();
if (rms[0] < this.last_rms[0]) { // improved
......@@ -1928,6 +1934,32 @@ public class IntersceneLma {
label, poseStep.valid, maxProducts, maxDelta, maxCandidate));
}
private static void reportPoseRmsDecision(
final IntersceneLmaFloat.ResidentLmaStepResult resident,
final double [] javaCurrent,
final double [] javaCandidate,
final double rmsDiff) {
final boolean finite = Float.isFinite(resident.currentRms) &&
Float.isFinite(resident.currentPureRms) &&
Float.isFinite(resident.candidateRms) &&
Float.isFinite(resident.candidatePureRms);
final boolean floatImproved = finite && (resident.candidateRms < resident.currentRms);
final boolean doubleImproved = javaCandidate[0] < javaCurrent[0];
final boolean floatStop = floatImproved &&
(resident.candidateRms >= resident.currentRms * (1.0f - (float) rmsDiff));
final boolean doubleStop = doubleImproved &&
(javaCandidate[0] >= javaCurrent[0] * (1.0 - rmsDiff));
System.out.println(String.format(
"IntersceneLma resident CUDA-float vs Java-double RMS/decision: finite=%s, |current RMS|=%g, |current pure RMS|=%g, |candidate RMS|=%g, |candidate pure RMS|=%g, improved-match=%s, stop-match=%s",
finite,
Math.abs(resident.currentRms - javaCurrent[0]),
Math.abs(resident.currentPureRms - javaCurrent[1]),
Math.abs(resident.candidateRms - javaCandidate[0]),
Math.abs(resident.candidatePureRms - javaCandidate[1]),
floatImproved == doubleImproved,
floatStop == doubleStop));
}
private static final class DoubleLmaStepResult {
final double [] products;
final double [] delta;
......
......@@ -42,7 +42,7 @@ public final class IntersceneLmaFloat {
public static final int NUM_COMPONENTS = 2;
public static final int LMA_PRODUCTS = NUM_PARAMS * NUM_PARAMS + NUM_PARAMS;
public static final int LMA_RESULT_FLOATS = 1 + LMA_PRODUCTS + 2 * NUM_PARAMS;
public static final int LMA_RESIDENT_RESULT_FLOATS = LMA_RESULT_FLOATS + 2;
public static final int LMA_RESIDENT_RESULT_FLOATS = LMA_RESULT_FLOATS + 4;
public static final float INFINITY_DISPARITY = 0.01f;
static final int ERS_XYZ = 0;
......@@ -216,10 +216,24 @@ public final class IntersceneLmaFloat {
public static final class ResidentLmaStepResult {
public final LmaStepResult step;
public final PreparedLma prepared;
public final float currentRms;
public final float currentPureRms;
public final float candidateRms;
public final float candidatePureRms;
public ResidentLmaStepResult(final LmaStepResult step, final PreparedLma prepared) {
public ResidentLmaStepResult(
final LmaStepResult step,
final PreparedLma prepared,
final float currentRms,
final float currentPureRms,
final float candidateRms,
final float candidatePureRms) {
this.step = step;
this.prepared = prepared;
this.currentRms = currentRms;
this.currentPureRms = currentPureRms;
this.candidateRms = candidateRms;
this.candidatePureRms = candidatePureRms;
}
}
......
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