예제 #1
0
    def __init__(
        self,
        *args,
        target: OptimizationTarget,
        benchmark=None,
        max_copies_of_pass=4,
        **kwargs,
    ):
        super().__init__(*args, **kwargs)
        self.opt = str(opt_path())

        self.env = target.make_env(benchmark)
        self.env.reset()
        self.target = target
        self.observation_space = self.env.observation.spaces[
            target.optimization_space_enum_name]

        self.unoptimized_path = str(self.env.service.connection.cache.path /
                                    "opentuner-unoptimized.bc")
        self.tmp_optimized_path = str(self.env.service.connection.cache.path /
                                      "opentuner-optimized.bc")
        self.env.write_bitcode(self.unoptimized_path)
        self.env.write_bitcode(self.tmp_optimized_path)

        self.cost_o0 = self.env.observation["IrInstructionCountO0"]
        self.cost_oz = self.env.observation["IrInstructionCountOz"]

        self.flags_limit = self.env.action_space.n * max_copies_of_pass
        self.run_count = 0
        self.best_config = None
예제 #2
0
    def __init__(
        self,
        working_directory: Path,
        action_space: ActionSpace,
        benchmark: Benchmark,
        use_custom_opt: bool = True,
    ):
        super().__init__(working_directory, action_space, benchmark)
        logging.info("Started a compilation session for %s", benchmark.uri)
        self._benchmark = benchmark
        self._action_space = action_space

        self.inst2vec = _INST2VEC_ENCODER

        # Resolve the paths to LLVM binaries once now.
        self._clang = str(llvm.clang_path())
        self._llc = str(llvm.llc_path())
        self._llvm_diff = str(llvm.llvm_diff_path())
        self._opt = str(llvm.opt_path())
        # LLVM's opt does not always enforce the loop optimization options passed as cli arguments.
        # Hence, we created our own exeutable with custom unrolling and vectorization pass in examples/loops_opt_service/opt_loops that enforces the unrolling and vectorization factors passed in its cli.
        # if self._use_custom_opt is true, use our custom exeutable, otherwise use LLVM's opt
        self._use_custom_opt = use_custom_opt

        # Dump the benchmark source to disk.
        self._src_path = str(self.working_dir / "benchmark.c")
        with open(self.working_dir / "benchmark.c", "wb") as f:
            f.write(benchmark.program.contents)

        self._llvm_path = str(self.working_dir / "benchmark.ll")
        self._llvm_before_path = str(self.working_dir /
                                     "benchmark.previous.ll")
        self._obj_path = str(self.working_dir / "benchmark.o")
        self._exe_path = str(self.working_dir / "benchmark.exe")

        run_command(
            [
                self._clang,
                "-Xclang",
                "-disable-O0-optnone",
                "-emit-llvm",
                "-S",
                self._src_path,
                "-o",
                self._llvm_path,
            ],
            timeout=30,
        )
예제 #3
0
def llvm_opt() -> Path:
    """Test fixture that yields the path of opt."""
    return llvm.opt_path()