Skip to content

Commit

Permalink
Release Grouper
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitriykovalev committed Jul 26, 2021
1 parent 8b21123 commit 6589d0b
Show file tree
Hide file tree
Showing 195 changed files with 7,628 additions and 2,614 deletions.
14 changes: 14 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
common --experimental_repo_remote_exec

build --define darwinn_portable=1
build --subcommands
build --verbose_failures
build --enable_platform_specific_config

build:linux --crosstool_top=@crosstool//:toolchains
build:linux --compiler=gcc

build:macos --cxxopt=-std=c++14

build:windows --incompatible_restrict_string_escapes=false
build:windows --cxxopt=/std:c++latest
1 change: 0 additions & 1 deletion .gitattributes

This file was deleted.

52 changes: 51 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,53 @@
# libcoral
# libcoral changes


## Grouper release

* API changes for `PipelinedModelRunner`:
* `Push()` and `Pop()` now return either `absl::OkStatus` or
`absl::InternalError`, instead of True/False.
* Added tensor `name` to `PipelineTensor`.
* `GetInputTensorNames()` and `GetInputTensor()` moved to `tflite_utils.h`.
* `GetDetectionResults()` now supports SSD models with different orders in
the output tensor.

* Updated profiling-based partitioner:
* Renamed executable to `partition_with_profiling`.
* Added support for SSD models, and other models with large CPU segments
and/or graph branches. (This also requires v16 of the Edge TPU Compiler.)
* Automatically enables the [`search_delegate`
option](https://coral.ai/docs/edgetpu/compiler#usage) (add in v16 of the Edge
TPU Compiler), so that if the compiler first fails to compile the model, it
continues to search for a portion of the graph that can compile.
* Added flags:
* `delegate_search_step`: Same as the `delegate_search_step` option
added in v16 of the Edge TPU Compiler.
* `partition_search_step`: Similar to the `delegate_search_step`
option, but applied to the delegate search for each segment (rather than
the entire pipelined graph).
* `initial_lower_bound_ns` and `initial_upper_bound_ns`: The known
smallest/largest latency among your model's segments. These are otherwise
calculated in the tool by benchmarking the heuristic-based segments from
the Edge TPU Compiler.

* Added `split_fc` tool to pre-process tflite models with fully-connected
layers that are too big for the Edge TPU Compiler. For example, the compiler is
unable to compile a layer that has 100,000 output classes due to the size of the
weights matrix applied to the fully-connected layer (this operation would be cut
from the Edge TPU delegate and instead execute on the CPU). So the `split_fc`
tool divides the weights into smaller blocks using block-wise matrix
multiplication (you can control the ratio of the split operation). The revised
`.tflite` file output by `split_fc` can then be passed to the Edge TPU Compiler.

* Added `append_recurrent_links` tool, which helps you create recurrent
networks for the Edge TPU with a hidden saved state. *Without this tool*,
creating a recurrent network that can compile for the Edge TPU typically
requires that your model output the saved state and then you must pass back
the saved state into your model manually. By instead passing such a model to the
`append_recurrent_links` tool, you can make that saved state hidden again so
your application code can focus on the final output.


## Frogfish release

* Initial libcoral release
80 changes: 27 additions & 53 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,64 +12,40 @@
# See the License for the specific language governing permissions and
# limitations under the License.
SHELL := /bin/bash
PYTHON3 ?= python3
MAKEFILE_DIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
PY3_VER ?= $(shell $(PYTHON3) -c "import sys;print('%d%d' % sys.version_info[:2])")
OS := $(shell uname -s)

# Allowed CPU values: k8, armv7a, aarch64, darwin
ifeq ($(OS),Linux)
CPU ?= k8
TEST_FILTER ?= cat
else ifeq ($(OS),Darwin)
CPU ?= darwin
TEST_FILTER ?= grep -v dmabuf
else
$(error $(OS) is not supported)
endif

ifeq ($(filter $(CPU),k8 armv7a aarch64 darwin),)
$(error CPU must be k8, armv7a, aarch64, or darwin)
endif

# Allowed COMPILATION_MODE values: opt, dbg, fastbuild
COMPILATION_MODE ?= opt
ifeq ($(filter $(COMPILATION_MODE),opt dbg fastbuild),)
$(error COMPILATION_MODE must be opt, dbg or fastbuild)
$(error COMPILATION_MODE must be opt, dbg, or fastbuild)
endif

BAZEL_OUT_DIR := $(MAKEFILE_DIR)/bazel-out/$(CPU)-$(COMPILATION_MODE)/bin
COMMON_BAZEL_BUILD_FLAGS_Linux := --crosstool_top=@crosstool//:toolchains \
--compiler=gcc
COMMON_BAZEL_BUILD_FLAGS_Darwin :=
COMMON_BAZEL_BUILD_FLAGS := --compilation_mode=$(COMPILATION_MODE) \
--copt=-DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION \
--verbose_failures \
--sandbox_debug \
--subcommands \
--define PY3_VER=$(PY3_VER) \
--action_env PYTHON_BIN_PATH=$(shell which $(PYTHON3)) \
--cpu=$(CPU) \
--define darwinn_portable=1 \
--experimental_repo_remote_exec \
$(COMMON_BAZEL_BUILD_FLAGS_$(OS))

BAZEL_BUILD_FLAGS_Linux := --linkopt=-l:libusb-1.0.so
BAZEL_BUILD_FLAGS_Darwin := --linkopt=-L/opt/local/lib \
--linkopt=-lusb-1.0

ifeq ($(COMPILATION_MODE), opt)
BAZEL_BUILD_FLAGS_Linux += --linkopt=-Wl,--strip-all
endif
BAZEL_BUILD_FLAGS := --compilation_mode=$(COMPILATION_MODE) \
--cpu=$(CPU)

ifeq ($(CPU),aarch64)
BAZEL_BUILD_FLAGS_Linux += --copt=-ffp-contract=off
BAZEL_BUILD_FLAGS += --copt=-ffp-contract=off
else ifeq ($(CPU),armv7a)
BAZEL_BUILD_FLAGS_Linux += --copt=-ffp-contract=off
BAZEL_BUILD_FLAGS += --copt=-ffp-contract=off
endif

BAZEL_QUERY_FLAGS := --experimental_repo_remote_exec

BAZEL_BUILD_FLAGS := $(COMMON_BAZEL_BUILD_FLAGS) \
$(BAZEL_BUILD_FLAGS_$(OS))

# $(1): pattern, $(2) destination directory
define copy_out_files
pushd $(BAZEL_OUT_DIR); \
Expand All @@ -80,10 +56,10 @@ done; \
popd
endef

EXAMPLES_OUT_DIR := $(MAKEFILE_DIR)/out/$(CPU)/examples
TOOLS_OUT_DIR := $(MAKEFILE_DIR)/out/$(CPU)/tools
TESTS_OUT_DIR := $(MAKEFILE_DIR)/out/$(CPU)/tests
BENCHMARKS_OUT_DIR := $(MAKEFILE_DIR)/out/$(CPU)/benchmarks
EXAMPLES_OUT_DIR := $(MAKEFILE_DIR)/out/$(CPU)/examples
TOOLS_OUT_DIR := $(MAKEFILE_DIR)/out/$(CPU)/tools
TESTS_OUT_DIR := $(MAKEFILE_DIR)/out/$(CPU)/tests
BENCHMARKS_OUT_DIR := $(MAKEFILE_DIR)/out/$(CPU)/benchmarks

.PHONY: all \
tests \
Expand All @@ -96,25 +72,27 @@ BENCHMARKS_OUT_DIR := $(MAKEFILE_DIR)/out/$(CPU)/benchmarks
all: tests benchmarks tools examples

tests:
bazel build $(BAZEL_BUILD_FLAGS) $(shell bazel query $(BAZEL_QUERY_FLAGS) 'kind(cc_.*test, //coral/...)')
bazel build $(BAZEL_BUILD_FLAGS) $(shell bazel query 'kind(cc_.*test, //coral/...)' | $(TEST_FILTER))
$(call copy_out_files,"*_test",$(TESTS_OUT_DIR))

benchmarks:
bazel build $(BAZEL_BUILD_FLAGS) $(shell bazel query $(BAZEL_QUERY_FLAGS) 'kind(cc_binary, //coral/...)' | grep benchmark)
bazel build $(BAZEL_BUILD_FLAGS) $(shell bazel query 'kind(cc_binary, //coral/...)' | grep benchmark)
$(call copy_out_files,"*_benchmark",$(BENCHMARKS_OUT_DIR))

tools:
bazel build $(BAZEL_BUILD_FLAGS) //coral/tools:join_tflite_models \
bazel build $(BAZEL_BUILD_FLAGS) //coral/tools:append_recurrent_links \
//coral/tools:join_tflite_models \
//coral/tools:multiple_tpus_performance_analysis \
//coral/tools:model_pipelining_performance_analysis \
//coral/tools/partitioner:profiling_partitioner
//coral/tools/partitioner:partition_with_profiling
mkdir -p $(TOOLS_OUT_DIR)
cp -f $(BAZEL_OUT_DIR)/coral/tools/join_tflite_models \
cp -f $(BAZEL_OUT_DIR)/coral/tools/append_recurrent_links \
$(BAZEL_OUT_DIR)/coral/tools/join_tflite_models \
$(BAZEL_OUT_DIR)/coral/tools/multiple_tpus_performance_analysis \
$(BAZEL_OUT_DIR)/coral/tools/model_pipelining_performance_analysis \
$(TOOLS_OUT_DIR)
mkdir -p $(TOOLS_OUT_DIR)/partitioner
cp -f $(BAZEL_OUT_DIR)/coral/tools/partitioner/profiling_partitioner \
cp -f $(BAZEL_OUT_DIR)/coral/tools/partitioner/partition_with_profiling \
$(TOOLS_OUT_DIR)/partitioner

examples:
Expand Down Expand Up @@ -143,14 +121,10 @@ DOCKER_TAG_BASE := coral-edgetpu
include $(MAKEFILE_DIR)/docker/docker.mk

help:
@echo "make all - Build all C++ code"
@echo "make tests - Build all C++ tests"
@echo "make benchmarks - Build all C++ benchmarks"
@echo "make tools - Build all C++ tools"
@echo "make examples - Build all C++ examples"
@echo "make clean - Remove generated files"
@echo "make help - Print help message"

# Debugging util, print variable names. For example, `make print-ROOT_DIR`.
print-%:
@echo $* = $($*)
@echo "make all - Build all C++ code"
@echo "make tests - Build all C++ tests"
@echo "make benchmarks - Build all C++ benchmarks"
@echo "make tools - Build all C++ tools"
@echo "make examples - Build all C++ examples"
@echo "make clean - Remove generated files"
@echo "make help - Print help message"
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ For developer documentation, see our guide to [Run inference on the Edge TPU
with C++](https://coral.ai/docs/edgetpu/tflite-cpp/) and check out the
[libcoral API reference](https://coral.ai/docs/reference/cpp/).


## Compilation

Be sure to clone this repo with submodules:
Expand Down
34 changes: 14 additions & 20 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,29 @@ workspace(name = "libcoral")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

TENSORFLOW_COMMIT = "48c3bae94a8b324525b45f157d638dfd4e8c3be1"
# Command to calculate: curl -L <FILE-URL> | sha256sum | awk '{print $1}'
TENSORFLOW_SHA256 = "363420a67b4cfa271cd21e5c8fac0d7d91b18b02180671c3f943c887122499d8"

# These values come from the Tensorflow workspace. If the TF commit is updated,
# these should be updated to match.
IO_BAZEL_RULES_CLOSURE_COMMIT = "308b05b2419edb5c8ee0471b67a40403df940149"
IO_BAZEL_RULES_CLOSURE_SHA256 = "5b00383d08dd71f28503736db0500b6fb4dda47489ff5fc6bed42557c07c6ba9"

CORAL_CROSSTOOL_COMMIT = "142e930ac6bf1295ff3ba7ba2b5b6324dfb42839"
CORAL_CROSSTOOL_SHA256 = "088ef98b19a45d7224be13636487e3af57b1564880b67df7be8b3b7eee4a1bfc"

# Configure libedgetpu and downstream libraries (TF and Crosstool).
new_local_repository(
local_repository(
name = "libedgetpu",
path = "libedgetpu",
build_file = "libedgetpu/BUILD"
)

load("@libedgetpu//:workspace.bzl", "libedgetpu_dependencies")
libedgetpu_dependencies(TENSORFLOW_COMMIT, TENSORFLOW_SHA256,
IO_BAZEL_RULES_CLOSURE_COMMIT,IO_BAZEL_RULES_CLOSURE_SHA256,
CORAL_CROSSTOOL_COMMIT,CORAL_CROSSTOOL_SHA256)
libedgetpu_dependencies()

load("@org_tensorflow//tensorflow:workspace3.bzl", "tf_workspace3")
tf_workspace3()

load("@org_tensorflow//tensorflow:workspace2.bzl", "tf_workspace2")
tf_workspace2()

load("@org_tensorflow//tensorflow:workspace1.bzl", "tf_workspace1")
tf_workspace1()

load("@org_tensorflow//tensorflow:workspace.bzl", "tf_workspace")
tf_workspace(tf_repo_name = "org_tensorflow")
load("@org_tensorflow//tensorflow:workspace0.bzl", "tf_workspace0")
tf_workspace0()

load("@coral_crosstool//:configure.bzl", "cc_crosstool")
cc_crosstool(name = "crosstool")
cc_crosstool(name = "crosstool", cpp_version = "c++14")

# External Dependencies
http_archive(
Expand Down
Loading

0 comments on commit 6589d0b

Please sign in to comment.