-
Notifications
You must be signed in to change notification settings - Fork 631
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
Rewrite benchmarking scripts with Python. #5082
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
46249b8
Rewrite benchmarking scripts with Python
hanhanW 336d45d
fix path
hanhanW 16c553d
fix pipeline
hanhanW 4bc5e3e
fix pipeline
hanhanW 4030e3a
fix scripts
hanhanW fa27072
rename + format
hanhanW c48a701
fix scripts
hanhanW c99c64a
add some commnets
hanhanW dfdd2ca
set back to 10 times
hanhanW a7b4d37
address comments
hanhanW e900913
formatting with yaqf
hanhanW a6b2294
fix f-string
hanhanW c4ca23e
fix typo
hanhanW a1e88a4
Remove default list for init method.
hanhanW 4ed327e
make default arguments None (not mutable)
hanhanW 6e8c509
Update build_tools/mako/benchmark_modules_on_android.py
hanhanW 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 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 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,102 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright 2021 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# Benchmarks modules generated by compile_android_modules.py and writes | ||
# performance data to a text proto file, e.g., mako-phone-mako_tag-git_hash. | ||
# | ||
# The script benchmarks modules on 7-th big core, ie, run with `taskset 80`. | ||
|
||
import argparse | ||
import datetime | ||
import subprocess | ||
import os | ||
import re | ||
|
||
import configuration | ||
|
||
PATTERN = re.compile(r"BM_(\w+)(.+)/real_time(\s+) (?P<ms>[.0-9]+) ms") | ||
DEVICE_ROOT = "/data/local/tmp/benchmark_tmpdir" | ||
|
||
|
||
def parse_arguments(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--git_hash", default="UNKNOWN") | ||
parser.add_argument("phone") | ||
args = parser.parse_args() | ||
return args | ||
|
||
|
||
def get_mako_sample(value, tag) -> str: | ||
return f""" | ||
samples: {{ | ||
time: {value} | ||
target: "{tag}" | ||
}}""".strip() | ||
|
||
|
||
def get_mako_metadata(git_hash, timestamp, benchmark_key) -> str: | ||
return f""" | ||
metadata: {{ | ||
git_hash: "{git_hash}" | ||
timestamp_ms: {timestamp} | ||
benchmark_key: "{benchmark_key}" | ||
}} | ||
""".strip() | ||
|
||
|
||
def benchmark(module_name, flagfile_name, target) -> str: | ||
samples = [] | ||
driver = target.get_driver() | ||
cmd = [ | ||
"adb", "shell", "LD_LIBRARY_PATH=/data/local/tmp", "taskset", "80", | ||
f"{DEVICE_ROOT}/iree-benchmark-module", | ||
f"--flagfile={DEVICE_ROOT}/{flagfile_name}", | ||
f"--module_file={DEVICE_ROOT}/{module_name}", f"--driver={driver}", | ||
"--benchmark_repetitions=10" | ||
] + target.runtime_flags | ||
print(f"Running cmd: {' '.join(cmd)}") | ||
output = subprocess.run(cmd, | ||
check=True, | ||
capture_output=True, | ||
universal_newlines=True).stdout | ||
for line in output.split("\n"): | ||
m = PATTERN.match(line) | ||
if m is not None: | ||
samples.append(get_mako_sample(m.group("ms"), target.mako_tag)) | ||
return "\n".join(samples) | ||
|
||
|
||
def main(args) -> None: | ||
timestamp = int(datetime.datetime.now().timestamp() * 1000) | ||
for model_benchmark in configuration.MODEL_BENCHMARKS: | ||
for phone in model_benchmark.phones: | ||
if phone.name != args.phone: | ||
continue | ||
mako_log = [] | ||
for target in phone.targets: | ||
module_name = configuration.get_module_name(model_benchmark.name, | ||
phone.name, target.mako_tag) | ||
flagfile_name = f"{model_benchmark.name}_flagfile" | ||
mako_log.append(benchmark(module_name, flagfile_name, target)) | ||
mako_log.append( | ||
get_mako_metadata(args.git_hash, timestamp, phone.benchmark_key)) | ||
mako_log = "\n".join(mako_log) | ||
filename = f"mako-{model_benchmark.name}-{phone.name}-{args.git_hash}.log" | ||
open(filename, "w").write(mako_log) | ||
print(mako_log) | ||
|
||
|
||
if __name__ == "__main__": | ||
main(parse_arguments()) |
This file was deleted.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think we should be using the more structured output instead of parsing the human-readable output... but this is ok for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think we can let it report a csv or something. I keep this because this is the same behavior as before. I will consider this.