Commit 7daccb0b authored by Narcon Nicolas's avatar Narcon Nicolas
Browse files

WIP: try to remove ltensorflow_framework when compiling (doesn't work)

No related merge requests found
Showing with 20 additions and 14 deletions
+20 -14
......@@ -40,15 +40,15 @@ WORKDIR /src/tf
RUN git config --global advice.detachedHead false
### TF
ARG TF=master
ARG TF=v2.5.0
# Install bazelisk (will read .bazelversion and download the right bazel binary - latest by default)
RUN wget -qO /opt/otbtf/bin/bazelisk https://github.com/bazelbuild/bazelisk/releases/latest/download/bazelisk-linux-amd64 \
&& chmod +x /opt/otbtf/bin/bazelisk \
&& ln -s /opt/otbtf/bin/bazelisk /opt/otbtf/bin/bazel
ARG BZL_TARGETS="//tensorflow:libtensorflow_cc.so //tensorflow/tools/pip_package:build_pip_package //tensorflow:libtensorflow_framework.so"
# "--config=opt" will enable 'march=native' (otherwise read comments about CPU compatibilty and edit CC_OPT_FLAGS in build-env-tf.sh)
ARG BZL_CONFIGS="--config=nogcp --config=noaws --config=nohdfs --config=opt"
ARG BZL_TARGETS="//tensorflow:libtensorflow_cc.so //tensorflow/tools/pip_package:build_pip_package"
# "--config=opt" will enable 'march=native' (otherwise read comments about CPU compatibility and edit CC_OPT_FLAGS in build-env-tf.sh)
ARG BZL_CONFIGS="--config=nogcp --config=noaws --config=nohdfs --config=opt --config=monolithic"
# "--compilation_mode opt" is already enabled by default (see tf repo .bazelrc and configure.py)
ARG BZL_OPTIONS="--verbose_failures --remote_cache=http://localhost:9090"
......@@ -57,7 +57,7 @@ ARG ZIP_TF_BIN=false
COPY tools/docker/build-env-tf.sh ./
RUN git clone --single-branch -b $TF https://github.com/tensorflow/tensorflow.git \
&& cd tensorflow \
&& echo "build --experimental_cc_shared_library" >> .bazelrc \
&& sed -i 's/ -ltensorflow_framework//' tensorflow/c/generate-pc.sh \
&& export PATH=$PATH:/opt/otbtf/bin \
&& export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/otbtf/lib \
&& bash -c '\
......@@ -65,34 +65,38 @@ RUN git clone --single-branch -b $TF https://github.com/tensorflow/tensorflow.gi
&& ./configure \
&& export TMP=/tmp/bazel \
&& BZL_CMD="build $BZL_TARGETS $BZL_CONFIGS $BZL_OPTIONS" \
&& bazel $BZL_CMD --jobs="HOST_CPUS*$CPU_RATIO" ' \
&& bazel $BZL_CMD --jobs="HOST_CPUS*$CPU_RATIO" '
# Installation - split here if you want to check files ^
#RUN cd tensorflow \
RUN cd tensorflow \
&& ./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg \
&& pip3 install --no-cache-dir --prefix=/opt/otbtf /tmp/tensorflow_pkg/tensorflow*.whl \
&& ln -s /opt/otbtf/lib/python3.* /opt/otbtf/lib/python3 \
&& cp -P bazel-bin/tensorflow/libtensorflow_cc.so* /opt/otbtf/lib/ \
&& cp -P bazel-bin/tensorflow/libtensorflow_framework.so* /opt/otbtf/lib/ \
&& ln -s $(find /opt/otbtf -type d -wholename "*/site-packages/tensorflow/include") /opt/otbtf/include/tf \
# The only missing header in the wheel
&& cp tensorflow/cc/saved_model/tag_constants.h /opt/otbtf/include/tf/tensorflow/cc/saved_model/ \
&& cp tensorflow/cc/saved_model/signature_constants.h /opt/otbtf/include/tf/tensorflow/cc/saved_model/ \
# Symlink external libs (required for MKL - libiomp5)
&& for f in $(find -L /opt/otbtf/include/tf -wholename "*/external/*/*.so"); do ln -s $f /opt/otbtf/lib/; done \
# Compress and save TF binaries
&& ( ! $ZIP_TF_BIN || zip -9 -j --symlinks /opt/otbtf/tf-$TF.zip tensorflow/cc/saved_model/tag_constants.h bazel-bin/tensorflow/libtensorflow_cc.so* bazel-bin/tensorflow/libtensorflow_framework.so* /tmp/tensorflow_pkg/tensorflow*.whl ) \
&& ( ! $ZIP_TF_BIN || zip -9 -j --symlinks /opt/otbtf/tf-$TF.zip tensorflow/cc/saved_model/tag_constants.h tensorflow/cc/saved_model/signature_constants.h bazel-bin/tensorflow/libtensorflow_cc.so* /tmp/tensorflow_pkg/tensorflow*.whl ) \
# Cleaning
&& rm -rf bazel-* /src/tf /root/.cache/ /tmp/*
### OTB
ARG GUI=false
ARG OTB=7.3.0
ARG OTB=7.4.0
RUN mkdir /src/otb
WORKDIR /src/otb
# SuperBuild OTB
COPY tools/docker/build-flags-otb.txt ./
RUN git clone --single-branch -b $OTB https://gitlab.orfeo-toolbox.org/orfeotoolbox/otb.git \
RUN apt-get update -y \
&& apt-get install --reinstall ca-certificates -y \
&& update-ca-certificates \
&& git clone --single-branch -b $OTB https://gitlab.orfeo-toolbox.org/orfeotoolbox/otb.git \
&& mkdir -p build \
&& cd build \
# Set GL/Qt build flags
......@@ -109,8 +113,11 @@ COPY . /src/otbtf
#RUN git clone https://github.com/remicres/otbtf.git /src/otbtf
RUN ln -s /src/otbtf /src/otb/otb/Modules/Remote/otbtf
# this is a desperate try (copy a previously compiled lib from host)
COPY libtensorflow_framework.so.2 /opt/otbtf/lib/python3/site-packages/tensorflow/.
# Rebuild OTB with module
ARG KEEP_SRC_OTB=false
ARG KEEP_SRC_OTB=true
RUN cd /src/otb/build/OTB/build \
&& export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/otbtf/lib \
&& export PATH=$PATH:/opt/otbtf/bin \
......@@ -121,8 +128,7 @@ RUN cd /src/otb/build/OTB/build \
-Dtensorflow_include_dir=/opt/otbtf/include/tf \
# Forcing TF>=2, this Dockerfile hasn't been tested with v1 + missing link for libtensorflow_framework.so in the wheel
-DTENSORFLOW_CC_LIB=/opt/otbtf/lib/libtensorflow_cc.so.2 \
#/opt/otbtf/lib/python3/site-packages/tensorflow/libtensorflow_framework.so.2 \
-DTENSORFLOW_FRAMEWORK_LIB=/opt/otbtf/lib/libtensorflow_framework.so.2 \
-DTENSORFLOW_FRAMEWORK_LIB=/opt/otbtf/lib/python3/site-packages/tensorflow/libtensorflow_framework.so.2 \
&& make install -j $(python -c "import os; print(round( os.cpu_count() * $CPU_RATIO ))") \
# Cleaning
&& ( $GUI || rm -rf /opt/otbtf/bin/otbgui* ) \
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment