gpu-ruby.py revision 11682
1# 2# Copyright (c) 2015 Advanced Micro Devices, Inc. 3# All rights reserved. 4# 5# For use for simulation and test purposes only 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions are met: 9# 10# 1. Redistributions of source code must retain the above copyright notice, 11# this list of conditions and the following disclaimer. 12# 13# 2. Redistributions in binary form must reproduce the above copyright notice, 14# this list of conditions and the following disclaimer in the documentation 15# and/or other materials provided with the distribution. 16# 17# 3. Neither the name of the copyright holder nor the names of its contributors 18# may be used to endorse or promote products derived from this software 19# without specific prior written permission. 20# 21# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31# POSSIBILITY OF SUCH DAMAGE. 32# 33# Author: Brad Beckmann 34# 35 36import m5 37from m5.objects import * 38from m5.defines import buildEnv 39from m5.util import addToPath 40import os, optparse, sys, math, glob 41 42m5.util.addToPath('../configs/') 43 44from ruby import Ruby 45from common import Options 46from common import GPUTLBOptions, GPUTLBConfig 47 48########################## Script Options ######################## 49def setOption(parser, opt_str, value = 1): 50 # check to make sure the option actually exists 51 if not parser.has_option(opt_str): 52 raise Exception("cannot find %s in list of possible options" % opt_str) 53 54 opt = parser.get_option(opt_str) 55 # set the value 56 exec("parser.values.%s = %s" % (opt.dest, value)) 57 58def getOption(parser, opt_str): 59 # check to make sure the option actually exists 60 if not parser.has_option(opt_str): 61 raise Exception("cannot find %s in list of possible options" % opt_str) 62 63 opt = parser.get_option(opt_str) 64 # get the value 65 exec("return_value = parser.values.%s" % opt.dest) 66 return return_value 67 68def run_test(root): 69 """gpu test requires a specialized run_test implementation to set up the 70 mmio space.""" 71 72 # instantiate configuration 73 m5.instantiate() 74 75 # Now that the system has been constructed, setup the mmio space 76 root.system.cpu[0].workload[0].map(0x10000000, 0x200000000, 4096) 77 78 # simulate until program terminates 79 exit_event = m5.simulate(maxtick) 80 print 'Exiting @ tick', m5.curTick(), 'because', exit_event.getCause() 81 82parser = optparse.OptionParser() 83Options.addCommonOptions(parser) 84Options.addSEOptions(parser) 85 86parser.add_option("-k", "--kernel-files", 87 help="file(s) containing GPU kernel code (colon separated)") 88parser.add_option("-u", "--num-compute-units", type="int", default=2, 89 help="number of GPU compute units"), 90parser.add_option("--num-cp", type="int", default=0, 91 help="Number of GPU Command Processors (CP)") 92parser.add_option("--simds-per-cu", type="int", default=4, help="SIMD units" \ 93 "per CU") 94parser.add_option("--cu-per-sqc", type="int", default=4, help="number of CUs" \ 95 "sharing an SQC (icache, and thus icache TLB)") 96parser.add_option("--wf-size", type="int", default=64, 97 help="Wavefront size(in workitems)") 98parser.add_option("--wfs-per-simd", type="int", default=8, help="Number of " \ 99 "WF slots per SIMD") 100parser.add_option("--sp-bypass-path-length", type="int", default=4, \ 101 help="Number of stages of bypass path in vector ALU for Single "\ 102 "Precision ops") 103parser.add_option("--dp-bypass-path-length", type="int", default=4, \ 104 help="Number of stages of bypass path in vector ALU for Double "\ 105 "Precision ops") 106parser.add_option("--issue-period", type="int", default=4, \ 107 help="Number of cycles per vector instruction issue period") 108parser.add_option("--glbmem-wr-bus-width", type="int", default=32, \ 109 help="VGPR to Coalescer (Global Memory) data bus width in bytes") 110parser.add_option("--glbmem-rd-bus-width", type="int", default=32, \ 111 help="Coalescer to VGPR (Global Memory) data bus width in bytes") 112parser.add_option("--shr-mem-pipes-per-cu", type="int", default=1, \ 113 help="Number of Shared Memory pipelines per CU") 114parser.add_option("--glb-mem-pipes-per-cu", type="int", default=1, \ 115 help="Number of Global Memory pipelines per CU") 116parser.add_option("--vreg-file-size", type="int", default=2048, 117 help="number of physical vector registers per SIMD") 118parser.add_option("--bw-scalor", type="int", default=0, 119 help="bandwidth scalor for scalability analysis") 120parser.add_option("--CPUClock", type="string", default="2GHz", 121 help="CPU clock") 122parser.add_option("--GPUClock", type="string", default="1GHz", 123 help="GPU clock") 124parser.add_option("--cpu-voltage", action="store", type="string", 125 default='1.0V', 126 help = """CPU voltage domain""") 127parser.add_option("--gpu-voltage", action="store", type="string", 128 default='1.0V', 129 help = """CPU voltage domain""") 130parser.add_option("--CUExecPolicy", type="string", default="OLDEST-FIRST", 131 help="WF exec policy (OLDEST-FIRST, ROUND-ROBIN)") 132parser.add_option("--xact-cas-mode", action="store_true", 133 help="enable load_compare mode (transactional CAS)") 134parser.add_option("--SegFaultDebug",action="store_true", 135 help="checks for GPU seg fault before TLB access") 136parser.add_option("--LocalMemBarrier",action="store_true", 137 help="Barrier does not wait for writethroughs to complete") 138parser.add_option("--countPages", action="store_true", 139 help="Count Page Accesses and output in per-CU output files") 140parser.add_option("--TLB-prefetch", type="int", help = "prefetch depth for"\ 141 "TLBs") 142parser.add_option("--pf-type", type="string", help="type of prefetch: "\ 143 "PF_CU, PF_WF, PF_PHASE, PF_STRIDE") 144parser.add_option("--pf-stride", type="int", help="set prefetch stride") 145parser.add_option("--numLdsBanks", type="int", default=32, 146 help="number of physical banks per LDS module") 147parser.add_option("--ldsBankConflictPenalty", type="int", default=1, 148 help="number of cycles per LDS bank conflict") 149 150# Add the ruby specific and protocol specific options 151Ruby.define_options(parser) 152 153GPUTLBOptions.tlb_options(parser) 154 155(options, args) = parser.parse_args() 156 157# The GPU cache coherence protocols only work with the backing store 158setOption(parser, "--access-backing-store") 159 160# Currently, the sqc (I-Cache of GPU) is shared by 161# multiple compute units(CUs). The protocol works just fine 162# even if sqc is not shared. Overriding this option here 163# so that the user need not explicitly set this (assuming 164# sharing sqc is the common usage) 165n_cu = options.num_compute_units 166num_sqc = int(math.ceil(float(n_cu) / options.cu_per_sqc)) 167options.num_sqc = num_sqc # pass this to Ruby 168 169########################## Creating the GPU system ######################## 170# shader is the GPU 171shader = Shader(n_wf = options.wfs_per_simd, 172 clk_domain = SrcClockDomain( 173 clock = options.GPUClock, 174 voltage_domain = VoltageDomain( 175 voltage = options.gpu_voltage)), 176 timing = True) 177 178# GPU_RfO(Read For Ownership) implements SC/TSO memory model. 179# Other GPU protocols implement release consistency at GPU side. 180# So, all GPU protocols other than GPU_RfO should make their writes 181# visible to the global memory and should read from global memory 182# during kernal boundary. The pipeline initiates(or do not initiate) 183# the acquire/release operation depending on this impl_kern_boundary_sync 184# flag. This flag=true means pipeline initiates a acquire/release operation 185# at kernel boundary. 186if buildEnv['PROTOCOL'] == 'GPU_RfO': 187 shader.impl_kern_boundary_sync = False 188else: 189 shader.impl_kern_boundary_sync = True 190 191# Switching off per-lane TLB by default 192per_lane = False 193if options.TLB_config == "perLane": 194 per_lane = True 195 196# List of compute units; one GPU can have multiple compute units 197compute_units = [] 198for i in xrange(n_cu): 199 compute_units.append(ComputeUnit(cu_id = i, perLaneTLB = per_lane, 200 num_SIMDs = options.simds_per_cu, 201 wfSize = options.wf_size, 202 spbypass_pipe_length = \ 203 options.sp_bypass_path_length, 204 dpbypass_pipe_length = \ 205 options.dp_bypass_path_length, 206 issue_period = options.issue_period, 207 coalescer_to_vrf_bus_width = \ 208 options.glbmem_rd_bus_width, 209 vrf_to_coalescer_bus_width = \ 210 options.glbmem_wr_bus_width, 211 num_global_mem_pipes = \ 212 options.glb_mem_pipes_per_cu, 213 num_shared_mem_pipes = \ 214 options.shr_mem_pipes_per_cu, 215 n_wf = options.wfs_per_simd, 216 execPolicy = options.CUExecPolicy, 217 xactCasMode = options.xact_cas_mode, 218 debugSegFault = options.SegFaultDebug, 219 functionalTLB = True, 220 localMemBarrier = options.LocalMemBarrier, 221 countPages = options.countPages, 222 localDataStore = \ 223 LdsState(banks = options.numLdsBanks, 224 bankConflictPenalty = \ 225 options.ldsBankConflictPenalty))) 226 wavefronts = [] 227 vrfs = [] 228 for j in xrange(options.simds_per_cu): 229 for k in xrange(shader.n_wf): 230 wavefronts.append(Wavefront(simdId = j, wf_slot_id = k)) 231 vrfs.append(VectorRegisterFile(simd_id=j, 232 num_regs_per_simd=options.vreg_file_size)) 233 compute_units[-1].wavefronts = wavefronts 234 compute_units[-1].vector_register_file = vrfs 235 if options.TLB_prefetch: 236 compute_units[-1].prefetch_depth = options.TLB_prefetch 237 compute_units[-1].prefetch_prev_type = options.pf_type 238 239 # attach the LDS and the CU to the bus (actually a Bridge) 240 compute_units[-1].ldsPort = compute_units[-1].ldsBus.slave 241 compute_units[-1].ldsBus.master = compute_units[-1].localDataStore.cuPort 242 243# Attach compute units to GPU 244shader.CUs = compute_units 245 246# this is a uniprocessor only test, thus the shader is the second index in the 247# list of "system.cpus" 248options.num_cpus = 1 249shader_idx = 1 250cpu = TimingSimpleCPU(cpu_id=0) 251 252########################## Creating the GPU dispatcher ######################## 253# Dispatcher dispatches work from host CPU to GPU 254host_cpu = cpu 255dispatcher = GpuDispatcher() 256 257# Currently does not test for command processors 258cpu_list = [cpu] + [shader] + [dispatcher] 259 260system = System(cpu = cpu_list, 261 mem_ranges = [AddrRange(options.mem_size)], 262 mem_mode = 'timing') 263 264# Dummy voltage domain for all our clock domains 265system.voltage_domain = VoltageDomain(voltage = options.sys_voltage) 266system.clk_domain = SrcClockDomain(clock = '1GHz', 267 voltage_domain = system.voltage_domain) 268 269# Create a seperate clock domain for components that should run at 270# CPUs frequency 271system.cpu[0].clk_domain = SrcClockDomain(clock = '2GHz', 272 voltage_domain = \ 273 system.voltage_domain) 274 275# configure the TLB hierarchy 276GPUTLBConfig.config_tlb_hierarchy(options, system, shader_idx) 277 278# create Ruby system 279system.piobus = IOXBar(width=32, response_latency=0, 280 frontend_latency=0, forward_latency=0) 281Ruby.create_system(options, None, system) 282 283# Create a separate clock for Ruby 284system.ruby.clk_domain = SrcClockDomain(clock = options.ruby_clock, 285 voltage_domain = system.voltage_domain) 286 287# create the interrupt controller 288cpu.createInterruptController() 289 290# 291# Tie the cpu cache ports to the ruby cpu ports and 292# physmem, respectively 293# 294cpu.connectAllPorts(system.ruby._cpu_ports[0]) 295system.ruby._cpu_ports[0].mem_master_port = system.piobus.slave 296 297# attach CU ports to Ruby 298# Because of the peculiarities of the CP core, you may have 1 CPU but 2 299# sequencers and thus 2 _cpu_ports created. Your GPUs shouldn't be 300# hooked up until after the CP. To make this script generic, figure out 301# the index as below, but note that this assumes there is one sequencer 302# per compute unit and one sequencer per SQC for the math to work out 303# correctly. 304gpu_port_idx = len(system.ruby._cpu_ports) \ 305 - options.num_compute_units - options.num_sqc 306gpu_port_idx = gpu_port_idx - options.num_cp * 2 307 308wavefront_size = options.wf_size 309for i in xrange(n_cu): 310 # The pipeline issues wavefront_size number of uncoalesced requests 311 # in one GPU issue cycle. Hence wavefront_size mem ports. 312 for j in xrange(wavefront_size): 313 system.cpu[shader_idx].CUs[i].memory_port[j] = \ 314 system.ruby._cpu_ports[gpu_port_idx].slave[j] 315 gpu_port_idx += 1 316 317for i in xrange(n_cu): 318 if i > 0 and not i % options.cu_per_sqc: 319 gpu_port_idx += 1 320 system.cpu[shader_idx].CUs[i].sqc_port = \ 321 system.ruby._cpu_ports[gpu_port_idx].slave 322gpu_port_idx = gpu_port_idx + 1 323 324# Current regression tests do not support the command processor 325assert(options.num_cp == 0) 326 327# connect dispatcher to the system.piobus 328dispatcher.pio = system.piobus.master 329dispatcher.dma = system.piobus.slave 330 331################# Connect the CPU and GPU via GPU Dispatcher ################### 332# CPU rings the GPU doorbell to notify a pending task 333# using this interface. 334# And GPU uses this interface to notify the CPU of task completion 335# The communcation happens through emulated driver. 336 337# Note this implicit setting of the cpu_pointer, shader_pointer and tlb array 338# parameters must be after the explicit setting of the System cpu list 339shader.cpu_pointer = host_cpu 340dispatcher.cpu = host_cpu 341dispatcher.shader_pointer = shader 342 343# ----------------------- 344# run simulation 345# ----------------------- 346 347root = Root(full_system = False, system = system) 348m5.ticks.setGlobalFrequency('1THz') 349root.system.mem_mode = 'timing' 350