Skip to content

[FEATURE] Avoid manually sync between torch and quadrants on Metal.#2760

Merged
duburcqa merged 3 commits into
Genesis-Embodied-AI:mainfrom
hughperkins:hp/metal-shared-queue
May 12, 2026
Merged

[FEATURE] Avoid manually sync between torch and quadrants on Metal.#2760
duburcqa merged 3 commits into
Genesis-Embodied-AI:mainfrom
hughperkins:hp/metal-shared-queue

Conversation

@hughperkins

@hughperkins hughperkins commented May 4, 2026

Copy link
Copy Markdown
Collaborator

At gs.init() time on Apple Metal, extract PyTorch MPS's MTLCommandQueue and pass it to Quadrants via external_metal_command_queue. This lets both frameworks dispatch GPU work on the same queue, so Metal's sequential command buffer ordering eliminates the need for explicit CPU-side syncs (qd.sync / torch.mps.synchronize) at every interop point.

Falls back gracefully to separate queues (with syncs preserved) if the queue pointer cannot be extracted (e.g. older PyTorch or non-MPS device).

Depends on Genesis-Embodied-AI/quadrants#618.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@hughperkins

Copy link
Copy Markdown
Collaborator Author

(note: needs a new quadrnst release)

@hughperkins hughperkins force-pushed the hp/metal-shared-queue branch from 15c0094 to 59bb31f Compare May 4, 2026 12:52
Comment thread genesis/engine/solvers/kinematic_solver.py Outdated
Comment thread genesis/engine/solvers/kinematic_solver.py Outdated
Comment thread genesis/engine/solvers/rigid/rigid_solver.py Outdated
Comment thread genesis/__init__.py Outdated
Comment thread genesis/__init__.py Outdated
@hughperkins hughperkins force-pushed the hp/metal-shared-queue branch from 59bb31f to 3d0330c Compare May 4, 2026 13:00
duburcqa
duburcqa previously approved these changes May 4, 2026
@github-actions

github-actions Bot commented May 5, 2026

Copy link
Copy Markdown

⚠️ Abnormal Benchmark Result Detected ➡️ Report

hughperkins and others added 2 commits May 12, 2026 14:42
At gs.init() time on Apple Metal, extract PyTorch MPS's MTLCommandQueue
and pass it to Quadrants via external_metal_command_queue. This lets both
frameworks dispatch GPU work on the same queue, so Metal's sequential
command buffer ordering eliminates the need for explicit CPU-side syncs
(qd.sync / torch.mps.synchronize) at every interop point.

Raises an exception if the queue cannot be extracted, since correct
synchronisation on Metal depends on the shared queue.

Removes all torch.mps.synchronize() guards from solvers and misc.py.

Depends on Genesis-Embodied-AI/quadrants#618.

Co-authored-by: Cursor <cursoragent@cursor.com>
The ctypes/ObjC logic to extract PyTorch MPS's MTLCommandQueue* now
lives in Quadrants (qd.interop module), so Genesis just calls the
public API. Removes ~35 lines of low-level ctypes code.

Co-authored-by: Cursor <cursoragent@cursor.com>
@duburcqa duburcqa changed the title [FEATURE] Share Metal command queue between Quadrants and PyTorch MPS [FEATURE] Avoid manually sync between torch and quadrants on Metal. May 12, 2026
@duburcqa duburcqa force-pushed the hp/metal-shared-queue branch from c9351d6 to 4e02588 Compare May 12, 2026 12:54
@duburcqa duburcqa force-pushed the hp/metal-shared-queue branch from 4e02588 to 1836b42 Compare May 12, 2026 12:55
@duburcqa duburcqa merged commit 2e83ce5 into Genesis-Embodied-AI:main May 12, 2026
19 of 20 checks passed
@github-actions

Copy link
Copy Markdown

🔴 Benchmark Regression Detected ➡️ Report

duburcqa added a commit that referenced this pull request May 13, 2026
@hughperkins hughperkins deleted the hp/metal-shared-queue branch May 17, 2026 20:56
duburcqa added a commit to duburcqa/Genesis that referenced this pull request May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants