Skip to content

Commit 2f27005

Browse files
Fix deleted tflite policy directory in regalloc_trace_worker
Due to the thread pool executor not being inside the `with` statement setting up the directory holding the policy, it sometimes got deleted before all compilations were finished. This patch fixes that by making sure the thread pool is done before the context manager for the temp dir closes. Reviewers: mtrofin Reviewed By: mtrofin Pull Request: #434
1 parent 0db6cd1 commit 2f27005

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

compiler_opt/es/regalloc_trace/regalloc_trace_worker.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -105,30 +105,30 @@ def _build_corpus(self, modules: Collection[corpus.ModuleSpec],
105105
else:
106106
tflite_policy_dir = None
107107

108-
with concurrent.futures.ThreadPoolExecutor(
109-
max_workers=self._thread_count) as thread_pool:
110-
compile_futures = [
111-
thread_pool.submit(self._compile_module, module, output_directory,
112-
tflite_policy_dir) for module in modules
113-
]
114-
115-
for future in compile_futures:
116-
if future.exception() is not None:
117-
raise future.exception()
118-
119-
# Write out a corpus description. basic_block_trace_model uses a corpus
120-
# description JSON to know which object files to load, so we need to emit
121-
# one before performing evaluation.
122-
corpus_description_path = os.path.join(output_directory,
123-
"corpus_description.json")
124-
corpus_description = {
125-
"modules": [module_spec.name for module_spec in modules]
126-
}
127-
128-
with open(
129-
corpus_description_path, "w",
130-
encoding="utf-8") as corpus_description_file:
131-
json.dump(corpus_description, corpus_description_file)
108+
with concurrent.futures.ThreadPoolExecutor(
109+
max_workers=self._thread_count) as thread_pool:
110+
compile_futures = [
111+
thread_pool.submit(self._compile_module, module, output_directory,
112+
tflite_policy_dir) for module in modules
113+
]
114+
115+
for future in compile_futures:
116+
if future.exception() is not None:
117+
raise future.exception()
118+
119+
# Write out a corpus description. basic_block_trace_model uses a corpus
120+
# description JSON to know which object files to load, so we need to emit
121+
# one before performing evaluation.
122+
corpus_description_path = os.path.join(output_directory,
123+
"corpus_description.json")
124+
corpus_description = {
125+
"modules": [module_spec.name for module_spec in modules]
126+
}
127+
128+
with open(
129+
corpus_description_path, "w",
130+
encoding="utf-8") as corpus_description_file:
131+
json.dump(corpus_description, corpus_description_file)
132132

133133
def _evaluate_corpus(self, module_directory: str, function_index_path: str,
134134
bb_trace_path: str):

0 commit comments

Comments
 (0)