Repository navigation
fix(wave): switch WaveSimulation2D_Real grids from vector_psram to SRAM (closes #3114) - #3117
Conversation
The previous fl::vector_psram<i16> default silently put both wave grids in PSRAM on every ESP32 with PSRAM available — including ESP32-S3, which has no L2 cache. The 5-point stencil reads 5 cells per inner cell, so a 64x64 update was reading ~80 KB per step at ~50 MB/s practical PSRAM throughput → ~1.6 ms per step on memory alone. Identical-looking user code produced wildly different frame rates on ESP32-S3 vs Teensy 4 vs ESP32-P4. Switch to fl::vector<i16> (SRAM). Predictable everywhere: - ESP32-S3: 320 KB SRAM, 64x64 i16 grid = 8 KB, 128x128 = 32 KB, both fit easily. - ESP32-P4: ~750 KB SRAM, 256x256 fits. - Teensy 4: OCRAM, even faster. - AVR / Cortex-M0: grid sizes were already SRAM-only via the 1D class precedent; this aligns 2D with that pattern. Header comment documents the rationale + points at #3114 for the follow-up PSRAM opt-in (WaveSimulation2D_Real_Large) for users who genuinely need grids bigger than SRAM can hold. Closes #3114 Refs #3113 (parent meta — Wave2D perf pipeline)
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughIn ChangesPSRAM → SRAM buffer switch in WaveSimulation2D_Real
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
…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.
…efs #3122 A3) (#3141) A3 of meta #3122. Closes the deferred PSRAM opt-in follow-up from #3114 without introducing a parallel class — instead, exposes a tag-dispatch constructor overload on the existing WaveSimulation2D_Real: WaveSimulation2D_Real sim{ WaveSimulation2D_Real::PsramStorage{}, 256, 256}; Default constructor stays SRAM (post-#3117 default). PsramStorage tag explicitly opts a grid into PSRAM for users who genuinely need a grid larger than SRAM can hold AND accept the per-cell perf cost (~5-10x slower on ESP32-S3 without L2 cache; ~no cost on ESP32-P4 with L2 + cached PSRAM). Implementation: - New PsramStorage tag type on WaveSimulation2D_Real. - New tag-dispatch constructor that constructs grid1/grid2 with psram_memory_resource() instead of the default SRAM resource. - Cell count populated via resize() after PSRAM allocation. Avoided creating a parallel WaveSimulation2D_Real_Large class — the duplicated body would have been a maintenance burden, and the existing class is already SRAM by default after #3117. One class, two constructors, predictable storage. Verified by tests/fl/math/wave/wave_simulation_real.cpp (9/9 cases pass, including the new PSRAM constructor exercise). The PSRAM constructor falls back to default allocator on host where there's no real PSRAM, so the test exercises the constructor path everywhere. Refs #3122 A3, #3114 (now closed), #3117 (SRAM default), #3113 parent meta.
Closes #3114. Switches the silent
vector_psram<i16>grid default inWaveSimulation2D_Realto plainfl::vector<i16>(SRAM).Why
The previous default landed both wave grids in PSRAM on every ESP32 with PSRAM available. On ESP32-S3 (no L2 cache) this paid the full ~80 ns PSRAM access latency per cell — the 5-point stencil reads 5 cells per inner cell, so a 64×64 update was reading ~80 KB per step at ~50 MB/s practical PSRAM throughput → ~1.6 ms per step on memory alone, cratering frame rate at the grid sizes users actually want.
Worse, identical-looking user code produced wildly different frame rates on ESP32-S3 vs Teensy 4 vs ESP32-P4 depending on whether each had PSRAM. The auto-decision is the actual bug; making storage choice predictable is the fix.
Where the grids now live
Users who genuinely need grids bigger than SRAM allows can construct a parallel
WaveSimulation2D_Real_Large(deferred follow-up) that re-enables PSRAM as an explicit, documented opt-in.Validation
bash test fl_math_wave_wave_simulation_real --cpp— 8/8 pass.bash lint --cpp— clean.Out of scope
WaveSimulation2D_Real_Largeopt-in variant — deferred. Today's fix removes the silent default; the explicit opt-in is a separate follow-up.Allocatorparameter — rejected per fix(wave): remove silent vector_psram default in WaveSimulation2D_Real — SRAM by default, PSRAM opt-in #3114 body for the alternatives-considered reasons (template instantiation cost, harder to debug perf).Closes #3114
Refs #3113 (parent meta — Wave2D perf pipeline)
Summary by CodeRabbit