Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions build_tools/benchmarks/run_benchmarks_on_android.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
BenchmarkResults, BenchmarkRun,
execute_cmd,
execute_cmd_and_get_output,
get_android_device_model,
IREE_PRETTY_NAMES_TO_DRIVERS)

# All benchmarks' relative path against root build directory.
Expand Down Expand Up @@ -547,12 +548,25 @@ def filter_and_run_benchmarks(
return (benchmark_files, captures, errors)


def set_frequency_scaling_governor(governor: str):
def set_cpu_frequency_scaling_governor(governor: str):
git_root = execute_cmd_and_get_output(["git", "rev-parse", "--show-toplevel"])
cpu_script = os.path.join(
git_root, "build_tools/benchmarks/set_android_scaling_governor.sh")
adb_push_to_tmp_dir(cpu_script)
adb_execute(["su", "root", "./set_android_scaling_governor.sh", governor])
android_path = adb_push_to_tmp_dir(cpu_script)
adb_execute(["su", "root", android_path, governor])


def set_gpu_frequency_scaling_policy(policy: str):
git_root = execute_cmd_and_get_output(["git", "rev-parse", "--show-toplevel"])
device_model = get_android_device_model()
if device_model == "Pixel-6":
gpu_script = os.path.join(
git_root, "build_tools/benchmarks/set_pixel6_gpu_scaling_policy.sh")
else:
raise RuntimeError(
f"Unsupported device '{device_model}' for setting GPU scaling policy")
android_path = adb_push_to_tmp_dir(gpu_script)
adb_execute(["su", "root", android_path, policy])


def parse_arguments():
Expand Down Expand Up @@ -617,6 +631,10 @@ def check_exe_path(path):
"--pin_cpu_freq",
action="store_true",
help="Pin CPU frequency for all cores to the maximum. Requires root")
parser.add_argument("--pin-gpu-freq",
"--pin_gpu_freq",
action="store_true",
help="Pin GPU frequency to the maximum. Requires root")
parser.add_argument(
"--keep_going",
"--keep-going",
Expand Down Expand Up @@ -658,8 +676,11 @@ def main(args):
"need to update the map")

if args.pin_cpu_freq:
set_frequency_scaling_governor("performance")
atexit.register(set_frequency_scaling_governor, "schedutil")
set_cpu_frequency_scaling_governor("performance")
atexit.register(set_cpu_frequency_scaling_governor, "schedutil")
if args.pin_gpu_freq:
set_gpu_frequency_scaling_policy("always_on")
atexit.register(set_gpu_frequency_scaling_policy, "coarse_demand")

previous_benchmarks = None
previous_captures = None
Expand Down
1 change: 1 addition & 0 deletions build_tools/benchmarks/set_android_scaling_governor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ done

echo "CPU info (after changing governor):"
echo 'cpu\tgovernor\tcur\tmin\tmax'
echo "------------------------------------------------"
for i in `cat /sys/devices/system/cpu/present | tr '-' ' ' | xargs seq`; do \
echo "cpu${i}" | paste \
- \
Expand Down
54 changes: 54 additions & 0 deletions build_tools/benchmarks/set_pixel6_gpu_scaling_policy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/sh

# Copyright 2021 The IREE Authors
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

# Runs on a Pixel 6 device itself to set the GPU frequency scaling policy.

################################### WARNING ####################################
# This will overheat the phone if it's not on a cooling plate, resulting in #
# thermal throttling. To prevent anything catching on fire, the actual GPU #
# frequencies will be throttled to below the maximum, skewing your results. #
################################################################################

set -euo pipefail

POLICY="${1:-always_on}"

readonly MALI_GPU_PATH="/sys/devices/platform/1c500000.mali"

echo "GPU info (before changing power policy):"
echo 'policy\t\t\t\t\tcur\tmin\tmax'
echo "--------------------------------------------------------------"
paste \
"${MALI_GPU_PATH}/power_policy" \
"${MALI_GPU_PATH}/cur_freq" \
"${MALI_GPU_PATH}/min_freq" \
"${MALI_GPU_PATH}/max_freq"

echo "Setting GPU power policy to ${POLICY}"

if [[ "$POLICY" == "always_on" ]]; then
echo "always_on" > "${MALI_GPU_PATH}/power_policy"
cat "${MALI_GPU_PATH}/max_freq" > "${MALI_GPU_PATH}/scaling_max_freq"
cat "${MALI_GPU_PATH}/max_freq" > "${MALI_GPU_PATH}/scaling_min_freq"
elif [[ "$POLICY" == "coarse_demand" ]]; then
echo "coarse_demand" > "${MALI_GPU_PATH}/power_policy"
cat "${MALI_GPU_PATH}/max_freq" > "${MALI_GPU_PATH}/scaling_max_freq"
cat "${MALI_GPU_PATH}/min_freq" > "${MALI_GPU_PATH}/scaling_min_freq"
else
echo "Unknown power policy: ${POLICY}"
exit 1
fi

echo "GPU info (after changing power policy):"
echo 'policy\t\t\t\t\tcur\tmin\tmax'
echo "--------------------------------------------------------------"
paste \
"${MALI_GPU_PATH}/power_policy" \
"${MALI_GPU_PATH}/cur_freq" \
"${MALI_GPU_PATH}/min_freq" \
"${MALI_GPU_PATH}/max_freq"