serving icon indicating copy to clipboard operation
serving copied to clipboard

Compiling 1.8.0 version with GPU support based on nvidia/cuda:9.0-cudnn7-devel-ubuntu16.04

Open frallain opened this issue 8 years ago • 34 comments

Hi, I use this Dockerfile

# https://github.com/tensorflow/serving/blob/master/tensorflow_serving/tools/docker/Dockerfile.devel-gpu

FROM nvidia/cuda:9.0-cudnn7-devel-ubuntu16.04

RUN apt-get update && apt-get install -y \
        automake \
        bash-completion \
        build-essential \
        curl \
        git \
        g++ \
        libfreetype6-dev \
        libpng12-dev \
        libtool \
        libzmq3-dev \
        mlocate \
        pkg-config \
        python-dev \
        python-numpy \
        python-pip \
        software-properties-common \
        swig \
        unzip \
        zip \
        zlib1g-dev \
        libcurl3-dev \
        openjdk-8-jdk\
        openjdk-8-jre-headless \
        wget \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# Set up grpc
RUN pip install mock grpcio

# Bazel
# required by TensorFlow
# sudo apt-get install pkg-config zip g++ zlib1g-dev unzip python
# https://github.com/bazelbuild/bazel/releases/
ENV BAZEL_VERSION=0.14.1
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


# Build TensorFlow with the CUDA configuration
ENV CI_BUILD_PYTHON python
ENV LD_LIBRARY_PATH /usr/local/cuda/extras/CUPTI/lib64:$LD_LIBRARY_PATH
ENV TF_NEED_CUDA 1
ENV TF_CUDA_COMPUTE_CAPABILITIES=3.0,3.5,5.2,6.0,6.1,7.0
ENV TF_CUDA_VERSION=9.0
ENV TF_CUDNN_VERSION=7

# Fix paths so that CUDNN can be found: https://github.com/tensorflow/tensorflow/issues/8264

WORKDIR /
RUN mkdir /usr/lib/x86_64-linux-gnu/include/ && \
  ln -s /usr/lib/x86_64-linux-gnu/include/cudnn.h /usr/lib/x86_64-linux-gnu/include/cudnn.h && \
  ln -s /usr/include/cudnn.h /usr/local/cuda/include/cudnn.h && \
  ln -s /usr/lib/x86_64-linux-gnu/libcudnn.so /usr/local/cuda/lib64/libcudnn.so && \
  ln -s /usr/lib/x86_64-linux-gnu/libcudnn.so.$TF_CUDNN_VERSION /usr/local/cuda/lib64/libcudnn.so.$TF_CUDNN_VERSION


# Fix paths so that NCCL can be found
# https://github.com/tensorflow/serving/issues/327
ENV TF_NCCL_VERSION=2.2.12
RUN echo "deb http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64 /" > /etc/apt/sources.list.d/nvidia-ml.list
RUN apt-get update && apt-get install -y --no-install-recommends \
        libnccl2=${TF_NCCL_VERSION}-1+cuda${TF_CUDA_VERSION} \
        libnccl-dev=${TF_NCCL_VERSION}-1+cuda${TF_CUDA_VERSION} \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

ENV NCCL_INSTALL_PATH=/usr/lib/nccl/
WORKDIR /
RUN mkdir /usr/lib/nccl && \
  mkdir /usr/lib/nccl/include/ && \
  mkdir /usr/lib/nccl/lib/ && \
  ln -s /usr/include/nccl.h /usr/lib/nccl/include/nccl.h && \
  ln -s /usr/lib/x86_64-linux-gnu/libnccl.so /usr/lib/nccl/lib/libnccl.so && \
  ln -s /usr/lib/x86_64-linux-gnu/libnccl.so.2 /usr/lib/nccl/lib/libnccl.so.2 && \
  ln -s /usr/lib/x86_64-linux-gnu/libnccl.so.$TF_NCCL_VERSION /usr/lib/nccl/lib/libnccl.so.$TF_NCCL_VERSION


# Download, build, and install TensorFlow Serving
ARG TF_SERVING_VERSION=1.8.0
WORKDIR /tensorflow-serving

RUN apt-get update && apt-get install -y --no-install-recommends \
       libevent-dev \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

RUN git clone --recurse-submodules https://github.com/tensorflow/serving \
    && cd serving \
    && git checkout $TF_SERVING_VERSION \
    && bazel build --jobs 16 -c opt --config=cuda -k --verbose_failures \
        --crosstool_top=@local_config_cuda//crosstool:toolchain \
        tensorflow_serving/model_servers:tensorflow_model_server \
    && cp bazel-bin/tensorflow_serving/model_servers/tensorflow_model_server /usr/local/bin/ \
    && bazel clean --expunge \
    && cd / && rm -rf /tensorflow-serving

and I hit this error:

[4,514 / 4,517] Compiling external/org_tensorflow/tensorflow/core/kernels/tile_functor_gpu.cu.cc; 505s local
ERROR: /tensorflow-serving/serving/tensorflow_serving/model_servers/BUILD:270:1: Couldn't build file tensorflow_serving/model_servers/tensorflow_model_server: Linking of rule '//tensorflow_serving/model_servers:tensorflow_model_server' failed (Exit 1): crosstool_wrapper_driver_is_not_gcc failed: error executing command
  (cd /root/.cache/bazel/_bazel_root/86e62be83a53cf1af5b8032777534537/execroot/tf_serving && \
  exec env - \
    LD_LIBRARY_PATH=/usr/local/cuda/extras/CUPTI/lib64:/usr/local/nvidia/lib:/usr/local/nvidia/lib64 \
    PATH=/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
    PWD=/proc/self/cwd \
    PYTHON_BIN_PATH=/usr/bin/python \
  external/local_config_cuda/crosstool/clang/bin/crosstool_wrapper_driver_is_not_gcc -o bazel-out/k8-opt/bin/tensorflow_serving/model_servers/tensorflow_model_server '-Wl,-rpath,$ORIGIN/../../_solib_local/_U@local_Uconfig_Ucuda_S_Scuda_Ccusolver___Uexternal_Slocal_Uconfig_Ucuda_Scuda_Scuda_Slib' '-Wl,-rpath,$ORIGIN/../../_solib_local/_U@local_Uconfig_Unccl_S_S_Cnccl___Uexternal_Slocal_Uconfig_Unccl_Snccl_Slib' '-Wl,-rpath,$ORIGIN/../../_solib_local/_U@local_Uconfig_Ucuda_S_Scuda_Ccublas___Uexternal_Slocal_Uconfig_Ucuda_Scuda_Scuda_Slib' '-Wl,-rpath,$ORIGIN/../../_solib_local/_U@local_Uconfig_Ucuda_S_Scuda_Ccuda_Udriver___Uexternal_Slocal_Uconfig_Ucuda_Scuda_Scuda_Slib' '-Wl,-rpath,$ORIGIN/../../_solib_local/_U@local_Uconfig_Ucuda_S_Scuda_Ccudnn___Uexternal_Slocal_Uconfig_Ucuda_Scuda_Scuda_Slib' '-Wl,-rpath,$ORIGIN/../../_solib_local/_U@local_Uconfig_Ucuda_S_Scuda_Ccufft___Uexternal_Slocal_Uconfig_Ucuda_Scuda_Scuda_Slib' '-Wl,-rpath,$ORIGIN/../../_solib_local/_U@local_Uconfig_Ucuda_S_Scuda_Ccurand___Uexternal_Slocal_Uconfig_Ucuda_Scuda_Scuda_Slib' '-Wl,-rpath,$ORIGIN/../../_solib_local/_U@local_Uconfig_Ucuda_S_Scuda_Ccudart___Uexternal_Slocal_Uconfig_Ucuda_Scuda_Scuda_Slib' -Lbazel-out/k8-opt/bin/_solib_local/_U@local_Uconfig_Ucuda_S_Scuda_Ccusolver___Uexternal_Slocal_Uconfig_Ucuda_Scuda_Scuda_Slib -Lbazel-out/k8-opt/bin/_solib_local/_U@local_Uconfig_Unccl_S_S_Cnccl___Uexternal_Slocal_Uconfig_Unccl_Snccl_Slib -Lbazel-out/k8-opt/bin/_solib_local/_U@local_Uconfig_Ucuda_S_Scuda_Ccublas___Uexternal_Slocal_Uconfig_Ucuda_Scuda_Scuda_Slib -Lbazel-out/k8-opt/bin/_solib_local/_U@local_Uconfig_Ucuda_S_Scuda_Ccuda_Udriver___Uexternal_Slocal_Uconfig_Ucuda_Scuda_Scuda_Slib -Lbazel-out/k8-opt/bin/_solib_local/_U@local_Uconfig_Ucuda_S_Scuda_Ccudnn___Uexternal_Slocal_Uconfig_Ucuda_Scuda_Scuda_Slib -Lbazel-out/k8-opt/bin/_solib_local/_U@local_Uconfig_Ucuda_S_Scuda_Ccufft___Uexternal_Slocal_Uconfig_Ucuda_Scuda_Scuda_Slib -Lbazel-out/k8-opt/bin/_solib_local/_U@local_Uconfig_Ucuda_S_Scuda_Ccurand___Uexternal_Slocal_Uconfig_Ucuda_Scuda_Scuda_Slib -Lbazel-out/k8-opt/bin/_solib_local/_U@local_Uconfig_Ucuda_S_Scuda_Ccudart___Uexternal_Slocal_Uconfig_Ucuda_Scuda_Scuda_Slib -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -Wl,-z,notext -Wl,-z,muldefs -Wl,-z,notext -Wl,-z,notext -Wl,-z,notext -Wl,-z,notext -Wl,-z,notext -Wl,-z,notext -Wl,-z,notext -Wl,-z,notext -Wl,-z,notext -Wl,-z,notext -Wl,-z,notext -Wl,-z,notext -Wl,-z,notext -Wl,-z,notext -Wl,-z,notext -Wl,-z,notext -Wl,-z,notext -Wl,-z,notext -Wl,-z,notext -pthread -Wl,-rpath,../local_config_cuda/cuda/lib64 -Wl,-rpath,../local_config_cuda/cuda/extras/CUPTI/lib64 -Wl,-no-as-needed -B/usr/bin/ -pie -Wl,-z,relro,-z,now -no-canonical-prefixes -pass-exit-codes '-Wl,--build-id=md5' '-Wl,--hash-style=gnu' -Wl,--gc-sections -Wl,@bazel-out/k8-opt/bin/tensorflow_serving/model_servers/tensorflow_model_server-2.params)
/usr/bin/ld: bazel-out/k8-opt/genfiles/external/com_github_libevent_libevent/libevent/lib/libevent.a(buffer.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
bazel-out/k8-opt/genfiles/external/com_github_libevent_libevent/libevent/lib/libevent.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
Target //tensorflow_serving/model_servers:tensorflow_model_server failed to build
INFO: Elapsed time: 1579.845s, Critical Path: 603.27s
INFO: 3721 processes, local.
FAILED: Build did NOT complete successfully
FAILED: Build did NOT complete successfully

I tried to add --copt="-fPIC" to the bazel command as recommended, to no success. I tried to apt install libevent-dev beforehand, to no success. Any ideas?

frallain avatar Jun 19 '18 15:06 frallain

Is it possible to compile tf-serving against the system libevent lib? because /usr/lib/x86_64-linux-gnu/libevent.so is present in the container.

frallain avatar Jun 19 '18 15:06 frallain

I'm having the same issue on Ubuntu 16.04 outside of docker

omrishiv avatar Jun 19 '18 17:06 omrishiv

I just tried with the template at https://github.com/tensorflow/serving/blob/master/tensorflow_serving/tools/docker/Dockerfile.devel-gpu , by changing TF_SERVING_VERSION_GIT_BRANCH to r1.8.

I had to install nvcc before the # Fix paths so that NCCL can be found part.

ENV TF_NCCL_VERSION=2.2.12
RUN echo "deb http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64 /" > /etc/apt/sources.list.d/nvidia-ml.list
RUN apt-get update && apt-get install -y --no-install-recommends \
        libnccl2=${TF_NCCL_VERSION}-1+cuda${TF_CUDA_VERSION} \
        libnccl-dev=${TF_NCCL_VERSION}-1+cuda${TF_CUDA_VERSION} \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

To eventually hit the same error:

NFO: Analysed target //tensorflow_serving/model_servers:tensorflow_model_server (125 packages loaded).
INFO: Found 1 target...
ERROR: /tensorflow-serving/tensorflow_serving/model_servers/BUILD:270:1: Linking of rule '//tensorflow_serving/model_servers:tensorflow_model_server' failed (Exit 1)
/usr/bin/ld: bazel-out/k8-opt/genfiles/external/com_github_libevent_libevent/libevent/lib/libevent.a(buffer.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
bazel-out/k8-opt/genfiles/external/com_github_libevent_libevent/libevent/lib/libevent.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
Target //tensorflow_serving/model_servers:tensorflow_model_server failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 1411.856s, Critical Path: 696.51s
FAILED: Build did NOT complete successfully

frallain avatar Jun 19 '18 18:06 frallain

+ 1 Same error un 18.04 LTS

hienphamlabs avatar Jun 20 '18 09:06 hienphamlabs

I eventually got it working by modifying serving/third_party/libevent.BUILD with these changes:

 lib_files = [
-    "libevent/lib/libevent.a",
+    "libevent/lib/libevent.so",
     "libevent/lib/libevent_core.a",
     "libevent/lib/libevent_extra.a",
-    "libevent/lib/libevent_pthreads.a",
+    "libevent/lib/libevent_pthreads.so",
 ]

genrule(
    name = "libevent-srcs",
    outs = include_files + lib_files,
    cmd = "\n".join([
        "export INSTALL_DIR=$$(pwd)/$(@D)/libevent",
        "export TMP_DIR=$$(mktemp -d -t libevent.XXXXX)",
        "mkdir -p $$TMP_DIR",
         "cp -R $$(pwd)/external/com_github_libevent_libevent/* $$TMP_DIR",
         "cd $$TMP_DIR",
         "./autogen.sh",
-        "./configure --prefix=$$INSTALL_DIR --enable-shared=no --disable-openssl",
+        "./configure --prefix=$$INSTALL_DIR --disable-openssl",
         "make install",
         "rm -rf $$TMP_DIR",
     ]),

 cc_library(
     name = "libevent",
     srcs = [
-        "libevent/lib/libevent.a",
-        "libevent/lib/libevent_pthreads.a",
+        "libevent/lib/libevent.so",
+        "libevent/lib/libevent_pthreads.so",
     ],
     hdrs = include_files,
     linkopts = ["-lpthread"],
    includes = ["libevent/include"],
    linkstatic = 1,
)

And then after compilation has ended:

cp /root/.cache/bazel/_bazel_root/64b3ff9b6976aaa0c1b20ff9a9038d9e/execroot/tf_serving/bazel-out/k8-opt/genfiles/external/com_github_libevent_libevent/libevent/lib/libevent-2.1.so.6.0.2 /usr/lib/x86_64-linux-gnu/
cp /root/.cache/bazel/_bazel_root/64b3ff9b6976aaa0c1b20ff9a9038d9e/execroot/tf_serving/bazel-out/k8-opt/genfiles/external/com_github_libevent_libevent/libevent/lib/libevent_pthreads-2.1.so.6 /usr/lib/x86_64-linux-gnu/
ldconfig
cp bazel-bin/tensorflow_serving/model_servers/tensorflow_model_server /usr/local/bin/ \
bazel clean --expunge \

frallain avatar Jun 20 '18 11:06 frallain

Did you remove the --copt="-fPIC"? I just tried again and am seeing another error: /usr/bin/ld: bazel-out/k8-opt/bin/external/com_google_absl/absl/time/libtime.a(duration.o): undefined reference to symbol 'floor@@GLIBC_2.2.5'

omrishiv avatar Jun 20 '18 15:06 omrishiv

@OmriShiv Yes :

# Download, build, and install TensorFlow Serving
ARG TF_SERVING_VERSION=1.8.0
WORKDIR /tensorflow-serving

RUN git clone --recurse-submodules https://github.com/tensorflow/serving \
    && cd serving \
    && git checkout $TF_SERVING_VERSION \
    && rm third_party/libevent.BUILD

COPY libevent.BUILD /tensorflow-serving/serving/third_party/libevent.BUILD

WORKDIR /tensorflow-serving/serving
RUN bazel build -c opt --config=cuda -k --verbose_failures \
        --crosstool_top=@local_config_cuda//crosstool:toolchain \
        tensorflow_serving/model_servers:tensorflow_model_server

RUN libevent_so_path=$(dirname $(find /root/.cache/bazel/_bazel_root/ -iname "libevent-2.1.so.6.0.2")) \
    && cp -r $libevent_so_path/* /usr/lib/ \
    && ldconfig \
    && cp bazel-bin/tensorflow_serving/model_servers/tensorflow_model_server /usr/local/bin/ \
    && bazel clean --expunge \
&& cd / && rm -rf /tensorflow-serving

frallain avatar Jun 20 '18 22:06 frallain

Thanks @frallain It worked!

hienphamlabs avatar Jun 25 '18 08:06 hienphamlabs

A little more futzing around and mine compiled as well. Thanks!

omrishiv avatar Jun 25 '18 18:06 omrishiv

@frallain I get error after I run bazel build -c opt --config=cuda -k --verbose_failures
--crosstool_top=@local_config_cuda//crosstool:toolchain
tensorflow_serving/model_servers:tensorflow_model_server.

Target //tensorflow_serving/model_servers:tensorflow_model_server failed to build

I modefied the serving/third_party/libevent.BUILD as you did.

CLIsVeryOK avatar Jun 26 '18 03:06 CLIsVeryOK

@CLIsVeryOK Could you print the full error message?

hienphamlabs avatar Jun 26 '18 03:06 hienphamlabs

@hienduyph only one line error message

external/org_tensorflow/tensorflow/core/kernels/cwise_ops.h(199): warning: device annotation on a defaulted function("scalar_right") is ignored

external/org_tensorflow/tensorflow/core/kernels/cwise_ops.h(169): warning: host annotation on a defaulted function("scalar_left") is ignored

external/org_tensorflow/tensorflow/core/kernels/cwise_ops.h(169): warning: device annotation on a defaulted function("scalar_left") is ignored

external/org_tensorflow/tensorflow/core/kernels/cwise_ops.h(199): warning: host annotation on a defaulted function("scalar_right") is ignored

external/org_tensorflow/tensorflow/core/kernels/cwise_ops.h(199): warning: device annotation on a defaulted function("scalar_right") is ignored

external/org_tensorflow/tensorflow/core/kernels/cwise_ops.h(169): warning: host annotation on a defaulted function("scalar_left") is ignored

external/org_tensorflow/tensorflow/core/kernels/cwise_ops.h(169): warning: device annotation on a defaulted function("scalar_left") is ignored

external/org_tensorflow/tensorflow/core/kernels/cwise_ops.h(199): warning: host annotation on a defaulted function("scalar_right") is ignored

external/org_tensorflow/tensorflow/core/kernels/cwise_ops.h(199): warning: device annotation on a defaulted function("scalar_right") is ignored

Target //tensorflow_serving/model_servers:tensorflow_model_server failed to build INFO: Elapsed time: 597.625s, Critical Path: 315.84s INFO: 3923 processes, local. FAILED: Build did NOT complete successfully

CLIsVeryOK avatar Jun 26 '18 03:06 CLIsVeryOK

@CLIsVeryOK It's weird, all of this logs are warning! Did you miss something?

hienphamlabs avatar Jun 26 '18 08:06 hienphamlabs

@hienduyph here is my steps 1.git clone --recursive https://github.com/tensorflow/serving.git 2.cd serving 3.git clone https://github.com/tensorflow/tensorflow.git 4.change tools/bazel.rc <@org_tensorflow//third_party/gpus/crosstool> to <@local_config_cuda//crosstool:toolchain> 5.cd tensorflow ./configure cd .. 6.bazel build -c opt --config=cuda tensorflow_serving/... after 6th step, the fPIC problem exit, 7. modifying serving/third_party/libevent.BUILD as @frallain 8. bazel build -c opt --config=cuda -k --verbose_failures --crosstool_top=@local_config_cuda//crosstool:toolchain tensorflow_serving/model_servers:tensorflow_model_server. the result is: Target //tensorflow_serving/model_servers:tensorflow_model_server failed to build

CLIsVeryOK avatar Jun 26 '18 08:06 CLIsVeryOK

@CLIsVeryOK Is your g++ version is 4.8 and bazel version is 0.11 ?

hienphamlabs avatar Jun 27 '18 06:06 hienphamlabs

@hienduyph no,g++&gcc 5.4.0 + bazel 0.14.1 + cuda9.0 + cuDNN7.0 + tensorflow 1.9.0 + tensorflow serving 1.8.0

CLIsVeryOK avatar Jun 27 '18 06:06 CLIsVeryOK

@CLIsVeryOK It seems that tensorflow serving has some problem with bazel > 0.11. You could try bazel 0.11

hienphamlabs avatar Jun 27 '18 12:06 hienphamlabs

Hey folks, there's an updated dockerfile.devel-gpu that works for building the latest.

gautamvasudevan avatar Jun 27 '18 22:06 gautamvasudevan

@gautamvasudevan thanks for your suggestion, I am trying this docker. The docker has been build successfully, but when I build the model using: bazel build -c opt //tensorflow_serving/example:mnist_saved_model it starts to fetching: http://github/tensorflow/archive/024aecf414941e11eb643e29ceed3e1c47a115ad.tar.gz but it seems that due to the network of China, this file can not be download. qq 20180628092306 I find the code in file: "serving/WORKSPACE, line 13-17" tensorflow_http_archive( name = "org_tensorflow", sha256 = "5b305706304c27027798feb4c0d9f6597a60cec825ebeaab507a6d7e2ee9c314", git_commit = "024aecf414941e11eb643e29ceed3e1c47a115ad", ) how can I modify it to change the download link to local because I have download the file from my windows and copy to my linux system. Best~

CLIsVeryOK avatar Jun 28 '18 01:06 CLIsVeryOK

@hienduyph thanks, I'll try it.

CLIsVeryOK avatar Jun 28 '18 01:06 CLIsVeryOK