fix(camera): blur CLI/self-verify calls undefined edge_detect -> NameError on NPU - #2
Conversation
…Error on NPU blur_pipeline.py defines the design function , but _run_and_verify() and main() still referenced (a leftover from the AMD example this was adapted from), which is never defined or imported in the module. The module imports aie.iron at the top, so a host without the NPU toolchain fails at that import first and CI's import-boundary check stays green. But on a real NPU box, `python camera/blur_pipeline.py` reaches main() and crashes with `NameError: name 'edge_detect' is not defined` instead of running the blur design or its self-verify. Rename the two runtime references to `blur` (the function the daemon and test_blur.py already import). Add a pure-AST regression test (no aie/numpy needed, runs anywhere) asserting the design symbol the CLI hands to the NPU is one the module actually defines.
…edge-detect Scottcjn#2 fixed the CLI/self-verify NameError (edge_detect -> blur) but left the golden reference itself wrong: _run_and_verify() still built its expected output with _edge_detect_ref() -- a Laplacian edge-detect + threshold + highlight pipeline that shares no math with the Gaussian blur the design actually computes. On real NPU hardware --verify would go from 'crashes' to 'runs and reports a correct blur as wrong', since a blur output never matches an edge map. Add _blur_ref(), a numpy reference mirroring blur()'s actual pipeline: rgba2gray -> 3x3 Gaussian blur (the unity-gain [[1,2,1],[2,4,2],[1,2,1]]/16 kernel filter_kernel_buff actually holds, per the module's own 'GAIN FIX' docstring, not the Laplacian used for edge-detect) -> gray2rgba, combined via add_weighted with alpha=1 (register 16384 = Q14 unity) and beta=0 (register 0 -- unlike edge_detect's highlighted-edges-over-original composite, the original RGBA is not blended back in). Route _run_and_verify() through it instead of _edge_detect_ref(). Tests (camera/test_blur_pipeline_golden_ref.py, no aie/NPU toolchain needed -- minimal import-time stand-ins only, real design/verify code never executed): - AST guard that _run_and_verify calls _blur_ref, not _edge_detect_ref - impulse-response test pinning the exact kernel weights + normalization - flat-field test covering BORDER_REPLICATE at the corners - checkerboard smoothing test mirroring test_blur.py's real-hardware smoke assertion, entirely in numpy, which also catches a beta!=0 regression (blending the original color back in would fail it) - sanity check that _blur_ref and _edge_detect_ref actually differ Mutation-checked: reverting the _run_and_verify call fails the AST guard; corrupting the kernel weights fails the impulse-response test. Existing camera/*.py CI convention preserved -- blur_pipeline.py still fails only at the aie import boundary, both new/existing camera test files run to completion.
|
Good catch, thank you -- pushed a revision. Added Added |
Problem
camera/blur_pipeline.pydefines its NPU design asblur(def blur(...), and bothcamera/npu_camera_daemon.pyandcamera/test_blur.pydofrom blur_pipeline import blur). But the module's own runtime paths were still callingedge_detect— a leftover name from AMD'sedge_detectIRON example this file was adapted from.edge_detectis never defined or imported anywhere inblur_pipeline.py:_run_and_verify()—edge_detect(in_t, b_t, out_t, **_compile_kwargs(opts))main()—run_design_cli(edge_detect, ...)Why CI stays green but real hardware crashes
blur_pipeline.pyimportsaie.ironat the top, so on a host without the NPU toolchain the module fails at that import first — which is exactly the boundaryci.yml's import loop expects, so CI is green. On a real NPU box the import succeeds,python camera/blur_pipeline.pyreachesmain(), and it dies with:before running the blur design or its self-verify. The module's CLI/self-verify is unusable on the one platform it's meant for.
Fix
Rename the two runtime references from
edge_detecttoblur(the function that actually exists and that the daemon/test already import). Two-line change; no behavior change on the happy path.Regression test
Added
camera/test_blur_pipeline_cli_symbol.py— a pure-AST test (noaie/numpy, runs anywhere) asserting the design symbol the CLI hands to the NPU is one the module actually defines. Mutation-guarded: it fails on the pre-fix code (AssertionError: ... references undefined edge_detect ...) and passes after the fix.python -m compileall -q camerastays clean.Verified bug — claimed under the RustChain verified-bug channel (rustchain-bounties#71).
RTC:
RTCd1554f0f35576faf01d386a6be1c947f560dd0b7