Open Cohen2902 opened 5 years ago
I have the same question as you. Have you solved it?
I have similar problem with you! how to solve it?
I have similar problem with you! how to solve it?
I use win10 system.
我的解决方法: 这个是没有链接上动态库,找不到这些函数的实现,TH.h里只提供了头文件,实现在动态链接库中ATen.dll 中,要链接上ATen.dll,就要加上ATen.lib;改 build.py 代码: 原先:extra_objects = ['src/cuda/nms_kernel.cu.o'] 改:extra_objects = ['src/ATen.lib'] extra_objects = [os.path.join(this_file, fname) for fname in extra_objects]
ffi = create_extension(
'_ext.nms',
headers=headers,
sources=sources,
define_macros=defines,
relative_to=__file__,
with_cuda=False,
extra_objects=extra_objects
)
然后在编译就可以生成了。
(base) M:\Users\Liz\MRCNN_Resnet18_final\cuda_functions\nms_3D>python build.py Including CUDA code. M:\Users\Liz\MRCNN_Resnet18_final\cuda_functions\nms_3D generating C:\Users\217216~1\AppData\Local\Temp\tmpmbg0y4hp_nms.c setting the current directory to 'C:\Users\217216~1\AppData\Local\Temp\tmpmbg0y4hp' running build_ext building '_nms' extension creating Release creating Release\Users creating Release\Users\Liz creating Release\Users\Liz\MRCNN_Resnet18_final creating Release\Users\Liz\MRCNN_Resnet18_final\cuda_functions creating Release\Users\Liz\MRCNN_Resnet18_final\cuda_functions\nms_3D creating Release\Users\Liz\MRCNN_Resnet18_final\cuda_functions\nms_3D\src C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DWITH_CUDA "-IC:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\torch\utils\ffi....\lib\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\torch\utils\ffi....\lib\include\TH" "-IC:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\torch\utils\ffi....\lib\include\THC" "-IC:\Program Files\NVIDIA Corporation\NvToolsExt\/include" "-IC:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt" /Tc_nms.c /Fo.\Release_nms.obj -std=c99 cl : Command line warning D9002 : ignoring unknown option '-std=c99' _nms.c C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DWITH_CUDA "-IC:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\torch\utils\ffi....\lib\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\torch\utils\ffi....\lib\include\TH" "-IC:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\torch\utils\ffi....\lib\include\THC" "-IC:\Program Files\NVIDIA Corporation\NvToolsExt\/include" "-IC:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt" /TcM:\Users\Liz\MRCNN_Resnet18_final\cuda_functions\nms_3D\src\nms.c /Fo.\Release\Users\Liz\MRCNN_Resnet18_final\cuda_functions\nms_3D\src\nms.obj -std=c99 cl : Command line warning D9002 : ignoring unknown option '-std=c99' nms.c M:\Users\Liz\MRCNN_Resnet18_final\cuda_functions\nms_3D\src\nms.c(12): warning C4244: 'initializing': conversion from 'int64_t' to 'long', possible loss of data M:\Users\Liz\MRCNN_Resnet18_final\cuda_functions\nms_3D\src\nms.c(13): warning C4244: 'initializing': conversion from 'int64_t' to 'long', possible loss of data M:\Users\Liz\MRCNN_Resnet18_final\cuda_functions\nms_3D\src\nms.c(15): warning C4133: 'initializing': incompatible types - from 'int64_t ' to 'long ' M:\Users\Liz\MRCNN_Resnet18_final\cuda_functions\nms_3D\src\nms.c(17): warning C4133: 'initializing': incompatible types - from 'int64_t ' to 'long ' M:\Users\Liz\MRCNN_Resnet18_final\cuda_functions\nms_3D\src\nms.c(70): warning C4133: 'initializing': incompatible types - from 'int64_t ' to 'long ' C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DWITH_CUDA "-IC:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\torch\utils\ffi....\lib\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\torch\utils\ffi....\lib\include\TH" "-IC:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\torch\utils\ffi....\lib\include\THC" "-IC:\Program Files\NVIDIA Corporation\NvToolsExt\/include" "-IC:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt" /TcM:\Users\Liz\MRCNN_Resnet18_final\cuda_functions\nms_3D\src\nms_cuda.c /Fo.\Release\Users\Liz\MRCNN_Resnet18_final\cuda_functions\nms_3D\src\nms_cuda.obj -std=c99 cl : Command line warning D9002 : ignoring unknown option '-std=c99' nms_cuda.c M:\Users\Liz\MRCNN_Resnet18_final\cuda_functions\nms_3D\src\nms_cuda.c(22): warning C4244: 'initializing': conversion from 'int64_t' to 'int', possible loss of data M:\Users\Liz\MRCNN_Resnet18_final\cuda_functions\nms_3D\src\nms_cuda.c(23): warning C4244: 'initializing': conversion from 'int64_t' to 'int', possible loss of data M:\Users\Liz\MRCNN_Resnet18_final\cuda_functions\nms_3D\src\nms_cuda.c(43): warning C4133: 'initializing': incompatible types - from 'int64_t ' to 'long ' M:\Users\Liz\MRCNN_Resnet18_final\cuda_functions\nms_3D\src\nms_cuda.c(60): warning C4133: 'initializing': incompatible types - from 'int64_t ' to 'long ' C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO "/LIBPATH:C:\Program Files\NVIDIA Corporation\NvToolsExt\/lib/x64" "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\torch\utils\ffi....\lib" "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\libs" "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\PCbuild\amd64" "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\ATLMFC\lib\x64" "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\lib\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\lib\um\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.17763.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.17763.0\um\x64" /EXPORT:PyInitnms .\Release_nms.obj .\Release\Users\Liz\MRCNN_Resnet18_final\cuda_functions\nms_3D\src\nms.obj .\Release\Users\Liz\MRCNN_Resnet18_final\cuda_functions\nms_3D\src\nms_cuda.obj M:\Users\Liz\MRCNN_Resnet18_final\cuda_functions\nms_3D\src/cuda/nms_kernel.cu.o /OUT:._nms.pyd /IMPLIB:.\Release_nms.lib Creating library .\Release_nms.lib and object .\Release_nms.exp LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library nms.obj : error LNK2001: unresolved external symbol imp_THFloatTensor_data nms.obj : error LNK2001: unresolved external symbol imp_THByteTensor_fill nms.obj : error LNK2001: unresolved external symbol imp_THByteTensor_data nms.obj : error LNK2001: unresolved external symbol imp_THByteTensor_free nms.obj : error LNK2001: unresolved external symbol impTHArgCheck nms.obj : error LNK2001: unresolved external symbol imp_THByteTensor_newWithSize1d nms.obj : error LNK2001: unresolved external symbol imp_THLongTensor_isContiguous nms.obj : error LNK2001: unresolved external symbol imp_THLongTensor_data nms.obj : error LNK2001: unresolved external symbol imp_THFloatTensor_size nms_cuda.obj : error LNK2001: unresolved external symbol __imp_THLongTensor_free nms_cuda.obj : error LNK2001: unresolved external symbol imp_THLongTensor_newWithSize2d nms_cuda.obj : error LNK2001: unresolved external symbol imp_THCudaLongTensor_newWithSize2d nms_cuda.obj : error LNK2001: unresolved external symbol __imp_THLongTensor_copyCuda nms_cuda.obj : error LNK2001: unresolved external symbol imp_THLongTensor_newWithSize1d nms_cuda.obj : error LNK2001: unresolved external symbol imp_THLongTensor_fill nms_cuda.obj : error LNK2001: unresolved external symbol imp_THCudaTensor_data nms_cuda.obj : error LNK2001: unresolved external symbol state nms_cuda.obj : error LNK2001: unresolved external symbol imp_THCudaTensor_isContiguous nms_cuda.obj : error LNK2001: unresolved external symbol imp_THCudaLongTensor_data nms_cuda.obj : error LNK2001: unresolved external symbol imp_THCudaTensor_size nms_cuda.obj : error LNK2001: unresolved external symbol imp_THCudaLongTensor_free nms_kernel.cu.o : error LNK2001: unresolved external symbol cudaConfigureCall nms_kernel.cu.o : error LNK2001: unresolved external symbol cudaSetupArgument nms_kernel.cu.o : error LNK2001: unresolved external symbol cudaLaunch nms_kernel.cu.o : error LNK2001: unresolved external symbol cudaRegisterFatBinary nms_kernel.cu.o : error LNK2001: unresolved external symbol cudaUnregisterFatBinary nms_kernel.cu.o : error LNK2001: unresolved external symbol __cudaRegisterFunction ._nms.pyd : fatal error LNK1120: 27 unresolved externals Traceback (most recent call last): File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\distutils_msvccompiler.py", line 519, in link self.spawn([self.linker] + ld_args) File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\distutils_msvccompiler.py", line 542, in spawn return super().spawn(cmd) File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\distutils\ccompiler.py", line 909, in spawn spawn(cmd, dry_run=self.dry_run) File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\distutils\spawn.py", line 38, in spawn _spawn_nt(cmd, search_path, dry_run=dry_run) File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\distutils\spawn.py", line 81, in _spawn_nt "command %r failed with exit status %d" % (cmd, rc)) distutils.errors.DistutilsExecError: command 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\link.exe' failed with exit status 1120
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\cffi\ffiplatform.py", line 51, in _build dist.run_command('build_ext') File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\distutils\dist.py", line 974, in run_command cmd_obj.run() File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\setuptools\command\build_ext.py", line 78, in run _build_ext.run(self) File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\Cython\Distutils\old_build_ext.py", line 186, in run _build_ext.build_ext.run(self) File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\distutils\command\build_ext.py", line 339, in run self.build_extensions() File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\Cython\Distutils\old_build_ext.py", line 194, in build_extensions self.build_extension(ext) File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\setuptools\command\build_ext.py", line 199, in build_extension _build_ext.build_extension(self, ext) File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\distutils\command\build_ext.py", line 558, in build_extension target_lang=language) File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\distutils\ccompiler.py", line 717, in link_shared_object extra_preargs, extra_postargs, build_temp, target_lang) File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\distutils_msvccompiler.py", line 522, in link raise LinkError(msg) distutils.errors.LinkError: command 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\link.exe' failed with exit status 1120
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "build.py", line 34, in
ffi.build()
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\torch\utils\ffi__init.py", line 189, in build
_build_extension(ffi, cffi_wrapper_name, target_dir, verbose)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\torch\utils\ffi__init__.py", line 111, in _build_extension
outfile = ffi.compile(tmpdir=tmpdir, verbose=verbose, target=libname)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\cffi\api.py", line 697, in compile
compiler_verbose=verbose, debug=debug, **kwds)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\cffi\recompiler.py", line 1520, in recompile
compiler_verbose, debug)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\cffi\ffiplatform.py", line 22, in compile
outputfilename = _build(tmpdir, ext, compiler_verbose, debug)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\cffi\ffiplatform.py", line 58, in _build
raise VerificationError('%s: %s' % (e.class.name__, e))
cffi.error.VerificationError: LinkError: command 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\link.exe' failed with exit status 1120
I have python 3.6.5, visual studio 2017 with C++ build tools and pytorch = 0.4.1 Do you have any idea what the problem is?