Repository navigation
Conversation
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/197837
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (3 Unrelated Failures)As of commit 34c6ac6 with merge base b7ab856 ( FLAKY - The following job failed but was likely due to flakiness present on trunk:
CRCR (non-blocking) - The following CRCR downstream CI jobs failed but are non-blocking:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
[ghstack-poisoned]
malfet
added a commit
that referenced
this pull request
Sep 22, 2026
The guard that landed in #167541 is a `std::recursive_mutex` member. Two problems with that: a member changes `sizeof(MetalShaderLibrary)`, so out-of-tree C++ extensions compiled against the older header break, and the recursion was only needed because the accessors call one another rather than because anything genuinely reenters. Make it a file-static `std::mutex` in OperationUtils.mm, where every accessor that touches `library` or the caches is defined. Callers outside that file reach them through out-of-line functions, so nothing else needs the mutex, and the header goes back to its original layout -- the diff against the pre-#167541 header is a comment only. Dropping recursion means untangling the two chains that nested: - `hasFunction` called `getFunctionNames`, which locks. It now checks the populated flag under the lock, computes the names unlocked, then reacquires to fill the set, re-testing the flag in case another thread got there first. - `getCachedKernelFunctionPtr` called `getLibrary` + `getLibraryPipelineState`, both of which lock. It now looks up under the lock, builds the kernel unlocked and reacquires to insert; `try_emplace` keeps whichever thread won and the loser's kernel is dropped. `getPipelineStateForFunc` never nested: `getLibraryPipelineState(getLibrary(), fname)` evaluates the argument before the call, so those locks are sequential. No behavior change intended; this is the cleanup discussed on #167541. Test Plan: ```bash python test/test_mps.py TestMPS.test_multithreaded_arange python test/test_cpp_extensions_jit.py -k test_mps_extension ``` Both clean with the previous commit in this stack applied, on an Apple M4 Max running macOS 26.5. The extension test matters here specifically because it builds against the installed header, so it catches the layout change. The header change against the pre-#167541 baseline is a comment only, so `sizeof` is unchanged: ```bash git diff c7e434c^ -- aten/src/ATen/native/mps/MetalShaderLibrary.h ``` ```bash python test/test_mps.py ``` `failures=2, errors=1`, the same three pre-existing failures as main. Authored with the assistance of Claude Code. Co-Authored-By: Claude Opus 5 <[email protected]> ghstack-source-id: edeb7f8 Pull-Request: #197837
malfet
added a commit
that referenced
this pull request
Sep 22, 2026
The guard that landed in #167541 is a `std::recursive_mutex` member. Two problems with that: a member changes `sizeof(MetalShaderLibrary)`, so out-of-tree C++ extensions compiled against the older header break, and the recursion was only needed because the accessors call one another rather than because anything genuinely reenters. Make it a file-static `std::mutex` in OperationUtils.mm, where every accessor that touches `library` or the caches is defined. Callers outside that file reach them through out-of-line functions, so nothing else needs the mutex, and the header goes back to its original layout -- the diff against the pre-#167541 header is a comment only. Dropping recursion means untangling the two chains that nested: - `hasFunction` called `getFunctionNames`, which locks. It now checks the populated flag under the lock, computes the names unlocked, then reacquires to fill the set, re-testing the flag in case another thread got there first. - `getCachedKernelFunctionPtr` called `getLibrary` + `getLibraryPipelineState`, both of which lock. It now looks up under the lock, builds the kernel unlocked and reacquires to insert; `try_emplace` keeps whichever thread won and the loser's kernel is dropped. `getPipelineStateForFunc` never nested: `getLibraryPipelineState(getLibrary(), fname)` evaluates the argument before the call, so those locks are sequential. No behavior change intended; this is the cleanup discussed on #167541. Test Plan: ```bash python test/test_mps.py TestMPS.test_multithreaded_arange python test/test_cpp_extensions_jit.py -k test_mps_extension ``` Both clean with the previous commit in this stack applied, on an Apple M4 Max running macOS 26.5. The extension test matters here specifically because it builds against the installed header, so it catches the layout change. The header change against the pre-#167541 baseline is a comment only, so `sizeof` is unchanged: ```bash git diff c7e434c^ -- aten/src/ATen/native/mps/MetalShaderLibrary.h ``` ```bash python test/test_mps.py ``` `failures=2, errors=1`, the same three pre-existing failures as main. Authored with the assistance of Claude Code. Co-Authored-By: Claude Opus 5 <[email protected]> ghstack-source-id: edeb7f8 Pull-Request: #197837
Skylion007
approved these changes
Sep 22, 2026
Collaborator
Author
|
@pytorchbot merge |
Collaborator
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
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.
Stack from ghstack (oldest at bottom):
The guard that landed in #167541 uses
std::recursive_mutex, that changessizeof(MetalShaderLibrary)and therefore breaks ABI with existing out-of-tree C++ extensions, and recursive calls were made from other methods within the same class.Make it a file-static
std::mutexin OperationUtils.mm, where every accessor that touches library caches are defined.Dropping recursion means untangling the two chains that nested:
hasFunctioncalledgetFunctionNames, which locks. It now checks the populated flag under the lock, computes the names unlocked, then reacquires to fill the set, re-testing the flag in case another thread got there first.getCachedKernelFunctionPtrcalledgetLibrary+getLibraryPipelineState,both of which lock. It now looks up under the lock, builds the kernel unlocked
and reacquires to insert;
try_emplacekeeps whichever thread won and theloser's kernel is dropped.
getPipelineStateForFuncnever nested:getLibraryPipelineState(getLibrary(), fname)evaluates the argument before the call, so those locks are sequential.No behavior change intended; this is the cleanup discussed on #167541.
Authored with the assistance of Claude Code.
Co-Authored-By: Claude Opus 5 [email protected]