Пример #1
0
def synthesize_accelerator(acc):
    shutil.rmtree(project_backend_path + '/HLS/' + acc.name,
                  ignore_errors=True)
    os.makedirs(project_backend_path + '/HLS/' + acc.name)

    shutil.copy2(
        acc.full_path,
        project_backend_path + '/HLS/' + acc.name + '/' + acc.filename)

    acc_tcl_script = '# Script automatically generated by the Accelerator Integration Tool. Edit at your own risk.\n' \
                     + 'open_project ' + acc.name + '\n' \
                     + 'set_top ' + acc.name + '_wrapper\n' \
                     + 'add_files ' + acc.name + '/' + acc.filename + ' -cflags "-I' + os.getcwd() + '"\n' \
                     + 'open_solution "solution1"\n' \
                     + 'set_part {' + chip_part + '} -tool vivado\n' \
                     + 'create_clock -period ' + str(args.clock) + 'MHz -name default\n' \
                     + 'config_rtl -reset control -reset_level low -reset_async\n'

    if board.arch.device == 'zynqmp' or board.arch.device == 'alveo':
        acc_tcl_script += 'config_interface -m_axi_addr64\n'

    acc_tcl_script += 'csynth_design\n' \
                      + 'export_design -rtl verilog -format ip_catalog -vendor bsc -library ompss -display_name ' + acc.name + ' -taxonomy /BSC/OmpSs\n' \
                      + 'exit\n'

    acc_tcl_script_file = open(
        project_backend_path + '/HLS/' + acc.name + '/HLS_' + acc.name +
        '.tcl', 'w')
    acc_tcl_script_file.write(acc_tcl_script)
    acc_tcl_script_file.close()

    msg.info('Synthesizing \'' + acc.name + '\'')

    p = subprocess.Popen('vivado_hls ' + project_backend_path + '/HLS/' +
                         acc.name + '/HLS_' + acc.name + '.tcl -l ' +
                         project_backend_path + '/HLS/' + acc.name + '/HLS_' +
                         acc.name + '.log',
                         cwd=project_backend_path + '/HLS',
                         stdout=sys.stdout.subprocess,
                         stderr=sys.stdout.subprocess,
                         shell=True)
    if args.verbose:
        for line in iter(p.stdout.readline, b''):
            sys.stdout.write(line.decode('utf-8'))

    retval = p.wait()
    if retval:
        if not args.keep_files:
            shutil.rmtree(project_backend_path + '/HLS/' + acc.name,
                          ignore_errors=True)
        msg.error('Synthesis of \'' + acc.name + '\' failed', start_time,
                  False)
    else:
        msg.success('Finished synthesis of \'' + acc.name + '\'')

    update_resource_utilization(acc)
Пример #2
0
def gen_wns_report(out_path):
    wns = None
    tns = None
    num_fail = 0
    num_total = 0

    # Check implementation reports path
    rpt_path = project_backend_path + '/' + args.name + '/' + args.name + '.runs/impl_1'
    rpt_path += '/' + args.name + '_design_wrapper_timing_summary_routed.rpt'
    if not os.path.exists(rpt_path):
        msg.warning('Cannot find rpt file. Skipping WNS report')
        return

    with open(rpt_path, 'r') as rpt_file:
        rpt_data = rpt_file.readlines()

        # Search header line
        ids = [
            idx for idx in range(len(rpt_data) - 1)
            if (re.match(r'^\s+WNS\(ns\)\s+TNS\(ns\)\s+', rpt_data[idx]))
        ]
        if len(ids) != 1:
            msg.warning(
                'Cannot find WNS report table header. Skipping WNS report')
            return

        # Get information from 1st row
        elems = rpt_data[ids[0] + 2].split()
        wns = float(elems[0])
        tns = float(elems[1])
        num_fail = int(elems[2])
        num_total = int(elems[3])

    msg.log('Worst Negative Slack (WNS) summary')
    if wns >= 0.0:
        msg.success(
            str(num_fail) + ' endpoints of ' + str(num_total) +
            ' have negative slack (WNS: ' + str(wns) + ')')
    else:
        msg.warning(
            str(num_fail) + ' endpoints of ' + str(num_total) +
            ' have negative slack (WNS: ' + str(wns) + ', TNS: ' + str(tns) +
            ')')

    with open(out_path, 'w') as timing_file:
        timing_file.write('WNS ' + str(wns) + '\n')
        timing_file.write('TNS ' + str(tns) + '\n')
        timing_file.write('NUM_ENDPOINTS ' + str(num_total) + '\n')
        timing_file.write('NUM_FAIL_ENDPOINTS ' + str(num_fail))
Пример #3
0
def run_boot_step(project_args):
    global start_time
    global project_backend_path
    global petalinux_build_path
    global petalinux_install_path

    start_time = project_args['start_time']
    project_path = project_args['path']
    board = project_args['board']
    args = project_args['args']

    project_backend_path = project_path + '/' + args.backend
    project_step_path = project_backend_path + '/scripts/' + script_folder
    ait_backend_path = ait_path + '/backend/' + args.backend

    petalinux_build_path = os.path.realpath(
        os.getenv('PETALINUX_BUILD')) if os.getenv('PETALINUX_BUILD') else ''
    petalinux_install_path = os.path.realpath(os.getenv(
        'PETALINUX_INSTALL')) if os.getenv('PETALINUX_INSTALL') else ''

    check_requirements()

    # During the execution of this step disable the Vivado_init.tcl script
    disable_init_scripts()

    path_hdf = project_backend_path + '/' + args.name + '/' + args.name + '.sdk/'

    if os.path.exists(petalinux_install_path + '/.version-history'):
        # Seems to be petalinux 2019.1 or later (may match other untested versions)
        command = 'petalinux-config --silentconfig --get-hw-description=' + path_hdf
    else:
        # Seems to be petalinux 2018.3 or previous (may match other untested versions)
        command = 'petalinux-config --oldconfig --get-hw-description=' + path_hdf

    if args.verbose_info:
        msg.log('> ' + command)
    p = subprocess.Popen(command,
                         stdout=sys.stdout.subprocess,
                         stderr=sys.stdout.subprocess,
                         cwd=petalinux_build_path,
                         shell=True)

    if args.verbose:
        for line in iter(p.stdout.readline, b''):
            sys.stdout.write(line.decode('utf-8'))

    retval = p.wait()
    if retval:
        restore_init_scripts()
        msg.error('Generation of petalinux boot files failed', start_time,
                  False)

    if os.path.exists(petalinux_build_path +
                      '/subsystems/linux/configs/device-tree/'):
        # Seems to be petalinux 2016.3 (may match other untested versions)
        if args.verbose_info:
            msg.log('Fixing devicetree (2016.3 mode)')

        petalinux_build_dts_path = petalinux_build_path + '/subsystems/linux/configs/device-tree/'
        shutil.copy2(
            project_backend_path + '/' + args.name + '/pl_ompss_at_fpga.dtsi',
            petalinux_build_dts_path)

        content_dtsi = None
        with open(petalinux_build_dts_path + '/system-conf.dtsi', 'r') as file:
            content_dtsi = file.read().splitlines()

        line = [
            idx for idx in range(len(content_dtsi))
            if content_dtsi[idx].find('/include/ "pl.dtsi"') != -1
        ]
        content_dtsi.insert(line[0] + 1, '/include/ \"pl_ompss_at_fpga.dtsi\"')

        board_dtsi_fix_file = project_backend_path + '/board/' + board.name + '/' + board.name + '_boot.dtsi'
        if os.path.exists(board_dtsi_fix_file):
            shutil.copy2(board_dtsi_fix_file, petalinux_build_dts_path)
            content_dtsi.insert(line[0] + 2,
                                '/include/ \"' + board.name + '_boot.dtsi\"')

        with open(petalinux_build_dts_path + '/system-conf.dtsi', 'w') as file:
            file.write('\n'.join(content_dtsi))

        command = 'petalinux-build -c bootloader -x mrproper'
        if args.verbose_info:
            msg.log('> ' + command)
        p = subprocess.Popen(command,
                             stdout=sys.stdout.subprocess,
                             stderr=sys.stdout.subprocess,
                             cwd=petalinux_build_path,
                             shell=True)
        if args.verbose:
            for line in iter(p.stdout.readline, b''):
                sys.stdout.write(line.decode('utf-8'))

        retval = p.wait()
        if retval:
            restore_init_scripts()
            msg.error('Generation of petalinux boot files failed', start_time,
                      False)
    elif os.path.exists(
            petalinux_build_path +
            '/project-spec/meta-user/recipes-bsp/device-tree/files/'):
        # Seems to be petalinux 2018.3 or 2019.1 (may match other untested versions)
        if args.verbose_info:
            msg.log('Fixing devicetree (2018.3 mode)')

        petalinux_build_dts_path = petalinux_build_path + '/project-spec/meta-user/recipes-bsp/device-tree/files/'

        content_dtsi = None
        with open(petalinux_build_dts_path + '/system-user.dtsi', 'r') as file:
            content_dtsi = file.read().splitlines()

        # Remove old includes to pl_bsc.dtsi and insert the new one
        line = [
            idx for idx in range(len(content_dtsi))
            if content_dtsi[idx].find('pl_bsc.dtsi') != -1
        ]
        if len(line) == 1:
            content_dtsi.pop(line[0])
        elif len(line) > 1:
            restore_init_scripts()
            msg.error(
                'Uncontrolled path in run_boot_step: more than 1 line of system-user.dtsi contains pl_bsc.dtsi'
            )

        # Remove old includes to pl_ompss_at_fpga.dtsi and insert the new one
        line = [
            idx for idx in range(len(content_dtsi))
            if content_dtsi[idx].find('pl_ompss_at_fpga.dtsi') != -1
        ]
        if len(line) == 1:
            content_dtsi.pop(line[0])
        elif len(line) > 1:
            restore_init_scripts()
            msg.error(
                'Uncontrolled path in run_boot_step: more than 1 line of system-user.dtsi contains pl_ompss_at_fpga.dtsi'
            )

        line = [
            idx for idx in range(len(content_dtsi))
            if content_dtsi[idx].find('pl_ompss_at_fpga.dtsi') != -1
        ]
        content_dtsi.insert(
            len(content_dtsi), '/include/ \"' + project_backend_path + '/' +
            args.name + '/pl_ompss_at_fpga.dtsi' + '\"')

        # Remove old includes to <board>_boot.dtsi and insert the new one
        line = [
            idx for idx in range(len(content_dtsi))
            if content_dtsi[idx].find(board.name + '_boot.dtsi') != -1
        ]
        if len(line) == 1:
            content_dtsi.pop(line[0])
        elif len(line) > 1:
            restore_init_scripts()
            msg.error(
                'Uncontrolled path in run_boot_step: more than 1 line of system-user.dtsi contains <board>_bsc.dtsi'
            )

        board_dtsi_fix_file = project_backend_path + '/board/' + board.name + '/' + board.name + '_boot.dtsi'
        if os.path.exists(board_dtsi_fix_file):
            shutil.copy2(board_dtsi_fix_file, petalinux_build_dts_path)
            content_dtsi.insert(len(content_dtsi),
                                '/include/ \"' + board_dtsi_fix_file + '\"')

        with open(petalinux_build_dts_path + '/system-user.dtsi', 'w') as file:
            file.write('\n'.join(content_dtsi))
    else:
        msg.warning(
            'Devicetree fix failed. Petalinux version cannot be determined. Continuing anyway...'
        )

    command = 'petalinux-build'
    if args.verbose_info:
        msg.log('> ' + command)
    p = subprocess.Popen(command,
                         stdout=sys.stdout.subprocess,
                         stderr=sys.stdout.subprocess,
                         cwd=petalinux_build_path,
                         shell=True)
    if args.verbose:
        for line in iter(p.stdout.readline, b''):
            sys.stdout.write(line.decode('utf-8'))

    retval = p.wait()
    if retval:
        restore_init_scripts()
        msg.error('Generation of petalinux boot files failed', start_time,
                  False)

    path_bit = project_path + '/' + args.name + '.bit'
    command = 'petalinux-package --force --boot --fsbl ./images/linux/*_fsbl.elf'
    command += ' --fpga ' + path_bit + ' --u-boot ./images/linux/u-boot.elf'
    if args.verbose_info:
        msg.log('> ' + command)
    p = subprocess.Popen(command,
                         stdout=sys.stdout.subprocess,
                         stderr=sys.stdout.subprocess,
                         cwd=petalinux_build_path,
                         shell=True)
    if args.verbose:
        for line in iter(p.stdout.readline, b''):
            sys.stdout.write(line.decode('utf-8'))

    retval = p.wait()
    if retval:
        msg.error('Generation of petalinux boot files failed', start_time,
                  False)
    else:
        shutil.copy2(petalinux_build_path + '/images/linux/BOOT.BIN',
                     project_path)
        shutil.copy2(petalinux_build_path + '/images/linux/image.ub',
                     project_path)
        msg.success('Petalinux boot files generated')

    restore_init_scripts()
Пример #4
0
def run_design_step(project_args):
    global args
    global board
    global accs
    global chip_part
    global start_time
    global num_accs
    global num_instances
    global num_acc_creators
    global ait_backend_path
    global project_backend_path

    args = project_args['args']
    board = project_args['board']
    accs = project_args['accs']
    start_time = project_args['start_time']
    num_accs = project_args['num_accs']
    num_instances = project_args['num_instances']
    num_acc_creators = project_args['num_acc_creators']
    project_path = project_args['path']

    chip_part = board.chip_part + ('-' + board.es if (board.es and not args.ignore_eng_sample) else '')
    ait_backend_path = ait_path + '/backend/' + args.backend
    project_backend_path = project_path + '/' + args.backend
    project_step_path = project_backend_path + '/scripts/' + script_folder

    # Check if the requirements are met
    check_requirements()

    # Load accelerator placement info
    load_acc_placement(accs, args)

    # Remove old directories used on the design step
    shutil.rmtree(project_step_path, ignore_errors=True)
    shutil.rmtree(project_backend_path + '/board', ignore_errors=True)
    shutil.rmtree(project_backend_path + '/IPs', ignore_errors=True)
    shutil.rmtree(project_backend_path + '/templates', ignore_errors=True)

    # Create directories and copy necessary files for design step
    shutil.copytree(ait_backend_path + '/scripts/' + script_folder, project_step_path, ignore=shutil.ignore_patterns('*.py*'))
    shutil.copytree(ait_backend_path + '/board/' + board.name, project_backend_path + '/board/' + board.name)

    os.makedirs(project_backend_path + '/IPs')
    os.makedirs(project_backend_path + '/templates')
    shutil.copy2(ait_backend_path + '/templates/dummy_acc.tcl', project_backend_path + '/templates')

    ip_list = [ip for ip in os.listdir(ait_backend_path + '/IPs/') if re.search(r'.*\.(zip|v|vhdl)$', ip)]
    for ip in ip_list:
        shutil.copy2(ait_backend_path + '/IPs/' + ip, project_backend_path + '/IPs')

    for template in glob.glob(ait_backend_path + '/templates/hwruntime/' + args.hwruntime
                              + '/' + ('extended/' if args.extended_hwruntime else '')
                              + '*.tcl'):
        shutil.copy2(template, project_backend_path + '/templates')

    for ipdef in glob.glob(ait_backend_path + '/IPs/hwruntime/' + args.hwruntime + '/*.zip'):
        shutil.copy2(ipdef, project_backend_path + '/IPs')

    if args.memory_interleaving_stride is not None:
        subprocess.check_output(['sed -i "s/\`undef __ENABLE__/\`define __ENABLE__/" ' + project_backend_path + '/IPs/addrInterleaver.v'], shell=True)
        subprocess.check_output(['sed -i "s/\`define __WIDTH__ 64/\`define __WIDTH__ ' + str(board.mem.addr_width) + '/" ' + project_backend_path + '/IPs/addrInterleaver.v'], shell=True)

    if args.user_constraints and os.path.exists(args.user_constraints):
        constraints_path = project_backend_path + '/board/' + board.name + '/constraints'
        if not os.path.exists(constraints_path):
            os.mkdir(constraints_path)
        if args.verbose_info:
            msg.log('Adding user constraints file: ' + args.user_constraints)
        shutil.copy2(args.user_constraints, constraints_path + '/')
    elif args.user_constraints:
        msg.error('User constraints file not found: ' + args.user_constraints)

    if args.user_pre_design and os.path.exists(args.user_pre_design):
        user_pre_design_ext = args.user_pre_design.split('.')[-1] if len(args.user_pre_design.split('.')) > 1 else ''
        if user_pre_design_ext != 'tcl':
            msg.error('Invalid extension for PRE design TCL script: ' + args.user_pre_design)
        elif args.verbose_info:
            msg.log('Adding pre design user script: ' + args.user_pre_design)
        shutil.copy2(args.user_pre_design, project_step_path + '/userPreDesign.tcl')
    elif args.user_pre_design:
        msg.error('User PRE design TCL script not found: ' + args.user_pre_design)

    if args.user_post_design and os.path.exists(args.user_post_design):
        user_post_design_ext = args.user_post_design.split('.')[-1] if len(args.user_post_design.split('.')) > 1 else ''
        if user_post_design_ext != 'tcl':
            msg.error('Invalid extension for POST design TCL script: ' + args.user_post_design)
        elif args.verbose_info:
            msg.log('Adding post design user script: ' + args.user_post_design)
        shutil.copy2(args.user_post_design, project_step_path + '/userPostDesign.tcl')
    elif args.user_post_design:
        msg.error('User POST design TCL script not found: ' + args.user_post_design)

    # Generate tcl file with project variables
    generate_Vivado_variables_tcl()

    # Enable beta device on Vivado init script
    if os.path.exists(project_backend_path + '/board/' + board.name + '/board_files'):
        p = subprocess.Popen('echo "enable_beta_device ' + chip_part + '\nset_param board.repoPaths [list '
                             + project_backend_path + '/board/' + board.name + '/board_files]" > '
                             + project_backend_path + '/scripts/Vivado_init.tcl', shell=True)
        retval = p.wait()
    else:
        p = subprocess.Popen('echo "enable_beta_device ' + chip_part + '" > '
                             + project_backend_path + '/scripts/Vivado_init.tcl', shell=True)
        retval = p.wait()

    os.environ['MYVIVADO'] = project_backend_path

    p = subprocess.Popen('vivado -nojournal -nolog -notrace -mode batch -source '
                         + project_step_path + '/generate_design.tcl',
                         cwd=project_backend_path + '/scripts', stdout=sys.stdout.subprocess,
                         stderr=sys.stdout.subprocess, shell=True)

    if args.verbose:
        for line in iter(p.stdout.readline, b''):
            sys.stdout.write(line.decode('utf-8'))

    retval = p.wait()
    del os.environ['MYVIVADO']
    if retval:
        msg.error('Block Design generation failed', start_time, False)
    else:
        msg.success('Block Design generated')

    if (args.hwruntime == 'pom'):
        regex_strings = [
            (r'MAX_ARGS_PER_TASK = [0-9]*', 'MAX_ARGS_PER_TASK = {}'.format(args.picos_max_args_per_task)),
            (r'MAX_DEPS_PER_TASK = [0-9]*', 'MAX_DEPS_PER_TASK = {}'.format(args.picos_max_deps_per_task)),
            (r'MAX_COPIES_PER_TASK = [0-9]*', 'MAX_COPIES_PER_TASK = {}'.format(args.picos_max_copies_per_task)),
            (r'NUM_DCTS = [0-9]*', 'NUM_DCTS = {}'.format(args.picos_num_dcts)),
            (r'TM_SIZE = [0-9]*', 'TM_SIZE = {}'.format(args.picos_tm_size)),
            (r'DM_SIZE = [0-9]*', 'DM_SIZE = {}'.format(args.picos_dm_size)),
            (r'VM_SIZE = [0-9]*', 'VM_SIZE = {}'.format(args.picos_vm_size)),
            (r'DM_DS = "[a-zA-Z_]*"', 'DM_DS = "{}"'.format(args.picos_dm_ds)),
            (r'DM_HASH = "[a-zA-Z_]*"', 'DM_HASH = "{}"'.format(args.picos_dm_hash)),
            (r'HASH_T_SIZE = [0-9]*', 'HASH_T_SIZE = {}'.format(args.picos_hash_t_size))]

        config_file_path = glob.glob(project_backend_path + '/IPs/bsc_ompss_picosompssmanager_*/')[0] + 'src/config.sv'

        with open(config_file_path, 'r') as config_file:
            config_str = config_file.read()
        for regex_str in regex_strings:
            config_str = re.sub(regex_str[0], regex_str[1], config_str, count=1)
        with open(config_file_path, 'w') as config_file:
            config_file.write(config_str)
Пример #5
0
def run_bitstream_step(project_args):
    global args
    global board
    global chip_part
    global start_time
    global ait_backend_path
    global project_backend_path

    args = project_args['args']
    board = project_args['board']
    start_time = project_args['start_time']
    project_path = project_args['path']

    chip_part = board.chip_part + ('-' + board.es if
                                   (board.es
                                    and not args.ignore_eng_sample) else '')
    ait_backend_path = ait_path + '/backend/' + args.backend
    project_backend_path = project_path + '/' + args.backend
    project_step_path = project_backend_path + '/scripts/' + script_folder

    # Check if the requirements are met
    check_requirements()

    # Remove old directories used on the bitstream step
    shutil.rmtree(project_step_path, ignore_errors=True)

    # Create directories and copy necessary files for bitstream step
    shutil.copytree(ait_backend_path + '/scripts/' + script_folder,
                    project_step_path,
                    ignore=shutil.ignore_patterns('*.py*'))

    if os.path.isfile(project_backend_path + '/' + args.name + '/' +
                      args.name + '.xpr'):
        # Enable beta device on Vivado init script
        if board.board_part:
            p = subprocess.Popen(
                'echo "enable_beta_device ' + chip_part +
                '\nset_param board.repoPaths [list ' + project_backend_path +
                '/board/' + board.name + '/board_files]" > ' +
                project_backend_path + '/scripts/Vivado_init.tcl',
                shell=True)
            retval = p.wait()
        else:
            p = subprocess.Popen('echo "enable_beta_device ' + chip_part +
                                 '" > ' + project_backend_path +
                                 '/scripts/Vivado_init.tcl',
                                 shell=True)
            retval = p.wait()

        os.environ['MYVIVADO'] = project_backend_path + '/scripts'

        p = subprocess.Popen(
            'vivado -nojournal -nolog -notrace -mode batch -source ' +
            project_step_path + '/generate_bitstream.tcl',
            cwd=project_backend_path + '/scripts/',
            stdout=sys.stdout.subprocess,
            stderr=sys.stdout.subprocess,
            shell=True)

        if args.verbose:
            for line in iter(p.stdout.readline, b''):
                sys.stdout.write(line.decode('utf-8'))

        retval = p.wait()
        del os.environ['MYVIVADO']
        if retval:
            msg.error('Bitstream generation failed', start_time, False)
        else:
            if board.arch.device == 'zynq':
                bif_file = open(
                    project_backend_path + '/' + args.name + '/' + args.name +
                    '.runs/impl_1/bitstream.bif', 'w')
                bif_file.write('all:\n' + '{\n' + '\t' + args.name +
                               '_design_wrapper.bit\n' + '}')
                bif_file.close()
                p = subprocess.Popen(
                    'bootgen -image bitstream.bif -arch zynq -process_bitstream bin -w',
                    cwd=project_backend_path + '/' + args.name + '/' +
                    args.name + '.runs/impl_1',
                    stdout=sys.stdout.subprocess,
                    stderr=sys.stdout.subprocess,
                    shell=True)

                if args.verbose:
                    for line in iter(p.stdout.readline, b''):
                        sys.stdout.write(line.decode('utf-8'))

                retval = p.wait()
                if retval:
                    msg.warning('Could not create .bit.bin file')
                else:
                    shutil.copy2(
                        glob.glob(project_backend_path + '/' + args.name +
                                  '/' + args.name + '.runs/impl_1/' +
                                  args.name + '*.bit.bin')[0],
                        project_path + '/' + args.name + '.bit.bin')

            shutil.copy2(
                glob.glob(project_backend_path + '/' + args.name + '/' +
                          args.name + '.runs/impl_1/' + args.name +
                          '*.bit')[0], project_path + '/' + args.name + '.bit')
            shutil.copy2(
                glob.glob(project_backend_path + '/' + args.name + '/' +
                          args.name + '.runs/impl_1/' + args.name +
                          '*.bin')[0], project_path + '/' + args.name + '.bin')
            gen_utilization_report(project_path + '/' + args.name +
                                   '.resources-impl.txt')
            gen_wns_report(project_path + '/' + args.name + '.timing-impl.txt')
            msg.success('Bitstream generated')
    else:
        msg.error(
            'No Vivado .xpr file exists for the current project. Bitstream generation failed'
        )
Пример #6
0
def run_implementation_step(project_args):
    global args
    global board
    global chip_part
    global start_time
    global ait_backend_path
    global project_backend_path

    args = project_args['args']
    board = project_args['board']
    start_time = project_args['start_time']
    project_path = project_args['path']

    chip_part = board.chip_part + ('-' + board.es if
                                   (board.es
                                    and not args.ignore_eng_sample) else '')
    ait_backend_path = ait_path + '/backend/' + args.backend
    project_backend_path = project_path + '/' + args.backend
    project_step_path = project_backend_path + '/scripts/' + script_folder

    # Check if the requirements are met
    check_requirements()

    # Remove old directories used on the implementation step
    shutil.rmtree(project_step_path, ignore_errors=True)

    # Create directories and copy necessary files for implementation step
    shutil.copytree(ait_backend_path + '/scripts/' + script_folder,
                    project_step_path,
                    ignore=shutil.ignore_patterns('*.py*'))

    if os.path.isfile(project_backend_path + '/' + args.name + '/' +
                      args.name + '.xpr'):
        # Enable beta device on Vivado init script
        if board.board_part:
            p = subprocess.Popen(
                'echo "enable_beta_device ' + chip_part +
                '\nset_param board.repoPaths [list ' + project_backend_path +
                '/board/' + board.name + '/board_files]" > ' +
                project_backend_path + '/scripts/Vivado_init.tcl',
                shell=True)
            retval = p.wait()
        else:
            p = subprocess.Popen('echo "enable_beta_device ' + chip_part +
                                 '" > ' + project_backend_path +
                                 '/scripts/Vivado_init.tcl',
                                 shell=True)
            retval = p.wait()

        os.environ['MYVIVADO'] = project_backend_path + '/scripts'

        p = subprocess.Popen(
            'vivado -nojournal -nolog -notrace -mode batch -source ' +
            project_step_path + '/implement_design.tcl',
            cwd=project_backend_path + '/scripts/',
            stdout=sys.stdout.subprocess,
            stderr=sys.stdout.subprocess,
            shell=True)

        if args.verbose:
            for line in iter(p.stdout.readline, b''):
                sys.stdout.write(line.decode('utf-8'))

        retval = p.wait()
        del os.environ['MYVIVADO']
        if retval:
            msg.error('Hardware implementation failed', start_time, False)
        else:
            msg.success('Hardware implemented')
    else:
        msg.error(
            'No Vivado .xpr file exists for the current project. Hardware implementation failed'
        )
Пример #7
0
def ait_main():
    global args

    start_time = time.time()

    args = None

    parser = ArgParser()

    args = parser.parse_args()
    msg.setProjectName(args.name)
    msg.setPrintTime(args.verbose_info)
    msg.setVerbose(args.verbose)

    msg.info('Using ' + args.backend + ' backend')

    board = json.load(open(ait_path + '/backend/' + args.backend + '/board/' +
                           args.board + '/basic_info.json'),
                      object_hook=JSONObject)

    # Check vendor-related board arguments
    parser.vendor_parser[args.backend].check_board_args(args, board)

    if not int(board.frequency.min) <= args.clock <= int(board.frequency.max):
        msg.error('Clock frequency requested (' + str(args.clock) +
                  'MHz) is not within the board range (' +
                  str(board.frequency.min) + '-' + str(board.frequency.max) +
                  'MHz)')

    if (args.slr_slices is not None or args.floorplanning_constr
            is not None) and not hasattr(board.arch, 'slr'):
        msg.error(
            'Use of placement constraints is only available for boards with SLRs'
        )

    project_path = os.path.normpath(
        os.path.realpath(args.dir + '/' + args.name + '_ait'))
    project_backend_path = os.path.normpath(project_path + '/' + args.backend)

    # Add backend to python import path
    sys.path.insert(0, ait_path + '/backend/' + args.backend + '/scripts')

    # Check for backend support for the given board
    if not args.disable_board_support_check:
        check_board_support(board)

    sys.stdout = Logger(project_path)
    sys.stdout.log.write(
        os.path.basename(sys.argv[0]) + ' ' + ' '.join(sys.argv[1:]) + '\n\n')

    get_accelerators(project_path)

    parser.check_hardware_runtime_args(args, max(2, num_instances))

    project_args = {
        'path':
        os.path.normpath(
            os.path.realpath(args.dir) + '/' + args.name + '_ait'),
        'num_accs':
        num_accs,
        'num_instances':
        num_instances,
        'num_acc_creators':
        num_acc_creators,
        'accs':
        accs,
        'board':
        board,
        'args':
        args
    }

    for step in generation_steps[args.backend]:
        if generation_steps[args.backend].index(
                args.from_step) <= generation_steps[args.backend].index(
                    step) <= generation_steps[args.backend].index(
                        args.to_step):
            generation_step_package = os.path.basename(
                os.path.dirname(
                    glob.glob(ait_path + '/backend/' + args.backend +
                              '/scripts/*-' + step + '/')[0]))
            generation_step_module = '%s.%s' % (generation_step_package, step)
            module = importlib.import_module(generation_step_module)
            step_func = getattr(module, 'STEP_FUNC')
            msg.info('Starting \'' + step + '\' step')
            step_start_time = time.time()
            project_args['start_time'] = step_start_time
            step_func(project_args)
            msg.success(
                'Step \'' + step + '\' finished. ' +
                secondsToHumanReadable(int(time.time() - step_start_time)) +
                ' elapsed')
        else:
            msg.warning('Step \'' + step + '\' is disabled')

    msg.success('Accelerator automatic integration finished. ' +
                secondsToHumanReadable(int(time.time() - start_time)) +
                ' elapsed')