Skip to content

feat(autoresearch): add perfProbe sanity probes (refs #3113 Task 2) - #3118

Merged
zackees merged 1 commit into
masterfrom
feat/3113-task2-sanity-probes
Jun 16, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/3113-task2-sanity-probes

Conversation

@zackees

@zackees zackees commented Jun 16, 2026 •

Copy link
Copy Markdown
Member

Task 2 of meta #3113. Three RPC handlers that calibrate the autoresearch timing infrastructure before wave2dPerf (#3116, Task 1) data is trusted for cross-platform comparison.

RPCs added

Method Args Returns Fail mode
perfProbeMemcpy { bytes, iterations } mb_per_s Below per-platform vendor SRAM floor → timer broken
perfProbeNop { iterations } us_per_iter Outside [1.0, 2.5] cycles/nop → timer broken or IRQ jitter
perfProbeRepeat { W, H, iterations, repeats, stencil } mean_us_per_update, std_dev_us_per_update, std_dev_pct std_dev_pct > 5 → IRQ noise or RPC framing jitter contaminating wave2dPerf

Fail-loud contract

All three follow the meta's fail-loud contract: probe failures must cause the host-side reporter to stamp the wave2dPerf result UNTRUSTED and refuse to feed it into cross-platform comparison tables. Silent corruption of perf data is worse than no data.

Implementation notes

  • Newton-Raphson sqrt in perfProbeRepeat (6 iterations, ~14 significant digits) avoids pulling in <cmath> on platforms where it's costly.
  • All probes guard inputs (bytes/iterations/W/H bounded) — bad RPC payload returns success=false + error="out_of_range" rather than crashing.
  • Nop probe uses __GNUC__/__clang__ asm nop with a volatile counter fallback for non-GCC compilers.

Validation

  • bash lint --cpp — clean.
  • bash compile wasm --examples AutoResearch — build clean.

What's NOT in this PR

  • Host-side Python orchestrator that chains the probes before wave2dPerf and gates the UNTRUSTED stamp — separate slice.
  • The host bash autoresearch <board> --wave2d-perf <W>x<H> flag — separate slice.

Refs #3113 Task 2.

Summary by CodeRabbit

  • New Features
    • Added three performance instrumentation validation endpoints (perfProbeMemcpy, perfProbeNop, perfProbeRepeat) to verify timing stability and provide diagnostic statistics before conducting performance measurements.

Three RPC handlers in AutoResearchRemote.cpp that calibrate the
autoresearch timing infrastructure BEFORE wave2dPerf (#3116, Task 1)
data is trusted for cross-platform comparison:

  perfProbeMemcpy { bytes, iterations }
    - Measures SRAM throughput via repeated memcpy.
    - Returns mb_per_s.
    - Host compares vs per-platform vendor floor (e.g. ESP32-S3
      ~175 MB/s); below floor → timer instrumentation broken.

  perfProbeNop { iterations }
    - Volatile-fenced nop loop calibration.
    - Returns total_us + us_per_iter.
    - Host computes (total_us * cpu_mhz / iterations) and checks
      [1.0, 2.5] cycles-per-nop. Out-of-band → timer broken or
      IRQ jitter / branch-predictor stall confounding measurement.

  perfProbeRepeat { W, H, iterations, repeats, stencil }
    - Runs wave2dPerf's measurement N times back-to-back, reports
      mean + std_dev_pct of us_per_update.
    - Host checks std_dev_pct < 5%; higher → IRQ noise or RPC
      framing jitter is contaminating wave2dPerf, mark UNTRUSTED.

All three follow the fail-loud contract: probe failures must stamp
result UNTRUSTED at the host reporter. Silent corruption of perf
data is worse than no data.

Probe details:

- Newton-Raphson sqrt in perfProbeRepeat (6 iterations, ~14
  significant digits) avoids pulling in <cmath> on platforms where
  it's costly.
- All probes guard their inputs (bytes/iterations/W/H bounded) — a
  bad RPC payload returns success=false + error=out_of_range rather
  than crashing the device.
- nop probe uses __GNUC__/__clang__ asm nop with a volatile counter
  fallback for non-GCC compilers.

Verified by bash compile wasm --examples AutoResearch (build clean).

Refs #3113 Task 2.
@coderabbitai

coderabbitai Bot commented Jun 16, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 61fc478a-d46c-4c1e-b2f9-43c8e7da0efa

📥 Commits

Reviewing files that changed from the base of the PR and between 7e17f58 and ce33721.

📒 Files selected for processing (1)
  • examples/AutoResearch/AutoResearchRemote.cpp

📝 Walkthrough

Walkthrough

Replaces the wave2dPerf RPC endpoint with three new performance sanity probe RPCs in registerFunctions(): perfProbeMemcpy (memcpy throughput via static SRAM buffers), perfProbeNop (NOP loop timing with platform-specific asm), and perfProbeRepeat (WaveSimulation2D_Real update stability with mean/std-dev statistics).

Changes

Performance Sanity Probe RPC Endpoints

Layer / File(s) Summary
perfProbeMemcpy and perfProbeNop endpoints
examples/AutoResearch/AutoResearchRemote.cpp
perfProbeMemcpy parses bytes/iterations, validates bounds, fills static SRAM source/dest buffers, runs timed memcpy, and returns total_us and mb_per_s. perfProbeNop parses optional iterations, validates range, runs a volatile NOP loop (nop asm on GCC/Clang; volatile counter otherwise), and returns total_us and us_per_iter.
perfProbeRepeat endpoint
examples/AutoResearch/AutoResearchRemote.cpp
Parses W, H, iterations, repeats, and stencil; validates all ranges; constructs and seeds a WaveSimulation2D_Real; performs one warm-up; then runs repeated timed update batches computing mean and standard deviation (including std-dev %) of microseconds per update, returned in JSON with the stencil name.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Poem

🐇 Three little probes went hopping along,
Memcpy, Nop, and Repeat — quite a strong throng!
They measure in micros, they tally the mean,
With std-dev in percent — the cleanest I've seen.
wave2dPerf has retired to its burrow to sleep,
While sanity calibrations run — steady and deep! 🕐

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/3113-task2-sanity-probes

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@zackees
zackees merged commit 4f620ff into master Jun 16, 2026
5 of 6 checks passed
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Jun 16, 2026
@zackees
zackees deleted the feat/3113-task2-sanity-probes branch June 16, 2026 01:28
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 16, 2026
zackees added a commit that referenced this pull request Jun 16, 2026
…ch becomes external binder (#3120)

Per user direction: wave-PDE benchmarking belongs to the wave simulator,
not to the AutoResearch RPC layer. AutoResearchRemote.cpp was embedding
the wave PDE setup (checkerboard seed, halfDuplex off, stencil selection,
warm-up, timing, statistics) inline in two RPC lambdas (wave2dPerf,
perfProbeRepeat). The simulator side did not own its own bench API; the
RPC layer had to know wave-PDE-specific details that don't belong in
transport plumbing.

This PR cleanly separates concerns:

  src/fl/math/wave/wave_perf_bench.h (new):
    namespace fl::wave_perf:
      struct WavePerfResult, WavePerfRepeatResult
      runWavePerf(W, H, iterations, stencil) -> WavePerfResult
      runWavePerfLoadsOnly(W, H, iterations, stencil) -> WavePerfResult
      runWavePerfRepeat(W, H, iterations, repeats, stencil) -> WavePerfRepeatResult

  examples/AutoResearch/AutoResearchRemote.cpp:
    wave2dPerf and perfProbeRepeat RPC handlers become thin JSON-RPC
    binders: parse args, dispatch to fl::wave_perf::*, format response.
    No wave PDE knowledge in the RPC layer.

The header-only design keeps the bench helpers compile-time-cheap and
co-located with the simulator they measure. They can be reused by any
future RPC layer (BLE, HTTP, etc.) or driven directly from a unit test
without standing up the AutoResearch sketch.

Things deliberately unchanged:
- perfProbeMemcpy and perfProbeNop stay in AutoResearchRemote.cpp.
  They're not wave-PDE-specific; they're general SRAM/cycle-counter
  calibration helpers. If the codebase ever grows a generic
  src/fl/perf/sanity_probes.h they can move there.
- All JSON wire formats are byte-identical to #3116 (wave2dPerf) and
  #3118 (perfProbeRepeat). Existing host-side callers don't notice.

Validation:
- bash test fl_math_wave_wave_simulation_real --cpp — 8/8 pass.
- bash lint --cpp — clean.
- bash compile wasm --examples AutoResearch — build clean.

Refs #3113 Task 1 + Task 2.
zackees added a commit that referenced this pull request Jun 16, 2026
…1 / #3113 Task 1) (#3134)

A1 of meta #3122. Wires the device-side wave2dPerf (#3116) + perfProbe*
(#3118) RPCs (refactored behind fl::wave_perf::* in #3120) into a
single host-driven measurement pass.

  bash autoresearch esp32s3 --wave2d-perf 64x64

Sequence per platform run:
  1. perfProbeMemcpy — SRAM throughput, MB/s.
  2. perfProbeNop    — cycle calibration, us/iter.
  3. perfProbeRepeat — wave2dPerf reproducibility, std_dev_pct.
                       >= 5% stamps results UNTRUSTED.
  4. wave2dPerf x 4 — { FivePoint, NinePointIsotropic } x
                       { compute, loads_only }.
                      The loads_only/compute gap isolates memory
                      cost from compute cost (critical for ESP32-S3
                      per #3114 / #3117 PSRAM analysis).

Output: per-RPC live progress + final JSON dump with structured
results { grid, probes, bench, untrusted, untrusted_reasons }.

Naming note: per #3124, future perf-related flags use the
--perf-XX prefix convention. This flag uses the original
--wave2d-perf name per explicit user direction in this session
("don't fix this now, just file an issue") — #3124 tracks the
prefix-rename pass for a future PR.

Args dataclass + RunContext extended with the new field; existing
test fixture updated to construct both with the new defaults. All
48 ci/tests/test_autoresearch_phases.py tests pass.

Refs #3122 A1, #3113 Task 1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant