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 13, 2021
1 parent dc95c01 commit e00e62b
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 63 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
132 changes: 70 additions & 62 deletions tests/llvm/observation_spaces_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,75 @@ def test_bitcode_observation_space(env: LlvmEnv):
assert not space.platform_dependent


# The Autophase feature vector for benchmark://cBench-v0/crc32 in its initial
# state.
AUTOPHASE_CBENCH_CRC32 = [
0,
0,
16,
12,
2,
16,
8,
2,
4,
8,
0,
0,
0,
29,
0,
24,
9,
2,
32,
44,
41,
14,
36,
16,
13,
0,
5,
26,
3,
5,
24,
20,
24,
33,
5,
10,
3,
51,
0,
1,
0,
5,
0,
0,
0,
42,
0,
1,
8,
5,
29,
242,
157,
15,
0,
103,
]


def test_autophase_observation_space_reset(env: LlvmEnv):
"""Test that the intial observation is returned on env.reset()."""
env.observation_space = "Autophase"
observation = env.reset("cBench-v0/crc32")
np.testing.assert_array_equal(observation, AUTOPHASE_CBENCH_CRC32)


def test_autophase_observation_space(env: LlvmEnv):
env.reset("cBench-v1/crc32")
key = "Autophase"
Expand All @@ -106,68 +175,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,
44,
41,
14,
36,
16,
13,
0,
5,
26,
3,
5,
24,
20,
24,
33,
5,
10,
3,
51,
0,
1,
0,
5,
0,
0,
0,
42,
0,
1,
8,
5,
29,
242,
157,
15,
0,
103,
],
)

np.testing.assert_array_equal(value, AUTOPHASE_CBENCH_CRC32)
assert space.space.contains(value)


Expand Down

0 comments on commit e00e62b

Please sign in to comment.