Commit d8ac8a6b authored by Andrey Filippov's avatar Andrey Filippov

CLAUDE: JNA export tp_proc_exec_consolidate - on-device TD consolidation chain

Wire the frozen v1 chain (index_consolidate -> consolidate_oob ->
clt_average_sensors_list) into the production JNA surface (roadmap 2c ->
step 4 JNA hookup, Andrey's ruling: JNA-only, no JCuda launch code):
- tp_jna.cpp: tp_consolidate.h/.cu added to the NVRTC module (23 kernels);
  new export tp_proc_exec_consolidate = host orchestration of the chain on
  the RESIDENT per-cam CLT (contiguous DtoD gather, no D2H/H2D of TD data;
  only the flattened task streams cross the boundary); average lands in the
  cam-0 slot (what the single conj-multiply correlates); lazy scratch,
  freed in tp_proc_destroy; stats {pairs, surviving tiles, misaligned}.
- tp_consolidate.h/.cu: JCUDA include guards (NVRTC concatenation has no
  include paths) + NAN/INFINITY fallbacks (NVRTC has no math.h macros).
- jna/test_proc_consolidate.cu: standalone validation of the export vs the
  real-scene avg_td_oob oracle case - PASS bit-exact (max|diff|=0,
  5120 pairs -> 5056 tiles == oracle, 0 misaligned).
Regressions: tests_bin/test_avg_td, test_avg_td_oob PASS at tol 0 after
the guard changes; module smoke = 23/23 kernels resolved.
Co-authored-by: 's avatarClaude Fable 5 <noreply@anthropic.com>
parent d7c2f189
// test_proc_consolidate.cu - validate the JNA production export
// tp_proc_exec_consolidate (the granular TpProc surface, libtileproc.so)
// against a real-scene oracle case exported by AvgTdExport.exportOob (the
// same case tests_bin/test_avg_td_oob passes at tol 0). Proves the
// production-facing path end-to-end: set_clt per cam -> exec_consolidate
// (contiguous DtoD gather + 3-kernel chain + avg->cam0) -> get_clt(0) ==
// expected_td_avg bit-exactly; stats == oracle (5120 pairs -> 5056 tiles).
// First PASS 07/12/2026 on the v013 case (max|diff|=0, 0 misaligned).
//
// Build (after jna/build_lib.sh):
// cd tile_processor_gpu && /usr/local/cuda-12.8/bin/nvcc -std=c++17 -O2 \
// -I src -I $HOME/git/cuda-samples/Common \
// jna/test_proc_consolidate.cu src/tests/tp_test_data.cu \
// -o tests_bin/test_proc_consolidate -L jna -ltileproc \
// -Xlinker -rpath -Xlinker $PWD/jna
// Run: tests_bin/test_proc_consolidate [case_dir]
//
// Created on: Jul 12, 2026
// Author: Claude (Anthropic), for Elphel
#include <cstdio>
#include <cstring>
#include <cmath>
#include "tests/tp_test_data.h"
extern "C" {
void* tp_create_module(const char*, const char*);
const char* tp_last_error();
void* tp_proc_create(void*);
int tp_proc_setup(void*, int,int,int,int,int,int);
int tp_proc_set_clt(void*, int, const float*, int);
int tp_proc_get_clt(void*, int, int, float*);
int tp_proc_exec_consolidate(void*, const float*, const float*, int, int, float, float, int*);
void tp_proc_destroy(void*);
void tp_destroy_module(void*);
}
int main(int argc, char** argv){
const char* dir = (argc>1)? argv[1] :
"/home/elphel/lwir16-proc/LV/models/models_1773135103-1773135664/1773135476_186641-CENTER/v013/testdata/avg_td_oob";
void* m = tp_create_module("/home/elphel/git/tile_processor_gpu/src",
"/usr/local/cuda-12.8/lib64/libcudadevrt.a");
if(!m){ printf("FAIL module: %s\n", tp_last_error()); return 1; }
TpTestData data(dir);
int num_sens = data.paramInt("num_sensors", 16);
int tilesx = data.paramInt("tilesx", 80);
int tilesy = data.paramInt("tilesy", 64);
int colors = data.paramInt("colors", 1);
int task_size = data.paramInt("task_size", 102);
int img_w = data.paramInt("img_width", 640);
int img_h = data.paramInt("img_height", 512);
float soft = (float) data.param("soft_margin", 12.0);
float hard = (float) data.param("hard_margin", 8.0);
int num_entries = (int)(data.elements("ftasks0") / task_size);
size_t slice = (size_t)tilesy*tilesx*colors*256;
printf("case: %d sensors %dx%dx%d frame %dx%d soft/hard %g/%g entries %d\n",
num_sens, tilesy, tilesx, colors, img_w, img_h, soft, hard, num_entries);
void* p = tp_proc_create(m);
if(tp_proc_setup(p, num_sens, colors, img_w, img_h, 0, 0)){ printf("FAIL setup: %s\n", tp_last_error()); return 1; }
float* td_sens = data.hostFloat("td_sens");
for(int c=0;c<num_sens;c++)
if(tp_proc_set_clt(p, c, td_sens + (size_t)c*slice, 0)){ printf("FAIL set_clt %d\n", c); return 1; }
float* ftasks0 = data.hostFloat("ftasks0");
int stats[3] = {-1,-1,-1};
int rc = tp_proc_exec_consolidate(p, ftasks0, nullptr, num_entries, task_size, soft, hard, stats);
if(rc){ printf("FAIL exec_consolidate rc=%d: %s\n", rc, tp_last_error()); return 1; }
printf("exec_consolidate: %d pairs -> %d tiles, %d misaligned\n", stats[0], stats[1], stats[2]);
float* got = new float[slice];
if(tp_proc_get_clt(p, 0, 0, got)){ printf("FAIL get_clt(0)\n"); return 1; }
float* exp = data.hostFloat("expected_td_avg");
double maxd = 0; long nan_mm = 0; long first = -1;
for(size_t i=0;i<slice;i++){
bool gn = std::isnan(got[i]), en = std::isnan(exp[i]);
if(gn||en){ if(gn!=en){ nan_mm++; if(first<0) first=(long)i; } continue; }
double d = std::fabs((double)got[i]-(double)exp[i]);
if(d>maxd){ maxd=d; if(d>0 && first<0) first=(long)i; }
}
int fail = (maxd>0)||(nan_mm>0)||(stats[2]!=0);
printf("compare cam0 vs expected_td_avg: max|diff|=%g NaN-mismatch=%ld first@%ld -> %s\n",
maxd, nan_mm, first, fail?"FAIL":"PASS (bit-exact)");
tp_proc_destroy(p); tp_destroy_module(m);
return fail;
}
This diff is collapsed.
...@@ -13,12 +13,20 @@ ...@@ -13,12 +13,20 @@
* Author: Claude (Anthropic), for Elphel * Author: Claude (Anthropic), for Elphel
*/ */
#ifndef JCUDA // NVRTC concatenation (tp_jna.cpp TP_DEFINES, headers merged in order) has no include paths // By Claude on 07/12/2026
#include <cuda_runtime.h> // __global__/__shared__ also for non-nvcc parsers // By Claude on 07/12/2026 #include <cuda_runtime.h> // __global__/__shared__ also for non-nvcc parsers // By Claude on 07/12/2026
#include <device_launch_parameters.h> // threadIdx/blockIdx: cuda_runtime.h gates this on __CUDACC__ // By Claude on 07/12/2026 #include <device_launch_parameters.h> // threadIdx/blockIdx: cuda_runtime.h gates this on __CUDACC__ // By Claude on 07/12/2026
#include <math.h> // NAN, isnan // By Claude on 07/12/2026 #include <math.h> // NAN, isnan // By Claude on 07/12/2026
#include "tp_defines.h" // NUM_CAMS (for geometry_correction.h) // By Claude on 07/12/2026 #include "tp_defines.h" // NUM_CAMS (for geometry_correction.h) // By Claude on 07/12/2026
#include "geometry_correction.h" // struct tp_task field offsets TP_TASK_*_OFFSET // By Claude on 07/12/2026 #include "geometry_correction.h" // struct tp_task field offsets TP_TASK_*_OFFSET // By Claude on 07/12/2026
#include "tp_consolidate.h" #include "tp_consolidate.h"
#endif // By Claude on 07/12/2026
#ifndef NAN // NVRTC has isnan built in but no math.h NAN/INFINITY macros (device-only use is fine) // By Claude on 07/12/2026
#define NAN __int_as_float(0x7fc00000)
#endif // By Claude on 07/12/2026
#ifndef INFINITY // By Claude on 07/12/2026
#define INFINITY __int_as_float(0x7f800000)
#endif // By Claude on 07/12/2026
#ifdef __CDT_PARSER__ // Eclipse CDT indexer only, nvcc never defines this // By Claude on 07/12/2026 #ifdef __CDT_PARSER__ // Eclipse CDT indexer only, nvcc never defines this // By Claude on 07/12/2026
extern "C" void __syncthreads(); // real decl is __CUDACC__-gated in crt/device_functions.h // By Claude on 07/12/2026 extern "C" void __syncthreads(); // real decl is __CUDACC__-gated in crt/device_functions.h // By Claude on 07/12/2026
#endif #endif
......
...@@ -35,7 +35,9 @@ ...@@ -35,7 +35,9 @@
#ifndef SRC_TP_CONSOLIDATE_H_ #ifndef SRC_TP_CONSOLIDATE_H_
#define SRC_TP_CONSOLIDATE_H_ #define SRC_TP_CONSOLIDATE_H_
#ifndef JCUDA // NVRTC concatenation (tp_jna.cpp TP_DEFINES) has no include paths // By Claude on 07/12/2026
#include <cuda_runtime.h> // __global__ in the prototypes below, also for non-nvcc parsers // By Claude on 07/12/2026 #include <cuda_runtime.h> // __global__ in the prototypes below, also for non-nvcc parsers // By Claude on 07/12/2026
#endif // By Claude on 07/12/2026
// TD tile = 4 quadrants x 8x8 = 256 floats (see dtt8x8 / TileProcessor docs) // TD tile = 4 quadrants x 8x8 = 256 floats (see dtt8x8 / TileProcessor docs)
#define TD_TILE_FLOATS 256 #define TD_TILE_FLOATS 256
......
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