def run (self):
        """ run the application graph
        """
        # cannot run unless weights file exists
        if self._weights_file is None:
            print "run aborted: weights file not given"
            return

        # may need to reload initial weights file if
        # application graph was modified after load
        if not self._weights_loaded:
            if not self.read_Lens_weights_file (self._weights_file):
                print "run aborted: error reading weights file"

        # cannot run unless example set exists
        if self._ex_set is None:
            print "run aborted: no example set"
            return

        # cannot run unless examples have been loaded
        if not self._ex_set.examples_loaded:
            print "run aborted: examples not loaded"
            return

        # generate summary set, example and event data
        self._num_examples = self._ex_set.compile (self)
        if self._num_examples == 0:
            print "run aborted: error compiling example set"
            return

        # generate machine graph
        self.generate_machine_graph ()

        # run application based on the machine graph
        g.run (None)

        # wait for the application to finish
        print "running: waiting for application to finish"
        _txrx = g.transceiver ()
        _app_id = globals_variables.get_simulator ()._app_id
#lap        _running = _txrx.get_core_state_count (_app_id, CPUState.RUNNING)  
        _finished = _txrx.get_core_state_count (_app_id, CPUState.FINISHED)  
        while _finished < self._num_vertices:
            time.sleep (0.5)
            _error = _txrx.get_core_state_count\
                     (_app_id, CPUState.RUN_TIME_EXCEPTION)
            _wdog = _txrx.get_core_state_count (_app_id, CPUState.WATCHDOG)
            if _error > 0 or _wdog > 0:
                print "application stopped: cores failed ({}\
                     RTE, {} WDOG)".format (_error, _wdog)
                break
#lap            _running = _txrx.get_core_state_count (_app_id, CPUState.RUNNING)
            _finished = _txrx.get_core_state_count (_app_id, CPUState.FINISHED)  
Exemplo n.º 2
0
    def run(self, mbs, number_of_repeats):

        # setup system
        sim.setup(model_binary_module=(
            test_extra_monitor_core_data_extraction_multiple_locations),
                  n_chips_required=49 * 2)

        # build vertices
        locs = [(0, 0), (2, 2), (7, 7), (3, 0), (1, 0), (0, 1), (3, 3), (4, 4),
                (5, 5), (3, 5), (4, 0), (7, 4), (8, 4), (4, 8), (11, 11),
                (11, 0), (0, 11), (6, 3), (0, 6)]
        writers = list()

        for chip_x, chip_y in locs:
            writer = SDRAMWriter(mbs,
                                 constraint=ChipAndCoreConstraint(
                                     chip_x, chip_y))
            # add vertices to graph
            sim.add_machine_vertex_instance(writer)
            writers.append(writer)

        sim.run(12)

        # get placements for extraction
        placements = sim.placements()
        machine = sim.machine()

        extra_monitor_vertices = sim.globals_variables. \
            get_simulator()._last_run_outputs[
                'MemoryExtraMonitorVertices']
        extra_monitor_gatherers = sim.globals_variables. \
            get_simulator()._last_run_outputs[
                'MemoryMCGatherVertexToEthernetConnectedChipMapping']
        time_out_setter = extra_monitor_gatherers[(0, 0)]

        time_out_setter.set_cores_for_data_extraction(sim.transceiver(),
                                                      extra_monitor_vertices,
                                                      placements)

        for _ in range(0, number_of_repeats):
            for writer in writers:

                writer_placement = placements.get_placement_of_vertex(writer)
                writer_chip = \
                    machine.get_chip_at(writer_placement.x, writer_placement.y)
                writer_nearest_ethernet = machine.get_chip_at(
                    writer_chip.nearest_ethernet_x,
                    writer_chip.nearest_ethernet_y)

                receiver = None
                gatherer = extra_monitor_gatherers[(writer_nearest_ethernet.x,
                                                    writer_nearest_ethernet.y)]
                for vertex in extra_monitor_vertices:
                    placement = placements.get_placement_of_vertex(vertex)
                    if (placement.x == writer_placement.x
                            and placement.y == writer_placement.y):
                        receiver = vertex

                start = float(time.time())
                data = gatherer.get_data(
                    sim.transceiver(),
                    placements.get_placement_of_vertex(receiver),
                    self._get_data_region_address(sim.transceiver(),
                                                  writer_placement),
                    writer.mbs_in_bytes)
                end = float(time.time())

                print("time taken to extract {} MB is {}. MBS of {}".format(
                    mbs, end - start, (mbs * 8) / (end - start)))

                self._check_data(data)

        time_out_setter.unset_cores_for_data_extraction(
            sim.transceiver(), extra_monitor_vertices, placements)
# add verts to graph
sim.add_machine_vertex_instance(receiver)

# run forever (to allow better speed testing)
sim.run()

# get placements for extraction
placements = sim.placements()

# try getting data via mc transmission
start = None
end = None
data = None

sim.transceiver().set_watch_dog(False)

try:
    print("starting data gathering")
    start = float(time.time())
    data = receiver.get_data(
        sim.transceiver(),
        placements.get_placement_of_vertex(receiver))
    end = float(time.time())
    # end sim
    sim.stop()

    # print data
    seconds = float(end - start)
    speed = (mbs * 8) / seconds
    print("Read {} MB in {} seconds ({} Mb/s)".format(mbs, seconds, speed))
Exemplo n.º 4
0
def transceiver():
    return front_end.transceiver()
Exemplo n.º 5
0
# build and add edge to graph
sim.add_machine_edge_instance(MachineEdge(reader, receiver), "TRANSMIT")

# run forever (to allow better speed testing)
sim.run()

# get placements for extraction
placements = sim.placements()

# try getting data via mc transmission
start = None
end = None
data = None

sim.transceiver().set_watch_dog(False)

try:
    print("starting data gathering")
    start = float(time.time())
    data = receiver.get_data(sim.transceiver(),
                             placements.get_placement_of_vertex(reader))
    end = float(time.time())
    # end sim
    sim.stop()

    # check data is correct here
    ints = struct.unpack("<{}I".format(len(data) // 4), data)
    start_value = 0
    for value in ints:
        if value != start_value:
Exemplo n.º 6
0
placements = sim.placements()

# try getting data via mc transmission
start = None
end = None
data = None

# set time outs using new interface (
# clunky, but will be hidden in interface at later date)
extra_monitor_vertices = sim.globals_variables. \
    get_simulator()._last_run_outputs['MemoryExtraMonitorVertices']

try:
    print("starting data gathering")
    start = float(time.time())
    data = receiver.get_data(sim.transceiver(),
                             placements.get_placement_of_vertex(reader),
                             extra_monitor_vertices, placements)
    end = float(time.time())
    # end sim
    sim.stop()

    # print data
    seconds = float(end - start)
    speed = (mbs * 8) / seconds
    print("Read {} MB in {} seconds ({} Mb/s)".format(mbs, seconds, speed))

    # check data is correct here
    ints = struct.unpack("<{}I".format(len(data) // 4), data)
    start_value = 0
    for value in ints:
Exemplo n.º 7
0
def run_mcmc(model,
             data,
             n_samples,
             burn_in=2000,
             thinning=5,
             degrees_of_freedom=3.0,
             seed=None,
             n_chips=None,
             n_boards=None):
    """ Executes an MCMC model, returning the received samples

    :param model: The MCMCModel to be used
    :param data: The data to sample
    :param n_samples: The number of samples to generate
    :param burn_in:\
        no of MCMC transitions to reach apparent equilibrium before\
        generating inference samples
    :param thinning:\
        sampling rate i.e. 5 = 1 sample for 5 generated steps
    :param degrees_of_freedom:\
        The number of degrees of freedom to jump around with
    :param seed: The random seed to use
    :param n_chips: The number of chips to run the model on
    :param root_finder: Use the root finder by adding root finder vertices
    :param cholesky: Use the Cholesky algorithm by adding Cholesky vertices

    :return: The samples read
    :rtype: A numpy array with fields for each model state variable
    """

    # Set up the simulation
    g.setup(n_boards_required=n_boards,
            n_chips_required=n_chips,
            model_binary_module=model_binaries)

    # Get the number of cores available for use
    n_cores = 0
    machine = g.machine()

    # Create a coordinator for each board
    coordinators = dict()
    boards = dict()
    for chip in machine.ethernet_connected_chips:

        # Create a coordinator
        coordinator = MCMCCoordinatorVertex(model, data, n_samples, burn_in,
                                            thinning, degrees_of_freedom, seed)
        g.add_machine_vertex_instance(coordinator)

        # Put the coordinator on the Ethernet chip
        coordinator.add_constraint(ChipAndCoreConstraint(chip.x, chip.y))
        coordinators[chip.x, chip.y] = coordinator
        boards[chip.x, chip.y] = chip.ip_address

    # Go through all the chips and add the workhorses
    n_chips_on_machine = machine.n_chips
    n_workers = 0
    if (model.root_finder):
        n_root_finders = 0
    if (model.cholesky):
        n_cholesky = 0
    for chip in machine.chips:

        # Count the cores in the processor
        # (-1 if this chip also has a coordinator)
        n_cores = len([p for p in chip.processors if not p.is_monitor])
        if (chip.x, chip.y) in coordinators:
            n_cores -= 3  # coordinator and extra_monitor_support (2)
            if (model.root_finder):
                if (model.cholesky):
                    n_cores = n_cores // 3
                else:
                    n_cores = n_cores // 2
        else:
            n_cores -= 1  # just extra_monitor_support
            if (model.root_finder):
                if (model.cholesky):
                    n_cores = n_cores // 3
                else:
                    n_cores = n_cores // 2

        # Find the coordinator for the board (or 0, 0 if it is missing)
        eth_x = chip.nearest_ethernet_x
        eth_y = chip.nearest_ethernet_y
        coordinator = coordinators.get((eth_x, eth_y))
        if coordinator is None:
            print("Warning - couldn't find {}, {} for chip {}, {}".format(
                eth_x, eth_y, chip.x, chip.y))
            coordinator = coordinators[0, 0]
            print("Using coordinator ", coordinator)

        # hard-code remove some cores (chip power monitor etc.) just
        # to see what happens
#        n_cores -= non_worker_cores_per_chip
#        print 'n_cores: ', n_cores

# Add a vertex for each core
        for _ in range(n_cores):

            # Create the vertex and add it to the graph
            vertex = MCMCVertex(coordinator, model)
            n_workers += 1
            g.add_machine_vertex_instance(vertex)

            # Put the vertex on the same board as the coordinator
            vertex.add_constraint(ChipAndCoreConstraint(chip.x, chip.y))

            # Add an edge from the coordinator to the vertex, to send the data
            g.add_machine_edge_instance(MachineEdge(coordinator, vertex),
                                        coordinator.data_partition_name)

            # Add an edge from the vertex to the coordinator,
            # to send acknowledgement
            g.add_machine_edge_instance(MachineEdge(vertex, coordinator),
                                        coordinator.acknowledge_partition_name)

            if (model.root_finder):
                # Create a root finder vertex
                rf_vertex = MCMCRootFinderVertex(vertex, model)
                n_root_finders += 1
                g.add_machine_vertex_instance(rf_vertex)

                # put it on the same chip as the standard mcmc vertex?
                # no - put it on a "nearby" chip, however that works
                rf_vertex.add_constraint(ChipAndCoreConstraint(chip.x, chip.y))

                # Add an edge from mcmc vertex to root finder vertex,
                # to "send" the data - need to work this out
                g.add_machine_edge_instance(MachineEdge(vertex, rf_vertex),
                                            vertex.parameter_partition_name)

                # Add edge from root finder vertex back to mcmc vertex
                # to send acknowledgement / result - need to work this out
                g.add_machine_edge_instance(MachineEdge(rf_vertex, vertex),
                                            vertex.result_partition_name)

            if (model.cholesky):
                # Create a Cholesky vertex
                cholesky_vertex = MCMCCholeskyVertex(vertex, model)
                n_cholesky += 1
                g.add_machine_vertex_instance(cholesky_vertex)

                # put it on the same chip as the standard mcmc vertex?
                # no - put it on a "nearby" chip, however that works
                cholesky_vertex.add_constraint(
                    ChipAndCoreConstraint(chip.x, chip.y))

                # Add an edge from mcmc vertex to Cholesky vertex,
                # to "send" the data - need to work this out
                g.add_machine_edge_instance(
                    MachineEdge(vertex, cholesky_vertex),
                    vertex.cholesky_partition_name)

                # Add edge from Cholesky vertex back to mcmc vertex
                # to send acknowledgement / result - need to work this out
                g.add_machine_edge_instance(
                    MachineEdge(cholesky_vertex, vertex),
                    vertex.cholesky_result_partition_name)

    start_computing_time = time.time()

    logger.info("n_chips_on_machine {}".format(n_chips_on_machine))
    logger.info("Running {} worker cores".format(n_workers))
    if (model.root_finder):
        logger.info("Running {} root finder cores".format(n_root_finders))
    if (model.cholesky):
        logger.info("Running {} Cholesky cores".format(n_cholesky))

    # Run the simulation
    g.run_until_complete()

    mid_computing_time = time.time()

    # Wait for the application to finish
    txrx = g.transceiver()
    app_id = globals_variables.get_simulator()._app_id
    logger.info("Running {} worker cores".format(n_workers))
    if (model.root_finder):
        logger.info("Running {} root finder cores".format(n_root_finders))
    if (model.cholesky):
        logger.info("Running {} Cholesky cores".format(n_cholesky))
    logger.info("Waiting for application to finish...")
    running = txrx.get_core_state_count(app_id, CPUState.RUNNING)
    # there are now cores doing extra_monitor etc.
    non_worker_cores = n_chips_on_machine + (2 * len(boards))
    while running > non_worker_cores:
        time.sleep(0.5)
        error = txrx.get_core_state_count(app_id, CPUState.RUN_TIME_EXCEPTION)
        watchdog = txrx.get_core_state_count(app_id, CPUState.WATCHDOG)
        if error > 0 or watchdog > 0:
            error_msg = "Some cores have failed ({} RTE, {} WDOG)".format(
                error, watchdog)
            raise Exception(error_msg)
        running = txrx.get_core_state_count(app_id, CPUState.RUNNING)
        print('running: ', running)

    finish_computing_time = time.time()

    # Get the data back
    samples = dict()
    for coord, coordinator in iteritems(coordinators):
        samples[coord[0],
                coord[1]] = coordinator.read_samples(g.buffer_manager())

    # Close the machine
    g.stop()

    finish_time = time.time()

    # Note: this timing appears to be incorrect now; needs looking at
    print("Overhead time is %s seconds" % (start_computing_time - start_time))
    print("Computing time is %s seconds" %
          (finish_computing_time - start_computing_time))
    print("run_until_complete takes %s seconds" %
          (mid_computing_time - start_computing_time))
    print("Data collecting time is %s seconds" %
          (finish_time - finish_computing_time))
    print("Overall running time is %s seconds" % (finish_time - start_time))

    return samples
def run_model(data, n_chips=None, n_ihcan=0, fs=44100, resample_factor=1):

    # Set up the simulation
    g.setup(n_chips_required=n_chips, model_binary_module=model_binaries)

    # Get the number of cores available for use
    n_cores = 0
    machine = g.machine()

    # Create a OME for each chip
    boards = dict()

    #changed to lists to ensure data is read back in the same order that verticies are instantiated
    ihcans = list()

    cf_index = 0
    count = 0
    for chip in machine.chips:
        if count >= n_chips:
            break
        else:
            boards[chip.x, chip.y] = chip.ip_address

            for j in range(n_ihcan):
                ihcan = IHCANVertex(data[j][:], fs, resample_factor)
                g.add_machine_vertex_instance(ihcan)
                # constrain placement to local chip
                ihcan.add_constraint(ChipAndCoreConstraint(chip.x, chip.y))
                #ihcans[chip.x, chip.y,j] = ihcan
                ihcans.append(ihcan)

            count = count + 1

# Run the simulation
    g.run(None)

    # Wait for the application to finish
    txrx = g.transceiver()
    app_id = globals_variables.get_simulator()._app_id
    #logger.info("Running {} worker cores".format(n_workers))
    logger.info("Waiting for application to finish...")
    running = txrx.get_core_state_count(app_id, CPUState.RUNNING)
    while running > 0:
        time.sleep(0.5)
        error = txrx.get_core_state_count(app_id, CPUState.RUN_TIME_EXCEPTION)
        watchdog = txrx.get_core_state_count(app_id, CPUState.WATCHDOG)
        if error > 0 or watchdog > 0:
            error_msg = "Some cores have failed ({} RTE, {} WDOG)".format(
                error, watchdog)
            raise Exception(error_msg)
        running = txrx.get_core_state_count(app_id, CPUState.RUNNING)

    # Get the data back
    samples = list()
    progress = ProgressBar(len(ihcans), "Reading results")

    for ihcan in ihcans:
        samples.append(ihcan.read_samples(g.buffer_manager()))
        progress.update()
    progress.end()
    samples = numpy.hstack(samples)

    # Close the machine
    g.stop()

    print "channels running: ", len(ihcans) / 5.0
    print "output data: {} fibres with length {}".format(
        len(ihcans) * 2, len(samples))
    #if(len(samples) != len(ihcans)*2*numpy.floor(len(data[0][0])/100)*100*(1.0/resample_factor)):
    if (len(samples) !=
            len(ihcans) * 2 * numpy.floor(len(data[0][0]) / 96) * 96):
        #print "samples length {} isn't expected size {}".format(len(samples),len(ihcans)*2*numpy.floor(len(data[0][0])/100)*100*(1.0/resample_factor))
        print "samples length {} isn't expected size {}".format(
            len(samples),
            len(ihcans) * 2 * numpy.floor(len(data[0][0]) / 96) * 96)

    return samples
Exemplo n.º 9
0
                MachineEdge(vertices[x][y],
                            vertices[dest_x][dest_y],
                            label=compass), ConwayBasicCell.PARTITION_ID)

# run the simulation
front_end.run(runtime)

# get recorded data
recorded_data = dict()

# get the data per vertex
if not front_end.use_virtual_machine():
    for x in range(0, MAX_X_SIZE_OF_FABRIC):
        for y in range(0, MAX_Y_SIZE_OF_FABRIC):
            recorded_data[x, y] = vertices[x][y].get_data(
                front_end.transceiver(),
                front_end.placements().get_placement_of_vertex(vertices[x][y]),
                front_end.no_machine_time_steps())

    # visualise it in text form (bad but no vis this time)
    for time in range(0, runtime):
        print("at time {}".format(time))
        output = ""
        for y in range(MAX_X_SIZE_OF_FABRIC - 1, 0, -1):
            for x in range(0, MAX_Y_SIZE_OF_FABRIC):
                output += "X" if recorded_data[x, y][time] else " "
            output += "\n"
        print(output)
        print("\n\n")

# clear the machine