-
Notifications
You must be signed in to change notification settings - Fork 834
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into batch-matmul-no-hybrid
- Loading branch information
Showing
16 changed files
with
288 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# TensorFlow Lite for Microcontrollers | ||
|
||
This package is built from commit | ||
[{STABLE_GIT_HASH}](https://github.com/tensorflow/tflite-micro/blob/{STABLE_GIT_HASH}/python/tflite_micro) | ||
of [github.com/tensorflow/tflite-micro](https://github.com/tensorflow/tflite-micro). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__version__ = "{BUILD_EMBED_LABEL}.dev{STABLE_GIT_COMMIT_TIME}-g{STABLE_GIT_HASH}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
load("@rules_python//python:defs.bzl", "py_binary", "py_test") | ||
|
||
package( | ||
default_visibility = ["//visibility:public"], | ||
) | ||
|
||
py_binary( | ||
name = "expand_stamp_vars", | ||
srcs = ["expand_stamp_vars.py"], | ||
) | ||
|
||
py_test( | ||
name = "expand_stamp_vars_test", | ||
srcs = ["expand_stamp_vars_test.py"], | ||
deps = [":expand_stamp_vars"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Copyright 2023 The TensorFlow Authors. All Rights Reserved. | ||
# | ||
# 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. | ||
# ---- | ||
|
||
def expand_stamp_vars(name, template, out): | ||
"""Macro for expanding a template using workspace status variables. | ||
Typical usage in a BUILD file: | ||
expand_stamp_vars( | ||
name = "version", | ||
template = "_version.py.in", | ||
out = "_version.py", | ||
) | ||
Writes `template` to `out`, expanding references of the form '{KEY}' to the | ||
value of the corresponding Bazel workspace status variable. | ||
""" | ||
|
||
# This macro uses a genrule to call a helper program at Bazel execution | ||
# time, because workspace variables are not available until execution time. | ||
# Workspace variables are generated by bazel on each invocation, and | ||
# written to the hardcoded files names used below. See the Bazel | ||
# documentation for the option --workspace_status_command. | ||
|
||
native.genrule( | ||
name = name, | ||
srcs = [template], | ||
outs = [out], | ||
cmd = "$(location //tools:expand_stamp_vars) " + | ||
"bazel-out/stable-status.txt " + | ||
"bazel-out/volatile-status.txt " + | ||
"<$< >$@", | ||
tools = [ | ||
"//tools:expand_stamp_vars", | ||
], | ||
|
||
# Undocumented, but valid, and the only way to declare the necessary | ||
# dependencies on {stable,volatile}-status.txt. | ||
stamp = 1, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright 2023 The TensorFlow Authors. All Rights Reserved. | ||
# | ||
# 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. | ||
# ---- | ||
|
||
# A filter that expands Bazel workspace stamp variables. | ||
# | ||
# For example, the input steam: | ||
# | ||
# This build was compiled at {BUILD_DATE}. | ||
# | ||
# is expanded into the output stream: | ||
# | ||
# This build was compiled at 2023-02-10T14:15. | ||
# | ||
# Stamp variable key-value pairs are read from all files passed as positional | ||
# arguments. These files are typically bazel-out/stable-status.txt and | ||
# bazel-out/volatile-status.txt. See the Bazel documentation for the option | ||
# --workspace_status_command. | ||
|
||
import sys | ||
|
||
|
||
def read_stamps(file): | ||
"""Return a dictionary of key-value pairs read from a stamp file. | ||
These files are typically bazel-out/stable-status.txt and | ||
bazel-out/volatile-status.txt. See the Bazel documentation for the option | ||
--workspace_status_command.""" | ||
|
||
stamps = {} | ||
for line in file: | ||
try: | ||
key, value = line.split(" ", maxsplit=1) | ||
stamps[key] = value.strip() | ||
except ValueError: | ||
pass # Skip blank lines, etc. | ||
|
||
return stamps | ||
|
||
|
||
def expand(istream, ostream, stamps): | ||
"""Write istream to ostream, expanding placeholders like {KEY}.""" | ||
for line in istream: | ||
for key, value in stamps.items(): | ||
line = line.replace(f"{{{key}}}", value) | ||
ostream.write(line) | ||
|
||
|
||
def _main(): | ||
"""Stamp variables are read from all files passed as positional arguments.""" | ||
stamps = {} | ||
for name in sys.argv[1:]: | ||
with open(name) as f: | ||
stamps.update(read_stamps(f)) | ||
|
||
expand(sys.stdin, sys.stdout, stamps) | ||
|
||
sys.exit(0) | ||
|
||
|
||
if __name__ == "__main__": | ||
_main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright 2023 The TensorFlow Authors. All Rights Reserved. | ||
# | ||
# 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. | ||
# ---- | ||
|
||
# A test for the filter that expands Bazel workspace stamp variables. | ||
|
||
from tools import expand_stamp_vars | ||
|
||
import io | ||
import unittest | ||
|
||
|
||
class FilterTest(unittest.TestCase): | ||
"""A simple test of the expansion feature.""" | ||
|
||
def test_basic(self): | ||
stamps = """ | ||
BUILD_STAMP_ONE value_one | ||
BUILD_STAMP_TWO value_two | ||
""" | ||
input = "This is {BUILD_STAMP_TWO}. This is {BUILD_STAMP_ONE}." | ||
golden = "This is value_two. This is value_one." | ||
|
||
istream = io.StringIO(input) | ||
ostream = io.StringIO() | ||
stamps = expand_stamp_vars.read_stamps(io.StringIO(stamps)) | ||
expand_stamp_vars.expand(istream, ostream, stamps) | ||
|
||
self.assertEqual(ostream.getvalue(), golden) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
Oops, something went wrong.