Search code examples
python-2.7cudagputheanonvcc

Link error with CUDA 7.5 in Windows 10 (from Theano project): MSVCRT.lib error LNK2019: unresolved external symbol


I am trying to properly setup CUDA in order to take advantage of the GPU in Theano.

After fixing many compilation problems by tuning my .theanorc and nvcc.profile files, I am struggling to fix this linking error:

mod.cu(735): warning: conversion from pointer to smaller integer    
mod.cu(1019): warning: statement is unreachable    
mod.cu(735): warning: conversion from pointer to smaller integer    
mod.cu(1019): warning: statement is unreachable    
mod.cu
Creating library C:/Users/niluje/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_60_Stepping_3_GenuineIntel-2.7.10-64/cuda_ndarray/cuda_ndarray.lib and object C:/Users/niluje/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_60_Stepping_3_GenuineIntel-2.7.10-64/cuda_ndarray/cuda_ndarray.exp
MSVCRT.lib(atonexit.obj) : error LNK2019: unresolved external symbol __imp_EncodePointer referenced in function __atonexitinit
MSVCRT.lib(crtdll.obj) : error LNK2001: unresolved external symbol __imp_EncodePointer
MSVCRT.lib(atonexit.obj) : error LNK2019: unresolved external symbol __imp_DecodePointer referenced in function _onexit
MSVCRT.lib(crtdll.obj) : error LNK2001: unresolved external symbol __imp_DecodePointer
MSVCRT.lib(gs_report.obj) : error LNK2019: unresolved external symbol __imp_IsDebuggerPresent referenced in function __raise_securityfailure
MSVCRT.lib(gs_report.obj) : error LNK2019: unresolved external symbol IsProcessorFeaturePresent referenced in function __report_gsfailure
MSVCRT.lib(gs_support.obj) : error LNK2019: unresolved external symbol __imp_QueryPerformanceCounter referenced in function __security_init_cookie
MSVCRT.lib(gs_support.obj) : error LNK2019: unresolved external symbol __imp_GetCurrentProcessId referenced in function __security_init_cookie
MSVCRT.lib(gs_support.obj) : error LNK2019: unresolved external symbol __imp_GetCurrentThreadId referenced in function __security_init_cookie
MSVCRT.lib(gs_support.obj) : error LNK2019: unresolved external symbol __imp_GetSystemTimeAsFileTime referenced in function __security_init_cookie
MSVCRT.lib(dllmain.obj) : error LNK2019: unresolved external symbol __imp_DisableThreadLibraryCalls referenced in function DllMain
C:/Users/niluje/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_60_Stepping_3_GenuineIntel-2.7.10-64/cuda_ndarray/cuda_ndarray.pyd : fatal error LNK1120: 9 unresolved externals

Here's my .theanorcfile:

[global]
device = gpu
floatX = float32

[cuda]
root = C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5

[nvcc]
flags = --use-local-env  --cl-version=2013 -LC:\Users\niluje\Anaconda\Lib;
compiler_bindir=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64

And here is my nvcc.profile file:

TOP              = $(_HERE_)/..

NVVMIR_LIBRARY_DIR = $(TOP)/nvvm/libdevice

PATH            += $(TOP)/open64/bin;$(TOP)/nvvm/bin;$(_HERE_);$(TOP)/lib;

INCLUDES        +=  "-I$(TOP)/include" "-IC:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include" "-IC:\Program Files\Microsoft SDKs\Windows\v6.0A\Include" $(_SPACE_)

LIBRARIES        =+ $(_SPACE_) "/LIBPATH:$(TOP)/lib/$(_WIN_PLATFORM_)" "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib\amd64" "/LIBPATH:C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib"

CUDAFE_FLAGS    +=
PTXAS_FLAGS     +=

It seems that this is not an uncommon error, but generally fixes involve changing some setting in the Visual Studio project. However, here I don't have a Visual Studio project. The code is dynamically generated by Theano and compiled at runtime.

Relevant system settings:

  • Windows 10 (yes...)
  • Python 2.7.10 64bits (Anaconda distrib)
  • CUDA 7.5 / NVIDIA driver 353.54 / GeForce GTX 760
  • Visual Studio Community 2013

Solution

  • Damn it! I figured it out just after posting the question. The solution: slightly different include and library folders:

    TOP              = $(_HERE_)/..
    
    NVVMIR_LIBRARY_DIR = $(TOP)/nvvm/libdevice
    
    PATH            += $(TOP)/open64/bin;$(TOP)/nvvm/bin;$(_HERE_);$(TOP)/lib;
    
    INCLUDES        +=  "-I$(TOP)/include" "-IC:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include" "-IC:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include" $(_SPACE_)
    
    LIBRARIES        =+ $(_SPACE_) "/LIBPATH:$(TOP)/lib/$(_WIN_PLATFORM_)" "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib\amd64" "/LIBPATH:C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\x64"
    
    CUDAFE_FLAGS    +=
    PTXAS_FLAGS     +=
    

    In particular I switched from:

    C:\Program Files\Microsoft SDKs\Windows\v6.0A\
    

    to:

    C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A
    

    (I thought that I had to use the Program Files ones because of my 64bits project, but in fact the 64bits files are also included in Program Files (x86))