From 65912b5734d41f48ec1c892ed21c5ffc01dee7d7 Mon Sep 17 00:00:00 2001 From: Jerry Wu Date: Sun, 12 Nov 2023 22:15:35 -0800 Subject: [PATCH] Rework CPU pinning for Android benchmarks (#15478) This change adds the configurations of CPU pinning to the benchmark definitions. Also follows #15452 to remap multi-thread benchmarks on the 2 homogeneous big cores on Pixel 6 --- .../benchmarks/run_benchmarks_on_android.py | 39 +++++++++---------- .../benchmarks/run_benchmarks_on_linux.py | 12 ++---- .../iree/armv8_a_benchmarks.py | 4 +- .../benchmark_suites/iree/vmvx_benchmarks.py | 4 +- .../python/e2e_model_tests/CMakeLists.txt | 12 ------ .../e2e_model_tests/run_module_utils.py | 28 ------------- .../e2e_model_tests/run_module_utils_test.py | 31 --------------- .../definitions/common_definitions.py | 23 +++++++++-- .../device_specs/device_collections.py | 9 ++--- .../device_specs/device_collections_test.py | 10 ++--- .../device_specs/device_parameters.py | 10 ----- .../device_specs/gcp_specs.py | 3 -- .../device_specs/moto_edge_x30_specs.py | 4 ++ .../device_specs/pixel_4_specs.py | 37 ------------------ .../device_specs/pixel_6_pro_specs.py | 21 +++++----- .../device_specs/riscv_specs.py | 3 -- .../e2e_test_framework/serialization.py | 2 + .../e2e_test_framework/serialization_test.py | 8 ++++ 18 files changed, 78 insertions(+), 182 deletions(-) delete mode 100644 build_tools/python/e2e_model_tests/CMakeLists.txt delete mode 100644 build_tools/python/e2e_model_tests/run_module_utils.py delete mode 100644 build_tools/python/e2e_model_tests/run_module_utils_test.py delete mode 100644 build_tools/python/e2e_test_framework/device_specs/device_parameters.py delete mode 100644 build_tools/python/e2e_test_framework/device_specs/pixel_4_specs.py diff --git a/build_tools/benchmarks/run_benchmarks_on_android.py b/build_tools/benchmarks/run_benchmarks_on_android.py index cd1571e60505..7f5fd1125bb1 100755 --- a/build_tools/benchmarks/run_benchmarks_on_android.py +++ b/build_tools/benchmarks/run_benchmarks_on_android.py @@ -67,8 +67,7 @@ ) import common.common_arguments from e2e_test_artifacts import iree_artifacts -from e2e_test_framework.definitions import common_definitions, iree_definitions -from e2e_test_framework.device_specs import device_parameters +from e2e_test_framework.definitions import iree_definitions # Root directory to perform benchmarks in on the Android device. ANDROID_TMPDIR = pathlib.PurePosixPath("/data/local/tmp/iree-benchmarks") @@ -308,6 +307,8 @@ def run_benchmark_case( ) run_config = benchmark_case.run_config + # TODO(#15452): Change to `--task_topology_cpu_ids` once we figure out + # the right mapping. taskset = self.__deduce_taskset_from_run_config(run_config) run_args = run_config.materialize_run_flags(inputs_dir=inputs_dir) run_args.append(f"--module={module_device_path}") @@ -440,29 +441,27 @@ def __run_capture( stdout_redirect = None if self.verbose else subprocess.DEVNULL execute_cmd(capture_cmd, verbose=self.verbose, stdout=stdout_redirect) - # TODO(#13187): These logics are inherited from the legacy benchmark suites, - # which only work for a few specific phones. We should define the topology - # in their device specs. def __deduce_taskset_from_run_config( self, run_config: iree_definitions.E2EModelRunConfig ) -> str: """Deduces the CPU mask according to device and execution config.""" - device_spec = run_config.target_device_spec - # For GPU benchmarks, use the most performant core. - if device_spec.architecture.type == common_definitions.ArchitectureType.GPU: - return "80" - - device_params = device_spec.device_parameters - single_thread = "1-thread" in run_config.module_execution_config.tags - if device_parameters.ARM_BIG_CORES in device_params: - return "80" if single_thread else "f0" - elif device_parameters.ARM_LITTLE_CORES in device_params: - return "08" if single_thread else "0f" - elif device_parameters.ALL_CORES in device_params: - return "80" if single_thread else "ff" - - raise ValueError(f"Unsupported config to deduce taskset: '{run_config}'.") + cpu_params = run_config.target_device_spec.device_parameters.cpu_params + if not cpu_params: + # Assume the mobile CPUs have <= 16 cores. + return "ffff" + + exec_config = run_config.module_execution_config + pinned_cores = cpu_params.pinned_cores + # Use the fastest cores in the spec for single-thread benchmarks. + if ( + exec_config.driver == iree_definitions.RuntimeDriver.LOCAL_SYNC + or "1-thread" in exec_config.tags + ): + pinned_cores = pinned_cores[-1:] + + cpu_mask = sum(1 << core_id for core_id in cpu_params.pinned_cores) + return f"{cpu_mask:04x}" def __check_and_push_file( self, host_path: pathlib.Path, device_dir: pathlib.PurePosixPath diff --git a/build_tools/benchmarks/run_benchmarks_on_linux.py b/build_tools/benchmarks/run_benchmarks_on_linux.py index 9bc3bfae4be5..2acc460088e4 100755 --- a/build_tools/benchmarks/run_benchmarks_on_linux.py +++ b/build_tools/benchmarks/run_benchmarks_on_linux.py @@ -34,7 +34,6 @@ ) from common.linux_device_utils import get_linux_device_info from e2e_test_artifacts import iree_artifacts -from e2e_model_tests import run_module_utils import common.common_arguments @@ -118,17 +117,14 @@ def __build_tool_cmds( inputs_dir: Optional[pathlib.Path] = None, ) -> List[Any]: run_config = benchmark_case.run_config - cmds: List[Any] = run_module_utils.build_linux_wrapper_cmds_for_device_spec( - run_config.target_device_spec - ) - cmds.append(tool_path) - - cmds += [f"--module={module_path}"] + cmds = [tool_path, f"--module={module_path}"] cmds += run_config.materialize_run_flags( gpu_id=self.gpu_id, inputs_dir=inputs_dir, ) - + cpu_params = run_config.target_device_spec.device_parameters.cpu_params + if cpu_params: + raise ValueError("CPU pinning is not supported yet.") return cmds def __fetch_and_unpack_npy(self, uri: str, dest_dir: pathlib.Path) -> pathlib.Path: diff --git a/build_tools/python/benchmark_suites/iree/armv8_a_benchmarks.py b/build_tools/python/benchmark_suites/iree/armv8_a_benchmarks.py index ff488d91172d..32aab35d779d 100644 --- a/build_tools/python/benchmark_suites/iree/armv8_a_benchmarks.py +++ b/build_tools/python/benchmark_suites/iree/armv8_a_benchmarks.py @@ -69,7 +69,7 @@ def generate( module_execution_configs.get_elf_system_scheduling_local_task_config( thread_num ) - for thread_num in [1, 4] + for thread_num in [1, 2] ] default_gen_confings = [ @@ -97,7 +97,7 @@ def generate( device_collections.DEFAULT_DEVICE_COLLECTION.query_device_specs( architecture=common_definitions.DeviceArchitecture.ARMV8_2_A_GENERIC, host_environment=common_definitions.HostEnvironment.ANDROID_ARMV8_2_A, - device_parameters={"big-cores"}, + tags=["big-cores"], ) ) run_configs = utils.generate_e2e_model_run_configs( diff --git a/build_tools/python/benchmark_suites/iree/vmvx_benchmarks.py b/build_tools/python/benchmark_suites/iree/vmvx_benchmarks.py index 80e20c831f3f..6638b80e79e7 100644 --- a/build_tools/python/benchmark_suites/iree/vmvx_benchmarks.py +++ b/build_tools/python/benchmark_suites/iree/vmvx_benchmarks.py @@ -42,14 +42,14 @@ def generate( ] default_execution_configs = [ module_execution_configs.get_vmvx_system_scheduling_local_task_config( - thread_num=4 + thread_num=2 ) ] big_cores_devices = ( device_collections.DEFAULT_DEVICE_COLLECTION.query_device_specs( architecture=common_definitions.DeviceArchitecture.ARMV8_2_A_GENERIC, host_environment=common_definitions.HostEnvironment.ANDROID_ARMV8_2_A, - device_parameters={"big-cores"}, + tags=["big-cores"], ) ) run_configs = utils.generate_e2e_model_run_configs( diff --git a/build_tools/python/e2e_model_tests/CMakeLists.txt b/build_tools/python/e2e_model_tests/CMakeLists.txt deleted file mode 100644 index 3ce60ed898f2..000000000000 --- a/build_tools/python/e2e_model_tests/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -# Copyright 2022 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 - -iree_build_tools_py_test( - NAME - run_module_utils_test - SRC - "run_module_utils_test.py" -) diff --git a/build_tools/python/e2e_model_tests/run_module_utils.py b/build_tools/python/e2e_model_tests/run_module_utils.py deleted file mode 100644 index eac9ad39c31c..000000000000 --- a/build_tools/python/e2e_model_tests/run_module_utils.py +++ /dev/null @@ -1,28 +0,0 @@ -## Copyright 2022 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 -"""Utils that help launch iree run module tools.""" - -from typing import List - -from e2e_test_framework.definitions import common_definitions -from e2e_test_framework.device_specs import device_parameters - - -def build_linux_wrapper_cmds_for_device_spec( - device_spec: common_definitions.DeviceSpec, -) -> List[str]: - """Builds the commands with tools to create the execution environment.""" - - affinity_mask = None - for param in device_spec.device_parameters: - if param != device_parameters.ALL_CORES: - raise ValueError(f"Unsupported device parameter: {param}.") - - cmds = [] - if affinity_mask is not None: - cmds += ["taskset", affinity_mask] - - return cmds diff --git a/build_tools/python/e2e_model_tests/run_module_utils_test.py b/build_tools/python/e2e_model_tests/run_module_utils_test.py deleted file mode 100644 index f86ddacdab1b..000000000000 --- a/build_tools/python/e2e_model_tests/run_module_utils_test.py +++ /dev/null @@ -1,31 +0,0 @@ -## Copyright 2022 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 - -import unittest - -from e2e_model_tests import run_module_utils -from e2e_test_framework.definitions import common_definitions -from e2e_test_framework.device_specs import device_parameters - - -class RunModuleUtilsTest(unittest.TestCase): - def test_build_linux_wrapper_cmds_for_device_spec(self): - device_spec = common_definitions.DeviceSpec.build( - id="abc", - device_name="test-device", - architecture=common_definitions.DeviceArchitecture.VMVX_GENERIC, - host_environment=common_definitions.HostEnvironment.LINUX_X86_64, - device_parameters=[device_parameters.ALL_CORES], - tags=[], - ) - - flags = run_module_utils.build_linux_wrapper_cmds_for_device_spec(device_spec) - - self.assertEqual(flags, []) - - -if __name__ == "__main__": - unittest.main() diff --git a/build_tools/python/e2e_test_framework/definitions/common_definitions.py b/build_tools/python/e2e_test_framework/definitions/common_definitions.py index 1a6a4a3418aa..6ffd7667364c 100644 --- a/build_tools/python/e2e_test_framework/definitions/common_definitions.py +++ b/build_tools/python/e2e_test_framework/definitions/common_definitions.py @@ -109,6 +109,23 @@ class ModelSourceType(Enum): EXPORTED_TFLITE = "exported_tflite" +@serialization.serializable +@dataclass(frozen=True) +class CPUParameters: + """Describes CPU related parameters.""" + + # CPU cores to pin at, ordered from the slowest to the fastest. + pinned_cores: List[int] + + +@serialization.serializable +@dataclass(frozen=True) +class DeviceParameters: + """Describes device parameters.""" + + cpu_params: Optional[CPUParameters] = None + + @serialization.serializable(type_key="device_specs") @dataclass(frozen=True) class DeviceSpec(object): @@ -138,7 +155,7 @@ class DeviceSpec(object): # This is for modeling the spec of a heterogeneous processor. Depending on # which cores you run, the device has a different spec. Benchmark machines use # these parameters to set up the devices. E.g. set CPU mask. - device_parameters: List[str] = dataclasses.field(default_factory=list) + device_parameters: DeviceParameters def __str__(self): return self.name @@ -150,7 +167,7 @@ def build( device_name: str, host_environment: HostEnvironment, architecture: DeviceArchitecture, - device_parameters: Sequence[str] = (), + device_parameters: DeviceParameters = DeviceParameters(), tags: Sequence[str] = (), ): tag_part = ",".join(tags) @@ -163,7 +180,7 @@ def build( device_name=device_name, host_environment=host_environment, architecture=architecture, - device_parameters=list(device_parameters), + device_parameters=device_parameters, ) diff --git a/build_tools/python/e2e_test_framework/device_specs/device_collections.py b/build_tools/python/e2e_test_framework/device_specs/device_collections.py index 9031cea23b93..a04efcbf1b25 100644 --- a/build_tools/python/e2e_test_framework/device_specs/device_collections.py +++ b/build_tools/python/e2e_test_framework/device_specs/device_collections.py @@ -10,7 +10,6 @@ from e2e_test_framework.device_specs import ( gcp_specs, moto_edge_x30_specs, - pixel_4_specs, pixel_6_pro_specs, riscv_specs, ) @@ -26,25 +25,26 @@ def query_device_specs( self, architecture: common_definitions.DeviceArchitecture, host_environment: common_definitions.HostEnvironment, - device_parameters: Set[str] = set(), + tags: Sequence[str] = (), ) -> List[common_definitions.DeviceSpec]: """Query the device specs. Args: architecture: device architecture to match. platform: device platform to match. - device_parameters: parameters that devices need to have. + tags: tags that devices need to have. Returns: List of matched device specs. """ matched_device_specs = [] + tag_set = set(tags) for device_spec in self.device_specs: if device_spec.architecture != architecture: continue if device_spec.host_environment != host_environment: continue - if not device_parameters.issubset(device_spec.device_parameters): + if not tag_set.issubset(device_spec.tags): continue matched_device_specs.append(device_spec) @@ -53,7 +53,6 @@ def query_device_specs( ALL_DEVICE_SPECS = [ # Pixel 6 Pro - pixel_6_pro_specs.LITTLE_CORES, pixel_6_pro_specs.BIG_CORES, pixel_6_pro_specs.ALL_CORES, pixel_6_pro_specs.GPU, diff --git a/build_tools/python/e2e_test_framework/device_specs/device_collections_test.py b/build_tools/python/e2e_test_framework/device_specs/device_collections_test.py index f7154be6dc63..123c4461919b 100644 --- a/build_tools/python/e2e_test_framework/device_specs/device_collections_test.py +++ b/build_tools/python/e2e_test_framework/device_specs/device_collections_test.py @@ -30,16 +30,14 @@ def test_query_device_specs(self): device_name="c", architecture=common_definitions.DeviceArchitecture.ARMV9_A_GENERIC, host_environment=common_definitions.HostEnvironment.ANDROID_ARMV8_2_A, - device_parameters=["little-cores"], - tags=[], + tags=["little-cores"], ) big_cores_device_spec = common_definitions.DeviceSpec.build( id="android_big", device_name="d", architecture=common_definitions.DeviceArchitecture.ARMV9_A_GENERIC, host_environment=common_definitions.HostEnvironment.ANDROID_ARMV8_2_A, - device_parameters=["big-cores"], - tags=[], + tags=["big-cores"], ) devices = device_collections.DeviceCollection( device_specs=[ @@ -61,12 +59,12 @@ def test_query_device_specs(self): little_cores_devices = devices.query_device_specs( architecture=common_definitions.DeviceArchitecture.ARMV9_A_GENERIC, host_environment=common_definitions.HostEnvironment.ANDROID_ARMV8_2_A, - device_parameters={"little-cores"}, + tags=["little-cores"], ) big_cores_devices = devices.query_device_specs( architecture=common_definitions.DeviceArchitecture.ARMV9_A_GENERIC, host_environment=common_definitions.HostEnvironment.ANDROID_ARMV8_2_A, - device_parameters={"big-cores"}, + tags=["big-cores"], ) all_arm_devices = devices.query_device_specs( architecture=common_definitions.DeviceArchitecture.ARMV9_A_GENERIC, diff --git a/build_tools/python/e2e_test_framework/device_specs/device_parameters.py b/build_tools/python/e2e_test_framework/device_specs/device_parameters.py deleted file mode 100644 index 3bcfa91ff8ec..000000000000 --- a/build_tools/python/e2e_test_framework/device_specs/device_parameters.py +++ /dev/null @@ -1,10 +0,0 @@ -## Copyright 2022 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 -"""Defines the common device parameters.""" - -ARM_LITTLE_CORES = "little-cores" -ARM_BIG_CORES = "big-cores" -ALL_CORES = "all-cores" diff --git a/build_tools/python/e2e_test_framework/device_specs/gcp_specs.py b/build_tools/python/e2e_test_framework/device_specs/gcp_specs.py index 97ffb27b2e74..812b5343cd08 100644 --- a/build_tools/python/e2e_test_framework/device_specs/gcp_specs.py +++ b/build_tools/python/e2e_test_framework/device_specs/gcp_specs.py @@ -7,14 +7,12 @@ from e2e_test_framework import unique_ids from e2e_test_framework.definitions import common_definitions -from e2e_test_framework.device_specs import device_parameters GCP_C2_STANDARD_16 = common_definitions.DeviceSpec.build( id=unique_ids.DEVICE_SPEC_GCP_C2_STANDARD_16, device_name="c2-standard-16", host_environment=common_definitions.HostEnvironment.LINUX_X86_64, architecture=common_definitions.DeviceArchitecture.X86_64_CASCADELAKE, - device_parameters=[device_parameters.ALL_CORES], tags=["cpu"], ) @@ -23,7 +21,6 @@ device_name="c2-standard-60", host_environment=common_definitions.HostEnvironment.LINUX_X86_64, architecture=common_definitions.DeviceArchitecture.X86_64_CASCADELAKE, - device_parameters=[device_parameters.ALL_CORES], tags=["cpu"], ) diff --git a/build_tools/python/e2e_test_framework/device_specs/moto_edge_x30_specs.py b/build_tools/python/e2e_test_framework/device_specs/moto_edge_x30_specs.py index 4a1f2d1ccb7f..abb1e392a785 100644 --- a/build_tools/python/e2e_test_framework/device_specs/moto_edge_x30_specs.py +++ b/build_tools/python/e2e_test_framework/device_specs/moto_edge_x30_specs.py @@ -15,5 +15,9 @@ device_name=DEVICE_NAME, architecture=common_definitions.DeviceArchitecture.QUALCOMM_ADRENO, host_environment=common_definitions.HostEnvironment.ANDROID_ARMV8_2_A, + device_parameters=common_definitions.DeviceParameters( + # Pin on the fastest CPU core. + cpu_params=common_definitions.CPUParameters(pinned_cores=[7]) + ), tags=["gpu"], ) diff --git a/build_tools/python/e2e_test_framework/device_specs/pixel_4_specs.py b/build_tools/python/e2e_test_framework/device_specs/pixel_4_specs.py deleted file mode 100644 index 97596b4af568..000000000000 --- a/build_tools/python/e2e_test_framework/device_specs/pixel_4_specs.py +++ /dev/null @@ -1,37 +0,0 @@ -## Copyright 2022 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 -"""Defines device specs of Pixel 4.""" - -from e2e_test_framework import unique_ids -from e2e_test_framework.definitions import common_definitions -from e2e_test_framework.device_specs import device_parameters - -DEVICE_NAME = "pixel-4" - -BIG_CORES = common_definitions.DeviceSpec.build( - id=unique_ids.DEVICE_SPEC_MOBILE_PIXEL_4 + "-big-core", - device_name=DEVICE_NAME, - architecture=common_definitions.DeviceArchitecture.ARMV8_2_A_GENERIC, - host_environment=common_definitions.HostEnvironment.ANDROID_ARMV8_2_A, - device_parameters=[device_parameters.ARM_BIG_CORES], - tags=["big-core"], -) -LITTLE_CORES = common_definitions.DeviceSpec.build( - id=unique_ids.DEVICE_SPEC_MOBILE_PIXEL_4 + "-little-core", - device_name=DEVICE_NAME, - architecture=common_definitions.DeviceArchitecture.ARMV8_2_A_GENERIC, - host_environment=common_definitions.HostEnvironment.ANDROID_ARMV8_2_A, - device_parameters=[device_parameters.ARM_LITTLE_CORES], - tags=["little-core"], -) -ALL_CORES = common_definitions.DeviceSpec.build( - id=unique_ids.DEVICE_SPEC_MOBILE_PIXEL_4 + "-all-core", - device_name=DEVICE_NAME, - architecture=common_definitions.DeviceArchitecture.ARMV8_2_A_GENERIC, - host_environment=common_definitions.HostEnvironment.ANDROID_ARMV8_2_A, - device_parameters=[device_parameters.ALL_CORES], - tags=["all-cores"], -) diff --git a/build_tools/python/e2e_test_framework/device_specs/pixel_6_pro_specs.py b/build_tools/python/e2e_test_framework/device_specs/pixel_6_pro_specs.py index 3b84faed4af1..4eaef97daad6 100644 --- a/build_tools/python/e2e_test_framework/device_specs/pixel_6_pro_specs.py +++ b/build_tools/python/e2e_test_framework/device_specs/pixel_6_pro_specs.py @@ -7,7 +7,6 @@ from e2e_test_framework import unique_ids from e2e_test_framework.definitions import common_definitions -from e2e_test_framework.device_specs import device_parameters DEVICE_NAME = "pixel-6-pro" @@ -16,23 +15,17 @@ device_name=DEVICE_NAME, architecture=common_definitions.DeviceArchitecture.ARMV8_2_A_GENERIC, host_environment=common_definitions.HostEnvironment.ANDROID_ARMV8_2_A, - device_parameters=[device_parameters.ARM_BIG_CORES], - tags=["big-core"], -) -LITTLE_CORES = common_definitions.DeviceSpec.build( - id=unique_ids.DEVICE_SPEC_MOBILE_PIXEL_6_PRO + "-little-core", - device_name=DEVICE_NAME, - architecture=common_definitions.DeviceArchitecture.ARMV8_2_A_GENERIC, - host_environment=common_definitions.HostEnvironment.ANDROID_ARMV8_2_A, - device_parameters=[device_parameters.ARM_LITTLE_CORES], - tags=["little-core"], + device_parameters=common_definitions.DeviceParameters( + # Cortex-X1 + cpu_params=common_definitions.CPUParameters(pinned_cores=[6, 7]) + ), + tags=["big-cores"], ) ALL_CORES = common_definitions.DeviceSpec.build( id=unique_ids.DEVICE_SPEC_MOBILE_PIXEL_6_PRO + "-all-core", device_name=DEVICE_NAME, architecture=common_definitions.DeviceArchitecture.ARMV8_2_A_GENERIC, host_environment=common_definitions.HostEnvironment.ANDROID_ARMV8_2_A, - device_parameters=[device_parameters.ALL_CORES], tags=["all-cores"], ) GPU = common_definitions.DeviceSpec.build( @@ -40,5 +33,9 @@ device_name=DEVICE_NAME, architecture=common_definitions.DeviceArchitecture.ARM_VALHALL, host_environment=common_definitions.HostEnvironment.ANDROID_ARMV8_2_A, + device_parameters=common_definitions.DeviceParameters( + # Pin on the fastest CPU core. + cpu_params=common_definitions.CPUParameters(pinned_cores=[7]) + ), tags=["gpu"], ) diff --git a/build_tools/python/e2e_test_framework/device_specs/riscv_specs.py b/build_tools/python/e2e_test_framework/device_specs/riscv_specs.py index 78fc75aaa67f..5c8bbc5705b2 100644 --- a/build_tools/python/e2e_test_framework/device_specs/riscv_specs.py +++ b/build_tools/python/e2e_test_framework/device_specs/riscv_specs.py @@ -7,7 +7,6 @@ from e2e_test_framework import unique_ids from e2e_test_framework.definitions import common_definitions -from e2e_test_framework.device_specs import device_parameters EMULATOR_RISCV_64 = common_definitions.DeviceSpec.build( @@ -15,7 +14,6 @@ device_name="emulator-riscv_64", host_environment=common_definitions.HostEnvironment.LINUX_RISCV_64, architecture=common_definitions.DeviceArchitecture.RV64_GENERIC, - device_parameters=[device_parameters.ALL_CORES], tags=["cpu"], ) @@ -24,6 +22,5 @@ device_name="emulator-riscv_32", host_environment=common_definitions.HostEnvironment.LINUX_RISCV_32, architecture=common_definitions.DeviceArchitecture.RV32_GENERIC, - device_parameters=[device_parameters.ALL_CORES], tags=["cpu"], ) diff --git a/build_tools/python/e2e_test_framework/serialization.py b/build_tools/python/e2e_test_framework/serialization.py index 5cd3d358f583..b62078e11b03 100644 --- a/build_tools/python/e2e_test_framework/serialization.py +++ b/build_tools/python/e2e_test_framework/serialization.py @@ -133,6 +133,8 @@ def _deserialize( subtypes = typing.get_args(obj_type) if len(subtypes) != 2 or NONE_TYPE not in subtypes: raise ValueError(f"Unsupported union type: {obj_type}.") + if data is None: + return None subtype = subtypes[0] if subtypes[1] == NONE_TYPE else subtypes[1] return _deserialize(data, subtype, keyed_obj_map, obj_cache) diff --git a/build_tools/python/e2e_test_framework/serialization_test.py b/build_tools/python/e2e_test_framework/serialization_test.py index e4fcca41fb00..ba687b267d7b 100644 --- a/build_tools/python/e2e_test_framework/serialization_test.py +++ b/build_tools/python/e2e_test_framework/serialization_test.py @@ -41,6 +41,7 @@ class TestA(object): c_obj: TestC str_val: Optional[str] enum_val: EnumX + optional_val: Optional[TestB] @serialization.serializable @@ -66,12 +67,14 @@ def test_serialize_and_pack(self): c_obj=TestC(float_val=0.1), str_val="test1", enum_val=EnumX.OPTION_B, + optional_val=None, ), TestA( b_list=[b_obj_a], c_obj=TestC(float_val=0.2), str_val=None, enum_val=EnumX.OPTION_C, + optional_val=b_obj_b, ), ] @@ -91,12 +94,14 @@ def test_serialize_and_pack(self): c_obj=dict(float_val=0.1), str_val="test1", enum_val="OPTION_B", + optional_val=None, ), dict( b_list=["id_a"], c_obj=dict(float_val=0.2), str_val=None, enum_val="OPTION_C", + optional_val="id_b", ), ], "obj_map": { @@ -135,18 +140,21 @@ def test_roundtrip(self): c_obj=TestC(float_val=0.1), str_val="test1", enum_val=EnumX.OPTION_B, + optional_val=None, ), TestA( b_list=[b_obj_a], c_obj=TestC(float_val=0.2), str_val=None, enum_val=EnumX.OPTION_C, + optional_val=None, ), TestA( b_list=[b_obj_b], c_obj=TestC(float_val=0.3), str_val="test3", enum_val=EnumX.OPTION_A, + optional_val=b_obj_a, ), ]