-
Notifications
You must be signed in to change notification settings - Fork 25.7k
[MPS] Release MetalShaderLibrary cached resources #142053
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/142053
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 93ca83c with merge base 61dc5e9 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@pytorchbot merge -f "MPS + Lint are green" |
Merge startedYour change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
By releasing retained `id<MTLFunction>` and `id<MTLComputePipelineState>`
Please note, that `id<MTLLibrary>` associated with class are currently leaked, which is by design, all dynamic shader allocations shoudl use `DynamicMetalShaderLibrary`
Test plan: `leaks --atExit -- ./bin/mps_test_metal_library`
Before:
```
STACK OF 1 INSTANCE OF 'ROOT LEAK: <_MTLFunctionInternal>':
18 dyld 0x197a94274 start + 2840
17 mps_test_metal_library 0x1002cb420 main + 68
16 mps_test_metal_library 0x1002fa388 testing::UnitTest::Run() + 124
15 mps_test_metal_library 0x1002fa40c bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) + 80
14 mps_test_metal_library 0x1002fac50 testing::internal::UnitTestImpl::RunAllTests() + 1588
13 mps_test_metal_library 0x1002e9934 testing::TestSuite::Run() + 1032
12 mps_test_metal_library 0x1002e8688 testing::TestInfo::Run() + 960
11 mps_test_metal_library 0x1002e715c testing::Test::Run() + 812
10 mps_test_metal_library 0x1002e7200 void testing::internal::HandleExceptionsInMethodIfSupported<testing::TestSuite, void>(testing::TestSuite*, void (testing::TestSuite::*)(), char const*) + 80
9 mps_test_metal_library 0x1002c5518 MPSTestMetalLibrary_ArangeShader_Test::TestBody() + 420
8 libtorch_cpu.dylib 0x10fdd3804 at::native::mps::MetalShaderLibrary::getKernelFunction(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&) + 56
7 libtorch_cpu.dylib 0x10fdd3394 at::native::mps::MetalShaderLibrary::getLibraryPipelineState(id<MTLLibrary>, std::__1::basic_string<char, id<MTLLibrary>::char_traits<char>, id<MTLLibrary>::allocator<char>> const&) + 268
6 com.apple.Metal 0x1a2be43b4 -[_MTLLibrary newFunctionWithName:] + 28
5 com.apple.Metal 0x1a2be4498 -[_MTLLibrary newFunctionWithNameInternal:] + 148
4 com.apple.Metal 0x1a2be4580 MTLLibraryContainer::functionWithName(NSString*, id<MTLDevice>) + 68
3 com.apple.Metal 0x1a2be4724 MTLLibraryDataWithArchive::newFunction(NSString*, id<MTLDevice>) + 368
2 libobjc.A.dylib 0x197a49ddc _objc_rootAllocWithZone + 48
1 libsystem_malloc.dylib 0x197c3baf8 _calloc + 88
0 libsystem_malloc.dylib 0x197c4e9bc _malloc_zone_calloc_instrumented_or_legacy + 128
====
2 (592 bytes) ROOT LEAK: <_MTLFunctionInternal 0x1325e5550> [448]
1 (144 bytes) _functionQueue --> <dispatch_queue_t (serial) 0x13254c340> [144] "function queue" (from Metal)
```
After:
```
Process: mps_test_metal_library [30687]
Path: /Users/USER/*/mps_test_metal_library
Load Address: 0x100f74000
Identifier: mps_test_metal_library
Version: 0
Code Type: ARM64
Platform: macOS
Parent Process: leaks [30686]
Date/Time: 2024-12-04 07:57:01.020 -0800
Launch Time: 2024-12-04 07:56:59.030 -0800
OS Version: macOS 15.1.1 (24B2091)
Report Version: 7
Analysis Tool: /usr/bin/leaks
Physical footprint: 177.2M
Physical footprint (peak): 236.5M
Idle exit: untracked
----
leaks Report Version: 4.0, multi-line stacks
Process 30687: 40691 nodes malloced for 5575 KB
Process 30687: 0 leaks for 0 total leaked bytes.
```
Pull Request resolved: pytorch#142053
Approved by: https://github.com/manuelcandales
ghstack dependencies: pytorch#142052
By releasing retained `id<MTLFunction>` and `id<MTLComputePipelineState>`
Please note, that `id<MTLLibrary>` associated with class are currently leaked, which is by design, all dynamic shader allocations shoudl use `DynamicMetalShaderLibrary`
Test plan: `leaks --atExit -- ./bin/mps_test_metal_library`
Before:
```
STACK OF 1 INSTANCE OF 'ROOT LEAK: <_MTLFunctionInternal>':
18 dyld 0x197a94274 start + 2840
17 mps_test_metal_library 0x1002cb420 main + 68
16 mps_test_metal_library 0x1002fa388 testing::UnitTest::Run() + 124
15 mps_test_metal_library 0x1002fa40c bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) + 80
14 mps_test_metal_library 0x1002fac50 testing::internal::UnitTestImpl::RunAllTests() + 1588
13 mps_test_metal_library 0x1002e9934 testing::TestSuite::Run() + 1032
12 mps_test_metal_library 0x1002e8688 testing::TestInfo::Run() + 960
11 mps_test_metal_library 0x1002e715c testing::Test::Run() + 812
10 mps_test_metal_library 0x1002e7200 void testing::internal::HandleExceptionsInMethodIfSupported<testing::TestSuite, void>(testing::TestSuite*, void (testing::TestSuite::*)(), char const*) + 80
9 mps_test_metal_library 0x1002c5518 MPSTestMetalLibrary_ArangeShader_Test::TestBody() + 420
8 libtorch_cpu.dylib 0x10fdd3804 at::native::mps::MetalShaderLibrary::getKernelFunction(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&) + 56
7 libtorch_cpu.dylib 0x10fdd3394 at::native::mps::MetalShaderLibrary::getLibraryPipelineState(id<MTLLibrary>, std::__1::basic_string<char, id<MTLLibrary>::char_traits<char>, id<MTLLibrary>::allocator<char>> const&) + 268
6 com.apple.Metal 0x1a2be43b4 -[_MTLLibrary newFunctionWithName:] + 28
5 com.apple.Metal 0x1a2be4498 -[_MTLLibrary newFunctionWithNameInternal:] + 148
4 com.apple.Metal 0x1a2be4580 MTLLibraryContainer::functionWithName(NSString*, id<MTLDevice>) + 68
3 com.apple.Metal 0x1a2be4724 MTLLibraryDataWithArchive::newFunction(NSString*, id<MTLDevice>) + 368
2 libobjc.A.dylib 0x197a49ddc _objc_rootAllocWithZone + 48
1 libsystem_malloc.dylib 0x197c3baf8 _calloc + 88
0 libsystem_malloc.dylib 0x197c4e9bc _malloc_zone_calloc_instrumented_or_legacy + 128
====
2 (592 bytes) ROOT LEAK: <_MTLFunctionInternal 0x1325e5550> [448]
1 (144 bytes) _functionQueue --> <dispatch_queue_t (serial) 0x13254c340> [144] "function queue" (from Metal)
```
After:
```
Process: mps_test_metal_library [30687]
Path: /Users/USER/*/mps_test_metal_library
Load Address: 0x100f74000
Identifier: mps_test_metal_library
Version: 0
Code Type: ARM64
Platform: macOS
Parent Process: leaks [30686]
Date/Time: 2024-12-04 07:57:01.020 -0800
Launch Time: 2024-12-04 07:56:59.030 -0800
OS Version: macOS 15.1.1 (24B2091)
Report Version: 7
Analysis Tool: /usr/bin/leaks
Physical footprint: 177.2M
Physical footprint (peak): 236.5M
Idle exit: untracked
----
leaks Report Version: 4.0, multi-line stacks
Process 30687: 40691 nodes malloced for 5575 KB
Process 30687: 0 leaks for 0 total leaked bytes.
```
Pull Request resolved: pytorch#142053
Approved by: https://github.com/manuelcandales
ghstack dependencies: pytorch#142052
By releasing retained `id<MTLFunction>` and `id<MTLComputePipelineState>`
Please note, that `id<MTLLibrary>` associated with class are currently leaked, which is by design, all dynamic shader allocations shoudl use `DynamicMetalShaderLibrary`
Test plan: `leaks --atExit -- ./bin/mps_test_metal_library`
Before:
```
STACK OF 1 INSTANCE OF 'ROOT LEAK: <_MTLFunctionInternal>':
18 dyld 0x197a94274 start + 2840
17 mps_test_metal_library 0x1002cb420 main + 68
16 mps_test_metal_library 0x1002fa388 testing::UnitTest::Run() + 124
15 mps_test_metal_library 0x1002fa40c bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) + 80
14 mps_test_metal_library 0x1002fac50 testing::internal::UnitTestImpl::RunAllTests() + 1588
13 mps_test_metal_library 0x1002e9934 testing::TestSuite::Run() + 1032
12 mps_test_metal_library 0x1002e8688 testing::TestInfo::Run() + 960
11 mps_test_metal_library 0x1002e715c testing::Test::Run() + 812
10 mps_test_metal_library 0x1002e7200 void testing::internal::HandleExceptionsInMethodIfSupported<testing::TestSuite, void>(testing::TestSuite*, void (testing::TestSuite::*)(), char const*) + 80
9 mps_test_metal_library 0x1002c5518 MPSTestMetalLibrary_ArangeShader_Test::TestBody() + 420
8 libtorch_cpu.dylib 0x10fdd3804 at::native::mps::MetalShaderLibrary::getKernelFunction(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&) + 56
7 libtorch_cpu.dylib 0x10fdd3394 at::native::mps::MetalShaderLibrary::getLibraryPipelineState(id<MTLLibrary>, std::__1::basic_string<char, id<MTLLibrary>::char_traits<char>, id<MTLLibrary>::allocator<char>> const&) + 268
6 com.apple.Metal 0x1a2be43b4 -[_MTLLibrary newFunctionWithName:] + 28
5 com.apple.Metal 0x1a2be4498 -[_MTLLibrary newFunctionWithNameInternal:] + 148
4 com.apple.Metal 0x1a2be4580 MTLLibraryContainer::functionWithName(NSString*, id<MTLDevice>) + 68
3 com.apple.Metal 0x1a2be4724 MTLLibraryDataWithArchive::newFunction(NSString*, id<MTLDevice>) + 368
2 libobjc.A.dylib 0x197a49ddc _objc_rootAllocWithZone + 48
1 libsystem_malloc.dylib 0x197c3baf8 _calloc + 88
0 libsystem_malloc.dylib 0x197c4e9bc _malloc_zone_calloc_instrumented_or_legacy + 128
====
2 (592 bytes) ROOT LEAK: <_MTLFunctionInternal 0x1325e5550> [448]
1 (144 bytes) _functionQueue --> <dispatch_queue_t (serial) 0x13254c340> [144] "function queue" (from Metal)
```
After:
```
Process: mps_test_metal_library [30687]
Path: /Users/USER/*/mps_test_metal_library
Load Address: 0x100f74000
Identifier: mps_test_metal_library
Version: 0
Code Type: ARM64
Platform: macOS
Parent Process: leaks [30686]
Date/Time: 2024-12-04 07:57:01.020 -0800
Launch Time: 2024-12-04 07:56:59.030 -0800
OS Version: macOS 15.1.1 (24B2091)
Report Version: 7
Analysis Tool: /usr/bin/leaks
Physical footprint: 177.2M
Physical footprint (peak): 236.5M
Idle exit: untracked
----
leaks Report Version: 4.0, multi-line stacks
Process 30687: 40691 nodes malloced for 5575 KB
Process 30687: 0 leaks for 0 total leaked bytes.
```
ghstack-source-id: 9a3fadc
Pull Request resolved: pytorch/pytorch#142053
Stack from ghstack (oldest at bottom):
By releasing retained
id<MTLFunction>andid<MTLComputePipelineState>Please note, that
id<MTLLibrary>associated with class are currently leaked, which is by design, all dynamic shader allocations shoudl useDynamicMetalShaderLibraryTest plan:
leaks --atExit -- ./bin/mps_test_metal_libraryBefore:
After: