-
Notifications
You must be signed in to change notification settings - Fork 800
Metal backend: compute init/execute times #16639
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
Open
manuelcandales
wants to merge
11
commits into
main
Choose a base branch
from
manuel/metal-backend-stats
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+267
−0
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
dd17287
metal backend execute stats
manuelcandales 70e5aec
per method statistics: execute
manuelcandales a1d3c52
init stats
manuelcandales ee2a8b5
conditional compilation
manuelcandales 9b8d336
refactor to metal/runtime/stats.[h/.cpp]
manuelcandales 88c36d5
define C++ preprocessor macro
manuelcandales a1f0384
add mutex
manuelcandales 69ce03e
rename reset function
manuelcandales 00d2bbf
clean up
manuelcandales e22f542
singleton pattern
manuelcandales 3cfefbf
new line
manuelcandales File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /* | ||
| * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| * All rights reserved. | ||
| * | ||
| * This source code is licensed under the BSD-style license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| #include <executorch/backends/apple/metal/runtime/stats.h> | ||
| #include <iostream> | ||
|
|
||
| namespace executorch { | ||
| namespace backends { | ||
| namespace metal { | ||
|
|
||
| void print_metal_backend_stats() { | ||
| std::cout << "\n--- Metal Backend Performance Statistics ---" << std::endl; | ||
|
|
||
| // Init stats | ||
| double metal_init_total_ms = get_metal_backend_init_total_ms(); | ||
| int64_t metal_init_call_count = get_metal_backend_init_call_count(); | ||
| std::cout << "Metal init() total: " << metal_init_total_ms << " ms (" | ||
| << metal_init_call_count << " calls)"; | ||
| if (metal_init_call_count > 0) { | ||
| std::cout << " (avg: " << metal_init_total_ms / metal_init_call_count | ||
| << " ms/call)"; | ||
| } | ||
| std::cout << std::endl; | ||
|
|
||
| // Per-method init breakdown | ||
| auto init_per_method_stats = get_metal_backend_init_per_method_stats(); | ||
| if (!init_per_method_stats.empty()) { | ||
| std::cout << " Per-method init breakdown:" << std::endl; | ||
| for (const auto& entry : init_per_method_stats) { | ||
| const std::string& method_name = entry.first; | ||
| double method_total_ms = entry.second.first; | ||
| int64_t method_call_count = entry.second.second; | ||
| std::cout << " " << method_name << ": " << method_total_ms << " ms (" | ||
| << method_call_count << " calls)"; | ||
| if (method_call_count > 0) { | ||
| std::cout << " (avg: " << method_total_ms / method_call_count | ||
| << " ms/call)"; | ||
| } | ||
| std::cout << std::endl; | ||
| } | ||
| } | ||
|
|
||
| // Execute stats | ||
| double metal_total_ms = get_metal_backend_execute_total_ms(); | ||
| int64_t metal_call_count = get_metal_backend_execute_call_count(); | ||
| std::cout << "\nMetal execute() total: " << metal_total_ms << " ms (" | ||
| << metal_call_count << " calls)"; | ||
| if (metal_call_count > 0) { | ||
| std::cout << " (avg: " << metal_total_ms / metal_call_count << " ms/call)"; | ||
| } | ||
| std::cout << std::endl; | ||
|
|
||
| // Per-method execute breakdown | ||
| auto per_method_stats = get_metal_backend_per_method_stats(); | ||
| if (!per_method_stats.empty()) { | ||
| std::cout << " Per-method execute breakdown:" << std::endl; | ||
| for (const auto& entry : per_method_stats) { | ||
manuelcandales marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const std::string& method_name = entry.first; | ||
| double method_total_ms = entry.second.first; | ||
| int64_t method_call_count = entry.second.second; | ||
| std::cout << " " << method_name << ": " << method_total_ms << " ms (" | ||
| << method_call_count << " calls)"; | ||
| if (method_call_count > 0) { | ||
| std::cout << " (avg: " << method_total_ms / method_call_count | ||
| << " ms/call)"; | ||
| } | ||
| std::cout << std::endl; | ||
| } | ||
| } | ||
|
|
||
| std::cout << "--------------------------------------------\n" << std::endl; | ||
| } | ||
|
|
||
| } // namespace metal | ||
| } // namespace backends | ||
| } // namespace executorch | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* | ||
| * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| * All rights reserved. | ||
| * | ||
| * This source code is licensed under the BSD-style license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <cstdint> | ||
| #include <string> | ||
| #include <unordered_map> | ||
| #include <utility> | ||
|
|
||
| namespace executorch { | ||
| namespace backends { | ||
| namespace metal { | ||
|
|
||
| // ======================= | ||
| // Metal backend timing statistics | ||
| // ======================= | ||
|
|
||
| // Execute timing | ||
| double get_metal_backend_execute_total_ms(); | ||
| int64_t get_metal_backend_execute_call_count(); | ||
| // Returns map of method_name -> (total_ms, call_count) | ||
| std::unordered_map<std::string, std::pair<double, int64_t>> | ||
| get_metal_backend_per_method_stats(); | ||
|
|
||
| // Init timing | ||
| double get_metal_backend_init_total_ms(); | ||
| int64_t get_metal_backend_init_call_count(); | ||
| // Returns map of method_name -> (total_ms, call_count) for init | ||
| std::unordered_map<std::string, std::pair<double, int64_t>> | ||
| get_metal_backend_init_per_method_stats(); | ||
|
|
||
| // Reset all timing stats | ||
manuelcandales marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| void reset_metal_backend_stats(); | ||
|
|
||
| // Print all timing stats to stdout | ||
| void print_metal_backend_stats(); | ||
|
|
||
| } // namespace metal | ||
| } // namespace backends | ||
| } // namespace executorch | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.