We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[High priority] Building from source + all CI jobs failing, csmith archive checksum invalid
## 🐛 Bug

*ALL* CI tests are currently in the red. The problem is that the csmith checksum has changed from ba871c1e5a05a71ecd1af514fedba30561b16ee80b8dd5ba8f884eaded47009f to 86d08c19a1f123054ed9350b7962edaad7d46612de0e07c10b73e578911156fd. This is blocking all CI tests and building from source!!

```
WARNING: Download from https://github.com/csmith-project/csmith/archive/refs/tags/csmith-2.3.0.tar.gz failed: class com.google.devtools.build.lib.bazel.repository.downloader.UnrecoverableHttpException Checksum was 86d08c19a1f[123](https://github.com/facebookresearch/CompilerGym/runs/5354537310?check_suite_focus=true#step:5:123)054ed9350b7962edaad7d46612de0e07c10b73e578911156fd but wanted ba871c1e5a05a71ecd1af514fedba30561b16ee80b8dd5ba8f884eaded47009f
ERROR: An error occurred during the fetch of repository 'csmith':
   Traceback (most recent call last):
	File "/home/runner/.cache/bazel/_bazel_runner/db3e34f1e14ee53d927a48b4c425fcaa/external/bazel_tools/tools/build_defs/repo/http.bzl", line 111, column 45, in _http_archive_impl
		download_info = ctx.download_and_extract(
Error in download_and_extract: java.io.IOException: Error downloading [https://github.com/csmith-project/csmith/archive/refs/tags/csmith-2.3.0.tar.gz] to /home/runner/.cache/bazel/_bazel_runner/db3e34f1e14ee53d927a48b4c425fcaa/external/csmith/temp5123569277232776356/csmith-2.3.0.tar.gz: Checksum was 86d08c19a1f123054ed9350b7962edaad7d46612de0e07c10b73e578911156fd but wanted ba871c1e5a05a71ecd1af514fedba30561b16ee80b8dd5ba8f884eaded47009f
ERROR: Error fetching repository: Traceback (most recent call last):
	File "/home/runner/.cache/bazel/_bazel_runner/db3e34f1e14ee53d927a48b4c425fcaa/external/bazel_tools/tools/build_defs/repo/http.bzl", line 111, column 45, in _http_archive_impl
		download_info = ctx.download_and_extract(
Error in download_and_extract: java.io.IOException: Error downloading [https://github.com/csmith-project/csmith/archive/refs/tags/csmith-2.3.0.tar.gz] to /home/runner/.cache/bazel/_bazel_runner/db3e34f1e14ee53d927a48b4c425fcaa/external/csmith/temp5123569277232776356/csmith-2.3.0.tar.gz: Checksum was 86d08c19a1f123054ed9350b7962edaad7d46612de0e07c10b73e578911156fd but wanted ba871c1e5a05a71ecd1af514fedba30561b16ee80b8dd5ba8f884eaded47009f
ERROR: /home/runner/work/CompilerGym/CompilerGym/compiler_gym/third_party/csmith/BUILD:16:15: //compiler_gym/third_party/csmith:csmith depends on @csmith//:all in repository @csmith which failed to fetch. no such package '@csmith//': java.io.IOException: Error downloading [https://github.com/csmith-project/csmith/archive/refs/tags/csmith-2.3.0.tar.gz] to /home/runner/.cache/bazel/_bazel_runner/db3e34f1e14ee53d927a48b4c425fcaa/external/csmith/temp5123569277232776356/csmith-2.3.0.tar.gz: Checksum was 86d08c19a1f123054ed9350b7962edaad7d46612de0e07c10b73e578911156fd but wanted ba871c1e5a05a71ecd1af514fedba30561b16ee80b8dd5ba8f884eaded47009f
```

![](https://c.tenor.com/eEs1jRy5UXgAAAAC/house-explosion.gif)

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `examples/example_compiler_gym_service/__init__.py`
Content:
```
1 # Copyright (c) Facebook, Inc. and its affiliates.
2 #
3 # This source code is licensed under the MIT license found in the
4 # LICENSE file in the root directory of this source tree.
5 """This module defines and registers the example gym environments."""
6 from pathlib import Path
7 from typing import Iterable
8 
9 from compiler_gym.datasets import Benchmark, Dataset
10 from compiler_gym.datasets.uri import BenchmarkUri
11 from compiler_gym.spaces import Reward
12 from compiler_gym.util.registration import register
13 from compiler_gym.util.runfiles_path import runfiles_path
14 
15 EXAMPLE_CC_SERVICE_BINARY: Path = runfiles_path(
16     "examples/example_compiler_gym_service/service_cc/compiler_gym-example-service-cc"
17 )
18 
19 EXAMPLE_PY_SERVICE_BINARY: Path = runfiles_path(
20     "examples/example_compiler_gym_service/service_py/compiler_gym-example-service-py"
21 )
22 
23 
24 class RuntimeReward(Reward):
25     """An example reward that uses changes in the "runtime" observation value
26     to compute incremental reward.
27     """
28 
29     def __init__(self):
30         super().__init__(
31             name="runtime",
32             observation_spaces=["runtime"],
33             default_value=0,
34             default_negates_returns=True,
35             deterministic=False,
36             platform_dependent=True,
37         )
38         self.previous_runtime = None
39 
40     def reset(self, benchmark: str, observation_view):
41         del benchmark  # unused
42         self.previous_runtime = None
43 
44     def update(self, action, observations, observation_view):
45         del action
46         del observation_view
47 
48         if self.previous_runtime is None:
49             self.previous_runtime = observations[0]
50 
51         reward = float(self.previous_runtime - observations[0])
52         self.previous_runtime = observations[0]
53         return reward
54 
55 
56 class ExampleDataset(Dataset):
57     def __init__(self, *args, **kwargs):
58         super().__init__(
59             name="benchmark://example-v0",
60             license="MIT",
61             description="An example dataset",
62         )
63         self._benchmarks = {
64             "/foo": Benchmark.from_file_contents(
65                 "benchmark://example-v0/foo", "Ir data".encode("utf-8")
66             ),
67             "/bar": Benchmark.from_file_contents(
68                 "benchmark://example-v0/bar", "Ir data".encode("utf-8")
69             ),
70         }
71 
72     def benchmark_uris(self) -> Iterable[str]:
73         yield from (f"benchmark://example-v0{k}" for k in self._benchmarks.keys())
74 
75     def benchmark_from_parsed_uri(self, uri: BenchmarkUri) -> Benchmark:
76         if uri.path in self._benchmarks:
77             return self._benchmarks[uri]
78         else:
79             raise LookupError("Unknown program name")
80 
81 
82 # Register the example service on module import. After importing this module,
83 # the example-v0 environment will be available to gym.make(...).
84 register(
85     id="example-cc-v0",
86     entry_point="compiler_gym.envs:CompilerEnv",
87     kwargs={
88         "service": EXAMPLE_CC_SERVICE_BINARY,
89         "rewards": [RuntimeReward()],
90         "datasets": [ExampleDataset()],
91     },
92 )
93 
94 register(
95     id="example-py-v0",
96     entry_point="compiler_gym.envs:CompilerEnv",
97     kwargs={
98         "service": EXAMPLE_PY_SERVICE_BINARY,
99         "rewards": [RuntimeReward()],
100         "datasets": [ExampleDataset()],
101     },
102 )
103
```

Path: `examples/loop_optimizations_service/__init__.py`
Content:
```
1 # Copyright (c) Facebook, Inc. and its affiliates.
2 #
3 # This source code is licensed under the MIT license found in the
4 # LICENSE file in the root directory of this source tree.
5 """This module registers the Loop Optimizations CompilerGym environment """
6 import subprocess
7 from pathlib import Path
8 from typing import Iterable
9 
10 from compiler_gym.datasets import Benchmark, Dataset
11 from compiler_gym.envs.llvm.llvm_benchmark import get_system_library_flags
12 from compiler_gym.spaces import Reward
13 from compiler_gym.third_party import llvm
14 from compiler_gym.util.registration import register
15 from compiler_gym.util.runfiles_path import runfiles_path
16 
17 LOOPS_OPT_PY_SERVICE_BINARY: Path = runfiles_path(
18     "examples/loop_optimizations_service/service_py/loops-opt-service-py"
19 )
20 
21 BENCHMARKS_PATH: Path = runfiles_path("examples/loop_optimizations_service/benchmarks")
22 
23 NEURO_VECTORIZER_HEADER: Path = runfiles_path(
24     "compiler_gym/third_party/neuro-vectorizer/header.h"
25 )
26 
27 
28 class RuntimeReward(Reward):
29     """An example reward that uses changes in the "runtime" observation value
30     to compute incremental reward.
31     """
32 
33     def __init__(self):
34         super().__init__(
35             name="runtime",
36             observation_spaces=["runtime"],
37             default_value=0,
38             default_negates_returns=True,
39             deterministic=False,
40             platform_dependent=True,
41         )
42         self.baseline_runtime = 0
43 
44     def reset(self, benchmark: str, observation_view):
45         del benchmark  # unused
46         self.baseline_runtime = observation_view["runtime"]
47 
48     def update(self, action, observations, observation_view):
49         del action  # unused
50         del observation_view  # unused
51         return float(self.baseline_runtime - observations[0]) / self.baseline_runtime
52 
53 
54 class SizeReward(Reward):
55     """An example reward that uses changes in the "size" observation value
56     to compute incremental reward.
57     """
58 
59     def __init__(self):
60         super().__init__(
61             name="size",
62             observation_spaces=["size"],
63             default_value=0,
64             default_negates_returns=True,
65             deterministic=False,
66             platform_dependent=True,
67         )
68         self.baseline_size = 0
69 
70     def reset(self, benchmark: str, observation_view):
71         del benchmark  # unused
72         self.baseline_runtime = observation_view["size"]
73 
74     def update(self, action, observations, observation_view):
75         del action  # unused
76         del observation_view  # unused
77         return float(self.baseline_size - observations[0]) / self.baseline_size
78 
79 
80 class LoopsDataset(Dataset):
81     def __init__(self, *args, **kwargs):
82         super().__init__(
83             name="benchmark://loops-opt-v0",
84             license="MIT",
85             description="Loops optimization dataset",
86         )
87 
88         self._benchmarks = {
89             "benchmark://loops-opt-v0/add": Benchmark.from_file_contents(
90                 "benchmark://loops-opt-v0/add",
91                 self.preprocess(BENCHMARKS_PATH / "add.c"),
92             ),
93             "benchmark://loops-opt-v0/offsets1": Benchmark.from_file_contents(
94                 "benchmark://loops-opt-v0/offsets1",
95                 self.preprocess(BENCHMARKS_PATH / "offsets1.c"),
96             ),
97             "benchmark://loops-opt-v0/conv2d": Benchmark.from_file_contents(
98                 "benchmark://loops-opt-v0/conv2d",
99                 self.preprocess(BENCHMARKS_PATH / "conv2d.c"),
100             ),
101         }
102 
103     @staticmethod
104     def preprocess(src: Path) -> bytes:
105         """Front a C source through the compiler frontend."""
106         # TODO(github.com/facebookresearch/CompilerGym/issues/325): We can skip
107         # this pre-processing, or do it on the service side, once support for
108         # multi-file benchmarks lands.
109         cmd = [
110             str(llvm.clang_path()),
111             "-E",
112             "-o",
113             "-",
114             "-I",
115             str(NEURO_VECTORIZER_HEADER.parent),
116             src,
117         ]
118         cmd += get_system_library_flags()
119         return subprocess.check_output(
120             cmd,
121             timeout=300,
122         )
123 
124     def benchmark_uris(self) -> Iterable[str]:
125         yield from self._benchmarks.keys()
126 
127     def benchmark(self, uri: str) -> Benchmark:
128         if uri in self._benchmarks:
129             return self._benchmarks[uri]
130         else:
131             raise LookupError("Unknown program name")
132 
133 
134 # Register the unrolling example service on module import. After importing this module,
135 # the loops-opt-py-v0 environment will be available to gym.make(...).
136 
137 register(
138     id="loops-opt-py-v0",
139     entry_point="compiler_gym.envs:CompilerEnv",
140     kwargs={
141         "service": LOOPS_OPT_PY_SERVICE_BINARY,
142         "rewards": [RuntimeReward(), SizeReward()],
143         "datasets": [LoopsDataset()],
144     },
145 )
146
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/examples/example_compiler_gym_service/__init__.py b/examples/example_compiler_gym_service/__init__.py
--- a/examples/example_compiler_gym_service/__init__.py
+++ b/examples/example_compiler_gym_service/__init__.py
@@ -74,7 +74,7 @@
 
     def benchmark_from_parsed_uri(self, uri: BenchmarkUri) -> Benchmark:
         if uri.path in self._benchmarks:
-            return self._benchmarks[uri]
+            return self._benchmarks[uri.path]
         else:
             raise LookupError("Unknown program name")
 
diff --git a/examples/loop_optimizations_service/__init__.py b/examples/loop_optimizations_service/__init__.py
--- a/examples/loop_optimizations_service/__init__.py
+++ b/examples/loop_optimizations_service/__init__.py
@@ -8,6 +8,7 @@
 from typing import Iterable
 
 from compiler_gym.datasets import Benchmark, Dataset
+from compiler_gym.datasets.uri import BenchmarkUri
 from compiler_gym.envs.llvm.llvm_benchmark import get_system_library_flags
 from compiler_gym.spaces import Reward
 from compiler_gym.third_party import llvm
@@ -86,15 +87,15 @@
         )
 
         self._benchmarks = {
-            "benchmark://loops-opt-v0/add": Benchmark.from_file_contents(
+            "/add": Benchmark.from_file_contents(
                 "benchmark://loops-opt-v0/add",
                 self.preprocess(BENCHMARKS_PATH / "add.c"),
             ),
-            "benchmark://loops-opt-v0/offsets1": Benchmark.from_file_contents(
+            "/offsets1": Benchmark.from_file_contents(
                 "benchmark://loops-opt-v0/offsets1",
                 self.preprocess(BENCHMARKS_PATH / "offsets1.c"),
             ),
-            "benchmark://loops-opt-v0/conv2d": Benchmark.from_file_contents(
+            "/conv2d": Benchmark.from_file_contents(
                 "benchmark://loops-opt-v0/conv2d",
                 self.preprocess(BENCHMARKS_PATH / "conv2d.c"),
             ),
@@ -122,11 +123,11 @@
         )
 
     def benchmark_uris(self) -> Iterable[str]:
-        yield from self._benchmarks.keys()
+        yield from (f"benchmark://loops-opt-v0{k}" for k in self._benchmarks.keys())
 
-    def benchmark(self, uri: str) -> Benchmark:
-        if uri in self._benchmarks:
-            return self._benchmarks[uri]
+    def benchmark_from_parsed_uri(self, uri: BenchmarkUri) -> Benchmark:
+        if uri.path in self._benchmarks:
+            return self._benchmarks[uri.path]
         else:
             raise LookupError("Unknown program name")

{"golden_diff": "diff --git a/examples/example_compiler_gym_service/__init__.py b/examples/example_compiler_gym_service/__init__.py\n--- a/examples/example_compiler_gym_service/__init__.py\n+++ b/examples/example_compiler_gym_service/__init__.py\n@@ -74,7 +74,7 @@\n \n     def benchmark_from_parsed_uri(self, uri: BenchmarkUri) -> Benchmark:\n         if uri.path in self._benchmarks:\n-            return self._benchmarks[uri]\n+            return self._benchmarks[uri.path]\n         else:\n             raise LookupError(\"Unknown program name\")\n \ndiff --git a/examples/loop_optimizations_service/__init__.py b/examples/loop_optimizations_service/__init__.py\n--- a/examples/loop_optimizations_service/__init__.py\n+++ b/examples/loop_optimizations_service/__init__.py\n@@ -8,6 +8,7 @@\n from typing import Iterable\n \n from compiler_gym.datasets import Benchmark, Dataset\n+from compiler_gym.datasets.uri import BenchmarkUri\n from compiler_gym.envs.llvm.llvm_benchmark import get_system_library_flags\n from compiler_gym.spaces import Reward\n from compiler_gym.third_party import llvm\n@@ -86,15 +87,15 @@\n         )\n \n         self._benchmarks = {\n-            \"benchmark://loops-opt-v0/add\": Benchmark.from_file_contents(\n+            \"/add\": Benchmark.from_file_contents(\n                 \"benchmark://loops-opt-v0/add\",\n                 self.preprocess(BENCHMARKS_PATH / \"add.c\"),\n             ),\n-            \"benchmark://loops-opt-v0/offsets1\": Benchmark.from_file_contents(\n+            \"/offsets1\": Benchmark.from_file_contents(\n                 \"benchmark://loops-opt-v0/offsets1\",\n                 self.preprocess(BENCHMARKS_PATH / \"offsets1.c\"),\n             ),\n-            \"benchmark://loops-opt-v0/conv2d\": Benchmark.from_file_contents(\n+            \"/conv2d\": Benchmark.from_file_contents(\n                 \"benchmark://loops-opt-v0/conv2d\",\n                 self.preprocess(BENCHMARKS_PATH / \"conv2d.c\"),\n             ),\n@@ -122,11 +123,11 @@\n         )\n \n     def benchmark_uris(self) -> Iterable[str]:\n-        yield from self._benchmarks.keys()\n+        yield from (f\"benchmark://loops-opt-v0{k}\" for k in self._benchmarks.keys())\n \n-    def benchmark(self, uri: str) -> Benchmark:\n-        if uri in self._benchmarks:\n-            return self._benchmarks[uri]\n+    def benchmark_from_parsed_uri(self, uri: BenchmarkUri) -> Benchmark:\n+        if uri.path in self._benchmarks:\n+            return self._benchmarks[uri.path]\n         else:\n             raise LookupError(\"Unknown program name\")\n", "issue": "[High priority] Building from source + all CI jobs failing, csmith archive checksum invalid\n## \ud83d\udc1b Bug\r\n\r\n*ALL* CI tests are currently in the red. The problem is that the csmith checksum has changed from ba871c1e5a05a71ecd1af514fedba30561b16ee80b8dd5ba8f884eaded47009f to 86d08c19a1f123054ed9350b7962edaad7d46612de0e07c10b73e578911156fd. This is blocking all CI tests and building from source!!\r\n\r\n```\r\nWARNING: Download from https://github.com/csmith-project/csmith/archive/refs/tags/csmith-2.3.0.tar.gz failed: class com.google.devtools.build.lib.bazel.repository.downloader.UnrecoverableHttpException Checksum was 86d08c19a1f[123](https://github.com/facebookresearch/CompilerGym/runs/5354537310?check_suite_focus=true#step:5:123)054ed9350b7962edaad7d46612de0e07c10b73e578911156fd but wanted ba871c1e5a05a71ecd1af514fedba30561b16ee80b8dd5ba8f884eaded47009f\r\nERROR: An error occurred during the fetch of repository 'csmith':\r\n   Traceback (most recent call last):\r\n\tFile \"/home/runner/.cache/bazel/_bazel_runner/db3e34f1e14ee53d927a48b4c425fcaa/external/bazel_tools/tools/build_defs/repo/http.bzl\", line 111, column 45, in _http_archive_impl\r\n\t\tdownload_info = ctx.download_and_extract(\r\nError in download_and_extract: java.io.IOException: Error downloading [https://github.com/csmith-project/csmith/archive/refs/tags/csmith-2.3.0.tar.gz] to /home/runner/.cache/bazel/_bazel_runner/db3e34f1e14ee53d927a48b4c425fcaa/external/csmith/temp5123569277232776356/csmith-2.3.0.tar.gz: Checksum was 86d08c19a1f123054ed9350b7962edaad7d46612de0e07c10b73e578911156fd but wanted ba871c1e5a05a71ecd1af514fedba30561b16ee80b8dd5ba8f884eaded47009f\r\nERROR: Error fetching repository: Traceback (most recent call last):\r\n\tFile \"/home/runner/.cache/bazel/_bazel_runner/db3e34f1e14ee53d927a48b4c425fcaa/external/bazel_tools/tools/build_defs/repo/http.bzl\", line 111, column 45, in _http_archive_impl\r\n\t\tdownload_info = ctx.download_and_extract(\r\nError in download_and_extract: java.io.IOException: Error downloading [https://github.com/csmith-project/csmith/archive/refs/tags/csmith-2.3.0.tar.gz] to /home/runner/.cache/bazel/_bazel_runner/db3e34f1e14ee53d927a48b4c425fcaa/external/csmith/temp5123569277232776356/csmith-2.3.0.tar.gz: Checksum was 86d08c19a1f123054ed9350b7962edaad7d46612de0e07c10b73e578911156fd but wanted ba871c1e5a05a71ecd1af514fedba30561b16ee80b8dd5ba8f884eaded47009f\r\nERROR: /home/runner/work/CompilerGym/CompilerGym/compiler_gym/third_party/csmith/BUILD:16:15: //compiler_gym/third_party/csmith:csmith depends on @csmith//:all in repository @csmith which failed to fetch. no such package '@csmith//': java.io.IOException: Error downloading [https://github.com/csmith-project/csmith/archive/refs/tags/csmith-2.3.0.tar.gz] to /home/runner/.cache/bazel/_bazel_runner/db3e34f1e14ee53d927a48b4c425fcaa/external/csmith/temp5123569277232776356/csmith-2.3.0.tar.gz: Checksum was 86d08c19a1f123054ed9350b7962edaad7d46612de0e07c10b73e578911156fd but wanted ba871c1e5a05a71ecd1af514fedba30561b16ee80b8dd5ba8f884eaded47009f\r\n```\r\n\r\n![](https://c.tenor.com/eEs1jRy5UXgAAAAC/house-explosion.gif)\n", "before_files": [{"content": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\"\"\"This module defines and registers the example gym environments.\"\"\"\nfrom pathlib import Path\nfrom typing import Iterable\n\nfrom compiler_gym.datasets import Benchmark, Dataset\nfrom compiler_gym.datasets.uri import BenchmarkUri\nfrom compiler_gym.spaces import Reward\nfrom compiler_gym.util.registration import register\nfrom compiler_gym.util.runfiles_path import runfiles_path\n\nEXAMPLE_CC_SERVICE_BINARY: Path = runfiles_path(\n    \"examples/example_compiler_gym_service/service_cc/compiler_gym-example-service-cc\"\n)\n\nEXAMPLE_PY_SERVICE_BINARY: Path = runfiles_path(\n    \"examples/example_compiler_gym_service/service_py/compiler_gym-example-service-py\"\n)\n\n\nclass RuntimeReward(Reward):\n    \"\"\"An example reward that uses changes in the \"runtime\" observation value\n    to compute incremental reward.\n    \"\"\"\n\n    def __init__(self):\n        super().__init__(\n            name=\"runtime\",\n            observation_spaces=[\"runtime\"],\n            default_value=0,\n            default_negates_returns=True,\n            deterministic=False,\n            platform_dependent=True,\n        )\n        self.previous_runtime = None\n\n    def reset(self, benchmark: str, observation_view):\n        del benchmark  # unused\n        self.previous_runtime = None\n\n    def update(self, action, observations, observation_view):\n        del action\n        del observation_view\n\n        if self.previous_runtime is None:\n            self.previous_runtime = observations[0]\n\n        reward = float(self.previous_runtime - observations[0])\n        self.previous_runtime = observations[0]\n        return reward\n\n\nclass ExampleDataset(Dataset):\n    def __init__(self, *args, **kwargs):\n        super().__init__(\n            name=\"benchmark://example-v0\",\n            license=\"MIT\",\n            description=\"An example dataset\",\n        )\n        self._benchmarks = {\n            \"/foo\": Benchmark.from_file_contents(\n                \"benchmark://example-v0/foo\", \"Ir data\".encode(\"utf-8\")\n            ),\n            \"/bar\": Benchmark.from_file_contents(\n                \"benchmark://example-v0/bar\", \"Ir data\".encode(\"utf-8\")\n            ),\n        }\n\n    def benchmark_uris(self) -> Iterable[str]:\n        yield from (f\"benchmark://example-v0{k}\" for k in self._benchmarks.keys())\n\n    def benchmark_from_parsed_uri(self, uri: BenchmarkUri) -> Benchmark:\n        if uri.path in self._benchmarks:\n            return self._benchmarks[uri]\n        else:\n            raise LookupError(\"Unknown program name\")\n\n\n# Register the example service on module import. After importing this module,\n# the example-v0 environment will be available to gym.make(...).\nregister(\n    id=\"example-cc-v0\",\n    entry_point=\"compiler_gym.envs:CompilerEnv\",\n    kwargs={\n        \"service\": EXAMPLE_CC_SERVICE_BINARY,\n        \"rewards\": [RuntimeReward()],\n        \"datasets\": [ExampleDataset()],\n    },\n)\n\nregister(\n    id=\"example-py-v0\",\n    entry_point=\"compiler_gym.envs:CompilerEnv\",\n    kwargs={\n        \"service\": EXAMPLE_PY_SERVICE_BINARY,\n        \"rewards\": [RuntimeReward()],\n        \"datasets\": [ExampleDataset()],\n    },\n)\n", "path": "examples/example_compiler_gym_service/__init__.py"}, {"content": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\"\"\"This module registers the Loop Optimizations CompilerGym environment \"\"\"\nimport subprocess\nfrom pathlib import Path\nfrom typing import Iterable\n\nfrom compiler_gym.datasets import Benchmark, Dataset\nfrom compiler_gym.envs.llvm.llvm_benchmark import get_system_library_flags\nfrom compiler_gym.spaces import Reward\nfrom compiler_gym.third_party import llvm\nfrom compiler_gym.util.registration import register\nfrom compiler_gym.util.runfiles_path import runfiles_path\n\nLOOPS_OPT_PY_SERVICE_BINARY: Path = runfiles_path(\n    \"examples/loop_optimizations_service/service_py/loops-opt-service-py\"\n)\n\nBENCHMARKS_PATH: Path = runfiles_path(\"examples/loop_optimizations_service/benchmarks\")\n\nNEURO_VECTORIZER_HEADER: Path = runfiles_path(\n    \"compiler_gym/third_party/neuro-vectorizer/header.h\"\n)\n\n\nclass RuntimeReward(Reward):\n    \"\"\"An example reward that uses changes in the \"runtime\" observation value\n    to compute incremental reward.\n    \"\"\"\n\n    def __init__(self):\n        super().__init__(\n            name=\"runtime\",\n            observation_spaces=[\"runtime\"],\n            default_value=0,\n            default_negates_returns=True,\n            deterministic=False,\n            platform_dependent=True,\n        )\n        self.baseline_runtime = 0\n\n    def reset(self, benchmark: str, observation_view):\n        del benchmark  # unused\n        self.baseline_runtime = observation_view[\"runtime\"]\n\n    def update(self, action, observations, observation_view):\n        del action  # unused\n        del observation_view  # unused\n        return float(self.baseline_runtime - observations[0]) / self.baseline_runtime\n\n\nclass SizeReward(Reward):\n    \"\"\"An example reward that uses changes in the \"size\" observation value\n    to compute incremental reward.\n    \"\"\"\n\n    def __init__(self):\n        super().__init__(\n            name=\"size\",\n            observation_spaces=[\"size\"],\n            default_value=0,\n            default_negates_returns=True,\n            deterministic=False,\n            platform_dependent=True,\n        )\n        self.baseline_size = 0\n\n    def reset(self, benchmark: str, observation_view):\n        del benchmark  # unused\n        self.baseline_runtime = observation_view[\"size\"]\n\n    def update(self, action, observations, observation_view):\n        del action  # unused\n        del observation_view  # unused\n        return float(self.baseline_size - observations[0]) / self.baseline_size\n\n\nclass LoopsDataset(Dataset):\n    def __init__(self, *args, **kwargs):\n        super().__init__(\n            name=\"benchmark://loops-opt-v0\",\n            license=\"MIT\",\n            description=\"Loops optimization dataset\",\n        )\n\n        self._benchmarks = {\n            \"benchmark://loops-opt-v0/add\": Benchmark.from_file_contents(\n                \"benchmark://loops-opt-v0/add\",\n                self.preprocess(BENCHMARKS_PATH / \"add.c\"),\n            ),\n            \"benchmark://loops-opt-v0/offsets1\": Benchmark.from_file_contents(\n                \"benchmark://loops-opt-v0/offsets1\",\n                self.preprocess(BENCHMARKS_PATH / \"offsets1.c\"),\n            ),\n            \"benchmark://loops-opt-v0/conv2d\": Benchmark.from_file_contents(\n                \"benchmark://loops-opt-v0/conv2d\",\n                self.preprocess(BENCHMARKS_PATH / \"conv2d.c\"),\n            ),\n        }\n\n    @staticmethod\n    def preprocess(src: Path) -> bytes:\n        \"\"\"Front a C source through the compiler frontend.\"\"\"\n        # TODO(github.com/facebookresearch/CompilerGym/issues/325): We can skip\n        # this pre-processing, or do it on the service side, once support for\n        # multi-file benchmarks lands.\n        cmd = [\n            str(llvm.clang_path()),\n            \"-E\",\n            \"-o\",\n            \"-\",\n            \"-I\",\n            str(NEURO_VECTORIZER_HEADER.parent),\n            src,\n        ]\n        cmd += get_system_library_flags()\n        return subprocess.check_output(\n            cmd,\n            timeout=300,\n        )\n\n    def benchmark_uris(self) -> Iterable[str]:\n        yield from self._benchmarks.keys()\n\n    def benchmark(self, uri: str) -> Benchmark:\n        if uri in self._benchmarks:\n            return self._benchmarks[uri]\n        else:\n            raise LookupError(\"Unknown program name\")\n\n\n# Register the unrolling example service on module import. After importing this module,\n# the loops-opt-py-v0 environment will be available to gym.make(...).\n\nregister(\n    id=\"loops-opt-py-v0\",\n    entry_point=\"compiler_gym.envs:CompilerEnv\",\n    kwargs={\n        \"service\": LOOPS_OPT_PY_SERVICE_BINARY,\n        \"rewards\": [RuntimeReward(), SizeReward()],\n        \"datasets\": [LoopsDataset()],\n    },\n)\n", "path": "examples/loop_optimizations_service/__init__.py"}], "after_files": [{"content": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\"\"\"This module defines and registers the example gym environments.\"\"\"\nfrom pathlib import Path\nfrom typing import Iterable\n\nfrom compiler_gym.datasets import Benchmark, Dataset\nfrom compiler_gym.datasets.uri import BenchmarkUri\nfrom compiler_gym.spaces import Reward\nfrom compiler_gym.util.registration import register\nfrom compiler_gym.util.runfiles_path import runfiles_path\n\nEXAMPLE_CC_SERVICE_BINARY: Path = runfiles_path(\n    \"examples/example_compiler_gym_service/service_cc/compiler_gym-example-service-cc\"\n)\n\nEXAMPLE_PY_SERVICE_BINARY: Path = runfiles_path(\n    \"examples/example_compiler_gym_service/service_py/compiler_gym-example-service-py\"\n)\n\n\nclass RuntimeReward(Reward):\n    \"\"\"An example reward that uses changes in the \"runtime\" observation value\n    to compute incremental reward.\n    \"\"\"\n\n    def __init__(self):\n        super().__init__(\n            name=\"runtime\",\n            observation_spaces=[\"runtime\"],\n            default_value=0,\n            default_negates_returns=True,\n            deterministic=False,\n            platform_dependent=True,\n        )\n        self.previous_runtime = None\n\n    def reset(self, benchmark: str, observation_view):\n        del benchmark  # unused\n        self.previous_runtime = None\n\n    def update(self, action, observations, observation_view):\n        del action\n        del observation_view\n\n        if self.previous_runtime is None:\n            self.previous_runtime = observations[0]\n\n        reward = float(self.previous_runtime - observations[0])\n        self.previous_runtime = observations[0]\n        return reward\n\n\nclass ExampleDataset(Dataset):\n    def __init__(self, *args, **kwargs):\n        super().__init__(\n            name=\"benchmark://example-v0\",\n            license=\"MIT\",\n            description=\"An example dataset\",\n        )\n        self._benchmarks = {\n            \"/foo\": Benchmark.from_file_contents(\n                \"benchmark://example-v0/foo\", \"Ir data\".encode(\"utf-8\")\n            ),\n            \"/bar\": Benchmark.from_file_contents(\n                \"benchmark://example-v0/bar\", \"Ir data\".encode(\"utf-8\")\n            ),\n        }\n\n    def benchmark_uris(self) -> Iterable[str]:\n        yield from (f\"benchmark://example-v0{k}\" for k in self._benchmarks.keys())\n\n    def benchmark_from_parsed_uri(self, uri: BenchmarkUri) -> Benchmark:\n        if uri.path in self._benchmarks:\n            return self._benchmarks[uri.path]\n        else:\n            raise LookupError(\"Unknown program name\")\n\n\n# Register the example service on module import. After importing this module,\n# the example-v0 environment will be available to gym.make(...).\nregister(\n    id=\"example-cc-v0\",\n    entry_point=\"compiler_gym.envs:CompilerEnv\",\n    kwargs={\n        \"service\": EXAMPLE_CC_SERVICE_BINARY,\n        \"rewards\": [RuntimeReward()],\n        \"datasets\": [ExampleDataset()],\n    },\n)\n\nregister(\n    id=\"example-py-v0\",\n    entry_point=\"compiler_gym.envs:CompilerEnv\",\n    kwargs={\n        \"service\": EXAMPLE_PY_SERVICE_BINARY,\n        \"rewards\": [RuntimeReward()],\n        \"datasets\": [ExampleDataset()],\n    },\n)\n", "path": "examples/example_compiler_gym_service/__init__.py"}, {"content": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\"\"\"This module registers the Loop Optimizations CompilerGym environment \"\"\"\nimport subprocess\nfrom pathlib import Path\nfrom typing import Iterable\n\nfrom compiler_gym.datasets import Benchmark, Dataset\nfrom compiler_gym.datasets.uri import BenchmarkUri\nfrom compiler_gym.envs.llvm.llvm_benchmark import get_system_library_flags\nfrom compiler_gym.spaces import Reward\nfrom compiler_gym.third_party import llvm\nfrom compiler_gym.util.registration import register\nfrom compiler_gym.util.runfiles_path import runfiles_path\n\nLOOPS_OPT_PY_SERVICE_BINARY: Path = runfiles_path(\n    \"examples/loop_optimizations_service/service_py/loops-opt-service-py\"\n)\n\nBENCHMARKS_PATH: Path = runfiles_path(\"examples/loop_optimizations_service/benchmarks\")\n\nNEURO_VECTORIZER_HEADER: Path = runfiles_path(\n    \"compiler_gym/third_party/neuro-vectorizer/header.h\"\n)\n\n\nclass RuntimeReward(Reward):\n    \"\"\"An example reward that uses changes in the \"runtime\" observation value\n    to compute incremental reward.\n    \"\"\"\n\n    def __init__(self):\n        super().__init__(\n            name=\"runtime\",\n            observation_spaces=[\"runtime\"],\n            default_value=0,\n            default_negates_returns=True,\n            deterministic=False,\n            platform_dependent=True,\n        )\n        self.baseline_runtime = 0\n\n    def reset(self, benchmark: str, observation_view):\n        del benchmark  # unused\n        self.baseline_runtime = observation_view[\"runtime\"]\n\n    def update(self, action, observations, observation_view):\n        del action  # unused\n        del observation_view  # unused\n        return float(self.baseline_runtime - observations[0]) / self.baseline_runtime\n\n\nclass SizeReward(Reward):\n    \"\"\"An example reward that uses changes in the \"size\" observation value\n    to compute incremental reward.\n    \"\"\"\n\n    def __init__(self):\n        super().__init__(\n            name=\"size\",\n            observation_spaces=[\"size\"],\n            default_value=0,\n            default_negates_returns=True,\n            deterministic=False,\n            platform_dependent=True,\n        )\n        self.baseline_size = 0\n\n    def reset(self, benchmark: str, observation_view):\n        del benchmark  # unused\n        self.baseline_runtime = observation_view[\"size\"]\n\n    def update(self, action, observations, observation_view):\n        del action  # unused\n        del observation_view  # unused\n        return float(self.baseline_size - observations[0]) / self.baseline_size\n\n\nclass LoopsDataset(Dataset):\n    def __init__(self, *args, **kwargs):\n        super().__init__(\n            name=\"benchmark://loops-opt-v0\",\n            license=\"MIT\",\n            description=\"Loops optimization dataset\",\n        )\n\n        self._benchmarks = {\n            \"/add\": Benchmark.from_file_contents(\n                \"benchmark://loops-opt-v0/add\",\n                self.preprocess(BENCHMARKS_PATH / \"add.c\"),\n            ),\n            \"/offsets1\": Benchmark.from_file_contents(\n                \"benchmark://loops-opt-v0/offsets1\",\n                self.preprocess(BENCHMARKS_PATH / \"offsets1.c\"),\n            ),\n            \"/conv2d\": Benchmark.from_file_contents(\n                \"benchmark://loops-opt-v0/conv2d\",\n                self.preprocess(BENCHMARKS_PATH / \"conv2d.c\"),\n            ),\n        }\n\n    @staticmethod\n    def preprocess(src: Path) -> bytes:\n        \"\"\"Front a C source through the compiler frontend.\"\"\"\n        # TODO(github.com/facebookresearch/CompilerGym/issues/325): We can skip\n        # this pre-processing, or do it on the service side, once support for\n        # multi-file benchmarks lands.\n        cmd = [\n            str(llvm.clang_path()),\n            \"-E\",\n            \"-o\",\n            \"-\",\n            \"-I\",\n            str(NEURO_VECTORIZER_HEADER.parent),\n            src,\n        ]\n        cmd += get_system_library_flags()\n        return subprocess.check_output(\n            cmd,\n            timeout=300,\n        )\n\n    def benchmark_uris(self) -> Iterable[str]:\n        yield from (f\"benchmark://loops-opt-v0{k}\" for k in self._benchmarks.keys())\n\n    def benchmark_from_parsed_uri(self, uri: BenchmarkUri) -> Benchmark:\n        if uri.path in self._benchmarks:\n            return self._benchmarks[uri.path]\n        else:\n            raise LookupError(\"Unknown program name\")\n\n\n# Register the unrolling example service on module import. After importing this module,\n# the loops-opt-py-v0 environment will be available to gym.make(...).\n\nregister(\n    id=\"loops-opt-py-v0\",\n    entry_point=\"compiler_gym.envs:CompilerEnv\",\n    kwargs={\n        \"service\": LOOPS_OPT_PY_SERVICE_BINARY,\n        \"rewards\": [RuntimeReward(), SizeReward()],\n        \"datasets\": [LoopsDataset()],\n    },\n)\n", "path": "examples/loop_optimizations_service/__init__.py"}]}