Skip to content

Commit 642a289

Browse files
Open source release of Edge TPU runtime library
1 parent 5414e71 commit 642a289

File tree

336 files changed

+47051
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

336 files changed

+47051
-2
lines changed

BUILD

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Copyright 2019 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Description:
16+
# DarwiNN Runtime Libaries.
17+
18+
package(default_visibility = ["//visibility:public"])
19+
20+
# All Google Owned Code except :
21+
# - certain files in port/default/ that are under Apache 2.0 license.
22+
licenses(["notice"])
23+
24+
exports_files([
25+
"LICENSE",
26+
])
27+
28+
# If --define darwinn_portable=1, compile without google3 deps.
29+
config_setting(
30+
name = "darwinn_portable",
31+
values = {
32+
"define": "darwinn_portable=1",
33+
},
34+
)
35+
36+
# If --define darwinn_portable=1 AND this is an otherwise non-portable config.
37+
config_setting(
38+
name = "darwinn_portable_with_non_portable_os",
39+
flag_values = {"//tools/cpp:cc_target_os": "linux-google"},
40+
values = {"define": "darwinn_portable=1"},
41+
)
42+
43+
# If --define darwinn_firmware=1, compile with minimal deps.
44+
config_setting(
45+
name = "darwinn_firmware",
46+
values = {
47+
"define": "darwinn_firmware=1",
48+
},
49+
)
50+
51+
config_setting(
52+
name = "windows",
53+
values = {
54+
"cpu": "x64_windows",
55+
},
56+
)
57+
58+
config_setting(
59+
name = "darwin",
60+
values = {
61+
"cpu": "darwin",
62+
},
63+
)

CONTRIBUTING.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# How to Contribute
2+
3+
This project is not currently accepting contributions.
4+
5+
## Contributor License Agreement
6+
7+
Contributions to this project must be accompanied by a Contributor License
8+
Agreement (CLA). You (or your employer) retain the copyright to your
9+
contribution; this simply gives us permission to use and redistribute your
10+
contributions as part of the project. Head over to
11+
<https://cla.developers.google.com/> to see your current agreements on file or
12+
to sign a new one.
13+
14+
You generally only need to submit a CLA once, so if you've already submitted one
15+
(even if it was for a different project), you probably don't need to do it
16+
again.
17+
18+
## Code reviews
19+
20+
All submissions, including submissions by project members, require review. We
21+
use GitHub pull requests for this purpose. Consult
22+
[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
23+
information on using pull requests.
24+
25+
## Community Guidelines
26+
27+
This project follows
28+
[Google's Open Source Community Guidelines](https://opensource.google/conduct/).

Makefile

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Copyright 2019 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
SHELL := /bin/bash
15+
MAKEFILE_DIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
16+
OUT_DIR := $(MAKEFILE_DIR)/out
17+
OS := $(shell uname -s)
18+
19+
ifeq ($(OS),Linux)
20+
CPU ?= k8
21+
else ifeq ($(OS),Darwin)
22+
CPU ?= darwin
23+
else
24+
$(error $(OS) is not supported)
25+
endif
26+
27+
ifeq ($(filter $(CPU),k8 armv6 armv7a aarch64 darwin),)
28+
$(error CPU must be k8, armv7a, armv6, aarch64, or darwin)
29+
endif
30+
31+
COMPILATION_MODE ?= opt
32+
ifeq ($(filter $(COMPILATION_MODE),opt dbg),)
33+
$(error COMPILATION_MODE must be opt or dbg)
34+
endif
35+
36+
BAZEL_OUT_DIR := $(MAKEFILE_DIR)/bazel-out/$(CPU)-$(COMPILATION_MODE)/bin
37+
38+
# Linux-specific parameters
39+
BAZEL_BUILD_TARGET_Linux := //tflite/public:libedgetpu_direct_all.so
40+
# --experimental_repo_remote_exec for remotable parameter used in
41+
# --`repository_rule` from TF.
42+
BAZEL_BUILD_FLAGS_Linux := --crosstool_top=@crosstool//:toolchains \
43+
--compiler=gcc \
44+
--linkopt=-l:libusb-1.0.so \
45+
--experimental_repo_remote_exec
46+
BAZEL_BUILD_OUTPUT_FILE_Linux := libedgetpu.so.1.0
47+
BAZEL_BUILD_OUTPUT_SYMLINK_Linux := libedgetpu.so.1
48+
49+
ifeq ($(COMPILATION_MODE), opt)
50+
BAZEL_BUILD_FLAGS_Linux += --linkopt=-Wl,--strip-all
51+
endif
52+
ifeq ($(CPU), armv6)
53+
BAZEL_BUILD_FLAGS_Linux += --linkopt=-L/usr/lib/arm-linux-gnueabihf/
54+
endif
55+
56+
# Darwin-specific parameters
57+
BAZEL_BUILD_TARGET_Darwin := //tflite/public:libedgetpu_direct_usb.dylib
58+
BAZEL_BUILD_FLAGS_Darwin := --linkopt=-L/opt/local/lib \
59+
--linkopt=-lusb-1.0 \
60+
--copt=-fvisibility=hidden
61+
BAZEL_BUILD_OUTPUT_FILE_Darwin := libedgetpu.1.0.dylib
62+
BAZEL_BUILD_OUTPUT_SYMLINK_Darwin := libedgetpu.1.dylib
63+
64+
# Common parameters
65+
BAZEL_BUILD_FLAGS := --sandbox_debug --subcommands \
66+
--compilation_mode=$(COMPILATION_MODE) \
67+
--define darwinn_portable=1 \
68+
--copt=-DSTRIP_LOG=1 \
69+
--copt=-DEDGETPU_EXTERNAL_RELEASE_RUNTIME \
70+
--copt=-fno-rtti \
71+
--copt=-fno-exceptions \
72+
--copt='-D__FILE__=""' \
73+
--cpu=$(CPU)
74+
BAZEL_BUILD_FLAGS += $(BAZEL_BUILD_FLAGS_$(OS))
75+
BAZEL_BUILD_TARGET := $(BAZEL_BUILD_TARGET_$(OS))
76+
BAZEL_BUILD_OUTPUT_FILE := $(BAZEL_BUILD_OUTPUT_FILE_$(OS))
77+
BAZEL_BUILD_OUTPUT_SYMLINK := $(BAZEL_BUILD_OUTPUT_SYMLINK_$(OS))
78+
79+
define copy_out
80+
mkdir -p $(OUT_DIR)/$(1)/$(CPU) && \
81+
cp -f $(BAZEL_OUT_DIR)/tflite/public/*$(suffix $(BAZEL_BUILD_TARGET)) \
82+
$(OUT_DIR)/$(1)/$(CPU)/$(BAZEL_BUILD_OUTPUT_FILE) && \
83+
ln -fs $(BAZEL_BUILD_OUTPUT_FILE) \
84+
$(OUT_DIR)/$(1)/$(CPU)/$(BAZEL_BUILD_OUTPUT_SYMLINK)
85+
endef
86+
87+
ifeq ($(OS),Darwin)
88+
ifeq ($(COMPILATION_MODE),opt)
89+
define strip_out
90+
strip -x -S -o $(OUT_DIR)/$(1)/$(CPU)/$(BAZEL_BUILD_OUTPUT_FILE) \
91+
$(OUT_DIR)/$(1)/$(CPU)/$(BAZEL_BUILD_OUTPUT_FILE)
92+
endef
93+
endif
94+
endif
95+
96+
libedgetpu: libedgetpu-direct libedgetpu-throttled
97+
98+
libedgetpu-direct:
99+
bazel build $(BAZEL_BUILD_FLAGS) $(BAZEL_BUILD_TARGET)
100+
$(call copy_out,direct)
101+
$(call strip_out,direct)
102+
103+
libedgetpu-throttled:
104+
bazel build $(BAZEL_BUILD_FLAGS) --copt=-DTHROTTLE_EDGE_TPU $(BAZEL_BUILD_TARGET)
105+
$(call copy_out,throttled)
106+
$(call strip_out,throttled)
107+
108+
clean:
109+
rm -rf $(OUT_DIR)
110+
111+
ifdef DOCKER_MK
112+
DOCKER_WORKSPACE := $(MAKEFILE_DIR)
113+
DOCKER_TAG_BASE=coral-libedgetpu
114+
include $(DOCKER_MK)
115+
endif

README.md

+33-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,33 @@
1-
# libedgetpu
2-
Source code for the userspace level runtime driver for Coral.ai devices.
1+
# Edge TPU runtime library (libedgetpu)
2+
3+
This repo contains the source code for the userspace
4+
level runtime driver for [Coral devices](https://coral.ai/products).
5+
This software is distributed in the binary form at [coral.ai/software](https://coral.ai/software/).
6+
7+
## Building
8+
9+
At present only Bazel build system is supported, but it can be invoked from the Makefile.
10+
11+
## Support
12+
13+
If you have question, comments or requests concerning this library, please
14+
reach out to coral-support@google.com.
15+
16+
## License
17+
18+
[Apache License 2.0](LICENSE)
19+
20+
## Warning
21+
22+
If you're using the Coral USB Accelerator, it may heat up during operation, depending
23+
on the computation workloads and operating frequency. Touching the metal part of the USB
24+
Accelerator after it has been operating for an extended period of time may lead to discomfort
25+
and/or skin burns. As such, if you enable the Edge TPU runtime using the maximum operating
26+
frequency, the USB Accelerator should be operated at an ambient temperature of 25°C or less.
27+
Alternatively, if you enable the Edge TPU runtime using the reduced operating frequency, then
28+
the device is intended to safely operate at an ambient temperature of 35°C or less.
29+
30+
Google does not accept any responsibility for any loss or damage if the device
31+
is operated outside of the recommended ambient temperature range.
32+
33+
Note: This issue affects only USB-based Coral devices, and is irrelevant for PCIe devices.

WORKSPACE

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Copyright 2019 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
workspace(name = "libedgetpu")
15+
16+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
17+
18+
http_archive(
19+
name = "io_bazel_rules_closure",
20+
sha256 = "5b00383d08dd71f28503736db0500b6fb4dda47489ff5fc6bed42557c07c6ba9",
21+
strip_prefix = "rules_closure-308b05b2419edb5c8ee0471b67a40403df940149",
22+
urls = [
23+
"http://mirror.tensorflow.org/github.com/bazelbuild/rules_closure/archive/308b05b2419edb5c8ee0471b67a40403df940149.tar.gz",
24+
"https://github.com/bazelbuild/rules_closure/archive/308b05b2419edb5c8ee0471b67a40403df940149.tar.gz", # 2019-06-13
25+
],
26+
)
27+
28+
# Be consistent with tensorflow/WORKSPACE.
29+
http_archive(
30+
name = "bazel_skylib",
31+
sha256 = "1dde365491125a3db70731e25658dfdd3bc5dbdfd11b840b3e987ecf043c7ca0",
32+
urls = ["https://github.com/bazelbuild/bazel-skylib/releases/download/0.9.0/bazel_skylib-0.9.0.tar.gz"],
33+
) # https://github.com/bazelbuild/bazel-skylib/releases
34+
35+
# The TF commit # here must be in sync with that specified under Gob edgetpu
36+
# repo WORKSPACE file.
37+
# TODO: figure out a way to keep single source of truth of the
38+
# TF commit # used.
39+
TENSORFLOW_COMMIT = "f394a768719a55b5c351ed1ecab2ec6f16f99dd4";
40+
# Command to calculate: curl -OL <FILE-URL> | sha256sum | awk '{print $1}'
41+
TENSORFLOW_SHA256 = "cb286abee7ee9cf5c8701d85fcc88f0fd59e72492ec4f254156de486e3e905c1"
42+
http_archive(
43+
name = "org_tensorflow",
44+
sha256 = TENSORFLOW_SHA256,
45+
strip_prefix = "tensorflow-" + TENSORFLOW_COMMIT,
46+
urls = [
47+
"https://github.com/tensorflow/tensorflow/archive/" + TENSORFLOW_COMMIT + ".tar.gz",
48+
],
49+
)
50+
51+
load("@org_tensorflow//tensorflow:workspace.bzl", "tf_workspace")
52+
tf_workspace(tf_repo_name = "org_tensorflow")
53+
54+
http_archive(
55+
name = "coral_crosstool",
56+
sha256 = "cb31b1417ccdcf7dd9fca5ec63e1571672372c30427730255997a547569d2feb",
57+
strip_prefix = "crosstool-9e00d5be43bf001f883b5700f5d04882fea00229",
58+
urls = [
59+
"https://github.com/google-coral/crosstool/archive/9e00d5be43bf001f883b5700f5d04882fea00229.tar.gz",
60+
],
61+
)
62+
load("@coral_crosstool//:configure.bzl", "cc_crosstool")
63+
cc_crosstool(name = "crosstool")
64+
new_local_repository(
65+
name = "libusb",
66+
path = "/usr/include/",
67+
build_file_content = """
68+
cc_library(
69+
name = "headers",
70+
includes = ["."],
71+
hdrs = ["libusb-1.0/libusb.h"],
72+
visibility = ["//visibility:public"],
73+
)
74+
"""
75+
)

0 commit comments

Comments
 (0)