def __init__(self,scene, x, y,\ in0=None,\ in1=None,\ out0=None,\ out1=None,\ boundRequest = None,\ boundReply = None,\ onConflict = None): component.__init__(self) if in0 is None: self.in0 = in0 = channels.biChannel(scene, boundRequest, boundReply) else: assert isinstance(in0,channels.biChannel) self.in0 = in0 if in1 is None: self.in1 = in1 = channels.biChannel(scene, boundRequest, boundReply) else: assert isinstance(in1,channels.biChannel) self.in1 = in1 if out0 is None: self.out0 = out0 = channels.biChannel(scene, boundRequest, boundReply) else: assert isinstance(out0,channels.biChannel) self.out0 = out0 if out1 is None: self.out1 = out1 = channels.biChannel(scene, boundRequest, boundReply) else: assert isinstance(out1,channels.biChannel) self.out1 = out1 in0.setP(70*x+5, 70*y+15) in1.setP(70*x+5, 70*y+45) out0.setP(70*x+45, 70*y+15) out1.setP(70*x+45, 70*y+45) self.req0 = None self.req1 = None self.rep0 = None self.rep1 = None if onConflict is not None: self.onConflict = onConflict print "Simple switch", self.id
def __init__(self,scene, x, y,\ latency,channel = None, boundRequest = None, boundReply = None): assert isinstance(latency,int) component.__init__(self) if channel is None: channel = channels.biChannel(scene, boundRequest, boundReply) else: assert isinstance(channel,channels.biChannel) self.channel = channel channel.setP(70*x+5, 70*y+25) self.latency = latency self.buff = [] print "Memory", self.id
def __init__(self,scene, x, y, p,nbits,channel = None,\ boundRequest = None, boundReply = None, loadRatio = 1.7): """A processor with a probability p of requesting a word in memory.""" assert 0 <= p <= 1 assert isinstance(nbits,int) self.rand = Random() component.__init__(self) self.p = p self.loadRatio = loadRatio if channel is None: self.channel = channel = channels.biChannel(scene, boundRequest, boundReply) else: assert isinstance(channel,channels.biChannel) self.channel = channel channel.setP(70*x+45, 70*y+25) self.nbits = nbits self.message = None self.num_instr = 0L print "Processor", self.id
def __init__(self, scene, x, y, position, upper_chan_up = None, upper_chan_down = None, upper_chan_left = None, upper_chan_right = None, lower_chan_up = None, lower_chan_down = None, lower_chan_left = None, lower_chan_right = None, proc = None, mem = None, boundRequest = None, boundReply = None): """Creates a 2D switch. The scene, x and y arguments are for the graphical display. The position argument is the logical position in the grid. The proc (resp. mem) argument are either a processor (resp. memory) instance or a function that returns an instance of it. The other arguments are for the channels. """ component.__init__(self) # there are eight channels to initialize. A lot of code to do one thing. if upper_chan_up is None: upper_chan_up = channels.biChannel(scene, boundRequest, boundReply) else: assert isinstance(upper_chan_up,channels.biChannel) if upper_chan_down is None: upper_chan_down = channels.biChannel(scene, boundRequest, boundReply) else: assert isinstance(upper_chan_down,channels.biChannel) if upper_chan_left is None: upper_chan_left = channels.biChannel(scene, boundRequest, boundReply) else: assert isinstance(upper_chan_left,channels.biChannel) if upper_chan_right is None: upper_chan_right = channels.biChannel(scene, boundRequest, boundReply) else: assert isinstance(upper_chan_right,channels.biChannel) if lower_chan_up is None: lower_chan_up = channels.biChannel(scene, boundRequest, boundReply) else: assert isinstance(lower_chan_up,channels.biChannel) if lower_chan_down is None: lower_chan_down = channels.biChannel(scene, boundRequest, boundReply) else: assert isinstance(lower_chan_down,channels.biChannel) if lower_chan_left is None: lower_chan_left = channels.biChannel(scene, boundRequest, boundReply) else: assert isinstance(lower_chan_left,channels.biChannel) if lower_chan_right is None: lower_chan_right = channels.biChannel(scene, boundRequest, boundReply) else: assert isinstance(lower_chan_right,channels.biChannel) upper_chan_up.setP( 70*x+25,70*y+ 5) upper_chan_down.setP( 70*x+25,70*y+45) upper_chan_left.setP( 70*x+ 5,70*y+25) upper_chan_right.setP(70*x+45,70*y+25) lower_chan_up.setP( 70*x+25,70*y+ 5) lower_chan_down.setP( 70*x+25,70*y+45) lower_chan_left.setP( 70*x+ 5,70*y+25) lower_chan_right.setP(70*x+45,70*y+25) self.upper_chan_up = upper_chan_up self.upper_chan_down = upper_chan_down self.upper_chan_left = upper_chan_left self.upper_chan_right = upper_chan_right self.lower_chan_up = lower_chan_up self.lower_chan_down = lower_chan_down self.lower_chan_left = lower_chan_left self.lower_chan_right = lower_chan_right # the 2D coordinates of the switch (logical, not graphical) self.position = position # the messages waiting to be transmitted self.upper_from_up = \ self.upper_from_down = \ self.upper_from_left = \ self.upper_from_right = \ self.lower_from_up = \ self.lower_from_down = \ self.lower_from_left = \ self.lower_from_right = \ self.from_proc = \ self.from_mem = None # we initialize the processor and memory attached to the switch if not isinstance(proc,processor): proc = proc() assert isinstance(proc,processor) if proc.channel == None: self.to_proc = channels.biChannel(scene, boundRequest, boundReply) proc.channel = self.to_proc else: self.to_proc = proc.channel self.to_proc.setP(70*x+ 5,70*y+25) if not isinstance(mem,base.memory): mem = mem() assert isinstance(mem,base.memory) if mem.channel == None: self.to_mem = channels.biChannel(scene, boundRequest, boundReply) mem.channel = self.to_mem else: self.to_mem = mem.channel self.to_mem.setP(70*x+ 5,70*y+25) # we have a list of messages to transmit on upper and lower channels self.upper = [] self.lower = []