Skip to content

Commit

Permalink
Add CPU microarchitecture to DeviceInfo (iree-org#9021)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerry Wu authored Apr 30, 2022
1 parent 697f20a commit 5d4d17b
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 16 deletions.
10 changes: 6 additions & 4 deletions build_tools/benchmarks/common/android_device_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ def get_android_gpu_name(verbose: bool = False) -> str:

def get_android_device_info(verbose: bool = False) -> DeviceInfo:
"""Returns device info for the Android device."""
return DeviceInfo(PlatformType.ANDROID, get_android_device_model(verbose),
get_android_cpu_abi(verbose),
get_android_cpu_features(verbose),
get_android_gpu_name(verbose))
return DeviceInfo(platform_type=PlatformType.ANDROID,
model=get_android_device_model(verbose),
cpu_abi=get_android_cpu_abi(verbose),
cpu_uarch=None,
cpu_features=get_android_cpu_features(verbose),
gpu_name=get_android_gpu_name(verbose))
36 changes: 32 additions & 4 deletions build_tools/benchmarks/common/benchmark_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
"unknown": "gpu-unknown",
}

# A map of canonical microarchitecture names.
CANONICAL_MICROARCHITECTURE_NAMES = {"CascadeLake", "Zen2"}


@dataclass
class DriverInfo:
Expand Down Expand Up @@ -167,14 +170,16 @@ class DeviceInfo:
It includes the following characteristics:
- platform_type: the OS platform, e.g., 'Android'
- model: the product model, e.g., 'Pixel-4'
- cpu_abi: the CPU ABI, e.g., 'arm64-v8a'
- cpu_abi: the CPU ABI, e.g., 'arm64-v8a', 'x86_64'
- cpu_uarch: the CPU microarchitecture, e.g., 'CascadeLake'
- cpu_features: the detailed CPU features, e.g., ['fphp', 'sve']
- gpu_name: the GPU name, e.g., 'Mali-G77'
"""

platform_type: PlatformType
model: str
cpu_abi: str
cpu_uarch: Optional[str]
cpu_features: Sequence[str]
gpu_name: str

Expand All @@ -183,6 +188,7 @@ def __str__(self):
params = [
f"model='{self.model}'",
f"cpu_abi='{self.cpu_abi}'",
f"cpu_uarch='{self.cpu_uarch}'",
f"gpu_name='{self.gpu_name}'",
f"cpu_features=[{features}]",
]
Expand All @@ -194,6 +200,15 @@ def get_iree_cpu_arch_name(self) -> str:
if not arch:
raise ValueError(f"Unrecognized CPU ABI: '{self.cpu_abi}'; "
"need to update the map")

if self.cpu_uarch:
if self.cpu_uarch not in CANONICAL_MICROARCHITECTURE_NAMES:
raise ValueError(
f"Unrecognized CPU microarchitecture: '{self.cpu_uarch}'; "
"need to update the map")

arch = f'{arch}-{self.cpu_uarch.lower()}'

return arch

def get_iree_gpu_arch_name(self) -> str:
Expand All @@ -203,28 +218,41 @@ def get_iree_gpu_arch_name(self) -> str:
"need to update the map")
return arch

def get_cpu_arch_revision(self) -> str:
def get_detailed_cpu_arch_name(self) -> str:
"""Returns the detailed architecture name."""

if self.cpu_abi == "arm64-v8a":
return self.__get_arm_cpu_arch_revision()
if self.cpu_abi == "x86_64":
return "x86_64"
return self.__get_x86_detailed_cpu_arch_name()
raise ValueError("Unrecognized CPU ABI; need to update the list")

def to_json_object(self) -> Dict[str, Any]:
return {
"platform_type": self.platform_type.value,
"model": self.model,
"cpu_abi": self.cpu_abi,
"cpu_uarch": self.cpu_uarch if self.cpu_uarch else "",
"cpu_features": self.cpu_features,
"gpu_name": self.gpu_name,
}

@staticmethod
def from_json_object(json_object: Dict[str, Any]):
cpu_uarch = json_object.get("cpu_uarch")
return DeviceInfo(PlatformType(json_object["platform_type"]),
json_object["model"], json_object["cpu_abi"],
None if cpu_uarch == "" else cpu_uarch,
json_object["cpu_features"], json_object["gpu_name"])

def __get_x86_detailed_cpu_arch_name(self) -> str:
"""Returns the x86 architecture with microarchitecture name."""

if not self.cpu_uarch:
return self.cpu_abi

return f"{self.cpu_abi}-{self.cpu_uarch}"

def __get_arm_cpu_arch_revision(self) -> str:
"""Returns the ARM architecture revision."""

Expand Down Expand Up @@ -276,7 +304,7 @@ def __str__(self):
if driver_info.device_type == 'GPU':
target_arch = "GPU-" + self.device_info.gpu_name
elif driver_info.device_type == 'CPU':
target_arch = "CPU-" + self.device_info.get_cpu_arch_revision()
target_arch = "CPU-" + self.device_info.get_detailed_cpu_arch_name()
else:
raise ValueError(
f"Unrecognized device type '{driver_info.device_type}' of the runner '{self.runner}'"
Expand Down
4 changes: 2 additions & 2 deletions build_tools/benchmarks/common/benchmark_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ def run(self) -> None:
benchmark_cases = self.benchmark_suite.filter_benchmarks_for_category(
category=category,
available_drivers=drivers,
cpu_target_arch_filter=cpu_target_arch,
gpu_target_arch_filter=gpu_target_arch,
cpu_target_arch_filter=f"^{cpu_target_arch}$",
gpu_target_arch_filter=f"^{gpu_target_arch}$",
driver_filter=self.config.driver_filter,
mode_filter=self.config.mode_filter,
model_name_filter=self.config.model_name_filter)
Expand Down
8 changes: 6 additions & 2 deletions build_tools/benchmarks/common/benchmark_driver_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@ def setUp(self):
capture_tarball="captures.tar",
capture_tmp_dir=os.path.join(self.tmp_dir.name, CAPTURES_REL_PATH)))

self.device_info = DeviceInfo(PlatformType.LINUX, "Unknown", "arm64-v8a",
["sha2"], "Mali-G78")
self.device_info = DeviceInfo(platform_type=PlatformType.LINUX,
model="Unknown",
cpu_abi="arm64-v8a",
cpu_uarch=None,
cpu_features=["sha2"],
gpu_name="Mali-G78")

case1 = BenchmarkCase(model_name_with_tags="DeepNet",
bench_mode=["1-thread", "full-inference"],
Expand Down
7 changes: 5 additions & 2 deletions build_tools/benchmarks/common/linux_device_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""Utils for accessing Linux device information."""

import re
from typing import Sequence
from typing import Optional, Sequence

from .benchmark_definition import (execute_cmd_and_get_output, DeviceInfo,
PlatformType)
Expand Down Expand Up @@ -35,18 +35,21 @@ def get_linux_cpu_model(verbose: bool = False) -> str:


def get_linux_device_info(device_model: str = "Unknown",
cpu_uarch: Optional[str] = None,
verbose: bool = False) -> DeviceInfo:
"""Returns device info for the Linux device.
Args:
- device_model: the device model name, e.g., 'ThinkStation P520'
- device_model: the device model name, e.g., 'ThinkStation P520'
- cpu_uarch: the CPU microarchitecture, e.g., 'CascadeLake'
"""
return DeviceInfo(
PlatformType.LINUX,
# Includes CPU model as it is the key factor of the device performance.
model=f"{device_model}({get_linux_cpu_model(verbose)})",
# Currently we only have x86, so CPU ABI = CPU arch.
cpu_abi=get_linux_cpu_arch(verbose),
cpu_uarch=cpu_uarch,
cpu_features=get_linux_cpu_features(verbose),
# We don't yet support GPU benchmark on Linux devices.
gpu_name="Unknown")
3 changes: 2 additions & 1 deletion build_tools/benchmarks/common/linux_device_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ def test_get_linux_cpu_model(self):

def test_get_linux_device_info(self):
self.assertEqual(
get_linux_device_info("Dummy"),
get_linux_device_info("Dummy", "Zen2"),
DeviceInfo(platform_type=PlatformType.LINUX,
model="Dummy(AMD EPYC 7B12)",
cpu_abi="x86_64",
cpu_uarch="Zen2",
cpu_features=["fpu", "vme", "de", "pse", "tsc"],
gpu_name="Unknown"))

Expand Down
6 changes: 5 additions & 1 deletion build_tools/benchmarks/run_benchmarks_on_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ def __run_capture(self, case_dir, tool_name: str, capture_filename: str,


def main(args):
device_info = get_linux_device_info(args.device_model, args.verbose)
device_info = get_linux_device_info(args.device_model, args.cpu_uarch,
args.verbose)
if args.verbose:
print(device_info)

Expand Down Expand Up @@ -141,6 +142,9 @@ def parse_argument():
arg_parser.add_argument("--device_model",
default="Unknown",
help="Device model")
arg_parser.add_argument("--cpu_uarch",
default=None,
help="CPU microarchitecture, e.g., CascadeLake")

return arg_parser.parse_args()

Expand Down

0 comments on commit 5d4d17b

Please sign in to comment.