Skip to content

Commit ad5513c

Browse files
authored
enable gin bindings for compilation flags (#103)
* enable gin bindings for compilation flags * updated gin bindings for compilation flags. make necessary changes to enable replace_flags. updates the default list of delete_flags. * updated gin bindings for compilation flags. make necessary changes to enable replace_flags. updates the default list of delete_flags. * update delete flags.
1 parent 4ee3689 commit ad5513c

File tree

6 files changed

+42
-13
lines changed

6 files changed

+42
-13
lines changed

compiler_opt/rl/corpus.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ def _build_modulespecs_from_datapath(
183183
logging.warning('Additional flags are specified together with override.')
184184
if len(delete_flags) > 0:
185185
logging.warning('Delete flags are specified together with override.')
186+
if len(replace_flags) > 0:
187+
logging.warning('Replace flags are specified together with override.')
186188

187189
module_specs: List[ModuleSpec] = []
188190

compiler_opt/rl/inlining/gin_configs/common.gin

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@ clang_path=None
77
runners.InliningRunner.llvm_size_path=%llvm_size_path
88
runners.InliningRunner.clang_path=%clang_path
99
runners.InliningRunner.launcher_path=%launcher_path
10+
11+
problem_config.flags_to_add.add_flags=()
12+
problem_config.flags_to_delete.delete_flags=('-split-dwarf-file','-split-dwarf-output',)
13+
# For AFDO profile reinjection elide overlapping flags from delete_flags and set
14+
# problem_config.flags_to_replace.replace_flags={'-fprofile-sample-use':'/path/to/gwp.afdo','-fprofile-remapping-file':'/path/to/prof_remap.txt'}
15+
problem_config.flags_to_replace.replace_flags={}

compiler_opt/rl/problem_configuration.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@
6868
"""
6969

7070
import abc
71-
from typing import Callable, Iterable, Tuple
71+
import gin
72+
from typing import Callable, Dict, Iterable, Optional, Tuple
7273

7374
import tensorflow as tf
7475
import tf_agents as tfa
@@ -103,15 +104,25 @@ def get_runner_type(self) -> 'type[compilation_runner.CompilationRunner]':
103104
# TODO(b/233935329): The following clang flags need to be tied to a corpus
104105
# rather than to a training tool invocation.
105106

106-
# List of flags to add to clang compilation command. The flag names should
107-
# match the actual flags provided to clang. An example for AFDO reinjection:
108-
# return ['-fprofile-sample-use=/path/to/gwp.afdo',
109-
# '-fprofile-remapping-file=/path/to/prof_remap.txt']
110-
def flags_to_add(self) -> Tuple[str, ...]:
111-
return ()
107+
# List of flags to add to clang compilation command.
108+
@gin.configurable(module='problem_config')
109+
def flags_to_add(self, add_flags=()) -> Tuple[str, ...]:
110+
return add_flags
112111

113112
# List of flags to remove from clang compilation command. The flag names
114113
# should match the actual flags provided to clang.'
115-
def flags_to_delete(self) -> Tuple[str, ...]:
116-
return ('-split-dwarf-file', '-split-dwarf-output', '-fprofile-sample-use',
117-
'-fprofile-remapping-file')
114+
@gin.configurable(module='problem_config')
115+
def flags_to_delete(self, delete_flags=()) -> Tuple[str, ...]:
116+
return delete_flags
117+
118+
# List of flags to replace in the clang compilation command. The flag names
119+
# should match the actual flags provided to clang. An example for AFDO
120+
# reinjection:
121+
# replace_flags={
122+
# '-fprofile-sample-use':'/path/to/gwp.afdo',
123+
# '-fprofile-remapping-file':'/path/to/prof_remap.txt'
124+
# }
125+
# return replace_flags
126+
@gin.configurable(module='problem_config')
127+
def flags_to_replace(self, replace_flags=None) -> Optional[Dict[str, str]]:
128+
return replace_flags

compiler_opt/rl/regalloc/gin_configs/common.gin

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ clang_path=None
55

66
runners.RegAllocRunner.clang_path=%clang_path
77
runners.RegAllocRunner.launcher_path=%launcher_path
8+
9+
problem_config.flags_to_add.add_flags=()
10+
problem_config.flags_to_delete.delete_flags=('-split-dwarf-file','-split-dwarf-output',)
11+
# For AFDO profile reinjection elide overlapping flags from delete_flags and set
12+
# problem_config.flags_to_replace.replace_flags={'-fprofile-sample-use':'/path/to/gwp.afdo','-fprofile-remapping-file':'/path/to/prof_remap.txt'}
13+
problem_config.flags_to_replace.replace_flags={}

compiler_opt/rl/train_locally.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,11 @@ def train_eval(agent_name=constant.AgentName.PPO,
9999
saver = policy_saver.PolicySaver(policy_dict=policy_dict)
100100

101101
logging.info('Loading module specs from corpus at %s.', FLAGS.data_path)
102-
cps = corpus.Corpus(FLAGS.data_path, problem_config.flags_to_add(),
103-
problem_config.flags_to_delete())
102+
cps = corpus.Corpus(
103+
FLAGS.data_path,
104+
additional_flags=problem_config.flags_to_add(),
105+
delete_flags=problem_config.flags_to_delete(),
106+
replace_flags=problem_config.flags_to_replace())
104107
logging.info('Done loading module specs from corpus.')
105108

106109
dataset_fn = data_reader.create_sequence_example_dataset_fn(

compiler_opt/tools/generate_default_trace.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ def main(_):
142142
cps = corpus.Corpus(
143143
_DATA_PATH.value,
144144
additional_flags=config.flags_to_add(),
145-
delete_flags=config.flags_to_delete())
145+
delete_flags=config.flags_to_delete(),
146+
replace_flags=config.flags_to_replace())
146147
logging.info('Done loading module specs from corpus.')
147148

148149
if _MODULE_FILTER.value:

0 commit comments

Comments
 (0)