From d5dfe03eb17e2a6313bcf6cd78670ea5a864102e Mon Sep 17 00:00:00 2001 From: "Erin (Jianghua) Le" Date: Tue, 1 Oct 2024 11:22:07 -0700 Subject: [PATCH] stdlib: Add warning message for set_workload being called twice (#1571) This commit adds a warning message for when set_workload is called twice, as users typically do not mean to do this. --- src/python/gem5/components/boards/abstract_board.py | 7 +++++++ src/python/gem5/components/boards/kernel_disk_workload.py | 5 +++++ src/python/gem5/components/boards/se_binary_workload.py | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/src/python/gem5/components/boards/abstract_board.py b/src/python/gem5/components/boards/abstract_board.py index d3c01e21f8..83ca32d9c0 100644 --- a/src/python/gem5/components/boards/abstract_board.py +++ b/src/python/gem5/components/boards/abstract_board.py @@ -110,6 +110,7 @@ class AbstractBoard: # is defined. Whether or not the board is to be run in FS mode is # determined by which kind of workload is set. self._is_fs = None + self._is_workload_set = False # This variable is used to record the checkpoint directory which is # set when declaring the board's workload and then used by the @@ -211,6 +212,12 @@ class AbstractBoard: ) return self._is_fs + def set_is_workload_set(self, is_set: bool) -> None: + self._is_workload_set = is_set + + def is_workload_set(self) -> bool: + return self._is_workload_set + def set_workload(self, workload: WorkloadResource) -> None: """ Set the workload for this board to run. diff --git a/src/python/gem5/components/boards/kernel_disk_workload.py b/src/python/gem5/components/boards/kernel_disk_workload.py index 27651ee082..181219a5cd 100644 --- a/src/python/gem5/components/boards/kernel_disk_workload.py +++ b/src/python/gem5/components/boards/kernel_disk_workload.py @@ -34,6 +34,7 @@ from typing import ( ) import m5 +from m5.util import warn from ...resources.resource import ( BootloaderResource, @@ -180,6 +181,10 @@ class KernelDiskWorkload: # Abstract board. This function will not work otherwise. assert isinstance(self, AbstractBoard) + if self.is_workload_set(): + warn("Workload has been set more than once!") + self.set_is_workload_set(True) + # Set the disk device self._disk_device = disk_device diff --git a/src/python/gem5/components/boards/se_binary_workload.py b/src/python/gem5/components/boards/se_binary_workload.py index 6f993f4d22..08c4518ded 100644 --- a/src/python/gem5/components/boards/se_binary_workload.py +++ b/src/python/gem5/components/boards/se_binary_workload.py @@ -101,6 +101,10 @@ class SEBinaryWorkload: # Abstract board. This function will not work otherwise. assert isinstance(self, AbstractBoard) + if self.is_workload_set(): + warn("Workload has been set more than once!") + self.set_is_workload_set(True) + # If we are setting a workload of this type, we need to run as a # SE-mode simulation. self._set_fullsystem(False)