def load_data_onto_vertices(data, number_of_chips, columns, num_string_cols, function_id): #get rid of the headers del data[0] num_processors = number_of_chips * 16 num_data_rows = len(data) rows_per_core = int(math.floor(num_data_rows/num_processors)) leftovers = num_data_rows % num_processors row_count = 0 vertices = [] for core in range(0, num_processors): #initiate if this is the first vertex in the circle initiate = 0 if core%16 == 0: initiate = 1 #distribute the data evenly among the cores add_leftover = 0 if core < leftovers: add_leftover = 1 data_parcel = [] for row in range(0, rows_per_core + add_leftover): data_row = [] for z in range(0, len(columns)): data_row.append(data[row_count][columns[z]]) row_count = row_count + 1 data_parcel.append(data_row) #load information onto the vertex current_vertex = front_end.add_machine_vertex( Vertex, { "columns": len(columns), "rows": rows_per_core + add_leftover, "string_size": 16, "num_string_cols": num_string_cols, "entries": data_parcel, "initiate": initiate, "function_id": function_id, "state": core }, label="Data packet at x {}".format(core)) vertices.append(current_vertex) make_circle(vertices, len(vertices), front_end)
import logging import os logger = logging.getLogger(__name__) front_end.setup(n_chips_required=None, model_binary_folder=os.path.dirname(__file__)) # calculate total number of 'free' cores for the given board # (i.e. does not include those busy with SARK or reinjection) total_number_of_cores = \ front_end.get_number_of_available_cores_on_machine() # fill all cores with a HelloWorldVertex each for x in range(0, total_number_of_cores): front_end.add_machine_vertex(HelloWorldVertex, {}, label="Hello World at x {}".format(x)) front_end.run(10) placements = front_end.placements() buffer_manager = front_end.buffer_manager() for placement in sorted(placements.placements, key=lambda p: (p.x, p.y, p.p)): if isinstance(placement.vertex, HelloWorldVertex): hello_world = placement.vertex.read(placement, buffer_manager) logger.info("{}, {}, {} > {}".format(placement.x, placement.y, placement.p, hello_world)) front_end.stop()
def run_broken(): machine_time_step = 1000 time_scale_factor = 1 # machine_port = 11111 machine_receive_port = 22222 machine_host = "0.0.0.0" live_gatherer_label = "LiveHeatGatherer" notify_port = 19999 database_listen_port = 19998 # set up the front end and ask for the detected machines dimensions front_end.setup( graph_label="heat_demo_graph", model_binary_module=sys.modules[__name__], database_socket_addresses={SocketAddress( "127.0.0.1", notify_port, database_listen_port)}) machine = front_end.machine() # create a live gatherer vertex for each board default_gatherer = None live_gatherers = dict() used_cores = set() for chip in machine.ethernet_connected_chips: # Try to use core 17 if one is available as it is outside the grid processor = chip.get_processor_with_id(17) if processor is None or processor.is_monitor: processor = chip.get_first_none_monitor_processor() if processor is not None: live_gatherer = front_end.add_machine_vertex( LivePacketGatherMachineVertex, { 'label': live_gatherer_label, 'ip_address': machine_host, 'port': machine_receive_port, 'payload_as_time_stamps': False, 'use_payload_prefix': False, 'strip_sdp': True, 'message_type': EIEIOType.KEY_PAYLOAD_32_BIT } ) live_gatherers[chip.x, chip.y] = live_gatherer used_cores.add((chip.x, chip.y, processor.processor_id)) if default_gatherer is None: default_gatherer = live_gatherer # Create a list of lists of vertices (x * 4) by (y * 4) # (for 16 cores on a chip - missing cores will have missing vertices) max_x_element_id = (machine.max_chip_x + 1) * 4 max_y_element_id = (machine.max_chip_y + 1) * 4 vertices = [ [None for _ in range(max_y_element_id)] for _ in range(max_x_element_id) ] receive_labels = list() for x in range(0, max_x_element_id): for y in range(0, max_y_element_id): chip_x = x / 4 chip_y = y / 4 core_x = x % 4 core_y = y % 4 core_p = ((core_x * 4) + core_y) + 1 # Add an element if the chip and core exists chip = machine.get_chip_at(chip_x, chip_y) if chip is not None: core = chip.get_processor_with_id(core_p) if (core is not None and not core.is_monitor and (chip_x, chip_y, core_p) not in used_cores): element = front_end.add_machine_vertex( HeatDemoVertex, { 'machine_time_step': machine_time_step, 'time_scale_factor': time_scale_factor }, label="Heat Element {}, {}".format( x, y)) vertices[x][y] = element vertices[x][y].add_constraint( ChipAndCoreConstraint(chip_x, chip_y, core_p)) # add a link from the heat element to the live packet # gatherer live_gatherer = live_gatherers.get( (chip.nearest_ethernet_x, chip.nearest_ethernet_y), default_gatherer) front_end.add_machine_edge( MachineEdge, { 'pre_vertex': vertices[x][y], 'post_vertex': live_gatherer }, label="Live output from {}, {}".format(x, y), semantic_label="TRANSMISSION") receive_labels.append(vertices[x][y].label) # build edges for x in range(0, max_x_element_id): for y in range(0, max_y_element_id): if vertices[x][y] is not None: # Add a north link if not at the top if y+1 < max_y_element_id and vertices[x][y+1] is not None: front_end.add_machine_edge( HeatDemoEdge, { 'pre_vertex': vertices[x][y], 'post_vertex': vertices[x][y + 1], 'direction': HeatDemoEdge.DIRECTIONS.SOUTH }, label="North Edge from {}, {} to {}, {}".format( x, y, x + 1, y), semantic_label="TRANSMISSION") # Add an east link if not at the right if x+1 < max_y_element_id and vertices[x+1][y] is not None: front_end.add_machine_edge( HeatDemoEdge, { 'pre_vertex': vertices[x][y], 'post_vertex': vertices[x + 1][y], 'direction': HeatDemoEdge.DIRECTIONS.WEST }, label="East Edge from {}, {} to {}, {}".format( x, y, x + 1, y), semantic_label="TRANSMISSION") # Add a south link if not at the bottom if (y - 1) >= 0 and vertices[x][y - 1] is not None: front_end.add_machine_edge( HeatDemoEdge, { 'pre_vertex': vertices[x][y], 'post_vertex': vertices[x][y - 1], 'direction': HeatDemoEdge.DIRECTIONS.NORTH }, label="South Edge from {}, {} to {}, {}".format( x, y, x, y - 1), semantic_label="TRANSMISSION") # check for the likely hood for a W link if (x - 1) >= 0 and vertices[x - 1][y] is not None: front_end.add_machine_edge( HeatDemoEdge, { 'pre_vertex': vertices[x][y], 'post_vertex': vertices[x - 1][y], 'direction': HeatDemoEdge.DIRECTIONS.EAST }, label="West Edge from {}, {} to {}, {}".format( x, y, x - 1, y), semantic_label="TRANSMISSION") # Set up the live connection for receiving heat elements live_heat_connection = LiveEventConnection( live_gatherer_label, receive_labels=receive_labels, local_port=notify_port, machine_vertices=True) heat_values = defaultdict(list) condition = Condition() def receive_heat(label, atom, value): with condition: print "{}: {}".format(label, value / 65536.0) # Set up callbacks to occur when spikes are received for label in receive_labels: live_heat_connection.add_receive_callback(label, receive_heat) front_end.run(1000) front_end.stop() for label in receive_labels: print "{}: {}".format( label, ["{:05.2f}".format(value) for value in heat_values[label]])
import logging import os logger = logging.getLogger(__name__) front_end.setup(n_chips_required=None, model_binary_folder=os.path.dirname(__file__)) # calculate total number of 'free' cores for the given board # (i.e. does not include those busy with SARK or reinjection) total_number_of_cores = \ front_end.get_number_of_available_cores_on_machine() # fill all cores with a Vertex each for x in range(0, total_number_of_cores): front_end.add_machine_vertex(TemplateVertex, {}, label="Template program at x {}".format(x)) # run for a specified length of time front_end.run(10) # set up placements (this is a simple example based on hello_world example # that should be edited to suit the application) placements = front_end.placements() buffer_manager = front_end.buffer_manager() for placement in sorted(placements.placements, key=lambda p: (p.x, p.y, p.p)): if isinstance(placement.vertex, TemplateVertex): template_info = placement.vertex.read(placement, buffer_manager) logger.info("{}, {}, {} > {}".format(placement.x, placement.y, placement.p, template_info))
import spinnaker_graph_front_end as front_end from spinnaker_graph_front_end.examples.hello_world.hello_world_vertex\ import HelloWorldVertex import time import os front_end.setup(n_chips_required=2, model_binary_folder=os.path.dirname(__file__)) front_end.add_machine_vertex(HelloWorldVertex, {}, label="Hello World") front_end.run(10) extra_monitor_vertices = front_end.globals_variables.\ get_simulator()._last_run_outputs['MemoryExtraMonitorVertices'] extra_monitor_gatherers = front_end.globals_variables.\ get_simulator()._last_run_outputs[ 'MemoryMCGatherVertexToEthernetConnectedChipMapping'] transceiver = front_end.transceiver() placements = front_end.placements() start = float(time.time()) receiver = extra_monitor_gatherers[0, 0] receiver.set_cores_for_data_extraction( transceiver=transceiver, placements=placements, extra_monitor_cores_for_router_timeout=(extra_monitor_vertices)) receiver.unset_cores_for_data_extraction( transceiver=transceiver, placements=placements,