stdlib, resources: Added warn msgs and commets.

- Added deprecated warnings to Workload and Abstract workload.

- Added comments to the classes changed.

Change-Id: I671daacf5ef455ea65103bd96aa442486142a486
This commit is contained in:
Harshil Patel
2023-08-23 13:50:08 -07:00
parent a18b4b17ed
commit 328d140c70
3 changed files with 23 additions and 90 deletions

View File

@@ -43,7 +43,6 @@ from gem5.utils.requires import requires
from gem5.isas import ISA
from gem5.simulate.simulator import Simulator
from gem5.resources.workload import Workload
from gem5.resources.resource import obtain_resource
import argparse
@@ -77,7 +76,7 @@ board = RISCVMatchedBoard(
# In the case where the `-i` flag is passed, we add the kernel argument
# `init=/root/exit.sh`. This means the simulation will exit after the Linux
# Kernel has booted.
workload = obtain_resource("riscv-ubuntu-20.04-boot")
workload = Workload("riscv-ubuntu-20.04-boot")
kernel_args = board.get_default_kernel_args()
if args.to_init:
kernel_args.append("init=/root/exit.sh")

View File

@@ -586,7 +586,6 @@ class WorkloadResource(AbstractResource):
self._func = function
self._params = parameters if parameters else {}
print(resources)
for key in resources.keys():
assert isinstance(key, str)
value = resources[key]
@@ -715,7 +714,6 @@ def obtain_resource(
# Obtain the type from the JSON. From this we will determine what subclass
# of `AbstractResource` we are to create and return.
resources_category = resource_json["category"]
print(resource_json)
if resources_category == "resource":
# This is a stop-gap measure to ensure to work with older versions of
# the "resource.json" file. These should be replaced with their

View File

@@ -28,59 +28,27 @@ from .resource import obtain_resource, WorkloadResource
from .client import get_resource_json_obj
from _m5 import core
from m5.util import warn
from typing import Dict, Any, List, Optional
"""
A workload specified locally (i.e., not via gem5-resources as with the
`Workload` class). Here the user specifies the function and the parameters
to be passed.
Usage
-----
def CustomWorkload(function: str, parameters: Dict[str, Any]):
"""
A custom workload gem5 resource. It can be used to specify a custom,
local workload.
```py
workload = CustomWorkload(
function = "set_se_binary_workload",
parameters = {
"binary" : obtain_resource("x86-print-this"),
"arguments" : ["hello", 6]
},
**Warning**: This class is deprecated and changed to a funtion and will be removed in future
releases of gem5. Please use the `WorkloadResource` class instead. This
class is merely a wrapper for it.
"""
warn(
"The `CustomWorkload` class is deprecated. Please use "
"`WorkloadResource` instead."
)
board.set_workload(workload)
```
"""
def CustomWorkload(function: str, parameters: Dict[str, Any]) -> None:
return WorkloadResource(function=function, parameters=parameters)
"""
The `Workload` class loads a workload's information from gem5-resources
based on a name/id passed via the constructor.
Usage
-----
```py
# Determine what workload we want to run.
workload = Workload("example-workload-id")
# Optionally we can override a parameter in the workload. In this example
# we are going to run this workload with a difference kernel.
workload.set_parameter("kernel",
obtain_resource("arm64-linux-kernel-4.14.134")
)
# We then set this workload to the board.
board.set_workload(workload)
```
"""
def Workload(
workload_name: str,
resource_directory: Optional[str] = None,
@@ -89,50 +57,18 @@ def Workload(
gem5_version: Optional[str] = core.gem5Version,
):
"""
This constructor will load the workload details from the workload with
the given name/id.
This function was created to maintain backwards compability for v23.0.0
and prior releases of gem5 where `Workload` was a class.
This function assumes the dictionary returned by the downloader's
`get_workload_json_obj` is a dictionary. An example of the schema is
shown below:
```json
{
"category" : "workload",
"id" : "x86-ubuntu-18.04-echo-hello",
"description" : "Description of workload here",
"function" : "set_kernel_disk_workload",
"resources" : {
"kernel" : "x86-linux-kernel-5.4.49",
"disk-image" : "x86-ubuntu-18.04-img"
},
"additional_params" : {
"readfile_contents" : "m5_exit; echo 'hello'; m5_exit"
}
}
```
This resource will result in the equivalent of the following action
being taken:
```python
board.set_kernel_disk_workload(
kernel = obtain_resource("x86-linux-kernel-5.4.49"),
disk-image = obtain_resource("x86-ubuntu-18.04-img"),
readfile_contents = "m5_exit; echo 'hello'; m5_exit",
)
```
:param workload_name: The name of the workload in the resources.json
file to be loaded.
:param resource_directory: An optional parameter that specifies where
any resources should be download and accessed from. If None, a default
location will be used. None by default.
:param gem5_version: The gem5 version for the Workload to be loaded.
By default, the current gem5 version is used. This will filter
resources which are incompatible with the current gem5 version. If
None, no filtering will be done.
In the interests of gem5-resource specialization, the `Workload` class
has been dropped. Instead users are advized to use the `obtain_resource`
function which will return the correct `AbstractResource` implementation.
This function (disguised as a class) wraps this function.
"""
warn(
"`Workload` has been deprecated. Please use the `obtain_resource` "
"function instead."
)
return obtain_resource(
workload_name,
resource_directory=resource_directory,