rosinality / stylegan2-pytorch

Implementation of Analyzing and Improving the Image Quality of StyleGAN (StyleGAN 2) in PyTorch
MIT License
2.74k stars 623 forks source link

Windows10 Error building extension #47

Open Ken1256 opened 4 years ago

Ken1256 commented 4 years ago

Windows10 VS 2017 PyTorch 1.3.1 CUDA 10.1

Any idea? Thanks

[3/3] "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64/link.exe" fused_bias_act.o fused_bias_act_kernel.cuda.o /nologo /DLL c10.lib torch.lib torch_python.lib _C.lib "/LIBPATH:C:\Program Files\Python37\libs" "/LIBPATH:C:\Program Files\Python37\lib\site-packages\torch\lib" "/LIBPATH:C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\lib/x64" cudart.lib /out:fused.pyd

FAILED: fused.pyd 

"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64/link.exe" fused_bias_act.o fused_bias_act_kernel.cuda.o /nologo /DLL c10.lib torch.lib torch_python.lib _C.lib "/LIBPATH:C:\Program Files\Python37\libs" "/LIBPATH:C:\Program Files\Python37\lib\site-packages\torch\lib" "/LIBPATH:C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\lib/x64" cudart.lib /out:fused.pyd

   Creating library fused.lib and object fused.exp

fused_bias_act_kernel.cuda.o : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl c10::cuda::CUDAStream::operator struct CUstream_st *(void)const " (__imp_??BCUDAStream@cuda@c10@@QEBAPEAUCUstream_st@@XZ) referenced in function "class at::Tensor __cdecl fused_bias_act_op(class at::Tensor const &,class at::Tensor const &,class at::Tensor const &,int,int,float,float)" (?fused_bias_act_op@@YA?AVTensor@at@@AEBV12@00HHMM@Z)

fused_bias_act_kernel.cuda.o : error LNK2019: unresolved external symbol "__declspec(dllimport) class c10::cuda::CUDAStream __cdecl c10::cuda::getCurrentCUDAStream(short)" (__imp_?getCurrentCUDAStream@cuda@c10@@YA?AVCUDAStream@12@F@Z) referenced in function "class at::Tensor __cdecl fused_bias_act_op(class at::Tensor const &,class at::Tensor const &,class at::Tensor const &,int,int,float,float)" (?fused_bias_act_op@@YA?AVTensor@at@@AEBV12@00HHMM@Z)

fused.pyd : fatal error LNK1120: 2 unresolved externals

ninja: build stopped: subcommand failed.
rosinality commented 4 years ago

Seems like that you need to do some configurations for compiling in windows: https://github.com/pytorch/pytorch/issues/15757#issuecomment-452113121 https://pytorch.org/docs/stable/notes/windows.html#cpp-extension

neoragex2002 commented 4 years ago

Seems like that you need to do some configurations for compiling in windows: pytorch/pytorch#15757 (comment) https://pytorch.org/docs/stable/notes/windows.html#cpp-extension

@rosinality I have used 'x86_x64 Cross Tools Command Prompt for VS 2017' but still have the same troubles about compiling these CUDA extensions under win10. I have read above links carefully, but unfortunately I am new for torch c++ extensions and could not to find the point. Would you plz give some more detailed hints?

rosinality commented 4 years ago

@neoragex2002 I don't know much about compiling cuda extensions in windows, too. I think you need to check you can compile cuda kernels in windows first. Then please give me a compiler error logs.

neoragex2002 commented 4 years ago

@rosinality Finally I found a hack :D

in .\op\fused_act.py: image

in .\op\upfirdn2d.py: image

The ldflags of 'c10_cuda.lib' is the key to solve the problem. sorry for my kinda messy screenshots!

rosinality commented 4 years ago

@neoragex2002 Interesting! Glad to hear that you have resolved the problem.

neoragex2002 commented 4 years ago

@neoragex2002 Interesting! Glad to hear that you have resolved the problem.

I think this way of hacking may not be portable (I didn't test in linux). so it is not a patch, but a suggestion for your consideration. Thanks for your help!