Files
gem5/configs/example/ruby_gpu_random_test.py
Matthew Poremba 4f7b3ed827 mem-ruby: Remove static methods from RubySystem (#1453)
There are several parts to this PR to work towards #1349 .

(1) Make RubySystem::getBlockSizeBytes non-static by providing ways to
access the block size or passing the block size explicitly to classes.

The main changes are:
 - DataBlocks must be explicitly allocated. A default ctor still exists
   to avoid needing to heavily modify SLICC. The size can be set using a
   realloc function, operator=, or copy ctor. This is handled completely
   transparently meaning no protocol or config changes are required.
 - WriteMask now requires block size to be set. This is also handled
   transparently by modifying the SLICC parser to identify WriteMask
   types and call setBlockSize().
 - AbstractCacheEntry and TBE classes now require block size to be set.
   This is handled transparently by modifying the SLICC parser to
   identify these classes and call initBlockSize() which calls
   setBlockSize() for any DataBlock or WriteMask.
 - All AbstractControllers now have a pointer to RubySystem. This is
   assigned in SLICC generated code and requires no changes to protocol
   or configs.
 - The Ruby Message class now requires block size in all constructors.
   This is added to the argument list automatically by the SLICC parser.
   
(2) Relax dependence on common functions in
src/mem/ruby/common/Address.hh
so that RubySystem::getBlockSizeBits is no longer static. Many classes
already have a way to get block size from the previous commit, so they
simply multiple by 8 to get the number of bits. For handling SLICC and
reducing the number of changes, define makeCacheLine, getOffset, etc. in
RubyPort and AbstractController. The only protocol changes required are
to change any "RubySystem::foo()" calls with "m_ruby_system->foo()".

For classes which do not have a way to get access to block size but
still used makeLineAddress, getOffset, etc., the block size must be
passed to that class. This requires some changes to the SimObject
interface for two commonly used classes: DirectoryMemory and
RubyPrefecther, resulting in user-facing API changes

User-facing API changes:
 - DirectoryMemory and RubyPrefetcher now require the cache line size as
   a non-optional argument.
 - RubySequencer SimObjects now require RubySystem as a non-optional
   argument.
 - TesterThread in the GPU ruby tester now requires the cache line size
   as a non-optional argument.

(3) Removes static member variables in RubySystem which control
randomization, cooldown, and warmup. These are mostly used by the Ruby
Network. The network classes are modified to take these former static
variables as parameters which are passed to the corresponding method
(e.g., enqueue, delayHead, etc.) rather than needing a RubySystem object
at all.

Change-Id: Ia63c2ad5cf0bf9d1cbdffba5d3a679bb4d3b1220

(4) There are two major SLICC generated static methods:
getNumControllers()
on each cache controller which returns the number of controllers created
by the configs at run time and the functions which access this method,
which are MachineType_base_count and MachineType_base_number. These need
to be removed to create multiple RubySystem objects otherwise NetDest,
version value, and other objects are incorrect.

To remove the static requirement, MachineType_base_count and
MachineType_base_number are moved to RubySystem. Any class which needs
to call these methods must now have a pointer to a RubySystem. To enable
that, several changes are made:
 - RubyRequest and Message now require a RubySystem pointer in the
   constructor. The pointer is passed to fields in the Message class
   which require a RubySystem pointer (e.g., NetDest). SLICC is modified
   to do this automatically.
 - SLICC structures may now optionally take an "implicit constructor"
   which can be used to call a non-default constructor for locally
   defined variables (e.g., temporary variables within SLICC actions). A
   statement such as "NetDest bcast_dest;" in SLICC will implicitly
   append a call to the NetDest constructor taking RubySystem, for
   example.
 - RubySystem gets passed to Ruby network objects (Network, Topology).
2024-10-08 08:14:50 -07:00

419 lines
12 KiB
Python

# Copyright (c) 2018-2021 Advanced Micro Devices, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
import argparse
import os
import sys
import m5
from m5.defines import buildEnv
from m5.objects import *
from m5.util import addToPath
addToPath("../")
from common import Options
from ruby import Ruby
#
# Add the ruby specific and protocol specific options
#
parser = argparse.ArgumentParser()
Options.addNoISAOptions(parser)
Ruby.define_options(parser)
# GPU Ruby tester options
parser.add_argument(
"--cache-size",
default="small",
choices=["small", "large"],
help="Cache sizes to use. Small encourages races between \
requests and writebacks. Large stresses write-through \
and/or write-back GPU caches.",
)
parser.add_argument(
"--system-size",
default="small",
choices=["small", "medium", "large"],
help="This option defines how many CUs, CPUs and cache \
components in the test system.",
)
parser.add_argument(
"--address-range",
default="small",
choices=["small", "large"],
help="This option defines the number of atomic \
locations that affects the working set's size. \
A small number of atomic locations encourage more \
races among threads. The large option stresses cache \
resources.",
)
parser.add_argument(
"--episode-length",
default="short",
choices=["short", "medium", "long"],
help="This option defines the number of LDs and \
STs in an episode. The small option encourages races \
between the start and end of an episode. The long \
option encourages races between LDs and STs in the \
same episode.",
)
parser.add_argument(
"--test-length",
type=int,
default=1,
help="The number of episodes to be executed by each \
wavefront. This determines the maximum number, i.e., \
val X #WFs, of episodes to be executed in the test.",
)
parser.add_argument(
"--debug-tester",
action="store_true",
help="This option will turn on DRF checker",
)
parser.add_argument(
"--random-seed",
type=int,
default=0,
help="Random seed number. Default value (i.e., 0) means \
using runtime-specific value",
)
parser.add_argument("--log-file", type=str, default="gpu-ruby-test.log")
parser.add_argument(
"--num-dmas",
type=int,
default=None,
help="The number of DMA engines to use in tester config.",
)
args = parser.parse_args()
#
# Set up cache size - 2 options
# 0: small cache
# 1: large cache
#
if args.cache_size == "small":
args.tcp_size = "256B"
args.tcp_assoc = 2
args.tcc_size = "1KiB"
args.tcc_assoc = 2
elif args.cache_size == "large":
args.tcp_size = "256KiB"
args.tcp_assoc = 16
args.tcc_size = "1024KiB"
args.tcc_assoc = 16
#
# Set up system size - 3 options
#
if args.system_size == "small":
# 1 CU, 1 CPU, 1 SQC, 1 Scalar
args.wf_size = 1
args.wavefronts_per_cu = 1
args.num_cpus = 1
n_DMAs = 1
args.cu_per_sqc = 1
args.cu_per_scalar_cache = 1
args.num_compute_units = 1
elif args.system_size == "medium":
# 4 CUs, 4 CPUs, 1 SQCs, 1 Scalars
args.wf_size = 16
args.wavefronts_per_cu = 4
args.num_cpus = 4
n_DMAs = 2
args.cu_per_sqc = 4
args.cu_per_scalar_cache = 4
args.num_compute_units = 4
elif args.system_size == "large":
# 8 CUs, 4 CPUs, 1 SQCs, 1 Scalars
args.wf_size = 32
args.wavefronts_per_cu = 4
args.num_cpus = 4
n_DMAs = 4
args.cu_per_sqc = 4
args.cu_per_scalar_cache = 4
args.num_compute_units = 8
# Number of DMA engines
if not (args.num_dmas is None):
n_DMAs = args.num_dmas
# currently the tester does not support requests returned as
# aliased, thus we need num_dmas to be 0 for it
if not (args.num_dmas == 0):
print("WARNING: num_dmas != 0 not supported with VIPER")
#
# Set address range - 2 options
# level 0: small
# level 1: large
# Each location corresponds to a 4-byte piece of data
#
args.mem_size = "1024MiB"
if args.address_range == "small":
num_atomic_locs = 10
num_regular_locs_per_atomic_loc = 10000
elif args.address_range == "large":
num_atomic_locs = 100
num_regular_locs_per_atomic_loc = 100000
#
# Set episode length (# of actions per episode) - 3 options
# 0: 10 actions
# 1: 100 actions
# 2: 500 actions
#
if args.episode_length == "short":
eps_length = 10
elif args.episode_length == "medium":
eps_length = 100
elif args.episode_length == "long":
eps_length = 500
#
# Set Ruby and tester deadlock thresholds. Ruby's deadlock detection is the
# primary check for deadlocks. The tester's deadlock threshold detection is
# a secondary check for deadlock. If there is a bug in RubyPort that causes
# a packet not to return to the tester properly, the tester will issue a
# deadlock panic. We set cache_deadlock_threshold < tester_deadlock_threshold
# to detect deadlock caused by Ruby protocol first before one caused by the
# coalescer. Both units are in Ticks
#
args.cache_deadlock_threshold = 1e8
tester_deadlock_threshold = 1e9
# For now we're testing only GPU protocol, so we force num_cpus to be 0
args.num_cpus = 0
# Number of CUs
n_CUs = args.num_compute_units
# Set test length, i.e., number of episodes per wavefront * #WFs.
# Test length can be 1x#WFs, 10x#WFs, 100x#WFs, ...
n_WFs = n_CUs * args.wavefronts_per_cu
max_episodes = args.test_length * n_WFs
# Number of SQC and Scalar caches
assert n_CUs % args.cu_per_sqc == 0
n_SQCs = n_CUs // args.cu_per_sqc
args.num_sqc = n_SQCs
assert args.cu_per_scalar_cache != 0
n_Scalars = n_CUs // args.cu_per_scalar_cache
args.num_scalar_cache = n_Scalars
#
# Create GPU Ruby random tester
#
tester = ProtocolTester(
cus_per_sqc=args.cu_per_sqc,
cus_per_scalar=args.cu_per_scalar_cache,
wavefronts_per_cu=args.wavefronts_per_cu,
workitems_per_wavefront=args.wf_size,
num_atomic_locations=num_atomic_locs,
num_normal_locs_per_atomic=num_regular_locs_per_atomic_loc,
max_num_episodes=max_episodes,
episode_length=eps_length,
debug_tester=args.debug_tester,
random_seed=args.random_seed,
log_file=args.log_file,
)
#
# Create a gem5 system. Note that the memory object isn't actually used by the
# tester, but is included to ensure the gem5 memory size == Ruby memory size
# checks. The system doesn't have real CPUs or CUs. It just has a tester that
# has physical ports to be connected to Ruby
#
system = System(
cpu=tester,
mem_ranges=[AddrRange(args.mem_size)],
cache_line_size=args.cacheline_size,
mem_mode="timing",
)
system.voltage_domain = VoltageDomain(voltage=args.sys_voltage)
system.clk_domain = SrcClockDomain(
clock=args.sys_clock, voltage_domain=system.voltage_domain
)
#
# Command processor is not needed for the tester since we don't run real
# kernels. Setting it to zero disables the VIPER protocol from creating
# a command processor and its caches.
#
args.num_cp = 0
#
# Make generic DMA sequencer for Ruby to use
#
if n_DMAs > 0:
dma_devices = [TesterDma()] * n_DMAs
system.piobus = IOXBar()
for _, dma_device in enumerate(dma_devices):
dma_device.pio = system.piobus.mem_side_ports
system.dma_devices = dma_devices
#
# Create the Ruby system
#
# the ruby tester reuses num_cpus to specify the
# number of cpu ports connected to the tester object, which
# is stored in system.cpu. because there is only ever one
# tester object, num_cpus is not necessarily equal to the
# size of system.cpu
cpu_list = [system.cpu] * args.num_cpus
Ruby.create_system(
args,
full_system=False,
system=system,
dma_ports=system.dma_devices if n_DMAs > 0 else [],
cpus=cpu_list,
)
#
# The tester is most effective when randomization is turned on and
# artifical delay is randomly inserted on messages
#
system.ruby.randomization = True
# Assert that we got the right number of Ruby ports
assert len(system.ruby._cpu_ports) == n_CUs + n_SQCs + n_Scalars
#
# Attach Ruby ports to the tester in the order:
# cpu_sequencers,
# vector_coalescers,
# sqc_sequencers,
# scalar_sequencers
#
# Note that this requires the protocol to create sequencers in this order
#
print("Attaching ruby ports to the tester")
for i, ruby_port in enumerate(system.ruby._cpu_ports):
ruby_port.no_retry_on_stall = True
ruby_port.using_ruby_tester = True
# piobus is only created if there are DMAs
if n_DMAs > 0:
ruby_port.mem_request_port = system.piobus.cpu_side_ports
if i < n_CUs:
tester.cu_vector_ports = ruby_port.in_ports
tester.cu_token_ports = ruby_port.gmTokenPort
tester.max_cu_tokens = 4 * n_WFs
elif i < (n_CUs + n_SQCs):
tester.cu_sqc_ports = ruby_port.in_ports
else:
tester.cu_scalar_ports = ruby_port.in_ports
i += 1
#
# Attach DMA ports. Since Ruby.py doesn't return these they need to be found.
# Connect tester's request port to each DMA sequencer's in_ports. This assumes
# the protocol names these system.dma_cntrl<#>.
#
dma_ports = []
for i in range(n_DMAs):
dma_cntrl = getattr(system, "dma_cntrl" + str(i))
dma_ports.append(dma_cntrl.dma_sequencer.in_ports)
tester.dma_ports = dma_ports
#
# Common variables for all types of threads
#
thread_clock = SrcClockDomain(
clock="1GHz", voltage_domain=system.voltage_domain
)
g_thread_idx = 0
#
# No CPU threads are used for GPU tester
#
tester.cpu_threads = []
#
# Create DMA threads
#
dma_threads = []
print("Creating %i DMAs" % n_DMAs)
for dma_idx in range(n_DMAs):
dma_threads.append(
DmaThread(
thread_id=g_thread_idx,
num_lanes=1,
clk_domain=thread_clock,
deadlock_threshold=tester_deadlock_threshold,
cache_line_size=system.cache_line_size,
)
)
g_thread_idx += 1
tester.dma_threads = dma_threads
#
# Create GPU wavefronts
#
wavefronts = []
print(
"Creating %i WFs attached to %i CUs"
% (n_CUs * tester.wavefronts_per_cu, n_CUs)
)
for cu_idx in range(n_CUs):
for wf_idx in range(tester.wavefronts_per_cu):
wavefronts.append(
GpuWavefront(
thread_id=g_thread_idx,
cu_id=cu_idx,
num_lanes=args.wf_size,
clk_domain=thread_clock,
deadlock_threshold=tester_deadlock_threshold,
cache_line_size=system.cache_line_size,
)
)
g_thread_idx += 1
tester.wavefronts = wavefronts
#
# Run simulation
#
root = Root(full_system=False, system=system)
# Not much point in this being higher than the L1 latency
m5.ticks.setGlobalFrequency("1ns")
# Instantiate configuration
m5.instantiate()
# Simulate until tester completes
exit_event = m5.simulate()
print("Exiting tick: ", m5.curTick())
print("Exiting because ", exit_event.getCause())