Peter
Peter

Reputation: 1442

Compiling library with cuda 7.0 using nvcc on windows while linking to 32-bit python 2.5

I'm trying to compile a library that can be called from python using nvcc. Typically on windows I use the msys/mingw toolchain and can compile python extensions with no problem. However, when I try to compile using nvcc I believe it is using the link.exe which is (part of Microsoft Visual Studio). Although it compiles just fine, it fails at the link step.

I realize I'm using an old version of python (version 2.5). I'm working with a legacy application and I am stuck on with the old version for the time being.

Here's the nvcc command that I'm trying:

nvcc -I "C:\Python25\include" -I "C:\python25\Lib\site-packages\numpy\core\include\numpy" -L "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.0\lib\x64" -lcusolver -lcusparse -Xlinker "C:\Python25\libs\python25.lib" cusolve5.cu

But it fails with this message:

   Creating library a.lib and object a.exp
tmpxft_00001128_00000000-28_cusolve5.obj : error LNK2019: unresolved external symbol __imp_PyObject_GetAttrString referenced in function _import_array
tmpxft_00001128_00000000-28_cusolve5.obj : error LNK2019: unresolved external symbol __imp_PyCObject_AsVoidPtr referenced in function _import_array
tmpxft_00001128_00000000-28_cusolve5.obj : error LNK2019: unresolved external symbol __imp_PyErr_SetString referenced in function _import_array
tmpxft_00001128_00000000-28_cusolve5.obj : error LNK2019: unresolved external symbol __imp_PyErr_Format referenced in function _import_array
tmpxft_00001128_00000000-28_cusolve5.obj : error LNK2019: unresolved external symbol __imp_PyArg_ParseTuple referenced in function main
tmpxft_00001128_00000000-28_cusolve5.obj : error LNK2019: unresolved external symbol __imp_Py_BuildValue referenced in function main
tmpxft_00001128_00000000-28_cusolve5.obj : error LNK2019: unresolved external symbol __imp_Py_InitModule4_64 referenced in function "void __cdecl initbmc(void)" (?initbmc@@YAXXZ)
tmpxft_00001128_00000000-28_cusolve5.obj : error LNK2019: unresolved external symbol __imp_PyErr_Print referenced in function "void __cdecl initbmc(void)" (?initbmc@@YAXXZ)
tmpxft_00001128_00000000-28_cusolve5.obj : error LNK2019: unresolved external symbol __imp_PyImport_ImportModule referenced in function _import_array
tmpxft_00001128_00000000-28_cusolve5.obj : error LNK2019: unresolved external symbol __imp_PyCObject_Type referenced in function _import_array
tmpxft_00001128_00000000-28_cusolve5.obj : error LNK2019: unresolved external symbol __imp_PyExc_AttributeError referenced in function _import_array
tmpxft_00001128_00000000-28_cusolve5.obj : error LNK2019: unresolved external symbol __imp_PyExc_ImportError referenced in function _import_array
tmpxft_00001128_00000000-28_cusolve5.obj : error LNK2019: unresolved external symbol __imp_PyExc_RuntimeError referenced in function _import_array
a.exe : fatal error LNK1120: 13 unresolved externals

It appears to me that can't find the python library. With msys/mingw I can link a similar library like this:

g++ bmc.o -L "/c/python25/libs" -lpython25 -shared -o bmc.pyd

which works fine (but doesn't include any of the GPU acceleration I'm working on). My guess is there's some option I need to pass link.exe through the -Xlinker command, but I can't seem to find a way to include the python library while building.

Upvotes: 0

Views: 842

Answers (1)

Peter
Peter

Reputation: 1442

Thanks to hints from @talonmies, I've concluded that what I'm trying to do is impossible for 2 reasons:

  1. python2.5 was compiled with VS 2005, which I don't have access to and probably isn't supported by nVidia (http://docs.nvidia.com/cuda/cuda-getting-started-guide-for-microsoft-windows does not include such an old compiler on its list)

This could be resolved, though, by using ctypes to load the dll rather than a standard python import. However...

  1. My python binary is 32-bit and Cuda 7.0 only supports 64-bit. The cusolver.lib and cusparse.lib (essential to my optimizations) can be found in the x64 directory of the Cuda 7.0 distribution. Linking to them while passing the "--machine 32" to nvcc does not work, although that is not very surprising.

Upvotes: 1

Related Questions