Skip to content

Commit

Permalink
scripts for building libmxnet binary and wheel (apache#13648)
Browse files Browse the repository at this point in the history
* add script for making all dependencies

* tools for building pip package

* build scripts for lib and wheel
  • Loading branch information
szha authored and Ubuntu committed Dec 18, 2018
1 parent 0072d82 commit 47e2c48
Show file tree
Hide file tree
Showing 12 changed files with 399 additions and 252 deletions.
80 changes: 80 additions & 0 deletions tools/build/build_lib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env bash

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

# This script builds the libraries of mxnet.
make_config=config/pip_${PLATFORM}_${VARIANT}.mk
if [[ ! -f $make_config ]]; then
>&2 echo "Couldn't find make config $make_config for the current settings."
exit 1
fi

git clone --recursive https://github.com/apache/incubator-mxnet mxnet-build

>&2 echo "Now building mxnet modules..."
cp $make_config mxnet-build/config.mk

cd mxnet-build

make DEPS_PATH=$DEPS_PATH DMLCCORE
make DEPS_PATH=$DEPS_PATH $PWD/3rdparty/tvm/nnvm/lib/libnnvm.a
make DEPS_PATH=$DEPS_PATH PSLITE

if [[ $VARIANT == *mkl ]]; then
MKLDNN_LICENSE='license.txt'
if [[ $PLATFORM == 'linux' ]]; then
IOMP_LIBFILE='libiomp5.so'
MKLML_LIBFILE='libmklml_intel.so'
MKLDNN_LIBFILE='libmkldnn.so.0'
else
IOMP_LIBFILE='libiomp5.dylib'
MKLML_LIBFILE='libmklml.dylib'
MKLDNN_LIBFILE='libmkldnn.0.dylib'
fi
make DEPS_PATH=$DEPS_PATH mkldnn
cp 3rdparty/mkldnn/LICENSE ./MKLML_LICENSE
fi

if [[ $VARIANT == *mkl ]]; then
>&2 echo "Copying MKL license."
rm lib/libmkldnn.{so,dylib}
rm lib/libmkldnn.0.*.dylib
rm lib/libmkldnn.so.0.*
fi

>&2 echo "Now building mxnet..."
make DEPS_PATH=$DEPS_PATH || exit 1;

if [[ $PLATFORM == 'linux' ]]; then
cp -L /usr/lib/gcc/x86_64-linux-gnu/4.8/libgfortran.so lib/libgfortran.so.3
cp -L /usr/lib/x86_64-linux-gnu/libquadmath.so.0 lib/libquadmath.so.0
fi

# Print the linked objects on libmxnet.so
>&2 echo "Checking linked objects on libmxnet.so..."
if [[ ! -z $(command -v readelf) ]]; then
readelf -d lib/libmxnet.so
strip --strip-unneeded lib/libmxnet.so
elif [[ ! -z $(command -v otool) ]]; then
otool -L lib/libmxnet.so
strip -u -r -x lib/libmxnet.so
else
>&2 echo "Not available"
fi

cd ../
17 changes: 14 additions & 3 deletions tools/pip_package/MANIFEST.in → tools/build/build_wheel.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
Expand All @@ -15,6 +17,15 @@
# specific language governing permissions and limitations
# under the License.

include README
recursive-include * *.py
recursive-include * *.so
# This script builds the wheel for binary distribution and performs sanity check.

cd mxnet-build
echo $(git rev-parse HEAD) >> python/mxnet/COMMIT_HASH
cd -

# Make wheel for testing
python setup.py bdist_wheel

wheel_name=$(ls -t dist | head -n 1)
pip install -U --user --force-reinstall dist/$wheel_name
python sanity_test.py
40 changes: 40 additions & 0 deletions tools/dependencies/make_shared_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

# This is a convenience script for calling the build scripts of all dependency libraries.
# Environment variables should be set beforehand.

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"


if [[ ! $PLATFORM == 'darwin' ]]; then
source $DIR/openblas.sh
fi
source $DIR/libz.sh
source $DIR/libturbojpeg.sh
source $DIR/libpng.sh
source $DIR/libtiff.sh
source $DIR/openssl.sh
source $DIR/curl.sh
source $DIR/eigen.sh
source $DIR/opencv.sh
source $DIR/protobuf.sh
source $DIR/cityhash.sh
source $DIR/zmq.sh
source $DIR/lz4.sh
3 changes: 2 additions & 1 deletion tools/dependencies/opencv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# This script builds the static library of opencv that can be used as dependency of mxnet.
# It expects openblas, libjpeg, libpng, libtiff, eigen, etc., to be in $DEPS_PATH.
OPENCV_VERSION=3.4.2
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
if [[ $PLATFORM == 'linux' ]]; then
OPENCV_LAPACK_OPTIONS=" \
-D OpenBLAS_HOME=$DEPS_PATH \
Expand Down Expand Up @@ -181,7 +182,7 @@ if [[ ! -f $DEPS_PATH/lib/libopencv_core.a ]] || [[ ! -f $DEPS_PATH/lib/libopenc
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=$DEPS_PATH ..
if [[ $PLATFORM == 'linux' ]]; then
cp $DEPS_PATH/../patch/opencv_lapack.h ./
cp $DIR/patch/opencv_lapack.h ./
fi
make
make install
Expand Down
23 changes: 23 additions & 0 deletions tools/dependencies/patch/opencv_lapack.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

extern "C" {
#include "cblas.h"
#include "lapacke.h"
}
2 changes: 2 additions & 0 deletions tools/dependencies/protobuf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ if [[ ! -e $LIBPROTOBUF ]] || [[ ! -e $LIBPROTOC ]]; then
make install
cd -
fi

export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$(dirname $(find $DEPS_PATH -type f -name 'libprotoc*' | grep protobuf | head -n 1)):$DEPS_PATH/lib
11 changes: 11 additions & 0 deletions tools/pip/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
include README
include mxnet/COMMIT_HASH
recursive-include mxnet/tools *
recursive-include mxnet *.py
recursive-include mxnet *.so
recursive-include mxnet *.so.*
recursive-include mxnet *.dylib
recursive-include mxnet *_LICENSE
recursive-include mxnet *.h
recursive-include mxnet *.cuh
recursive-include dmlc_tracker *.py
32 changes: 32 additions & 0 deletions tools/pip/sanity_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

# coding: utf-8
"""Sanity test."""
from __future__ import print_function
import sys
from base64 import b64decode

try:
import mxnet as mx
mx.img.imdecode(b64decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==')).asnumpy()
print('Test succeeded')
except:
import traceback
print('Test failed')
traceback.print_exc()
sys.exit(1)
Loading

0 comments on commit 47e2c48

Please sign in to comment.