Skip to content

Commit

Permalink
Open source release of Edge TPU runtime library
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitriykovalev committed Jun 9, 2020
1 parent 5414e71 commit 642a289
Show file tree
Hide file tree
Showing 336 changed files with 47,051 additions and 2 deletions.
63 changes: 63 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Copyright 2019 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.

# Description:
# DarwiNN Runtime Libaries.

package(default_visibility = ["//visibility:public"])

# All Google Owned Code except :
# - certain files in port/default/ that are under Apache 2.0 license.
licenses(["notice"])

exports_files([
"LICENSE",
])

# If --define darwinn_portable=1, compile without google3 deps.
config_setting(
name = "darwinn_portable",
values = {
"define": "darwinn_portable=1",
},
)

# If --define darwinn_portable=1 AND this is an otherwise non-portable config.
config_setting(
name = "darwinn_portable_with_non_portable_os",
flag_values = {"//tools/cpp:cc_target_os": "linux-google"},
values = {"define": "darwinn_portable=1"},
)

# If --define darwinn_firmware=1, compile with minimal deps.
config_setting(
name = "darwinn_firmware",
values = {
"define": "darwinn_firmware=1",
},
)

config_setting(
name = "windows",
values = {
"cpu": "x64_windows",
},
)

config_setting(
name = "darwin",
values = {
"cpu": "darwin",
},
)
28 changes: 28 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# How to Contribute

This project is not currently accepting contributions.

## Contributor License Agreement

Contributions to this project must be accompanied by a Contributor License
Agreement (CLA). You (or your employer) retain the copyright to your
contribution; this simply gives us permission to use and redistribute your
contributions as part of the project. Head over to
<https://cla.developers.google.com/> to see your current agreements on file or
to sign a new one.

You generally only need to submit a CLA once, so if you've already submitted one
(even if it was for a different project), you probably don't need to do it
again.

## Code reviews

All submissions, including submissions by project members, require review. We
use GitHub pull requests for this purpose. Consult
[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
information on using pull requests.

## Community Guidelines

This project follows
[Google's Open Source Community Guidelines](https://opensource.google/conduct/).
115 changes: 115 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# Copyright 2019 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
#
# https://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.
SHELL := /bin/bash
MAKEFILE_DIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
OUT_DIR := $(MAKEFILE_DIR)/out
OS := $(shell uname -s)

ifeq ($(OS),Linux)
CPU ?= k8
else ifeq ($(OS),Darwin)
CPU ?= darwin
else
$(error $(OS) is not supported)
endif

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

COMPILATION_MODE ?= opt
ifeq ($(filter $(COMPILATION_MODE),opt dbg),)
$(error COMPILATION_MODE must be opt or dbg)
endif

BAZEL_OUT_DIR := $(MAKEFILE_DIR)/bazel-out/$(CPU)-$(COMPILATION_MODE)/bin

# Linux-specific parameters
BAZEL_BUILD_TARGET_Linux := //tflite/public:libedgetpu_direct_all.so
# --experimental_repo_remote_exec for remotable parameter used in
# --`repository_rule` from TF.
BAZEL_BUILD_FLAGS_Linux := --crosstool_top=@crosstool//:toolchains \
--compiler=gcc \
--linkopt=-l:libusb-1.0.so \
--experimental_repo_remote_exec
BAZEL_BUILD_OUTPUT_FILE_Linux := libedgetpu.so.1.0
BAZEL_BUILD_OUTPUT_SYMLINK_Linux := libedgetpu.so.1

ifeq ($(COMPILATION_MODE), opt)
BAZEL_BUILD_FLAGS_Linux += --linkopt=-Wl,--strip-all
endif
ifeq ($(CPU), armv6)
BAZEL_BUILD_FLAGS_Linux += --linkopt=-L/usr/lib/arm-linux-gnueabihf/
endif

# Darwin-specific parameters
BAZEL_BUILD_TARGET_Darwin := //tflite/public:libedgetpu_direct_usb.dylib
BAZEL_BUILD_FLAGS_Darwin := --linkopt=-L/opt/local/lib \
--linkopt=-lusb-1.0 \
--copt=-fvisibility=hidden
BAZEL_BUILD_OUTPUT_FILE_Darwin := libedgetpu.1.0.dylib
BAZEL_BUILD_OUTPUT_SYMLINK_Darwin := libedgetpu.1.dylib

# Common parameters
BAZEL_BUILD_FLAGS := --sandbox_debug --subcommands \
--compilation_mode=$(COMPILATION_MODE) \
--define darwinn_portable=1 \
--copt=-DSTRIP_LOG=1 \
--copt=-DEDGETPU_EXTERNAL_RELEASE_RUNTIME \
--copt=-fno-rtti \
--copt=-fno-exceptions \
--copt='-D__FILE__=""' \
--cpu=$(CPU)
BAZEL_BUILD_FLAGS += $(BAZEL_BUILD_FLAGS_$(OS))
BAZEL_BUILD_TARGET := $(BAZEL_BUILD_TARGET_$(OS))
BAZEL_BUILD_OUTPUT_FILE := $(BAZEL_BUILD_OUTPUT_FILE_$(OS))
BAZEL_BUILD_OUTPUT_SYMLINK := $(BAZEL_BUILD_OUTPUT_SYMLINK_$(OS))

define copy_out
mkdir -p $(OUT_DIR)/$(1)/$(CPU) && \
cp -f $(BAZEL_OUT_DIR)/tflite/public/*$(suffix $(BAZEL_BUILD_TARGET)) \
$(OUT_DIR)/$(1)/$(CPU)/$(BAZEL_BUILD_OUTPUT_FILE) && \
ln -fs $(BAZEL_BUILD_OUTPUT_FILE) \
$(OUT_DIR)/$(1)/$(CPU)/$(BAZEL_BUILD_OUTPUT_SYMLINK)
endef

ifeq ($(OS),Darwin)
ifeq ($(COMPILATION_MODE),opt)
define strip_out
strip -x -S -o $(OUT_DIR)/$(1)/$(CPU)/$(BAZEL_BUILD_OUTPUT_FILE) \
$(OUT_DIR)/$(1)/$(CPU)/$(BAZEL_BUILD_OUTPUT_FILE)
endef
endif
endif

libedgetpu: libedgetpu-direct libedgetpu-throttled

libedgetpu-direct:
bazel build $(BAZEL_BUILD_FLAGS) $(BAZEL_BUILD_TARGET)
$(call copy_out,direct)
$(call strip_out,direct)

libedgetpu-throttled:
bazel build $(BAZEL_BUILD_FLAGS) --copt=-DTHROTTLE_EDGE_TPU $(BAZEL_BUILD_TARGET)
$(call copy_out,throttled)
$(call strip_out,throttled)

clean:
rm -rf $(OUT_DIR)

ifdef DOCKER_MK
DOCKER_WORKSPACE := $(MAKEFILE_DIR)
DOCKER_TAG_BASE=coral-libedgetpu
include $(DOCKER_MK)
endif
35 changes: 33 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,33 @@
# libedgetpu
Source code for the userspace level runtime driver for Coral.ai devices.
# Edge TPU runtime library (libedgetpu)

This repo contains the source code for the userspace
level runtime driver for [Coral devices](https://coral.ai/products).
This software is distributed in the binary form at [coral.ai/software](https://coral.ai/software/).

## Building

At present only Bazel build system is supported, but it can be invoked from the Makefile.

## Support

If you have question, comments or requests concerning this library, please
reach out to [email protected].

## License

[Apache License 2.0](LICENSE)

## Warning

If you're using the Coral USB Accelerator, it may heat up during operation, depending
on the computation workloads and operating frequency. Touching the metal part of the USB
Accelerator after it has been operating for an extended period of time may lead to discomfort
and/or skin burns. As such, if you enable the Edge TPU runtime using the maximum operating
frequency, the USB Accelerator should be operated at an ambient temperature of 25°C or less.
Alternatively, if you enable the Edge TPU runtime using the reduced operating frequency, then
the device is intended to safely operate at an ambient temperature of 35°C or less.

Google does not accept any responsibility for any loss or damage if the device
is operated outside of the recommended ambient temperature range.

Note: This issue affects only USB-based Coral devices, and is irrelevant for PCIe devices.
75 changes: 75 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Copyright 2019 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
#
# https://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.
workspace(name = "libedgetpu")

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

http_archive(
name = "io_bazel_rules_closure",
sha256 = "5b00383d08dd71f28503736db0500b6fb4dda47489ff5fc6bed42557c07c6ba9",
strip_prefix = "rules_closure-308b05b2419edb5c8ee0471b67a40403df940149",
urls = [
"http://mirror.tensorflow.org/github.com/bazelbuild/rules_closure/archive/308b05b2419edb5c8ee0471b67a40403df940149.tar.gz",
"https://github.com/bazelbuild/rules_closure/archive/308b05b2419edb5c8ee0471b67a40403df940149.tar.gz", # 2019-06-13
],
)

# Be consistent with tensorflow/WORKSPACE.
http_archive(
name = "bazel_skylib",
sha256 = "1dde365491125a3db70731e25658dfdd3bc5dbdfd11b840b3e987ecf043c7ca0",
urls = ["https://github.com/bazelbuild/bazel-skylib/releases/download/0.9.0/bazel_skylib-0.9.0.tar.gz"],
) # https://github.com/bazelbuild/bazel-skylib/releases

# The TF commit # here must be in sync with that specified under Gob edgetpu
# repo WORKSPACE file.
# TODO: figure out a way to keep single source of truth of the
# TF commit # used.
TENSORFLOW_COMMIT = "f394a768719a55b5c351ed1ecab2ec6f16f99dd4";
# Command to calculate: curl -OL <FILE-URL> | sha256sum | awk '{print $1}'
TENSORFLOW_SHA256 = "cb286abee7ee9cf5c8701d85fcc88f0fd59e72492ec4f254156de486e3e905c1"
http_archive(
name = "org_tensorflow",
sha256 = TENSORFLOW_SHA256,
strip_prefix = "tensorflow-" + TENSORFLOW_COMMIT,
urls = [
"https://github.com/tensorflow/tensorflow/archive/" + TENSORFLOW_COMMIT + ".tar.gz",
],
)

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

http_archive(
name = "coral_crosstool",
sha256 = "cb31b1417ccdcf7dd9fca5ec63e1571672372c30427730255997a547569d2feb",
strip_prefix = "crosstool-9e00d5be43bf001f883b5700f5d04882fea00229",
urls = [
"https://github.com/google-coral/crosstool/archive/9e00d5be43bf001f883b5700f5d04882fea00229.tar.gz",
],
)
load("@coral_crosstool//:configure.bzl", "cc_crosstool")
cc_crosstool(name = "crosstool")
new_local_repository(
name = "libusb",
path = "/usr/include/",
build_file_content = """
cc_library(
name = "headers",
includes = ["."],
hdrs = ["libusb-1.0/libusb.h"],
visibility = ["//visibility:public"],
)
"""
)
Loading

0 comments on commit 642a289

Please sign in to comment.