diff --git a/WORKSPACE b/WORKSPACE index 46bdeae55d..4b0501c47f 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,6 +1,6 @@ workspace(name = "CompilerGym") -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file") # === Google test === @@ -201,11 +201,81 @@ filegroup( ) http_archive( + name = "ctuning-ai", + build_file = "//:compiler_gym/third_party/ctuning-ai.BUILD", + sha256 = "2e12233a3d898a96a2ce279123ee256bee357f649e3c579f974628b6c35ea53d", + strip_prefix = "ai-afaba3e2900523a0813693fd614a114b4a6f6729", + urls = ["https://github.com/ctuning/ai/archive/afaba3e2900523a0813693fd614a114b4a6f6729.tar.gz"], +) + +# Datasets. + +http_file( + name = "cBench_consumer_tiff_data", + sha256 = "779abb7b7fee8733313e462e6066c16375e9209a9f7ff692fd06c7598946939a", + urls = ["https://downloads.sourceforge.net/project/cbenchmark/cDatasets/V1.1/cDatasets_V1.1_consumer_tiff_data.tar.gz"], +) + +http_file( + name = "cBench_office_data", + sha256 = "cfa09cd37cb93aba57415033905dc6308653c7b833feba5a25067bfb62999f32", + urls = ["https://downloads.sourceforge.net/project/cbenchmark/cDatasets/V1.1/cDatasets_V1.1_office_data.tar.gz"], +) + +http_file( + name = "cBench_telecom_data", + sha256 = "e5cb6663beefe32fd12f90c8f533f8e1bce2f05ee4e3836efb5556d5e1089df0", + urls = ["https://downloads.sourceforge.net/project/cbenchmark/cDatasets/V1.1/cDatasets_V1.1_telecom_data.tar.gz"], +) + +http_file( + name = "cBench_consumer_jpeg_data", + sha256 = "bec5ffc15cd2f952d9a786f3cd31d90955c318a5e4f69c5ba472f79d5a3e8f0b", + urls = ["https://downloads.sourceforge.net/project/cbenchmark/cDatasets/V1.1/cDatasets_V1.1_consumer_jpeg_data.tar.gz"], +) + +http_file( + name = "cBench_telecom_gsm_data", + sha256 = "52545d3a0ce15021131c62d96d3a3d7e6670e2d6c34226ac9a3d5191a1ee214a", + urls = ["https://downloads.sourceforge.net/project/cbenchmark/cDatasets/V1.1/cDatasets_V1.1_telecom_gsm_data.tar.gz"], +) + +http_file( + name = "cBench_consumer_data", + sha256 = "a4d40344af3022bfd7b4c6fcf6d59d598825b07d9e37769dbf1b3effa39aa445", + urls = ["https://downloads.sourceforge.net/project/cbenchmark/cDatasets/V1.1/cDatasets_V1.1_consumer_data.tar.gz"], +) + +http_file( + name = "cBench_bzip2_data", + sha256 = "46e5760eeef77e6b0c273af92de971bc45f33a59e0efc183073d9aa6b716c302", + urls = ["https://downloads.sourceforge.net/project/cbenchmark/cDatasets/V1.1/cDatasets_V1.1_bzip2_data.tar.gz"], +) + +http_file( + name = "cBench_network_patricia_data", + sha256 = "72dae0e670d93ef929e50aca7a138463e0915502281ccafe793e378cb2a85dfb", + urls = ["https://downloads.sourceforge.net/project/cbenchmark/cDatasets/V1.1/cDatasets_V1.1_network_patricia_data.tar.gz"], +) + +http_file( name = "cBench_network_dijkstra_data", - build_file_content = all_content, + sha256 = "41c13f59cdfbc772081cd941f499b030370bc570fc2ba60a5c4b7194bc36ca5f", urls = ["https://downloads.sourceforge.net/project/cbenchmark/cDatasets/V1.1/cDatasets_V1.1_network_dijkstra_data.tar.gz"], ) +http_file( + name = "cBench_automotive_susan_data", + sha256 = "df56e1e44ccc560072381cdb001d770003ac74f92593dd5dbdfdd4ff9332a8e6", + urls = ["https://downloads.sourceforge.net/project/cbenchmark/cDatasets/V1.1/cDatasets_V1.1_automotive_susan_data.tar.gz"], +) + +http_file( + name = "cBench_automotive_qsort_data", + sha256 = "510b4225021408ac190f6f793e7d7171d3553c9916cfa8b2fb4ace005105e768", + urls = ["https://downloads.sourceforge.net/project/cbenchmark/cDatasets/V1.1/cDatasets_V1.1_automotive_qsort_data.tar.gz"], +) + # === C++ cpuinfo === http_archive( diff --git a/compiler_gym/envs/compiler_env.py b/compiler_gym/envs/compiler_env.py index 0fbdbb9985..cbf822764d 100644 --- a/compiler_gym/envs/compiler_env.py +++ b/compiler_gym/envs/compiler_env.py @@ -795,7 +795,7 @@ def register_dataset(self, dataset: Dataset) -> bool: >>> env.benchmark = "my-dataset-v0/1" :param dataset: A :class:`Dataset` instance describing the new dataset. - :return: :code:`True` if the dataset was registered added, else :code:`False`. + :return: :code:`True` if the dataset was added, else :code:`False`. :raises ValueError: If a dataset with this name is already registered. """ platform = {"darwin": "macos"}.get(sys.platform, sys.platform) diff --git a/compiler_gym/envs/llvm/BUILD b/compiler_gym/envs/llvm/BUILD index c65478ad7d..10daf39019 100644 --- a/compiler_gym/envs/llvm/BUILD +++ b/compiler_gym/envs/llvm/BUILD @@ -33,8 +33,12 @@ py_library( py_library( name = "datasets", srcs = ["datasets.py"], + data = [ + "//compiler_gym/third_party/llvm:clang", + ], deps = [ "//compiler_gym/datasets:dataset", + "//compiler_gym/util", ], ) diff --git a/compiler_gym/envs/llvm/datasets.py b/compiler_gym/envs/llvm/datasets.py index a4cf787259..034c330313 100644 --- a/compiler_gym/envs/llvm/datasets.py +++ b/compiler_gym/envs/llvm/datasets.py @@ -3,9 +3,44 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. """This module defines the available LLVM datasets.""" -from typing import Callable, Dict, Optional +import io +import os +import re +import shutil +import subprocess +import sys +import tarfile +import tempfile +from collections import defaultdict +from concurrent.futures import ThreadPoolExecutor, as_completed +from contextlib import contextmanager +from pathlib import Path +from typing import Callable, Dict, List, NamedTuple, Optional + +import fasteners +import gym from compiler_gym.datasets.dataset import Dataset +from compiler_gym.util.download import download +from compiler_gym.util.runfiles_path import cache_path, runfiles_path, site_data_path +from compiler_gym.util.timer import Timer + +_CLANG = runfiles_path("CompilerGym/compiler_gym/third_party/llvm/clang") + +_CBENCH_DATA = site_data_path("llvm/cBench-v0-runtime-data/runtime_data") +_CBENCH_DATA_URL = ( + "https://dl.fbaipublicfiles.com/compiler_gym/cBench-v0-runtime-data.tar.bz2" +) +_CBENCH_DATA_SHA256 = "a1b5b5d6b115e5809ccaefc2134434494271d184da67e2ee43d7f84d07329055" + + +if sys.platform == "darwin": + _COMPILE_ARGS = [ + "-L", + "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib", + ] +else: + _COMPILE_ARGS = [] LLVM_DATASETS = [ Dataset( @@ -20,13 +55,25 @@ ), Dataset( name="cBench-v0", - url="https://dl.fbaipublicfiles.com/compiler_gym/llvm_bitcodes-10.0.0-cBench-v0.tar.bz2", + url="https://dl.fbaipublicfiles.com/compiler_gym/llvm_bitcodes-10.0.0-cBench-v0-macos.tar.bz2", + license="BSD 3-Clause", + description="https://github.com/ctuning/ctuning-programs", + compiler="llvm-10.0.0", + file_count=23, + size_bytes=7154448, + sha256="072a730c86144a07bba948c49afe543e4f06351f1cb17f7de77f91d5c1a1b120", + platforms=["macos"], + ), + Dataset( + name="cBench-v0", + url="https://dl.fbaipublicfiles.com/compiler_gym/llvm_bitcodes-10.0.0-cBench-v0-linux.tar.bz2", license="BSD 3-Clause", description="https://github.com/ctuning/ctuning-programs", compiler="llvm-10.0.0", file_count=23, - size_bytes=7150112, - sha256="498425efe8e335eb72623df50427eca87333d011f017ec3be5608883b4b7687a", + size_bytes=6940416, + sha256="9b5838a90895579aab3b9375e8eeb3ed2ae58e0ad354fec7eb4f8b31ecb4a360", + platforms=["linux"], ), Dataset( name="github-v0", @@ -110,12 +157,554 @@ ), ] -# A map from benchmark name to a callback which takes as input an LlvmEnv -# instance and returns None if the environment is valid, else a string error -# message. -# -# TODO(cummins): Populate this map for cBench using the CK meta properties. -# See: https://github.com/ctuning/ai/blob/main/program/cbench-bzip2/.cm/meta.json -LLVM_BENCHMARK_VALIDATION_CALLBACKS: Dict[ - str, Callable[["LlvmEnv"], Optional[str]] -] = {} + +class BenchmarkExecutionResult(NamedTuple): + """The result of running a benchmark.""" + + walltime_seconds: float + """The execution time in seconds.""" + + error: Optional[str] = None + """An error message.""" + + output: Optional[str] = None + """The output generated by the benchmark.""" + + +def _compile_and_run_bitcode_file( + bitcode_file: Path, + cmd: str, + cwd: Path, + linkopts: List[str], + num_runs: int, + timeout_seconds: float = 60, +) -> BenchmarkExecutionResult: + """Run the given cBench benchmark.""" + binary = cwd / "a.out" + + # cBench benchmarks expect that a file _finfo_dataset exists in the + # current working directory and contains the number of benchmark + # iterations in it. + with open(cwd / "_finfo_dataset", "w") as f: + print(num_runs, file=f) + + # Generate the a.out binary file. + assert not binary.is_file() + subprocess.check_call( + [_CLANG, str(bitcode_file), "-o", str(binary)] + _COMPILE_ARGS + list(linkopts) + ) + assert binary.is_file() + + process = subprocess.Popen( + cmd, + shell=True, + stderr=subprocess.STDOUT, + stdout=subprocess.PIPE, + env=os.environ, + cwd=cwd, + ) + + try: + with Timer() as timer: + stdout, _ = process.communicate(timeout=timeout_seconds) + except subprocess.TimeoutExpired: + process.kill() + return BenchmarkExecutionResult( + walltime_seconds=timeout_seconds, + error=f"Benchmark failed to complete with {timeout_seconds} timeout.", + ) + finally: + binary.unlink() + + if process.returncode: + try: + output = stdout.decode("utf-8") + msg = f"Benchmark exited with returncode {process.returncode}. Output: {output}" + except UnicodeDecodeError: + msg = f"Benchmark exited with returncode {process.returncode}" + return BenchmarkExecutionResult(walltime_seconds=timer.time, error=msg) + + return BenchmarkExecutionResult(walltime_seconds=timer.time, output=stdout) + + +@fasteners.interprocess_locked(cache_path("cBench-v0-runtime-data.LOCK")) +def download_cBench_runtime_data() -> bool: + """Download and unpack the cBench runtime dataset.""" + if _CBENCH_DATA.is_dir(): + return False + else: + tar_contents = io.BytesIO( + download(_CBENCH_DATA_URL, sha256=_CBENCH_DATA_SHA256) + ) + with tarfile.open(fileobj=tar_contents, mode="r:bz2") as tar: + _CBENCH_DATA.parent.mkdir(parents=True) + tar.extractall(_CBENCH_DATA.parent) + assert _CBENCH_DATA.is_dir() + return True + + +def _make_cBench_validator( + cmd: str, + linkopts: List[str], + os_env: Dict[str, str], + num_runs: int = 1, + compare_output: bool = True, + input_files: Optional[List[Path]] = None, + output_files: Optional[List[Path]] = None, + validate_result: Optional[ + Callable[[BenchmarkExecutionResult], Optional[str]] + ] = None, + pre_execution_callback: Optional[Callable[[], None]] = None, +): + """Construct a validation callback for a cBench benchmark. See validator() for usage.""" + input_files = input_files or [] + output_files = output_files or [] + + def validator_cb(env): + """The validation callback.""" + for path in input_files: + if not path.is_file(): + raise FileNotFoundError(f"Required benchmark input not found: {path}") + + # Expand shell variable substitutions in the benchmark command. + expanded_command = expand_command_vars(cmd) + + with tempfile.TemporaryDirectory(dir=env.service.connection.working_dir) as d: + # Execute the benchmark in a temporary working directory. + cwd = Path(d) + # Translate the output file names into paths inside the working + # directory. + output_paths = [cwd / o for o in output_files] + + with benchmark_execution_environment(os_env): + if pre_execution_callback: + pre_execution_callback() + + # Produce a gold-standard output using a reference version of + # the benchmark. + if compare_output or output_files: + gs_env = gym.make("llvm-v0") + try: + gs_env.reset(benchmark=env.benchmark) + # Serialize the benchmark to a bitcode file that will then be + # compiled to a binary. + bitcode_file = Path(gs_env.observation["BitcodeFile"]) + try: + gold_standard = _compile_and_run_bitcode_file( + bitcode_file=bitcode_file, + cmd=expanded_command, + cwd=cwd, + num_runs=1, + linkopts=linkopts, + ) + if gold_standard.error: + raise OSError( + f"Failed to produce reference output for benchmark '{env.benchmark}' " + f"using '{cmd}': {gold_standard.error}" + ) + finally: + bitcode_file.unlink() + finally: + gs_env.close() + + # Check that the reference run produced the expected output + # files. + for path in output_paths: + if not path.is_file(): + try: + output = gold_standard.output.decode("utf-8") + except UnicodeDecodeError: + output = "" + raise FileNotFoundError( + f"Expected file '{path}' not generated\n" + f"Benchmark: {env.benchmark}\n" + f"Command: {cmd}\n" + f"Output: {output}" + ) + path.rename(f"{path}.gold_standard") + + # Serialize the benchmark to a bitcode file that will then be + # compiled to a binary. + bitcode_file = Path(env.observation["BitcodeFile"]) + try: + outcome = _compile_and_run_bitcode_file( + bitcode_file=bitcode_file, + cmd=expanded_command, + cwd=cwd, + num_runs=num_runs, + linkopts=linkopts, + ) + finally: + bitcode_file.unlink() + + if outcome.error: + return outcome.error + + # Run a user-specified validation hook. + if validate_result: + validate_result(outcome) + + # Difftest the console output. + if compare_output and gold_standard.output != outcome.output: + try: + return ( + f"Benchmark output differs from expected.\n" + f"Expected: {gold_standard.decode('utf-8')}\n" + f"Actual: {outcome.output.decode('utf-8')}" + ) + except UnicodeDecodeError: + return f"Benchmark output differs from expected (binary diff)" + + # Difftest the output files. + for path in output_paths: + if not path.is_file(): + return f"Expected file not generated by benchmark {env.benchmark}: {path}.\nCommand: {cmd}" + diff = subprocess.Popen(["diff", str(path), f"{path}.gold_standard"]) + stdout, _ = diff.communicate() + if diff.returncode: + try: + return f"Benchmark output file '{path}' differs from expected: {stdout}" + except UnicodeDecodeError: + return f"Benchmark output file '{path}' differs from expected (binary diff)" + + return validator_cb + + +@contextmanager +def temporary_environment(): + """Yield a temporary os.environ state.""" + _environ = os.environ.copy() + try: + yield + finally: + os.environ.clear() + os.environ.update(_environ) + + +@contextmanager +def benchmark_execution_environment(env: Dict[str, str]): + """Setup the os.environ state for executing benchmarks.""" + with temporary_environment(): + for var in os.environ: + if not var.startswith("COMPILER_GYM_SITE_DATA") and var not in { + "PATH", + "RUNFILES_DIR", + "RUNFILES_MANIFEST_FILE", + "USER", + "SHELL", + "TERM", + "TMPDIR", + "HOME", + }: + del os.environ[var] + for key, val in env.items(): + os.environ[key] = expand_command_vars(val) + yield + + +def expand_command_vars(cmd: str) -> str: + """Expand shell variables in a command.""" + with temporary_environment(): + os.environ.clear() + os.environ["BIN"] = "./a.out" + os.environ["D"] = str(_CBENCH_DATA) + return os.path.expandvars(cmd) + + +# A map from benchmark name to validation callbacks. Defined below. +_VALIDATORS: Dict[str, List[Callable[["LlvmEnv"], Optional[str]]]] = defaultdict(list) + + +def validator( + benchmark: str, + cmd: str, + data: Optional[List[str]] = None, + outs: Optional[List[str]] = None, + platforms: Optional[List[str]] = None, + compare_output: bool = True, + validate_result: Optional[ + Callable[[BenchmarkExecutionResult], Optional[str]] + ] = None, + linkopts: List[str] = None, + env: Dict[str, str] = None, + pre_execution_callback: Optional[Callable[[], None]] = None, +) -> bool: + """Declare a new benchmark validator. + + TODO(cummins): Pull this out into a public API. + + :param benchmark: The name of the benchmark that this validator supports. + :cmd: The shell command to run the validation. Variable substitution is + applied to this value as follows: :code:`$BIN` is replaced by the path + of the compiled binary and :code:`$D` is replaced with the path to the + benchmark's runtime data directory. + :data: A list of paths to input files. + :outs: A list of paths to output files. + :return: :code:`True` if the new validator was registered, else :code:`False`. + """ + platforms = platforms or ["linux", "macos"] + if {"darwin": "macos"}.get(sys.platform, sys.platform) not in platforms: + return False + infiles = [_CBENCH_DATA / p for p in data or []] + outfiles = [Path(p) for p in outs or []] + linkopts = linkopts or [] + env = env or {} + + _VALIDATORS[benchmark].append( + _make_cBench_validator( + cmd=cmd, + input_files=infiles, + output_files=outfiles, + compare_output=compare_output, + validate_result=validate_result, + linkopts=linkopts, + os_env=env, + pre_execution_callback=pre_execution_callback, + ) + ) + + return True + + +def get_llvm_benchmark_validation_callback( + env: "LlvmEnv", +) -> Optional[Callable[["LlvmEnv"], Optional[str]]]: + """Return a callback for validating a given environment state. + + If there is no valid callback, returns :code:`None`. + + :param env: An :class:`LlvmEnv` instance. + :return: An optional callback that takes an :class:`LlvmEnv` instance as + argument and returns an optional string containing a validation error + message. + """ + validators = _VALIDATORS.get(env.benchmark) + + # No match. + if not validators: + return None + + def composed(env): + download_cBench_runtime_data() + + # Validation callbacks are read-only on the environment so it is + # safe to run validators simultaneously in parallel threads. + with ThreadPoolExecutor() as executor: + futures = [executor.submit(validator, env) for validator in validators] + result = None + for future in as_completed(futures): + result = future.result() or result + return result + + return composed + + +# =============================== +# Definition of cBench validators +# =============================== + + +def validate_sha_output(result: BenchmarkExecutionResult): + """SHA benchmark prints 5 random hex strings. Normally these hex strings are + 16 characters but occasionally they are less (presumably becuase of a + leading zero being omitted). + """ + assert re.match( + r"[0-9a-f]{0,16} [0-9a-f]{0,16} [0-9a-f]{0,16} [0-9a-f]{0,16} [0-9a-f]{0,16}", + result.output.decode("utf-8").rstrip(), + ) + + +def setup_ghostscript_library_files(): + """Pre-execution setup hook for ghostscript.""" + # Copy input data into current directory since ghostscript doesn't like long + # input paths. + for path in (_CBENCH_DATA / "office_data").iterdir(): + if path.name.endswith(".ps"): + shutil.copyfile(path, path.name) + # Ghostscript doesn't like the library files being symlinks so copy them + # into the working directory as regular files. + for path in (_CBENCH_DATA / "ghostscript").iterdir(): + if path.name.endswith(".ps"): + shutil.copyfile(path, path.name) + + +validator( + benchmark="benchmark://cBench-v0/bitcount", + cmd="$BIN 1125000", +) + +validator( + benchmark="benchmark://cBench-v0/bitcount", + cmd="$BIN 512", +) + +for i in range(1, 21): + validator( + benchmark="benchmark://cBench-v0/adpcm", + cmd=f"$BIN $D/telecom_data/{i}.adpcm", + data=[f"telecom_data/{i}.adpcm"], + ) + + validator( + benchmark="benchmark://cBench-v0/adpcm", + cmd=f"$BIN $D/telecom_data/{i}.pcm", + data=[f"telecom_data/{i}.pcm"], + ) + + validator( + benchmark="benchmark://cBench-v0/blowfish", + cmd=f"$BIN d $D/office_data/{i}.benc output.txt 1234567890abcdeffedcba0987654321", + data=[f"office_data/{i}.benc"], + outs=["output.txt"], + ) + + validator( + benchmark="benchmark://cBench-v0/bzip2", + cmd=f"$BIN -d -k -f -c $D/bzip2_data/{i}.bz2", + data=[f"bzip2_data/{i}.bz2"], + ) + + validator( + benchmark="benchmark://cBench-v0/crc32", + cmd=f"$BIN $D/telecom_data/{i}.pcm", + data=[f"telecom_data/{i}.pcm"], + ) + + validator( + benchmark="benchmark://cBench-v0/dijkstra", + cmd=f"$BIN $D/network_dijkstra_data/{i}.dat", + data=[f"network_dijkstra_data/{i}.dat"], + ) + + validator( + benchmark="benchmark://cBench-v0/gsm", + cmd=f"$BIN -fps -c $D/telecom_gsm_data/{i}.au", + data=[f"telecom_gsm_data/{i}.au"], + ) + + # TODO(cummins): ispell executable appears broken. Investigation needed. + # validator( + # benchmark="benchmark://cBench-v0/ispell", + # cmd=f"$BIN -a -d americanmed+ $D/office_data/{i}.txt", + # data = [f"office_data/{i}.txt"], + # ) + + validator( + benchmark="benchmark://cBench-v0/jpeg-c", + cmd=f"$BIN -dct int -progressive -outfile output.jpeg $D/consumer_jpeg_data/{i}.ppm", + data=[f"consumer_jpeg_data/{i}.ppm"], + outs=["output.jpeg"], + ) + + validator( + benchmark="benchmark://cBench-v0/jpeg-d", + cmd=f"$BIN -dct int -outfile output.ppm $D/consumer_jpeg_data/{i}.jpg", + data=[f"consumer_jpeg_data/{i}.jpg"], + outs=["output.ppm"], + ) + + validator( + benchmark="benchmark://cBench-v0/patricia", + cmd=f"$BIN $D/network_patricia_data/{i}.udp", + data=[f"network_patricia_data/{i}.udp"], + ) + + validator( + benchmark="benchmark://cBench-v0/qsort", + cmd=f"$BIN $D/automotive_qsort_data/{i}.dat", + data=[f"automotive_qsort_data/{i}.dat"], + outs=["sorted_output.dat"], + linkopts=["-lm"], + ) + + validator( + benchmark="benchmark://cBench-v0/rijndael", + cmd=f"$BIN $D/office_data/{i}.enc output.dec d 1234567890abcdeffedcba09876543211234567890abcdeffedcba0987654321", + data=[f"office_data/{i}.enc"], + outs=["output.dec"], + ) + + validator( + benchmark="benchmark://cBench-v0/sha", + cmd=f"$BIN $D/office_data/{i}.txt", + data=[f"office_data/{i}.txt"], + compare_output=False, + validate_result=validate_sha_output, + ) + + validator( + benchmark="benchmark://cBench-v0/stringsearch", + cmd=f"$BIN $D/office_data/{i}.txt $D/office_data/{i}.s.txt output.txt", + data=[f"office_data/{i}.txt"], + outs=["output.txt"], + linkopts=["-lm"], + ) + + validator( + benchmark="benchmark://cBench-v0/stringsearch2", + cmd=f"$BIN $D/office_data/{i}.txt $D/office_data/{i}.s.txt output.txt", + data=[f"office_data/{i}.txt"], + outs=["output.txt"], + ) + + validator( + benchmark="benchmark://cBench-v0/susan", + cmd=f"$BIN $D/automotive_susan_data/{i}.pgm output_large.corners.pgm -c", + data=[f"automotive_susan_data/{i}.pgm"], + outs=["output_large.corners.pgm"], + linkopts=["-lm"], + ) + + validator( + benchmark="benchmark://cBench-v0/tiff2bw", + cmd=f"$BIN $D/consumer_tiff_data/{i}.tif output.tif", + data=[f"consumer_tiff_data/{i}.tif"], + outs=["output.tif"], + linkopts=["-lm"], + ) + + validator( + benchmark="benchmark://cBench-v0/tiff2rgba", + cmd=f"$BIN $D/consumer_tiff_data/{i}.tif output.tif", + data=[f"consumer_tiff_data/{i}.tif"], + outs=["output.tif"], + linkopts=["-lm"], + ) + + validator( + benchmark="benchmark://cBench-v0/tiffdither", + cmd=f"$BIN $D/consumer_tiff_data/{i}.bw.tif out.tif", + data=[f"consumer_tiff_data/{i}.bw.tif"], + outs=["out.tif"], + linkopts=["-lm"], + ) + + validator( + benchmark="benchmark://cBench-v0/tiffmedian", + cmd=f"$BIN $D/consumer_tiff_data/{i}.nocomp.tif output.tif", + data=[f"consumer_tiff_data/{i}.nocomp.tif"], + outs=["output.tif"], + linkopts=["-lm"], + ) + + # TODO(cummins): On macOS the following benchmarks abort with an illegal + # hardware instruction error. + if sys.platform != "darwin": + validator( + benchmark="benchmark://cBench-v0/lame", + cmd=f"$BIN $D/consumer_data/{i}.wav output.mp3", + data=[f"consumer_data/{i}.wav"], + outs=["output.mp3"], + compare_output=False, + linkopts=["-lm"], + ) + + validator( + benchmark="benchmark://cBench-v0/ghostscript", + cmd=f"$BIN -sDEVICE=ppm -dNOPAUSE -dQUIET -sOutputFile=output.ppm -- {i}.ps", + data=[f"office_data/{i}.ps"], + outs=["output.ppm"], + linkopts=["-lm", "-lz"], + pre_execution_callback=setup_ghostscript_library_files, + ) diff --git a/compiler_gym/third_party/cBench/BUILD b/compiler_gym/third_party/cBench/BUILD index 59a3e40d7d..bb78136987 100644 --- a/compiler_gym/third_party/cBench/BUILD +++ b/compiler_gym/third_party/cBench/BUILD @@ -3,6 +3,76 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. +genrule( + name = "cBench_tar", + srcs = [":cBench"], + outs = ["llvm_bitcodes-10.0.0-cBench.tar.bz2"], + cmd = "tar cjfh $@ -C $(@D) cBench-v0", + visibility = ["//visibility:public"], +) + +filegroup( + name = "cBench", + srcs = [ + ":adpcm", + ":bitcount", + ":blowfish", + ":bzip2", + ":crc32", + ":dijkstra", + ":ghostscript", + ":gsm", + ":ispell", + ":jpeg-c", + ":jpeg-d", + ":lame", + ":patricia", + ":qsort", + ":rijndael", + ":sha", + ":stringsearch", + ":stringsearch2", + ":susan", + ":tiff2bw", + ":tiff2rgba", + ":tiffdither", + ":tiffmedian", + ], + visibility = ["//visibility:public"], +) + +genrule( + name = "make_runtime_data", + srcs = [ + "@cBench_consumer_tiff_data//file", + "@cBench_office_data//file", + "@cBench_telecom_data//file", + "@cBench_consumer_jpeg_data//file", + "@cBench_telecom_gsm_data//file", + "@cBench_consumer_data//file", + "@cBench_bzip2_data//file", + "@cBench_network_patricia_data//file", + "@cBench_network_dijkstra_data//file", + "@cBench_automotive_susan_data//file", + "@cBench_automotive_qsort_data//file", + ] + glob(["runtime_data/**/*"]), + outs = ["runtime_data"], + cmd = ( + "cp -R $$(dirname $(location runtime_data/ghostscript/gs_init.ps))/../.. $(@D) &&" + + "tar xzf $(location @cBench_consumer_tiff_data//file) -C $(@D)/runtime_data &&" + + "tar xzf $(location @cBench_office_data//file) -C $(@D)/runtime_data &&" + + "tar xzf $(location @cBench_telecom_data//file) -C $(@D)/runtime_data &&" + + "tar xzf $(location @cBench_consumer_jpeg_data//file) -C $(@D)/runtime_data &&" + + "tar xzf $(location @cBench_telecom_gsm_data//file) -C $(@D)/runtime_data &&" + + "tar xzf $(location @cBench_consumer_data//file) -C $(@D)/runtime_data &&" + + "tar xzf $(location @cBench_bzip2_data//file) -C $(@D)/runtime_data &&" + + "tar xzf $(location @cBench_network_patricia_data//file) -C $(@D)/runtime_data &&" + + "tar xzf $(location @cBench_network_dijkstra_data//file) -C $(@D)/runtime_data &&" + + "tar xzf $(location @cBench_automotive_susan_data//file) -C $(@D)/runtime_data &&" + + "tar xzf $(location @cBench_automotive_qsort_data//file) -C $(@D)/runtime_data" + ), +) + filegroup( name = "benchmarks_list", srcs = ["benchmarks.txt"], @@ -27,8 +97,276 @@ genrule( "@cBench//:all", "@cBench//:readme", ], - outs = ["cBench/crc32.bc"], + outs = ["cBench-v0/crc32.bc"], cmd = "mkdir -p $(@D) && $(location :make_llvm_module) $$(dirname $(location @cBench//:readme))/telecom_CRC32 $@", tools = [":make_llvm_module"], visibility = ["//visibility:public"], ) + +genrule( + name = "jpeg-c", + srcs = [ + "@ctuning-ai//:all", + "@ctuning-ai//:readme", + ], + outs = ["cBench-v0/jpeg-c.bc"], + cmd = "mkdir -p $(@D) && $(location :make_llvm_module) $$(dirname $(location @ctuning-ai//:readme))/program/cbench-consumer-jpeg-c $@", + tools = [ + ":make_llvm_module", + ], +) + +genrule( + name = "jpeg-d", + srcs = [ + "@ctuning-ai//:all", + "@ctuning-ai//:readme", + ], + outs = ["cBench-v0/jpeg-d.bc"], + cmd = "mkdir -p $(@D) && $(location :make_llvm_module) $$(dirname $(location @ctuning-ai//:readme))/program/cbench-consumer-jpeg-d $@", + tools = [ + ":make_llvm_module", + ], +) + +genrule( + name = "stringsearch2", + srcs = [ + "@ctuning-ai//:all", + "@ctuning-ai//:readme", + ], + outs = ["cBench-v0/stringsearch2.bc"], + cmd = "mkdir -p $(@D) && $(location :make_llvm_module) $$(dirname $(location @ctuning-ai//:readme))/program/cbench-office-stringsearch2 $@", + tools = [ + ":make_llvm_module", + ], +) + +genrule( + name = "adpcm", + srcs = [ + "@cBench//:all", + "@cBench//:readme", + ], + outs = ["cBench-v0/adpcm.bc"], + cmd = "mkdir -p $(@D) && $(location :make_llvm_module) $$(dirname $(location @cBench//:readme))/telecom_adpcm_c $@", + tools = [":make_llvm_module"], + visibility = ["//visibility:public"], +) + +genrule( + name = "bitcount", + srcs = [ + "@cBench//:all", + "@cBench//:readme", + ], + outs = ["cBench-v0/bitcount.bc"], + cmd = "mkdir -p $(@D) && $(location :make_llvm_module) $$(dirname $(location @cBench//:readme))/automotive_bitcount $@", + tools = [":make_llvm_module"], +) + +genrule( + name = "blowfish", + srcs = [ + "@cBench//:all", + "@cBench//:readme", + ], + outs = ["cBench-v0/blowfish.bc"], + cmd = "mkdir -p $(@D) && $(location :make_llvm_module) $$(dirname $(location @cBench//:readme))/security_blowfish_d $@", + tools = [":make_llvm_module"], +) + +genrule( + name = "bzip2", + srcs = [ + "@cBench//:all", + "@cBench//:readme", + ], + outs = ["cBench-v0/bzip2.bc"], + cmd = "mkdir -p $(@D) && $(location :make_llvm_module) $$(dirname $(location @cBench//:readme))/bzip2d $@", + tools = [":make_llvm_module"], +) + +genrule( + name = "dijkstra", + srcs = [ + "@cBench//:all", + "@cBench//:readme", + ], + outs = ["cBench-v0/dijkstra.bc"], + cmd = "mkdir -p $(@D) && $(location :make_llvm_module) $$(dirname $(location @cBench//:readme))/network_dijkstra $@", + tools = [":make_llvm_module"], +) + +genrule( + name = "ghostscript", + srcs = [ + "@cBench//:all", + "@cBench//:readme", + "cBench-ghostscript-std.h.patch", + "cBench-ghostscript-idebug.c.patch", + ], + outs = ["cBench-v0/ghostscript.bc"], + cmd = ( + "mkdir -p $(@D) && rsync -rL $$(dirname $(location @cBench//:readme))/office_ghostscript/ $(@D)/office_ghostscript_src/ &&" + + "patch --quiet --forward $(@D)/office_ghostscript_src/src/idebug.c < $(location cBench-ghostscript-idebug.c.patch);" + + "patch --quiet --forward $(@D)/office_ghostscript_src/src/std.h < $(location cBench-ghostscript-std.h.patch);" + + "$(location :make_llvm_module) $(@D)/office_ghostscript_src $@" + ), + tools = [":make_llvm_module"], +) + +genrule( + name = "gsm", + srcs = [ + "@cBench//:all", + "@cBench//:readme", + "cBench-gsm-add.c.patch", + ], + outs = ["cBench-v0/gsm.bc"], + cmd = ( + "mkdir -p $(@D) &&rsync -rL $$(dirname $(location @cBench//:readme))/telecom_gsm/ $(@D)/telecom_gsm_src/ &&" + + "patch --quiet --forward $(@D)/telecom_gsm_src/src/add.c < $(location cBench-gsm-add.c.patch);" + + "$(location :make_llvm_module) $(@D)/telecom_gsm_src $@ -DSASR -DSTUPID_COMPILER -DNeedFunctionPrototypes=1" + ), + tools = [":make_llvm_module"], +) + +genrule( + name = "ispell", + srcs = [ + "@cBench//:all", + "@cBench//:readme", + "cBench-ispell-correct.c.patch", + ], + outs = ["cBench-v0/ispell.bc"], + cmd = ( + "mkdir -p $(@D) &&rsync -rL $$(dirname $(location @cBench//:readme))/office_ispell/ $(@D)/office_ispell_src/ &&" + + "patch --quiet --forward $(@D)/office_ispell_src/src/correct.c < $(location cBench-ispell-correct.c.patch);" + + "$(location :make_llvm_module) $(@D)/office_ispell_src $@" + ), + tools = [":make_llvm_module"], +) + +genrule( + name = "lame", + srcs = [ + "@cBench//:all", + "@cBench//:readme", + ], + outs = ["cBench-v0/lame.bc"], + cmd = "mkdir -p $(@D) && $(location :make_llvm_module) $$(dirname $(location @cBench//:readme))/consumer_lame $@ -DLAMESNDFILE -DHAVEMPGLIB -DLAMEPARSE", + tools = [":make_llvm_module"], +) + +genrule( + name = "patricia", + srcs = [ + "@cBench//:all", + "@cBench//:readme", + ], + outs = ["cBench-v0/patricia.bc"], + cmd = ( + "mkdir -p $(@D) && $(location :make_llvm_module) $$(dirname $(location @cBench//:readme))/network_patricia/ $@" + ), + tools = [":make_llvm_module"], +) + +genrule( + name = "qsort", + srcs = [ + "@cBench//:all", + "@cBench//:readme", + ], + outs = ["cBench-v0/qsort.bc"], + cmd = "mkdir -p $(@D) && $(location :make_llvm_module) $$(dirname $(location @cBench//:readme))/automotive_qsort1 $@", + tools = [":make_llvm_module"], +) + +genrule( + name = "rijndael", + srcs = [ + "@cBench//:all", + "@cBench//:readme", + ], + outs = ["cBench-v0/rijndael.bc"], + cmd = "mkdir -p $(@D) && $(location :make_llvm_module) $$(dirname $(location @cBench//:readme))/security_rijndael_d $@", + tools = [":make_llvm_module"], +) + +genrule( + name = "sha", + srcs = [ + "@cBench//:all", + "@cBench//:readme", + ], + outs = ["cBench-v0/sha.bc"], + cmd = "mkdir -p $(@D) && $(location :make_llvm_module) $$(dirname $(location @cBench//:readme))/security_sha $@", + tools = [":make_llvm_module"], +) + +genrule( + name = "stringsearch", + srcs = [ + "@cBench//:all", + "@cBench//:readme", + ], + outs = ["cBench-v0/stringsearch.bc"], + cmd = "mkdir -p $(@D) && $(location :make_llvm_module) $$(dirname $(location @cBench//:readme))/office_stringsearch1 $@", + tools = [":make_llvm_module"], +) + +genrule( + name = "susan", + srcs = [ + "@cBench//:all", + "@cBench//:readme", + ], + outs = ["cBench-v0/susan.bc"], + cmd = "mkdir -p $(@D) && $(location :make_llvm_module) $$(dirname $(location @cBench//:readme))/automotive_susan_c $@", + tools = [":make_llvm_module"], +) + +genrule( + name = "tiff2bw", + srcs = [ + "@cBench//:all", + "@cBench//:readme", + ], + outs = ["cBench-v0/tiff2bw.bc"], + cmd = "mkdir -p $(@D) && $(location :make_llvm_module) $$(dirname $(location @cBench//:readme))/consumer_tiff2bw $@", + tools = [":make_llvm_module"], +) + +genrule( + name = "tiff2rgba", + srcs = [ + "@cBench//:all", + "@cBench//:readme", + ], + outs = ["cBench-v0/tiff2rgba.bc"], + cmd = "mkdir -p $(@D) && $(location :make_llvm_module) $$(dirname $(location @cBench//:readme))/consumer_tiff2rgba $@", + tools = [":make_llvm_module"], +) + +genrule( + name = "tiffdither", + srcs = [ + "@cBench//:all", + "@cBench//:readme", + ], + outs = ["cBench-v0/tiffdither.bc"], + cmd = "mkdir -p $(@D) && $(location :make_llvm_module) $$(dirname $(location @cBench//:readme))/consumer_tiffdither $@", + tools = [":make_llvm_module"], +) + +genrule( + name = "tiffmedian", + srcs = [ + "@cBench//:all", + "@cBench//:readme", + ], + outs = ["cBench-v0/tiffmedian.bc"], + cmd = "mkdir -p $(@D) && $(location :make_llvm_module) $$(dirname $(location @cBench//:readme))/consumer_tiffmedian $@", + tools = [":make_llvm_module"], +) diff --git a/compiler_gym/third_party/cBench/BUILD.inactive b/compiler_gym/third_party/cBench/BUILD.inactive deleted file mode 100644 index 3288c14135..0000000000 --- a/compiler_gym/third_party/cBench/BUILD.inactive +++ /dev/null @@ -1,316 +0,0 @@ -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -genrule( - name = "cBench_tar", - srcs = [":cBench"], - outs = ["cBench-llvm-10.0.0.tar.bz2"], - cmd = "tar cjfh $@ -C $(@D) cBench", - visibility = ["//visibility:public"], -) - -filegroup( - name = "cBench", - srcs = [ - ":adpcm", - ":bitcount", - ":blowfish", - ":bzip2", - ":crc32", - ":dijkstra", - ":ghostscript", - ":gsm", - ":ispell", - ":jpeg-c", - ":jpeg-d", - ":lame", - ":patricia", - ":qsort", - ":rijndael", - ":sha", - ":stringsearch", - ":stringsearch2", - ":susan", - ":tiff2bw", - ":tiff2rgba", - ":tiffdither", - ":tiffmedian", - ], - visibility = ["//visibility:public"], -) - -genrule( - name = "jpeg-c", - srcs = [ - "@ctuning-programs//:all", - "@ctuning-programs//:readme", - ], - outs = ["cBench/jpeg-c.bc"], - cmd = "mkdir -p cBench && $(location //compiler_gym/third_party/ctuning-programs:make_bitcode) $(location @llvm//10.0.0:clang) $(location @llvm//10.0.0:llvm-link) $@ $$(dirname $(location @ctuning-programs//:readme))/program/cbench-consumer-jpeg-c", - tools = [ - "//compiler_gym/third_party/ctuning-programs:make_bitcode", - "@llvm//10.0.0:clang", - "@llvm//10.0.0:llvm-link", - ], -) - -genrule( - name = "jpeg-d", - srcs = [ - "@ctuning-programs//:all", - "@ctuning-programs//:readme", - ], - outs = ["cBench/jpeg-d.bc"], - cmd = "mkdir -p cBench && $(location //compiler_gym/third_party/ctuning-programs:make_bitcode) $(location @llvm//10.0.0:clang) $(location @llvm//10.0.0:llvm-link) $@ $$(dirname $(location @ctuning-programs//:readme))/program/cbench-consumer-jpeg-d", - tools = [ - "//compiler_gym/third_party/ctuning-programs:make_bitcode", - "@llvm//10.0.0:clang", - "@llvm//10.0.0:llvm-link", - ], -) - -genrule( - name = "stringsearch2", - srcs = [ - "@ctuning-programs//:all", - "@ctuning-programs//:readme", - ], - outs = ["cBench/stringsearch2.bc"], - cmd = "mkdir -p cBench && $(location //compiler_gym/third_party/ctuning-programs:make_bitcode) $(location @llvm//10.0.0:clang) $(location @llvm//10.0.0:llvm-link) $@ $$(dirname $(location @ctuning-programs//:readme))/program/cbench-office-stringsearch2", - tools = [ - "//compiler_gym/third_party/ctuning-programs:make_bitcode", - "@llvm//10.0.0:clang", - "@llvm//10.0.0:llvm-link", - ], -) - -genrule( - name = "adpcm", - srcs = [ - "@cBench//:all", - "@cBench//:readme", - ], - outs = ["cBench/adpcm.bc"], - cmd = "mkdir -p $(@D) && $(location :make_llvm_module) $$(dirname $(location @cBench//:readme))/telecom_adpcm_c $@", - tools = [":make_llvm_module"], - visibility = ["//visibility:public"], -) - -genrule( - name = "bitcount", - srcs = [ - "@cBench//:all", - "@cBench//:readme", - ], - outs = ["cBench/bitcount.bc"], - cmd = "mkdir -p $(@D) && $(location :make_llvm_module) $$(dirname $(location @cBench//:readme))/automotive_bitcount $@", - tools = [":make_llvm_module"], -) - -genrule( - name = "blowfish", - srcs = [ - "@cBench//:all", - "@cBench//:readme", - ], - outs = ["cBench/blowfish.bc"], - cmd = "mkdir -p $(@D) && $(location :make_llvm_module) $$(dirname $(location @cBench//:readme))/security_blowfish_d $@", - tools = [":make_llvm_module"], -) - -genrule( - name = "bzip2", - srcs = [ - "@cBench//:all", - "@cBench//:readme", - ], - outs = ["cBench/bzip2.bc"], - cmd = "mkdir -p $(@D) && $(location :make_llvm_module) $$(dirname $(location @cBench//:readme))/bzip2d $@", - tools = [":make_llvm_module"], -) - -genrule( - name = "dijkstra", - srcs = [ - "@cBench//:all", - "@cBench//:readme", - ], - outs = ["cBench/dijkstra.bc"], - cmd = "mkdir -p $(@D) && $(location :make_llvm_module) $$(dirname $(location @cBench//:readme))/network_dijkstra $@", - tools = [":make_llvm_module"], -) - -genrule( - name = "ghostscript", - srcs = [ - "@cBench//:all", - "@cBench//:readme", - "cBench-ghostscript-std.h.patch", - "cBench-ghostscript-idebug.c.patch", - ], - outs = ["cBench/ghostscript.bc"], - cmd = ( - "mkdir -p $(@D) && rsync -rL $$(dirname $(location @cBench//:readme))/office_ghostscript/ $(@D)/office_ghostscript_src/ && " + - "patch --quiet --forward $(@D)/office_ghostscript_src/src/idebug.c < $(location cBench-ghostscript-idebug.c.patch);" + - "patch --quiet --forward $(@D)/office_ghostscript_src/src/std.h < $(location cBench-ghostscript-std.h.patch);" + - "$(location :make_llvm_module) $(@D)/office_ghostscript_src $@" - ), - tools = [":make_llvm_module"], -) - -genrule( - name = "gsm", - srcs = [ - "@cBench//:all", - "@cBench//:readme", - "cBench-gsm-add.c.patch", - ], - outs = ["cBench/gsm.bc"], - cmd = ( - "mkdir -p $(@D) &&rsync -rL $$(dirname $(location @cBench//:readme))/telecom_gsm/ $(@D)/telecom_gsm_src/ && " + - "patch --quiet --forward $(@D)/telecom_gsm_src/src/add.c < $(location cBench-gsm-add.c.patch);" + - "$(location :make_llvm_module) $(@D)/telecom_gsm_src $@ -DSASR -DSTUPID_COMPILER -DNeedFunctionPrototypes=1" - ), - tools = [":make_llvm_module"], -) - -genrule( - name = "ispell", - srcs = [ - "@cBench//:all", - "@cBench//:readme", - "cBench-ispell-correct.c.patch", - ], - outs = ["cBench/ispell.bc"], - cmd = ( - "mkdir -p $(@D) &&rsync -rL $$(dirname $(location @cBench//:readme))/office_ispell/ $(@D)/office_ispell_src/ && " + - "patch --quiet --forward $(@D)/office_ispell_src/src/correct.c < $(location cBench-ispell-correct.c.patch);" + - "$(location :make_llvm_module) $(@D)/office_ispell_src $@" - ), - tools = [":make_llvm_module"], -) - -genrule( - name = "lame", - srcs = [ - "@cBench//:all", - "@cBench//:readme", - ], - outs = ["cBench/lame.bc"], - cmd = "mkdir -p $(@D) && $(location :make_llvm_module) $$(dirname $(location @cBench//:readme))/consumer_lame $@ -DLAMESNDFILE -DHAVEMPGLIB -DLAMEPARSE", - tools = [":make_llvm_module"], -) - -genrule( - name = "patricia", - srcs = [ - "@cBench//:all", - "@cBench//:readme", - ], - outs = ["cBench/patricia.bc"], - cmd = ( - "mkdir -p $(@D) && $(location :make_llvm_module) $$(dirname $(location @cBench//:readme))/network_patricia/ $@" - ), - tools = [":make_llvm_module"], -) - -genrule( - name = "qsort", - srcs = [ - "@cBench//:all", - "@cBench//:readme", - ], - outs = ["cBench/qsort.bc"], - cmd = "mkdir -p $(@D) && $(location :make_llvm_module) $$(dirname $(location @cBench//:readme))/automotive_qsort1 $@", - tools = [":make_llvm_module"], -) - -genrule( - name = "rijndael", - srcs = [ - "@cBench//:all", - "@cBench//:readme", - ], - outs = ["cBench/rijndael.bc"], - cmd = "mkdir -p $(@D) && $(location :make_llvm_module) $$(dirname $(location @cBench//:readme))/security_rijndael_d $@", - tools = [":make_llvm_module"], -) - -genrule( - name = "sha", - srcs = [ - "@cBench//:all", - "@cBench//:readme", - ], - outs = ["cBench/sha.bc"], - cmd = "mkdir -p $(@D) && $(location :make_llvm_module) $$(dirname $(location @cBench//:readme))/security_sha $@", - tools = [":make_llvm_module"], -) - -genrule( - name = "stringsearch", - srcs = [ - "@cBench//:all", - "@cBench//:readme", - ], - outs = ["cBench/stringsearch.bc"], - cmd = "mkdir -p $(@D) && $(location :make_llvm_module) $$(dirname $(location @cBench//:readme))/office_stringsearch1 $@", - tools = [":make_llvm_module"], -) - -genrule( - name = "susan", - srcs = [ - "@cBench//:all", - "@cBench//:readme", - ], - outs = ["cBench/susan.bc"], - cmd = "mkdir -p $(@D) && $(location :make_llvm_module) $$(dirname $(location @cBench//:readme))/automotive_susan_c $@", - tools = [":make_llvm_module"], -) - -genrule( - name = "tiff2bw", - srcs = [ - "@cBench//:all", - "@cBench//:readme", - ], - outs = ["cBench/tiff2bw.bc"], - cmd = "mkdir -p $(@D) && $(location :make_llvm_module) $$(dirname $(location @cBench//:readme))/consumer_tiff2bw $@", - tools = [":make_llvm_module"], -) - -genrule( - name = "tiff2rgba", - srcs = [ - "@cBench//:all", - "@cBench//:readme", - ], - outs = ["cBench/tiff2rgba.bc"], - cmd = "mkdir -p $(@D) && $(location :make_llvm_module) $$(dirname $(location @cBench//:readme))/consumer_tiff2rgba $@", - tools = [":make_llvm_module"], -) - -genrule( - name = "tiffdither", - srcs = [ - "@cBench//:all", - "@cBench//:readme", - ], - outs = ["cBench/tiffdither.bc"], - cmd = "mkdir -p $(@D) && $(location :make_llvm_module) $$(dirname $(location @cBench//:readme))/consumer_tiffdither $@", - tools = [":make_llvm_module"], -) - -genrule( - name = "tiffmedian", - srcs = [ - "@cBench//:all", - "@cBench//:readme", - ], - outs = ["cBench/tiffmedian.bc"], - cmd = "mkdir -p $(@D) && $(location :make_llvm_module) $$(dirname $(location @cBench//:readme))/consumer_tiffmedian $@", - tools = [":make_llvm_module"], -) diff --git a/compiler_gym/third_party/cBench/benchmarks.txt b/compiler_gym/third_party/cBench/benchmarks.txt index 52a9b33d51..daeb171a9b 100644 --- a/compiler_gym/third_party/cBench/benchmarks.txt +++ b/compiler_gym/third_party/cBench/benchmarks.txt @@ -9,6 +9,7 @@ benchmark://cBench-v0/gsm benchmark://cBench-v0/ispell benchmark://cBench-v0/jpeg-c benchmark://cBench-v0/jpeg-d +benchmark://cBench-v0/lame benchmark://cBench-v0/patricia benchmark://cBench-v0/qsort benchmark://cBench-v0/rijndael diff --git a/compiler_gym/third_party/cBench/make_llvm_module.py b/compiler_gym/third_party/cBench/make_llvm_module.py index 940ba59b74..0ffad8b0f5 100644 --- a/compiler_gym/third_party/cBench/make_llvm_module.py +++ b/compiler_gym/third_party/cBench/make_llvm_module.py @@ -30,6 +30,8 @@ def make_cbench_llvm_module( cflags = cflags or [] src_dir = benchmark_dir / "src" + if not src_dir.is_dir(): + src_dir = benchmark_dir assert src_dir.is_dir(), f"Source directory not found: {src_dir}" clang_command = [ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/acctest.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/acctest.ps new file mode 100644 index 0000000000..2af46bef1e Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/acctest.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/align.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/align.ps new file mode 100644 index 0000000000..9aae0006a5 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/align.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/bdftops.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/bdftops.ps new file mode 100644 index 0000000000..bce697376f Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/bdftops.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/caption.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/caption.ps new file mode 100644 index 0000000000..4e94d17452 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/caption.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/decrypt.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/decrypt.ps new file mode 100644 index 0000000000..9cc8b2f179 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/decrypt.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/docie.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/docie.ps new file mode 100644 index 0000000000..ce2bd9a4db Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/docie.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/font2c.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/font2c.ps new file mode 100644 index 0000000000..e0e398ca15 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/font2c.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_btokn.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_btokn.ps new file mode 100644 index 0000000000..d8051ac728 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_btokn.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_ccfnt.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_ccfnt.ps new file mode 100644 index 0000000000..d69e9c8f07 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_ccfnt.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_cff.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_cff.ps new file mode 100644 index 0000000000..bcf0c78109 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_cff.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_cidfn.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_cidfn.ps new file mode 100644 index 0000000000..e2e2f4f808 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_cidfn.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_cmap.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_cmap.ps new file mode 100644 index 0000000000..f47fb0128b Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_cmap.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_dbt_e.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_dbt_e.ps new file mode 100644 index 0000000000..bf8af88eb6 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_dbt_e.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_diskf.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_diskf.ps new file mode 100644 index 0000000000..00619ac2a5 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_diskf.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_dpnxt.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_dpnxt.ps new file mode 100644 index 0000000000..3ed782f6f6 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_dpnxt.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_dps1.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_dps1.ps new file mode 100644 index 0000000000..70ada3acd4 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_dps1.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_dps2.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_dps2.ps new file mode 100644 index 0000000000..3ce56f8f95 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_dps2.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_epsf.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_epsf.ps new file mode 100644 index 0000000000..af25f86c82 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_epsf.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_fonts.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_fonts.ps new file mode 100644 index 0000000000..51032f4b62 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_fonts.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_init.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_init.ps new file mode 100644 index 0000000000..fcac688ff4 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_init.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_iso_e.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_iso_e.ps new file mode 100644 index 0000000000..941d60994b Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_iso_e.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_kanji.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_kanji.ps new file mode 100644 index 0000000000..9196eea192 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_kanji.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_ksb_e.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_ksb_e.ps new file mode 100644 index 0000000000..ae8ba65dd4 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_ksb_e.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_l2img.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_l2img.ps new file mode 100644 index 0000000000..053d81aa26 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_l2img.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_lev2.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_lev2.ps new file mode 100644 index 0000000000..3223061675 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_lev2.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_mex_e.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_mex_e.ps new file mode 100644 index 0000000000..11fd670647 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_mex_e.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_mro_e.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_mro_e.ps new file mode 100644 index 0000000000..8cd75b5663 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_mro_e.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_pdf.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_pdf.ps new file mode 100644 index 0000000000..1e455f80b2 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_pdf.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_pdf_e.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_pdf_e.ps new file mode 100644 index 0000000000..3e02c48a35 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_pdf_e.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_pdfwr.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_pdfwr.ps new file mode 100644 index 0000000000..85ea6af39f Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_pdfwr.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_pfile.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_pfile.ps new file mode 100644 index 0000000000..dfa9455387 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_pfile.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_res.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_res.ps new file mode 100644 index 0000000000..177c260c15 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_res.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_setpd.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_setpd.ps new file mode 100644 index 0000000000..f1ccfd7f05 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_setpd.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_statd.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_statd.ps new file mode 100644 index 0000000000..8bbb9ac5f2 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_statd.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_std_e.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_std_e.ps new file mode 100644 index 0000000000..4947a68afa Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_std_e.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_sym_e.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_sym_e.ps new file mode 100644 index 0000000000..1e924cac3e Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_sym_e.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_ttf.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_ttf.ps new file mode 100644 index 0000000000..59ad30b963 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_ttf.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_typ42.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_typ42.ps new file mode 100644 index 0000000000..6f5b3f2b38 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_typ42.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_type1.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_type1.ps new file mode 100644 index 0000000000..4afd7740bf Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_type1.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_wan_e.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_wan_e.ps new file mode 100644 index 0000000000..34f0cae63b Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gs_wan_e.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/gslp.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gslp.ps new file mode 100644 index 0000000000..cd278d229f Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/gslp.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/impath.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/impath.ps new file mode 100644 index 0000000000..5dd564dca3 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/impath.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/landscap.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/landscap.ps new file mode 100644 index 0000000000..770ecaad53 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/landscap.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/level1.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/level1.ps new file mode 100644 index 0000000000..b4c53c1a45 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/level1.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/lines.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/lines.ps new file mode 100644 index 0000000000..49e0853388 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/lines.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/markhint.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/markhint.ps new file mode 100644 index 0000000000..0ae0f22b46 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/markhint.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/markpath.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/markpath.ps new file mode 100644 index 0000000000..823bad3dbb Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/markpath.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/packfile.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/packfile.ps new file mode 100644 index 0000000000..6dfcf97491 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/packfile.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/pcharstr.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/pcharstr.ps new file mode 100644 index 0000000000..25e40e3154 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/pcharstr.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/pdf2dsc.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/pdf2dsc.ps new file mode 100644 index 0000000000..9dada7320d Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/pdf2dsc.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/pdf_2ps.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/pdf_2ps.ps new file mode 100644 index 0000000000..f64e631214 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/pdf_2ps.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/pdf_base.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/pdf_base.ps new file mode 100644 index 0000000000..593f4b0db6 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/pdf_base.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/pdf_draw.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/pdf_draw.ps new file mode 100644 index 0000000000..5cabd0ac12 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/pdf_draw.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/pdf_font.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/pdf_font.ps new file mode 100644 index 0000000000..fdaae0be74 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/pdf_font.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/pdf_main.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/pdf_main.ps new file mode 100644 index 0000000000..dc6851a642 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/pdf_main.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/pdf_sec.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/pdf_sec.ps new file mode 100644 index 0000000000..b0290a65e2 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/pdf_sec.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/pfbtogs.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/pfbtogs.ps new file mode 100644 index 0000000000..e14d57f34d Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/pfbtogs.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/ppath.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/ppath.ps new file mode 100644 index 0000000000..f9ed3716e8 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/ppath.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/prfont.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/prfont.ps new file mode 100644 index 0000000000..cbbc716e47 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/prfont.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/printafm.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/printafm.ps new file mode 100644 index 0000000000..b068481489 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/printafm.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/ps2ai.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/ps2ai.ps new file mode 100644 index 0000000000..46f1aa3816 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/ps2ai.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/ps2ascii.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/ps2ascii.ps new file mode 100644 index 0000000000..564d4f9957 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/ps2ascii.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/ps2epsi.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/ps2epsi.ps new file mode 100644 index 0000000000..d82ba168a0 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/ps2epsi.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/ps2image.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/ps2image.ps new file mode 100644 index 0000000000..1006b46336 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/ps2image.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/quit.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/quit.ps new file mode 100644 index 0000000000..ff604669be Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/quit.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/showchar.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/showchar.ps new file mode 100644 index 0000000000..19e35c0b89 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/showchar.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/showpage.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/showpage.ps new file mode 100644 index 0000000000..97a4789f75 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/showpage.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/stcinfo.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/stcinfo.ps new file mode 100644 index 0000000000..7394406326 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/stcinfo.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/stcolor.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/stcolor.ps new file mode 100644 index 0000000000..184003d43f Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/stcolor.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/traceimg.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/traceimg.ps new file mode 100644 index 0000000000..9b9039449f Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/traceimg.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/traceop.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/traceop.ps new file mode 100644 index 0000000000..ef7ab96493 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/traceop.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/type1enc.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/type1enc.ps new file mode 100644 index 0000000000..8f722ab605 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/type1enc.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/type1ops.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/type1ops.ps new file mode 100644 index 0000000000..d300f842be Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/type1ops.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/uninfo.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/uninfo.ps new file mode 100644 index 0000000000..b05f2b4e79 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/uninfo.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/unprot.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/unprot.ps new file mode 100644 index 0000000000..e2b2ad7167 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/unprot.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/viewcmyk.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/viewcmyk.ps new file mode 100644 index 0000000000..a6b6e85faa Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/viewcmyk.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/viewgif.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/viewgif.ps new file mode 100644 index 0000000000..796ac35790 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/viewgif.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/viewjpeg.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/viewjpeg.ps new file mode 100644 index 0000000000..786e304fa4 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/viewjpeg.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/viewpbm.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/viewpbm.ps new file mode 100644 index 0000000000..16b9aab4ed Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/viewpbm.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/viewpcx.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/viewpcx.ps new file mode 100644 index 0000000000..09e0e28758 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/viewpcx.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/viewps2a.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/viewps2a.ps new file mode 100644 index 0000000000..0a8289cf38 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/viewps2a.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/wftopfa.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/wftopfa.ps new file mode 100644 index 0000000000..79b2d9459f Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/wftopfa.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/winmaps.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/winmaps.ps new file mode 100644 index 0000000000..f586e54e7c Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/winmaps.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/wrfont.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/wrfont.ps new file mode 100644 index 0000000000..c52c2cb69e Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/wrfont.ps differ diff --git a/compiler_gym/third_party/cBench/runtime_data/ghostscript/zeroline.ps b/compiler_gym/third_party/cBench/runtime_data/ghostscript/zeroline.ps new file mode 100644 index 0000000000..d4c77ae352 Binary files /dev/null and b/compiler_gym/third_party/cBench/runtime_data/ghostscript/zeroline.ps differ diff --git a/compiler_gym/third_party/ctuning-ai.BUILD b/compiler_gym/third_party/ctuning-ai.BUILD new file mode 100644 index 0000000000..81a154ffb5 --- /dev/null +++ b/compiler_gym/third_party/ctuning-ai.BUILD @@ -0,0 +1,11 @@ +filegroup( + name = "all", + srcs = glob(["**"]), + visibility = ["//visibility:public"], +) + +filegroup( + name = "readme", + srcs = ["README.md"], + visibility = ["//visibility:public"], +) diff --git a/compiler_gym/util/runfiles_path.py b/compiler_gym/util/runfiles_path.py index 603c5acfa2..4444e7e0af 100644 --- a/compiler_gym/util/runfiles_path.py +++ b/compiler_gym/util/runfiles_path.py @@ -55,7 +55,7 @@ def site_data_path(relpath: str) -> Path: elif os.environ.get("HOME"): return Path("~/.local/share/compiler_gym").expanduser() / relpath else: - return Path("/tmp/CompilerGym") / relpath + return Path("/tmp/compiler_gym/site_data") / relpath def cache_path(relpath: str) -> Path: @@ -74,4 +74,4 @@ def cache_path(relpath: str) -> Path: elif os.environ.get("HOME"): return Path("~/.cache/compiler_gym").expanduser() / relpath else: - return Path("/tmp/compiler_gym") / relpath + return Path("/tmp/compiler_gym/cache") / relpath diff --git a/compiler_gym/util/temporary_working_directory.py b/compiler_gym/util/temporary_working_directory.py index 6146e34471..50478dd72d 100644 --- a/compiler_gym/util/temporary_working_directory.py +++ b/compiler_gym/util/temporary_working_directory.py @@ -14,7 +14,21 @@ def temporary_working_directory(directory: Optional[Union[str, Path]] = None) -> Path: """Temporarily set the working directory. - :param directory: The directory to set as the temporary working directory. + This function provides a way to set the working directory within the + scope of a "with statement". Example usage: + + .. code-block:: python + + print(os.getcwd()) # /tmp/foo + with temporary_working_directory("/tmp/bar"): + # Now in scope of new working directory. + print(os.getcwd()) # /tmp/bar + # Return to original working directory. + print(os.getcwd()) # /tmp/foo + + :param directory: A directory to set as the temporary working directory. If + not provided, a temporary directory is created and deleted once out of + scope. :return: The temporary working directory. """ old_working_directory = os.getcwd() @@ -24,6 +38,7 @@ def temporary_working_directory(directory: Optional[Union[str, Path]] = None) -> yield Path(directory) else: with tempfile.TemporaryDirectory(prefix="compiler_gym-") as d: + os.chdir(d) yield Path(d) finally: os.chdir(old_working_directory) diff --git a/compiler_gym/validate.py b/compiler_gym/validate.py index 4b51b8792a..15134d3400 100644 --- a/compiler_gym/validate.py +++ b/compiler_gym/validate.py @@ -12,7 +12,7 @@ from compiler_gym.envs.compiler_env import CompilerEnv, CompilerEnvState from compiler_gym.envs.llvm import LlvmEnv -from compiler_gym.envs.llvm.datasets import LLVM_BENCHMARK_VALIDATION_CALLBACKS +from compiler_gym.envs.llvm.datasets import get_llvm_benchmark_validation_callback from compiler_gym.spaces import Commandline from compiler_gym.util.timer import Timer @@ -129,9 +129,7 @@ def validate_state(env: CompilerEnv, state: CompilerEnvState) -> ValidationResul f"Expected reward {state.reward:.4f} but received reward {reward:.4f}" ) - validate_semantics = LLVM_BENCHMARK_VALIDATION_CALLBACKS.get( - state.benchmark - ) + validate_semantics = get_llvm_benchmark_validation_callback(env) if validate_semantics: validation["benchmark_semantics_validated"] = True semantics_error = validate_semantics(env) diff --git a/setup.py b/setup.py index 5f2ff147df..06a58aa443 100644 --- a/setup.py +++ b/setup.py @@ -73,7 +73,8 @@ def get_tag(self): "envs/llvm/service/libLLVMPolly.so", "third_party/inst2vec/*.pickle", "third_party/cBench/benchmarks.txt", - "third_party/cBench/cBench/crc32.bc", # Needed for install-tests. + "third_party/cBench/cBench-v0/*", + "third_party/cBench/runtime_data/**/*", "third_party/llvm/*", ] }, diff --git a/tests/BUILD b/tests/BUILD index 5e94bd9ad8..1545c2dba6 100644 --- a/tests/BUILD +++ b/tests/BUILD @@ -53,7 +53,6 @@ cc_library( py_test( name = "validate_test", - timeout = "short", srcs = ["validate_test.py"], deps = [ ":test_main", diff --git a/tests/envs/llvm/BUILD b/tests/envs/llvm/BUILD index 1cbaf04a2a..e0fe3b2453 100644 --- a/tests/envs/llvm/BUILD +++ b/tests/envs/llvm/BUILD @@ -38,6 +38,20 @@ py_test( ], ) +py_test( + name = "benchmark_semantics_validation_test", + timeout = "long", + srcs = ["benchmark_semantics_validation_test.py"], + shard_count = 4, + deps = [ + ":fixtures", + "//compiler_gym", + "//compiler_gym/datasets", + "//compiler_gym/envs", + "//tests:test_main", + ], +) + py_test( name = "benchmarks_random_actions_test", srcs = ["benchmarks_random_actions_test.py"], diff --git a/tests/envs/llvm/benchmark_semantics_validation_test.py b/tests/envs/llvm/benchmark_semantics_validation_test.py new file mode 100644 index 0000000000..075e325296 --- /dev/null +++ b/tests/envs/llvm/benchmark_semantics_validation_test.py @@ -0,0 +1,70 @@ +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. +"""Integrations tests for the LLVM CompilerGym environments.""" +import re +import sys +import tempfile +from pathlib import Path +from typing import Set + +import pytest + +from compiler_gym.envs import LlvmEnv +from compiler_gym.envs.llvm import datasets +from compiler_gym.envs.llvm.datasets import get_llvm_benchmark_validation_callback +from tests.test_main import main + +pytest_plugins = ["tests.envs.llvm.fixtures"] + +# The set of cBench benchmarks which do not have support for semantics +# validation. +CBENCH_VALIDATION_EXCLUDE_LIST: Set[str] = { + "benchmark://cBench-v0/ispell", +} +if sys.platform == "darwin": + CBENCH_VALIDATION_EXCLUDE_LIST.add("benchmark://cBench-v0/lame") + CBENCH_VALIDATION_EXCLUDE_LIST.add("benchmark://cBench-v0/ghostscript") + + +def test_no_validation_callback_for_custom_benchmark(env: LlvmEnv): + """Test that a custom benchmark has no validation callback.""" + with tempfile.TemporaryDirectory() as d: + p = Path(d) / "example.c" + with open(p, "w") as f: + print("int main() {return 0;}", file=f) + benchmark = env.make_benchmark(p) + + env.benchmark = benchmark + env.reset() + + validation_cb = get_llvm_benchmark_validation_callback(env) + + assert validation_cb is None + + +def test_expand_command_vars(): + assert datasets.expand_command_vars("abc") == "abc" + assert datasets.expand_command_vars("$BIN") == "./a.out" + assert re.match( + r"./a.out .+/runtime_data/foo", + datasets.expand_command_vars("$BIN $D/foo"), + ) + assert datasets.expand_command_vars("$UNKNOWN $BIN") == "$UNKNOWN ./a.out" + + +def test_validate_cBench_unoptimized(env: LlvmEnv, benchmark_name: str): + """Run the validation routine on unoptimized version of all cBench benchmarks.""" + env.reset(benchmark=benchmark_name) + cb = datasets.get_llvm_benchmark_validation_callback(env) + + if benchmark_name in CBENCH_VALIDATION_EXCLUDE_LIST: + assert cb is None + else: + assert cb + assert cb(env) is None + + +if __name__ == "__main__": + main() diff --git a/tests/envs/llvm/custom_benchmarks_test.py b/tests/envs/llvm/custom_benchmarks_test.py index c162dedc66..29d5492c60 100644 --- a/tests/envs/llvm/custom_benchmarks_test.py +++ b/tests/envs/llvm/custom_benchmarks_test.py @@ -18,7 +18,7 @@ pytest_plugins = ["tests.envs.llvm.fixtures"] EXAMPLE_BITCODE_FILE = runfiles_path( - "CompilerGym/compiler_gym/third_party/cBench/cBench/crc32.bc" + "CompilerGym/compiler_gym/third_party/cBench/cBench-v0/crc32.bc" ) EXAMPLE_BITCODE_IR_INSTRUCTION_COUNT = 196 diff --git a/tests/envs/llvm/observation_spaces_test.py b/tests/envs/llvm/observation_spaces_test.py index 3e66cf148e..0d9cb1dbc9 100644 --- a/tests/envs/llvm/observation_spaces_test.py +++ b/tests/envs/llvm/observation_spaces_test.py @@ -242,6 +242,8 @@ def cbench_crc32_inst2vec_embedding_indices() -> List[int]: # The linux/macOS builds of clang produce slightly different bitcodes. if sys.platform.lower().startswith("linux"): return [ + 8564, + 8564, 8564, 8564, 5, @@ -284,7 +286,7 @@ def cbench_crc32_inst2vec_embedding_indices() -> List[int]: 213, 8564, 8564, - 5666, + 8564, 204, 8564, 213, @@ -294,7 +296,7 @@ def cbench_crc32_inst2vec_embedding_indices() -> List[int]: 8564, 216, 8564, - 5665, + 8564, 8564, 311, 634, @@ -318,7 +320,7 @@ def cbench_crc32_inst2vec_embedding_indices() -> List[int]: 214, 216, 8564, - 5665, + 8564, 8564, 634, 204, @@ -329,7 +331,7 @@ def cbench_crc32_inst2vec_embedding_indices() -> List[int]: 205, 216, 8564, - 5665, + 8564, 8564, 182, 961, @@ -436,17 +438,17 @@ def cbench_crc32_inst2vec_embedding_indices() -> List[int]: 8564, 8564, 8564, - 5666, + 8564, 204, 8564, - 5391, + 8564, 8564, 364, 216, 8564, - 5665, 8564, - 5665, + 8564, + 8564, 8564, 205, 216, diff --git a/tests/util/BUILD b/tests/util/BUILD index ee1d97b7d1..7dbcc17dfc 100644 --- a/tests/util/BUILD +++ b/tests/util/BUILD @@ -32,6 +32,16 @@ cc_test( ], ) +py_test( + name = "temporary_working_directory_test", + timeout = "short", + srcs = ["temporary_working_directory_test.py"], + deps = [ + "//compiler_gym/util", + "//tests:test_main", + ], +) + py_test( name = "timer_test", srcs = ["timer_test.py"], diff --git a/tests/util/temporary_working_directory_test.py b/tests/util/temporary_working_directory_test.py new file mode 100644 index 0000000000..acf0cf25ba --- /dev/null +++ b/tests/util/temporary_working_directory_test.py @@ -0,0 +1,46 @@ +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. +"""Unit tests for //compiler_gym/util:temporary_working_directory.""" +import os +import tempfile +from pathlib import Path + +from compiler_gym.util.temporary_working_directory import temporary_working_directory +from tests.test_main import main + + +def test_temporary_working_directory_tempdir(): + with temporary_working_directory() as cwdir: + # Suffix test rather than equality test because on macOS temporary + # directories can have a /private prefix. + assert os.getcwd().endswith(str(cwdir)) + assert cwdir.is_dir() + assert not list(cwdir.iterdir()) + (cwdir / "test").touch() + assert (cwdir / "test").is_file() + + # Out of scope, the directory is removed. + assert not cwdir.is_dir() + + +def test_temporary_working_directory(): + with tempfile.TemporaryDirectory() as d: + path = Path(d) + with temporary_working_directory(path) as cwdir: + assert path == cwdir + # Suffix test rather than equality test because on macOS temporary + # directories can have a /private prefix. + assert os.getcwd().endswith(str(path)) + assert cwdir.is_dir() + assert not list(cwdir.iterdir()) + (cwdir / "test").touch() + assert (cwdir / "test").is_file() + + # Out of scope, the directory is preserved. + assert path.is_dir() + + +if __name__ == "__main__": + main() diff --git a/tests/validate_test.py b/tests/validate_test.py index 33b1cbe6ad..1599010590 100644 --- a/tests/validate_test.py +++ b/tests/validate_test.py @@ -18,6 +18,7 @@ def test_validate_state_no_reward(): ) env = gym.make("llvm-v0") try: + env.require_dataset("cBench-v0") result = validate_state(env, state) finally: env.close() @@ -37,6 +38,7 @@ def test_validate_state_with_reward(): ) env = gym.make("llvm-v0", reward_space="IrInstructionCount") try: + env.require_dataset("cBench-v0") result = validate_state(env, state) finally: env.close() @@ -57,6 +59,7 @@ def test_validate_state_invalid_reward(): ) env = gym.make("llvm-v0", reward_space="IrInstructionCount") try: + env.require_dataset("cBench-v0") result = validate_state(env, state) finally: env.close()