Beispiel #1
0
 def test_selector_concat_empty(self):
     s = Selector.concat(Selector(''), Selector(''))
     assert len(s) == 0
     assert not s.nonempty
     assert s.expanded == ((), )
     assert s.max_levels == 0
     assert s.str == ''
Beispiel #2
0
 def test_selector_add_empty(self):
     s = Selector('') + Selector('')
     assert len(s) == 0
     assert not s.nonempty
     assert s.expanded == ((), )
     assert s.max_levels == 0
     assert s.str == ''
 def test_selector_concat_empty(self):
     s = Selector.concat(Selector(''), Selector(''))
     self.assertEqual(len(s), 0)
     self.assertTrue(not s.nonempty)
     self.assertEqual(s.expanded, ((),))
     self.assertEqual(s.max_levels, 0)
     self.assertEqual(s.str, '')
Beispiel #4
0
 def test_selector_union_empty(self):
     a = Selector('')
     b = Selector('')
     c = Selector.union(a, b)
     assert len(c) == 0
     assert c.expanded == ((), )
     assert c.max_levels == 0
     assert c.str == ''
Beispiel #5
0
 def test_selector_union_empty_nonempty(self):
     a = Selector('')
     b = Selector('/x[0:3]')
     c = Selector.union(a, b)
     assert len(c) == 3
     assert c.expanded == (('x', 0), ('x', 1), ('x', 2))
     assert c.max_levels == 2
     assert c.str == '/x/0,/x/1,/x/2'
 def test_selector_union_empty(self):
     a = Selector('')
     b = Selector('')
     c = Selector.union(a, b)
     self.assertEqual(len(c), 0)
     self.assertEqual(c.expanded, ((),))
     self.assertEqual(c.max_levels, 0)
     self.assertEqual(c.str, '')
 def test_selector_union_empty_nonempty(self):
     a = Selector('')
     b = Selector('/x[0:3]')
     c = Selector.union(a, b)
     self.assertEqual(len(c), 3)
     self.assertEqual(c.expanded, (('x', 0), ('x', 1), ('x', 2)))
     self.assertEqual(c.max_levels, 2)
     self.assertEqual(c.str, '/x/0,/x/1,/x/2')
 def test_selector_iter(self):
     sel = Selector('/x[0:3]')
     self.assertSequenceEqual([s for s in sel],
                              [(('x', 0),),
                               (('x', 1),),
                               (('x', 2),)])
     sel = Selector('')
     self.assertSequenceEqual([s for s in sel],
                              [((),)])
Beispiel #9
0
    def test_selector_concat_nonempty(self):
        s = Selector.concat(Selector('[x,y]'), Selector('[0,1]'))
        assert len(s) == 2
        assert s.nonempty
        assert s.expanded == (('x', 0), ('y', 1))
        assert s.max_levels == 2
        assert s.str == '/x/0,/y/1'

        self.assertRaises(Exception, Selector.concat, Selector('[x,y]'),
                          Selector('[0:3]'))
Beispiel #10
0
    def test_selector_concat_nonempty(self):
        s = Selector.concat(Selector('[x,y]'), Selector('[0,1]'))
        self.assertEqual(len(s), 2)
        self.assertTrue(s.nonempty)
        self.assertEqual(s.expanded, (('x', 0), ('y', 1)))
        self.assertEqual(s.max_levels, 2)
        self.assertEqual(s.str, '/x/0,/y/1')

        self.assertRaises(Exception, Selector.concat, Selector('[x,y]'),
                          Selector('[0:3]'))
Beispiel #11
0
def make_sels(sel_in_gpot, sel_out_gpot, sel_in_spike, sel_out_spike):
    sel_in_gpot = Selector(sel_in_gpot)
    sel_out_gpot = Selector(sel_out_gpot)
    sel_in_spike = Selector(sel_in_spike)
    sel_out_spike = Selector(sel_out_spike)

    sel = sel_in_gpot + sel_out_gpot + sel_in_spike + sel_out_spike
    sel_in = sel_in_gpot + sel_in_spike
    sel_out = sel_out_gpot + sel_out_spike
    sel_gpot = sel_in_gpot + sel_out_gpot
    sel_spike = sel_in_spike + sel_out_spike

    return sel, sel_in, sel_out, sel_gpot, sel_spike
Beispiel #12
0
    def test_selector_prod_nonempty(self):
        s = Selector.prod(Selector('/x'), Selector('[0,1]'))
        assert len(s) == 2
        assert s.nonempty
        assert s.expanded == (('x', 0), ('x', 1))
        assert s.max_levels == 2
        assert s.str == '/x/0,/x/1'

        s = Selector.prod(Selector('/x[0:2]'), Selector('[a,b,c]'))
        assert len(s) == 6
        assert s.nonempty
        assert s.expanded == (('x', 0, 'a'), ('x', 0, 'b'), ('x', 0, 'c'),
                              ('x', 1, 'a'), ('x', 1, 'b'), ('x', 1, 'c'))
        assert s.str == '/x/0/a,/x/0/b,/x/0/c,/x/1/a,/x/1/b,/x/1/c'
Beispiel #13
0
    def test_selector_prod_nonempty(self):
        s = Selector.prod(Selector('/x'), Selector('[0,1]'))
        self.assertEqual(len(s), 2)
        self.assertTrue(s.nonempty)
        self.assertEqual(s.expanded, (('x', 0), ('x', 1)))
        self.assertEqual(s.max_levels, 2)
        self.assertEqual(s.str, '/x/0,/x/1')

        s = Selector.prod(Selector('/x[0:2]'), Selector('[a,b,c]'))
        self.assertEqual(len(s), 6)
        self.assertTrue(s.nonempty)
        self.assertEqual(s.expanded, (('x', 0, 'a'), ('x', 0, 'b'), ('x', 0, 'c'),
                              ('x', 1, 'a'), ('x', 1, 'b'), ('x', 1, 'c')))
        self.assertEqual(s.str, '/x/0/a,/x/0/b,/x/0/c,/x/1/a,/x/1/b,/x/1/c')
Beispiel #14
0
    def test_selector_add_nonempty(self):
        s = Selector('/foo[0]')+Selector('/bar[0]')
        self.assertEqual(len(s), 2)
        self.assertTrue(s.nonempty)
        self.assertEqual(s.expanded, (('foo', 0), ('bar', 0)))
        self.assertEqual(s.max_levels, 2)
        self.assertEqual(s.str, '/foo/0,/bar/0')

        s = Selector('')+Selector('/foo[0:0]')
        self.assertEqual(len(s), 0)
        self.assertTrue(not s.nonempty)
        self.assertEqual(s.expanded, ((),))
        self.assertEqual(s.max_levels, 0)
        self.assertEqual(s.str, '')
Beispiel #15
0
    def test_selector_add_nonempty(self):
        s = Selector('/foo[0]') + Selector('/bar[0]')
        assert len(s) == 2
        assert s.nonempty
        assert s.expanded == (('foo', 0), ('bar', 0))
        assert s.max_levels == 2
        assert s.str == '/foo/0,/bar/0'

        s = Selector('') + Selector('/foo[0:0]')
        assert len(s) == 0
        assert not s.nonempty
        assert s.expanded == ((), )
        assert s.max_levels == 0
        assert s.str == ''
Beispiel #16
0
 def test_selector_concat_empty(self):
     s = Selector.concat(Selector(''), Selector(''))
     self.assertEqual(len(s), 0)
     self.assertTrue(not s.nonempty)
     self.assertEqual(s.expanded, ((),))
     self.assertEqual(s.max_levels, 0)
     self.assertEqual(s.str, '')
Beispiel #17
0
 def test_selector_add_str(self):
     s = Selector.add_str('/foo[0]', '/bar[0]')
     self.assertEqual(len(s), 2)
     self.assertTrue(s.nonempty)
     self.assertEqual(s.expanded, (('foo', 0), ('bar', 0)))
     self.assertEqual(s.max_levels, 2)
     self.assertEqual(s.str, '/foo/0,/bar/0')
Beispiel #18
0
 def test_selector_prod_empty(self):
     s = Selector.prod(Selector(''), Selector(''))
     assert len(s) == 0
     assert not s.nonempty
     assert s.expanded == ((),)
     assert s.max_levels == 0
     assert s.str == ''
Beispiel #19
0
 def test_selector_add_str(self):
     s = Selector.add_str('/foo[0]', '/bar[0]')
     self.assertEqual(len(s), 2)
     self.assertTrue(s.nonempty)
     self.assertEqual(s.expanded, (('foo', 0), ('bar', 0)))
     self.assertEqual(s.max_levels, 2)
     self.assertEqual(s.str, '/foo/0,/bar/0')
Beispiel #20
0
    def test_expand_pad(self):
        result = self.sel.expand('/foo/bar[0:2],/moo', float('inf'))
        self.assertSequenceEqual(result, [('foo', 'bar', 0), ('foo', 'bar', 1),
                                          ('moo', '', '')])
        result = self.sel.expand('/foo/bar[0:2],/moo', 4)
        self.assertSequenceEqual(result, [('foo', 'bar', 0, ''),
                                          ('foo', 'bar', 1, ''),
                                          ('moo', '', '', '')])

        result = self.sel.expand(Selector('/foo/bar[0:2],/moo'), float('inf'))
        self.assertSequenceEqual(result, [('foo', 'bar', 0), ('foo', 'bar', 1),
                                          ('moo', '', '')])
        result = self.sel.expand(Selector('/foo/bar[0:2],/moo'), 4)
        self.assertSequenceEqual(result, [('foo', 'bar', 0, ''),
                                          ('foo', 'bar', 1, ''),
                                          ('moo', '', '', '')])
Beispiel #21
0
    def test_make_index_empty(self):
        idx = self.sel.make_index('')
        assert_index_equal(idx,
                           pd.MultiIndex(levels=[[]], labels=[[]], names=[0]))

        idx = self.sel.make_index(Selector(''))
        assert_index_equal(idx,
                           pd.MultiIndex(levels=[[]], labels=[[]], names=[0]))
Beispiel #22
0
 def test_selector_union_empty_nonempty(self):
     a = Selector('')
     b = Selector('/x[0:3]')
     c = Selector.union(a, b)
     self.assertEqual(len(c), 3)
     self.assertEqual(c.expanded, (('x', 0), ('x', 1), ('x', 2)))
     self.assertEqual(c.max_levels, 2)
     self.assertEqual(c.str, '/x/0,/x/1,/x/2')
Beispiel #23
0
 def test_selector_union_empty(self):
     a = Selector('')
     b = Selector('')
     c = Selector.union(a, b)
     self.assertEqual(len(c), 0)
     self.assertEqual(c.expanded, ((),))
     self.assertEqual(c.max_levels, 0)
     self.assertEqual(c.str, '')
Beispiel #24
0
 def test_selector_union_empty_nonempty(self):
     a = Selector('')
     b = Selector('/x[0:3]')
     c = Selector.union(a, b)
     assert len(c) == 3
     assert c.expanded == (('x', 0), ('x', 1), ('x', 2))
     assert c.max_levels == 2
     assert c.str == '/x/0,/x/1,/x/2'
Beispiel #25
0
 def test_selector_union_empty(self):
     a = Selector('')
     b = Selector('')
     c = Selector.union(a, b)
     assert len(c) == 0
     assert c.expanded == ((),)
     assert c.max_levels == 0
     assert c.str == ''
Beispiel #26
0
    def test_selector_concat_nonempty(self):
        s = Selector.concat(Selector('[x,y]'), Selector('[0,1]'))
        self.assertEqual(len(s), 2)
        self.assertTrue(s.nonempty)
        self.assertEqual(s.expanded, (('x', 0), ('y', 1)))
        self.assertEqual(s.max_levels, 2)
        self.assertEqual(s.str, '/x/0,/y/1')

        self.assertRaises(Exception, Selector.concat, Selector('[x,y]'),
                          Selector('[0:3]'))
Beispiel #27
0
    def test_selector_concat_nonempty(self):
        s = Selector.concat(Selector('[x,y]'), Selector('[0,1]'))
        assert len(s) == 2
        assert s.nonempty
        assert s.expanded == (('x', 0), ('y', 1))
        assert s.max_levels == 2
        assert s.str == '/x/0,/y/1'

        self.assertRaises(Exception, Selector.concat, Selector('[x,y]'),
                          Selector('[0:3]'))
Beispiel #28
0
    def test_trans_both(self):
        m0_sel_in_gpot = Selector('')
        m0_sel_in_spike = Selector('')
        m0_sel_out_gpot = Selector('/m0/out/gpot[0:5]')
        m0_sel_out_spike = Selector('/m0/out/spike[0:5]')
        m1_sel_in_gpot = Selector('/m1/in/gpot[0:5]')
        m1_sel_in_spike = Selector('/m1/in/spike[0:5]')
        m1_sel_out_gpot = Selector('')
        m1_sel_out_spike = Selector('')

        run_test(m0_sel_in_gpot, m0_sel_in_spike, m0_sel_out_gpot, m0_sel_out_spike,
                 m1_sel_in_gpot, m1_sel_in_spike, m1_sel_out_gpot, m1_sel_out_spike)
Beispiel #29
0
    def __init__(self, sel, sel_in_gpot, sel_in_spike, sel_out_gpot,
                 sel_out_spike, data_gpot, data_spike, port_data, port_ctrl,
                 port_time, id):
        super(TestModule,
              self).__init__(sel, Selector.add(sel_in_gpot, sel_out_gpot),
                             Selector.add(sel_in_spike, sel_out_spike),
                             data_gpot, data_spike,
                             ['interface', 'io', 'type'], port_data, port_ctrl,
                             port_time, id, None, True, True)
        assert SelectorMethods.is_in(sel_in_gpot, sel)
        assert SelectorMethods.is_in(sel_out_gpot, sel)
        assert SelectorMethods.are_disjoint(sel_in_gpot, sel_out_gpot)
        assert SelectorMethods.is_in(sel_in_spike, sel)
        assert SelectorMethods.is_in(sel_out_spike, sel)
        assert SelectorMethods.are_disjoint(sel_in_spike, sel_out_spike)

        self.interface[sel_in_gpot, 'io', 'type'] = ['in', 'gpot']
        self.interface[sel_out_gpot, 'io', 'type'] = ['out', 'gpot']
        self.interface[sel_in_spike, 'io', 'type'] = ['in', 'spike']
        self.interface[sel_out_spike, 'io', 'type'] = ['out', 'spike']
Beispiel #30
0
    def __init__(self, sel,
                 sel_in_gpot, sel_in_spike,
                 sel_out_gpot, sel_out_spike,
                 data_gpot, data_spike,
                 port_data, port_ctrl, port_time,
                 id):
        super(TestModule, self).__init__(sel,
                                       Selector.add(sel_in_gpot, sel_out_gpot),
                                       Selector.add(sel_in_spike, sel_out_spike),
                                       data_gpot, data_spike,
                                       ['interface', 'io', 'type'],
                                       port_data, port_ctrl, port_time,
                                       id, None, True, True)
        assert SelectorMethods.is_in(sel_in_gpot, sel)
        assert SelectorMethods.is_in(sel_out_gpot, sel)
        assert SelectorMethods.are_disjoint(sel_in_gpot, sel_out_gpot)
        assert SelectorMethods.is_in(sel_in_spike, sel)
        assert SelectorMethods.is_in(sel_out_spike, sel)
        assert SelectorMethods.are_disjoint(sel_in_spike, sel_out_spike)

        self.interface[sel_in_gpot, 'io', 'type'] = ['in', 'gpot']
        self.interface[sel_out_gpot, 'io', 'type'] = ['out', 'gpot']
        self.interface[sel_in_spike, 'io', 'type'] = ['in', 'spike']
        self.interface[sel_out_spike, 'io', 'type'] = ['out', 'spike']
Beispiel #31
0
    def test_selector_prod_nonempty(self):
        s = Selector.prod(Selector('/x'), Selector('[0,1]'))
        assert len(s) == 2
        assert s.nonempty
        assert s.expanded == (('x', 0), ('x', 1))
        assert s.max_levels == 2
        assert s.str == '/x/0,/x/1'

        s = Selector.prod(Selector('/x[0:2]'), Selector('[a,b,c]'))
        assert len(s) == 6
        assert s.nonempty
        assert s.expanded == (('x', 0, 'a'), ('x', 0, 'b'), ('x', 0, 'c'),
                              ('x', 1, 'a'), ('x', 1, 'b'), ('x', 1, 'c'))
        assert s.str == '/x/0/a,/x/0/b,/x/0/c,/x/1/a,/x/1/b,/x/1/c'
Beispiel #32
0
    def test_selector_prod_nonempty(self):
        s = Selector.prod(Selector('/x'), Selector('[0,1]'))
        self.assertEqual(len(s), 2)
        self.assertTrue(s.nonempty)
        self.assertEqual(s.expanded, (('x', 0), ('x', 1)))
        self.assertEqual(s.max_levels, 2)
        self.assertEqual(s.str, '/x/0,/x/1')

        s = Selector.prod(Selector('/x[0:2]'), Selector('[a,b,c]'))
        self.assertEqual(len(s), 6)
        self.assertTrue(s.nonempty)
        self.assertEqual(s.expanded, (('x', 0, 'a'), ('x', 0, 'b'), ('x', 0, 'c'),
                              ('x', 1, 'a'), ('x', 1, 'b'), ('x', 1, 'c')))
        self.assertEqual(s.str, '/x/0/a,/x/0/b,/x/0/c,/x/1/a,/x/1/b,/x/1/c')
Beispiel #33
0
        sel_out_spike = Selector(sel_out_spike)

        sel = sel_in_gpot+sel_out_gpot+sel_in_spike+sel_out_spike
        sel_in = sel_in_gpot+sel_in_spike
        sel_out = sel_out_gpot+sel_out_spike
        sel_gpot = sel_in_gpot+sel_out_gpot
        sel_spike = sel_in_spike+sel_out_spike

        return sel, sel_in, sel_out, sel_gpot, sel_spike

    logger = mpi.setup_logger(screen=True, file_name='neurokernel.log',
                              mpi_comm=MPI.COMM_WORLD, multiline=True)

    man = Manager()

    m1_sel_in_gpot = Selector('/a/in/gpot[0:2]')
    m1_sel_out_gpot = Selector('/a/out/gpot[0:2]')
    m1_sel_in_spike = Selector('/a/in/spike[0:2]')
    m1_sel_out_spike = Selector('/a/out/spike[0:2]')
    m1_sel, m1_sel_in, m1_sel_out, m1_sel_gpot, m1_sel_spike = \
        make_sels(m1_sel_in_gpot, m1_sel_out_gpot, m1_sel_in_spike, m1_sel_out_spike)
    N1_gpot = SelectorMethods.count_ports(m1_sel_gpot)
    N1_spike = SelectorMethods.count_ports(m1_sel_spike)

    m2_sel_in_gpot = Selector('/b/in/gpot[0:2]')
    m2_sel_out_gpot = Selector('/b/out/gpot[0:2]')
    m2_sel_in_spike = Selector('/b/in/spike[0:2]')
    m2_sel_out_spike = Selector('/b/out/spike[0:2]')
    m2_sel, m2_sel_in, m2_sel_out, m2_sel_gpot, m2_sel_spike = \
        make_sels(m2_sel_in_gpot, m2_sel_out_gpot, m2_sel_in_spike, m2_sel_out_spike)
    N2_gpot = SelectorMethods.count_ports(m2_sel_gpot)
Beispiel #34
0
    def test_transmit_spikes_one_to_many(self):
        m1_sel_in_gpot = Selector('')
        m1_sel_out_gpot = Selector('')
        m1_sel_in_spike = Selector('')
        m1_sel_out_spike = Selector('/m1/out/spike[0:4]')
        m1_sel, m1_sel_in, m1_sel_out, m1_sel_gpot, m1_sel_spike = \
            make_sels(m1_sel_in_gpot, m1_sel_out_gpot, m1_sel_in_spike, m1_sel_out_spike)
        N1_gpot = SelectorMethods.count_ports(m1_sel_gpot)
        N1_spike = SelectorMethods.count_ports(m1_sel_spike)

        m2_sel_in_gpot = Selector('')
        m2_sel_out_gpot = Selector('')
        m2_sel_in_spike = Selector('/m2/in/spike[0:4]')
        m2_sel_out_spike = Selector('')
        m2_sel, m2_sel_in, m2_sel_out, m2_sel_gpot, m2_sel_spike = \
            make_sels(m2_sel_in_gpot, m2_sel_out_gpot, m2_sel_in_spike, m2_sel_out_spike)
        N2_gpot = SelectorMethods.count_ports(m2_sel_gpot)
        N2_spike = SelectorMethods.count_ports(m2_sel_spike)

        m1_id = 'm1'
        self.man.add(MyModule1,
                     m1_id,
                     m1_sel,
                     m1_sel_in,
                     m1_sel_out,
                     m1_sel_gpot,
                     m1_sel_spike,
                     np.zeros(N1_gpot, dtype=np.double),
                     np.zeros(N1_spike, dtype=int),
                     device=0,
                     debug=debug,
                     out_spike_data=[1, 0, 0, 0])

        f, out_file_name = tempfile.mkstemp()
        os.close(f)

        m2_id = 'm2'
        self.man.add(MyModule2,
                     m2_id,
                     m2_sel,
                     m2_sel_in,
                     m2_sel_out,
                     m2_sel_gpot,
                     m2_sel_spike,
                     np.zeros(N2_gpot, dtype=np.double),
                     np.zeros(N2_spike, dtype=int),
                     device=1,
                     debug=debug,
                     out_file_name=out_file_name)

        pat12 = Pattern(m1_sel, m2_sel)
        pat12.interface[m1_sel_out_gpot] = [0, 'in', 'gpot']
        pat12.interface[m1_sel_in_gpot] = [0, 'out', 'gpot']
        pat12.interface[m1_sel_out_spike] = [0, 'in', 'spike']
        pat12.interface[m1_sel_in_spike] = [0, 'out', 'spike']
        pat12.interface[m2_sel_in_gpot] = [1, 'out', 'gpot']
        pat12.interface[m2_sel_out_gpot] = [1, 'in', 'gpot']
        pat12.interface[m2_sel_in_spike] = [1, 'out', 'spike']
        pat12.interface[m2_sel_out_spike] = [1, 'in', 'spike']
        pat12['/m1/out/spike[0]', '/m2/in/spike[0]'] = 1
        pat12['/m1/out/spike[0]', '/m2/in/spike[1]'] = 1
        pat12['/m1/out/spike[0]', '/m2/in/spike[2]'] = 1
        pat12['/m1/out/spike[0]', '/m2/in/spike[3]'] = 1
        self.man.connect(m1_id, m2_id, pat12, 0, 1)

        # Run emulation for 2 steps:
        self.man.spawn()
        self.man.start(2)
        self.man.wait()

        # Get output of m2:
        with open(out_file_name, 'r') as f:
            output = pickle.load(f)

        os.remove(out_file_name)
        self.assertSequenceEqual(list(output), [1, 1, 1, 1])
Beispiel #35
0
 def test_selector_identifiers(self):
     a = Selector('/x[0:3]')
     assert a.identifiers == ['/x/0', '/x/1', '/x/2']
Beispiel #36
0
 def test_select_Selector(self):
     result = self.sel.select(self.df, Selector('/foo/qux[0:2]'))
     idx = pd.MultiIndex.from_tuples([('foo','qux',0),
                                      ('foo','qux',1)], names=[0, 1, 2])
     assert_frame_equal(result, self.df.loc[idx])
Beispiel #37
0
 def test_selector_identifiers(self):
     a = Selector('/x[0:3]')
     self.assertEqual(a.identifiers, ['/x/0', '/x/1', '/x/2'])
Beispiel #38
0
    def test_make_index_empty(self):
        idx = self.sel.make_index('')
        assert_index_equal(idx, pd.Index([], dtype='object'))

        idx = self.sel.make_index(Selector(''))
        assert_index_equal(idx, pd.Index([], dtype='object'))
Beispiel #39
0
def emulate(n_lpu, n_spike, n_gpot, steps):
    """
    Benchmark inter-LPU communication throughput.

    Each LPU is configured to use a different local GPU.

    Parameters
    ----------
    n_lpu : int
        Number of LPUs. Must be at least 2 and no greater than the number of
        local GPUs.
    n_spike : int
        Total number of input and output spiking ports any
        single LPU exposes to any other LPU. Each LPU will therefore
        have 2*n_spike*(n_lpu-1) total spiking ports.
    n_gpot : int
        Total number of input and output graded potential ports any
        single LPU exposes to any other LPU. Each LPU will therefore
        have 2*n_gpot*(n_lpu-1) total graded potential ports.
    steps : int
        Number of steps to execute.

    Returns
    -------
    average_throughput, total_throughput : float
        Average per-step and total received data throughput in bytes/seconds.
    exec_time : float
        Execution time in seconds.
    """

    # Time everything starting with manager initialization:
    start_all = time.time()

    # Check whether a sufficient number of GPUs are available:
    drv.init()
    if n_lpu > drv.Device.count():
        raise RuntimeError('insufficient number of available GPUs.')

    # Set up manager:
    man = Manager()

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

    # Set up modules:
    for i in xrange(n_lpu):
        lpu_i = 'lpu%s' % i
        sel, sel_in, sel_out, sel_gpot, sel_spike = mod_sels[lpu_i]
        sel = Selector.union(sel_in, sel_out, sel_gpot, sel_spike)
        man.add(MyModule, lpu_i, sel, sel_in, sel_out,
                sel_gpot, sel_spike,
                None, None, ['interface', 'io', 'type'],
                CTRL_TAG, GPOT_TAG, SPIKE_TAG,
                device=i, time_sync=True)

    # Set up connections between module pairs:
    for i, j in itertools.combinations(xrange(n_lpu), 2):
        lpu_i = 'lpu%s' % i
        lpu_j = 'lpu%s' % j
        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)
        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, '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.connect(lpu_i, lpu_j, pat, 0, 1, compat_check=False)

    man.spawn()
    start_main = time.time()
    man.start(steps)
    man.wait()
    stop_main = time.time()
    return man.average_step_sync_time, (time.time()-start_all), \
        (stop_main-start_main), (man.stop_time-man.start_time)
Beispiel #40
0
def gen_sels(conn_mat, scaling=1):
    """
    Generate port selectors for LPUs in benchmark test.

    Parameters
    ----------
    conn_mat : numpy.ndarray
        Square array containing numbers of directed spiking port connections 
        between LPUs (which correspond to the row and column indices). 
    scaling : int
        Scaling factor; multiply all connection numbers by this value.

    Returns
    -------
    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.
    """

    conn_mat = np.asarray(conn_mat)
    r, c = conn_mat.shape
    assert r == c
    n_lpu = r

    assert scaling > 0 and isinstance(scaling, numbers.Integral)
    conn_mat *= scaling

    # Construct selectors describing the ports exposed by each module:
    mod_sels = {}
    for i in xrange(n_lpu):
        lpu_id = 'lpu%s' % i

        # Structure ports as
        # /lpu_id/in_or_out/spike_or_gpot/other_lpu_id/[0:n_spike]
        # where in_or_out is relative to module i:
        sel_in_gpot = Selector('')
        sel_out_gpot = Selector('')

        sel_in_spike = \
            Selector(','.join(['/lpu%i/in/spike/lpu%i/[0:%i]' % (i, j, n) for j, n in \
                               enumerate(conn_mat[:, i]) if (j != i and n != 0)]))
        sel_out_spike = \
            Selector(','.join(['/lpu%i/out/spike/lpu%i/[0:%i]' % (i, j, n) for j, n in \
                               enumerate(conn_mat[i, :]) if (j != i and n != 0)]))

        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))

    # Construct selectors describing the ports connected by each pattern:
    pat_sels = {}
    for i, j in itertools.combinations(xrange(n_lpu), 2):
        lpu_i = 'lpu%s' % i
        lpu_j = 'lpu%s' % j

        # The pattern's input ports are labeled "../out.." because that selector
        # describes the output ports of the connected module's interface:
        sel_in_gpot_i = Selector('')
        sel_out_gpot_i = Selector('')
        sel_in_gpot_j = Selector('')
        sel_out_gpot_j = Selector('')

        sel_in_spike_i = Selector('/%s/out/spike/%s[0:%i]' %
                                  (lpu_i, lpu_j, conn_mat[i, j]))
        sel_out_spike_i = Selector('/%s/in/spike/%s[0:%i]' %
                                   (lpu_i, lpu_j, conn_mat[j, i]))
        sel_in_spike_j = Selector('/%s/out/spike/%s[0:%i]' %
                                  (lpu_j, lpu_i, conn_mat[j, i]))
        sel_out_spike_j = Selector('/%s/in/spike/%s[0:%i]' %
                                   (lpu_j, lpu_i, conn_mat[i, 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 = 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)

        # Exclude scenarios where the "from" or "to" selector is empty (and
        # therefore cannot be used to construct a pattern):
        if len(sel_from) and len(sel_to):
            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 gen_sels(conn_mat, scaling=1):
    """
    Generate port selectors for LPUs in benchmark test.

    Parameters
    ----------
    conn_mat : numpy.ndarray
        Square array containing numbers of directed spiking port connections 
        between LPUs (which correspond to the row and column indices). 
    scaling : int
        Scaling factor; multiply all connection numbers by this value.

    Returns
    -------
    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.
    """

    conn_mat = np.asarray(conn_mat)
    r, c = conn_mat.shape
    assert r == c
    n_lpu = r

    assert scaling > 0 and isinstance(scaling, numbers.Integral)
    conn_mat *= scaling

    # Construct selectors describing the ports exposed by each module:
    mod_sels = {}
    for i in xrange(n_lpu):
        lpu_id = 'lpu%s' % i

        # Structure ports as 
        # /lpu_id/in_or_out/spike_or_gpot/other_lpu_id/[0:n_spike]
        # where in_or_out is relative to module i:
        sel_in_gpot = Selector('')
        sel_out_gpot = Selector('')

        sel_in_spike = \
            Selector(','.join(['/lpu%i/in/spike/lpu%i/[0:%i]' % (i, j, n) for j, n in \
                               enumerate(conn_mat[:, i]) if (j != i and n != 0)]))
        sel_out_spike = \
            Selector(','.join(['/lpu%i/out/spike/lpu%i/[0:%i]' % (i, j, n) for j, n in \
                               enumerate(conn_mat[i, :]) if (j != i and n != 0)]))
                                                                         
        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))

    # Construct selectors describing the ports connected by each pattern:
    pat_sels = {}
    for i, j in itertools.combinations(xrange(n_lpu), 2):
        lpu_i = 'lpu%s' % i
        lpu_j = 'lpu%s' % j

        # The pattern's input ports are labeled "../out.." because that selector
        # describes the output ports of the connected module's interface:
        sel_in_gpot_i = Selector('')
        sel_out_gpot_i = Selector('')
        sel_in_gpot_j = Selector('')
        sel_out_gpot_j = Selector('')

        sel_in_spike_i = Selector('/%s/out/spike/%s[0:%i]' % (lpu_i, lpu_j,
                                                              conn_mat[i, j]))
        sel_out_spike_i = Selector('/%s/in/spike/%s[0:%i]' % (lpu_i, lpu_j,
                                                              conn_mat[j, i]))
        sel_in_spike_j = Selector('/%s/out/spike/%s[0:%i]' % (lpu_j, lpu_i,
                                                              conn_mat[j, i]))
        sel_out_spike_j = Selector('/%s/in/spike/%s[0:%i]' % (lpu_j, lpu_i,
                                                              conn_mat[i, 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 = 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)

        # Exclude scenarios where the "from" or "to" selector is empty (and
        # therefore cannot be used to construct a pattern):
        if len(sel_from) and len(sel_to):
            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
Beispiel #42
0
check_compatibility = False
if check_compatibility:
    lpu_name_to_sel_in_gpot = {}
    lpu_name_to_sel_in_spike = {}
    lpu_name_to_sel_out_gpot = {}
    lpu_name_to_sel_out_spike = {}
    lpu_name_to_sel_in = {}
    lpu_name_to_sel_out = {}
    lpu_name_to_sel_gpot = {}
    lpu_name_to_sel_spike = {}
    lpu_name_to_sel = {}

    for name in lpu_name_list:
        n_dict = lpu_name_to_n_dict[name]
        lpu_name_to_sel_in_gpot[name] = \
            Selector(LPU.extract_in_gpot(n_dict))
        lpu_name_to_sel_in_spike[name] = \
            Selector(LPU.extract_in_spk(n_dict))
        lpu_name_to_sel_out_gpot[name] = \
            Selector(LPU.extract_out_gpot(n_dict))
        lpu_name_to_sel_out_spike[name] = \
            Selector(LPU.extract_out_spk(n_dict))
        lpu_name_to_sel_in[name] = \
            Selector.union(lpu_name_to_sel_in_gpot[name], lpu_name_to_sel_in_spike[name])
        lpu_name_to_sel_out[name] = \
            Selector.union(lpu_name_to_sel_out_gpot[name], lpu_name_to_sel_out_spike[name])
        lpu_name_to_sel_gpot[name] = \
            Selector.union(lpu_name_to_sel_in_gpot[name], lpu_name_to_sel_out_gpot[name])
        lpu_name_to_sel_spike[name] = \
            Selector.union(lpu_name_to_sel_in_spike[name], lpu_name_to_sel_out_spike[name])
        lpu_name_to_sel[name] = Selector.union(lpu_name_to_sel_in[name],
Beispiel #43
0
def gen_sels(n_lpu, n_spike, n_gpot):
    """
    Generate port selectors for LPUs in benchmark test.

    Parameters
    ----------
    n_lpu : int
        Number of LPUs. Must be at least 2.
    n_spike : int
        Total number of input and output spiking ports any
        single LPU exposes to any other LPU. Each LPU will therefore
        have 2*n_spike*(n_lpu-1) total spiking ports.
    n_gpot : int
        Total number of input and output graded potential ports any
        single LPU exposes to any other LPU. Each LPU will therefore
        have 2*n_gpot*(n_lpu-1) total graded potential ports.

    Returns
    -------
    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

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

    for i in xrange(n_lpu):
        lpu_id = 'lpu%s' % i
        other_lpu_ids = '['+','.join(['lpu%s' % j for j in xrange(n_lpu) if j != i])+']'

        # Structure ports as 
        # /lpu_id/in_or_out/spike_or_gpot/[other_lpu_ids,..]/[0:n_spike]
        sel_in_gpot = Selector('/%s/in/gpot/%s/[0:%i]' % \
                    (lpu_id, other_lpu_ids, n_gpot))
        sel_in_spike = Selector('/%s/in/spike/%s/[0:%i]' % \
                    (lpu_id, other_lpu_ids, n_spike))
        sel_out_gpot = Selector('/%s/out/gpot/%s/[0:%i]' % \
                    (lpu_id, other_lpu_ids, n_gpot))
        sel_out_spike = Selector('/%s/out/spike/%s/[0:%i]' % \
                    (lpu_id, other_lpu_ids, n_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))

    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