NervanaSystems / neon

Intel® Nervana™ reference deep learning framework committed to best performance on all hardware
http://neon.nervanasys.com/docs/latest
Apache License 2.0
3.87k stars 811 forks source link

Is it possible to use MKL on Win7 64-bit computer? #406

Closed iNomaD closed 6 years ago

iNomaD commented 7 years ago

I've successfully installed neon on Win7 with msys64 and Anaconda. Unfortunately, MKL doesn't work out of the box. When I run python examples/mnist_mlp.py -b mkl, I get the following:

DISPLAY:neon:mklEngine.so not found; falling back to cpu backend
DISPLAY:neon:mklEngine.so not found; falling back to cpu backend
2017-10-18 20:13:42,937 - neon - DISPLAY - mklEngine.so not found; falling back to cpu backend
Traceback (most recent call last):
  File "examples/mnist_mlp.py", line 59, in <module>
    args = parser.parse_args()
  File "E:\Programs\Anaconda3\envs\intel27\lib\site-packages\neon-2.2.0-py2.7.egg\neon\util\argparser.py", line 366, in parse_args
    compat_mode=args.compat_mode)
  File "E:\Programs\Anaconda3\envs\intel27\lib\site-packages\neon-2.2.0-py2.7.egg\neon\backends\__init__.py", line 113, in gen_backend
    deterministic=deterministic)
  File "E:\Programs\Anaconda3\envs\intel27\lib\site-packages\neon-2.2.0-py2.7.egg\neon\backends\backend.py", line 468, in allocate_backend
    return Backend.backends[name](**kargs)
  File "E:\Programs\Anaconda3\envs\intel27\lib\site-packages\neon-2.2.0-py2.7.egg\neon\backends\nervanamkl.py", line 180, in __init__
    assert get_mkl_lib(), "MKL is not installed correctly"
AssertionError: MKL is not installed correctly 

Inside sources these lines cause get_mkl_lib() to produce AssertionError:

mkl_engine_path = os.path.join(path, os.pardir, 'backends', 'mklEngine', 'mklEngine.so')
math_engine_path = os.path.join(os.path.dirname(__file__), 'mklEngine', 'cmath.so')
header_path = os.path.join(os.path.dirname(__file__), 'mklEngine', 'src', 'math_cpu.header')

Now I am trying to build neon/backends/mklEngine. I put the path to my Intel MKL distribution for Windows as SET MKLROOT=E:\Programs\IntelSWTools\compilers_and_libraries_2018.0.124\windows\mkl and I also made conda install mkl. Now typing make I get links errors because I don't have mklml_gnu lib inside my MKL distribution:

Building mklEngine.so...
cc src/conv.c src/pooling.c src/relu.c src/batchNorm.c src/concat.c src/softmax.c src/MKLDNN.h -shared -o mklEngine.so -std=c99 -O3 -IE:\Programs\IntelSWTools\compilers_and_libraries_2018.0.124\windows\mkl/include -LE:\Programs\IntelSWTools\compilers_and_libraries_2018.0.124\windows\mkl/lib -Wl,-rpath=E:\Programs\IntelSWTools\compilers_and_libraries_2018.0.124\windows\mkl/lib -fopenmp -lmklml_gnu -fPIC -march=native -g -liomp5
E:/Programs/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lmklml_gnu
E:/Programs/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -liomp5
collect2.exe: error: ld returned 1 exit status
make: *** [Makefile:38: mklEngine.so] Error 1

Could you help me to build it?

P.S. I hope, the official support of Windows would be a great contribution for the community.

wei-v-wang commented 7 years ago

Hello @iNomaD Thank you for trying neon, and especially neon with MKL! As you may know, we have only tested neon with MKL Linux versions. However, from the information you provided, I see at least we can try one more thing:

First apologies for the confusion regarding "MKL", in neon when we say "MKL" we mean the small library (Deep Neural Network part of MKL): https://github.com/01org/mkl-dnn/releases from this page you can see mklml_lnx_2018.0.20170908.tgz (since you are using msys64). Otherwise I would have suggested trying mklml_win_2018.0.20170908.tgz (again, sorry we never tried this windows MKLML version).

From the above "cannot find -lmklml_gnu" and "cannot find -liomp5" I know it is trying to find the libary (.so format) in the mklml_lnx_2018.0.20170908/lib directory.

So instead of putting INTEL (BIG) MKL distribution path in MKLROOT, can you please check if directory (under neon) mklml_lnx_2018.0.20170908 is available (and futher whether mklml_lnx_2018.0.20170908/lib) contains the following .so files?

libiomp5.so libmklml_gnu.so libmklml_intel.so

If you do not have "mklml_lnx_2018.0.20170908" directory AFTER typing "make" under neon. Then I would suggest checking whether mklml_lnx_2018.0.20170908.tgz was downloaded successfully:

66M Sep 13 13:41 mklml_lnx_2018.0.20170908.tgz

If not, I would suggest downloading directly from https://github.com/01org/mkl-dnn/releases where you can find the mklml_lnx_2018.0.20170908.tgz

Please keep us updated whether the above is of any help. Thank you again for trying neon with MKL (MKLML) on IA!

iNomaD commented 7 years ago

Thank you, @wei-v-wang I made it work with zip release and sent my solution as a pull request https://github.com/NervanaSystems/neon/pull/407

wei-v-wang commented 6 years ago

Thanks @iNomaD ! We will work on merging your PR.

wei-v-wang commented 6 years ago

https://github.com/NervanaSystems/neon/commit/082da5dc72c6e5b1dd7c1851a9110df56ae4aa41 has the merged PR.