Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Created using spr 1.3.4
  • Loading branch information
boomanaiden154 committed Jan 12, 2025
2 parents b071f30 + 2d576f3 commit c718a8e
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
14 changes: 14 additions & 0 deletions compiler_opt/es/regalloc_trace/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# coding=utf-8
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
3 changes: 2 additions & 1 deletion compiler_opt/es/regalloc_trace/regalloc_trace_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ def _evaluate_corpus(self, module_directory: str, function_index_path: str,

def compile_corpus_and_evaluate(
self, modules: Collection[corpus.ModuleSpec], function_index_path: str,
bb_trace_path: str, tflite_policy: Optional[policy_saver.Policy]) -> int:
bb_trace_path: str,
tflite_policy: Optional[policy_saver.Policy]) -> float:
with tempfile.TemporaryDirectory() as compilation_dir:
self._build_corpus(modules, compilation_dir, tflite_policy)

Expand Down
23 changes: 22 additions & 1 deletion compiler_opt/es/regalloc_trace/regalloc_trace_worker_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

from compiler_opt.es.regalloc_trace import regalloc_trace_worker
from compiler_opt.rl import corpus
from compiler_opt.testing import model_test_utils
from compiler_opt.rl import policy_saver


def _setup_corpus(corpus_dir: str) -> List[corpus.ModuleSpec]:
Expand Down Expand Up @@ -120,8 +122,27 @@ def test_compile_corpus_and_evaluate_with_tflite(self):
_create_test_binary(fake_bb_trace_model_binary.full_path,
fake_bb_trace_model_invocations.full_path)

saved_model_dir = self.create_tempdir("saved_model")
tflite_dir = self.create_tempdir("converted_model")
model_test_utils.gen_test_model(saved_model_dir.full_path)
policy_saver.convert_mlgo_model(saved_model_dir.full_path,
tflite_dir.full_path)
serialized_policy = policy_saver.Policy.from_filesystem(
tflite_dir.full_path)

worker = regalloc_trace_worker.RegallocTraceWorker(
fake_clang_binary.full_path, fake_bb_trace_model_binary.full_path, 1,
corpus_dir.full_path)
worker.compile_corpus_and_evaluate(corpus_modules, "function_index_path.pb",
"bb_trace_path.pb", None)
"bb_trace_path.pb", serialized_policy)

# Assert that we pass the TFLite model to the clang invocations.
clang_command_lines = fake_clang_invocations.read_text().split("\n")
clang_command_lines.remove("")
self.assertLen(clang_command_lines, 2)
self.assertTrue(
"-regalloc-enable-advisor=development" in clang_command_lines[0])
self.assertTrue("-regalloc-model=" in clang_command_lines[0])
self.assertTrue(
"-regalloc-enable-advisor=development" in clang_command_lines[1])
self.assertTrue("-regalloc-model=" in clang_command_lines[1])
14 changes: 14 additions & 0 deletions compiler_opt/testing/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# coding=utf-8
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

0 comments on commit c718a8e

Please sign in to comment.