Skip to content

Commit 3a31367

Browse files
authored
Default to using self.cancellation_manager (#115)
Part of #96
1 parent 5bbca7d commit 3a31367

File tree

4 files changed

+13
-31
lines changed

4 files changed

+13
-31
lines changed

compiler_opt/rl/compilation_runner.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -335,20 +335,14 @@ def collect_data(
335335
"""
336336
if reward_stat is None:
337337
default_result = self.compile_fn(
338-
module_spec,
339-
tf_policy_path='',
340-
reward_only=bool(tf_policy_path),
341-
cancellation_manager=self._cancellation_manager)
338+
module_spec, tf_policy_path='', reward_only=bool(tf_policy_path))
342339
reward_stat = {
343340
k: RewardStat(v[1], v[1]) for (k, v) in default_result.items()
344341
}
345342

346343
if tf_policy_path:
347344
policy_result = self.compile_fn(
348-
module_spec,
349-
tf_policy_path,
350-
reward_only=False,
351-
cancellation_manager=self._cancellation_manager)
345+
module_spec, tf_policy_path, reward_only=False)
352346
else:
353347
policy_result = default_result
354348

@@ -384,17 +378,13 @@ def collect_data(
384378

385379
def compile_fn(
386380
self, module_spec: corpus.ModuleSpec, tf_policy_path: str,
387-
reward_only: bool,
388-
cancellation_manager: Optional[WorkerCancellationManager]
389-
) -> Dict[str, Tuple[tf.train.SequenceExample, float]]:
381+
reward_only: bool) -> Dict[str, Tuple[tf.train.SequenceExample, float]]:
390382
"""Compiles for the given IR file under the given policy.
391383
392384
Args:
393385
module_spec: a ModuleSpec.
394386
tf_policy_path: path to TF policy directory on local disk.
395387
reward_only: whether only return reward.
396-
cancellation_manager: a WorkerCancellationManager to handle early
397-
termination
398388
399389
Returns:
400390
A dict mapping from example identifier to tuple containing:

compiler_opt/rl/compilation_runner_test.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,8 @@ def _get_sequence_example(feature_value):
7676
return text_format.Parse(sequence_example_text, tf.train.SequenceExample())
7777

7878

79-
def _mock_compile_fn(file_paths, tf_policy_path, reward_only,
80-
cancellation_manager): # pylint: disable=unused-argument
79+
def _mock_compile_fn(file_paths, tf_policy_path, reward_only): # pylint: disable=unused-argument
8180
del file_paths
82-
del cancellation_manager
8381
if tf_policy_path:
8482
sequence_example = _get_sequence_example(_POLICY_FEATURE_VALUE)
8583
native_size = _POLICY_REWARD

compiler_opt/rl/inlining/inlining_runner.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import io
1818
import os
1919
import tempfile
20-
from typing import Dict, Optional, Tuple
20+
from typing import Dict, Tuple
2121

2222
import gin
2323
import tensorflow as tf
@@ -47,17 +47,13 @@ def __init__(self, llvm_size_path: str, *args, **kwargs):
4747

4848
def compile_fn(
4949
self, module_spec: corpus.ModuleSpec, tf_policy_path: str,
50-
reward_only: bool, cancellation_manager: Optional[
51-
compilation_runner.WorkerCancellationManager]
52-
) -> Dict[str, Tuple[tf.train.SequenceExample, float]]:
50+
reward_only: bool) -> Dict[str, Tuple[tf.train.SequenceExample, float]]:
5351
"""Run inlining for the given IR file under the given policy.
5452
5553
Args:
5654
module_spec: a ModuleSpec.
5755
tf_policy_path: path to TF policy direcoty on local disk.
5856
reward_only: whether only return native size.
59-
cancellation_manager: handler for early termination by killing any running
60-
processes
6157
6258
Returns:
6359
A dict mapping from example identifier to tuple containing:
@@ -71,6 +67,7 @@ def compile_fn(
7167
cancelled work.
7268
RuntimeError: if llvm-size produces unexpected output.
7369
"""
70+
7471
working_dir = tempfile.mkdtemp()
7572

7673
log_path = os.path.join(working_dir, 'log')
@@ -91,12 +88,12 @@ def compile_fn(
9188
['-mllvm', '-ml-inliner-model-under-training=' + tf_policy_path])
9289
compilation_runner.start_cancellable_process(command_line,
9390
self._compilation_timeout,
94-
cancellation_manager)
91+
self._cancellation_manager)
9592
command_line = [self._llvm_size_path, output_native_path]
9693
output_bytes = compilation_runner.start_cancellable_process(
9794
command_line,
9895
timeout=self._compilation_timeout,
99-
cancellation_manager=cancellation_manager,
96+
cancellation_manager=self._cancellation_manager,
10097
want_output=True)
10198
if not output_bytes:
10299
raise RuntimeError(f'Empty llvm-size output: {" ".join(command_line)}')

compiler_opt/rl/regalloc/regalloc_runner.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import io
1919
import os
2020
import tempfile
21-
from typing import Dict, Optional, Tuple
21+
from typing import Dict, Tuple
2222

2323
import gin
2424
import tensorflow as tf
@@ -45,17 +45,13 @@ class RegAllocRunner(compilation_runner.CompilationRunner):
4545
# construction
4646
def compile_fn(
4747
self, module_spec: corpus.ModuleSpec, tf_policy_path: str,
48-
reward_only: bool, cancellation_manager: Optional[
49-
compilation_runner.WorkerCancellationManager]
50-
) -> Dict[str, Tuple[tf.train.SequenceExample, float]]:
48+
reward_only: bool) -> Dict[str, Tuple[tf.train.SequenceExample, float]]:
5149
"""Run inlining for the given IR file under the given policy.
5250
5351
Args:
5452
module_spec: a ModuleSpec.
5553
tf_policy_path: path to TF policy direcoty on local disk.
5654
reward_only: whether only return reward.
57-
cancellation_manager: handler for early termination by killing any running
58-
processes
5955
6056
Returns:
6157
A dict mapping from example identifier to tuple containing:
@@ -69,6 +65,7 @@ def compile_fn(
6965
cancelled work.
7066
RuntimeError: if llvm-size produces unexpected output.
7167
"""
68+
7269
working_dir = tempfile.mkdtemp()
7370

7471
log_path = os.path.join(working_dir, 'log')
@@ -88,7 +85,7 @@ def compile_fn(
8885
command_line.extend(['-mllvm', '-regalloc-model=' + tf_policy_path])
8986
compilation_runner.start_cancellable_process(command_line,
9087
self._compilation_timeout,
91-
cancellation_manager)
88+
self._cancellation_manager)
9289

9390
sequence_example = struct_pb2.Struct()
9491

0 commit comments

Comments
 (0)