Esempio n. 1
0
def test_custom_models():

    # define the search model in a decoupled way
    # the model can query the history and returns a proposal
    # use weight factor to balance from multiple search engines
    @ut.model(name="random", weight=0.5)
    def random_prop(vars, history):
        prop = dict()
        while True:
            for key, scope in vars.iterate():
                if key == "v1":
                    prop[key] = 1
                else:
                    prop[key] = scope.random()
            if not history.duplicate(prop):
                break
        return prop

    v1 = ut.tune(3, (1, 9), name="v1")
    v2 = ut.tune(5, (2, ut.vars.v1), name="v2")
    v3 = ut.tune(5, (2, 7), name="v3")

    # register co-variates
    ut.register(random.randint(1, 10), name="temp")
    ut.target(v1 + v2 + v3 * 2, "max")
Esempio n. 2
0
def main(parse_only=False):

    # Create an EDA option pool
    if not parse_only:
        cleanup()
        option = OrderedDict()
        for key, values in options.items():
            option[key] = ut.tune(values[0], values, name=key)

        # If the design folder is symbolic
        if os.path.islink(design):
            os.unlink(design)

        t1 = Process(target=config, args=(option, ))
        t2 = Process(target=execute, args=(design, ))
        t1.daemon = True
        t2.daemon = True
        t1.start()
        t2.start()
        t1.join()
        t2.join()

    qor = 0
    index = "default"
    work_path = os.path.abspath("./")

    # TODO: Parse the data
    # We just copy the rpt to separate folder
    if os.getenv("UT_TUNE_START"):
        index = ut.get_global_id()
        work_path = os.path.join(ut.get_meta_data("UT_WORK_DIR"),
                                 "ut-work-dir")

    index = "ut-rpt-{}".format(index)
    rpt_folder = os.path.join(work_path, str(index))
    cmd = "mkdir -p {}; ".format(rpt_folder)
    cmd += "cd {}; ".format(design)
    cmd += "cp acl_quartus_report.txt quartus_sh_compile.log *json *rpt *qsf {}; cp ../*log {}".format(
        rpt_folder, rpt_folder)
    run_process(cmd)

    # Read frequency
    rpt = "{}/acl_quartus_report.txt".format(rpt_folder)
    if os.path.isfile(rpt):
        with open(rpt, "r") as fp:
            content = str(fp.readlines())
            match = re.search(r"Kernel fmax: (\d+\.\d+)", content)
            qor = float(match[1])
    else:
        print("Cannot find acl quartus report...")
        qor = -1 * float("inf")

    # Remove temp in profiling phase
    if os.getenv("UT_BEFORE_RUN_PROFILE"):
        cleanup()

    # Set the target
    ut.target(qor, "max")
Esempio n. 3
0
def test_constraints():
    
    # limit the search space
    @ut.rule(name="remove_outlier")
    def rule(vars):
        if (vars.v1 < 5) and (vars.v2 > 5):
            vars.v3 = 10
        
    v1 = ut.tune(3, (1, 9), name="v1") 
    v2 = ut.tune(5, (2, ut.vars.v1), name="v2") 
    v3 = ut.tune(5, (2, 7), name="v3") 

    # register co-variates
    ut.register(random.randint(1, 10), name="temp")
    ut.target(v1 + v2 + v3 *2, "max")
Esempio n. 4
0
def test_query():

    # limit search result to satisfy certain conditions
    @ut.constraint(name="limit")
    def requirements(vars):
        conditions = [
            vars.temp > 2,
            var.v1 + vars.v3 < 5,
        ]
        return conditions

    v1 = ut.tune(3, (1, 9), name="v1")
    v2 = ut.tune(5, (2, ut.vars.v1), name="v2")
    v3 = ut.tune(5, (2, 7), name="v3")

    a = random.randint(0, 10)
    ut.register(a * 2, name="temp")
    ut.target(v1 + v2 - v3, "max")
Esempio n. 5
0
    at2 = ut.tune(6, [6, 8, 10, 12])
    if at == 'resub':
        at += ' -K ' + str(at2)
    syn_all.append(at)


def abc_synthesis_flow(aig_pth="i10.aig"):
    command = "abc -c \"read %s;" % aig_pth
    for at in syn_all:
        command += at + ";"
    command += "if -K 6;print_stats\" > abc_if_res.log"
    return command


print(abc_synthesis_flow()[:-16])
process = subprocess.Popen(abc_synthesis_flow(), shell=True)
process.wait()


def res():
    with open("abc_if_res.log", 'rb') as f:
        l = f.readlines()[-1]
    f.close()
    #print(str(l))
    x = re.findall("\d+", str(l))
    print("%s: #LUT = %d ; #LEV = %d" % (aig_pth, int(x[9]), int(x[-1])))
    return int(x[9]), int(x[-1])  # lut count, depth


val = ut.target(res()[0], objective='min')
Esempio n. 6
0
import uptune as ut

x = ut.tune(2, (2, 15), name="x")
y = ut.tune(5, (2, 12), name="y")
a = ut.tune(2, (2, 15), name="a")
b = ut.tune(5, (2, 12), name="b")

# Expected causal graph
xy = x * y + x * x
ab = a * a + b * b + a * b

res = ab - xy
ut.feature(ab, "ab")
ut.feature(xy, "xy")

ut.target(res, "max")
Esempio n. 7
0
def main(parse_only=False):

    # Create an EDA option pool
    option = OrderedDict()
    if not parse_only:
        cleanup()
        for key, values in options.items():
            option[key] = ut.tune(values[0], values, name=key)

        config(option)
        pwd = os.getcwd()
        t1 = Process(target=execute, args=(pwd,)) 
        t1.daemon = True
        t1.start()
        t1.join()

    # Extract QoR result
    qor = 0; index = "default"
    work_path = os.path.abspath("./")
    
    # TODO: Parse the data
    # We just copy the rpt to separate folder
    if os.getenv("UT_TUNE_START"):        
        index = ut.get_global_id()
        work_path = os.path.join(ut.get_meta_data("UT_WORK_DIR"), "ut.temp")

    index = "ut.rpt.{}".format(index)
    rpt_folder = os.path.join(work_path, str(index))

    cmd = "mkdir -p {}; cp build_dir.hw.xilinx_u280_xdma_201920_1/reports/link/imp/* {}"\
        .format(rpt_folder, rpt_folder)
    run_process(cmd)
    # cp the vivado log and config files
    cmd = "cp build_dir.hw.xilinx_u280_xdma_201920_1/link/vivado/vpl/vivado.log {}; cp *config.ini {}"\
        .format(rpt_folder, rpt_folder)
    run_process(cmd)

    # Read frequency
    rpt = "{}/xilinx_u280_xdma_201920_1_bb_locked_timing_summary_postroute_physopted.rpt".format(rpt_folder)
    if os.path.isfile(rpt):
        with open(rpt, "r") as fp:
            content = fp.readlines()
            index = 0
            for line in content:
                if "Design Timing Summary" in line:
                    numbers = content[index+6].strip().split()
                    wns = float(numbers[0])
                    tns = float(numbers[1])
                    qor = (1000 / float(option["Frequency"])) - wns
                    break
                index += 1
    else:
        print("Cannot find vivado timing report...")
        qor = float("inf")
    
    # Remove temp in profiling phase
    if os.getenv("UT_BEFORE_RUN_PROFILE"):
        cleanup()

    # Set the target
    ut.target(qor, "min")
Esempio n. 8
0
def test_async_execution():
    stall = ut.tune(10, (0, 20), name="stall")
    time.sleep(stall)
    ut.target(stall, "max")
Esempio n. 9
0
for flag in found_cc_flags:
    options[flag] = ut.tune('default', ['on', 'off', 'default'], name=flag)

for param in working_params:
    defaults = param_defaults[param]
    if defaults['max'] <= defaults['min']: defaults['max'] = float('inf')
    defaults['max'] = min(defaults['max'],
                          max(1, defaults['default']) * args.scaler)
    defaults['min'] = max(defaults['min'],
                          old_div(max(1, defaults['default']), args.scaler))

    if param == 'l1-cache-line-size':
        # gcc requires this to be a power of two or it internal errors
        options[param] = 2**ut.tune(defaults['default'], (2, 8), name=param)

    elif defaults['max'] > 128:
        options[param] = ut.tune(defaults['default'],
                                 (defaults['min'], defaults['max']),
                                 name=param)
        # m.add_parameter(manipulator.LogIntegerParameter(
        #   param, defaults['min'], defaults['max']))
    else:
        options[param] = ut.tune(defaults['default'],
                                 (defaults['min'], defaults['max']),
                                 name=param)

cmd = make_command(options)
runtime = run_with_flags([], cmd)
print("Runtime {} ms".format(runtime))
ut.target(runtime, "min")
Esempio n. 10
0
           isinstance(default, (bool, list)), \
           "for boolean or permutation range should be ()"
    if isinstance(default, bool):
        return types.TuneBool(default, name=name).val
    else:  # create permutation param
        return types.TunePermutation(default, name=name).val


def tune_at(default, tuning_range, path, name):
    # check local file
    assert os.path.isfile(path), "file not exist"
    val = tune(default, tuning_range, name=name)
    with open(path, 'r+') as fp:
        txt = fp.read().replace(name, val)
        fp.seek(0)
        fp.truncate()
        fp.write(txt)


if __name__ == "__main__":
    os.environ["EZTUNING"] = "ON"
    # os.environ["ANALYSIS"] = "ON"
    a = tune(2, (6, 8))
    b = tune(2, (7, 8))
    c = tune(2, (7, 8))
    print(types.TuneBase.names)

    from uptune import target
    res = target(2 * a + b)
    print(res)
Esempio n. 11
0
#!/usr/bin/env python
#
# test case - permutation parameter
#
import uptune as ut

dataset = ["p01_d.txt", "att48_d.txt", "p01_s.txt"]
data = "data/" + dataset[0]
m = open(data).readlines()
distance = [[int(i) for i in l.split()] for l in m]


def eval(p):
    return sum(distance[p[i]][p[i + 1]] for i in range(len(p) - 1))


default = list(range(len(distance)))
p = ut.tune(default, name="perm")

# return the distance
ret = ut.target(eval(p))
Esempio n. 12
0
import time
import uptune as ut

a = ut.tune(1, (2, 109))
b = ut.tune(1, (3, 999))
c = ut.tune(1, (4, 239))
res = ut.target(2 * a + c)

time.sleep(10)

d = ut.tune(1, (5, 89))
e = ut.tune(1, (6, 909))
f = ut.tune(1, (2, 1299))
val = ut.target(2 * f + a)
Esempio n. 13
0
                                                      ['On', 'Off', 'Auto'])
mux_restructure = ut.tune('Off', ['On', 'Off', 'Auto'])
optimization_technique = ut.tune('Area', ['Area', 'Speed', 'Balanced'])
synthesis_effort = ut.tune('Auto', ['Auto', 'Fast'])
synth_timing_driven_synthesis = ut.tune('On', ['On', 'Off'])
fitter_aggressive_routability_optimization = ut.tune(
    'Never', ['Always', 'Automatically', 'Never'])
fitter_effort = ut.tune('Auto Fit', ['Standard Fit', 'Auto Fit'])
remove_duplicate_registers = ut.tune('On', ['On', 'Off'])
physical_synthesis = ut.tune('On', ['On', 'Off'])

arg_list = ('auto_dsp_recognition',
            'disable_register_merging_across_hierarchies', 'mux_restructure',
            'optimization_technique', 'synthesis_effort',
            'synth_timing_driven_synthesis',
            'fitter_aggressive_routability_optimization', 'fitter_effort',
            'remove_duplicate_registers', 'physical_synthesis')

config = dict()
for i in arg_list:
    config[i] = locals()[i]

# Run thru logic synthesis & packing
# Features are returned & rated by ML modesl
# the program exits with less promising result
features = ut.interm(prestage(config, design))
print(features)

# Run thru placing and routing
qor = ut.target(poststage(config, design))
import uptune as ut

a = 'a'  # {% a = TuneEnum('a', ['a', 'b', 'c', 'd', 'e', 'f', 'g']) %}
b = 'c'  # {% b = TuneEnum('c', ['a', 'b', 'c', 'd', 'e', 'f', 'g']) %}

val = ut.target(hash(a) - hash(b))
Esempio n. 15
0
import uptune as ut

# define the design search space
chars = [chr(i) for i in range(97, 97 + 26)]

a = ut.tune('a', chars)
b = ut.tune('c', chars)

c = ut.tune(0.2, (1.0, 9.0), name="c")
d = ut.tune(2, (1, 9), name="d")

print(ut.c, type(ut.d))

ut.constraint(ut.c * ut.d < 9)
res = ut.target(c * hash(a) - d * hash(b))
Esempio n. 16
0
        self.result = float(result)
        self.objective = objective
        assert objective in ['minimize', 'maximize'], "unrecognized objective"


if __name__ == '__main__':

    import uptune.template.types as shared
    os.environ["EZTUNING"] = "ON"
    os.environ["ANALYSIS"] = "ON"
    factor = shared.TuneInt(4, (3, 5), 'xxx')
    factow = shared.TuneInt(6, (3, 5)).val
    factoe = shared.TuneEnum(8, [3, 5, 89], 'xxxa').val
    factot = shared.TuneEnum(8, [5, 9, 7], 'xa').val

    for obj in TuneEnum._get_instances():
        obj.set_node(0)

    print(shared.TuneEnum._get_instances())
    print(shared.TuneInt._get_instances())
    print(shared.TuneBase._get_instances(recursive=True))

    shared.TuneBase._remove_instance(factor)
    print(shared.TuneBase._get_instances(recursive=True))
    print(TuneBase.params)

    # save result
    from uptune import target
    res = target(factoe * 2)
    print(res)