diff --git a/src/python/SConscript b/src/python/SConscript index 7f7f5ad113..dd67610425 100644 --- a/src/python/SConscript +++ b/src/python/SConscript @@ -53,6 +53,8 @@ PySource('gem5.components.boards', 'gem5/components/boards/x86_board.py') PySource('gem5.components.boards', 'gem5/components/boards/arm_board.py') PySource('gem5.components.boards', "gem5/components/boards/kernel_disk_workload.py") +PySource('gem5.components.boards', + "gem5/components/boards/gpu_fs_workload.py") PySource('gem5.components.boards', "gem5/components/boards/se_binary_workload.py") PySource('gem5.components.cachehierarchies', diff --git a/src/python/gem5/components/boards/gpu_fs_workload.py b/src/python/gem5/components/boards/gpu_fs_workload.py new file mode 100644 index 0000000000..d0648f2835 --- /dev/null +++ b/src/python/gem5/components/boards/gpu_fs_workload.py @@ -0,0 +1,85 @@ +import os +from abc import abstractmethod +from pathlib import Path +from typing import ( + List, + Optional, + Union, +) + +import m5 +from m5.util import warn + +from ...resources.resource import ( + BootloaderResource, + CheckpointResource, + DiskImageResource, + KernelResource, +) +from .kernel_disk_workload import KernelDiskWorkload +from ...devices.gpus.amdgpu import BaseViperGPU + +class GpuFsWorkload(KernelDiskWorkload): + + @abstractmethod + def set_app_gpu(self, app_gpu: Optional['BaseViperGPU']) -> None: + """ + Set the GPU device to be used by the application. + """ + raise NotImplementedError + + @abstractmethod + def get_app_gpu(self) -> Optional['BaseViperGPU']: + """ + Get the GPU device to be used by the application. + """ + raise NotImplementedError + + def set_gpu_fs_workload( + self, + binary: BinaryResource, + debug: Optional[bool] = False, + kernel: Optional[KernelResource] = None, + disk_image: Optional[DiskImageResource] = None, + bootloader: Optional = None, + disk_device: Optional[str] = None, + readfile: Optional[str] = None, + kernel_args: Optional[List[str]] = None, + exit_on_work_items: bool = True, + checkpoint: Optional[Union[Path, str]] = None, + ) -> None: + """ + Set the GPU application to be run. + """ + app_gpu = self.get_app_gpu() + readfile_contents = None + + if app_gpu is None: + warn("No GPU device set for the application. GPU device is required.") + else: + driver_load_command = self.get_app_gpu().get_driver_load_command(debug=debug) + + binary_path = binary.get_local_path() + with open(binary_path, "rb") as binfile: + encodedBin = base64.b64encode(binfile.read()).decode() + + application_command = ( + f'echo "{encodedBin}" | base64 -d > myapp\n' + "chmod +x myapp\n" + "./myapp {}\n" + "/sbin/m5 exit\n" + ) + + readfile_contents = driver_load_command + application_command + + self.set_kernel_disk_workload( + kernel=kernel, + disk_image=disk_image, + bootloader=bootloader, + disk_device=disk_device, + readfile=readfile, + readfile_contents=readfile_contents, + kernel_args=kernel_args, + exit_on_work_items=exit_on_work_items, + checkpoint=checkpoint, + ) diff --git a/src/python/gem5/prebuilt/viper/board.py b/src/python/gem5/prebuilt/viper/board.py index a7958016ac..9c5ca6eca8 100644 --- a/src/python/gem5/prebuilt/viper/board.py +++ b/src/python/gem5/prebuilt/viper/board.py @@ -37,7 +37,7 @@ from m5.util import warn from ...components.boards.abstract_board import AbstractBoard -from ...components.boards.kernel_disk_workload import KernelDiskWorkload +from ...components.boards.gpu_fs_workload import GpuFsWorkload from ...components.boards.x86_board import X86Board from ...components.cachehierarchies.abstract_cache_hierarchy import ( AbstractCacheHierarchy, @@ -48,7 +48,7 @@ from ...utils.override import overrides -class ViperBoard(X86Board): +class ViperBoard(X86Board, GpuFsWorkload): """ A derivative of X86Board capable of full system simulation for X86 with a GPU device. Provides all the functionality of the X86Board with helper @@ -148,21 +148,16 @@ def get_default_kernel_args(self) -> List[str]: "modprobe.blacklist=amdgpu", "modprobe.blacklist=psmouse", ] - - # Replicate the capability of the old GPUFS config, which embed a binary - # application or script into a bash script setting up the environment and - # loading the GPU driver. - def make_gpu_app(self, gpu: BaseViperGPU, app: str, debug: bool = False): - driver_load_command = gpu.get_driver_command(debug=debug) - - with open(os.path.abspath(app), "rb") as binfile: - encodedBin = base64.b64encode(binfile.read()).decode() - - application_command = ( - f'echo "{encodedBin}" | base64 -d > myapp\n' - "chmod +x myapp\n" - "./myapp {}\n" - "/sbin/m5 exit\n" - ) - - return driver_load_command + application_command + @overrides(GpuFsWorkload) + def set_app_gpu(self, app_gpu: Optional[BaseViperGPU]) -> None: + if self._gpus is None and app_gpu is None: + warn("No GPU device has been set") + return + if app_gpu is not None: + self._app_gpu = app_gpu + else: + self._app_gpu = self._gpus[0] + + @overrides(GpuFsWorkload) + def get_app_gpu(self) -> Optional[BaseViperGPU]: + return self._app_gpu