From 0022d9ab5fc7b227712a40f6aeaffac2b2b31a93 Mon Sep 17 00:00:00 2001 From: Graham Neubig Date: Fri, 21 Oct 2016 20:51:21 -0400 Subject: [PATCH 1/8] Fixed hierarchy in doc --- README.md | 2 +- doc/source/index.rst | 4 ++-- doc/source/install.rst | 45 +++++++++++++++++++++--------------------- doc/source/python.rst | 18 ++++++++--------- 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 391bf3784..4ae41811a 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # DyNet Dynamic neural network library -DyNet (formerly known as [cnn](http://github.com/clab/cnn-v1)) is a neural network library that is written in C++ with bindings in Python. It is designed to be efficient when run on either CPU or GPU, and works well with networks that have dynamic structures that change for every training instance. For example, these kinds of networks are particularly important in natural language processing tasks, and DyNet has been used to build state-of-the-art systems for [syntactic parsing](https://github.com/clab/lstm-parser), [machine translation](https://github.com/neubig/lamtram), [morphological inflection](https://github.com/mfaruqui/morph-trans), and many other application areas. +DyNet (formerly known as [cnn](http://github.com/clab/cnn-v1)) is a neural network library developed by Carnegie Mellon University and many others. It is written in C++ (with bindings in Python) and is designed to be efficient when run on either CPU or GPU, and to work well with networks that have dynamic structures that change for every training instance. For example, these kinds of networks are particularly important in natural language processing tasks, and DyNet has been used to build state-of-the-art systems for [syntactic parsing](https://github.com/clab/lstm-parser), [machine translation](https://github.com/neubig/lamtram), [morphological inflection](https://github.com/mfaruqui/morph-trans), and many other application areas. Read the [documentation](http://dynet.readthedocs.io/en/latest/) to get started, and feel free to contact the [dynet-users group](https://groups.google.com/forum/#!forum/dynet-users) group or [github page](http://github.com/clab/dynet) with any questions, issues, or contributions. diff --git a/doc/source/index.rst b/doc/source/index.rst index 31dc74b4a..ef3de90c9 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -6,9 +6,9 @@ Dynet documentation ================================= -DyNet (formerly known as `cnn `_) is a neural network library that is written in C++ with bindings in Python. It is designed to be efficient when run on either CPU or GPU, and works well with networks that have dynamic structures that change for every training instance. For example, these kinds of networks are particularly important in natural language processing tasks, and DyNet has been used to build state-of-the-art systems for `syntactic parsing `_, `machine translation `_, `morphological inflection `_, and many other application areas. +DyNet (formerly known as `cnn `_) is a neural network library developed by Carnegie Mellon University and many others. It is written in C++ (with bindings in Python) and is designed to be efficient when run on either CPU or GPU, and to work well with networks that have dynamic structures that change for every training instance. For example, these kinds of networks are particularly important in natural language processing tasks, and DyNet has been used to build state-of-the-art systems for `syntactic parsing `_, `machine translation `_, `morphological inflection `_, and many other application areas. -First, you need to install DyNet: +DyNet can be installed according to the instructions below: .. toctree:: :maxdepth: 2 diff --git a/doc/source/install.rst b/doc/source/install.rst index 5b8ecabfd..ae09ac5fd 100644 --- a/doc/source/install.rst +++ b/doc/source/install.rst @@ -58,7 +58,7 @@ To see that things have built properly, you can run which will train a multilayer perceptron to predict the xor function. -Compiling/linking External Programs +Compiling/linking external programs ----------------------------------- When you want to use DyNet in an external program, you will need to add @@ -88,11 +88,12 @@ then examine the commands in the ``make.log`` file to see if anything looks fishy. If you would like help, send this ``make.log`` file via the "Issues" tab on github, or to the dynet-users mailing list. -Build options -------------- + +GPU/MKL support and build options +--------------------------------- GPU (CUDA) support -~~~~~~~~~~~~~~~~~~ +------------------ ``dynet`` supports running programs on GPUs with CUDA. If you have CUDA installed, you can build DyNet with GPU support by adding @@ -109,6 +110,24 @@ GPU, you can link to the "libgdynet" and "libdynetcuda" libraries. (Eventually you will be able to use a single library to run on either CPU or GPU, but this is not fully implemented yet.) + +MKL support +----------- + +DyNet can leverage Intel's MKL library to speed up computation on the CPU. As an example, we've seen 3x speedup in seq2seq training when using MKL. To use MKL, include the following cmake option: + +:: + + -DMKL=TRUE + +If cmake is unable to find MKL automatically, try setting `MKL_ROOT`, such as + +:: + + -DMKL_ROOT="/path/to/MKL" + +If either MKL or MKL_ROOT are set, CMake will look for MKL. + Non-standard Boost location ~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -161,21 +180,3 @@ The Windows build also supports CUDA. The latest (development) version of Eigen - ref.h: add `#ifndef __CUDACC__ / #endif` around `EIGEN_INHERIT_ASSIGNMENT_OPERATORS(RefBase)` - TensorDeviceCuda.h: Change `sleep(1)` to `Sleep(1000)` -MKL support -~~~~~~~~~~~ - -DyNet can leverage Intel's MKL library to speed up computation on the CPU. As an example, we've seen 3x speedup in seq2seq training when using MKL. To use MKL, include the following cmake option: - -:: - - -DMKL=TRUE - -If cmake is unable to find MKL automatically, try setting `MKL_ROOT`, such as - -:: - - -DMKL_ROOT="/path/to/MKL" - -If either MKL or MKL_ROOT are set, CMake will look for MKL. - - diff --git a/doc/source/python.rst b/doc/source/python.rst index ccf139b36..f8caee3a4 100644 --- a/doc/source/python.rst +++ b/doc/source/python.rst @@ -32,8 +32,8 @@ TL;DR cd python python setup.py install # or `python setup.py install --user` for a user-local install. -Detailed Instructions: ----------------------- +Detailed Instructions +--------------------- First, get DyNet: @@ -151,8 +151,11 @@ installation is likely to be working: from dynet import * model = Model() -Installing with GPU support ---------------------------- +GPU/MKL Support +--------------- + +Installing/running on GPU +~~~~~~~~~~~~~~~~~~~~~~~~~ For installing on a computer with GPU, first install CUDA. The following instructions assume CUDA is installed. @@ -176,9 +179,6 @@ After running ``make -j 2``, you should have the files ``_dynet.so`` and As before, ``cd build/python`` followed by ``python setup.py install --user`` will install the module. -Using the GPU -------------- - In order to use the GPU support, you can either: - Use ``import _gdynet as dy`` instead of ``import dynet as dy`` @@ -189,8 +189,8 @@ In order to use the GPU support, you can either: on how it is invoked. -Using MKL ---------- +Running with MKL +~~~~~~~~~~~~~~~~ If you've built dynet to use MKL (using -DMKL or -DMKL_ROOT), python sometimes has difficulty finding the MKL shared libraries. You can try setting LD_LIBRARY_PATH to point to your MKL library directory. If that doesn't work, try setting the following environment variable (supposing, for example, your MKL libraries are located at /opt/intel/mkl/lib/intel64): From 165aa1e22bff33afeeda36661facbaa4704546c2 Mon Sep 17 00:00:00 2001 From: Matthew Richardson Date: Mon, 24 Oct 2016 16:36:13 -0700 Subject: [PATCH 2/8] Got python working for Windows. --- doc/source/python.rst | 19 +++++++++++++++++++ python/setup.py.in | 19 ++++++++++++++----- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/doc/source/python.rst b/doc/source/python.rst index f8caee3a4..5a1940bb9 100644 --- a/doc/source/python.rst +++ b/doc/source/python.rst @@ -151,6 +151,25 @@ installation is likely to be working: from dynet import * model = Model() +Windows Support +------------------ +You can also use Python on Windows by following similar steps to the above. For simplicity, we recommend +using a Python distribution that already has Cython installed. The following has been tested to work: + +1) Install WinPython 2.7.10 (comes with Cython already installed). +2) Run CMake as above with ``-DPYTHON=/path/to/your/python.exe``. +3) Open a command prompt and set ``VS90COMNTOOLS`` to the path to your Visual Studio "Common7/Tools" directory. One easy way to do this is a command such as: + +:: + + set VS90COMNTOOLS=%VS140COMNTOOLS% + +4) Open dynet.sln from this command prompt and build the "Release" version of the solution. +5) Follow the rest of the instructions above for testing the build and installing it for other users + +Note, currently only the Release version works. + + GPU/MKL Support --------------- diff --git a/python/setup.py.in b/python/setup.py.in index f0abc3656..236eb22da 100644 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -9,7 +9,16 @@ cfg_vars = distutils.sysconfig.get_config_vars() if "CFLAGS" in cfg_vars: cfg_vars["CFLAGS"] = cfg_vars["CFLAGS"].replace("-Wstrict-prototypes", "") -COMPILER_ARGS=["-std=c++11"] +if ${MSVC}: + COMPILER_ARGS=["-DNOMINMAX", "/EHsc"] + DYNET_LIB_DIR="${PROJECT_BINARY_DIR}/dynet/Release/" + RUNTIME_LIB_DIRS=[] +else: + COMPILER_ARGS=["-std=c++11"] + DYNET_LIB_DIR="${PROJECT_BINARY_DIR}/dynet/" + RUNTIME_LIB_DIRS=[DYNET_LIB_DIR] + + import platform # in some OSX systems, the following extra flags are needed: @@ -25,10 +34,10 @@ ext_cpu = Extension( "${EIGEN3_INCLUDE_DIR}", # this is the directory where eigen is saved. "${Boost_INCLUDE_DIR}"], # this is the directory where boost is. libraries=['dynet'], # ditto - library_dirs=[".","${PROJECT_BINARY_DIR}/dynet/"], + library_dirs=[".",DYNET_LIB_DIR, "${Boost_LIBRARY_DIRS}"], #extra_link_args=["-L/home/yogo/Vork/Research/dynet/dynet/build/dynet"], # if needed extra_compile_args=COMPILER_ARGS, - runtime_library_dirs=["${PROJECT_BINARY_DIR}/dynet/"], + runtime_library_dirs=RUNTIME_LIB_DIRS, ) ext_gpu = Extension( @@ -39,10 +48,10 @@ ext_gpu = Extension( "${EIGEN3_INCLUDE_DIR}", # this is the directory where eigen is saved. "${Boost_INCLUDE_DIR}"], # this is the directory where boost is. libraries=['gdynet','dynetcuda','cublas'], # ditto - library_dirs=[".","${PROJECT_BINARY_DIR}/dynet/","${CUDA_CUBLAS_LIB}"], + library_dirs=[".",DYNET_LIB_DIR,"${Boost_LIBRARY_DIRS}","${CUDA_CUBLAS_LIB}"], #extra_link_args=["-L/home/yogo/Vork/Research/dynet/dynet/build/dynet"], # if needed extra_compile_args=COMPILER_ARGS, - runtime_library_dirs=["${PROJECT_BINARY_DIR}/dynet/"], + #runtime_library_dirs=RUNTIME_LIB_DIRS, ) TARGET = [ext_cpu] From 137fc979ac13cc6fc288684058e5a51f7a2ea30b Mon Sep 17 00:00:00 2001 From: Matthew Richardson Date: Mon, 24 Oct 2016 16:36:42 -0700 Subject: [PATCH 3/8] Removing unneeded pyc file --- pyexamples/util.pyc | Bin 2607 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 pyexamples/util.pyc diff --git a/pyexamples/util.pyc b/pyexamples/util.pyc deleted file mode 100644 index 450ea3918ff7edb7e04940a8f82d2f75ea62bab9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2607 zcmb_dT~8!M6us3wJ2335;3BN3>+U8#%tmF*CcbTm0&gb7G|3W)*crMDXy}h&swRMe z2ebPR{1yH_-_>(&&rBQj1#mKTyXtmz)j9W`x)uKZXyKRN{@6=o@(c0&2F)G7r1%@j zMG7PPMhwS+Kn54oW|8jN$FW{Izz58zCyap^sKZ>nT)ID;C%vx(-ufU!b^1SIkfXhX38 zV{}gpfg)gkzb(;juZ0g1e$Gb5TWIckm}{&dayBoc&%_(?0oQnICg9rFf&3cCc^ltj ziqwXm0*}c0S3o9mp*Cw~xX%%LzfcdW(>!d1%8*>;ruHTW~JRYD4=v8SWJSEZ`(N)?@ukZM!C#s8AneX74c{@TY zoO-iY7di0R6QX3=OmsS&m`k67@q9F3|Xt~X#L>Tm=r=8<`3RBTKcVQDy) z(Lp#Mwo^zIoN#1Gi<5R#rV2c_WrOz2UOAl*busH6a5Y`o&vp^ZI5h0YpiNR*4hkE` zo^p)iqDsd(h7rRTu|{ZRNb-Smh4m*@8a?Kl6_^H*_HKIsG-njB<6dpkZ7t4uGTo}P zW(TPqB^c|Ef!aiKAHht@4QdT)iWUiWLKYWBd{$g$;U^KEY*5s?It{!YE6V1GQP7Vy z*b#SW_}!Ws_hX#&L`$s)f>Ctze+_fF-beys*gkm58U&cNK3Mc*;(24vmt-$xNvjpZ zl&X@CvfL_KEz!=8vSHmD=9zB@>D)Xk?cGUDD*(z&9DhI(%$t~1^Ejx_ Date: Mon, 24 Oct 2016 17:12:52 -0700 Subject: [PATCH 4/8] Fixing python build for Linux. Adding pyc to gitignore so they aren't checked in accidentally in the future. --- .gitignore | 3 +++ python/setup.py.in | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index eb39fc4fc..e382eba34 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,9 @@ examples/nlm #data rnnlm/ptb-mikolov/ +# Python temporary files +*.pyc + # Compiled Object files *.slo *.lo diff --git a/python/setup.py.in b/python/setup.py.in index 236eb22da..ba51d6262 100644 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -9,7 +9,7 @@ cfg_vars = distutils.sysconfig.get_config_vars() if "CFLAGS" in cfg_vars: cfg_vars["CFLAGS"] = cfg_vars["CFLAGS"].replace("-Wstrict-prototypes", "") -if ${MSVC}: +if "${MSVC}"=="1": COMPILER_ARGS=["-DNOMINMAX", "/EHsc"] DYNET_LIB_DIR="${PROJECT_BINARY_DIR}/dynet/Release/" RUNTIME_LIB_DIRS=[] From 507ac19a6d36f8b10264a74e6a45d8fdd606dd77 Mon Sep 17 00:00:00 2001 From: Matthew Richardson Date: Tue, 25 Oct 2016 11:53:11 -0700 Subject: [PATCH 5/8] Windows python build now working with MKL. --- CMakeLists.txt | 1 + python/setup.py.in | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 79a4d54b3..6ea603853 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,7 @@ function(find_mkl) endif() include_directories(${MKL_INCLUDE_DIR}) link_directories(${MKL_CORE_LIB_DIR} ${MKL_COMPILER_LIB_DIR}) + set(MKL_LINK_DIRS ${MKL_CORE_LIB_DIR} ${MKL_COMPILER_LIB_DIR} PARENT_SCOPE) # Keeping this for python build else() message(FATAL_ERROR "Failed to find MKL in path: ${MKL_ROOT} (Did you set MKL_ROOT properly?)") endif() diff --git a/python/setup.py.in b/python/setup.py.in index ba51d6262..7ccc60891 100644 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -2,6 +2,10 @@ from setuptools import setup from setuptools.extension import Extension from Cython.Distutils import build_ext +def appendCMakeList(list, var): + if var != "": + list.extend(var.split(';')) + # Remove the "-Wstrict-prototypes" compiler option, which isn't valid for C++. import distutils.sysconfig @@ -9,15 +13,29 @@ cfg_vars = distutils.sysconfig.get_config_vars() if "CFLAGS" in cfg_vars: cfg_vars["CFLAGS"] = cfg_vars["CFLAGS"].replace("-Wstrict-prototypes", "") + +LIBRARIES=['dynet'] +LIBRARY_DIRS=["."] + if "${MSVC}"=="1": COMPILER_ARGS=["-DNOMINMAX", "/EHsc"] DYNET_LIB_DIR="${PROJECT_BINARY_DIR}/dynet/Release/" RUNTIME_LIB_DIRS=[] + # For MSVC, we compile dynet as a static lib, so we need to also link in the + # other libraries it depends on: + appendCMakeList(LIBRARIES, '${LIBS}'.replace('.lib', '')) # Remove .lib extension from compiler lib + appendCMakeList(LIBRARY_DIRS, '${MKL_LINK_DIRS}') # Add the MKL dirs, if MKL is being used + # Boost does auto-linking in MSVC, just point to the right directory: + appendCMakeList(LIBRARY_DIRS, '${Boost_LIBRARY_DIRS}') else: COMPILER_ARGS=["-std=c++11"] DYNET_LIB_DIR="${PROJECT_BINARY_DIR}/dynet/" RUNTIME_LIB_DIRS=[DYNET_LIB_DIR] +LIBRARY_DIRS.append(DYNET_LIB_DIR) +GPULIBRARIES=['gdynet','dynetcuda','cublas'] +GPULIBRARY_DIRS=list(LIBRARY_DIRS) # make a copy +GPULIBRARY_DIRS.append("${CUDA_CUBLAS_LIB}") import platform @@ -33,8 +51,8 @@ ext_cpu = Extension( include_dirs=["${PROJECT_SOURCE_DIR}", # this is the location of the main dynet directory. "${EIGEN3_INCLUDE_DIR}", # this is the directory where eigen is saved. "${Boost_INCLUDE_DIR}"], # this is the directory where boost is. - libraries=['dynet'], # ditto - library_dirs=[".",DYNET_LIB_DIR, "${Boost_LIBRARY_DIRS}"], + libraries=LIBRARIES, # ditto + library_dirs=LIBRARY_DIRS, #extra_link_args=["-L/home/yogo/Vork/Research/dynet/dynet/build/dynet"], # if needed extra_compile_args=COMPILER_ARGS, runtime_library_dirs=RUNTIME_LIB_DIRS, @@ -47,8 +65,8 @@ ext_gpu = Extension( include_dirs=["${PROJECT_SOURCE_DIR}", # this is the location of the main dynet directory. "${EIGEN3_INCLUDE_DIR}", # this is the directory where eigen is saved. "${Boost_INCLUDE_DIR}"], # this is the directory where boost is. - libraries=['gdynet','dynetcuda','cublas'], # ditto - library_dirs=[".",DYNET_LIB_DIR,"${Boost_LIBRARY_DIRS}","${CUDA_CUBLAS_LIB}"], + libraries=GPULIBRARIES, # ditto + library_dirs=GPULIBRARY_DIRS, #extra_link_args=["-L/home/yogo/Vork/Research/dynet/dynet/build/dynet"], # if needed extra_compile_args=COMPILER_ARGS, #runtime_library_dirs=RUNTIME_LIB_DIRS, From 3920a6684d0e1cc07576dc83da0f8de4aa197941 Mon Sep 17 00:00:00 2001 From: Matthew Richardson Date: Tue, 25 Oct 2016 18:35:41 -0700 Subject: [PATCH 6/8] Got Python with GPU working for Windows --- python/CMakeLists.txt | 16 ++++++++++++++-- python/setup.py.in | 28 ++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 27c18e663..e37fc1e2c 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -1,4 +1,12 @@ +function(get_filename_components DEST ITEMS PART) + foreach(ITEM ${ITEMS}) + get_filename_component(ITEMPART "${ITEM}" ${PART}) + list(APPEND ${DEST} ${ITEMPART}) + endforeach() + list(REMOVE_DUPLICATES ${DEST}) + set(${DEST} ${${DEST}} PARENT_SCOPE) +endfunction() if(!PYTHON) find_program(PYTHON "python") @@ -14,8 +22,12 @@ if(PYTHON) ) if (WITH_CUDA_BACKEND) - message("--- CUDA:" ${CUDA_CUBLAS_LIBRARIES}) - get_filename_component(CUDA_CUBLAS_LIB ${CUDA_CUBLAS_LIBRARIES} PATH) + message("--- CUDA: CUBLAS: ${CUDA_CUBLAS_LIBRARIES} RT: ${CUDA_LIBRARIES}") + # Collect all of the library filenames and paths for setup.py + get_filename_components(CUDA_CUBLAS_DIRS "${CUDA_CUBLAS_LIBRARIES}" PATH) + get_filename_components(CUDA_CUBLAS_FILES "${CUDA_CUBLAS_LIBRARIES}" NAME) + get_filename_components(CUDA_RT_DIRS "${CUDA_LIBRARIES}" PATH) + get_filename_components(CUDA_RT_FILES "${CUDA_LIBRARIES}" NAME) endif() add_custom_target(copy) diff --git a/python/setup.py.in b/python/setup.py.in index 7ccc60891..7e262df67 100644 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -1,11 +1,22 @@ from setuptools import setup from setuptools.extension import Extension from Cython.Distutils import build_ext +import re def appendCMakeList(list, var): if var != "": list.extend(var.split(';')) - + +def appendCMakeLibList(list, var): + if var != "": + list.extend(map(stripLib, var.split(';'))) + +# Strip library prefixes and suffixes to prevent linker confusion +def stripLib(filename): + filename = re.sub(".lib$", "", filename) + filename = re.sub("^lib", "", filename) + filename = re.sub(".so$", "", filename) + return filename # Remove the "-Wstrict-prototypes" compiler option, which isn't valid for C++. import distutils.sysconfig @@ -16,6 +27,11 @@ if "CFLAGS" in cfg_vars: LIBRARIES=['dynet'] LIBRARY_DIRS=["."] +GPULIBRARIES=['gdynet', 'dynetcuda'] +GPULIBRARY_DIRS=[] + +appendCMakeLibList(GPULIBRARIES, '${CUDA_CUBLAS_FILES}') +appendCMakeList(GPULIBRARY_DIRS, '${CUDA_CUBLAS_DIRS}') if "${MSVC}"=="1": COMPILER_ARGS=["-DNOMINMAX", "/EHsc"] @@ -23,8 +39,10 @@ if "${MSVC}"=="1": RUNTIME_LIB_DIRS=[] # For MSVC, we compile dynet as a static lib, so we need to also link in the # other libraries it depends on: - appendCMakeList(LIBRARIES, '${LIBS}'.replace('.lib', '')) # Remove .lib extension from compiler lib + appendCMakeLibList(LIBRARIES, '${LIBS}') # Remove .lib extension from compiler lib appendCMakeList(LIBRARY_DIRS, '${MKL_LINK_DIRS}') # Add the MKL dirs, if MKL is being used + appendCMakeLibList(GPULIBRARIES, '${CUDA_RT_FILES}') + appendCMakeList(GPULIBRARY_DIRS, '${CUDA_RT_DIRS}') # Boost does auto-linking in MSVC, just point to the right directory: appendCMakeList(LIBRARY_DIRS, '${Boost_LIBRARY_DIRS}') else: @@ -33,9 +51,7 @@ else: RUNTIME_LIB_DIRS=[DYNET_LIB_DIR] LIBRARY_DIRS.append(DYNET_LIB_DIR) -GPULIBRARIES=['gdynet','dynetcuda','cublas'] -GPULIBRARY_DIRS=list(LIBRARY_DIRS) # make a copy -GPULIBRARY_DIRS.append("${CUDA_CUBLAS_LIB}") +GPULIBRARY_DIRS = LIBRARY_DIRS + GPULIBRARY_DIRS import platform @@ -69,7 +85,7 @@ ext_gpu = Extension( library_dirs=GPULIBRARY_DIRS, #extra_link_args=["-L/home/yogo/Vork/Research/dynet/dynet/build/dynet"], # if needed extra_compile_args=COMPILER_ARGS, - #runtime_library_dirs=RUNTIME_LIB_DIRS, + runtime_library_dirs=RUNTIME_LIB_DIRS, ) TARGET = [ext_cpu] From b919444042edb479191707e9d8bee38ef0a94109 Mon Sep 17 00:00:00 2001 From: Matthew Richardson Date: Tue, 25 Oct 2016 19:09:03 -0700 Subject: [PATCH 7/8] Fixing MKL Python build for Windows (stripping "lib" prefix screwed up libiomp5md.lib, should be done only for .so/.a files) --- python/setup.py.in | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/python/setup.py.in b/python/setup.py.in index 7e262df67..90c4570c4 100644 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -13,9 +13,12 @@ def appendCMakeLibList(list, var): # Strip library prefixes and suffixes to prevent linker confusion def stripLib(filename): - filename = re.sub(".lib$", "", filename) - filename = re.sub("^lib", "", filename) - filename = re.sub(".so$", "", filename) + if filename.endswith(".lib"): + filename = re.sub(".lib$", "", filename) + elif filename.endswith(".so") or filename.endswith(".a"): + filename = re.sub("^lib", "", filename) + filename = re.sub(".so$", "", filename) + filename = re.sub(".a$", "", filename) return filename # Remove the "-Wstrict-prototypes" compiler option, which isn't valid for C++. From 1eb472748bf414c2500ef0f2e4fff3c867802eaf Mon Sep 17 00:00:00 2001 From: Matthew Richardson Date: Tue, 25 Oct 2016 19:28:16 -0700 Subject: [PATCH 8/8] Fix Windows Python with both MKL and GPU. The GPU compilation may still need some of the non-GPU libraries (like MKL). --- python/setup.py.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/setup.py.in b/python/setup.py.in index 90c4570c4..ece1b50d3 100644 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -42,7 +42,8 @@ if "${MSVC}"=="1": RUNTIME_LIB_DIRS=[] # For MSVC, we compile dynet as a static lib, so we need to also link in the # other libraries it depends on: - appendCMakeLibList(LIBRARIES, '${LIBS}') # Remove .lib extension from compiler lib + appendCMakeLibList(LIBRARIES, '${LIBS}') + appendCMakeLibList(GPULIBRARIES, '${LIBS}') appendCMakeList(LIBRARY_DIRS, '${MKL_LINK_DIRS}') # Add the MKL dirs, if MKL is being used appendCMakeLibList(GPULIBRARIES, '${CUDA_RT_FILES}') appendCMakeList(GPULIBRARY_DIRS, '${CUDA_RT_DIRS}')