Skip to content

feat(autoresearch): add wave2dPerf RPC handler (refs #3113 Task 1) - #3116

Merged
zackees merged 1 commit into
masterfrom
feat/3113-wave2d-perf-rpc
Jun 16, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/3113-wave2d-perf-rpc

Conversation

@zackees

@zackees zackees commented Jun 16, 2026 •

Copy link
Copy Markdown
Member

First slice of meta #3113 Task 1 — adds a device-side wave2dPerf RPC handler in AutoResearchRemote.cpp that benchmarks WaveSimulation2D_Real::update() on hardware.

API

// RPC call:
{
  "method": "wave2dPerf",
  "params": [{
    "W": 64,
    "H": 64,
    "iterations": 100,
    "stencil": "NinePointIsotropic",
    "loads_only": false
  }]
}

// Response:
{
  "success": true,
  "W": 64, "H": 64,
  "iterations": 100,
  "stencil": "NinePointIsotropic",
  "loads_only": false,
  "total_us": 12345,
  "us_per_update": 123.45,
  "us_per_cell_per_update": 0.0301,
  "fps_at_one_update_per_frame": 8101.6
}

What it does

  • Builds a WaveSimulation2D_Real of requested W × H.
  • Seeds with a deterministic checkerboard at ±0.5.
  • Warm-up step to prime caches.
  • Times iterations calls to update() using fl::micros().

loads_only mode

When loads_only=true, the kernel call is replaced with a memory-bound baseline (reads every inner cell into a volatile sink). The gap between the two results isolates memory cost from compute cost — critical for the ESP32-S3 PSRAM-vs-SRAM analysis tracked in sibling #3114.

What's NOT in this PR

Deliberate slicing:

Validation

  • bash lint --cpp — clean.
  • bash compile wasm --examples AutoResearch — build clean (verifies the new fl::WaveSimulation2D_Real include + fl::LaplacianStencil enum + the RPC body compile cleanly through the AutoResearch sketch).
  • On-hardware validation requires bash autoresearch <board> with the appropriate board on the desk.

Refs #3113 Task 1.

Summary by CodeRabbit

Release Notes

  • New Features
    • Added wave2dPerf remote performance benchmark method for 2D wave simulations with configurable parameters (grid dimensions, iteration count, stencil type, and memory-only baseline mode)
    • Returns comprehensive timing metrics including total elapsed time, per-update latency, per-cell-per-update cost, and frame-rate measurements

First slice of the wave2d perf pipeline. Adds a device-side RPC handler
in AutoResearchRemote.cpp that:

- Constructs a fl::WaveSimulation2D_Real of requested W x H
- Seeds it with a deterministic checkerboard at +/-0.5 (avoids the
  +/-1.0 float_to_fixed asymmetry noted in #3083)
- Optionally warms up to prime caches
- Times `iterations` calls to update() using fl::micros()
- Returns { total_us, us_per_update, us_per_cell_per_update,
            fps_at_one_update_per_frame }

Args (JSON-RPC):
  {
    W: 32, H: 32,           // grid dimensions
    iterations: 100,        // measurement window
    stencil: "NinePointIsotropic" | "FivePoint",
    loads_only: false       // memory-bound baseline mode
  }

`loads_only=true` swaps update() for a memory-bound baseline (reads
every inner cell into a volatile sink) — the gap between the two
results isolates memory cost from compute cost. This is critical for
the ESP32-S3 PSRAM-vs-SRAM analysis tracked in sibling issue #3114.

Input validation: refuses W/H outside [4, 1024] and iterations outside
[1, 100000] — defensive against bad RPC payloads (e.g. accidentally
requesting a multi-MB grid).

What's NOT in this PR (deliberately):
- Host-side `bash autoresearch <board> --wave2d-perf <W>x<H>` flag
  (Task 1 continuation). Will be a follow-up that wires the Python
  side to invoke this RPC and format the comparison table.
- Sanity calibration probes (Task 2 of #3113). Filed as the next slice.
- Compact O(h^4) stencil (research doc top recommendation). Filed
  separately so the perf benchmark is in place first.

Refs #3113 Task 1.

Verified by `bash compile wasm --examples AutoResearch` (build clean).
@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: 8c1ff918-82cc-4338-aec0-8d4a8cfa1281

📥 Commits

Reviewing files that changed from the base of the PR and between adedfc4 and 8a63076.

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

📝 Walkthrough

Walkthrough

A new wave2dPerf RPC method is added to AutoResearchRemote.cpp. It includes the real-valued 2D wave simulation header, then registers a remote endpoint that configures a WaveSimulation2D_Real instance, seeds it with a checkerboard, benchmarks either update() or a memory-read baseline, and returns JSON timing metrics.

Changes

wave2dPerf RPC Benchmark

Layer / File(s) Summary
wave2dPerf RPC: include, implementation, and registration
examples/AutoResearch/AutoResearchRemote.cpp
Adds #include "fl/math/wave/wave_simulation_real.h" and the full wave2dPerf RPC handler. Parses optional JSON params (W, H, iterations, stencil, loads_only), validates ranges, constructs fl::WaveSimulation2D_Real with the selected Laplacian stencil, seeds a deterministic checkerboard, performs a warm-up update(), then benchmarks either repeated update() calls or a loads-only memory-read loop using geti16(). Measures elapsed time with fl::micros() and returns total_us, time_per_update_us, time_per_cell_us, and fps as a JSON object.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Poem

🐇 Hop, hop, the waves do race,
A grid of ripples, time to trace!
Checkerboard seeds in memory laid,
Each update() call precisely weighed.
Microseconds fly, the JSON gleams—
The bunny benchmarks all the things! 🌊

✨ 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-wave2d-perf-rpc

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.

@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Jun 16, 2026
@zackees
zackees merged commit 8d19776 into master Jun 16, 2026
6 checks passed
@zackees
zackees deleted the feat/3113-wave2d-perf-rpc branch June 16, 2026 01:07
@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
#3118)

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.
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