File: run_sim_multi.py

package info (click to toggle)
uhd 4.8.0.0%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 183,172 kB
  • sloc: cpp: 279,415; python: 109,850; ansic: 103,348; vhdl: 57,230; tcl: 20,007; xml: 8,581; makefile: 2,863; sh: 2,797; pascal: 230; javascript: 120; csh: 94; asm: 20; perl: 11
file content (106 lines) | stat: -rwxr-xr-x 3,830 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/python3
#
# Copyright 2018 Ettus Research, a National Instruments Company
#
# SPDX-License-Identifier: LGPL-3.0-or-later
#
# Description
#   Run the crossbar testbench (crossbar_tb) for varios parameter
#   configurations and generates load-latency graphs for each run.

import argparse
import math
import os, sys
import shutil
import glob
import subprocess

g_tb_top_template = """
`timescale 1ns/1ps
module crossbar_tb_auto();
  crossbar_tb #(
    .TEST_NAME          ("crossbar_tb_auto"),
    .ROUTER_IMPL        ("{rtr_impl}"),
    .ROUTER_PORTS       ({rtr_ports}),
    .ROUTER_DWIDTH      ({rtr_width}),
    .MTU_LOG2           ({rtr_mtu}),
    .NUM_MASTERS        ({rtr_sources}),
    .TEST_MAX_PACKETS   ({tst_maxpkts}),
    .TEST_LPP           ({tst_lpp}),
    .TEST_MIN_INJ_RATE  ({tst_injrate_min}),
    .TEST_MAX_INJ_RATE  ({tst_injrate_max}),
    .TEST_INJ_RATE_INCR (10),
    .TEST_GEN_LL_FILES  (1)
  ) impl (
    /* no IO */
  );
endmodule
"""

g_test_params = {
    'data': {'rtr_width':64, 'rtr_mtu':7, 'tst_maxpkts':100, 'tst_lpp':100, 'tst_injrate_min':30, 'tst_injrate_max':100},
    'ctrl': {'rtr_width':64, 'rtr_mtu':5, 'tst_maxpkts':100, 'tst_lpp':20,  'tst_injrate_min':10, 'tst_injrate_max':50},
}

g_xb_types = {
    'chdr_crossbar_nxn':'data', 'axi_crossbar':'data',
    'axis_ctrl_2d_torus':'ctrl', 'axis_ctrl_2d_mesh':'ctrl'
}

def get_options():
    parser = argparse.ArgumentParser(description='Run correctness sim and generate load-latency plots')
    parser.add_argument('--impl', type=str, default='chdr_crossbar_nxn', help='Implementation (CSV) [%s]'%(','.join(g_xb_types.keys())))
    parser.add_argument('--ports', type=str, default='16', help='Number of ports (CSV)')
    parser.add_argument('--sources', type=str, default='16', help='Number of active data sources (masters)')
    return parser.parse_args()

def launch_run(impl, ports, sources):
    run_name = '%s_ports%d_srcs%d'%(impl, ports, sources)
    # Prepare a transform map to autogenerate a TB file
    transform = {'rtr_impl':impl, 'rtr_ports':ports, 'rtr_sources':sources}
    for k,v in g_test_params[g_xb_types[impl]].items():
        transform[k] = v
    # Create crossbar_tb_auto.sv with specified parameters
    with open('crossbar_tb_auto.sv', 'w') as out_file:
        out_file.write(g_tb_top_template.format(**transform))
    # Create data directory for the simulation
    data_dir = os.path.join('data', impl)
    export_dir = os.path.join('data', run_name)
    try:
        os.makedirs('data')
    except FileExistsError:
        pass
    os.makedirs(data_dir)
    os.makedirs(export_dir)
    # Run "make xsim"
    exitcode = subprocess.Popen('make xsim TB_TOP_MODULE=crossbar_tb_auto', shell=True).wait()
    if exitcode != 0:
        raise RuntimeError('Error running "make xsim". Was setupenv.sh run?')
    # Generate load-latency graphs
    exitcode = subprocess.Popen('gen_load_latency_graph.py ' + data_dir, shell=True).wait()
    if exitcode != 0:
        raise RuntimeError('Error running "gen_load_latency_graph.py"')
    # Copy files
    os.rename('xsim.log', os.path.join(export_dir, 'xsim.log'))
    for file in glob.glob(os.path.join(data_dir, '*.png')):
        shutil.copy(file, export_dir)
    # Cleanup outputs
    subprocess.Popen('make cleanall', shell=True).wait()
    try:
        os.remove('crossbar_tb_auto.sv')
    except FileNotFoundError:
        pass
    try:
        shutil.rmtree(data_dir)
    except OSError:
        print('WARNING: Could not delete ' + data_dir)

def main():
    args = get_options();
    for impl in args.impl.strip().split(','):
        for ports in args.ports.strip().split(','):
            for sources in args.sources.strip().split(','):
                launch_run(impl, int(ports), min(int(ports), int(sources)))

if __name__ == '__main__':
    main()