Skip to content

Commit

Permalink
Update/fix materials
Browse files Browse the repository at this point in the history
These fixes are incorporated from doing a first-pass of the tutorial.
Minor fixes and improvements.
  • Loading branch information
BobbyRBruce committed Feb 24, 2023
1 parent 4e9bb63 commit e7a77f9
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 24 deletions.
9 changes: 5 additions & 4 deletions materials/complete/hello-world.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
from gem5.components.boards.simple_board import SimpleBoard
from gem5.components.cachehierarchies.classic.no_cache import NoCache
from gem5.components.memory.single_channel import SingleChannelDDR_1600
from gem5.components.memory import SingleChannelDDR3_1600
from gem5.components.processors.simple_processor import SimpleProcessor
from gem5.components.processors.cpu_types import CPUTypes
from gem5.resources.resource import obtain_resource
from gem5.simulate.simulator import Simulator
from gem5.isas import ISA

# Obtain the components.
cache_hierarchy = NoCache
memory = SingleChannelDDR_1600("1GiB")
processor = SimpleProcessor(cpu_type=CPUTypes.Atomic, num_cores=1)
cache_hierarchy = NoCache()
memory = SingleChannelDDR3_1600("1GiB")
processor = SimpleProcessor(cpu_type=CPUTypes.ATOMIC, num_cores=1, isa=ISA.X86)

# Add them to the board.
board = SimpleBoard(
Expand Down
14 changes: 9 additions & 5 deletions materials/complete/traffic-generator-hbm2stack.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
from gem5.components.boards.test_board import TestBoard
from gem5.components.memory import HBM2Stack
from gem5.components.processors.random_generator import RandomGenerator
from gem5.components.boards.test_board import TestBoard
from gem5.components.processors.random_generator import RandomGenerator
from gem5.components.cachehierarchies.classic.no_cache import NoCache

import m5
from m5.objects import Root

# Obtain the compinents
mem_size = "1GiB"
memory = HBM2Stack(mem_size)
# Setup the components.
memory = HBM2Stack("1GiB")
generator = RandomGenerator(
duration="250us",
rate="40GB/s",
num_cores=1,
max_addr=mem_size,
max_addr=memory.get_size(),
)
cache_hierarchy = NoCache()

# Add them to the Test board.
board = TestBoard(
clk_freq="3GHz",
generator=generator,
memory=memory,
cache_hierarchy=cache_hierarchy,
)

# Setup the root and instantiate the simulation.
Expand All @@ -29,5 +33,5 @@
m5.instantiate()

# Start the traffic generator.
board.start_traffic()
generator.start_traffic()
exit_event = m5.simulate()
53 changes: 41 additions & 12 deletions materials/complete/x86-full-system-complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from gem5.coherence_protocol import CoherenceProtocol
from gem5.isas import ISA
from gem5.components.processors.cpu_types import CPUTypes
from gem5.resources.resource import Resource
from gem5.resources.workload import Workload
from gem5.simulate.simulator import Simulator
from gem5.simulate.exit_event import ExitEvent

Expand Down Expand Up @@ -48,6 +48,7 @@
starting_core_type=CPUTypes.TIMING,
switch_core_type=CPUTypes.O3,
num_cores=2,
isa=ISA.X86,
)

# Here we setup the board. The X86Board allows for Full-System X86 simulations.
Expand All @@ -71,19 +72,47 @@
+ "m5 exit;"
)

# Here we set the Full System workload.
# The `set_workload` function for the X86Board takes a kernel, a disk image,
# and, optionally, a the contents of the "readfile". In the case of the
# "x86-ubuntu-18.04-img", a file to be executed as a script after booting the
# system.
board.set_kernel_disk_workload(
kernel=Resource(
"x86-linux-kernel-5.4.49",
),
disk_image=Resource("x86-ubuntu-18.04-img"),
readfile_contents=command,
# Here we set the workload. If we look up
# http://resources.gem5.org/resources.json we can see the following entry for
# the workload "x86-ubuntu-18.04-boot":
# ```
# {
# "type" : "workload",
# "name" : "x86-ubuntu-18.04-boot",
# "documentation" : "A full boot of Ubuntu 18.04 with Linux 5.4.49 for
# X86. It runs an `m5 exit` command when the boot is
# completed unless the readfile is specified. If
# specified the readfile will be executed after
# booting.",
# "function": "set_kernel_disk_workload",
# "resources" : {
# "kernel" : "x86-linux-kernel-5.4.49",
# "disk_image":"x86-ubuntu-18.04-img"
# },
# "additional_params" : {}
# },
# ```
workload = Workload("x86-ubuntu-18.04-boot")

# We want to ammend this workload slightly to carry out a script when the OS
# boot is complete. The script immediately exits the simulation loop then,
# when re-entered, will print "This is running on Timing CPU cores." before
# sleeping for 1 simulated second then exiting the simulation loop again.
#
# We set this to the "readfile_contents" parameter. This parameter allows for
# the setting of the contents of the readfile. The readfile is executed by this
# resource when the OS is booted.
command = (
"m5 exit;"
+ "echo 'This is running on Timing CPU cores.';"
+ "sleep 1;"
+ "m5 exit;"
)

workload.set_parameter("readfile_contents", command)

board.set_workload(workload)

simulator = Simulator(
board=board,
on_exit_event={
Expand Down
5 changes: 3 additions & 2 deletions materials/hello-world.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from gem5.components.boards.simple_board import SimpleBoard
from gem5.components.cachehierarchies.classic.no_cache import NoCache
from gem5.components.memory.single_channel import SingleChannelDDR3_1600
from gem5.components.memory import SingleChannelDDR3_1600
from gem5.components.processors.simple_processor import SimpleProcessor
from gem5.components.processors.cpu_types import CPUTypes
from gem5.resources.resource import Resource
from gem5.resources.resource import obtain_resource
from gem5.simulate.simulator import Simulator
from gem5.isas import ISA
2 changes: 1 addition & 1 deletion materials/x86-full-system.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
from gem5.coherence_protocol import CoherenceProtocol
from gem5.isas import ISA
from gem5.components.processors.cpu_types import CPUTypes
from gem5.resources.resource import Resource
from gem5.resources.workload import Workload
from gem5.simulate.simulator import Simulator
from gem5.simulate.exit_event import ExitEvent

0 comments on commit e7a77f9

Please sign in to comment.