Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resources: Add set_gpu_fs_workload function #278

Open
wants to merge 1 commit into
base: gpu-stdlib
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/python/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
85 changes: 85 additions & 0 deletions src/python/gem5/components/boards/gpu_fs_workload.py
Original file line number Diff line number Diff line change
@@ -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,
)
35 changes: 15 additions & 20 deletions src/python/gem5/prebuilt/viper/board.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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