sim: get MetaDrive bridge working on macOS (fixes #33207) - #38283
Closed
flowmar47 wants to merge 3 commits into
Closed
sim: get MetaDrive bridge working on macOS (fixes #33207)#38283flowmar47 wants to merge 3 commits into
flowmar47 wants to merge 3 commits into
Conversation
Three fixes to make tools/sim/tests/test_metadrive_bridge.py pass on macOS: - manager: skip unblock_stdout() on Darwin. forkpty() of the already multi-threaded manager process kills the child before main() runs, and macOS ptys discard the child's pending output on exit, so manager died silently with exit code 0. - hardwared: exempt the free_space startup condition under SIMULATION, matching the existing SIMULATION exemption in selfdrived. The 2% killall rationale is device-specific and silently blocks onroad on a nearly-full dev machine. - sim camerad: stamp frames with time.monotonic() (the same clock as logMonoTime) instead of frame_id * 0.05s. locationd's filter rewind check compares cameraOdometry's timestampEof against IMU logMonoTime, so the fabricated near-zero eof made it reject every camera observation (platform-independent bug; also affects Linux). Fixes commaai#33207 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RVUzZmGEtSvH77hxaCSmsn
Contributor
Process replay diff reportReplays driving segments through this PR and compares the behavior to master. ✅ 0 changed, 66 passed, 0 errors |
modeld's warp kernels are compiled against the device camerad's NV12 layout from get_nv12_info() (128-aligned stride, aligned plane heights, VENUS-padded buffer size), but the sim allocated tightly-packed w*h*3/2 buffers. Two consequences: - modeld maps a get_nv12_info()-sized tensor over the smaller buffer, and the UV plane read runs ~240KB past the mapping: SIGSEGV on the x86 CI runners (modeld exits -11 ~8s after start), survives on macOS only by allocation-granularity luck - the warp samples Y with a 2048 stride over 1928-packed data and reads UV from the wrong offset, so the model has been driving on a sheared, wrong-chroma image (verified by pushing a test pattern through the shipped warp pkl: packed layout smears it, this layout keeps it intact) Publish the buffers with create_buffers_with_sizes() using the same layout; encoderd/ui already honor the stride and uv_offset metadata. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RVUzZmGEtSvH77hxaCSmsn
Fork PRs run on ubuntu-24.04 where build_stripped.sh needs ~70s; the 1-minute step timeout was failing build release. Co-authored-by: flowmar47 <flowmar47@users.noreply.github.com>
Contributor
|
This PR has had no activity for 24 days. It will be automatically closed in 7 days if there is no activity. |
Contributor
|
This PR has been automatically closed due to inactivity. Feel free to re-open once activity resumes. |
1 similar comment
Contributor
|
This PR has been automatically closed due to inactivity. Feel free to re-open once activity resumes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #33207 —
tools/sim/tests/test_metadrive_bridge.pynow passes on macOS (Apple Silicon), and the same branch was verified on Linux (arm64 Ubuntu 24.04 container, xvfb): the test passes there too.Three root causes, three small fixes:
1. manager died silently at launch (
system/manager/helpers.py)unblock_stdout()callsos.forkpty()after manager's imports have already spawned threads. On macOS the forked child is killed beforemain()runs, and macOS ptys discard the child's pending output on exit — solaunch_openpilot.shexited 0 with no output and nothing running. Skip the pty relay on Darwin; Linux is unchanged.2. free_space startup condition blocks sim on a full dev disk (
system/hardware/hardwared.py)freeSpacePercent > 2exists so the device kills processes before the phone can't boot. On a dev machine under 2% free it silently blocks onroad in simulation (on any OS).selfdrivedalready exempts its own free-space check underSIMULATION; this mirrors that inhardwared's startup conditions.3. sim camera frames stamped with a fake clock (
tools/sim/lib/camerad.py)Sim camerad set
eof = frame_id * 0.05s, i.e. a clock starting at 0, while every other message useslogMonoTime = time.monotonic(). locationd's filter-rewind check comparescameraOdometry.timestampEofagainst IMU time, so every camera observation was rejected ("Observation cameraOdometry ignored due to failed timing check") andlivePose/liveCalibrationnever became valid. This is platform-independent — it also affects current master on Linux, and may be related to why the CI sim job started timing out. Stamp frames withtime.monotonic().Results
out_of_lanewhile a parallel Linux build was saturating the CPU.Related: acados NaN on Apple Silicon
After these fixes the car engaged but only crept (~0.15 m/s): the long MPC failed every solve (
SQP_RTI: QP solver returned error status 3, "Long mpc reset, solution_status: 4"). Root cause is in commaai/dependencies: BLASFEO is built withARMV8A_ARM_CORTEX_A57on Darwin, and those asm kernels return NaNs on M-series. Rebuilding only libblasfeo.dylib withTARGET=GENERICmakes 100/100 solves succeed and the sim car actually drive. I'll submit that separately to commaai/dependencies; the fixes here are correct and useful independently.Test