def create_app_less(): app_graph = ApplicationGraph("Test") 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() mac_graph.add_vertex(out_mac_vertex) # Create 5 application vertices (3 bits) for app_index in range(5): # 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() 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) n_keys_map.set_n_keys_for_partition( p, (mac_edge_index * 4) + 1) return app_graph, mac_graph, n_keys_map
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 _do_test(self, placer): machine = VirtualMachine(width=8, height=8) graph = MachineGraph("Test") vertices = [ SimpleMachineVertex(ResourceContainer(), label="v{}".format(i)) for i in range(100) ] for vertex in vertices: graph.add_vertex(vertex) same_vertices = [ SimpleMachineVertex(ResourceContainer(), label="same{}".format(i)) for i in range(10) ] random.seed(12345) sdram_edges = list() for vertex in same_vertices: graph.add_vertex(vertex) for i in range(0, random.randint(1, 5)): sdram_edge = MachineEdge( vertex, vertices[random.randint(0, 99)], traffic_type=EdgeTrafficType.SDRAM) sdram_edges.append(sdram_edge) graph.add_edge(sdram_edge, "Test") placements = placer(graph, machine) for edge in sdram_edges: pre_place = placements.get_placement_of_vertex(edge.pre_vertex) post_place = placements.get_placement_of_vertex(edge.post_vertex) self.assert_(pre_place.x == post_place.x) self.assert_(pre_place.y == post_place.y)
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 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 test_convert_to_file_machine_graph_pure_multicast(tmpdir): # Construct the sample graph graph = MachineGraph("foo") v0 = SimpleMachineVertex(ResourceContainer()) graph.add_vertex(v0) tag = IPtagResource("1.2.3.4", 5, False, tag="footag") v1 = SimpleMachineVertex(ResourceContainer(iptags=[tag])) graph.add_vertex(v1) t1id = md5("%s_tag" % ident(v1)) tag = ReverseIPtagResource(tag="bartag") v2 = SimpleMachineVertex(ResourceContainer(reverse_iptags=[tag])) graph.add_vertex(v2) t2id = md5("%s_tag" % ident(v2)) graph.add_edge(MachineEdge(v1, v0), "part1") p1 = graph.get_outgoing_edge_partition_starting_at_vertex(v1, "part1") graph.add_edge(MachineEdge(v0, v2, label="foobar"), "part2") p2 = graph.get_outgoing_edge_partition_starting_at_vertex(v0, "part2") # Convert it to JSON algo = ConvertToFileMachineGraphPureMulticast() fn = tmpdir.join("foo.json") filename, _vertex_by_id, _partition_by_id = algo(graph, str(fn)) assert filename == str(fn) # Rebuild and compare; simplest way of checking given that order is not # preserved in the underlying string and altering that is hard obj = json.loads(fn.read()) baseline = { "vertices_resources": { ident(v0): { "cores": 1, "sdram": 0 }, ident(v1): { "cores": 1, "sdram": 0 }, t1id: { "cores": 0, "sdram": 0 }, ident(v2): { "cores": 1, "sdram": 0 }, t2id: { "cores": 0, "sdram": 0 } }, "edges": { ident(p1): { "source": ident(v1), "sinks": [ident(v0)], "type": "multicast", "weight": 1 }, ident(p2): { "source": ident(v0), "sinks": [ident(v2)], "type": "multicast", "weight": 1 }, t1id: { "source": ident(v1), "sinks": [t1id], "weight": 1.0, "type": "FAKE_TAG_EDGE" }, t2id: { "source": ident(v2), "sinks": [t2id], "weight": 1.0, "type": "FAKE_TAG_EDGE" } } } assert obj == baseline