Exemple #1
0
def random_search(env: CompilerEnv):
    best = float("inf")
    for _ in range(FLAGS.gcc_search_budget):
        env.reset()
        env.choices = [
            random.randint(-1, min(FLAGS.max_range,
                                   len(opt) - 1))
            for opt in env.gcc_spec.options
        ]
        best = min(objective(env), best)
    return best
Exemple #2
0
def hill_climb(env: CompilerEnv):
    best = float("inf")
    for _ in range(FLAGS.gcc_search_budget):
        with env.fork() as fkd:
            fkd.choices = [
                random.randint(max(-1, x - 5),
                               min(len(env.gcc_spec.options[i]) - 1, x + 5))
                for i, x in enumerate(env.choices)
            ]
            cost = objective(fkd)
            if cost < objective(env):
                best = cost
                env.choices = fkd.choices
    return best