def create_graphs_only_fixed(): app_graph = ApplicationGraph("Test") # An output vertex to aim things at (to make keys required) out_app_vertex = SimpleAppVertex() app_graph.add_vertex(out_app_vertex) # Create 5 application vertices (3 bits) app_vertex = SimpleAppVertex() app_graph.add_vertex(app_vertex) mac_graph = MachineGraph("Test", app_graph) n_keys_map = DictBasedMachinePartitionNKeysMap() # An output vertex to aim things at (to make keys required) out_mac_vertex = SimpleMacVertex(app_vertex=out_app_vertex) mac_graph.add_vertex(out_mac_vertex) mac_vertex = SimpleMacVertex(app_vertex=app_vertex) mac_graph.add_vertex(mac_vertex) for mac_edge_index in range(2): mac_edge = MachineEdge(mac_vertex, out_mac_vertex) part_name = "Part{}".format(mac_edge_index) mac_graph.add_edge(mac_edge, part_name) p = mac_graph.get_outgoing_edge_partition_starting_at_vertex( mac_vertex, part_name) if (mac_edge_index == 0): p.add_constraint(FixedKeyAndMaskConstraint( [BaseKeyAndMask(0x4c00000, 0xFFFFFFFE)])) if (mac_edge_index == 1): p.add_constraint(FixedKeyAndMaskConstraint( [BaseKeyAndMask(0x4c00000, 0xFFFFFFFF)])) n_keys_map.set_n_keys_for_partition( p, (mac_edge_index * 4) + 1) return app_graph, mac_graph, n_keys_map
def test_fixed_key_and_mask_constraint(self): c1 = FixedKeyAndMaskConstraint([BaseKeyAndMask(0xFF0, 0xFF8)]) self.constraint_there_and_back(c1) km = BaseKeyAndMask(0xFF0, 0xFF8) km2 = BaseKeyAndMask(0xFE0, 0xFF8) c2 = FixedKeyAndMaskConstraint([km, km2]) self.constraint_there_and_back(c2)
def test_share_key_with_fixed_key_on_new_partitions(self): machine_graph, n_keys_map, v1, v2, _v3, _v4, e1, e2, e3, e4 = \ self._integration_setup() partition = machine_graph.\ get_outgoing_edge_partition_starting_at_vertex(v1, "part1") other_partition = machine_graph.\ get_outgoing_edge_partition_starting_at_vertex(v2, "part2") partition.add_constraint(ShareKeyConstraint([other_partition])) other_partition.add_constraint(FixedKeyAndMaskConstraint( [BaseKeyAndMask(base_key=25, mask=0xFFFFFFF)])) results = malloc_based_routing_info_allocator( machine_graph, n_keys_map) key = results.get_first_key_from_partition( machine_graph.get_outgoing_edge_partition_starting_at_vertex( v1, "part1")) edge1_key = results.get_first_key_for_edge(e1) edge2_key = results.get_first_key_for_edge(e2) edge3_key = results.get_first_key_for_edge(e3) edge4_key = results.get_first_key_for_edge(e4) self.assertEqual(key, 25) self.assertEqual(edge1_key, key) self.assertEqual(edge2_key, key) self.assertEqual(edge3_key, key) self.assertNotEqual(edge4_key, key)
def constraint_from_json(json_dict, graph=None): if json_dict["class"] == "BoardConstraint": return BoardConstraint(json_dict["board_address"]) if json_dict["class"] == "ChipAndCoreConstraint": if "p" in json_dict: p = json_dict["p"] else: p = None return ChipAndCoreConstraint(json_dict["x"], json_dict["y"], p) if json_dict["class"] == "ContiguousKeyRangeContraint": return ContiguousKeyRangeContraint() if json_dict["class"] == "FixedKeyAndMaskConstraint": if "key_list_function" in json_dict: raise NotImplementedError("key_list_function {}".format( json_dict["key_list_function"])) return FixedKeyAndMaskConstraint( key_masks_from_json(json_dict["keys_and_masks"])) if json_dict["class"] == "FixedMaskConstraint": return FixedMaskConstraint(json_dict["mask"]) if json_dict["class"] == "FixedVertexAtomsConstraint": return FixedVertexAtomsConstraint(json_dict["size"]) if json_dict["class"] == "MaxVertexAtomsConstraint": return MaxVertexAtomsConstraint(json_dict["size"]) if json_dict["class"] == "RadialPlacementFromChipConstraint": return RadialPlacementFromChipConstraint(json_dict["x"], json_dict["y"]) if json_dict["class"] == "SameChipAsConstraint": return SameChipAsConstraint(vertex_lookup(json_dict["vertex"], graph)) if json_dict["class"] == "SameAtomsAsVertexConstraint": return SameAtomsAsVertexConstraint( vertex_lookup(json_dict["vertex"], graph)) raise NotImplementedError("constraint {}".format(json_dict["class"]))
def get_outgoing_partition_constraints(self, partition): return [ FixedKeyAndMaskConstraint([ BaseKeyAndMask(self._partition_id_to_key[partition.identifier], self._DEFAULT_COMMAND_MASK) ]) ]
def get_outgoing_partition_constraints(self, partition): if self._virtual_key is not None: return list([ FixedKeyAndMaskConstraint( [BaseKeyAndMask(self._virtual_key, self._mask)]) ]) return list()
def get_outgoing_partition_constraints(self, partition): return [ FixedKeyAndMaskConstraint(keys_and_masks=[ BaseKeyAndMask( base_key=0, #upper part of the key, mask=0xFFFFFF00) ]) ] #256 neurons in the LSB bits ,
def get_outgoing_partition_constraints(self, partition): return [ FixedKeyAndMaskConstraint(keys_and_masks=[ BaseKeyAndMask( base_key=0, #upper part of the key, mask=MASK_IN) ]) ]
def test_share_key_with_conflicting_fixed_key_on_partitions(self): machine_graph, n_keys_map, v1, v2, _v3, _v4, _e1, _e2, _e3, _e4 = \ self._integration_setup() partition = machine_graph.\ get_outgoing_edge_partition_starting_at_vertex(v1, "part1") other_partition = machine_graph.\ get_outgoing_edge_partition_starting_at_vertex(v2, "part2") other_partition.add_constraint(ShareKeyConstraint([partition])) other_partition.add_constraint(FixedKeyAndMaskConstraint( [BaseKeyAndMask(base_key=30, mask=0xFFFFFFF)])) partition.add_constraint(FixedKeyAndMaskConstraint( [BaseKeyAndMask(base_key=25, mask=0xFFFFFFF)])) with self.assertRaises(PacmanRouteInfoAllocationException): malloc_based_routing_info_allocator(machine_graph, n_keys_map)
def get_incoming_partition_constraints(self, partition, graph_mapper): if isinstance(partition.pre_vertex, CommandSenderMachineVertex): return [] index = graph_mapper.get_machine_vertex_index(partition.pre_vertex) vertex_slice = graph_mapper.get_slice(partition.pre_vertex) mask = get_possible_masks(vertex_slice.n_atoms)[0] key = (0x1000 + index) << 16 return [FixedKeyAndMaskConstraint( keys_and_masks=[BaseKeyAndMask(key, mask)])]
def get_outgoing_partition_constraints(self, partition): base_key = app_constants.FILTER_BASE_KEY | ( self._row_id << app_constants.RETINA_Y_BIT_SHIFT) return [ FixedKeyAndMaskConstraint(keys_and_masks=[ BaseKeyAndMask(base_key=base_key, mask=app_constants.FILTER_BASE_MASK) ]) ]
def test_fixed_key_and_mask_constraint(self): c1 = FixedKeyAndMaskConstraint([BaseKeyAndMask(0xFF0, 0xFF8)]) km = BaseKeyAndMask(0xFF0, 0xFF8) c2 = FixedKeyAndMaskConstraint([km]) c3 = FixedKeyAndMaskConstraint([BaseKeyAndMask(0xFE0, 0xFF8)]) c4 = FixedKeyAndMaskConstraint([km, BaseKeyAndMask(0xFE0, 0xFF8)]) self.assertEqual(c1, c2) self.assertIsNone(c1.key_list_function) self.assertEqual(c1.keys_and_masks, [km]) r = ("FixedKeyAndMaskConstraint(keys_and_masks=[KeyAndMask:0xff0:" "0xff8], key_list_function=None)") self.assertEqual(str(c1), r) d = {} d[c1] = 1 d[c2] = 2 d[c3] = 3 self.assertEqual(len(d), 2) self.assertEqual(d[c1], 2) self.assertNotEqual(c4, c1) self.assertNotEqual(c1, c4)
def get_incoming_partition_constraints(self, partition): if partition.identifier == self._partition_identifier: base_key = app_constants.RETINA_BASE_KEY | \ (self._row_id << app_constants.RETINA_Y_BIT_SHIFT) return [ FixedKeyAndMaskConstraint(keys_and_masks=[ BaseKeyAndMask(base_key=base_key, mask=app_constants.FILTER_BASE_MASK) ]) ] return []
def get_outgoing_partition_constraints(self, partition): if partition.identifier == app_constants.EDGE_PARTITION_MAIN_TO_FILTER: return [ FixedKeyAndMaskConstraint(keys_and_masks=[ BaseKeyAndMask( base_key=app_constants.MAIN_PARTICLE_ROI_KEY, mask=app_constants.MESSAGE_TYPE_MASK) ]) ] elif partition.identifier == app_constants.EDGE_PARTITION_TARGET_POSITION: return [ FixedKeyAndMaskConstraint(keys_and_masks=[ BaseKeyAndMask( base_key=app_constants.MAIN_PARTICLE_TARGET_KEY, mask=app_constants.MESSAGE_TYPE_MASK) ]) ] elif partition.identifier == app_constants.EDGE_PARTITION_PARTICLE_TO_PARTICLE: return [] else: raise Exception("Asking for a partition not defined")
def __call__(self, machine_graph): for outgoing_partition in machine_graph.outgoing_edge_partitions: if not isinstance(outgoing_partition, MulticastEdgePartition): continue mac_vertex = outgoing_partition.pre_vertex if isinstance(mac_vertex, ReverseIPTagMulticastSourceMachineVertex): if mac_vertex.vertex_slice.lo_atom == 0: outgoing_partition.add_constraint( FixedKeyAndMaskConstraint( [BaseKeyAndMask(base_key=0, mask=0xFFFFFFc0)])) else: outgoing_partition.add_constraint( FixedKeyAndMaskConstraint( [BaseKeyAndMask(base_key=64, mask=0xFFFFFFc0)])) elif isinstance(mac_vertex, DelayExtensionMachineVertex): if mac_vertex.vertex_slice.lo_atom == 0: outgoing_partition.add_constraint( FixedKeyAndMaskConstraint( [BaseKeyAndMask(base_key=128, mask=0xFFFFFFc0)])) else: outgoing_partition.add_constraint( FixedKeyAndMaskConstraint( [BaseKeyAndMask(base_key=192, mask=0xFFFFFFc0)]))
def create_big(with_fixed): # This test shows how easy it is to trip up the allocator with a retina app_graph = ApplicationGraph("Test") # Create a single "big" vertex big_app_vertex = SimpleTestVertex(1, label="Retina") app_graph.add_vertex(big_app_vertex) # Create a single output vertex (which won't send) out_app_vertex = SimpleTestVertex(1, label="Destination") app_graph.add_vertex(out_app_vertex) # Create a load of middle vertex mid_app_vertex = SimpleTestVertex(1, "Population") app_graph.add_vertex(mid_app_vertex) mac_graph = MachineGraph("Test", app_graph) n_keys_map = DictBasedMachinePartitionNKeysMap() # Create a single big machine vertex big_mac_vertex = big_app_vertex.create_machine_vertex(None, None, label="RETINA") mac_graph.add_vertex(big_mac_vertex) # Create a single output vertex (which won't send) out_mac_vertex = out_app_vertex.create_machine_vertex(None, None) mac_graph.add_vertex(out_mac_vertex) # Create a load of middle vertices and connect them up for _ in range(2000): # 2000 needs 11 bits mid_mac_vertex = mid_app_vertex.create_machine_vertex(None, None) mac_graph.add_vertex(mid_mac_vertex) edge = MachineEdge(big_mac_vertex, mid_mac_vertex) mac_graph.add_edge(edge, "Test") edge_2 = MachineEdge(mid_mac_vertex, out_mac_vertex) mac_graph.add_edge(edge_2, "Test") mid_part = mac_graph.get_outgoing_edge_partition_starting_at_vertex( mid_mac_vertex, "Test") n_keys_map.set_n_keys_for_partition(mid_part, 100) big_mac_part = mac_graph.get_outgoing_edge_partition_starting_at_vertex( big_mac_vertex, "Test") if with_fixed: big_mac_part.add_constraint( FixedKeyAndMaskConstraint([BaseKeyAndMask(0x0, 0x180000)])) # Make the "retina" need 21 bits, so total is now 21 + 11 = 32 bits, # but the application vertices need some bits too n_keys_map.set_n_keys_for_partition(big_mac_part, 1024 * 768 * 2) return app_graph, mac_graph, n_keys_map
def generate_constraints(self, machine_vertex, partition_identifier): """ Returns the fixed keys for the outgoing edge partition. """ partition = self._get_partition(partition_identifier) if partition is None: raise KeyError("I've never heard of parition: {}".format( partition_identifier)) base_key = partition.get_first_key(machine_vertex) n_keys = machine_vertex.get_n_keys_for_partition( partition_identifier) keys_and_masks = [BaseKeyAndMask(key, globals.mask) for key in range(base_key, base_key + n_keys)] return [FixedKeyAndMaskConstraint(keys_and_masks)]
def create_graphs1(with_fixed): app_graph = ApplicationGraph("Test") # An output vertex to aim things at (to make keys required) out_app_vertex = SimpleAppVertex() app_graph.add_vertex(out_app_vertex) # Create 5 application vertices (3 bits) app_vertices = list() for app_index in range(5): app_vertices.append(SimpleAppVertex()) app_graph.add_vertices(app_vertices) mac_graph = MachineGraph("Test", app_graph) n_keys_map = DictBasedMachinePartitionNKeysMap() # An output vertex to aim things at (to make keys required) out_mac_vertex = SimpleMacVertex(app_vertex=out_app_vertex) mac_graph.add_vertex(out_mac_vertex) # Create 5 application vertices (3 bits) for app_index, app_vertex in enumerate(app_vertices): # For each, create up to (5 x 4) + 1 = 21 machine vertices (5 bits) for mac_index in range((app_index * 4) + 1): mac_vertex = SimpleMacVertex(app_vertex=app_vertex) mac_graph.add_vertex(mac_vertex) # For each machine vertex create up to # (20 x 2) + 1 = 81(!) partitions (6 bits) for mac_edge_index in range((mac_index * 2) + 1): mac_edge = MachineEdge(mac_vertex, out_mac_vertex) part_name = "Part{}".format(mac_edge_index) mac_graph.add_edge(mac_edge, part_name) # Give the partition up to (40 x 4) + 1 = 161 keys (8 bits) p = mac_graph.get_outgoing_edge_partition_starting_at_vertex( mac_vertex, part_name) if with_fixed: if (app_index == 2 and mac_index == 4 and part_name == "Part7"): p.add_constraint(FixedKeyAndMaskConstraint( [BaseKeyAndMask(0xFE00000, 0xFFFFFFC0)])) if (app_index == 2 and mac_index == 0 and part_name == "Part1"): p.add_constraint(FixedKeyAndMaskConstraint( [BaseKeyAndMask(0x4c00000, 0xFFFFFFFE)])) if (app_index == 2 and mac_index == 0 and part_name == "Part1"): p.add_constraint(FixedKeyAndMaskConstraint( [BaseKeyAndMask(0x4c00000, 0xFFFFFFFF)])) if (app_index == 3 and mac_index == 0 and part_name == "Part1"): p.add_constraint(FixedKeyAndMaskConstraint( [BaseKeyAndMask(0x3300000, 0xFFFFFFFF)])) if (app_index == 3 and mac_index == 0 and part_name == "Part1"): p.add_constraint(FixedKeyAndMaskConstraint( [BaseKeyAndMask(0x3300001, 0)])) n_keys_map.set_n_keys_for_partition( p, (mac_edge_index * 4) + 1) return app_graph, mac_graph, n_keys_map
def get_outgoing_partition_constraints(self, partition): return [ FixedKeyAndMaskConstraint( [BaseKeyAndMask(self._fixed_key, self._fixed_mask)]) ]
def get_outgoing_partition_constraints(self, partition): return [ FixedKeyAndMaskConstraint([BaseKeyAndMask(0x12340000, 0xFFFF0000)]) ]