Skip to content

Commit

Permalink
add AutoPaseDict observation
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafaelhoushi committed Feb 26, 2022
1 parent ce6cee3 commit 7ff28d4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/loop_optimizations_service/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
with compiler_gym.make(
"loops-opt-py-v0",
benchmark="loops-opt-v0/add",
observation_space="Autophase",
observation_space="AutophaseDict",
reward_space="runtime",
) as env:
compiler_gym.set_debug_level(4) # TODO: check why this has no effect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from compiler_gym.service.proto import (
ActionSpace,
Benchmark,
DictEvent,
DictSpace,
DoubleRange,
Event,
Expand Down Expand Up @@ -85,6 +86,19 @@ class LoopsOptCompilationSession(CompilationSession):
),
ObservationSpace(
name="Autophase",
space=Space(
int64_sequence=Int64SequenceSpace(
length_range=Int64Range(
min=len(AUTOPHASE_FEATURE_NAMES),
max=len(AUTOPHASE_FEATURE_NAMES),
)
),
),
deterministic=True,
platform_dependent=False,
),
ObservationSpace(
name="AutophaseDict",
space=Space(
space_dict=DictSpace(
space={
Expand Down Expand Up @@ -256,7 +270,7 @@ def get_observation(self, observation_space: ObservationSpace) -> Event:
int64_tensor=Int64Tensor(shape=[len(Inst2vec_ids)], value=Inst2vec_ids)
)
elif observation_space.name == "Autophase":
Autophase_ids_str = run_command(
Autophase_str = run_command(
[
runfiles_path(
"compiler_gym/third_party/autophase/compute_autophase-prelinked"
Expand All @@ -265,12 +279,28 @@ def get_observation(self, observation_space: ObservationSpace) -> Event:
],
timeout=30,
)
Autophase_ids_int = list(map(int, list(Autophase_ids_str.split(" "))))
Autophase_list = list(map(int, list(Autophase_str.split(" "))))
return Event(
int64_tensor=Int64Tensor(
shape=[len(Autophase_ids_int)], value=Autophase_ids_int
shape=[len(Autophase_list)], value=Autophase_list
)
)
elif observation_space.name == "AutophaseDict":
Autophase_str = run_command(
[
runfiles_path(
"compiler_gym/third_party/autophase/compute_autophase-prelinked"
),
self._llvm_path,
],
timeout=30,
)
Autophase_list = list(map(int, list(Autophase_str.split(" "))))
Autophase_dict = {
name: Event(int64_value=val)
for name, val in zip(AUTOPHASE_FEATURE_NAMES, Autophase_list)
}
return Event(event_dict=DictEvent(event=Autophase_dict))
elif observation_space.name == "Programl":
Programl_str = run_command(
[
Expand Down

0 comments on commit 7ff28d4

Please sign in to comment.