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

Commit

Permalink
Picking up mklml 20171227 (#1126)
Browse files Browse the repository at this point in the history
* update to mklml 20171227

* update mklmk to 20171227

* update mkl version to v0.12

* update mklml artifacts

* enabled mkl mac install

* ignore mac and win mkl dynamic link files

* fix style

* add case selection for darwin

* disabled openblas warning on mac
  • Loading branch information
baojun-nervana authored Jan 4, 2018
1 parent 9e858fb commit 6968659
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 15 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
*.dll
*.dylib
*.dSYM
*.sublime-project
*.sublime-workspace
*.pyc
Expand Down Expand Up @@ -34,4 +37,4 @@ neon/data/loader/loader
.idea/
aeon
dist
mklml_lnx_*
mklml_*
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ clean_so:

clean: clean_py clean_so
@echo "Removing virtual environment files..."
@rm -rf aeon build dist mklml_lnx*
@rm -rf aeon build dist mklml_*
@rm -rf $(VIRTUALENV_DIR_BASE) $(VIRTUALENV_DIR_BASE)2 $(VIRTUALENV_DIR_BASE)3 $(STYLEVIRTUALENV_DIR_BASE)
@echo

Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ RUN pip --no-cache-dir install --upgrade \

RUN git clone https://github.com/NervanaSystems/neon /neon && \
make -C /neon sysinstall && \
rm -rf /neon/mklml_lnx_*.tgz
rm -rf /neon/mklml_*.tgz

WORKDIR /neon

Expand Down
18 changes: 17 additions & 1 deletion install_mkl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ if [[ `uname` == 'Linux' ]]; then
cd $MKL_ENGINE_PATH && make clean && make
cd $THIS_DIR

elif [[ `uname` == 'Darwin' ]]; then
echo -e "Mac detected"
RETURN_STRING=`./prepare_mkl.sh 2`
export MKLROOT=`echo $RETURN_STRING | awk -F "=" '{print $2}' | awk '{print $1}'`
echo -e "mkl root: ${GREEN}$MKLROOT${NORM}"
export LD_LIBRARY_PATH=$MKLROOT/lib:$LD_LIBRARY_PATH
export LIBRARY_PATH=$MKLROOT/lib:$LIBRARY_PATH
export CPATH=$MKLROOT/include:$CPATH
#build neon mklEngine
MKL_ENGINE_PATH='neon/backends/mklEngine'
export DYLD_LIBRARY_PATH=$MKLROOT/lib:$THIS_DIR/$MKL_ENGINE_PATH:$DYLD_LIBRARY_PATH
export MAC_BUILD=1
cd $MKL_ENGINE_PATH && make clean && make
cp ${MKLROOT}/lib/*.dylib .
cd $THIS_DIR

elif [[ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" || "$(expr substr $(uname -s) 1 7)" == "MSYS_NT" ]]; then
echo -e "Windows detected"
#build neon mklEngine
Expand All @@ -65,5 +81,5 @@ elif [[ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" || "$(expr substr $(un
cd $THIS_DIR

else
echo -e "Currently only Linux Environment supported, skipping MKL install"
echo -e "Environment not supported, skipping MKL install"
fi
10 changes: 9 additions & 1 deletion neon/backends/mklEngine/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ else
CFLAGS := -fopenmp -lmklml_gnu -fPIC -march=native -g -liomp5
endif

ifeq ($(MAC_BUILD), 1)
CFLAGS := -fopenmp -lmklml -fPIC -march=native -g -liomp5
COMMON_FLAGS := -std=c99 -O3 -I$(MKL_PATH)/include -L$(MKL_PATH)/lib
MKL_ENGINE_SO := mklEngine.dylib
MATH_CPU_SO := cmath.dylib
CC := gcc-7
endif

ifeq ($(WIN_BUILD), 1)
CFLAGS := -fopenmp -lmklml -fPIC -march=native -g -liomp5md
endif
Expand All @@ -45,5 +53,5 @@ $(MATH_CPU_SO): src/math_cpu.c
$(CC) $^ -shared -o $@ $(COMMON_FLAGS) $(CFLAGS)

clean:
@rm -vf *.o *.so *.dll
@rm -vrf *.o *.so *.dylib *.dSYM *.dll

6 changes: 3 additions & 3 deletions neon/backends/mklEngine/make_msys64.bat
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
set WIN_BUILD=1
set MKLROOT=mklml_win_2018.0.20170908
wget https://github.com/01org/mkl-dnn/releases/download/v0.10/%MKLROOT%.zip
set MKLROOT=mklml_win_2018.0.1.20171227
wget https://github.com/01org/mkl-dnn/releases/download/v0.12/%MKLROOT%.zip
pacman -S --needed unzip
unzip %MKLROOT%.zip
make
copy "%MKLROOT%\lib\mklml.dll"
ren *.so *.dll
rmdir /q /s %MKLROOT%
rm %MKLROOT%.zip
rm %MKLROOT%.zip
6 changes: 4 additions & 2 deletions neon/backends/nervanacpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from __future__ import division
from builtins import object, round, str, zip
import numpy as np
import sys
import logging
import time
import functools
Expand Down Expand Up @@ -563,8 +564,9 @@ def __init__(self,
"performance may suffer. Consider installing "
"one of openblas, Atlas, MKL, or vecLib")
except (AttributeError, KeyError):
logger.warn("Problems inferring BLAS info, CPU performance may "
"be suboptimal")
if sys.platform != 'darwin':
logger.warn("Problems inferring BLAS info, CPU performance may "
"be suboptimal")

self.device_type = 0
self.device_id = 0
Expand Down
13 changes: 13 additions & 0 deletions neon/backends/nervanamkl.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,19 @@ def __init__(self,
'mklEngine.dll')
self.mklEngine = ctypes.windll.LoadLibrary(mkl_engine_path)
math_engine_path = os.path.join(os.path.dirname(__file__), 'mklEngine', 'cmath.dll')

elif sys.platform == 'darwin':
mkl_ml_path = os.path.join(path, os.pardir, 'backends', 'mklEngine',
'libmklml.dylib')
ctypes.cdll.LoadLibrary(mkl_ml_path)
iomp5_path = os.path.join(path, os.pardir, 'backends', 'mklEngine',
'libiomp5.dylib')
ctypes.cdll.LoadLibrary(iomp5_path)
mkl_engine_path = os.path.join(path, os.pardir, 'backends', 'mklEngine',
'mklEngine.dylib')
self.mklEngine = ctypes.cdll.LoadLibrary(mkl_engine_path)
math_engine_path = os.path.join(os.path.dirname(__file__), 'mklEngine', 'cmath.dylib')

else:
mkl_engine_path = os.path.join(path, os.pardir, 'backends', 'mklEngine',
'mklEngine.so')
Expand Down
20 changes: 20 additions & 0 deletions neon/backends/util/check_mkl.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,26 @@ def get_mkl_lib(device_id=None, verbose=False):
return 0
return 1

elif sys.platform == 'darwin':
# find *.dylib
current_path = os.path.dirname(os.path.realpath(__file__))
mkl_engine_path = os.path.join(current_path, os.pardir, 'mklEngine', 'mklEngine.dylib')
if not os.path.isfile(mkl_engine_path):
neon_logger.display("mklEngine.dylib not found")
return 0

math_engine_path = os.path.join(current_path, os.pardir, 'mklEngine', 'cmath.dylib')
if not os.path.isfile(math_engine_path):
neon_logger.display("cmath.dylib not found")
return 0

header_path = os.path.join(os.path.dirname(__file__), 'mklEngine',
'src', 'math_cpu.header')
if os.path.isfile(header_path):
neon_logger.display("math_cpu.header not found")
return 0
return 1

else:
# find *.so
current_path = os.path.dirname(os.path.realpath(__file__))
Expand Down
15 changes: 11 additions & 4 deletions prepare_mkl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ FindLibrary()
intel|1)
LOCALMKL=`find $DST -name libmklml_intel.so` # name of MKL SDL lib
;;
*)
2)
LOCALMKL=`find $DST -name libmklml.dylib`
;;
*)
LOCALMKL=`find $DST -name libmklml_gnu.so` # name of MKL SDL lib
;;
esac
Expand All @@ -40,12 +43,16 @@ echo $VERSION_LINE # Return Version Line
}

# MKL
PLATFORM=lnx
if [ `uname` = 'Darwin' ]; then
PLATFORM=mac
fi
DST=`dirname $0`
OMP=0
VERSION_MATCH=20171007
ARCHIVE_BASE=mklml_lnx_2018.0.1.$VERSION_MATCH
VERSION_MATCH=20171227
ARCHIVE_BASE=mklml_${PLATFORM}_2018.0.1.$VERSION_MATCH
ARCHIVE_BASENAME=$ARCHIVE_BASE.tgz
GITHUB_RELEASE_TAG=v0.11
GITHUB_RELEASE_TAG=v0.12
MKLURL="https://github.com/01org/mkl-dnn/releases/download/$GITHUB_RELEASE_TAG/$ARCHIVE_BASENAME"
# there are diffrent MKL lib to be used for GCC and for ICC
reg='^[0-9]+$'
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@
'backends/kernels/maxas/MaxAs/*.pm',
'backends/mklEngine/*.so',
'backends/mklEngine/*.dll',
'backends/mklEngine/*.dylib',
'backends/mklEngine/src/*.header',
'../mklml_lnx_*/lib/*.so',
'../mklml_*/lib/*.so',
'../loader/bin/*.so']},
classifiers=['Development Status :: 3 - Alpha',
'Environment :: Console',
Expand Down

0 comments on commit 6968659

Please sign in to comment.