Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Solved] dcn_v2_cuda.obj : error LNK2001: unresolved external symbol state caused by extern THCState *state; #14

Closed
ausk opened this issue Apr 18, 2019 · 9 comments

Comments

@ausk
Copy link

ausk commented Apr 18, 2019

First thank you for your job.

When compiling the DCNv2 on Win10 with Pytorch 1.0.1 using make.sh, error occurs at the last step:

dcn_v2_cuda.obj : error LNK2001: unresolved external symbol state caused by extern THCState *state;

The original error info is in Chinese:

... 
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:D:\Programs\Python\Python37\lib\site-packages\torch\lib /LIBPATH:D:\Programs\Nvidia\CudaToolkit\v10.1\lib/x64 /LIBPATH:D:\Programs\Python\Python37\libs /LIBPATH:D:\Programs\Python\Python37\PCbuild\amd64 "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\LIB\amd64" "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\LIB\amd64" "/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" cudart.lib c10.lib caffe2.lib torch.lib torch_python.lib caffe2_gpu.lib _C.lib /EXPORT:PyInit__ext build\temp.win-amd64-3.7\Release\Projects\Python\201904\centernet\CenterNet-master\src\lib\models\networks\DCNv2\src\vision.obj build\temp.win-amd64-3.7\Release\Projects\Python\201904\centernet\CenterNet-master\src\lib\models\networks\DCNv2\src\cpu\dcn_v2_cpu.obj build\temp.win-amd64-3.7\Release\Projects\Python\201904\centernet\CenterNet-master\src\lib\models\networks\DCNv2\src\cuda\dcn_v2_cuda.obj build\temp.win-amd64-3.7\Release\Projects\Python\201904\centernet\CenterNet-master\src\lib\models\networks\DCNv2\src\cuda\dcn_v2_im2col_cuda.obj build\temp.win-amd64-3.7\Release\Projects\Python\201904\centernet\CenterNet-master\src\lib\models\networks\DCNv2\src\cuda\dcn_v2_psroi_pooling_cuda.obj /OUT:build\lib.win-amd64-3.7\_ext.cp37-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.7\Release\Projects\Python\201904\centernet\CenterNet-master\src\lib\models\networks\DCNv2\src\_ext.cp37-win_amd64.lib
vision.obj : warning LNK4197: 多次指定导出“PyInit__ext”;使用第一个规范
  正在创建库 build\temp.win-amd64-3.7\Release\Projects\Python\201904\centernet\CenterNet-master\src\lib\models\networks\DCNv2\src\_ext.cp37-win_amd64.lib 和对象 build\temp.win-amd64-3.7\Release\Projects\Python\201904\centernet\CenterNet-master\src\lib\models\networks\DCNv2\src\_ext.cp37-win_amd64.exp
dcn_v2_cuda.obj : error LNK2001: 无法解析的外部符号 "struct THCState * state" (?state@@3PEAUTHCState@@EA)
build\lib.win-amd64-3.7\_ext.cp37-win_amd64.pyd : fatal error LNK1120: 1 个无法解析的外部命令
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\link.exe' failed with exit status 1120

I want to know: does DCNv2 support Pytorch 1.0.1 + Cuda 10.1 + Win10 64 ?

@ausk
Copy link
Author

ausk commented Apr 18, 2019

I find there is an declaration in src/cuda/dcn_va_cuda.cu

extern THCState *state;

But I can't find where it is initialized.

Then I modify the line to the following, and it compiles and works ok:

THCState *state = at::globalContext().lazyInitCUDA(); 

Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.__version__
'1.0.1'
>>> 
>>> from dcn_v2 import DCN
>>> input = torch.randn(2, 64, 128, 128).cuda()
>>> # wrap all things (offset and mask) in DCN
... dcn = DCN(64, 64, kernel_size=(3,3), stride=1, padding=1, deformable_groups=2).cuda()
>>> print(dcn)
DCN(
  (conv_offset_mask): Conv2d(64, 54, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
)
>>> output = dcn(input)
>>> print(output.shape)
torch.Size([2, 64, 128, 128])
>>>
>>> from dcn_v2 import DCNPooling
>>> input = torch.randn(2, 32, 64, 64).cuda()
>>> batch_inds = torch.randint(2, (20, 1)).cuda().float()
>>> x = torch.randint(256, (20, 1)).cuda().float()
>>> y = torch.randint(256, (20, 1)).cuda().float()
>>> w = torch.randint(64, (20, 1)).cuda().float()
>>> h = torch.randint(64, (20, 1)).cuda().float()
>>> rois = torch.cat((batch_inds, x, y, x + w, y + h), dim=1)
>>>
>>> # mdformable pooling (V2)
... # wrap all things (offset and mask) in DCNPooling
... dpooling = DCNPooling(spatial_scale=1.0 / 4,
...                      pooled_size=7,
...                      output_dim=32,
...                      no_trans=False,
...                      group_size=1,
...                      trans_std=0.1).cuda()
>>>
>>> print(dpooling)
DCNPooling(
  (offset_mask_fc): Sequential(
    (0): Linear(in_features=1568, out_features=1024, bias=True)
    (1): ReLU(inplace)
    (2): Linear(in_features=1024, out_features=1024, bias=True)
    (3): ReLU(inplace)
    (4): Linear(in_features=1024, out_features=147, bias=True)
  )
)
>>>
>>> dout = dpooling(input, rois)
>>> print(dout.shape)
torch.Size([20, 32, 7, 7])

@ausk ausk changed the title dcn_v2_cuda.obj : error LNK2001: unresolved external symbol state caused by extern THCState *state; [Solved] dcn_v2_cuda.obj : error LNK2001: unresolved external symbol state caused by extern THCState *state; Apr 18, 2019
@mk123qwe
Copy link

how to compile in windows and run sh
git bash?
Can you elaborate on GIT and GCC versions?

@ausk
Copy link
Author

ausk commented Apr 25, 2019

I have Git for Windows, make.exe、VS2017、 Cuda10.1、torch 1.0.1 on my PC. And I also set paths for cl.exe bash.exe make.exe and cuda.

prabindh added a commit to prabindh/DCNv2 that referenced this issue Apr 25, 2019
@mk123qwe
Copy link

mk123qwe commented Apr 25, 2019

DCNv2 is failed,external is failed

output = dcn(input)
Traceback (most recent call last):
File "", line 1, in
File "D:\Anaconda3\envs\CenterNet\lib\site-packages\torch\nn\modules\module.py", line 489, in call
result = self.forward(*input, **kwargs)
File "d:\research\centernet-master\src\lib\models\networks\dcnv2\dcn_v2.py", line 128, in forward
self.deformable_groups)
File "d:\research\centernet-master\src\lib\models\networks\dcnv2\dcn_v2.py", line 25, in forward
output = _backend.dcn_v2_forward(input, weight, bias,
AttributeError: module '_ext' has no attribute 'dcn_v2_forward'

running build_ext
building 'nms' extension
D:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -ID:\Anaconda3\envs\CenterNet\lib\site-packages\numpy\core\include -ID:\Anaconda3\envs\CenterNet\include -ID:\Anaconda3\envs\CenterNet\include "-ID:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\shared" "-IC:\Program Files (x86)\Windows Kits\8.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\winrt" /Tcnms.c /Fobuild\temp.win-amd64-3.6\Release\nms.obj -Wno-cpp -Wno-unused-function
cl : Command line error D8021 : invalid numeric argument '/Wno-cpp'
error: command 'D:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe' failed with exit status 2

@mk123qwe
Copy link

Generating code
Finished generating code
running develop
running egg_info
creating DCNv2.egg-info
writing DCNv2.egg-info\PKG-INFO
writing dependency_links to DCNv2.egg-info\dependency_links.txt
writing top-level names to DCNv2.egg-info\top_level.txt
writing manifest file 'DCNv2.egg-info\SOURCES.txt'
reading manifest file 'DCNv2.egg-info\SOURCES.txt'
writing manifest file 'DCNv2.egg-info\SOURCES.txt'
running build_ext
copying build\lib.win-amd64-3.6_ext.cp36-win_amd64.pyd ->
Creating d:\anaconda3\envs\centernet\lib\site-packages\DCNv2.egg-link (link to .)
DCNv2 0.1 is already the active version in easy-install.pth

Installed d:\research\centernet-master\src\lib\models\networks\dcnv2
Processing dependencies for DCNv2==0.1
Finished processing dependencies for DCNv2==0.1

@ausk ausk closed this as completed Apr 26, 2019
@MenGuangwen-CN-0411
Copy link

@ausk ,Thanks a lot,it works well~

@CandyCook
Copy link

DCNv2 is failed,external is failed

output = dcn(input)
Traceback (most recent call last):
File "", line 1, in
File "D:\Anaconda3\envs\CenterNet\lib\site-packages\torch\nn\modules\module.py", line 489, in call
result = self.forward(*input, **kwargs)
File "d:\research\centernet-master\src\lib\models\networks\dcnv2\dcn_v2.py", line 128, in forward
self.deformable_groups)
File "d:\research\centernet-master\src\lib\models\networks\dcnv2\dcn_v2.py", line 25, in forward
output = _backend.dcn_v2_forward(input, weight, bias,
AttributeError: module '_ext' has no attribute 'dcn_v2_forward'

running build_ext
building 'nms' extension
D:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -ID:\Anaconda3\envs\CenterNet\lib\site-packages\numpy\core\include -ID:\Anaconda3\envs\CenterNet\include -ID:\Anaconda3\envs\CenterNet\include "-ID:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\shared" "-IC:\Program Files (x86)\Windows Kits\8.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\winrt" /Tcnms.c /Fobuild\temp.win-amd64-3.6\Release\nms.obj -Wno-cpp -Wno-unused-function
cl : Command line error D8021 : invalid numeric argument '/Wno-cpp'
error: command 'D:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe' failed with exit status 2

did you sovle this problem? I meet the same question again.

@CandyCook
Copy link

error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe' failed with exit status 2

How can i solve it

@allezsyh
Copy link

error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe' failed with exit status 2

How can i solve it

check this: xingyizhou/CenterNet#7 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants