From f6133bfcf9a1ae8f56e0a3c860b745b70071e871 Mon Sep 17 00:00:00 2001 From: Kellen Sunderland Date: Thu, 6 Sep 2018 15:12:34 +0200 Subject: [PATCH] [MXNET-703] Use static libs for TensorRT Moving a few libraries to static linking to mitigate risk of dep conflicts. --- Makefile | 4 +++- ci/docker/install/tensorrt.sh | 2 +- ci/docker/runtime_functions.sh | 13 +++++++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index ad7f0ff3485f..1b4b21888a9c 100644 --- a/Makefile +++ b/Makefile @@ -99,7 +99,9 @@ endif ifeq ($(USE_TENSORRT), 1) CFLAGS += -I$(ROOTDIR) -I$(TPARTYDIR) -DONNX_NAMESPACE=$(ONNX_NAMESPACE) -DMXNET_USE_TENSORRT=1 - LDFLAGS += -lprotobuf -pthread -lonnx -lonnx_proto -lnvonnxparser -lnvonnxparser_runtime -lnvinfer -lnvinfer_plugin + LDFLAGS += -lprotobuf -pthread -lonnx -l:libonnx_proto.a -l:libnvonnxparser_static.a \ + -l:libnvonnxparser_runtime_static.a -l:libnvonnxparser_plugin.a -lnvinfer -lnvinfer_plugin \ + -l:libonnx_proto.a -l:libonnxtrt_proto.a endif # -L/usr/local/lib diff --git a/ci/docker/install/tensorrt.sh b/ci/docker/install/tensorrt.sh index 641a88e5dc91..1950cad0b52f 100755 --- a/ci/docker/install/tensorrt.sh +++ b/ci/docker/install/tensorrt.sh @@ -26,7 +26,7 @@ pip3 install gluoncv==0.2.0 pushd . cd .. apt-get update -apt-get install -y automake libtool +apt-get install -y automake libtool zip git clone --recursive -b 3.5.1.1 https://github.com/google/protobuf.git cd protobuf ./autogen.sh diff --git a/ci/docker/runtime_functions.sh b/ci/docker/runtime_functions.sh index 2ddbc84a8841..c564699c9716 100755 --- a/ci/docker/runtime_functions.sh +++ b/ci/docker/runtime_functions.sh @@ -79,6 +79,8 @@ build_wheel() { export MXNET_LIBRARY_PATH=${BUILD_DIR}/libmxnet.so cd ${PYTHON_DIR} + + # If building for redistribution edit the name in this setup.py python setup.py bdist_wheel --universal # repackage @@ -96,6 +98,8 @@ build_wheel() { rm -rf ${TMPDIR} popd + + # If redistributing you may now run `twine upload -r pypi *.whl` } # Build commands: Every platform in docker/Dockerfile.build. should have a corresponding @@ -498,7 +502,7 @@ build_ubuntu_gpu_tensorrt() { cd build cmake \ -DCMAKE_CXX_FLAGS=-I/usr/include/python${PYVER}\ - -DBUILD_SHARED_LIBS=ON ..\ + -DBUILD_SHARED_LIBS=OFF ..\ -G Ninja ninja -j 1 -v onnx/onnx.proto ninja -j 1 -v @@ -514,12 +518,11 @@ build_ubuntu_gpu_tensorrt() { cmake .. make -j$(nproc) export LIBRARY_PATH=`pwd`:$LIBRARY_PATH + export LIBRARY_PATH=$LIBRARY_PATH:`pwd`/third_party/onnx/ + mv third_party/onnx/libonnx_proto.a third_party/onnx/libonnxtrt_proto.a popd mkdir -p /work/mxnet/lib/ - cp 3rdparty/onnx-tensorrt/third_party/onnx/build/*.so /work/mxnet/lib/ - cp -L 3rdparty/onnx-tensorrt/build/libnvonnxparser_runtime.so.0 /work/mxnet/lib/ - cp -L 3rdparty/onnx-tensorrt/build/libnvonnxparser.so.0 /work/mxnet/lib/ rm -rf build make \ @@ -537,6 +540,8 @@ build_ubuntu_gpu_tensorrt() { ONNX_NAMESPACE=onnx \ CUDA_ARCH="-gencode arch=compute_70,code=compute_70" \ -j$(nproc) + + build_wheel /work/mxnet/python /work/mxnet/lib } build_ubuntu_gpu_mkldnn() {