3 class AssertionFailure
< RuntimeError
8 return self.name
== "Boolean"
12 def assert(condition
,message
)
14 raise AssertionFailure
, "\n\nAssertion failed: \n\n #{message}\n\n"
19 @
@all_objs = Array
.new
21 @
@default_params = Hash
.new
23 def initialize(obj_name
)
24 assert obj_name
.is_a
?(String
), "Obj_Name must be a string"
31 raise NotImplementedException
34 def self.param(param_name
, type
)
35 idx
= self.name
.to_sym
36 @
@default_params[idx
] = Hash
.new
if ! @
@default_params.key
?(idx
)
37 @
@default_params[idx
][param_name
] = nil
38 send
:define_method, param_name
do
39 @params[param_name
] = @
@default_params[idx
][param_name
] if ! @params.key
?(param_name
)
42 method_name
= (param_name
.to_s
+ "=").to_sym
43 send
:define_method, method_name
do |val
|
44 if val
.is_a
?(FalseClass
) || val
.is_a
?(TrueClass
)
45 assert type
.is_a
?(Boolean
), "default value of param \"#{param_name}\" must be either true or false"
47 assert val
.is_a
?(type
), "default value of param \"#{param_name}\" does not match type #{type}"
49 # assert val.is_a?(type), "#{param_name} must be of type #{type}"
50 @params[param_name
] = val
54 def self.default_param(param_name
, type
, default
)
55 idx
= self.name
.to_sym
56 @
@default_params[idx
] = Hash
.new
if ! @
@default_params.key
?(idx
)
57 if default
.is_a
?(FalseClass
) || default
.is_a
?(TrueClass
)
58 assert type
.is_a
?(Boolean
), "default value of param \"#{param_name}\" must be either true or false"
60 assert default
.is_a
?(type
), "default value of param \"#{param_name}\" does not match type #{type}"
62 @
@default_params[idx
][param_name
] = default
63 send
:define_method, param_name
do
64 @params[param_name
] = @
@default_params[idx
][param_name
] if ! @params.key
?(param_name
)
67 method_name
= (param_name
.to_s
+ "=").to_sym
68 send
:define_method, method_name
do |val
|
69 assert val
.is_a
?(type
), "#{param_name} must be of type #{type}"
70 @params[param_name
] = val
75 idx
= self.class.name
.to_sym
76 @
@default_params[idx
] = Hash
.new
if ! @
@default_params.key
?(idx
)
77 @
@default_params[idx
].each
{ |key
, val
|
78 @params[key
] = val
if ! @params.key
?(key
)
87 @params.each
{ |key
, val
|
88 str
+= key
.id2name
+ " "
89 if val
.is_a
?(LibRubyObject
)
90 str
+= val
.obj_name
+ " "
92 if val
.is_a
?(String
) and val
== ""
102 def self.printConstructors()
104 @
@all_objs.each
{ |obj
|
105 str
+= obj
.cppClassName
+ " " + obj
.obj_name
+ " " + obj
.argv + "\n"
114 class IfacePort
< LibRubyObject
115 def initialize(obj_name
)
120 raise NotImplementedException
124 class NetPort
< LibRubyObject
128 @
@type_cnt = Hash
.new
130 def initialize(obj_name
, mach_type
)
132 @mach_type = mach_type
133 @
@type_cnt[mach_type
] ||= 0
134 @type_id = @
@type_cnt[mach_type
]
135 @
@type_cnt[mach_type
] += 1
137 idx
= "NetPort".to_sym
138 @
@default_params[idx
] = Hash
.new
if ! @
@default_params.key
?(idx
)
139 @
@default_params[idx
].each
{ |key
, val
|
140 @params[key
] = val
if ! @params.key
?(key
)
153 def self.totalOfType(mach_type
)
154 return @
@type_cnt[mach_type
]
158 class MemoryVector
< LibRubyObject
159 def initialize(obj_name
)
168 class Debug
< LibRubyObject
180 def init_params (protocol_trace
, filter_string
, verbosity_string
, start_time
, output_filename
)
181 @params[:protocol_trace] = protocol_trace
182 @params[:filter_string] = filter_string
183 @params[:verbosity_string] = verbosity_string
184 @params[:start_time] = start_time
185 @params[:output_filename] = output_filename
196 @
@defaults = Hash
.new
199 def self.init(iface_ports
, network
)
200 @
@iface_ports = iface_ports
207 @
@params.each
{ |param_name
, param
|
208 param
= @
@defaults[param_name
]
212 def self.default_param(param_name
, type
, default
)
213 if default
.is_a
?(FalseClass
) || default
.is_a
?(TrueClass
)
214 assert type
.is_a
?(Boolean
), "default value of param \"#{param_name}\" must be either true or false"
216 assert default
.is_a
?(type
), "default value of param \"#{param_name}\" does not match type #{type}"
218 @
@params[param_name
] = default
219 @
@defaults[param_name
] = default
220 method_name
= (param_name
.to_s
).to_sym
222 def #{method_name.to_s}
223 @@params[:#{param_name.to_s}]
227 def #{method_name.to_s}=(val)
228 @@params[:#{param_name.to_s}] = val
234 # get current time for random seed if set to "rand"
235 if @
@params[:random_seed] == "rand"
237 @
@params[:random_seed] = t
.usec
.to_i
239 if ! @
@params[:random_seed].is_a
?(Integer
)
242 str
= "System sys0 "+argv+"\n"
243 LibRubyObject
.all
.each
{ |obj
|
244 if obj
.is_a
?(SetAssociativeCache
)
248 str
+= LibRubyObject
.printConstructors
249 #puts str.gsub('%',' ').gsub('#','\n')
253 def self.generateConfig()
257 def self.printIfacePorts()
258 @
@iface_ports.each
{ |port
|
259 print port
.obj_name
, " "
264 def self.getBochsConnections()
266 @
@iface_ports.each
{ |port
|
267 ports
[port
.obj_name
] = port
.bochsConnType
272 def self.getMemorySizeMB()
273 DirectoryMemory
.memorySizeMB
276 # override the default accessors (generated by default_param) for random_seed
277 def self.random_seed
=(seed
)
278 assert (val
.is_a
?(Integer
) or val
== "rand"), "RubySystem.random_seed takes either an integer value or the string \"rand\""
279 @
@params[:random_seed] = seed
286 @
@params.each
{ |key
, val
|
287 str
+= key
.id2name
+ " "
288 str
+= val
.to_s
+ " "
293 def self.writeConfig()
294 @
@network.printTopology
299 #require "defaults.rb"
303 class CacheController
< NetPort
304 @
@total_cache_controllers = Hash
.new
306 def initialize(obj_name
, mach_type
, caches
)
307 super(obj_name
, mach_type
)
308 caches
.each
{ |cache
|
309 cache
.controller
= self
312 if !@
@total_cache_controllers.key
?(mach_type
)
313 @
@total_cache_controllers[mach_type
] = 0
315 @version = @
@total_cache_controllers[mach_type
]
316 @
@total_cache_controllers[mach_type
] += 1
318 # call inhereted parameters
319 transitions_per_cycle
326 vec
= "version "+@version.to_s
327 vec
+= " transitions_per_cycle "+@params[:transitions_per_cycle].to_s
328 vec
+= " buffer_size "+@params[:buffer_size].to_s
329 vec
+= " number_of_TBEs "+@params[:number_of_TBEs].to_s
330 vec
+= " recycle_latency "+@params[:recycle_latency].to_s
334 "generated:"+@mach_type
338 class L1CacheController
< CacheController
341 def initialize(obj_name
, mach_type
, caches
, sequencer
)
342 super(obj_name
, mach_type
, caches
)
344 @sequencer = sequencer
345 @sequencer.controller
= self
346 @sequencer.version = @version
351 vec
+= " sequencer "+@sequencer.obj_name
355 class DirectoryController
< NetPort
356 @
@total_directory_controllers = 0
360 def initialize(obj_name
, mach_type
, directory
, memory_control
)
361 super(obj_name
, mach_type
)
363 @directory = directory
364 directory
.controller
= self
366 @memory_control = memory_control
368 @version = @
@total_directory_controllers
369 @
@total_directory_controllers += 1
374 "version "+@version.to_s
+" directory_name "+@directory.obj_name
+" transitions_per_cycle "+@params[:transitions_per_cycle].to_s
+ " buffer_size "+@params[:buffer_size].to_s
+ " number_of_TBEs "+@params[:number_of_TBEs].to_s
+ " memory_controller_name "+@memory_control.obj_name
+ " recycle_latency "+@params[:recycle_latency].to_s
378 "generated:"+@mach_type
383 class DMAController
< NetPort
384 @
@total_dma_controllers = 0
386 def initialize(obj_name
, mach_type
, dma_sequencer
)
387 super(obj_name
, mach_type
)
388 @dma_sequencer = dma_sequencer
389 @version = @
@total_dma_controllers
390 @
@total_dma_controllers += 1
391 dma_sequencer
.controller
= self
396 "version "+@version.to_s
+" dma_sequencer "+@dma_sequencer.obj_name
+" transitions_per_cycle "+@params[:transitions_per_cycle].to_s
+ " buffer_size "+@params[:buffer_size].to_s
+ " number_of_TBEs "+@params[:number_of_TBEs].to_s
+ " recycle_latency "+@params[:recycle_latency].to_s
400 "generated:"+@mach_type
404 class Cache
< LibRubyObject
405 attr
:size_kb, :latency
406 attr_writer
:controller
407 def initialize(obj_name
, size_kb
, latency
)
409 assert size_kb
.is_a
?(Integer
), "Cache size must be an integer"
415 "controller "+@controller.obj_name
+" size_kb "+@size_kb.to_s
+" latency "+@latency.to_s
419 class SetAssociativeCache
< Cache
420 attr
:assoc, :replacement_policy
422 # latency can be either an integer, a float, or the string "auto"
423 # when an integer, it represents the number of cycles for a hit
424 # when a float, it represents the cache access time in ns
425 # when set to "auto", libruby will attempt to find a realistic latency by running CACTI
426 def initialize(obj_name
, size_kb
, latency
, assoc
, replacement_policy
)
427 super(obj_name
, size_kb
, latency
)
429 @replacement_policy = replacement_policy
432 def calculateLatency()
433 if @latency == "auto"
434 cacti_args
= Array
.new()
435 cacti_args
<< (@size_kb*1024) << RubySystem
.block_size_bytes
<< @assoc
436 cacti_args
<< 1 << 0 << 0 << 0 << 1
437 cacti_args
<< RubySystem
.tech_nm
<< RubySystem
.block_size_bytes
*8
438 cacti_args
<< 0 << 0 << 0 << 1 << 0 << 0 << 0 << 0 << 1
439 cacti_args
<< 360 << 0 << 0 << 0 << 0 << 1 << 1 << 1 << 1 << 0 << 0
440 cacti_args
<< 50 << 10 << 10 << 0 << 1 << 1
442 cacti_cmd
= File
.dirname(__FILE__
) + "/cacti/cacti " + cacti_args
.join(" ")
444 IO
.popen(cacti_cmd
) { |pipe
|
447 results
= str2
.split(", ")
448 if results
.size
!= 61
449 print
"CACTI ERROR: CACTI produced unexpected output.\n"
450 print
"Are you using the version shipped with libruby?\n"
453 latency_ns
= results
[5].to_f
454 if (latency_ns
== "1e+39")
455 print
"CACTI ERROR: CACTI was unable to realistically model the cache ",@obj_name,"\n"
456 print
"Either change the cache parameters or manually set the latency values\n"
459 clk_period_ns
= 1e9
* (1.0 / (RubySystem
.freq_mhz
* 1e6
))
460 latency_cycles
= (latency_ns
/ clk_period_ns
).ceil
461 @latency = latency_cycles
463 elsif @latency.is_a
?(Float
)
464 clk_period_ns
= 1e9
* (1.0 / (RubySystem
.freq_mhz
* 1e6
))
465 latency_cycles
= (@latency / clk_period_ns
).ceil
466 @latency = latency_cycles
467 elsif ! @latency.is_a
?(Integer
)
473 args
+" assoc "+@assoc.to_s
+" replacement_policy "+@replacement_policy
477 "SetAssociativeCache"
481 class DirectoryMemory
< LibRubyObject
483 attr_writer
:controller
486 def initialize(obj_name
, size_mb
)
489 @
@total_size_mb += size_mb
493 "version "+@controller.version.to_s
+" size_mb "+@size_mb.to_s
+" controller "+@controller.obj_name
500 def self.memorySizeMB()
506 class MemoryControl
< LibRubyObject
508 def initialize(obj_name
)
515 vec
+= " mem_bus_cycle_multiplier "+mem_bus_cycle_multiplier
.to_s
516 vec
+= " banks_per_rank "+banks_per_rank
.to_s
517 vec
+= " ranks_per_dimm "+ranks_per_dimm
.to_s
518 vec
+= " dimms_per_channel "+dimms_per_channel
.to_s
519 vec
+= " bank_bit_0 "+bank_bit_0
.to_s
520 vec
+= " rank_bit_0 "+rank_bit_0
.to_s
521 vec
+= " dimm_bit_0 "+dimm_bit_0
.to_s
522 vec
+= " bank_queue_size "+bank_queue_size
.to_s
523 vec
+= " bank_busy_time "+bank_busy_time
.to_s
524 vec
+= " rank_rank_delay "+rank_rank_delay
.to_s
525 vec
+= " read_write_delay "+read_write_delay
.to_s
526 vec
+= " basic_bus_busy_time "+basic_bus_busy_time
.to_s
527 vec
+= " mem_ctl_latency "+mem_ctl_latency
.to_s
528 vec
+= " refresh_period "+refresh_period
.to_s
529 vec
+= " tFaw "+tFaw
.to_s
530 vec
+= " mem_random_arbitrate "+mem_random_arbitrate
.to_s
531 vec
+= " mem_fixed_delay "+mem_fixed_delay
.to_s
532 vec
+= " memory_controller_name "+@name
544 class Sequencer
< IfacePort
550 param
:controller, NetPort
# must be set after initialization
553 param
:version, Integer
555 def initialize(obj_name
, icache
, dcache
)
562 return "cpu"+version.to_s
569 class DMASequencer
< IfacePort
570 def initialize(obj_name
)
578 def controller
=(controller
)
579 @params[:controller] = controller
.obj_name
580 @params[:version] = controller
.version
588 return "dma"+@params[:version].to_s
599 class Network
< LibRubyObject
602 class Topology
< LibRubyObject
604 param
:network, Network
605 def initialize(name
, net_ports
)
607 @net_ports = net_ports
615 class Network
< LibRubyObject
616 param
:topology, Topology
617 def initialize(name
, topo
)
619 @params[:topology] = topo
626 vec
+= " endpoint_bandwidth "+endpoint_bandwidth
.to_s
627 vec
+= " adaptive_routing "+adaptive_routing
.to_s
628 vec
+= " number_of_virtual_networks "+number_of_virtual_networks
.to_s
629 vec
+= " fan_out_degree "+fan_out_degree
.to_s
631 vec
+= " buffer_size "+buffer_size
.to_s
632 vec
+= " link_latency "+adaptive_routing
.to_s
633 vec
+= " on_chip_latency "+on_chip_latency
.to_s
634 vec
+= " control_msg_size "+control_msg_size
.to_s
646 class PtToPtTopology
< Topology
648 param
:connections,String
650 def initialize(name
, net_ports
)
651 super(name
, net_ports
)
652 @params[:connections] = ""
653 @net_ports.each_index
{ |idx
|
654 @params[:connections] << ("ext_node:"+@net_ports[idx
].port_name
+":"+@net_ports[idx
].port_num
.to_s
)
655 @params[:connections] << ("%int_node:"+ idx
.to_s
+ "%link_latency:"+ link_latency
.to_s
)
656 @params[:connections] << ("%bw_multiplier:"+external_bw
.to_s
+"#")
658 @net_ports.each_index
{ |outer_idx
|
659 @net_ports.each_index
{ |inner_idx
|
660 if (outer_idx
!= inner_idx
)
661 @params[:connections] << ("int_node:"+ outer_idx
.to_s
+ "%int_node:"+ inner_idx
.to_s
)
662 @params[:connections] << ("%link_latency:"+link_latency
.to_s
+"%bw_multiplier:"+internal_bw
.to_s
)
663 @params[:connections] << ("%link_weight:"+1.to_s
+"#")
667 # call the accessors of the parent class to initialize them
668 # need to find a better method!!
674 class CrossbarTopology
< Topology
675 param
:connections,String
677 def initialize(name
, net_ports
)
678 super(name
, net_ports
)
679 @params[:connections] = ""
680 crossbar_node
= @net_ports.size
681 @net_ports.each_index
{ |idx
|
682 @params[:connections] << ("ext_node:"+@net_ports[idx
].port_name
+":"+@net_ports[idx
].port_num
.to_s
)
683 @params[:connections] << ("%int_node:"+ idx
.to_s
+ "%link_latency:"+ link_latency
.to_s
)
684 @params[:connections] << ("%bw_multiplier:"+external_bw
.to_s
+"#")
686 @net_ports.each_index
{ |idx
|
687 @params[:connections] << ("int_node:"+idx
.to_s
+"%int_node:"+crossbar_node
.to_s
)
688 @params[:connections] << ("%link_latency:"+link_latency
.to_s
+"%bw_multiplier:"+internal_bw
.to_s
)
689 @params[:connections] << ("%link_weight:"+1.to_s
+"#")
696 class Tracer
< LibRubyObject
697 def initialize(obj_name
)
707 class Profiler
< LibRubyObject
708 def initialize(obj_name
)
719 class GarnetNetwork
< Network
720 def initialize(name
, topo
)
725 vec
+= " flit_size "+flit_size
.to_s
726 vec
+= " number_of_pipe_stages "+number_of_pipe_stages
.to_s
727 vec
+= " vcs_per_class "+vcs_per_class
.to_s
728 vec
+= " buffer_size "+buffer_size
.to_s
729 vec
+= " using_network_testing "+using_network_testing
.to_s
734 class GarnetFixedPipeline
< GarnetNetwork
735 def initialize(name
, net_ports
)
736 super(name
, net_ports
)
748 class GarnetFlexiblePipeline
< GarnetNetwork
749 def initialize(name
, net_ports
)
750 super(name
, net_ports
)
762 require "defaults.rb"