예제 #1
0
    hw_spec = importlib.import_module(HW, "*")
    latency_spec = importlib.import_module(LATENCY, "*")

    for i in range(0, 4):
        branch_spec[i].action_fields_limit = hw_spec.action_fields_limit
        branch_spec[i].match_unit_limit = hw_spec.match_unit_limit
        branch_spec[i].match_unit_size = hw_spec.match_unit_size
        branch_spec[i].action_proc_limit = hw_spec.action_proc_limit
        branch_spec[i].match_proc_limit = hw_spec.match_proc_limit

    # Create graphs for all branches
    graphs_map = {}

    for i in range(0, 4):
        graphs_map[i] = ScheduleDAG()
        graphs_map[i].create_dag(branch_spec[i].nodes, branch_spec[i].edges,
                                 latency_spec)

    common_nodes_mapping = {}
    for i in range(0, 3):
        common_nodes_mapping[i] = {}
        for j in range(i + 1, 4):
            common_nodes_mapping[i][j] = get_common_nodes(
                graphs_map[i], graphs_map[j])

    match_key_size = {}
    for i in range(0, 4):
        print("Branch " + str(i) + " nodes length", len(graphs_map[i].nodes()))
        print("Branch " + str(i) + " match nodes length",
              len(graphs_map[i].nodes(select='match')))
    hw_file      = sys.argv[2]
    latency_file = sys.argv[3]
    minute_limit = int(sys.argv[4])

  # Input specification
  input_spec = importlib.import_module(input_file, "*")
  hw_spec    = importlib.import_module(hw_file, "*")
  latency_spec=importlib.import_module(latency_file, "*")
  input_spec.action_fields_limit = hw_spec.action_fields_limit
  input_spec.match_unit_limit    = hw_spec.match_unit_limit
  input_spec.match_unit_size     = hw_spec.match_unit_size
  input_spec.action_proc_limit   = hw_spec.action_proc_limit
  input_spec.match_proc_limit    = hw_spec.match_proc_limit

  # Create G
  G = ScheduleDAG()
  G.create_dag(input_spec.nodes, input_spec.edges, latency_spec)
  cpath, cplat = G.critical_path()

  print ('{:*^80}'.format(' Input DAG '))
  tpt_upper_bound = print_problem(G, input_spec)
  tpt_lower_bound = 0.01 # Just for kicks
  print ('\n\n')

  # Try to max. throughput
  # We do this by min. the period
  period_lower_bound = int(math.ceil((1.0) / tpt_upper_bound))
  period_upper_bound = int(math.ceil((1.0) / tpt_lower_bound))
  period = period_upper_bound
  last_good_solution = None
  last_good_period   = None
예제 #3
0
파일: prmt.py 프로젝트: sandyhouse/drmt
        hw_file = sys.argv[2]
        latency_file = sys.argv[3]
        assert ((sys.argv[4] == "coarse") or (sys.argv[4] == "fine"))
        solve_coarse = bool(sys.argv[4] == "coarse")

    # Input example
    input_spec = importlib.import_module(input_file, "*")
    hw_spec = importlib.import_module(hw_file, "*")
    latency_spec = importlib.import_module(latency_file, "*")
    input_spec.action_fields_limit = hw_spec.action_fields_limit
    input_spec.match_unit_limit = hw_spec.match_unit_limit
    input_spec.match_unit_size = hw_spec.match_unit_size
    input_spec.action_proc_limit = hw_spec.action_proc_limit
    input_spec.match_proc_limit = hw_spec.match_proc_limit

    G = ScheduleDAG()
    G.create_dag(input_spec.nodes, input_spec.edges, latency_spec)

    print('{:*^80}'.format(' Input DAG '))
    print_problem(G, input_spec)

    print('{:*^80}'.format(' Scheduling PRMT fine '))
    solver = PrmtFineSolver(G, input_spec, latency_spec, seed_greedy=True)
    solution = solver.solve(solve_coarse)
    print('Number of pipeline stages: %f' % (math.ceil(solution.length / 2.0)))
    print('{:*^80}'.format(' Schedule'))
    print(
        timeline_str(solution.ops_at_time, white_space=0, timeslots_per_row=4),
        '\n\n')
    print_resource_usage(input_spec, solution)
예제 #4
0
        exit(1)
    else :
        input_spec = importlib.import_module(sys.argv[1], "*")
        hw_spec = importlib.import_module(sys.argv[2], "*")
        latency_spec = importlib.import_module(sys.argv[3], "*")
        minute_limit = int(sys.argv[4])
        seed = int(sys.argv[5])
        burst_size = int(sys.argv[6])

    input_spec.action_fields_limit = hw_spec.action_fields_limit
    input_spec.match_unit_limit = hw_spec.match_unit_limit
    input_spec.match_unit_size = hw_spec.match_unit_size
    input_spec.action_proc_limit = hw_spec.action_proc_limit
    input_spec.match_proc_limit = hw_spec.match_proc_limit

    graph_map = ScheduleDAG()

    
    t_nodes, t_edges = create_compund_graph(input_spec.nodes, input_spec.edges, burst_size)
    graph_map.create_dag(t_nodes, t_edges, latency_spec)
    print(graph_map.critical_path())
    print(len(graph_map.nodes()))

    last_good_soln = None
    last_good_period = None

    for period in range(seed+5, seed-5, -1):
        soln = model_ilp(graph_map, hw_spec, period, minute_limit, burst_size)

        if (soln):
            last_good_period = period
예제 #5
0

    branch1_spec.action_fields_limit = hw_spec.action_fields_limit
    branch1_spec.match_unit_limit = hw_spec.match_unit_limit
    branch1_spec.match_unit_size = hw_spec.match_unit_size
    branch1_spec.action_proc_limit = hw_spec.action_proc_limit
    branch1_spec.match_proc_limit = hw_spec.match_proc_limit    

    branch2_spec.action_fields_limit = hw_spec.action_fields_limit
    branch2_spec.match_unit_limit = hw_spec.match_unit_limit
    branch2_spec.match_unit_size = hw_spec.match_unit_size
    branch2_spec.action_proc_limit = hw_spec.action_proc_limit
    branch2_spec.match_proc_limit = hw_spec.match_proc_limit

    # Create graphs for both branches
    G1 = ScheduleDAG()
    G2 = ScheduleDAG()
    G1.create_dag(branch1_spec.nodes, branch1_spec.edges, latency_spec)
    G2.create_dag(branch2_spec.nodes, branch2_spec.edges, latency_spec)

    # Group common nodes
    common_nodes_mapping = get_common_nodes(G1, G2)
    #print (common_nodes_mapping)
    print ("Branch1 - nodes", len(G1.nodes()) )
    print ("Branch1 - match nodes", len(G1.nodes(select='match')))
    
    match_nodes = G1.nodes(select='match')
    action_nodes = G1.nodes(select='action')
     
    match_key_size = 0
    action_key_size = 0
예제 #6
0
def contract_dag(input_spec, latency_spec):
    G = ScheduleDAG()
    G.create_dag(input_spec.nodes, input_spec.edges, latency_spec)

    action_nodes = G.nodes(select='action')
    match_nodes = G.nodes(select='match')

    tables = []
    found_table = dict()

    for m in match_nodes:
        for a in action_nodes:
            if (a.startswith("_condition")):
                continue
            assert (m.endswith('MATCH'))
            assert (a.endswith('ACTION'))
            m_table = m.strip('MATCH')
            a_table = a.strip('ACTION')
            if (m_table == a_table):
                tables.append((m, a))
                found_table[m] = True
                found_table[a] = True

    for m in match_nodes:
        if m not in found_table:
            print("Unpaired match, ERROR!!!")
            exit(1)

    for a in action_nodes:
        if a not in found_table:
            pass
    #    print ("Unpaired action or condition: ", a, file=sys.stderr)

    # Contract table edges
    for table in tables:
        match = table[0]
        action = table[1]
        table_name = match.strip('MATCH') + 'TABLE'
        key_width = G.node[match]['key_width']
        num_fields = G.node[action]['num_fields']
        G = nx.contracted_edge(G, table, self_loops=False)
        nx.relabel_nodes(G, {match: table_name}, False)
        G.node[table_name]['type'] = 'table'
        G.node[table_name]['key_width'] = key_width
        G.node[table_name]['num_fields'] = num_fields

    # Create dummy tables for the rest
    for v in G.nodes():
        if (G.node[v]['type'] != 'table'):
            G.node[v]['type'] = 'table'
            G.node[v]['key_width'] = 0
            assert (G.node[v]['num_fields'] >= 0)
            # leave num_fields unchanged

    return G
        hw_file      = sys.argv[2]
        latency_file = sys.argv[3]
        minute_limit = int(sys.argv[4])
        burst_size = int(sys.argv[5])
    
    # Input specification
    input_spec = importlib.import_module(input_file, "*")
    hw_spec    = importlib.import_module(hw_file, "*")
    latency_spec=importlib.import_module(latency_file, "*")
    input_spec.action_fields_limit = hw_spec.action_fields_limit
    input_spec.match_unit_limit    = hw_spec.match_unit_limit
    input_spec.match_unit_size     = hw_spec.match_unit_size
    input_spec.action_proc_limit   = hw_spec.action_proc_limit
    input_spec.match_proc_limit    = hw_spec.match_proc_limit

    G = ScheduleDAG()
    G.create_dag(input_spec.nodes, input_spec.edges, latency_spec)
    cpath, cplat = G.critical_path()

    match_nodes = G.nodes(select='match')
    action_nodes = G.nodes(select='action')

    match_key_size = 0
    action_key_size = 0

    for node in match_nodes:
        match_key_size += G.node[node]['key_width']
    
    for node in action_nodes:
        action_key_size += G.node[node]['num_fields']