Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Compile MKLDNN in Mac. (#10115)
Browse files Browse the repository at this point in the history
* Compile MKLDNN in Mac.

* A more general way of finding #cores.

* find the right dyn library of mkldnn.
  • Loading branch information
zheng-da authored and szha committed Mar 15, 2018
1 parent 93e0ceb commit f7fa49e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion 3rdparty/mkldnn
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,13 @@ lib/libmxnet.so: $(ALLX_DEP)
@mkdir -p $(@D)
$(CXX) $(CFLAGS) -shared -o $@ $(filter-out %libnnvm.a, $(filter %.o %.a, $^)) $(LDFLAGS) \
-Wl,${WHOLE_ARCH} $(filter %libnnvm.a, $^) -Wl,${NO_WHOLE_ARCH}
ifeq ($(USE_MKLDNN), 1)
ifeq ($(UNAME_S), Darwin)
install_name_tool -change '@rpath/libmklml.dylib' '@loader_path/libmklml.dylib' lib/libmxnet.so
install_name_tool -change '@rpath/libiomp5.dylib' '@loader_path/libiomp5.dylib' lib/libmxnet.so
install_name_tool -change '@rpath/libmkldnn.0.dylib' '@loader_path/libmkldnn.0.dylib' lib/libmxnet.so
endif
endif

$(PS_PATH)/build/libps.a: PSLITE

Expand Down
19 changes: 17 additions & 2 deletions prepare_mkldnn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,14 @@ if [ ! -z "$HOME_MKLDNN" ]; then
fi
fi

if [ $OSTYPE == "darwin16" ]; then
MKLDNN_LIBFILE="$MKLDNN_INSTALLDIR/lib/libmkldnn.dylib"
else
MKLDNN_LIBFILE="$MKLDNN_INSTALLDIR/lib/libmkldnn.so"
fi

if [ -z $MKLDNNROOT ]; then
if [ ! -f "$MKLDNN_INSTALLDIR/lib/libmkldnn.so" ]; then
if [ ! -f $MKLDNN_LIBFILE ]; then
mkdir -p $MKLDNN_INSTALLDIR
cd $MKLDNN_ROOTDIR
if [ -z $MKLROOT ] && [ ! -f $MKLDNN_INSTALLDIR/include/mkl_cblas.h ]; then
Expand All @@ -84,7 +90,16 @@ if [ ! -f "$MKLDNN_INSTALLDIR/lib/libmkldnn.so" ]; then
cd $MXNET_ROOTDIR
g++ --version >&2
cmake $MKLDNN_ROOTDIR -DCMAKE_INSTALL_PREFIX=$MKLDNN_INSTALLDIR -B$MKLDNN_BUILDDIR -DARCH_OPT_FLAGS="-mtune=generic" >&2
make -C $MKLDNN_BUILDDIR -j$(cat /proc/cpuinfo | grep processor | wc -l) VERBOSE=1 >&2
NUM_PROC=1
if [[ ! -z $(command -v nproc) ]]; then
NUM_PROC=$(nproc)
elif [[ ! -z $(command -v sysctl) ]]; then
NUM_PROC=$(sysctl -n hw.ncpu)
else
>&2 echo "Can't discover number of cores."
fi
make -C $MKLDNN_BUILDDIR -j$(NUM_PROC) VERBOSE=1 >&2

make -C $MKLDNN_BUILDDIR install >&2
rm -rf $MKLDNN_BUILDDIR
mkdir -p $MKLDNN_LIBDIR
Expand Down

0 comments on commit f7fa49e

Please sign in to comment.