예제 #1
0
def _generic_policy_wrapper(all_arguments):

    instruction, outputdir, outputname, target, kwargs = all_arguments

    bname = instruction.name
    bname = bname + "#DD_%d" % kwargs['dependency_distance']
    bname = bname + "#BS_%d" % kwargs['benchmark_size']
    bname = bname + "#DI_%s" % kwargs['data_init']

    if MICROPROBE_RC['debugwrapper']:
        policy = find_policy(target.name, 'debug')
    else:
        policy = find_policy(target.name, 'epi')

    extension = ""

    if target.name.endswith("z64_mesa_st") or target.name.endswith(
            "z64_mesa_smt2"):

        wrapper_name = "Avp"
        wrapper_class = _get_wrapper(wrapper_name)
        wrapper = wrapper_class(reset=kwargs['reset'], )
        extension = "avp"

    elif target.name.endswith("ppc64_mesa"):

        wrapper_name = "Tst"
        wrapper_class = _get_wrapper(wrapper_name)
        wrapper = wrapper_class(
            outputname.replace("%INSTR%", bname).replace("%EXT%", "tst"),
            reset=kwargs['reset'],
        )
        extension = "tst"

    elif target.name.endswith("linux_gcc"):

        wrapper_name = "CInfGen"
        wrapper_class = _get_wrapper(wrapper_name)
        wrapper = wrapper_class(reset=kwargs['reset'])
        extension = "c"

    elif target.name.endswith("poe"):

        wrapper_name = "Poe"
        wrapper_class = _get_wrapper(wrapper_name)
        wrapper = wrapper_class(reset=kwargs['reset'], )
        extension = "bin"

    elif target.name.endswith("cronus"):

        wrapper_name = "Cronus"
        wrapper_class = _get_wrapper(wrapper_name)
        wrapper = wrapper_class(reset=kwargs['reset'], )
        extension = "bin"

    elif target.name.endswith("test_p"):

        wrapper_name = "RiscvTestsP"
        wrapper_class = _get_wrapper(wrapper_name)
        wrapper = wrapper_class(reset=kwargs['reset'], )
        extension = "S"

    else:
        raise NotImplementedError("Unsupported configuration '%s'" %
                                  target.name)

    if MICROPROBE_RC['debugwrapper']:
        extension = "s"

    extra_arguments = {}
    extra_arguments['instruction'] = instruction
    extra_arguments['benchmark_size'] = kwargs['benchmark_size']
    extra_arguments['dependency_distance'] = kwargs['dependency_distance']
    extra_arguments['data_init'] = kwargs['data_init']

    outputfile = os.path.join(outputdir, outputname)
    outputfile = outputfile.replace("%INSTR%", bname)
    outputfile = outputfile.replace("%EXT%", extension)

    if wrapper.outputname(outputfile) != outputfile:
        print_error("Fix outputname to have a proper extension. E.g. '%s'" %
                    wrapper.outputname(outputfile))
        exit(-1)

    if instruction.unsupported:
        print_info("%s not supported!" % instruction.name)
        return

    if kwargs['skip'] and os.path.isfile(outputfile):
        print_info("%s already generated!" % outputfile)
        return

    outputfile = new_file(wrapper.outputname(outputfile), internal=True)
    synth = policy.apply(target, wrapper, **extra_arguments)
    print_info("Generating %s..." % outputfile)

    if not kwargs["ignore_errors"]:
        bench = synth.synthesize()
    else:

        if os.path.exists("%s.fail" % outputfile):
            print_error("%s failed before. Skip." % outputfile)
            return

        try:
            bench = synth.synthesize()
        except (MicroprobeException, AssertionError) as exc:

            with open("%s.fail" % outputfile, 'a'):
                os.utime("%s.fail" % outputfile, None)

            print_error("%s" % exc)
            print_error("Generation failed and ignore error flag set")
            return

    synth.save(outputfile, bench=bench)
    print_info("%s generated!" % outputfile)

    return
예제 #2
0
def _generic_policy_wrapper(all_arguments):

    instructions, outputdir, outputname, target, kwargs = all_arguments

    outputfile = os.path.join(outputdir, "%DIRTREE%", outputname)
    outputfile = outputfile.replace(
        "%DIRTREE%", os.path.join(*[instr.name for instr in instructions]))

    if kwargs['shortnames']:
        outputfile = outputfile.replace(
            "%INSTR%", "mp_seq_%s" % hashlib.sha1("_".join(
                instr.name for instr in instructions).encode()).hexdigest())
    else:
        outputfile = outputfile.replace(
            "%INSTR%", "_".join(instr.name for instr in instructions))

    extension = ""
    if target.name.endswith("linux_gcc"):

        wrapper_name = "CInfGen"
        wrapper_class = _get_wrapper(wrapper_name)
        wrapper = wrapper_class(reset=kwargs['reset'])
        extension = "c"

    elif target.name.endswith("cronus"):

        wrapper_name = "Cronus"
        wrapper_class = _get_wrapper(wrapper_name)
        wrapper = wrapper_class(reset=kwargs['reset'],
                                endless=kwargs['endless'])
        extension = "bin"

    elif target.name.endswith("mesa"):

        wrapper_name = "Tst"
        extension = "tst"
        wrapper_class = _get_wrapper(wrapper_name)
        wrapper = wrapper_class(os.path.basename(
            outputfile.replace("%EXT%", extension)),
                                endless=kwargs['endless'],
                                reset=kwargs['reset'])

    elif target.name.endswith("riscv64_test_p"):

        wrapper_name = "RiscvTestsP"
        extension = "S"
        wrapper_class = _get_wrapper(wrapper_name)
        wrapper = wrapper_class(endless=kwargs['endless'],
                                reset=kwargs['reset'])

    elif target.environment.default_wrapper:

        wrapper_name = target.environment.default_wrapper
        wrapper_class = _get_wrapper(wrapper_name)
        wrapper = wrapper_class(endless=kwargs['endless'],
                                reset=kwargs['reset'])

        outputfile = outputfile.replace(".%EXT%", "")
        outputfile = wrapper.outputname(outputfile)

    else:
        raise NotImplementedError("Unsupported configuration '%s'" %
                                  target.name)

    if MICROPROBE_RC['debugwrapper']:
        extension = "s"

    outputfile = outputfile.replace("%EXT%", extension)

    if kwargs['skip'] and outputfile in _DIRCONTENTS:
        print_info("%s already exists!" % outputfile)
        return

    if (kwargs['skip'] and "%s.gz" % outputfile in _DIRCONTENTS
            and kwargs["compress"]):
        print_info("%s.gz already exists!" % outputfile)
        return

    if kwargs['skip'] and os.path.isfile(outputfile):
        print_info("%s already exists!" % outputfile)
        return

    if (kwargs['skip'] and os.path.isfile("%s.gz" % outputfile)
            and kwargs["compress"]):
        print_info("%s already exists!" % outputfile)
        return

    extra_arguments = {}
    extra_arguments['instructions'] = instructions
    extra_arguments['benchmark_size'] = kwargs['benchmark_size']
    extra_arguments['dependency_distance'] = kwargs['dependency_distance']
    extra_arguments['force_switch'] = kwargs['force_switch']
    extra_arguments['endless'] = kwargs['endless']

    if wrapper.outputname(outputfile) != outputfile:
        print_error(
            "Fix outputname '%s' to have a proper extension. E.g. '%s'" %
            (outputfile, wrapper.outputname(outputfile)))
        exit(-1)

    for instr in instructions:
        if instr.unsupported:
            print_info("%s not supported!" % instr.name)
            return

    policy = find_policy(target.name, 'seq')

    if not os.path.exists(os.path.dirname(outputfile)):
        os.makedirs(os.path.dirname(outputfile))

    outputfile = new_file(wrapper.outputname(outputfile), internal=True)

    print_info("Generating %s..." % outputfile)
    synth = policy.apply(target, wrapper, **extra_arguments)
    bench = synth.synthesize()

    synth.save(outputfile, bench=bench)

    print_info("%s generated!" % outputfile)

    if kwargs['compress']:
        move_file(outputfile, "%s.gz" % outputfile)
        print_info("%s compressed to %s.gz" % (outputfile, outputfile))

    return
예제 #3
0
def _generic_policy_wrapper(all_arguments):

    instructions, outputdir, outputname, target, kwargs = all_arguments

    extension = ""
    if target.name.endswith("linux_gcc"):

        wrapper_name = "CInfGen"
        wrapper_class = _get_wrapper(wrapper_name)
        wrapper = wrapper_class(reset=kwargs['reset'])
        extension = "c"

    elif target.name.endswith("cronus"):

        wrapper_name = "Cronus"
        wrapper_class = _get_wrapper(wrapper_name)
        wrapper = wrapper_class(reset=kwargs['reset'])
        extension = "bin"

    else:
        raise NotImplementedError("Unsupported configuration '%s'" %
                                  target.name)

    if MICROPROBE_RC['debugwrapper']:
        extension = "s"

    outputfile = os.path.join(outputdir, "%DIRTREE%", outputname)
    outputfile = outputfile.replace(
        "%DIRTREE%", os.path.join(*[instr.name for instr in instructions]))
    outputfile = outputfile.replace(
        "%INSTR%", "_".join(instr.name for instr in instructions))
    outputfile = outputfile.replace("%EXT%", extension)

    if kwargs['skip'] and outputfile in _DIRCONTENTS:
        print_info("%s already exists!" % outputfile)
        return

    if kwargs['skip'] and os.path.isfile(outputfile):
        print_info("%s already exists!" % outputfile)
        return

    extra_arguments = {}
    extra_arguments['instructions'] = instructions
    extra_arguments['benchmark_size'] = kwargs['benchmark_size']
    extra_arguments['dependency_distance'] = kwargs['dependency_distance']
    extra_arguments['force_switch'] = kwargs['force_switch']

    if wrapper.outputname(outputfile) != outputfile:
        print_error("Fix outputname to have a proper extension. E.g. '%s'" %
                    wrapper.outputname(outputfile))
        exit(-1)

    for instr in instructions:
        if instr.unsupported:
            print_info("%s not supported!" % instr.name)
            return

    policy = find_policy(target.name, 'seq')

    if not os.path.exists(os.path.dirname(outputfile)):
        os.makedirs(os.path.dirname(outputfile))

    outputfile = new_file(wrapper.outputname(outputfile), internal=True)

    print_info("Generating %s..." % outputfile)
    synth = policy.apply(target, wrapper, **extra_arguments)
    bench = synth.synthesize()
    synth.save(outputfile, bench=bench)
    print_info("%s generated!" % outputfile)

    return
예제 #4
0
def _generic_policy_wrapper(all_arguments):

    configuration, outputdir, outputname, target, kwargs = all_arguments

    instructions, mem_switch, data_switch, switch_branch, branch_pattern, \
        replace_every, add_every, memory_streams, \
        benchmark_size = configuration

    extrapath = []
    extrapath.append("BS_%d" % benchmark_size)
    extrapath.append("MS_%d" % mem_switch)
    extrapath.append("DS_%d" % data_switch)
    extrapath.append("BP_%s" % branch_pattern)
    extrapath.append("SB_%d" % switch_branch)

    for repl in replace_every:
        extrapath.append("RE_%d_%s_%s" % (repl[2], repl[0].name, repl[1].name))

    for addl in add_every:
        extrapath.append("AE_%d_%s" % (addl[1],
                                       "_".join(
                                           [elem.name for elem in addl[0]]
        )
        )
        )

    for mems in memory_streams:
        extrapath.append("ME_%d_%d_%d_%d_%d" % mems)

    outputfile = os.path.join(outputdir, "%DIRTREE%", outputname)
    outputfile = outputfile.replace(
        "%DIRTREE%", os.path.join(
            *([instr.name for instr in instructions] + extrapath)))
    outputfile = outputfile.replace(
        "%BASENAME%", "_".join(
            instr.name for instr in instructions) + "#" + "#".join(extrapath))

    extension = ""
    if target.name.endswith("linux_gcc"):

        wrapper_name = "CInfGen"
        wrapper_class = _get_wrapper(wrapper_name)
        wrapper = wrapper_class(
            reset=kwargs['reset']
        )
        extension = "c"

    elif target.name.endswith("cronus"):

        wrapper_name = "Cronus"
        wrapper_class = _get_wrapper(wrapper_name)
        wrapper = wrapper_class(
            reset=kwargs['reset']
        )
        extension = "bin"

    elif target.name.endswith("mesa"):

        wrapper_name = "Tst"
        extension = "tst"
        wrapper_class = _get_wrapper(wrapper_name)
        wrapper = wrapper_class(
            os.path.basename(outputfile.replace("%EXT%", extension)),
            reset=kwargs['reset']
        )

    elif target.name.endswith("riscv64_test_p"):

        wrapper_name = "RiscvTestsP"
        extension = "S"
        wrapper_class = _get_wrapper(wrapper_name)
        wrapper = wrapper_class(
            reset=kwargs['reset'],
            endless=True
        )

    else:
        raise NotImplementedError(
            "Unsupported configuration '%s'" % target.name
        )

    if MICROPROBE_RC['debugwrapper']:
        extension = "s"

    outputfile = outputfile.replace("%EXT%", extension)

    if kwargs['skip']:
        if os.path.exists(outputfile):
            print_info("%s already exists!" % outputfile)
            return

    if len(memory_streams) == 0:
        warnings.warn(
            "No memory streams provided "
            "using 1K stream stride 64 bytes"
        )
        memory_streams = [(1, 1024, 1, 64, 1)]

    streamid = 0
    new_memory_streams = []
    for stream in memory_streams:
        for elem in range(0, stream[0]):
            new_memory_streams.append([streamid] + list(stream)[1:])
            streamid += 1

    extra_arguments = {}
    extra_arguments['instructions'] = instructions
    extra_arguments['benchmark_size'] = benchmark_size
    extra_arguments['dependency_distance'] = kwargs['dependency_distance']
    extra_arguments['mem_switch'] = mem_switch
    extra_arguments['data_switch'] = data_switch
    extra_arguments['branch_pattern'] = branch_pattern
    extra_arguments['replace_every'] = replace_every
    extra_arguments['add_every'] = add_every
    extra_arguments['memory_streams'] = new_memory_streams
    extra_arguments['branch_switch'] = switch_branch

    if wrapper.outputname(outputfile) != outputfile:
        print_error(
            "Fix outputname to have a proper extension. E.g. '%s'" %
            wrapper.outputname(outputfile)
        )
        exit(-1)

    for instr in instructions:
        if instr.unsupported:
            print_info("%s not supported!" % instr.name)
            return

    policy = find_policy(target.name, 'seqtune')

    if not os.path.exists(os.path.dirname(outputfile)):
        os.makedirs(os.path.dirname(outputfile))

    outputfile = new_file(wrapper.outputname(outputfile), internal=True)

    print_info("Generating %s..." % outputfile)
    synth = policy.apply(target, wrapper, **extra_arguments)

    if not kwargs["ignore_errors"]:
        bench = synth.synthesize()
    else:

        if os.path.exists("%s.fail" % outputfile):
            print_error("%s failed before. Not generating" % outputfile)
            return

        try:
            bench = synth.synthesize()
        except Exception as exc:

            with open("%s.fail" % outputfile, 'a'):
                os.utime("%s.fail" % outputfile, None)

            print_error("%s" % exc)
            print_error("Generation failed for current configuration.")
            print_error("Generating next configurations.")
            return

    synth.save(outputfile, bench=bench)
    print_info("%s generated!" % outputfile)

    return