Exemple #1
0
    conn = Connectivity(N_gpot_0, N_spike_0, N_gpot_1, N_spike_1, 1,
                        lpu_dict[lpu_0]['id'], lpu_dict[lpu_1]['id'],
                        syn_params)

    # Define synapses between spiking neurons in both directions:
    for id_src, id_dest, N_spike_src, N_spike_dest in \
      [(lpu_dict[lpu_0]['id'], lpu_dict[lpu_1]['id'], N_spike_0, N_spike_1),
        (lpu_dict[lpu_1]['id'], lpu_dict[lpu_0]['id'], N_spike_1, N_spike_0)]:
        id_start = 0
        for id, (i, j) in enumerate(itertools.product(xrange(N_spike_src),
                                                      xrange(N_spike_dest)), id_start):
            conn[id_src, 'spike', i, id_dest, 'spike', j] = 1
            conn[id_src, 'spike', i, id_dest, 'spike', j, 0, 'name'] = \
                'syn_%s:%s_%s:%s' % (id_src, i, id_dest, j)
            conn[id_src, 'spike', i, id_dest, 'spike', j, 0, 'model'] = 'AlphaSynapse'

            conn[id_src, 'spike', i, id_dest, 'spike', j, 0, 'ad'] = 0.19*1000
            conn[id_src, 'spike', i, id_dest, 'spike', j, 0, 'ar'] = 1.1*100
            conn[id_src, 'spike', i, id_dest, 'spike', j, 0, 'class'] = 0 # spike->spike            
            conn[id_src, 'spike', i, id_dest, 'spike', j, 0, 'conductance'] = True
            conn[id_src, 'spike', i, id_dest, 'spike', j, 0, 'gmax'] = 0.003
            conn[id_src, 'spike', i, id_dest, 'spike', j, 0, 'id'] = id
            conn[id_src, 'spike', i, id_dest, 'spike', j, 0, 'reverse'] = 0.065
        id_start = id+1

    man.connect(lpu_dict[lpu_0]['lpu'], lpu_dict[lpu_1]['lpu'], conn)

man.start(steps=steps)
man.stop()
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 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:
    for i in xrange(n_lpu):
        lpu_i = 'lpu%s' % i
        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,
                     port_time=man.port_time,
                     id=lpu_i, device=i, debug=args.debug)
        man.add_mod(m)

    # 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(man.modules[lpu_i], man.modules[lpu_j], pat, 0, 1,
                compat_check=False)

    start_main = time.time()
    man.start(steps=steps)
    man.stop()
    stop_main = time.time()
    t = man.get_throughput()
    return t[0], (time.time()-start_all), (stop_main-start_main), t[3]
Exemple #3
0
def 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):

    # Create test module classes with a queue installed in the destination
    # module to check that data was correctly propagated:
    class TestModule0(TestModule):
        def __init__(self, *args, **kwargs):
            super(TestModule0, self).__init__(*args, **kwargs)
            self.q = Queue()

        def run_step(self):
            self.log_info('saving data to queue before run step')
            if self.steps > 0:
                self.q.put((self.pm['gpot'][self._out_port_dict['gpot']['m1']].copy(),
                            self.pm['spike'][self._out_port_dict['spike']['m1']].copy()))
            super(TestModule0, self).run_step()

    class TestModule1(TestModule):
        def __init__(self, *args, **kwargs):
            super(TestModule1, self).__init__(*args, **kwargs)
            self.q = Queue()

        def run_step(self):
            super(TestModule1, self).run_step()
            self.log_info('saving data to queue after run step')
            if self.steps > 0:
                self.q.put((self.pm['gpot'][self._in_port_dict['gpot']['m0']].copy(),
                            self.pm['spike'][self._in_port_dict['spike']['m0']].copy()))

    m0_sel_gpot = m0_sel_in_gpot+m0_sel_out_gpot
    m0_sel_spike = m0_sel_in_spike+m0_sel_out_spike
    m0_sel = m0_sel_in_gpot+m0_sel_in_spike+m0_sel_out_gpot+m0_sel_out_spike
    m0_data_gpot = np.ones(len(m0_sel_gpot), np.double)
    m0_data_spike = np.ones(len(m0_sel_spike), np.int32)

    m1_sel_gpot = m1_sel_in_gpot+m1_sel_out_gpot
    m1_sel_spike = m1_sel_in_spike+m1_sel_out_spike
    m1_sel = m1_sel_in_gpot+m1_sel_in_spike+m1_sel_out_gpot+m1_sel_out_spike
    m1_data_gpot = np.zeros(len(m1_sel_gpot), np.double)
    m1_data_spike = np.zeros(len(m1_sel_spike), np.int32)

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

    # Add modules:
    m0 = TestModule0(m0_sel, m0_sel_in_gpot, m0_sel_in_spike,
                     m0_sel_out_gpot, m0_sel_out_spike, 
                     m0_data_gpot, m0_data_spike,
                     man.port_data, man.port_ctrl, man.port_time,
                     id='m0')
    man.add_mod(m0)
    m1 = TestModule1(m1_sel, m1_sel_in_gpot, m1_sel_in_spike,
                     m1_sel_out_gpot, m1_sel_out_spike,
                     m1_data_gpot, m1_data_spike,
                     man.port_data, man.port_ctrl, man.port_time,
                     id='m1')
    man.add_mod(m1)

    # Connect the modules:
    pat = Pattern(m0_sel, m1_sel)
    pat.interface[m0_sel_in_gpot] = [0, 'in', 'gpot']
    pat.interface[m0_sel_out_gpot] = [0, 'out', 'gpot']
    pat.interface[m0_sel_in_spike] = [0, 'in', 'spike']
    pat.interface[m0_sel_out_spike] = [0, 'out', 'spike']

    pat.interface[m1_sel_in_gpot] = [1, 'in', 'gpot']
    pat.interface[m1_sel_out_gpot] = [1, 'out', 'gpot']
    pat.interface[m1_sel_in_spike] = [1, 'in', 'spike']
    pat.interface[m1_sel_out_spike] = [1, 'out', 'spike']
    for sel_from, sel_to in zip(m0_sel_out_gpot,
                                m1_sel_in_gpot):
        if not (sel_from == ((),) or sel_to == ((),)):
            pat[sel_from, sel_to] = 1
    for sel_from, sel_to in zip(m0_sel_out_spike,
                                m1_sel_in_spike):
        if not (sel_from == ((),) or sel_to == ((),)):
            pat[sel_from, sel_to] = 1

    man.connect(m0, m1, pat, 0, 1)

    # Execute exactly two steps; m0 transmits data during the first step, which
    # should be received by m1 during the second step:
    man.start(steps=2)
    man.stop()

    # Forcibly terminate all processes that are still alive:
    if m0.is_alive():
        m0.terminate()
    if m1.is_alive():
        m1.terminate()
    for b in man.brokers.values():
        if b.is_alive():
            b.terminate()

    # Check that data was propagated correctly:
    m0_data_gpot_after, m0_data_spike_after = m0.q.get()
    m1_data_gpot_after, m1_data_spike_after = m1.q.get()
    assert all(m0_data_gpot_after == m1_data_gpot_after)
    assert all(m0_data_spike_after == m1_data_spike_after)
Exemple #4
0
def 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):

    # Create test module classes with a queue installed in the destination
    # module to check that data was correctly propagated:
    class TestModule0(TestModule):
        def __init__(self, *args, **kwargs):
            super(TestModule0, self).__init__(*args, **kwargs)
            self.q = Queue()

        def run_step(self):
            self.log_info('saving data to queue before run step')
            if self.steps > 0:
                self.q.put(
                    (self.pm['gpot'][self._out_port_dict['gpot']['m1']].copy(),
                     self.pm['spike'][self._out_port_dict['spike']
                                      ['m1']].copy()))
            super(TestModule0, self).run_step()

    class TestModule1(TestModule):
        def __init__(self, *args, **kwargs):
            super(TestModule1, self).__init__(*args, **kwargs)
            self.q = Queue()

        def run_step(self):
            super(TestModule1, self).run_step()
            self.log_info('saving data to queue after run step')
            if self.steps > 0:
                self.q.put(
                    (self.pm['gpot'][self._in_port_dict['gpot']['m0']].copy(),
                     self.pm['spike'][self._in_port_dict['spike']
                                      ['m0']].copy()))

    m0_sel_gpot = m0_sel_in_gpot + m0_sel_out_gpot
    m0_sel_spike = m0_sel_in_spike + m0_sel_out_spike
    m0_sel = m0_sel_in_gpot + m0_sel_in_spike + m0_sel_out_gpot + m0_sel_out_spike
    m0_data_gpot = np.ones(len(m0_sel_gpot), np.double)
    m0_data_spike = np.ones(len(m0_sel_spike), np.int32)

    m1_sel_gpot = m1_sel_in_gpot + m1_sel_out_gpot
    m1_sel_spike = m1_sel_in_spike + m1_sel_out_spike
    m1_sel = m1_sel_in_gpot + m1_sel_in_spike + m1_sel_out_gpot + m1_sel_out_spike
    m1_data_gpot = np.zeros(len(m1_sel_gpot), np.double)
    m1_data_spike = np.zeros(len(m1_sel_spike), np.int32)

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

    # Add modules:
    m0 = TestModule0(m0_sel,
                     m0_sel_in_gpot,
                     m0_sel_in_spike,
                     m0_sel_out_gpot,
                     m0_sel_out_spike,
                     m0_data_gpot,
                     m0_data_spike,
                     man.port_data,
                     man.port_ctrl,
                     man.port_time,
                     id='m0')
    man.add_mod(m0)
    m1 = TestModule1(m1_sel,
                     m1_sel_in_gpot,
                     m1_sel_in_spike,
                     m1_sel_out_gpot,
                     m1_sel_out_spike,
                     m1_data_gpot,
                     m1_data_spike,
                     man.port_data,
                     man.port_ctrl,
                     man.port_time,
                     id='m1')
    man.add_mod(m1)

    # Connect the modules:
    pat = Pattern(m0_sel, m1_sel)
    pat.interface[m0_sel_in_gpot] = [0, 'in', 'gpot']
    pat.interface[m0_sel_out_gpot] = [0, 'out', 'gpot']
    pat.interface[m0_sel_in_spike] = [0, 'in', 'spike']
    pat.interface[m0_sel_out_spike] = [0, 'out', 'spike']

    pat.interface[m1_sel_in_gpot] = [1, 'in', 'gpot']
    pat.interface[m1_sel_out_gpot] = [1, 'out', 'gpot']
    pat.interface[m1_sel_in_spike] = [1, 'in', 'spike']
    pat.interface[m1_sel_out_spike] = [1, 'out', 'spike']
    for sel_from, sel_to in zip(m0_sel_out_gpot, m1_sel_in_gpot):
        if not (sel_from == ((), ) or sel_to == ((), )):
            pat[sel_from, sel_to] = 1
    for sel_from, sel_to in zip(m0_sel_out_spike, m1_sel_in_spike):
        if not (sel_from == ((), ) or sel_to == ((), )):
            pat[sel_from, sel_to] = 1

    man.connect(m0, m1, pat, 0, 1)

    # Execute exactly two steps; m0 transmits data during the first step, which
    # should be received by m1 during the second step:
    man.start(steps=2)
    man.stop()

    # Forcibly terminate all processes that are still alive:
    if m0.is_alive():
        m0.terminate()
    if m1.is_alive():
        m1.terminate()
    for b in man.brokers.values():
        if b.is_alive():
            b.terminate()

    # Check that data was propagated correctly:
    m0_data_gpot_after, m0_data_spike_after = m0.q.get()
    m1_data_gpot_after, m1_data_spike_after = m1.q.get()
    assert all(m0_data_gpot_after == m1_data_gpot_after)
    assert all(m0_data_spike_after == m1_data_spike_after)
    # Define synapses between spiking neurons in both directions:
    for id_src, id_dest, N_spike_src, N_spike_dest in \
      [(lpu_dict[lpu_0]['id'], lpu_dict[lpu_1]['id'], N_spike_0, N_spike_1),
        (lpu_dict[lpu_1]['id'], lpu_dict[lpu_0]['id'], N_spike_1, N_spike_0)]:
        id_start = 0
        for id, (i, j) in enumerate(
                itertools.product(xrange(N_spike_src), xrange(N_spike_dest)),
                id_start):
            conn[id_src, 'spike', i, id_dest, 'spike', j] = 1
            conn[id_src, 'spike', i, id_dest, 'spike', j, 0, 'name'] = \
                'syn_%s:%s_%s:%s' % (id_src, i, id_dest, j)
            conn[id_src, 'spike', i, id_dest, 'spike', j, 0,
                 'model'] = 'AlphaSynapse'

            conn[id_src, 'spike', i, id_dest, 'spike', j, 0,
                 'ad'] = 0.19 * 1000
            conn[id_src, 'spike', i, id_dest, 'spike', j, 0, 'ar'] = 1.1 * 100
            conn[id_src, 'spike', i, id_dest, 'spike', j, 0,
                 'class'] = 0  # spike->spike
            conn[id_src, 'spike', i, id_dest, 'spike', j, 0,
                 'conductance'] = True
            conn[id_src, 'spike', i, id_dest, 'spike', j, 0, 'gmax'] = 0.003
            conn[id_src, 'spike', i, id_dest, 'spike', j, 0, 'id'] = id
            conn[id_src, 'spike', i, id_dest, 'spike', j, 0, 'reverse'] = 0.065
        id_start = id + 1

    man.connect(lpu_dict[lpu_0]['lpu'], lpu_dict[lpu_1]['lpu'], conn)

man.start(steps=steps)
man.stop()