Skip to content

Commit

Permalink
[llvm] Fix initial observation value on env.reset().
Browse files Browse the repository at this point in the history
A regression introduced in:

    commit 6cccf05
    Author: Chris Cummins <chrisc.101@gmail.com>
    Date:   Fri Feb 26 14:10:35 2021 +0000

    [llvm] Install cBench-v0 if no benchmarks are installed.

means that env.reset() would not return an observation value for
LlvmEnv instances.
  • Loading branch information
ChrisCummins committed Mar 11, 2021
1 parent a7cf83b commit b75e8db
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 62 deletions.
2 changes: 1 addition & 1 deletion compiler_gym/envs/llvm/llvm_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def reset(self, *args, **kwargs):
# once the dataset API has been refactored so that service-side datasets
# are no longer an issue.
try:
super().reset(*args, **kwargs)
return super().reset(*args, **kwargs)
except FileNotFoundError:
self.logger.warning(
"reset() called on servie with no benchmarks available. "
Expand Down
129 changes: 68 additions & 61 deletions tests/llvm/observation_spaces_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,73 @@ def test_bitcode_observation_space(env: LlvmEnv):
assert not space.platform_dependent


AUTOPHASE_CRC32 = [
0,
0,
16,
12,
2,
16,
8,
2,
4,
8,
0,
0,
0,
29,
0,
24,
9,
2,
32,
38,
21,
14,
30,
16,
13,
0,
5,
24,
3,
3,
26,
0,
24,
13,
5,
10,
3,
51,
0,
1,
0,
5,
0,
0,
0,
38,
0,
1,
8,
5,
29,
196,
131,
13,
0,
81,
]


def test_autophase_observation_space_reset(env: LlvmEnv):
"""Test that feature vector is reutned by env.reset()."""
env.observation_space = "Autophase"
observation = env.reset("cBench-v0/crc32")
np.testing.assert_array_equal(observation, AUTOPHASE_CRC32)


def test_autophase_observation_space(env: LlvmEnv):
env.reset("cBench-v0/crc32")
key = "Autophase"
Expand All @@ -106,67 +173,7 @@ def test_autophase_observation_space(env: LlvmEnv):
assert space.deterministic
assert not space.platform_dependent

np.testing.assert_array_equal(
value,
[
0,
0,
16,
12,
2,
16,
8,
2,
4,
8,
0,
0,
0,
29,
0,
24,
9,
2,
32,
38,
21,
14,
30,
16,
13,
0,
5,
24,
3,
3,
26,
0,
24,
13,
5,
10,
3,
51,
0,
1,
0,
5,
0,
0,
0,
38,
0,
1,
8,
5,
29,
196,
131,
13,
0,
81,
],
)
np.testing.assert_array_equal(value, AUTOPHASE_CRC32)

assert space.space.contains(value)

Expand Down

0 comments on commit b75e8db

Please sign in to comment.