Skip to content

Commit

Permalink
Fix timing demos to exclude unnecessary connections in patterns inter…
Browse files Browse the repository at this point in the history
…fering with setup of scenarios with > 2 LPUs.
  • Loading branch information
lebedov committed Mar 12, 2015
1 parent b633d5d commit 73f04eb
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 58 deletions.
95 changes: 66 additions & 29 deletions examples/timing/timing_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,29 @@ def gen_sels(n_lpu, n_spike, n_gpot):
Returns
-------
results : dict of tuples
The keys of the result are the module IDs; the values are tuples
containing the respective selectors for input, output, graded potential,
and spiking ports.
mod_sels : dict of tuples
Ports in module interfaces; the keys are the module IDs and the values are tuples
containing the respective selectors for all ports, all input ports, all
output ports, all graded potential, and all spiking ports.
pat_sels : dict of tuples
Ports in pattern interfaces; the keys are tuples containing the two
module IDs connected by the pattern and the values are pairs of tuples
containing the respective selectors for all source ports, all
destination ports, all input ports connected to the first module,
all output ports connected to the first module, all graded potential ports
connected to the first module, all spiking ports connected to the first
module, all input ports connected to the second module,
all output ports connected to the second module, all graded potential ports
connected to the second module, and all spiking ports connected to the second
module.
"""

assert n_lpu >= 2
assert n_spike >= 0
assert n_gpot >= 0

results = {}
mod_sels = {}
pat_sels = {('lpu%s' % i) : {} for i in xrange(n_lpu)}

for i in xrange(n_lpu):
lpu_id = 'lpu%s' % i
Expand All @@ -90,12 +102,46 @@ def gen_sels(n_lpu, n_spike, n_gpot):
(lpu_id, other_lpu_ids, n_gpot))
sel_out_spike = Selector('/%s/out/spike/%s/[0:%i]' % \
(lpu_id, other_lpu_ids, n_spike))
results[lpu_id] = (Selector.union(sel_in_gpot, sel_in_spike),
Selector.union(sel_out_gpot, sel_out_spike),
Selector.union(sel_in_gpot, sel_out_gpot),
Selector.union(sel_in_spike, sel_out_spike))
mod_sels[lpu_id] = (Selector.union(sel_in_gpot, sel_in_spike,
sel_out_gpot, sel_out_spike),
Selector.union(sel_in_gpot, sel_in_spike),
Selector.union(sel_out_gpot, sel_out_spike),
Selector.union(sel_in_gpot, sel_out_gpot),
Selector.union(sel_in_spike, sel_out_spike))

return results
for i, j in itertools.combinations(xrange(n_lpu), 2):
lpu_i = 'lpu%s' % i
lpu_j = 'lpu%s' % j

sel_in_gpot_i = Selector('/%s/out/gpot/%s[0:%i]' % (lpu_i, lpu_j, n_gpot))
sel_in_spike_i = Selector('/%s/out/spike/%s[0:%i]' % (lpu_i, lpu_j, n_spike))
sel_out_gpot_i = Selector('/%s/in/gpot/%s[0:%i]' % (lpu_i, lpu_j, n_gpot))
sel_out_spike_i = Selector('/%s/in/spike/%s[0:%i]' % (lpu_i, lpu_j, n_spike))

sel_in_gpot_j = Selector('/%s/out/gpot/%s[0:%i]' % (lpu_j, lpu_i, n_gpot))
sel_in_spike_j = Selector('/%s/out/spike/%s[0:%i]' % (lpu_j, lpu_i, n_spike))
sel_out_gpot_j = Selector('/%s/in/gpot/%s[0:%i]' % (lpu_j, lpu_i, n_gpot))
sel_out_spike_j = Selector('/%s/in/spike/%s[0:%i]' % (lpu_j, lpu_i, n_spike))

# The order of these two selectors is important; the individual 'from'
# and 'to' ports must line up properly for Pattern.from_concat to
# produce the right pattern:
sel_from = Selector.add(sel_in_gpot_i, sel_in_spike_i,
sel_in_gpot_j, sel_in_spike_j)
sel_to = Selector.add(sel_out_gpot_j, sel_out_spike_j,
sel_out_gpot_i, sel_out_spike_i)
pat_sels[(lpu_i, lpu_j)] = \
(sel_from, sel_to,
Selector.union(sel_in_gpot_i, sel_in_spike_i),
Selector.union(sel_out_gpot_i, sel_out_spike_i),
Selector.union(sel_in_gpot_i, sel_out_gpot_i),
Selector.union(sel_in_spike_i, sel_out_spike_i),
Selector.union(sel_in_gpot_j, sel_in_spike_j),
Selector.union(sel_out_gpot_j, sel_out_spike_j),
Selector.union(sel_in_gpot_j, sel_out_gpot_j),
Selector.union(sel_in_spike_j, sel_out_spike_j))

return mod_sels, pat_sels

def emulate(n_lpu, n_spike, n_gpot, steps):
"""
Expand Down Expand Up @@ -134,12 +180,13 @@ def emulate(n_lpu, n_spike, n_gpot, steps):
man = Manager(get_random_port(), get_random_port(), get_random_port())
man.add_brok()

# Generate selectors for configuring modules and patterns:
mod_sels, pat_sels = gen_sels(n_lpu, n_spike, n_gpot)

# Set up modules:
sel_dict = gen_sels(n_lpu, n_spike, n_gpot)
for i in xrange(n_lpu):
lpu_i = 'lpu%s' % i
sel_in, sel_out, sel_gpot, sel_spike = sel_dict[lpu_i]
sel = Selector.union(sel_in, sel_out, sel_gpot, sel_spike)
sel, sel_in, sel_out, sel_gpot, sel_spike = mod_sels[lpu_i]
m = MyModule(sel, sel_in, sel_out,
sel_gpot, sel_spike,
port_data=man.port_data, port_ctrl=man.port_ctrl,
Expand All @@ -151,28 +198,18 @@ def emulate(n_lpu, n_spike, n_gpot, steps):
for i, j in itertools.combinations(xrange(n_lpu), 2):
lpu_i = 'lpu%s' % i
lpu_j = 'lpu%s' % j
sel_in_i, sel_out_i, sel_gpot_i, sel_spike_i = sel_dict[lpu_i]
sel_in_j, sel_out_j, sel_gpot_j, sel_spike_j = sel_dict[lpu_j]

# The order of these two selectors is important; the individual 'from'
# and 'to' ports must line up properly for Pattern.from_concat to
# produce the right pattern:
sel_from = sel_out_i+sel_out_j
sel_to = sel_in_j+sel_in_i
man.log_info('before from_concat')
sel_from, sel_to, sel_in_i, sel_out_i, sel_gpot_i, sel_spike_i, \
sel_in_j, sel_out_j, sel_gpot_j, sel_spike_j = pat_sels[(lpu_i, lpu_j)]
pat = Pattern.from_concat(sel_from, sel_to,
from_sel=sel_from, to_sel=sel_to, data=1)

man.log_info('before setting attribs')
pat.interface[sel_in_i, 'interface', 'io'] = [0, 'out']
pat.interface[sel_out_i, 'interface', 'io'] = [0, 'in']
pat.interface[sel_in_i, 'interface', 'io'] = [0, 'in']
pat.interface[sel_out_i, 'interface', 'io'] = [0, 'out']
pat.interface[sel_gpot_i, 'interface', 'type'] = [0, 'gpot']
pat.interface[sel_spike_i, 'interface', 'type'] = [0, 'spike']
pat.interface[sel_in_j, 'interface', 'io'] = [1, 'out']
pat.interface[sel_out_j, 'interface', 'io'] = [1, 'in']
pat.interface[sel_in_j, 'interface', 'io'] = [1, 'in']
pat.interface[sel_out_j, 'interface', 'io'] = [1, 'out']
pat.interface[sel_gpot_j, 'interface', 'type'] = [1, 'gpot']
pat.interface[sel_spike_j, 'interface', 'type'] = [1, 'spike']
man.log_info('before connecting modules')
man.connect(man.modules[lpu_i], man.modules[lpu_j], pat, 0, 1)

man.start(steps=steps)
Expand Down
96 changes: 67 additions & 29 deletions examples/timing/timing_demo_gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,29 @@ def gen_sels(n_lpu, n_spike, n_gpot):
Returns
-------
results : dict of tuples
The keys of the result are the module IDs; the values are tuples
containing the respective selectors for input, output, graded potential,
and spiking ports.
mod_sels : dict of tuples
Ports in module interfaces; the keys are the module IDs and the values are tuples
containing the respective selectors for all ports, all input ports, all
output ports, all graded potential, and all spiking ports.
pat_sels : dict of tuples
Ports in pattern interfaces; the keys are tuples containing the two
module IDs connected by the pattern and the values are pairs of tuples
containing the respective selectors for all source ports, all
destination ports, all input ports connected to the first module,
all output ports connected to the first module, all graded potential ports
connected to the first module, all spiking ports connected to the first
module, all input ports connected to the second module,
all output ports connected to the second module, all graded potential ports
connected to the second module, and all spiking ports connected to the second
module.
"""

assert n_lpu >= 2
assert n_spike >= 0
assert n_gpot >= 0

results = {}
mod_sels = {}
pat_sels = {('lpu%s' % i) : {} for i in xrange(n_lpu)}

for i in xrange(n_lpu):
lpu_id = 'lpu%s' % i
Expand All @@ -103,12 +115,46 @@ def gen_sels(n_lpu, n_spike, n_gpot):
(lpu_id, other_lpu_ids, n_gpot))
sel_out_spike = Selector('/%s/out/spike/%s/[0:%i]' % \
(lpu_id, other_lpu_ids, n_spike))
results[lpu_id] = (Selector.union(sel_in_gpot, sel_in_spike),
Selector.union(sel_out_gpot, sel_out_spike),
Selector.union(sel_in_gpot, sel_out_gpot),
Selector.union(sel_in_spike, sel_out_spike))
mod_sels[lpu_id] = (Selector.union(sel_in_gpot, sel_in_spike,
sel_out_gpot, sel_out_spike),
Selector.union(sel_in_gpot, sel_in_spike),
Selector.union(sel_out_gpot, sel_out_spike),
Selector.union(sel_in_gpot, sel_out_gpot),
Selector.union(sel_in_spike, sel_out_spike))

return results
for i, j in itertools.combinations(xrange(n_lpu), 2):
lpu_i = 'lpu%s' % i
lpu_j = 'lpu%s' % j

sel_in_gpot_i = Selector('/%s/out/gpot/%s[0:%i]' % (lpu_i, lpu_j, n_gpot))
sel_in_spike_i = Selector('/%s/out/spike/%s[0:%i]' % (lpu_i, lpu_j, n_spike))
sel_out_gpot_i = Selector('/%s/in/gpot/%s[0:%i]' % (lpu_i, lpu_j, n_gpot))
sel_out_spike_i = Selector('/%s/in/spike/%s[0:%i]' % (lpu_i, lpu_j, n_spike))

sel_in_gpot_j = Selector('/%s/out/gpot/%s[0:%i]' % (lpu_j, lpu_i, n_gpot))
sel_in_spike_j = Selector('/%s/out/spike/%s[0:%i]' % (lpu_j, lpu_i, n_spike))
sel_out_gpot_j = Selector('/%s/in/gpot/%s[0:%i]' % (lpu_j, lpu_i, n_gpot))
sel_out_spike_j = Selector('/%s/in/spike/%s[0:%i]' % (lpu_j, lpu_i, n_spike))

# The order of these two selectors is important; the individual 'from'
# and 'to' ports must line up properly for Pattern.from_concat to
# produce the right pattern:
sel_from = Selector.add(sel_in_gpot_i, sel_in_spike_i,
sel_in_gpot_j, sel_in_spike_j)
sel_to = Selector.add(sel_out_gpot_j, sel_out_spike_j,
sel_out_gpot_i, sel_out_spike_i)
pat_sels[(lpu_i, lpu_j)] = \
(sel_from, sel_to,
Selector.union(sel_in_gpot_i, sel_in_spike_i),
Selector.union(sel_out_gpot_i, sel_out_spike_i),
Selector.union(sel_in_gpot_i, sel_out_gpot_i),
Selector.union(sel_in_spike_i, sel_out_spike_i),
Selector.union(sel_in_gpot_j, sel_in_spike_j),
Selector.union(sel_out_gpot_j, sel_out_spike_j),
Selector.union(sel_in_gpot_j, sel_out_gpot_j),
Selector.union(sel_in_spike_j, sel_out_spike_j))

return mod_sels, pat_sels

def emulate(n_lpu, n_spike, n_gpot, steps):
"""
Expand Down Expand Up @@ -148,15 +194,17 @@ def emulate(n_lpu, n_spike, n_gpot, steps):
if n_lpu > drv.Device.count():
raise RuntimeError('insufficient number of available GPUs.')

# Set up manager and broker:
man = Manager(get_random_port(), get_random_port(), get_random_port())
man.add_brok()

# Generate selectors for configuring modules and patterns:
mod_sels, pat_sels = gen_sels(n_lpu, n_spike, n_gpot)

# Set up modules:
sel_dict = gen_sels(n_lpu, n_spike, n_gpot)
for i in xrange(n_lpu):
lpu_i = 'lpu%s' % i
sel_in, sel_out, sel_gpot, sel_spike = sel_dict[lpu_i]
sel = Selector.union(sel_in, sel_out, sel_gpot, sel_spike)
sel, sel_in, sel_out, sel_gpot, sel_spike = mod_sels[lpu_i]
m = MyModule(sel, sel_in, sel_out,
sel_gpot, sel_spike,
port_data=man.port_data, port_ctrl=man.port_ctrl,
Expand All @@ -168,28 +216,18 @@ def emulate(n_lpu, n_spike, n_gpot, steps):
for i, j in itertools.combinations(xrange(n_lpu), 2):
lpu_i = 'lpu%s' % i
lpu_j = 'lpu%s' % j
sel_in_i, sel_out_i, sel_gpot_i, sel_spike_i = sel_dict[lpu_i]
sel_in_j, sel_out_j, sel_gpot_j, sel_spike_j = sel_dict[lpu_j]

# The order of these two selectors is important; the individual 'from'
# and 'to' ports must line up properly for Pattern.from_concat to
# produce the right pattern:
sel_from = sel_out_i+sel_out_j
sel_to = sel_in_j+sel_in_i
man.log_info('before from_concat')
sel_from, sel_to, sel_in_i, sel_out_i, sel_gpot_i, sel_spike_i, \
sel_in_j, sel_out_j, sel_gpot_j, sel_spike_j = pat_sels[(lpu_i, lpu_j)]
pat = Pattern.from_concat(sel_from, sel_to,
from_sel=sel_from, to_sel=sel_to, data=1)

man.log_info('before setting attribs')
pat.interface[sel_in_i, 'interface', 'io'] = [0, 'out']
pat.interface[sel_out_i, 'interface', 'io'] = [0, 'in']
pat.interface[sel_in_i, 'interface', 'io'] = [0, 'in']
pat.interface[sel_out_i, 'interface', 'io'] = [0, 'out']
pat.interface[sel_gpot_i, 'interface', 'type'] = [0, 'gpot']
pat.interface[sel_spike_i, 'interface', 'type'] = [0, 'spike']
pat.interface[sel_in_j, 'interface', 'io'] = [1, 'out']
pat.interface[sel_out_j, 'interface', 'io'] = [1, 'in']
pat.interface[sel_in_j, 'interface', 'io'] = [1, 'in']
pat.interface[sel_out_j, 'interface', 'io'] = [1, 'out']
pat.interface[sel_gpot_j, 'interface', 'type'] = [1, 'gpot']
pat.interface[sel_spike_j, 'interface', 'type'] = [1, 'spike']
man.log_info('before connecting modules')
man.connect(man.modules[lpu_i], man.modules[lpu_j], pat, 0, 1)

man.start(steps=steps)
Expand Down

0 comments on commit 73f04eb

Please sign in to comment.