Skip to content

[FEATURE] Share Metal command queue between Quadrants and PyTorch MPS#2760

Open
hughperkins wants to merge 1 commit intoGenesis-Embodied-AI:mainfrom
hughperkins:hp/metal-shared-queue
Open

[FEATURE] Share Metal command queue between Quadrants and PyTorch MPS#2760
hughperkins wants to merge 1 commit intoGenesis-Embodied-AI:mainfrom
hughperkins:hp/metal-shared-queue

Conversation

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

Description

Related Issue

Resolves Genesis-Embodied-AI/Genesis#

Motivation and Context

How Has This Been / Can This Be Tested?

Screenshots (if appropriate):

Checklist:

  • I read the CONTRIBUTING document.
  • I followed the Submitting Code Changes section of CONTRIBUTING document.
  • I tagged the title correctly (including BUG FIX/FEATURE/MISC/BREAKING)
  • I updated the documentation accordingly or no change is needed.
  • I tested my changes and added instructions on how to test it for reviewers.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Copy link
Copy Markdown

@claude claude Bot left a comment

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
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>
@hughperkins hughperkins force-pushed the hp/metal-shared-queue branch from 59bb31f to 3d0330c Compare May 4, 2026 13:00
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