From dccf0a34f6015b8b0026a6b32c0e4a5613fcfe04 Mon Sep 17 00:00:00 2001 From: Zach Date: Fri, 19 Jun 2020 19:58:00 -0400 Subject: [PATCH] Rebuild (#24) * Reworked build process to be easier and more flexible * arm32 and arm64 builds renamed * arm32 and arm64 docker images are all built on x86 via cross-compiling --- .dockerignore | 3 +- Dockerfile | 135 +- Dockerfile.base.amd64 => Dockerfile.amd64 | 74 +- Dockerfile.rpi => Dockerfile.arm32 | 74 +- Dockerfile.base.aarch64 => Dockerfile.arm64 | 98 +- Dockerfile.base.cuda | 1 - Dockerfile.base.rpi | 137 -- Dockerfile.builder | 109 +- Dockerfile.base.noavx => Dockerfile.noavx | 74 +- Makefile | 35 +- README.md | 98 +- builder.sh | 2 + config.arm.yaml | 18 + config.yaml | 9 +- go.mod | 2 +- odrpc/rpc.proto | 12 + tftoolchain.sh | 1290 ++++--------------- 17 files changed, 830 insertions(+), 1341 deletions(-) rename Dockerfile.base.amd64 => Dockerfile.amd64 (58%) rename Dockerfile.rpi => Dockerfile.arm32 (74%) rename Dockerfile.base.aarch64 => Dockerfile.arm64 (62%) delete mode 100644 Dockerfile.base.rpi rename Dockerfile.base.noavx => Dockerfile.noavx (57%) create mode 100644 builder.sh create mode 100644 config.arm.yaml diff --git a/.dockerignore b/.dockerignore index ea2c18a..341f866 100644 --- a/.dockerignore +++ b/.dockerignore @@ -12,4 +12,5 @@ doods private models/** Dockerfile.*.* - +Dockerfile.* +README.md diff --git a/Dockerfile b/Dockerfile index c2ac7b2..7c241b2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,150 @@ -ARG BUILDER_TAG="latest" -FROM registry.prozach.org/doods-builder:$BUILDER_TAG as builder +FROM ubuntu:18.04 as base + +# Install reqs with cross compile support +RUN apt-get update && apt-get install -y --no-install-recommends \ + pkg-config zip zlib1g-dev unzip wget bash-completion git curl \ + build-essential patch g++ python python-future python-numpy python-six python3 \ + cmake ca-certificates \ + libc6-dev libstdc++6 libusb-1.0-0 + +# Install protoc +RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v3.12.3/protoc-3.12.3-linux-x86_64.zip && \ + unzip protoc-3.12.3-linux-x86_64.zip -d /usr/local && \ + rm /usr/local/readme.txt && \ + rm protoc-3.12.3-linux-x86_64.zip + +# Version Configuration +ARG BAZEL_VERSION="0.26.1" +ARG TF_VERSION="v1.15.3" +ARG OPENCV_VERSION="4.3.0" +ARG GO_VERSION="1.14.3" + +# Install bazel +ENV BAZEL_VERSION $BAZEL_VERSION +RUN wget https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel_${BAZEL_VERSION}-linux-x86_64.deb && \ + dpkg -i bazel_${BAZEL_VERSION}-linux-x86_64.deb && \ + rm bazel_${BAZEL_VERSION}-linux-x86_64.deb + +# Download tensorflow sources +ENV TF_VERSION $TF_VERSION +RUN cd /opt && git clone https://github.com/tensorflow/tensorflow.git --branch $TF_VERSION --single-branch + +# Configure tensorflow +ENV TF_NEED_GDR=0 TF_NEED_AWS=0 TF_NEED_GCP=0 TF_NEED_CUDA=0 TF_NEED_HDFS=0 TF_NEED_OPENCL_SYCL=0 TF_NEED_VERBS=0 TF_NEED_MPI=0 TF_NEED_MKL=0 TF_NEED_JEMALLOC=1 TF_ENABLE_XLA=0 TF_NEED_S3=0 TF_NEED_KAFKA=0 TF_NEED_IGNITE=0 TF_NEED_ROCM=0 +RUN cd /opt/tensorflow && yes '' | ./configure + +# Tensorflow build flags for rpi +ENV BAZEL_COPT_FLAGS="--local_resources 16000,16,1 -c opt --config monolithic --copt=-march=native --copt=-O3 --copt=-fomit-frame-pointer --incompatible_no_support_tools_in_action_inputs=false --config=noaws --config=nohdfs" +ENV BAZEL_EXTRA_FLAGS="" + +# Compile and build tensorflow lite +RUN cd /opt/tensorflow && \ + bazel build -c opt $BAZEL_COPT_FLAGS --verbose_failures $BAZEL_EXTRA_FLAGS //tensorflow/lite:libtensorflowlite.so && \ + install bazel-bin/tensorflow/lite/libtensorflowlite.so /usr/local/lib/libtensorflowlite.so && \ + bazel build -c opt $BAZEL_COPT_FLAGS --verbose_failures $BAZEL_EXTRA_FLAGS //tensorflow/lite/experimental/c:libtensorflowlite_c.so && \ + install bazel-bin/tensorflow/lite/experimental/c/libtensorflowlite_c.so /usr/local/lib/libtensorflowlite_c.so && \ + mkdir -p /usr/local/include/flatbuffers && cp bazel-tensorflow/external/flatbuffers/include/flatbuffers/* /usr/local/include/flatbuffers + +# Compile and install tensorflow shared library +RUN cd /opt/tensorflow && \ + bazel build -c opt $BAZEL_COPT_FLAGS --verbose_failures $BAZEL_EXTRA_FLAGS //tensorflow:libtensorflow.so && \ + install bazel-bin/tensorflow/libtensorflow.so /usr/local/lib/libtensorflow.so && \ + ln -rs /usr/local/lib/libtensorflow.so /usr/local/lib/libtensorflow.so.1 + +# cleanup so the cache directory isn't huge +RUN cd /opt/tensorflow && \ + bazel clean && rm -Rf /root/.cache + +# Install GOCV +ENV OPENCV_VERSION $OPENCV_VERSION +RUN cd /tmp && \ + curl -Lo opencv.zip https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip && \ + unzip -q opencv.zip && \ + curl -Lo opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip && \ + unzip -q opencv_contrib.zip && \ + rm opencv.zip opencv_contrib.zip && \ + cd opencv-${OPENCV_VERSION} && \ + mkdir build && cd build && \ + cmake -D CMAKE_BUILD_TYPE=RELEASE \ + -D CMAKE_INSTALL_PREFIX=/usr/local \ + -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-${OPENCV_VERSION}/modules \ + -D WITH_JASPER=OFF \ + -D WITH_QT=OFF \ + -D WITH_GTK=OFF \ + -D BUILD_DOCS=OFF \ + -D BUILD_EXAMPLES=OFF \ + -D BUILD_TESTS=OFF \ + -D BUILD_PERF_TESTS=OFF \ + -D BUILD_opencv_java=NO \ + -D BUILD_opencv_python=NO \ + -D BUILD_opencv_python2=NO \ + -D BUILD_opencv_python3=NO \ + -D OPENCV_GENERATE_PKGCONFIG=ON .. && \ + make -j $(nproc --all) && \ + make preinstall && make install && \ + cd /tmp && rm -rf opencv* + +# Download the edgetpu library and install it +RUN cd /tmp && git clone https://github.com/google-coral/edgetpu.git && \ + install edgetpu/libedgetpu/throttled/k8/libedgetpu.so.1.0 /usr/local/lib/libedgetpu.so.1.0 && \ + ln -rs /usr/local/lib/libedgetpu.so.1.0 /usr/local/lib/libedgetpu.so.1 && \ + ln -rs /usr/local/lib/libedgetpu.so.1.0 /usr/local/lib/libedgetpu.so && \ + mkdir -p /usr/local/include/libedgetpu && \ + install edgetpu/libedgetpu/edgetpu.h /usr/local/include/libedgetpu/edgetpu.h && \ + install edgetpu/libedgetpu/edgetpu_c.h /usr/local/include/libedgetpu/edgetpu_c.h && \ + rm -Rf edgetpu + +# Configure the Go version to be used +ENV GO_ARCH "amd64" +ENV GOARCH=amd64 + +# Install Go +ENV GO_VERSION $GO_VERSION +RUN curl -kLo go${GO_VERSION}.linux-${GO_ARCH}.tar.gz https://dl.google.com/go/go${GO_VERSION}.linux-${GO_ARCH}.tar.gz && \ + tar -C /usr/local -xzf go${GO_VERSION}.linux-${GO_ARCH}.tar.gz && \ + rm go${GO_VERSION}.linux-${GO_ARCH}.tar.gz + +FROM ubuntu:18.04 as builder + +RUN apt-get update && apt-get install -y --no-install-recommends \ + pkg-config zip zlib1g-dev unzip wget bash-completion git curl \ + build-essential patch g++ python python-future python3 ca-certificates \ + libc6-dev libstdc++6 libusb-1.0-0 + +# Copy all libraries, includes and go +COPY --from=base /usr/local/. /usr/local/. +COPY --from=base /opt/tensorflow /opt/tensorflow + +ENV GOOS=linux +ENV CGO_ENABLED=1 +ENV CGO_CFLAGS=-I/opt/tensorflow +ENV PATH /usr/local/go/bin:/go/bin:${PATH} +ENV GOPATH /go # Create the build directory +RUN mkdir /build WORKDIR /build ADD . . RUN make -FROM debian:buster-slim +FROM ubuntu:18.04 + RUN apt-get update && \ - apt-get install -y --no-install-recommends libusb-1.0 libc++-7-dev wget unzip ca-certificates libdc1394-22 libavcodec58 libavformat58 && \ + apt-get install -y --no-install-recommends libusb-1.0 libc++-7-dev wget unzip ca-certificates libdc1394-22 libavcodec57 libavformat57 && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* RUN mkdir -p /opt/doods WORKDIR /opt/doods COPY --from=builder /usr/local/lib/. /usr/local/lib/. COPY --from=builder /build/doods /opt/doods/doods -ADD config.yaml /opt/doods/config.yaml RUN ldconfig +# Download sample models RUN mkdir models RUN wget https://storage.googleapis.com/download.tensorflow.org/models/tflite/coco_ssd_mobilenet_v1_1.0_quant_2018_06_29.zip && unzip coco_ssd_mobilenet_v1_1.0_quant_2018_06_29.zip && rm coco_ssd_mobilenet_v1_1.0_quant_2018_06_29.zip && mv detect.tflite models/coco_ssd_mobilenet_v1_1.0_quant.tflite && rm labelmap.txt RUN wget https://dl.google.com/coral/canned_models/coco_labels.txt && mv coco_labels.txt models/coco_labels0.txt +RUN wget http://download.tensorflow.org/models/object_detection/faster_rcnn_inception_v2_coco_2018_01_28.tar.gz && tar -zxvf faster_rcnn_inception_v2_coco_2018_01_28.tar.gz faster_rcnn_inception_v2_coco_2018_01_28/frozen_inference_graph.pb --strip=1 && mv frozen_inference_graph.pb models/faster_rcnn_inception_v2_coco_2018_01_28.pb && rm faster_rcnn_inception_v2_coco_2018_01_28.tar.gz +RUN wget https://github.com/raw/amikelive/coco-labels/master/coco-labels-2014_2017.txt && mv coco-labels-2014_2017.txt models/coco_labels1.txt +ADD config.yaml config.yaml CMD ["/opt/doods/doods", "-c", "/opt/doods/config.yaml", "api"] diff --git a/Dockerfile.base.amd64 b/Dockerfile.amd64 similarity index 58% rename from Dockerfile.base.amd64 rename to Dockerfile.amd64 index 700646c..f1ea546 100644 --- a/Dockerfile.base.amd64 +++ b/Dockerfile.amd64 @@ -1,4 +1,4 @@ -FROM debian:buster as builder +FROM ubuntu:18.04 as base # Install reqs with cross compile support RUN apt-get update && apt-get install -y --no-install-recommends \ @@ -8,18 +8,24 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ libc6-dev libstdc++6 libusb-1.0-0 # Install protoc -RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v3.9.1/protoc-3.9.1-linux-x86_64.zip && \ - unzip protoc-3.9.1-linux-x86_64.zip -d /usr/local && \ +RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v3.12.3/protoc-3.12.3-linux-x86_64.zip && \ + unzip protoc-3.12.3-linux-x86_64.zip -d /usr/local && \ rm /usr/local/readme.txt && \ - rm protoc-3.9.1-linux-x86_64.zip + rm protoc-3.12.3-linux-x86_64.zip + +# Version Configuration +ARG BAZEL_VERSION="0.26.1" +ARG TF_VERSION="v1.15.3" +ARG OPENCV_VERSION="4.3.0" +ARG GO_VERSION="1.14.3" # Install bazel -RUN wget https://github.com/bazelbuild/bazel/releases/download/0.27.1/bazel_0.27.1-linux-x86_64.deb && \ - dpkg -i bazel_0.27.1-linux-x86_64.deb && \ - rm bazel_0.27.1-linux-x86_64.deb +ENV BAZEL_VERSION $BAZEL_VERSION +RUN wget https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel_${BAZEL_VERSION}-linux-x86_64.deb && \ + dpkg -i bazel_${BAZEL_VERSION}-linux-x86_64.deb && \ + rm bazel_${BAZEL_VERSION}-linux-x86_64.deb # Download tensorflow sources -ARG TF_VERSION="v2.1.0-rc1" ENV TF_VERSION $TF_VERSION RUN cd /opt && git clone https://github.com/tensorflow/tensorflow.git --branch $TF_VERSION --single-branch @@ -50,7 +56,6 @@ RUN cd /opt/tensorflow && \ bazel clean && rm -Rf /root/.cache # Install GOCV -ARG OPENCV_VERSION="4.1.2" ENV OPENCV_VERSION $OPENCV_VERSION RUN cd /tmp && \ curl -Lo opencv.zip https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip && \ @@ -92,3 +97,54 @@ RUN cd /tmp && git clone https://github.com/google-coral/edgetpu.git && \ # Configure the Go version to be used ENV GO_ARCH "amd64" ENV GOARCH=amd64 + +# Install Go +ENV GO_VERSION $GO_VERSION +RUN curl -kLo go${GO_VERSION}.linux-${GO_ARCH}.tar.gz https://dl.google.com/go/go${GO_VERSION}.linux-${GO_ARCH}.tar.gz && \ + tar -C /usr/local -xzf go${GO_VERSION}.linux-${GO_ARCH}.tar.gz && \ + rm go${GO_VERSION}.linux-${GO_ARCH}.tar.gz + +FROM ubuntu:18.04 as builder + +RUN apt-get update && apt-get install -y --no-install-recommends \ + pkg-config zip zlib1g-dev unzip wget bash-completion git curl \ + build-essential patch g++ python python-future python3 ca-certificates \ + libc6-dev libstdc++6 libusb-1.0-0 + +# Copy all libraries, includes and go +COPY --from=base /usr/local/. /usr/local/. +COPY --from=base /opt/tensorflow /opt/tensorflow + +ENV GOOS=linux +ENV CGO_ENABLED=1 +ENV CGO_CFLAGS=-I/opt/tensorflow +ENV PATH /usr/local/go/bin:/go/bin:${PATH} +ENV GOPATH /go + +# Create the build directory +RUN mkdir /build +WORKDIR /build +ADD . . +RUN make + +FROM ubuntu:18.04 + +RUN apt-get update && \ + apt-get install -y --no-install-recommends libusb-1.0 libc++-7-dev wget unzip ca-certificates libdc1394-22 libavcodec57 libavformat57 && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* +RUN mkdir -p /opt/doods +WORKDIR /opt/doods +COPY --from=builder /usr/local/lib/. /usr/local/lib/. +COPY --from=builder /build/doods /opt/doods/doods +RUN ldconfig + +# Download sample models +RUN mkdir models +RUN wget https://storage.googleapis.com/download.tensorflow.org/models/tflite/coco_ssd_mobilenet_v1_1.0_quant_2018_06_29.zip && unzip coco_ssd_mobilenet_v1_1.0_quant_2018_06_29.zip && rm coco_ssd_mobilenet_v1_1.0_quant_2018_06_29.zip && mv detect.tflite models/coco_ssd_mobilenet_v1_1.0_quant.tflite && rm labelmap.txt +RUN wget https://dl.google.com/coral/canned_models/coco_labels.txt && mv coco_labels.txt models/coco_labels0.txt +RUN wget http://download.tensorflow.org/models/object_detection/faster_rcnn_inception_v2_coco_2018_01_28.tar.gz && tar -zxvf faster_rcnn_inception_v2_coco_2018_01_28.tar.gz faster_rcnn_inception_v2_coco_2018_01_28/frozen_inference_graph.pb --strip=1 && mv frozen_inference_graph.pb models/faster_rcnn_inception_v2_coco_2018_01_28.pb && rm faster_rcnn_inception_v2_coco_2018_01_28.tar.gz +RUN wget https://github.com/raw/amikelive/coco-labels/master/coco-labels-2014_2017.txt && mv coco-labels-2014_2017.txt models/coco_labels1.txt +ADD config.yaml config.yaml + +CMD ["/opt/doods/doods", "-c", "/opt/doods/config.yaml", "api"] diff --git a/Dockerfile.rpi b/Dockerfile.arm32 similarity index 74% rename from Dockerfile.rpi rename to Dockerfile.arm32 index 59bc94e..cae6ca0 100644 --- a/Dockerfile.rpi +++ b/Dockerfile.arm32 @@ -1,4 +1,4 @@ -FROM debian:buster as builder +FROM debian:buster as base # Install reqs with cross compile support RUN dpkg --add-architecture armhf && \ @@ -9,18 +9,24 @@ RUN dpkg --add-architecture armhf && \ libc6-dev:armhf libstdc++6:armhf libusb-1.0-0:armhf # Install protoc -RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v3.9.1/protoc-3.9.1-linux-x86_64.zip && \ - unzip protoc-3.9.1-linux-x86_64.zip -d /usr/local && \ +RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v3.12.3/protoc-3.12.3-linux-x86_64.zip && \ + unzip protoc-3.12.3-linux-x86_64.zip -d /usr/local && \ rm /usr/local/readme.txt && \ - rm protoc-3.9.1-linux-x86_64.zip + rm protoc-3.12.3-linux-x86_64.zip + +# Version Configuration +ARG BAZEL_VERSION="0.26.1" +ARG TF_VERSION="v1.15.3" +ARG OPENCV_VERSION="4.3.0" +ARG GO_VERSION="1.14.3" # Install bazel -RUN wget https://github.com/bazelbuild/bazel/releases/download/0.24.1/bazel_0.24.1-linux-x86_64.deb && \ - dpkg -i bazel_0.24.1-linux-x86_64.deb && \ - rm bazel_0.24.1-linux-x86_64.deb +ENV BAZEL_VERSION $BAZEL_VERSION +RUN wget https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel_${BAZEL_VERSION}-linux-x86_64.deb && \ + dpkg -i bazel_${BAZEL_VERSION}-linux-x86_64.deb && \ + rm bazel_${BAZEL_VERSION}-linux-x86_64.deb # Download tensorflow sources -ARG TF_VERSION="r1.14" ENV TF_VERSION $TF_VERSION RUN cd /opt && git clone https://github.com/tensorflow/tensorflow.git --branch $TF_VERSION --single-branch @@ -37,8 +43,8 @@ ENV TF_NEED_GDR=0 TF_NEED_AWS=0 TF_NEED_GCP=0 TF_NEED_CUDA=0 TF_NEED_HDFS=0 TF_N RUN cd /opt/tensorflow && yes '' | ./configure # Tensorflow build flags for rpi -ENV BAZEL_COPT_FLAGS="--local_resources 16000,16,1 --copt=-march=armv7-a --copt=-mfpu=neon-vfpv4 --copt=-mfloat-abi=hard --copt=-O3 --copt=-std=c++11 --copt=-DS_IREAD=S_IRUSR --copt=-DS_IWRITE=S_IWUSR --copt=-U__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 --copt=-U__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 --copt=-U__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 --config=monolithic --copt=-funsafe-math-optimizations --copt=-ftree-vectorize --copt=-fomit-frame-pointer --copt=-DRASPBERRY_PI --config=noaws --config=nogcp --config=nohdfs --config=nokafka --config=noignite --define tensorflow_mkldnn_contraction_kernel=0" -ENV BAZEL_EXTRA_FLAGS="--cpu=armeabi --crosstool_top=//tools/local_arm_compiler:toolchain" +ENV BAZEL_COPT_FLAGS="--local_resources 16000,16,1 --copt=-march=armv7-a --copt=-mfpu=neon-vfpv4 --copt=-mfloat-abi=hard --copt=-O3 --copt=-fno-tree-pre --copt=-fpermissive --copt=-std=c++11 --copt=-DS_IREAD=S_IRUSR --copt=-DS_IWRITE=S_IWUSR --copt=-U__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 --copt=-U__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 --copt=-U__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 --config=monolithic --copt=-funsafe-math-optimizations --copt=-ftree-vectorize --copt=-fomit-frame-pointer --copt=-DRASPBERRY_PI --noincompatible_strict_action_env --config=noaws --config=nohdfs --define tensorflow_mkldnn_contraction_kernel=0 --define=raspberry_pi_with_neon=true" +ENV BAZEL_EXTRA_FLAGS="--cpu=armeabi --crosstool_top=@local_config_arm_compiler//:toolchain" # Compile and build tensorflow lite RUN cd /opt/tensorflow && \ @@ -65,7 +71,7 @@ RUN mkdir -p /tmp/sysroot/lib && mkdir -p /tmp/sysroot/usr/lib && \ tar xf toolchain.tar.xz -C /opt/toolchain/ && \ rm toolchain.tar.xz && \ cp -r /opt/toolchain/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/* /tmp/sysroot/ -RUN mkdir -p /tmp/debs && cd /tmp/debs && apt-get download libc6:armhf libc6-dev:armhf && \ +RUN mkdir -p /tmp/debs && cd /tmp/debs && apt-get update && apt-get download libc6:armhf libc6-dev:armhf && \ ar x libc6_*.deb && tar xvf data.tar.xz && \ ar x libc6-dev*.deb && tar xvf data.tar.xz && \ cp -R usr /tmp/sysroot && cp -R lib /tmp/sysroot && rm -Rf /tmp/debs && \ @@ -90,7 +96,6 @@ ENV CFLAGS="-L /lib -L /usr/lib --sysroot /tmp/sysroot" ENV CXXFLAGS="-L /lib -L /usr/lib --sysroot /tmp/sysroot" # Install GOCV -ARG OPENCV_VERSION="4.0.1" ENV OPENCV_VERSION $OPENCV_VERSION RUN cd /tmp && \ curl -Lo opencv.zip https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip && \ @@ -130,24 +135,29 @@ RUN cd /tmp && git clone https://github.com/google-coral/edgetpu.git && \ rm -Rf edgetpu # Install Go -ARG GO_ARCH="armv6l" -ARG GO_VERSION="1.13.3" ENV GO_VERSION $GO_VERSION +ARG GO_ARCH="amd64" ENV GOOS=linux -ENV GOARCH=arm -ENV CGO_ENABLED=1 -ENV CGO_LDFLAGS="-v -L /lib -L /usr/lib -L /usr/local/lib --sysroot /tmp/sysroot -ledgetpu" -ENV CGO_CFLAGS="-L /lib -L /usr/lib -L /usr/local/lib --sysroot /tmp/sysroot" -ENV CGO_CXXFLAGS="-L /lib -L /usr/lib -L /usr/local/lib --sysroot /tmp/sysroot" RUN curl -Lo go${GO_VERSION}.linux-$GO_ARCH.tar.gz https://dl.google.com/go/go${GO_VERSION}.linux-$GO_ARCH.tar.gz && \ tar -C /usr/local -xzf go${GO_VERSION}.linux-$GO_ARCH.tar.gz && \ rm go${GO_VERSION}.linux-$GO_ARCH.tar.gz ENV PATH /usr/local/go/bin:/go/bin:${PATH} ENV GOPATH /go -# Compile doods +# Start compile WORKDIR /build ADD . . + +# Install/Compile tools +ENV CGO_ENABLED=0 +RUN make tools + +# Compile DOODS +ENV GOARCH=arm +ENV CGO_ENABLED=1 +ENV CGO_LDFLAGS="-v -L /lib -L /usr/lib -L /usr/local/lib --sysroot /tmp/sysroot -ledgetpu" +ENV CGO_CFLAGS="-L /lib -L /usr/lib -L /usr/local/lib -I /opt/tensorflow --sysroot /tmp/sysroot" +ENV CGO_CXXFLAGS="-L /lib -L /usr/lib -L /usr/local/lib -I /opt/tensorflow --sysroot /tmp/sysroot" RUN make # Start creating the new root directory @@ -156,19 +166,25 @@ RUN mkdir -p /tmp/newroot/lib && mkdir -p /tmp/newroot/usr/lib && \ cp -r /tmp/sysroot/lib/* /tmp/newroot/lib && \ cp -r /tmp/sysroot/usr/lib/* /tmp/newroot/usr/lib -# Setup doods and sample config with models +# Copy doods executable RUN mkdir -p /tmp/newroot/opt/doods && \ - cp /build/doods /tmp/newroot/opt/doods/doods && \ - cp /build/config.yaml /tmp/newroot/opt/doods/config.yaml && \ - cd /tmp/newroot/opt/doods && \ - mkdir models && \ - wget https://storage.googleapis.com/download.tensorflow.org/models/tflite/coco_ssd_mobilenet_v1_1.0_quant_2018_06_29.zip && unzip coco_ssd_mobilenet_v1_1.0_quant_2018_06_29.zip && rm coco_ssd_mobilenet_v1_1.0_quant_2018_06_29.zip && mv detect.tflite models/coco_ssd_mobilenet_v1_1.0_quant.tflite && rm labelmap.txt && \ - wget https://dl.google.com/coral/canned_models/coco_labels.txt && mv coco_labels.txt models/coco_labels0.txt + cp /build/doods /tmp/newroot/opt/doods/doods +WORKDIR /tmp/newroot/opt/doods + +# Download sample models +RUN mkdir models +RUN wget https://storage.googleapis.com/download.tensorflow.org/models/tflite/coco_ssd_mobilenet_v1_1.0_quant_2018_06_29.zip && unzip coco_ssd_mobilenet_v1_1.0_quant_2018_06_29.zip && rm coco_ssd_mobilenet_v1_1.0_quant_2018_06_29.zip && mv detect.tflite models/coco_ssd_mobilenet_v1_1.0_quant.tflite && rm labelmap.txt +RUN wget https://dl.google.com/coral/canned_models/coco_labels.txt && mv coco_labels.txt models/coco_labels0.txt +RUN wget http://download.tensorflow.org/models/object_detection/faster_rcnn_inception_v2_coco_2018_01_28.tar.gz && tar -zxvf faster_rcnn_inception_v2_coco_2018_01_28.tar.gz faster_rcnn_inception_v2_coco_2018_01_28/frozen_inference_graph.pb --strip=1 && mv frozen_inference_graph.pb models/faster_rcnn_inception_v2_coco_2018_01_28.pb && rm faster_rcnn_inception_v2_coco_2018_01_28.tar.gz +RUN wget https://github.com/raw/amikelive/coco-labels/master/coco-labels-2014_2017.txt && mv coco-labels-2014_2017.txt models/coco_labels1.txt +ADD config.arm.yaml config.yaml FROM arm32v7/debian:buster-slim # Copy the pre-built root filesystem -COPY --from=builder /tmp/newroot/. /. -COPY --from=builder /usr/local/. /usr/local/. +COPY --from=base /tmp/newroot/. /. +COPY --from=base /usr/local/. /usr/local/. +# Needed because we can't run ldconfig +ENV LD_LIBRARY_PATH=/usr/local/lib WORKDIR /opt/doods CMD ["/opt/doods/doods", "-c", "/opt/doods/config.yaml", "api"] diff --git a/Dockerfile.base.aarch64 b/Dockerfile.arm64 similarity index 62% rename from Dockerfile.base.aarch64 rename to Dockerfile.arm64 index dcb0cc3..bff3a6c 100644 --- a/Dockerfile.base.aarch64 +++ b/Dockerfile.arm64 @@ -1,26 +1,32 @@ -FROM debian:buster as builder +FROM debian:buster as base # Install reqs with cross compile support RUN dpkg --add-architecture arm64 && \ apt-get update && apt-get install -y --no-install-recommends \ pkg-config zip zlib1g-dev unzip wget bash-completion git curl \ - build-essential patch g++ python python-future python-numpy python-six python3 \ + build-essential patch g++ python python-future python3 \ cmake ca-certificates \ libc6-dev:arm64 libstdc++6:arm64 libusb-1.0-0:arm64 # Install protoc -RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v3.9.1/protoc-3.9.1-linux-x86_64.zip && \ - unzip protoc-3.9.1-linux-x86_64.zip -d /usr/local && \ +RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v3.12.3/protoc-3.12.3-linux-x86_64.zip && \ + unzip protoc-3.12.3-linux-x86_64.zip -d /usr/local && \ rm /usr/local/readme.txt && \ - rm protoc-3.9.1-linux-x86_64.zip + rm protoc-3.12.3-linux-x86_64.zip + +# Version Configuration +ARG BAZEL_VERSION="0.26.1" +ARG TF_VERSION="v1.15.3" +ARG OPENCV_VERSION="4.3.0" +ARG GO_VERSION="1.14.3" # Install bazel -RUN wget https://github.com/bazelbuild/bazel/releases/download/0.24.1/bazel_0.24.1-linux-x86_64.deb && \ - dpkg -i bazel_0.24.1-linux-x86_64.deb && \ - rm bazel_0.24.1-linux-x86_64.deb +ENV BAZEL_VERSION $BAZEL_VERSION +RUN wget https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel_${BAZEL_VERSION}-linux-x86_64.deb && \ + dpkg -i bazel_${BAZEL_VERSION}-linux-x86_64.deb && \ + rm bazel_${BAZEL_VERSION}-linux-x86_64.deb # Download tensorflow sources -ARG TF_VERSION="v1.15.0" ENV TF_VERSION $TF_VERSION RUN cd /opt && git clone https://github.com/tensorflow/tensorflow.git --branch $TF_VERSION --single-branch @@ -36,9 +42,9 @@ RUN cd /opt/tensorflow && /opt/tftoolchain.sh ENV TF_NEED_GDR=0 TF_NEED_AWS=0 TF_NEED_GCP=0 TF_NEED_CUDA=0 TF_NEED_HDFS=0 TF_NEED_OPENCL_SYCL=0 TF_NEED_VERBS=0 TF_NEED_MPI=0 TF_NEED_MKL=0 TF_NEED_JEMALLOC=1 TF_ENABLE_XLA=0 TF_NEED_S3=0 TF_NEED_KAFKA=0 TF_NEED_IGNITE=0 TF_NEED_ROCM=0 RUN cd /opt/tensorflow && yes '' | ./configure -# Tensorflow build flags for rpi -ENV BAZEL_COPT_FLAGS="--local_resources 16000,16,1 --copt=-march=armv8-a+crc+simd --copt=-mtune=cortex-a53 --copt=-O3 --copt=-flax-vector-conversions --copt=-std=c++11 --copt=-DS_IREAD=S_IRUSR --copt=-DS_IWRITE=S_IWUSR --config=monolithic --copt=-funsafe-math-optimizations --copt=-ftree-vectorize --copt=-fomit-frame-pointer --copt=-DRASPBERRY_PI --config=noaws --config=nohdfs --define tensorflow_mkldnn_contraction_kernel=0" -ENV BAZEL_EXTRA_FLAGS="--cpu=armeabi --crosstool_top=//tools/local_arm_compiler:toolchain" +# Tensorflow build flags for aarch64 (odroid c2 used for example) +ENV BAZEL_COPT_FLAGS="--local_resources 16000,16,1 --copt=-march=armv8-a+crc+simd --copt=-mtune=cortex-a53 --copt=-O3 --copt=-flax-vector-conversions --copt=-std=c++11 --copt=-DS_IREAD=S_IRUSR --copt=-DS_IWRITE=S_IWUSR --config=monolithic --copt=-funsafe-math-optimizations --copt=-ftree-vectorize --copt=-fomit-frame-pointer --copt=-DRASPBERRY_PI --noincompatible_strict_action_env --config=v2 --config=noaws --config=nohdfs --define tensorflow_mkldnn_contraction_kernel=0 --define=raspberry_pi_with_neon=true" +ENV BAZEL_EXTRA_FLAGS="--cpu=armeabi --crosstool_top=@local_config_arm_compiler//:toolchain" # Compile and build tensorflow lite RUN cd /opt/tensorflow && \ @@ -65,7 +71,7 @@ RUN mkdir -p /tmp/sysroot/lib && mkdir -p /tmp/sysroot/usr/lib && \ tar xf toolchain.tar.xz -C /opt/toolchain/ && \ rm toolchain.tar.xz && \ cp -r /opt/toolchain/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/aarch64-linux-gnu/libc/* /tmp/sysroot/ -RUN mkdir -p /tmp/debs && cd /tmp/debs && apt-get download libc6:arm64 libc6-dev:arm64 && \ +RUN mkdir -p /tmp/debs && cd /tmp/debs && apt-get update && apt-get download libc6:arm64 libc6-dev:arm64 && \ ar x libc6_*.deb && tar xvf data.tar.xz && \ ar x libc6-dev*.deb && tar xvf data.tar.xz && \ cp -R usr /tmp/sysroot && cp -R lib /tmp/sysroot && rm -Rf /tmp/debs && \ @@ -86,11 +92,10 @@ RUN mkdir -p /tmp/debs && cd /tmp/debs && apt-get download libc6:arm64 libc6-dev ENV CC="/opt/toolchain/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc" ENV CXX="/opt/toolchain/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++" ENV LDFLAGS="-v -L /lib -L /usr/lib --sysroot /tmp/sysroot" -ENV CFLAGS="-L /lib -L /usr/lib --sysroot /tmp/sysroot" -ENV CXXFLAGS="-L /lib -L /usr/lib --sysroot /tmp/sysroot" +ENV CFLAGS="-L /lib -L /usr/lib -D PNG_ARM_NEON_OPT=0 --sysroot /tmp/sysroot" +ENV CXXFLAGS="-L /lib -L /usr/lib -D PNG_ARM_NEON_OPT=0 --sysroot /tmp/sysroot" # Install GOCV -ARG OPENCV_VERSION="4.1.2" ENV OPENCV_VERSION $OPENCV_VERSION RUN cd /tmp && \ curl -Lo opencv.zip https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip && \ @@ -103,14 +108,12 @@ RUN cd /tmp && \ cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-${OPENCV_VERSION}/modules \ - -D CMAKE_TOOLCHAIN_FILE=/tmp/opencv-${OPENCV_VERSION}/platforms/linux/aarch64-gnu.toolchain.cmake \ -D WITH_JASPER=OFF \ -D WITH_QT=OFF \ -D WITH_GTK=OFF \ -D WITH_IPP=OFF \ -D BUILD_DOCS=OFF \ -D BUILD_EXAMPLES=OFF \ - -D BUILD_IPP_IW=OFF \ -D BUILD_TESTS=OFF \ -D BUILD_PERF_TESTS=OFF \ -D BUILD_opencv_java=NO \ @@ -124,7 +127,7 @@ RUN cd /tmp && \ # Download the edgetpu library and install it RUN cd /tmp && git clone https://github.com/google-coral/edgetpu.git && \ - install edgetpu/libedgetpu/throttled/aarch64/libedgetpu.so.1.0 /usr/local/lib/libedgetpu.so.1.0 && \ + install edgetpu/libedgetpu/direct/aarch64/libedgetpu.so.1.0 /usr/local/lib/libedgetpu.so.1.0 && \ ln -rs /usr/local/lib/libedgetpu.so.1.0 /usr/local/lib/libedgetpu.so.1 && \ ln -rs /usr/local/lib/libedgetpu.so.1.0 /usr/local/lib/libedgetpu.so && \ mkdir -p /usr/local/include/libedgetpu && \ @@ -132,8 +135,57 @@ RUN cd /tmp && git clone https://github.com/google-coral/edgetpu.git && \ install edgetpu/libedgetpu/edgetpu_c.h /usr/local/include/libedgetpu/edgetpu_c.h && \ rm -Rf edgetpu -# Configure the Go version to be used -ENV GO_ARCH "arm64" +# Install Go +ENV GO_VERSION $GO_VERSION +ARG GO_ARCH="amd64" +ENV GOOS=linux +RUN curl -Lo go${GO_VERSION}.linux-$GO_ARCH.tar.gz https://dl.google.com/go/go${GO_VERSION}.linux-$GO_ARCH.tar.gz && \ + tar -C /usr/local -xzf go${GO_VERSION}.linux-$GO_ARCH.tar.gz && \ + rm go${GO_VERSION}.linux-$GO_ARCH.tar.gz +ENV PATH /usr/local/go/bin:/go/bin:${PATH} +ENV GOPATH /go + +# Start compile +WORKDIR /build +ADD . . + +# Install/Compile tools +ENV CGO_ENABLED=0 +RUN make tools + +# Compile DOODS ENV GOARCH=arm64 - - +ENV CGO_ENABLED=1 +ENV CGO_LDFLAGS="-v -L /lib -L /usr/lib -L /usr/local/lib --sysroot /tmp/sysroot -ledgetpu" +ENV CGO_CFLAGS="-L /lib -L /usr/lib -L /usr/local/lib -I /opt/tensorflow --sysroot /tmp/sysroot" +ENV CGO_CXXFLAGS="-L /lib -L /usr/lib -L /usr/local/lib -I /opt/tensorflow --sysroot /tmp/sysroot" +RUN make + +# Start creating the new root directory +WORKDIR /tmp/newroot +RUN mkdir -p /tmp/newroot/lib && mkdir -p /tmp/newroot/usr/lib && \ + cp -r /tmp/sysroot/lib/* /tmp/newroot/lib && \ + cp -r /tmp/sysroot/usr/lib/* /tmp/newroot/usr/lib + +# Setup doods and sample config with models +RUN mkdir -p /tmp/newroot/opt/doods && \ + cp /build/doods /tmp/newroot/opt/doods/doods +WORKDIR /tmp/newroot/opt/doods + +# Download sample models +RUN mkdir models +RUN wget https://storage.googleapis.com/download.tensorflow.org/models/tflite/coco_ssd_mobilenet_v1_1.0_quant_2018_06_29.zip && unzip coco_ssd_mobilenet_v1_1.0_quant_2018_06_29.zip && rm coco_ssd_mobilenet_v1_1.0_quant_2018_06_29.zip && mv detect.tflite models/coco_ssd_mobilenet_v1_1.0_quant.tflite && rm labelmap.txt +RUN wget https://dl.google.com/coral/canned_models/coco_labels.txt && mv coco_labels.txt models/coco_labels0.txt +RUN wget http://download.tensorflow.org/models/object_detection/faster_rcnn_inception_v2_coco_2018_01_28.tar.gz && tar -zxvf faster_rcnn_inception_v2_coco_2018_01_28.tar.gz faster_rcnn_inception_v2_coco_2018_01_28/frozen_inference_graph.pb --strip=1 && mv frozen_inference_graph.pb models/faster_rcnn_inception_v2_coco_2018_01_28.pb && rm faster_rcnn_inception_v2_coco_2018_01_28.tar.gz +RUN wget https://github.com/raw/amikelive/coco-labels/master/coco-labels-2014_2017.txt && mv coco-labels-2014_2017.txt models/coco_labels1.txt +ADD config.arm.yaml config.yaml + +FROM arm64v8/debian:buster-slim +# Copy the pre-built root filesystem +COPY --from=base /tmp/newroot/. /. +COPY --from=base /usr/local/. /usr/local/. +# Needed because we can't run ldconfig +ENV LD_LIBRARY_PATH=/usr/local/lib + +WORKDIR /opt/doods +CMD ["/opt/doods/doods", "-c", "/opt/doods/config.yaml", "api"] diff --git a/Dockerfile.base.cuda b/Dockerfile.base.cuda index d84f924..4505de2 100644 --- a/Dockerfile.base.cuda +++ b/Dockerfile.base.cuda @@ -122,7 +122,6 @@ ENV GOPATH /go # Create the build directory RUN mkdir /build WORKDIR /build - ADD . . RUN make diff --git a/Dockerfile.base.rpi b/Dockerfile.base.rpi deleted file mode 100644 index 8069c48..0000000 --- a/Dockerfile.base.rpi +++ /dev/null @@ -1,137 +0,0 @@ -FROM debian:buster as builder - -# Install reqs with cross compile support -RUN dpkg --add-architecture armhf && \ - apt-get update && apt-get install -y --no-install-recommends \ - pkg-config zip zlib1g-dev unzip wget bash-completion git curl \ - build-essential patch g++ python python-future python-numpy python-six python3 \ - cmake ca-certificates \ - libc6-dev:armhf libstdc++6:armhf libusb-1.0-0:armhf - -# Install protoc -RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v3.9.1/protoc-3.9.1-linux-x86_64.zip && \ - unzip protoc-3.9.1-linux-x86_64.zip -d /usr/local && \ - rm /usr/local/readme.txt && \ - rm protoc-3.9.1-linux-x86_64.zip - -# Install bazel -RUN wget https://github.com/bazelbuild/bazel/releases/download/0.24.1/bazel_0.24.1-linux-x86_64.deb && \ - dpkg -i bazel_0.24.1-linux-x86_64.deb && \ - rm bazel_0.24.1-linux-x86_64.deb - -# Download tensorflow sources -ARG TF_VERSION="v1.15.0" -ENV TF_VERSION $TF_VERSION -RUN cd /opt && git clone https://github.com/tensorflow/tensorflow.git --branch $TF_VERSION --single-branch - -# Download and configure the toolchain and patch tensorflow as needed -ENV CROSSTOOL_COMPILER="yes" -ENV CROSSTOOL_URL="https://releases.linaro.org/components/toolchain/binaries/5.5-2017.10/arm-linux-gnueabihf/gcc-linaro-5.5.0-2017.10-x86_64_arm-linux-gnueabihf.tar.xz" -ENV CROSSTOOL_DIR="gcc-linaro-5.5.0-2017.10-x86_64_arm-linux-gnueabihf" -ENV CROSSTOOL_NAME="arm-linux-gnueabihf" -COPY tftoolchain.sh /opt/tftoolchain.sh -RUN cd /opt/tensorflow && /opt/tftoolchain.sh - -# Configure tensorflow -ENV TF_NEED_GDR=0 TF_NEED_AWS=0 TF_NEED_GCP=0 TF_NEED_CUDA=0 TF_NEED_HDFS=0 TF_NEED_OPENCL_SYCL=0 TF_NEED_VERBS=0 TF_NEED_MPI=0 TF_NEED_MKL=0 TF_NEED_JEMALLOC=1 TF_ENABLE_XLA=0 TF_NEED_S3=0 TF_NEED_KAFKA=0 TF_NEED_IGNITE=0 TF_NEED_ROCM=0 -RUN cd /opt/tensorflow && yes '' | ./configure - -# Tensorflow build flags for rpi -ENV BAZEL_COPT_FLAGS="--local_resources 16000,16,1 --copt=-march=armv7-a --copt=-mfpu=neon-vfpv4 --copt=-mfloat-abi=hard --copt=-O3 --copt=-std=c++11 --copt=-DS_IREAD=S_IRUSR --copt=-DS_IWRITE=S_IWUSR --copt=-U__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 --copt=-U__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 --copt=-U__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 --config=monolithic --copt=-funsafe-math-optimizations --copt=-ftree-vectorize --copt=-fomit-frame-pointer --copt=-DRASPBERRY_PI --config=noaws --config=nohdfs --define tensorflow_mkldnn_contraction_kernel=0" -ENV BAZEL_EXTRA_FLAGS="--cpu=armeabi --crosstool_top=//tools/local_arm_compiler:toolchain" - -# Compile and build tensorflow lite -RUN cd /opt/tensorflow && \ - bazel build -c opt $BAZEL_COPT_FLAGS --verbose_failures $BAZEL_EXTRA_FLAGS //tensorflow/lite:libtensorflowlite.so && \ - install bazel-bin/tensorflow/lite/libtensorflowlite.so /usr/local/lib/libtensorflowlite.so && \ - bazel build -c opt $BAZEL_COPT_FLAGS --verbose_failures $BAZEL_EXTRA_FLAGS //tensorflow/lite/experimental/c:libtensorflowlite_c.so && \ - install bazel-bin/tensorflow/lite/experimental/c/libtensorflowlite_c.so /usr/local/lib/libtensorflowlite_c.so && \ - mkdir -p /usr/local/include/flatbuffers && cp bazel-tensorflow/external/flatbuffers/include/flatbuffers/* /usr/local/include/flatbuffers - -# Compile and install tensorflow shared library -RUN cd /opt/tensorflow && \ - bazel build -c opt $BAZEL_COPT_FLAGS --verbose_failures $BAZEL_EXTRA_FLAGS //tensorflow:libtensorflow.so && \ - install bazel-bin/tensorflow/libtensorflow.so /usr/local/lib/libtensorflow.so && \ - ln -rs /usr/local/lib/libtensorflow.so /usr/local/lib/libtensorflow.so.1 - -# cleanup so the cache directory isn't huge -RUN cd /opt/tensorflow && \ - bazel clean && rm -Rf /root/.cache - -# Download and configure the build environment for gcc 6 which is needed to compile everything else -RUN mkdir -p /tmp/sysroot/lib && mkdir -p /tmp/sysroot/usr/lib && \ - cd /tmp && \ - wget --no-check-certificate https://releases.linaro.org/components/toolchain/binaries/6.3-2017.05/arm-linux-gnueabihf/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf.tar.xz -O toolchain.tar.xz && \ - tar xf toolchain.tar.xz -C /opt/toolchain/ && \ - rm toolchain.tar.xz && \ - cp -r /opt/toolchain/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/* /tmp/sysroot/ -RUN mkdir -p /tmp/debs && cd /tmp/debs && apt-get download libc6:armhf libc6-dev:armhf && \ - ar x libc6_*.deb && tar xvf data.tar.xz && \ - ar x libc6-dev*.deb && tar xvf data.tar.xz && \ - cp -R usr /tmp/sysroot && cp -R lib /tmp/sysroot && rm -Rf /tmp/debs && \ - mkdir -p /tmp/debs && cd /tmp/debs && \ - apt-get download libusb-1.0-0:armhf libudev1:armhf zlib1g-dev:armhf zlib1g:armhf && \ - ar x libusb-1.0*.deb && tar xvf data.tar.xz && \ - ar x libudev1*.deb && tar xvf data.tar.xz && \ - ar x zlib1g_*.deb && tar xvf data.tar.xz && \ - ar x zlib1g-dev*.deb && tar xvf data.tar.xz && rm usr/lib/arm-linux-gnueabihf/libz.so && \ - cp -r lib/arm-linux-gnueabihf/* /tmp/sysroot/lib && \ - cp -r usr/lib/arm-linux-gnueabihf/* /tmp/sysroot/usr/lib && \ - cp -r usr/include/* /tmp/sysroot/usr/include && \ - ln -rs /tmp/sysroot/lib/libusb-1.0.so.0.1.0 /tmp/sysroot/lib/libusb-1.0.so && \ - ln -rs /tmp/sysroot/lib/libudev.so.1.6.13 /tmp/sysroot/lib/libudev.so && \ - ln -rs /tmp/sysroot/lib/libz.so.1.2.11 /tmp/sysroot/lib/libz.so && \ - ln -s /usr/local /tmp/sysroot/usr/local && \ - cd /tmp && rm -Rf /tmp/debs -ENV CC="/opt/toolchain/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc" -ENV CXX="/opt/toolchain/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++" -ENV LDFLAGS="-v -L /lib -L /usr/lib --sysroot /tmp/sysroot" -ENV CFLAGS="-L /lib -L /usr/lib --sysroot /tmp/sysroot" -ENV CXXFLAGS="-L /lib -L /usr/lib --sysroot /tmp/sysroot" - -# Install GOCV -ARG OPENCV_VERSION="4.1.2" -ENV OPENCV_VERSION $OPENCV_VERSION -RUN cd /tmp && \ - curl -Lo opencv.zip https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip && \ - unzip -q opencv.zip && \ - curl -Lo opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip && \ - unzip -q opencv_contrib.zip && \ - rm opencv.zip opencv_contrib.zip && \ - cd opencv-${OPENCV_VERSION} && \ - mkdir build && cd build && \ - cmake -D CMAKE_BUILD_TYPE=RELEASE \ - -D CMAKE_INSTALL_PREFIX=/usr/local \ - -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-${OPENCV_VERSION}/modules \ - -D CMAKE_TOOLCHAIN_FILE=/tmp/opencv-${OPENCV_VERSION}/platforms/linux/arm-gnueabi.toolchain.cmake \ - -D WITH_JASPER=OFF \ - -D WITH_QT=OFF \ - -D WITH_GTK=OFF \ - -D BUILD_DOCS=OFF \ - -D BUILD_EXAMPLES=OFF \ - -D BUILD_TESTS=OFF \ - -D BUILD_PERF_TESTS=OFF \ - -D BUILD_opencv_java=NO \ - -D BUILD_opencv_python=NO \ - -D BUILD_opencv_python2=NO \ - -D BUILD_opencv_python3=NO \ - -D OPENCV_GENERATE_PKGCONFIG=ON .. && \ - make -j $(nproc --all) && \ - make preinstall && make install && \ - cd /tmp && rm -rf opencv* - -# Download the edgetpu library and install it -RUN cd /tmp && git clone https://github.com/google-coral/edgetpu.git && \ - install edgetpu/libedgetpu/throttled/armv7a/libedgetpu.so.1.0 /usr/local/lib/libedgetpu.so.1.0 && \ - ln -rs /usr/local/lib/libedgetpu.so.1.0 /usr/local/lib/libedgetpu.so.1 && \ - ln -rs /usr/local/lib/libedgetpu.so.1.0 /usr/local/lib/libedgetpu.so && \ - mkdir -p /usr/local/include/libedgetpu && \ - install edgetpu/libedgetpu/edgetpu.h /usr/local/include/libedgetpu/edgetpu.h && \ - install edgetpu/libedgetpu/edgetpu_c.h /usr/local/include/libedgetpu/edgetpu_c.h && \ - rm -Rf edgetpu - -# Configure the Go version to be used -ENV GO_ARCH "armv6l" -ENV GOARCH=arm - - diff --git a/Dockerfile.builder b/Dockerfile.builder index ea89e7e..e06c8f2 100644 --- a/Dockerfile.builder +++ b/Dockerfile.builder @@ -1,13 +1,110 @@ -ARG BUILDER_TAG="latest" -FROM registry.prozach.org/doods-base:$BUILDER_TAG as base +FROM ubuntu:18.04 as base + +# Install reqs with cross compile support +RUN apt-get update && apt-get install -y --no-install-recommends \ + pkg-config zip zlib1g-dev unzip wget bash-completion git curl \ + build-essential patch g++ python python-future python-numpy python-six python3 \ + cmake ca-certificates \ + libc6-dev libstdc++6 libusb-1.0-0 + +# Install protoc +RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v3.12.3/protoc-3.12.3-linux-x86_64.zip && \ + unzip protoc-3.12.3-linux-x86_64.zip -d /usr/local && \ + rm /usr/local/readme.txt && \ + rm protoc-3.12.3-linux-x86_64.zip + +# Version Configuration +ARG BAZEL_VERSION="0.26.1" +ARG TF_VERSION="v1.15.3" +ARG OPENCV_VERSION="4.3.0" +ARG GO_VERSION="1.14.3" + +# Install bazel +ENV BAZEL_VERSION $BAZEL_VERSION +RUN wget https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel_${BAZEL_VERSION}-linux-x86_64.deb && \ + dpkg -i bazel_${BAZEL_VERSION}-linux-x86_64.deb && \ + rm bazel_${BAZEL_VERSION}-linux-x86_64.deb + +# Download tensorflow sources +ENV TF_VERSION $TF_VERSION +RUN cd /opt && git clone https://github.com/tensorflow/tensorflow.git --branch $TF_VERSION --single-branch + +# Configure tensorflow +ENV TF_NEED_GDR=0 TF_NEED_AWS=0 TF_NEED_GCP=0 TF_NEED_CUDA=0 TF_NEED_HDFS=0 TF_NEED_OPENCL_SYCL=0 TF_NEED_VERBS=0 TF_NEED_MPI=0 TF_NEED_MKL=0 TF_NEED_JEMALLOC=1 TF_ENABLE_XLA=0 TF_NEED_S3=0 TF_NEED_KAFKA=0 TF_NEED_IGNITE=0 TF_NEED_ROCM=0 +RUN cd /opt/tensorflow && yes '' | ./configure + +# Tensorflow build flags for rpi +ENV BAZEL_COPT_FLAGS="--local_resources 16000,16,1 -c opt --config monolithic --copt=-march=native --copt=-O3 --copt=-fomit-frame-pointer --incompatible_no_support_tools_in_action_inputs=false --config=noaws --config=nohdfs" +ENV BAZEL_EXTRA_FLAGS="" + +# Compile and build tensorflow lite +RUN cd /opt/tensorflow && \ + bazel build -c opt $BAZEL_COPT_FLAGS --verbose_failures $BAZEL_EXTRA_FLAGS //tensorflow/lite:libtensorflowlite.so && \ + install bazel-bin/tensorflow/lite/libtensorflowlite.so /usr/local/lib/libtensorflowlite.so && \ + bazel build -c opt $BAZEL_COPT_FLAGS --verbose_failures $BAZEL_EXTRA_FLAGS //tensorflow/lite/experimental/c:libtensorflowlite_c.so && \ + install bazel-bin/tensorflow/lite/experimental/c/libtensorflowlite_c.so /usr/local/lib/libtensorflowlite_c.so && \ + mkdir -p /usr/local/include/flatbuffers && cp bazel-tensorflow/external/flatbuffers/include/flatbuffers/* /usr/local/include/flatbuffers + +# Compile and install tensorflow shared library +RUN cd /opt/tensorflow && \ + bazel build -c opt $BAZEL_COPT_FLAGS --verbose_failures $BAZEL_EXTRA_FLAGS //tensorflow:libtensorflow.so && \ + install bazel-bin/tensorflow/libtensorflow.so /usr/local/lib/libtensorflow.so && \ + ln -rs /usr/local/lib/libtensorflow.so /usr/local/lib/libtensorflow.so.1 + +# cleanup so the cache directory isn't huge +RUN cd /opt/tensorflow && \ + bazel clean && rm -Rf /root/.cache + +# Install GOCV +ENV OPENCV_VERSION $OPENCV_VERSION +RUN cd /tmp && \ + curl -Lo opencv.zip https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip && \ + unzip -q opencv.zip && \ + curl -Lo opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip && \ + unzip -q opencv_contrib.zip && \ + rm opencv.zip opencv_contrib.zip && \ + cd opencv-${OPENCV_VERSION} && \ + mkdir build && cd build && \ + cmake -D CMAKE_BUILD_TYPE=RELEASE \ + -D CMAKE_INSTALL_PREFIX=/usr/local \ + -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-${OPENCV_VERSION}/modules \ + -D WITH_JASPER=OFF \ + -D WITH_QT=OFF \ + -D WITH_GTK=OFF \ + -D BUILD_DOCS=OFF \ + -D BUILD_EXAMPLES=OFF \ + -D BUILD_TESTS=OFF \ + -D BUILD_PERF_TESTS=OFF \ + -D BUILD_opencv_java=NO \ + -D BUILD_opencv_python=NO \ + -D BUILD_opencv_python2=NO \ + -D BUILD_opencv_python3=NO \ + -D OPENCV_GENERATE_PKGCONFIG=ON .. && \ + make -j $(nproc --all) && \ + make preinstall && make install && \ + cd /tmp && rm -rf opencv* + +# Download the edgetpu library and install it +RUN cd /tmp && git clone https://github.com/google-coral/edgetpu.git && \ + install edgetpu/libedgetpu/throttled/k8/libedgetpu.so.1.0 /usr/local/lib/libedgetpu.so.1.0 && \ + ln -rs /usr/local/lib/libedgetpu.so.1.0 /usr/local/lib/libedgetpu.so.1 && \ + ln -rs /usr/local/lib/libedgetpu.so.1.0 /usr/local/lib/libedgetpu.so && \ + mkdir -p /usr/local/include/libedgetpu && \ + install edgetpu/libedgetpu/edgetpu.h /usr/local/include/libedgetpu/edgetpu.h && \ + install edgetpu/libedgetpu/edgetpu_c.h /usr/local/include/libedgetpu/edgetpu_c.h && \ + rm -Rf edgetpu + +# Configure the Go version to be used +ENV GO_ARCH "amd64" +ENV GOARCH=amd64 # Install Go -ENV GO_VERSION "1.13.3" +ENV GO_VERSION $GO_VERSION RUN curl -kLo go${GO_VERSION}.linux-${GO_ARCH}.tar.gz https://dl.google.com/go/go${GO_VERSION}.linux-${GO_ARCH}.tar.gz && \ tar -C /usr/local -xzf go${GO_VERSION}.linux-${GO_ARCH}.tar.gz && \ rm go${GO_VERSION}.linux-${GO_ARCH}.tar.gz -FROM debian:buster-slim as build +FROM ubuntu:18.04 as builder RUN apt-get update && apt-get install -y --no-install-recommends \ pkg-config zip zlib1g-dev unzip wget bash-completion git curl \ @@ -23,7 +120,3 @@ ENV CGO_ENABLED=1 ENV CGO_CFLAGS=-I/opt/tensorflow ENV PATH /usr/local/go/bin:/go/bin:${PATH} ENV GOPATH /go - -# Create the build directory -RUN mkdir /build -WORKDIR /build diff --git a/Dockerfile.base.noavx b/Dockerfile.noavx similarity index 57% rename from Dockerfile.base.noavx rename to Dockerfile.noavx index 9208f74..2bb4ea4 100644 --- a/Dockerfile.base.noavx +++ b/Dockerfile.noavx @@ -1,4 +1,4 @@ -FROM debian:buster as builder +FROM ubuntu:18.04 as base # Install reqs with cross compile support RUN apt-get update && apt-get install -y --no-install-recommends \ @@ -8,18 +8,24 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ libc6-dev libstdc++6 libusb-1.0-0 # Install protoc -RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v3.9.1/protoc-3.9.1-linux-x86_64.zip && \ - unzip protoc-3.9.1-linux-x86_64.zip -d /usr/local && \ +RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v3.12.3/protoc-3.12.3-linux-x86_64.zip && \ + unzip protoc-3.12.3-linux-x86_64.zip -d /usr/local && \ rm /usr/local/readme.txt && \ - rm protoc-3.9.1-linux-x86_64.zip + rm protoc-3.12.3-linux-x86_64.zip + +# Version Configuration +ARG BAZEL_VERSION="0.26.1" +ARG TF_VERSION="v1.15.3" +ARG OPENCV_VERSION="4.3.0" +ARG GO_VERSION="1.14.3" # Install bazel -RUN wget https://github.com/bazelbuild/bazel/releases/download/0.27.1/bazel_0.27.1-linux-x86_64.deb && \ - dpkg -i bazel_0.27.1-linux-x86_64.deb && \ - rm bazel_0.27.1-linux-x86_64.deb +ENV BAZEL_VERSION $BAZEL_VERSION +RUN wget https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel_${BAZEL_VERSION}-linux-x86_64.deb && \ + dpkg -i bazel_${BAZEL_VERSION}-linux-x86_64.deb && \ + rm bazel_${BAZEL_VERSION}-linux-x86_64.deb # Download tensorflow sources -ARG TF_VERSION="v2.1.0-rc1" ENV TF_VERSION $TF_VERSION RUN cd /opt && git clone https://github.com/tensorflow/tensorflow.git --branch $TF_VERSION --single-branch @@ -50,7 +56,6 @@ RUN cd /opt/tensorflow && \ bazel clean && rm -Rf /root/.cache # Install GOCV -ARG OPENCV_VERSION="4.1.2" ENV OPENCV_VERSION $OPENCV_VERSION RUN cd /tmp && \ curl -Lo opencv.zip https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip && \ @@ -92,3 +97,54 @@ RUN cd /tmp && git clone https://github.com/google-coral/edgetpu.git && \ # Configure the Go version to be used ENV GO_ARCH "amd64" ENV GOARCH=amd64 + +# Install Go +ENV GO_VERSION $GO_VERSION +RUN curl -kLo go${GO_VERSION}.linux-${GO_ARCH}.tar.gz https://dl.google.com/go/go${GO_VERSION}.linux-${GO_ARCH}.tar.gz && \ + tar -C /usr/local -xzf go${GO_VERSION}.linux-${GO_ARCH}.tar.gz && \ + rm go${GO_VERSION}.linux-${GO_ARCH}.tar.gz + +FROM ubuntu:18.04 as builder + +RUN apt-get update && apt-get install -y --no-install-recommends \ + pkg-config zip zlib1g-dev unzip wget bash-completion git curl \ + build-essential patch g++ python python-future python3 ca-certificates \ + libc6-dev libstdc++6 libusb-1.0-0 + +# Copy all libraries, includes and go +COPY --from=base /usr/local/. /usr/local/. +COPY --from=base /opt/tensorflow /opt/tensorflow + +ENV GOOS=linux +ENV CGO_ENABLED=1 +ENV CGO_CFLAGS=-I/opt/tensorflow +ENV PATH /usr/local/go/bin:/go/bin:${PATH} +ENV GOPATH /go + +# Create the build directory +RUN mkdir /build +WORKDIR /build +ADD . . +RUN make + +FROM ubuntu:18.04 + +RUN apt-get update && \ + apt-get install -y --no-install-recommends libusb-1.0 libc++-7-dev wget unzip ca-certificates libdc1394-22 libavcodec57 libavformat57 && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* +RUN mkdir -p /opt/doods +WORKDIR /opt/doods +COPY --from=builder /usr/local/lib/. /usr/local/lib/. +COPY --from=builder /build/doods /opt/doods/doods +RUN ldconfig + +# Download sample models +RUN mkdir models +RUN wget https://storage.googleapis.com/download.tensorflow.org/models/tflite/coco_ssd_mobilenet_v1_1.0_quant_2018_06_29.zip && unzip coco_ssd_mobilenet_v1_1.0_quant_2018_06_29.zip && rm coco_ssd_mobilenet_v1_1.0_quant_2018_06_29.zip && mv detect.tflite models/coco_ssd_mobilenet_v1_1.0_quant.tflite && rm labelmap.txt +RUN wget https://dl.google.com/coral/canned_models/coco_labels.txt && mv coco_labels.txt models/coco_labels0.txt +RUN wget http://download.tensorflow.org/models/object_detection/faster_rcnn_inception_v2_coco_2018_01_28.tar.gz && tar -zxvf faster_rcnn_inception_v2_coco_2018_01_28.tar.gz faster_rcnn_inception_v2_coco_2018_01_28/frozen_inference_graph.pb --strip=1 && mv frozen_inference_graph.pb models/faster_rcnn_inception_v2_coco_2018_01_28.pb && rm faster_rcnn_inception_v2_coco_2018_01_28.tar.gz +RUN wget https://github.com/raw/amikelive/coco-labels/master/coco-labels-2014_2017.txt && mv coco-labels-2014_2017.txt models/coco_labels1.txt +ADD config.yaml config.yaml + +CMD ["/opt/doods/doods", "-c", "/opt/doods/config.yaml", "api"] diff --git a/Makefile b/Makefile index 253f955..6000e5a 100644 --- a/Makefile +++ b/Makefile @@ -50,13 +50,34 @@ deps: # Fetching dependancies... go get -d -v # Adding -u here will break CI -docker: docker-base docker-builder docker-image +docker: + docker build -t docker.io/snowzach/doods:local -f Dockerfile . -docker-base: - docker build -t docker.io/snowzach/doods-base:${CONFIG} -f Dockerfile.base.${CONFIG} . +docker-images: docker-noavx docker-amd64 docker-arm32 docker-arm64 + docker manifest push --purge snowzach/doods:latest + docker manifest create snowzach/doods:latest snowzach/doods:noavx snowzach/doods:arm32 snowzach/doods:arm64 + docker manifest push snowzach/doods:latest -docker-builder: - docker build -t docker.io/snowzach/doods-builder:${CONFIG} -f Dockerfile.builder.${CONFIG} . +.PHONY: docker-noavx +docker-noavx: + docker build -t docker.io/snowzach/doods:noavx -f Dockerfile.noavx . + docker push docker.io/snowzach/doods:noavx + +.PHONY: docker-amd64 +docker-amd64: + docker build -t docker.io/snowzach/doods:amd64 -f Dockerfile.amd64 . + docker push docker.io/snowzach/doods:amd64 + +.PHONY: docker-arm32 +docker-arm32: + docker build -t docker.io/snowzach/doods:arm32 -f Dockerfile.arm32 . + docker push docker.io/snowzach/doods:arm32 -docker-image: - docker build -t docker.io/snowzach/doods:${CONFIG} --build-arg BUILDER_TAG=${CONFIG} -f Dockerfile . +.PHONY: docker-arm64 +docker-arm64: + docker build -t docker.io/snowzach/doods:arm64 -f Dockerfile.arm64 . + docker push docker.io/snowzach/doods:arm64 + +.PHONY: docker-builder +docker-builder: + docker build -t docker.io/snowzach/doods:builder -f Dockerfile.builder . diff --git a/README.md b/README.md index 8b7be58..521b8fc 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # DOODS -Dedicated Open Object Detection Service - Yes, it's a backronym, so what... +Dedicated Open Object Detection Service - Yes, it's a backronym... -DOODS is a GRPC service that detects objects in images. It's designed to be run as a container, optionally remotely. +DOODS is a GRPC/REST service that detects objects in images. It's designed to be very easy to use, run as a container and available remotely. ## API The API uses gRPC to communicate but it has a REST gateway built in for ease of use. It supports both a single call RPC and a streaming interface. @@ -16,10 +16,12 @@ The protobuf API definitations are in the `odrpc/odrpc.proto` file. There are 3 - DetectStream - Detect objects in a stream of images ### REST/JSON +The services are available via rest API at these endpoints * `GET /version` - Get the version * `GET /detectors` - Get the list of configured detectors * `POST /detect` - Detect objects in an image +For `POST /detect` it expects JSON in the following format. ``` { "detector_name": "default", @@ -46,28 +48,28 @@ The result is returned as: ] } ``` -Perform a detection. Use the default detector. (If omitted, it will use the default) +This will perform a detection using the detector called default. (If omitted, it will use one called default if it exists) The `data`, when using the REST interface is base64 encoded image data. DOODS can decode png, bmp and jpg. The `detect` object allows you to specify the list of objects to detect as defined in the labels file. You can give a min percentage match. You can also use "*" which will match anything with a minimum percentage. -Example One Liner: +Example 1-Liner to call the API using curl with image data: ``` echo "{\"detector_name\":\"default\", \"detect\":{\"*\":60}, \"data\":\"`cat grace_hopper.png|base64 -w0`\"}" > /tmp/postdata.json && curl -d@/tmp/postdata.json -H "Content-Type: application/json" -X POST http://localhost:8080/detect ``` ## Detectors You should optimally pass image data in the requested size for the detector. If not, it will be automatically resized. -It can read BMP, PNG and JPG as well as PPM. +It can read BMP, PNG and JPG as well as PPM. For detectors that do not specify a size (inception) you do not need to resize ### TFLite -If you pass PPM image data in the right dimensions, it can be fed directly into tensorflow. This skips a couple steps for speed. +If you pass PPM image data in the right dimensions, it can be fed directly into tensorflow lite. This skips a couple steps for speed. You can also specify `hwAccel: true` in the config and it will enable Coral EdgeTPU hardware acceleration. -You must also provide it an appropriate EdgeTPU model file. +You must also provide it an appropriate EdgeTPU model file. There are none included with the base image. ## Compiling This is designed as a go module aware program and thus requires go 1.12 or better. It also relies heavily on CGO. The easiest way to compile it -is to use the Dockerfile which will build a functioning docker image. It's a little large. +is to use the Dockerfile which will build a functioning docker image. It's a little large but it includes 2 models. ## Configuration The configuration can be specified in a number of ways. By default you can create a json file and call it with the -c option @@ -87,31 +89,31 @@ LOGGER_LEVEL=debug ``` ### Options: -| Setting | Description | Default | -|--------------------------------|-------------------------------------------------------------|--------------| -| logger.level | The default logging level | "info" | -| logger.encoding | Logging format (console or json) | "console" | -| logger.color | Enable color in console mode | true | -| logger.disable_caller | Hide the caller source file and line number | false | -| logger.disable_stacktrace | Hide a stacktrace on debug logs | true | -| --- | --- | --- | -| server.host | The host address to listen on (blank=all addresses) | "" | -| server.port | The port number to listen on | 8080 | -| server.tls | Enable https/tls | false | -| server.devcert | Generate a development cert | false | -| server.certfile | The HTTPS/TLS server certificate | "server.crt" | -| server.keyfile | The HTTPS/TLS server key file | "server.key" | -| server.log_requests | Log API requests | true | -| server.profiler_enabled | Enable the profiler | false | -| server.profiler_path | Where should the profiler be available | "/debug" | -| --- | --- | --- | -| pidfile | Write a pidfile (only if specified) | "" | -| profiler.enabled | Enable the debug pprof interface | "false" | -| profiler.host | The profiler host address to listen on | "" | -| profiler.port | The profiler port to listen on | "6060" | -| --- | --- | --- | -| doods.auth_key | A pre-shared auth key. Disabled if blank | "" | -| doods.detectors | The detector configurations | | +| Setting | Description | Default | +| ------------------------- | --------------------------------------------------- | ------------ | +| logger.level | The default logging level | "info" | +| logger.encoding | Logging format (console or json) | "console" | +| logger.color | Enable color in console mode | true | +| logger.disable_caller | Hide the caller source file and line number | false | +| logger.disable_stacktrace | Hide a stacktrace on debug logs | true | +| --- | --- | --- | +| server.host | The host address to listen on (blank=all addresses) | "" | +| server.port | The port number to listen on | 8080 | +| server.tls | Enable https/tls | false | +| server.devcert | Generate a development cert | false | +| server.certfile | The HTTPS/TLS server certificate | "server.crt" | +| server.keyfile | The HTTPS/TLS server key file | "server.key" | +| server.log_requests | Log API requests | true | +| server.profiler_enabled | Enable the profiler | false | +| server.profiler_path | Where should the profiler be available | "/debug" | +| --- | --- | --- | +| pidfile | Write a pidfile (only if specified) | "" | +| profiler.enabled | Enable the debug pprof interface | "false" | +| profiler.host | The profiler host address to listen on | "" | +| profiler.port | The profiler port to listen on | "6060" | +| --- | --- | --- | +| doods.auth_key | A pre-shared auth key. Disabled if blank | "" | +| doods.detectors | The detector configurations | | ### TLS/HTTPS You can enable https by setting the config option server.tls = true and pointing it to your keyfile and certfile. @@ -119,7 +121,8 @@ To create a self-signed cert: `openssl req -new -newkey rsa:2048 -days 3650 -nod You will need to mount these in the container and adjust the config to find them. ### Detector Config -Detector config must be done with a configuration file. The default config includes one Tensorflow lite mobilenet detector. +Detector config must be done with a configuration file. The default config includes one Tensorflow Lite mobilenet detector and the Tensorflow Inception model. +This is the default config with the exception of the threads and concurrent are tuned a bit for the architecture they are running on. ``` doods: detectors: @@ -130,20 +133,29 @@ doods: numThreads: 4 numConcurrent: 4 hwAccel: false - timeout: 30s + timeout: 2m + - name: tensorflow + type: tensorflow + modelFile: models/faster_rcnn_inception_v2_coco_2018_01_28.pb + labelFile: models/coco_labels1.txt + numThreads: 4 + numConcurrent: 4 + hwAccel: false + timeout: 2m ``` -The default model is downloaded from google: coco_ssd_mobilenet_v1_1.0_quant_2018_06_29 +The default models are downloaded from google: coco_ssd_mobilenet_v1_1.0_quant_2018_06_29 and faster_rcnn_inception_v2_coco_2018_01_28.pb The `numThreads` option is the number of threads that will be available for compatible operations in a model The `numConcurrent` option sets the number of models that will be able to run at the same time. This should be 1 unless you have a beefy machine. The `hwAccel` option is used to specify that a hardware device should be used. The only device supported is the edgetpu currently If `timeout` is set than a detector (namely an edgetpu) that hangs for longer than the timeout will cause doods to error and exit. Generally this error is not recoverable and Doods needs to be restarted. - ### Detector Types Supported * tflite - Tensorflow lite models - Supports Coral EdgeTPU if hwAccel: true and appropriate model is used * tensorflow - Tensorflow +EdgeTPU models can be downloaded from here: https://coral.ai/models/ (Use the Object Detection Models) + ## Examples - Clients See the examples directory for sample clients @@ -166,10 +178,10 @@ And special thanks to @lhelontra, @marianopeck and @PINTO0309 for help in buildi ## Docker Images There are several published Docker images that you can use -* latest - This is a multi-arch image that points to the rpi image, aarch64 and noavx image +* latest - This is a multi-arch image that points to the arm32 image, arm64 and noavx image * noavx - 64 bit x86 image that should be a highly compatible with any cpu. -* aarch64 - Arm 64 bit image -* rpi - Arm 32 bit/arm7 image optimized for the Raspberry Pi +* arm64 - Arm 64 bit image +* arm32 - Arm 32 bit/arm7 image optimized for the Raspberry Pi * amd64 - 64 bit x86 image with all the fancy cpu features like avx and sse4.2 * cuda - Support for NVidia GPUs @@ -179,10 +191,10 @@ There is now NVidia GPU support with an docker image tagged cuda, to run: For whatever reason, it can take a good 60-80 seconds before the model finishes loading. ## Compiling -You can compile it yourself using the native config which should optimize for whatever you have installed. -Make the `snowzach/doods-builder:native` image followed by the `snowzach/doods:native` image with this command: +You can compile it yourself using the plain `Dockerfile` which should pick the optimal CPU flags for your architecture. +Make the `snowzach/doods:local` image with this command: ``` -$ make docker CONFIG=native +$ make docker ``` [![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QG353JUXA6BFW&source=url) diff --git a/builder.sh b/builder.sh new file mode 100644 index 0000000..c4f12db --- /dev/null +++ b/builder.sh @@ -0,0 +1,2 @@ +#!/bin/bash +docker run -it -v $PWD:/build --device /dev/bus/usb snowzach/doods:builder bash diff --git a/config.arm.yaml b/config.arm.yaml new file mode 100644 index 0000000..47106fd --- /dev/null +++ b/config.arm.yaml @@ -0,0 +1,18 @@ +doods: + detectors: + - name: default + type: tflite + modelFile: models/coco_ssd_mobilenet_v1_1.0_quant.tflite + labelFile: models/coco_labels0.txt + numThreads: 4 + numConcurrent: 4 + hwAccel: false + timeout: 2m + - name: tensorflow + type: tensorflow + modelFile: models/faster_rcnn_inception_v2_coco_2018_01_28.pb + labelFile: models/coco_labels1.txt + numThreads: 4 + numConcurrent: 1 + hwAccel: false + timeout: 2m diff --git a/config.yaml b/config.yaml index 3946de3..a06fafd 100644 --- a/config.yaml +++ b/config.yaml @@ -8,4 +8,11 @@ doods: numConcurrent: 4 hwAccel: false timeout: 2m - \ No newline at end of file + - name: tensorflow + type: tensorflow + modelFile: models/faster_rcnn_inception_v2_coco_2018_01_28.pb + labelFile: models/coco_labels1.txt + numThreads: 4 + numConcurrent: 4 + hwAccel: false + timeout: 2m diff --git a/go.mod b/go.mod index 5715dd0..3941e2b 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 github.com/pelletier/go-toml v1.6.0 // indirect github.com/snowzach/certtools v1.0.2 - github.com/snowzach/mjpeg v0.0.1 // indirect + github.com/snowzach/mjpeg v0.0.1 github.com/spf13/afero v1.2.2 // indirect github.com/spf13/cobra v0.0.5 github.com/spf13/jwalterweatherman v1.1.0 // indirect diff --git a/odrpc/rpc.proto b/odrpc/rpc.proto index 6149d05..59aa6f4 100644 --- a/odrpc/rpc.proto +++ b/odrpc/rpc.proto @@ -65,6 +65,18 @@ message DetectRequest { bytes data = 3 [(gogoproto.casttype) = "Raw",(gogoproto.jsontag) = "data"]; // What to detect map detect = 4; + // Sub regions for detection + repeated DetectRegion regions = 5; +} + +message DetectRegion { + // Coordinates + float top = 1 [(gogoproto.jsontag) = "top"]; + float left = 2 [(gogoproto.jsontag) = "left"]; + float bottom = 3 [(gogoproto.jsontag) = "bottom"]; + float right = 4 [(gogoproto.jsontag) = "right"]; + // What to detect + map detect = 5; } // Area for detection diff --git a/tftoolchain.sh b/tftoolchain.sh index e5ce9a9..b4762d9 100755 --- a/tftoolchain.sh +++ b/tftoolchain.sh @@ -1,1076 +1,232 @@ #!/bin/bash -if [ "$CROSSTOOL_COMPILER" == "yes" ]; then - WORKDIR="$(realpath $(dirname $0))" - CROSSTOOL_DIR="${WORKDIR}/toolchain/${CROSSTOOL_DIR}/" - mkdir -p ${WORKDIR}/toolchain/ - wget --no-check-certificate $CROSSTOOL_URL -O toolchain.tar.xz - tar xf toolchain.tar.xz -C ${WORKDIR}/toolchain/ - rm toolchain.tar.xz &>/dev/null +WORKDIR="$(realpath $(dirname $0))" +CROSSTOOL_DIR="${WORKDIR}/toolchain/${CROSSTOOL_DIR}/" +mkdir -p ${WORKDIR}/toolchain/ +wget --no-check-certificate $CROSSTOOL_URL -O toolchain.tar.xz +tar xf toolchain.tar.xz -C ${WORKDIR}/toolchain/ +rm toolchain.tar.xz &>/dev/null - [ -z "$CROSSTOOL_EXTRA_INCLUDE" ] && CROSSTOOL_EXTRA_INCLUDE="/usr/local/include/" - CROSSTOOL_VERSION=$($CROSSTOOL_DIR/bin/$CROSSTOOL_NAME-gcc -dumpversion) - git apply << EOF -diff --git a/BUILD.local_arm_compiler b/BUILD.local_arm_compiler -new file mode 100644 -index 000000000..e5d8cc384 -+++ b/BUILD.local_arm_compiler -@@ -0,0 +1,81 @@ -+package(default_visibility = ['//visibility:public']) -+ -+filegroup( -+ name = 'gcc', -+ srcs = [ -+ 'bin/$CROSSTOOL_NAME-gcc', -+ ], -+) -+ -+filegroup( -+ name = 'ar', -+ srcs = [ -+ 'bin/$CROSSTOOL_NAME-ar', -+ ], -+) -+ -+filegroup( -+ name = 'ld', -+ srcs = [ -+ 'bin/$CROSSTOOL_NAME-ld', -+ ], -+) -+ -+filegroup( -+ name = 'nm', -+ srcs = [ -+ 'bin/$CROSSTOOL_NAME-nm', -+ ], -+) -+ -+filegroup( -+ name = 'objcopy', -+ srcs = [ -+ 'bin/$CROSSTOOL_NAME-objcopy', -+ ], -+) -+ -+filegroup( -+ name = 'objdump', -+ srcs = [ -+ 'bin/$CROSSTOOL_NAME-objdump', -+ ], -+) -+ -+filegroup( -+ name = 'strip', -+ srcs = [ -+ 'bin/$CROSSTOOL_NAME-strip', -+ ], -+) -+ -+filegroup( -+ name = 'as', -+ srcs = [ -+ 'bin/$CROSSTOOL_NAME-as', -+ ], -+) -+ -+filegroup( -+ name = 'compiler_pieces', -+ srcs = glob([ -+ '$CROSSTOOL_NAME/**', -+ 'libexec/**', -+ 'lib/gcc/$CROSSTOOL_NAME/**', -+ 'include/**', -+ ]), -+) -+ -+filegroup( -+ name = 'compiler_components', -+ srcs = [ -+ ':gcc', -+ ':ar', -+ ':ld', -+ ':nm', -+ ':objcopy', -+ ':objdump', -+ ':strip', -+ ':as', -+ ], -+) -diff --git a/WORKSPACE b/WORKSPACE -index babb14b509..bb62b3e0ab 100644 ---- a/WORKSPACE -+++ b/WORKSPACE -@@ -145,3 +145,9 @@ http_archive( - "https://storage.googleapis.com/download.tensorflow.org/models/speech_commands_v0.01.zip", +CROSSTOOL_EXTRA_INCLUDE="/usr/local/include/" +CROSSTOOL_VERSION=$($CROSSTOOL_DIR/bin/$CROSSTOOL_NAME-gcc -dumpversion) +git apply << EOF +diff --git a/third_party/toolchains/cpus/arm/BUILD b/third_party/toolchains/cpus/arm/BUILD +index 5d388e918b..5e44b7e702 100644 +--- a/third_party/toolchains/cpus/arm/BUILD ++++ b/third_party/toolchains/cpus/arm/BUILD +@@ -64,5 +64,5 @@ cc_toolchain( + strip_files = "arm_linux_all_files", + supports_param_files = 1, + toolchain_config = ":armeabi_config", +- toolchain_identifier = "arm-linux-gnueabihf", ++ toolchain_identifier = "$CROSSTOOL_NAME", + ) +diff --git a/arm_compiler.BUILD b/arm_compiler.BUILD +index cffe3fac70..dbde41825c 100644 +--- a/arm_compiler.BUILD ++++ b/arm_compiler.BUILD +@@ -3,65 +3,65 @@ package(default_visibility = ["//visibility:public"]) + filegroup( + name = "gcc", + srcs = [ +- "bin/arm-rpi-linux-gnueabihf-gcc", ++ "bin/$CROSSTOOL_NAME-gcc", ], ) -+ -+new_local_repository( -+ name = "local_arm_compiler", -+ path = "$CROSSTOOL_DIR", -+ build_file = "BUILD.local_arm_compiler", -+) -diff --git a/tools/local_arm_compiler/BUILD b/tools/local_arm_compiler/BUILD -new file mode 100644 -index 000000000..ccddd6d50 -+++ b/tools/local_arm_compiler/BUILD -@@ -0,0 +1,50 @@ -+package(default_visibility = ["//visibility:public"]) -+ -+cc_toolchain_suite( -+ name = 'toolchain', -+ toolchains = { -+ 'armeabi|compiler':':cc-compiler-armeabi', -+ "local|compiler": ":cc-compiler-local", -+ "armeabi": ":cc-compiler-armeabi", -+ "k8": ":cc-compiler-local", -+ "piii": ":cc-compiler-local", -+ "arm": ":cc-compiler-local", -+ "s390x": ":cc-compiler-local", -+ }, -+) -+ -+filegroup( -+ name = "empty", -+ srcs = [], -+) -+ -+filegroup( -+ name = 'linaro_linux_all_files', -+ srcs = [ -+ '@local_arm_compiler//:compiler_pieces', -+ ], -+) -+ -+cc_toolchain( -+ name = "cc-compiler-local", -+ all_files = ":empty", -+ compiler_files = ":empty", -+ cpu = "local", -+ dwp_files = ":empty", -+ linker_files = ":empty", -+ objcopy_files = ":empty", -+ strip_files = ":empty", -+ supports_param_files = 1, -+ toolchain_identifier = "local_linux", -+) -+cc_toolchain( -+ name = 'cc-compiler-armeabi', -+ all_files = ':linaro_linux_all_files', -+ compiler_files = ':linaro_linux_all_files', -+ cpu = 'armeabi', -+ dwp_files = ':empty', -+ linker_files = ':linaro_linux_all_files', -+ objcopy_files = 'linaro_linux_all_files', -+ strip_files = 'linaro_linux_all_files', -+ supports_param_files = 1, -+ toolchain_identifier = "$CROSSTOOL_NAME",) -diff --git a/tools/local_arm_compiler/CROSSTOOL b/tools/local_arm_compiler/CROSSTOOL -new file mode 100644 -index 000000000..3ff006da8 -+++ b/tools/local_arm_compiler/CROSSTOOL -@@ -0,0 +1,862 @@ -+major_version: "local" -+minor_version: "" -+default_target_cpu: "same_as_host" -+ -+ -+ -+ -+ -+ -+ -+ -+ -+default_toolchain { -+ cpu: "darwin" -+ toolchain_identifier: "local_darwin" -+} -+default_toolchain { -+ cpu: "freebsd" -+ toolchain_identifier: "local_freebsd" -+} -+default_toolchain { -+ cpu: "armeabi" -+ toolchain_identifier: "$CROSSTOOL_NAME" -+} -+default_toolchain { -+ cpu: "arm" -+ toolchain_identifier: "local_linux" -+} -+default_toolchain { -+ cpu: "x64_windows" -+ toolchain_identifier: "local_windows_msys64" -+} -+default_toolchain { -+ cpu: "x64_windows_msvc" -+ toolchain_identifier: "vc_14_0_x64" -+} -+default_toolchain { -+ cpu: "s390x" -+ toolchain_identifier: "local_linux" -+} -+ -+toolchain { -+ abi_version: "armeabi" -+ abi_libc_version: "armeabi" -+ builtin_sysroot: "" -+ compiler: "compiler" -+ host_system_name: "armeabi" -+ needsPic: true -+ supports_gold_linker: false -+ supports_incremental_linker: false -+ supports_fission: false -+ supports_interface_shared_objects: false -+ supports_normalizing_ar: false -+ supports_start_end_lib: false -+ target_libc: "armeabi" -+ target_cpu: "armeabi" -+ target_system_name: "armeabi" -+ toolchain_identifier: "$CROSSTOOL_NAME" -+ tool_path { name: "ar" path: "$CROSSTOOL_DIR/bin/$CROSSTOOL_NAME-ar" } -+ tool_path { name: "compat-ld" path: "/bin/false" } -+ tool_path { name: "cpp" path: "$CROSSTOOL_DIR/bin/$CROSSTOOL_NAME-cpp" } -+ tool_path { name: "dwp" path: "$CROSSTOOL_DIR/bin/$CROSSTOOL_NAME-dwp" } -+ tool_path { name: "gcc" path: "$CROSSTOOL_DIR/bin/$CROSSTOOL_NAME-gcc" } -+ tool_path { name: "gcov" path: "$CROSSTOOL_DIR/bin/$CROSSTOOL_NAME-gcov" } -+ tool_path { name: "ld" path: "$CROSSTOOL_DIR/bin/$CROSSTOOL_NAME-ld" } -+ tool_path { name: "nm" path: "$CROSSTOOL_DIR/bin/$CROSSTOOL_NAME-nm" } -+ tool_path { name: "objcopy" path: "$CROSSTOOL_DIR/bin/$CROSSTOOL_NAME-objcopy" } -+ tool_path { name: "objdump" path: "$CROSSTOOL_DIR/bin/$CROSSTOOL_NAME-objdump" } -+ tool_path { name: "strip" path: "$CROSSTOOL_DIR/bin/$CROSSTOOL_NAME-strip" } -+ -+ cxx_builtin_include_directory: "$CROSSTOOL_DIR/$CROSSTOOL_NAME/include/c++/$CROSSTOOL_VERSION/" -+ cxx_builtin_include_directory: "$CROSSTOOL_DIR/$CROSSTOOL_NAME/sysroot/usr/include/" -+ cxx_builtin_include_directory: "$CROSSTOOL_DIR/$CROSSTOOL_NAME/libc/usr/include/" -+ cxx_builtin_include_directory: "$CROSSTOOL_DIR/lib/gcc/$CROSSTOOL_NAME/$CROSSTOOL_VERSION/include" -+ cxx_builtin_include_directory: "$CROSSTOOL_DIR/lib/gcc/$CROSSTOOL_NAME/$CROSSTOOL_VERSION/include-fixed" -+ cxx_builtin_include_directory: "/usr/include" -+ cxx_builtin_include_directory: "/usr/include/$CROSSTOOL_NAME" -+ cxx_builtin_include_directory: "$CROSSTOOL_EXTRA_INCLUDE" -+ -+ cxx_flag: "-std=c++11" -+ cxx_flag: "-isystem" -+ cxx_flag: "/usr/include" -+ cxx_flag: "-isystem" -+ cxx_flag: "/usr/include/$CROSSTOOL_NAME" -+ linker_flag: "-lstdc++" -+ -+ unfiltered_cxx_flag: "-Wno-builtin-macro-redefined" -+ unfiltered_cxx_flag: "-D__DATE__=\"redacted\"" -+ unfiltered_cxx_flag: "-D__TIMESTAMP__=\"redacted\"" -+ unfiltered_cxx_flag: "-D__TIME__=\"redacted\"" -+ -+ unfiltered_cxx_flag: "-no-canonical-prefixes" -+ unfiltered_cxx_flag: "-fno-canonical-system-headers" -+ -+ compiler_flag: "-U_FORTIFY_SOURCE" -+ compiler_flag: "-D_FORTIFY_SOURCE=1" -+ compiler_flag: "-fstack-protector" -+ linker_flag: "-Wl,-z,relro,-z,now" -+ -+ linker_flag: "-no-canonical-prefixes" -+ linker_flag: "-pass-exit-codes" -+ linker_flag: "-Wl,--build-id=md5" -+ linker_flag: "-Wl,--hash-style=gnu" -+ -+ compilation_mode_flags { -+ mode: DBG -+ compiler_flag: "-g" -+ } -+ compilation_mode_flags { -+ mode: OPT -+ # No debug symbols. -+ # Maybe we should enable https://gcc.gnu.org/wiki/DebugFission for opt or -+ # even generally? However, that can't happen here, as it requires special -+ # handling in Bazel. -+ compiler_flag: "-g0" -+ # Conservative choice for -O -+ # -O3 can increase binary size and even slow down the resulting binaries. -+ # Profile first and / or use FDO if you need better performance than this. -+ compiler_flag: "-O2" -+ -+ # Disable assertions -+ compiler_flag: "-DNDEBUG" -+ -+ # Removal of unused code and data at link time (can this increase binary size in some cases?). -+ compiler_flag: "-ffunction-sections" -+ compiler_flag: "-fdata-sections" -+ linker_flag: "-Wl,--gc-sections" -+ } -+ linking_mode_flags { mode: DYNAMIC } -+} -+ -+toolchain { -+ abi_version: "local" -+ abi_libc_version: "local" -+ builtin_sysroot: "" -+ compiler: "compiler" -+ host_system_name: "local" -+ needsPic: true -+ supports_gold_linker: false -+ supports_incremental_linker: false -+ supports_fission: false -+ supports_interface_shared_objects: false -+ supports_normalizing_ar: false -+ supports_start_end_lib: false -+ target_libc: "local" -+ target_cpu: "local" -+ target_system_name: "local" -+ toolchain_identifier: "local_linux" -+ -+ tool_path { name: "ar" path: "/usr/bin/ar" } -+ tool_path { name: "compat-ld" path: "/usr/bin/ld" } -+ tool_path { name: "cpp" path: "/usr/bin/cpp" } -+ tool_path { name: "dwp" path: "/usr/bin/dwp" } -+ tool_path { name: "gcc" path: "/usr/bin/gcc" } -+ cxx_flag: "-std=c++0x" -+ linker_flag: "-lstdc++" -+ linker_flag: "-B/usr/bin/" -+ -+ # TODO(bazel-team): In theory, the path here ought to exactly match the path -+ # used by gcc. That works because bazel currently doesn't track files at -+ # absolute locations and has no remote execution, yet. However, this will need -+ # to be fixed, maybe with auto-detection? -+ cxx_builtin_include_directory: "/usr/lib/gcc/" -+ cxx_builtin_include_directory: "/usr/local/include" -+ cxx_builtin_include_directory: "/usr/include" -+ tool_path { name: "gcov" path: "/usr/bin/gcov" } -+ -+ # C(++) compiles invoke the compiler (as that is the one knowing where -+ # to find libraries), but we provide LD so other rules can invoke the linker. -+ tool_path { name: "ld" path: "/usr/bin/ld" } -+ -+ tool_path { name: "nm" path: "/usr/bin/nm" } -+ tool_path { name: "objcopy" path: "/usr/bin/objcopy" } -+ objcopy_embed_flag: "-I" -+ objcopy_embed_flag: "binary" -+ tool_path { name: "objdump" path: "/usr/bin/objdump" } -+ tool_path { name: "strip" path: "/usr/bin/strip" } -+ -+ # Anticipated future default. -+ unfiltered_cxx_flag: "-no-canonical-prefixes" -+ unfiltered_cxx_flag: "-fno-canonical-system-headers" -+ -+ # Make C++ compilation deterministic. Use linkstamping instead of these -+ # compiler symbols. -+ unfiltered_cxx_flag: "-Wno-builtin-macro-redefined" -+ unfiltered_cxx_flag: "-D__DATE__=\"redacted\"" -+ unfiltered_cxx_flag: "-D__TIMESTAMP__=\"redacted\"" -+ unfiltered_cxx_flag: "-D__TIME__=\"redacted\"" -+ -+ # Security hardening on by default. -+ # Conservative choice; -D_FORTIFY_SOURCE=2 may be unsafe in some cases. -+ # We need to undef it before redefining it as some distributions now have -+ # it enabled by default. -+ compiler_flag: "-U_FORTIFY_SOURCE" -+ compiler_flag: "-D_FORTIFY_SOURCE=1" -+ compiler_flag: "-fstack-protector" -+ linker_flag: "-Wl,-z,relro,-z,now" -+ -+ # Enable coloring even if there's no attached terminal. Bazel removes the -+ # escape sequences if --nocolor is specified. This isn't supported by gcc -+ # on Ubuntu 14.04. -+ # compiler_flag: "-fcolor-diagnostics" -+ -+ # All warnings are enabled. Maybe enable -Werror as well? -+ compiler_flag: "-Wall" -+ # Enable a few more warnings that aren't part of -Wall. -+ compiler_flag: "-Wunused-but-set-parameter" -+ # But disable some that are problematic. -+ compiler_flag: "-Wno-free-nonheap-object" # has false positives -+ -+ # Keep stack frames for debugging, even in opt mode. -+ compiler_flag: "-fno-omit-frame-pointer" -+ -+ # Anticipated future default. -+ linker_flag: "-no-canonical-prefixes" -+ # Have gcc return the exit code from ld. -+ linker_flag: "-pass-exit-codes" -+ # Stamp the binary with a unique identifier. -+ linker_flag: "-Wl,--build-id=md5" -+ linker_flag: "-Wl,--hash-style=gnu" -+ # Gold linker only? Can we enable this by default? -+ # linker_flag: "-Wl,--warn-execstack" -+ # linker_flag: "-Wl,--detect-odr-violations" -+ -+ compilation_mode_flags { -+ mode: DBG -+ # Enable debug symbols. -+ compiler_flag: "-g" -+ } -+ compilation_mode_flags { -+ mode: OPT -+ -+ # No debug symbols. -+ # Maybe we should enable https://gcc.gnu.org/wiki/DebugFission for opt or -+ # even generally? However, that can't happen here, as it requires special -+ # handling in Bazel. -+ compiler_flag: "-g0" -+ -+ # Conservative choice for -O -+ # -O3 can increase binary size and even slow down the resulting binaries. -+ # Profile first and / or use FDO if you need better performance than this. -+ compiler_flag: "-O2" -+ -+ # Disable assertions -+ compiler_flag: "-DNDEBUG" -+ -+ # Removal of unused code and data at link time (can this increase binary size in some cases?). -+ compiler_flag: "-ffunction-sections" -+ compiler_flag: "-fdata-sections" -+ linker_flag: "-Wl,--gc-sections" -+ } -+ linking_mode_flags { mode: DYNAMIC } -+} -+ -+toolchain { -+ abi_version: "local" -+ abi_libc_version: "local" -+ builtin_sysroot: "" -+ compiler: "compiler" -+ host_system_name: "local" -+ needsPic: true -+ target_libc: "macosx" -+ target_cpu: "darwin" -+ target_system_name: "local" -+ toolchain_identifier: "local_darwin" -+ -+ tool_path { name: "ar" path: "/usr/bin/libtool" } -+ tool_path { name: "compat-ld" path: "/usr/bin/ld" } -+ tool_path { name: "cpp" path: "/usr/bin/cpp" } -+ tool_path { name: "dwp" path: "/usr/bin/dwp" } -+ tool_path { name: "gcc" path: "osx_cc_wrapper.sh" } -+ cxx_flag: "-std=c++0x" -+ ar_flag: "-static" -+ ar_flag: "-s" -+ ar_flag: "-o" -+ linker_flag: "-lstdc++" -+ linker_flag: "-undefined" -+ linker_flag: "dynamic_lookup" -+ linker_flag: "-headerpad_max_install_names" -+ # TODO(ulfjack): This is wrong on so many levels. Figure out a way to auto-detect the proper -+ # setting from the local compiler, and also how to make incremental builds correct. -+ cxx_builtin_include_directory: "/" -+ tool_path { name: "gcov" path: "/usr/bin/gcov" } -+ tool_path { name: "ld" path: "/usr/bin/ld" } -+ tool_path { name: "nm" path: "/usr/bin/nm" } -+ tool_path { name: "objcopy" path: "/usr/bin/objcopy" } -+ objcopy_embed_flag: "-I" -+ objcopy_embed_flag: "binary" -+ tool_path { name: "objdump" path: "/usr/bin/objdump" } -+ tool_path { name: "strip" path: "/usr/bin/strip" } -+ -+ # Anticipated future default. -+ unfiltered_cxx_flag: "-no-canonical-prefixes" -+ -+ # Make C++ compilation deterministic. Use linkstamping instead of these -+ # compiler symbols. -+ unfiltered_cxx_flag: "-Wno-builtin-macro-redefined" -+ unfiltered_cxx_flag: "-D__DATE__=\"redacted\"" -+ unfiltered_cxx_flag: "-D__TIMESTAMP__=\"redacted\"" -+ unfiltered_cxx_flag: "-D__TIME__=\"redacted\"" -+ -+ # Security hardening on by default. -+ # Conservative choice; -D_FORTIFY_SOURCE=2 may be unsafe in some cases. -+ compiler_flag: "-D_FORTIFY_SOURCE=1" -+ compiler_flag: "-fstack-protector" -+ -+ # Enable coloring even if there's no attached terminal. Bazel removes the -+ # escape sequences if --nocolor is specified. -+ compiler_flag: "-fcolor-diagnostics" -+ -+ # All warnings are enabled. Maybe enable -Werror as well? -+ compiler_flag: "-Wall" -+ # Enable a few more warnings that aren't part of -Wall. -+ compiler_flag: "-Wthread-safety" -+ compiler_flag: "-Wself-assign" -+ -+ # Keep stack frames for debugging, even in opt mode. -+ compiler_flag: "-fno-omit-frame-pointer" -+ -+ # Anticipated future default. -+ linker_flag: "-no-canonical-prefixes" -+ -+ compilation_mode_flags { -+ mode: DBG -+ # Enable debug symbols. -+ compiler_flag: "-g" -+ } -+ compilation_mode_flags { -+ mode: OPT -+ # No debug symbols. -+ # Maybe we should enable https://gcc.gnu.org/wiki/DebugFission for opt or even generally? -+ # However, that can't happen here, as it requires special handling in Bazel. -+ compiler_flag: "-g0" -+ -+ # Conservative choice for -O -+ # -O3 can increase binary size and even slow down the resulting binaries. -+ # Profile first and / or use FDO if you need better performance than this. -+ compiler_flag: "-O2" -+ -+ # Disable assertions -+ compiler_flag: "-DNDEBUG" -+ -+ # Removal of unused code and data at link time (can this increase binary size in some cases?). -+ compiler_flag: "-ffunction-sections" -+ compiler_flag: "-fdata-sections" -+ } -+ linking_mode_flags { mode: DYNAMIC } -+} -+ -+toolchain { -+ abi_version: "local" -+ abi_libc_version: "local" -+ builtin_sysroot: "" -+ compiler: "compiler" -+ host_system_name: "local" -+ needsPic: true -+ supports_gold_linker: false -+ supports_incremental_linker: false -+ supports_fission: false -+ supports_interface_shared_objects: false -+ supports_normalizing_ar: false -+ supports_start_end_lib: false -+ target_libc: "local" -+ target_cpu: "freebsd" -+ target_system_name: "local" -+ toolchain_identifier: "local_freebsd" -+ -+ tool_path { name: "ar" path: "/usr/bin/ar" } -+ tool_path { name: "compat-ld" path: "/usr/bin/ld" } -+ tool_path { name: "cpp" path: "/usr/bin/cpp" } -+ tool_path { name: "dwp" path: "/usr/bin/dwp" } -+ tool_path { name: "gcc" path: "/usr/bin/clang" } -+ cxx_flag: "-std=c++0x" -+ linker_flag: "-lstdc++" -+ linker_flag: "-B/usr/bin/" -+ -+ # TODO(bazel-team): In theory, the path here ought to exactly match the path -+ # used by gcc. That works because bazel currently doesn't track files at -+ # absolute locations and has no remote execution, yet. However, this will need -+ # to be fixed, maybe with auto-detection? -+ cxx_builtin_include_directory: "/usr/lib/clang" -+ cxx_builtin_include_directory: "/usr/local/include" -+ cxx_builtin_include_directory: "/usr/include" -+ tool_path { name: "gcov" path: "/usr/bin/gcov" } -+ -+ # C(++) compiles invoke the compiler (as that is the one knowing where -+ # to find libraries), but we provide LD so other rules can invoke the linker. -+ tool_path { name: "ld" path: "/usr/bin/ld" } -+ -+ tool_path { name: "nm" path: "/usr/bin/nm" } -+ tool_path { name: "objcopy" path: "/usr/bin/objcopy" } -+ objcopy_embed_flag: "-I" -+ objcopy_embed_flag: "binary" -+ tool_path { name: "objdump" path: "/usr/bin/objdump" } -+ tool_path { name: "strip" path: "/usr/bin/strip" } -+ -+ # Anticipated future default. -+ unfiltered_cxx_flag: "-no-canonical-prefixes" -+ -+ # Make C++ compilation deterministic. Use linkstamping instead of these -+ # compiler symbols. -+ unfiltered_cxx_flag: "-Wno-builtin-macro-redefined" -+ unfiltered_cxx_flag: "-D__DATE__=\"redacted\"" -+ unfiltered_cxx_flag: "-D__TIMESTAMP__=\"redacted\"" -+ unfiltered_cxx_flag: "-D__TIME__=\"redacted\"" -+ -+ # Security hardening on by default. -+ # Conservative choice; -D_FORTIFY_SOURCE=2 may be unsafe in some cases. -+ # We need to undef it before redefining it as some distributions now have -+ # it enabled by default. -+ compiler_flag: "-U_FORTIFY_SOURCE" -+ compiler_flag: "-D_FORTIFY_SOURCE=1" -+ compiler_flag: "-fstack-protector" -+ linker_flag: "-Wl,-z,relro,-z,now" -+ -+ # Enable coloring even if there's no attached terminal. Bazel removes the -+ # escape sequences if --nocolor is specified. This isn't supported by gcc -+ # on Ubuntu 14.04. -+ # compiler_flag: "-fcolor-diagnostics" -+ -+ # All warnings are enabled. Maybe enable -Werror as well? -+ compiler_flag: "-Wall" -+ # Enable a few more warnings that aren't part of -Wall. -+ #compiler_flag: "-Wunused-but-set-parameter" -+ # But disable some that are problematic. -+ #compiler_flag: "-Wno-free-nonheap-object" # has false positives -+ -+ # Keep stack frames for debugging, even in opt mode. -+ compiler_flag: "-fno-omit-frame-pointer" -+ -+ # Anticipated future default. -+ linker_flag: "-no-canonical-prefixes" -+ # Have gcc return the exit code from ld. -+ #linker_flag: "-pass-exit-codes" -+ # Stamp the binary with a unique identifier. -+ #linker_flag: "-Wl,--build-id=md5" -+ linker_flag: "-Wl,--hash-style=gnu" -+ # Gold linker only? Can we enable this by default? -+ # linker_flag: "-Wl,--warn-execstack" -+ # linker_flag: "-Wl,--detect-odr-violations" -+ -+ compilation_mode_flags { -+ mode: DBG -+ # Enable debug symbols. -+ compiler_flag: "-g" -+ } -+ compilation_mode_flags { -+ mode: OPT -+ -+ # No debug symbols. -+ # Maybe we should enable https://gcc.gnu.org/wiki/DebugFission for opt or -+ # even generally? However, that can't happen here, as it requires special -+ # handling in Bazel. -+ compiler_flag: "-g0" -+ -+ # Conservative choice for -O -+ # -O3 can increase binary size and even slow down the resulting binaries. -+ # Profile first and / or use FDO if you need better performance than this. -+ compiler_flag: "-O2" -+ -+ # Disable assertions -+ compiler_flag: "-DNDEBUG" -+ -+ # Removal of unused code and data at link time (can this increase binary size in some cases?). -+ compiler_flag: "-ffunction-sections" -+ compiler_flag: "-fdata-sections" -+ linker_flag: "-Wl,--gc-sections" -+ } -+ linking_mode_flags { mode: DYNAMIC } -+} -+ -+toolchain { -+ abi_version: "local" -+ abi_libc_version: "local" -+ builtin_sysroot: "" -+ compiler: "windows_mingw" -+ host_system_name: "local" -+ needsPic: false -+ target_libc: "local" -+ target_cpu: "x64_windows" -+ target_system_name: "local" -+ toolchain_identifier: "local_windows_mingw" -+ -+ tool_path { name: "ar" path: "C:/mingw/bin/ar" } -+ tool_path { name: "compat-ld" path: "C:/mingw/bin/ld" } -+ tool_path { name: "cpp" path: "C:/mingw/bin/cpp" } -+ tool_path { name: "dwp" path: "C:/mingw/bin/dwp" } -+ tool_path { name: "gcc" path: "C:/mingw/bin/gcc" } -+ cxx_flag: "-std=c++0x" -+ # TODO(bazel-team): In theory, the path here ought to exactly match the path -+ # used by gcc. That works because bazel currently doesn't track files at -+ # absolute locations and has no remote execution, yet. However, this will need -+ # to be fixed, maybe with auto-detection? -+ cxx_builtin_include_directory: "C:/mingw/include" -+ cxx_builtin_include_directory: "C:/mingw/lib/gcc" -+ tool_path { name: "gcov" path: "C:/mingw/bin/gcov" } -+ tool_path { name: "ld" path: "C:/mingw/bin/ld" } -+ tool_path { name: "nm" path: "C:/mingw/bin/nm" } -+ tool_path { name: "objcopy" path: "C:/mingw/bin/objcopy" } -+ objcopy_embed_flag: "-I" -+ objcopy_embed_flag: "binary" -+ tool_path { name: "objdump" path: "C:/mingw/bin/objdump" } -+ tool_path { name: "strip" path: "C:/mingw/bin/strip" } -+ linking_mode_flags { mode: DYNAMIC } -+} -+ -+toolchain { -+ abi_version: "local" -+ abi_libc_version: "local" -+ builtin_sysroot: "" -+ compiler: "windows_msys64_mingw64" -+ host_system_name: "local" -+ needsPic: false -+ target_libc: "local" -+ target_cpu: "x64_windows" -+ target_system_name: "local" -+ toolchain_identifier: "local_windows_msys64_mingw64" -+ -+ tool_path { name: "ar" path: "C:/tools/msys64/mingw64/bin/ar" } -+ tool_path { name: "compat-ld" path: "C:/tools/msys64/mingw64/bin/ld" } -+ tool_path { name: "cpp" path: "C:/tools/msys64/mingw64/bin/cpp" } -+ tool_path { name: "dwp" path: "C:/tools/msys64/mingw64/bin/dwp" } -+ tool_path { name: "gcc" path: "C:/tools/msys64/mingw64/bin/gcc" } -+ cxx_flag: "-std=c++0x" -+ # TODO(bazel-team): In theory, the path here ought to exactly match the path -+ # used by gcc. That works because bazel currently doesn't track files at -+ # absolute locations and has no remote execution, yet. However, this will need -+ # to be fixed, maybe with auto-detection? -+ cxx_builtin_include_directory: "C:/tools/msys64/mingw64/x86_64-w64-mingw32/include" -+ tool_path { name: "gcov" path: "C:/tools/msys64/mingw64/bin/gcov" } -+ tool_path { name: "ld" path: "C:/tools/msys64/mingw64/bin/ld" } -+ tool_path { name: "nm" path: "C:/tools/msys64/mingw64/bin/nm" } -+ tool_path { name: "objcopy" path: "C:/tools/msys64/mingw64/bin/objcopy" } -+ objcopy_embed_flag: "-I" -+ objcopy_embed_flag: "binary" -+ tool_path { name: "objdump" path: "C:/tools/msys64/mingw64/bin/objdump" } -+ tool_path { name: "strip" path: "C:/tools/msys64/mingw64/bin/strip" } -+ linking_mode_flags { mode: DYNAMIC } -+} -+ -+toolchain { -+ abi_version: "local" -+ abi_libc_version: "local" -+ builtin_sysroot: "" -+ compiler: "windows_clang" -+ host_system_name: "local" -+ needsPic: false -+ target_libc: "local" -+ target_cpu: "x64_windows" -+ target_system_name: "local" -+ toolchain_identifier: "local_windows_clang" -+ -+ tool_path { name: "ar" path: "C:/mingw/bin/ar" } -+ tool_path { name: "compat-ld" path: "C:/Program Files (x86)/LLVM/bin/ld" } -+ tool_path { name: "cpp" path: "C:/Program Files (x86)/LLVM/bin/cpp" } -+ tool_path { name: "dwp" path: "C:/Program Files (x86)/LLVM/bin/dwp" } -+ tool_path { name: "gcc" path: "C:/Program Files (x86)/LLVM/bin/clang" } -+ cxx_flag: "-std=c++0x" -+ # TODO(bazel-team): In theory, the path here ought to exactly match the path -+ # used by gcc. That works because bazel currently doesn't track files at -+ # absolute locations and has no remote execution, yet. However, this will need -+ # to be fixed, maybe with auto-detection? -+ cxx_builtin_include_directory: "/usr/lib/gcc/" -+ cxx_builtin_include_directory: "/usr/local/include" -+ cxx_builtin_include_directory: "/usr/include" -+ tool_path { name: "gcov" path: "C:/Program Files (x86)/LLVM/bin/gcov" } -+ tool_path { name: "ld" path: "C:/Program Files (x86)/LLVM/bin/ld" } -+ tool_path { name: "nm" path: "C:/Program Files (x86)/LLVM/bin/nm" } -+ tool_path { name: "objcopy" path: "C:/Program Files (x86)/LLVM/bin/objcopy" } -+ objcopy_embed_flag: "-I" -+ objcopy_embed_flag: "binary" -+ tool_path { name: "objdump" path: "C:/Program Files (x86)/LLVM/bin/objdump" } -+ tool_path { name: "strip" path: "C:/Program Files (x86)/LLVM/bin/strip" } -+ linking_mode_flags { mode: DYNAMIC } -+} -+ -+toolchain { -+ abi_version: "local" -+ abi_libc_version: "local" -+ builtin_sysroot: "" -+ compiler: "windows_msys64" -+ host_system_name: "local" -+ needsPic: false -+ target_libc: "local" -+ target_cpu: "x64_windows" -+ target_system_name: "local" -+ toolchain_identifier: "local_windows_msys64" -+ -+ tool_path { name: "ar" path: "C:/tools/msys64/usr/bin/ar" } -+ tool_path { name: "compat-ld" path: "C:/tools/msys64/usr/bin/ld" } -+ tool_path { name: "cpp" path: "C:/tools/msys64/usr/bin/cpp" } -+ tool_path { name: "dwp" path: "C:/tools/msys64/usr/bin/dwp" } -+ # Use gcc instead of g++ so that C will compile correctly. -+ tool_path { name: "gcc" path: "C:/tools/msys64/usr/bin/gcc" } -+ cxx_flag: "-std=gnu++0x" -+ linker_flag: "-lstdc++" -+ # TODO(bazel-team): In theory, the path here ought to exactly match the path -+ # used by gcc. That works because bazel currently doesn't track files at -+ # absolute locations and has no remote execution, yet. However, this will need -+ # to be fixed, maybe with auto-detection? -+ cxx_builtin_include_directory: "C:/tools/msys64/" -+ cxx_builtin_include_directory: "/usr/" -+ tool_path { name: "gcov" path: "C:/tools/msys64/usr/bin/gcov" } -+ tool_path { name: "ld" path: "C:/tools/msys64/usr/bin/ld" } -+ tool_path { name: "nm" path: "C:/tools/msys64/usr/bin/nm" } -+ tool_path { name: "objcopy" path: "C:/tools/msys64/usr/bin/objcopy" } -+ objcopy_embed_flag: "-I" -+ objcopy_embed_flag: "binary" -+ tool_path { name: "objdump" path: "C:/tools/msys64/usr/bin/objdump" } -+ tool_path { name: "strip" path: "C:/tools/msys64/usr/bin/strip" } -+ linking_mode_flags { mode: DYNAMIC } -+} -+ -+toolchain { -+ toolchain_identifier: "vc_14_0_x64" -+ host_system_name: "local" -+ target_system_name: "local" -+ -+ abi_version: "local" -+ abi_libc_version: "local" -+ target_cpu: "x64_windows_msvc" -+ compiler: "cl" -+ target_libc: "msvcrt140" -+ default_python_version: "python2.7" -+ cxx_builtin_include_directory: "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/INCLUDE" -+ cxx_builtin_include_directory: "C:/Program Files (x86)/Windows Kits/10/include/" -+ cxx_builtin_include_directory: "C:/Program Files (x86)/Windows Kits/8.1/include/" -+ cxx_builtin_include_directory: "C:/Program Files (x86)/GnuWin32/include/" -+ cxx_builtin_include_directory: "C:/python_27_amd64/files/include" -+ tool_path { -+ name: "ar" -+ path: "wrapper/bin/msvc_link.bat" -+ } -+ tool_path { -+ name: "cpp" -+ path: "wrapper/bin/msvc_cl.bat" -+ } -+ tool_path { -+ name: "gcc" -+ path: "wrapper/bin/msvc_cl.bat" -+ } -+ tool_path { -+ name: "gcov" -+ path: "wrapper/bin/msvc_nop.bat" -+ } -+ tool_path { -+ name: "ld" -+ path: "wrapper/bin/msvc_link.bat" -+ } -+ tool_path { -+ name: "nm" -+ path: "wrapper/bin/msvc_nop.bat" -+ } -+ tool_path { -+ name: "objcopy" -+ path: "wrapper/bin/msvc_nop.bat" -+ } -+ tool_path { -+ name: "objdump" -+ path: "wrapper/bin/msvc_nop.bat" -+ } -+ tool_path { -+ name: "strip" -+ path: "wrapper/bin/msvc_nop.bat" -+ } -+ supports_gold_linker: false -+ supports_start_end_lib: false -+ supports_interface_shared_objects: false -+ supports_incremental_linker: false -+ supports_normalizing_ar: true -+ needsPic: false -+ -+ compiler_flag: "-m64" -+ compiler_flag: "/D__inline__=__inline" -+ # TODO(pcloudy): Review those flags below, they should be defined by cl.exe -+ compiler_flag: "/DOS_WINDOWS=OS_WINDOWS" -+ compiler_flag: "/DCOMPILER_MSVC" -+ -+ # Don't pollute with GDI macros in windows.h. -+ compiler_flag: "/DNOGDI" -+ # Don't define min/max macros in windows.h. -+ compiler_flag: "/DNOMINMAX" -+ compiler_flag: "/DPRAGMA_SUPPORTED" -+ # Platform defines. -+ compiler_flag: "/D_WIN32_WINNT=0x0600" -+ # Turn off warning messages. -+ compiler_flag: "/D_CRT_SECURE_NO_DEPRECATE" -+ compiler_flag: "/D_CRT_SECURE_NO_WARNINGS" -+ compiler_flag: "/D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS" -+ # Use math constants (M_PI, etc.) from the math library -+ compiler_flag: "/D_USE_MATH_DEFINES" -+ -+ # Useful options to have on for compilation. -+ # Suppress startup banner. -+ compiler_flag: "/nologo" -+ # Increase the capacity of object files to 2^32 sections. -+ compiler_flag: "/bigobj" -+ # Allocate 500MB for precomputed headers. -+ compiler_flag: "/Zm500" -+ # Use unsigned char by default. -+ compiler_flag: "/J" -+ # Use function level linking. -+ compiler_flag: "/Gy" -+ # Use string pooling. -+ compiler_flag: "/GF" -+ # Warning level 3 (could possibly go to 4 in the future). -+ compiler_flag: "/W3" -+ # Catch both asynchronous (structured) and synchronous (C++) exceptions. -+ compiler_flag: "/EHsc" -+ -+ # Globally disabled warnings. -+ # Don't warn about elements of array being be default initialized. -+ compiler_flag: "/wd4351" -+ # Don't warn about no matching delete found. -+ compiler_flag: "/wd4291" -+ # Don't warn about diamond inheritance patterns. -+ compiler_flag: "/wd4250" -+ # Don't warn about insecure functions (e.g. non _s functions). -+ compiler_flag: "/wd4996" -+ -+ linker_flag: "-m64" -+ -+ feature { -+ name: 'include_paths' -+ flag_set { -+ action: 'preprocess-assemble' -+ action: 'c-compile' -+ action: 'c++-compile' -+ action: 'c++-header-parsing' -+ action: 'c++-header-preprocessing' -+ action: 'c++-module-compile' -+ flag_group { -+ flag: '/I%{quote_include_paths}' -+ } -+ flag_group { -+ flag: '/I%{include_paths}' -+ } -+ flag_group { -+ flag: '/I%{system_include_paths}' -+ } -+ } -+ } -+ -+ feature { -+ name: 'dependency_file' -+ flag_set { -+ action: 'assemble' -+ action: 'preprocess-assemble' -+ action: 'c-compile' -+ action: 'c++-compile' -+ action: 'c++-module-compile' -+ action: 'c++-header-preprocessing' -+ action: 'c++-header-parsing' -+ expand_if_all_available: 'dependency_file' -+ flag_group { -+ flag: '/DEPENDENCY_FILE' -+ flag: '%{dependency_file}' -+ } -+ } -+ } -+ -+ # Stop passing -frandom-seed option -+ feature { -+ name: 'random_seed' -+ } -+ -+ # This feature is just for enabling flag_set in action_config for -c and -o options during the transitional period -+ feature { -+ name: 'compile_action_flags_in_flag_set' -+ } -+ -+ action_config { -+ config_name: 'c-compile' -+ action_name: 'c-compile' -+ tool { -+ tool_path: 'wrapper/bin/msvc_cl.bat' -+ } -+ flag_set { -+ flag_group { -+ flag: '/c' -+ flag: '%{source_file}' -+ } -+ } -+ flag_set { -+ expand_if_all_available: 'output_object_file' -+ flag_group { -+ flag: '/Fo%{output_object_file}' -+ } -+ } -+ flag_set { -+ expand_if_all_available: 'output_assembly_file' -+ flag_group { -+ flag: '/Fa%{output_assembly_file}' -+ } -+ } -+ flag_set { -+ expand_if_all_available: 'output_preprocess_file' -+ flag_group { -+ flag: '/P' -+ flag: '/Fi%{output_preprocess_file}' -+ } -+ } -+ } -+ action_config { -+ config_name: 'c++-compile' -+ action_name: 'c++-compile' -+ tool { -+ tool_path: 'wrapper/bin/msvc_cl.bat' -+ } -+ -+ flag_set { -+ flag_group { -+ flag: '/c' -+ flag: '%{source_file}' -+ } -+ } -+ -+ flag_set { -+ expand_if_all_available: 'output_object_file' -+ flag_group { -+ flag: '/Fo%{output_object_file}' -+ } -+ } -+ -+ flag_set { -+ expand_if_all_available: 'output_assembly_file' -+ flag_group { -+ flag: '/Fa%{output_assembly_file}' -+ } -+ } -+ -+ flag_set { -+ expand_if_all_available: 'output_preprocess_file' -+ flag_group { -+ flag: '/P' -+ flag: '/Fi%{output_preprocess_file}' -+ } -+ } -+ } -+ -+ compilation_mode_flags { -+ mode: DBG -+ compiler_flag: "/DDEBUG=1" -+ compiler_flag: "-g" -+ compiler_flag: "/Od" -+ compiler_flag: "-Xcompilation-mode=dbg" -+ } -+ -+ compilation_mode_flags { -+ mode: FASTBUILD -+ compiler_flag: "/DNDEBUG" -+ compiler_flag: "/Od" -+ compiler_flag: "-Xcompilation-mode=fastbuild" -+ } -+ -+ compilation_mode_flags { -+ mode: OPT -+ compiler_flag: "/DNDEBUG" -+ compiler_flag: "/O2" -+ compiler_flag: "-Xcompilation-mode=opt" -+ } -+} -diff --git a/tensorflow/lite/kernels/internal/BUILD b/tensorflow/lite/kernels/internal/BUILD -index 5bafcdc00c..7fb7b4a4ef 100644 ---- a/tensorflow/lite/kernels/internal/BUILD -+++ b/tensorflow/lite/kernels/internal/BUILD -@@ -23,6 +23,9 @@ NEON_FLAGS_IF_APPLICABLE = select({ - ":arm": [ - "-O3", - "-mfpu=neon", -+ ], -+ ":armeabi": [ -+ "-O3", + + filegroup( + name = "ar", + srcs = [ +- "bin/arm-rpi-linux-gnueabihf-ar", ++ "bin/$CROSSTOOL_NAME-ar", ], - ":armeabi-v7a": [ - "-O3", -@@ -76,6 +79,13 @@ config_setting( - }, ) -+config_setting( -+ name = "armeabi", -+ values = { -+ "cpu": "armeabi", -+ }, -+) -+ - config_setting( - name = "arm64-v8a", - values = { -@@ -572,6 +582,9 @@ cc_library( - ], - ":arm64-v8a": [ - ":neon_tensor_utils", -+ ], -+ ":armeabi": [ -+ ":neon_tensor_utils", - ], - ":armeabi-v7a": [ - ":neon_tensor_utils", -EOF + filegroup( + name = "ld", + srcs = [ +- "bin/arm-rpi-linux-gnueabihf-ld", ++ "bin/$CROSSTOOL_NAME-ld", + ], + ) + + filegroup( + name = "nm", + srcs = [ +- "bin/arm-rpi-linux-gnueabihf-nm", ++ "bin/$CROSSTOOL_NAME-nm", + ], + ) + + filegroup( + name = "objcopy", + srcs = [ +- "bin/arm-rpi-linux-gnueabihf-objcopy", ++ "bin/$CROSSTOOL_NAME-objcopy", + ], + ) + + filegroup( + name = "objdump", + srcs = [ +- "bin/arm-rpi-linux-gnueabihf-objdump", ++ "bin/$CROSSTOOL_NAME-objdump", + ], + ) + + filegroup( + name = "strip", + srcs = [ +- "bin/arm-rpi-linux-gnueabihf-strip", ++ "bin/$CROSSTOOL_NAME-strip", + ], + ) + + filegroup( + name = "as", + srcs = [ +- "bin/arm-rpi-linux-gnueabihf-as", ++ "bin/$CROSSTOOL_NAME-as", + ], + ) + + filegroup( + name = "compiler_pieces", + srcs = glob([ +- "arm-linux-gnueabihf/**", ++ "$CROSSTOOL_NAME/**", + "libexec/**", +- "lib/gcc/arm-linux-gnueabihf/**", ++ "lib/gcc/$CROSSTOOL_NAME/**", + "include/**", + ]), + ) +diff --git a/third_party/toolchains/cpus/arm/cc_config.bzl.tpl b/third_party/toolchains/cpus/arm/cc_config.bzl.tpl +index bfe91e711b..da292cdcaf 100644 +--- a/third_party/toolchains/cpus/arm/cc_config.bzl.tpl ++++ b/third_party/toolchains/cpus/arm/cc_config.bzl.tpl +@@ -17,7 +17,7 @@ load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") + + def _impl(ctx): + if (ctx.attr.cpu == "armeabi"): +- toolchain_identifier = "arm-linux-gnueabihf" ++ toolchain_identifier = "$CROSSTOOL_NAME" + elif (ctx.attr.cpu == "local"): + toolchain_identifier = "local_linux" + else: +@@ -269,7 +269,6 @@ def _impl(ctx): + "-U_FORTIFY_SOURCE", + "-D_FORTIFY_SOURCE=1", + "-fstack-protector", +- "-DRASPBERRY_PI", + ], + ), + ], +@@ -331,17 +330,23 @@ def _impl(ctx): + flags = [ + "-std=c++11", + "-isystem", +- "%{ARM_COMPILER_PATH}%/lib/gcc/arm-rpi-linux-gnueabihf/6.5.0/include", ++ "$CROSSTOOL_DIR/$CROSSTOOL_NAME/include/c++/$CROSSTOOL_VERSION/", + "-isystem", +- "%{ARM_COMPILER_PATH}%/lib/gcc/arm-rpi-linux-gnueabihf/6.5.0/include-fixed", ++ "$CROSSTOOL_DIR/$CROSSTOOL_NAME/sysroot/usr/include/", + "-isystem", +- "%{ARM_COMPILER_PATH}%/arm-rpi-linux-gnueabihf/sysroot/usr/include/", ++ "$CROSSTOOL_DIR/$CROSSTOOL_NAME/libc/usr/include/", + "-isystem", +- "%{ARM_COMPILER_PATH}%/arm-rpi-linux-gnueabihf/include/c++/6.5.0/", ++ "$CROSSTOOL_DIR/lib/gcc/$CROSSTOOL_NAME/$CROSSTOOL_VERSION/include", ++ "-isystem", ++ "$CROSSTOOL_DIR/lib/gcc/$CROSSTOOL_NAME/$CROSSTOOL_VERSION/include-fixed", ++ "-isystem", ++ "$CROSSTOOL_ROOT/usr/include", ++ "-isystem", ++ "$CROSSTOOL_ROOT/usr/include/$CROSSTOOL_NAME", ++ "-isystem", ++ "$CROSSTOOL_EXTRA_INCLUDE", + "-isystem", + "%{PYTHON_INCLUDE_PATH}%", +- "-isystem", +- "/usr/include/", + ], + ), + ], +@@ -559,12 +564,15 @@ def _impl(ctx): -fi \ No newline at end of file + if (ctx.attr.cpu == "armeabi"): + cxx_builtin_include_directories = [ +- "%{ARM_COMPILER_PATH}%/lib/gcc/arm-rpi-linux-gnueabihf/6.5.0/include", +- "%{ARM_COMPILER_PATH}%/lib/gcc/arm-rpi-linux-gnueabihf/6.5.0/include-fixed", +- "%{ARM_COMPILER_PATH}%/arm-rpi-linux-gnueabihf/sysroot/usr/include/", +- "%{ARM_COMPILER_PATH}%/arm-rpi-linux-gnueabihf/include/c++/6.5.0/", ++ "$CROSSTOOL_DIR/$CROSSTOOL_NAME/include/c++/$CROSSTOOL_VERSION/", ++ "$CROSSTOOL_DIR/$CROSSTOOL_NAME/sysroot/usr/include/", ++ "$CROSSTOOL_DIR/$CROSSTOOL_NAME/libc/usr/include/", ++ "$CROSSTOOL_DIR/lib/gcc/$CROSSTOOL_NAME/$CROSSTOOL_VERSION/include", ++ "$CROSSTOOL_DIR/lib/gcc/$CROSSTOOL_NAME/$CROSSTOOL_VERSION/include-fixed", +- "/usr/include", ++ "$CROSSTOOL_ROOT/usr/include", +- "/tmp/openblas_install/include/", ++ "/usr/include/$CROSSTOOL_NAME", ++ "$CROSSTOOL_EXTRA_INCLUDE", ++ "%{PYTHON_INCLUDE_PATH}%" + ] + elif (ctx.attr.cpu == "local"): + cxx_builtin_include_directories = ["/usr/lib/gcc/", "/usr/local/include", "/usr/include"] +@@ -579,44 +587,44 @@ def _impl(ctx): + tool_paths = [ + tool_path( + name = "ar", +- path = "%{ARM_COMPILER_PATH}%/bin/arm-rpi-linux-gnueabihf-ar", ++ path = "$CROSSTOOL_DIR/bin/$CROSSTOOL_NAME-ar", + ), + tool_path(name = "compat-ld", path = "/bin/false"), + tool_path( + name = "cpp", +- path = "%{ARM_COMPILER_PATH}%/bin/arm-rpi-linux-gnueabihf-cpp", ++ path = "$CROSSTOOL_DIR/bin/$CROSSTOOL_NAME-cpp", + ), + tool_path( + name = "dwp", +- path = "%{ARM_COMPILER_PATH}%/bin/arm-rpi-linux-gnueabihf-dwp", ++ path = "$CROSSTOOL_DIR/bin/$CROSSTOOL_NAME-dwp", + ), + tool_path( + name = "gcc", +- path = "%{ARM_COMPILER_PATH}%/bin/arm-rpi-linux-gnueabihf-gcc", ++ path = "$CROSSTOOL_DIR/bin/$CROSSTOOL_NAME-gcc", + ), + tool_path( + name = "gcov", +- path = "%{ARM_COMPILER_PATH}%/bin/arm-rpi-linux-gnueabihf-gcov", ++ path = "$CROSSTOOL_DIR/bin/$CROSSTOOL_NAME-gcov", + ), + tool_path( + name = "ld", +- path = "%{ARM_COMPILER_PATH}%/bin/arm-rpi-linux-gnueabihf-ld", ++ path = "$CROSSTOOL_DIR/bin/$CROSSTOOL_NAME-ld", + ), + tool_path( + name = "nm", +- path = "%{ARM_COMPILER_PATH}%/bin/arm-rpi-linux-gnueabihf-nm", ++ path = "$CROSSTOOL_DIR/bin/$CROSSTOOL_NAME-nm", + ), + tool_path( + name = "objcopy", +- path = "%{ARM_COMPILER_PATH}%/bin/arm-rpi-linux-gnueabihf-objcopy", ++ path = "$CROSSTOOL_DIR/bin/$CROSSTOOL_NAME-objcopy", + ), + tool_path( + name = "objdump", +- path = "%{ARM_COMPILER_PATH}%/bin/arm-rpi-linux-gnueabihf-objdump", ++ path = "$CROSSTOOL_DIR/bin/$CROSSTOOL_NAME-objdump", + ), + tool_path( + name = "strip", +- path = "%{ARM_COMPILER_PATH}%/bin/arm-rpi-linux-gnueabihf-strip", ++ path = "$CROSSTOOL_DIR/bin/$CROSSTOOL_NAME-strip", + ), + ] + elif (ctx.attr.cpu == "local"): +EOF