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

Fixing Windows MSVC Compatibility #10

Closed
yuanluxu opened this issue Jan 24, 2020 · 5 comments
Closed

Fixing Windows MSVC Compatibility #10

yuanluxu opened this issue Jan 24, 2020 · 5 comments
Assignees

Comments

@yuanluxu
Copy link
Contributor

yuanluxu commented Jan 24, 2020

🐛 Bugs / Unexpected behaviors

Fixed Windows MSVC build compatibility issues. All tests passed.

If you are using pre-compiled pytorch 1.4 and torchvision 0.5. You should make the following revisions to the pytorch source codes also to successfully compile with visual studio 2019 (MSVC 19.16.27034) and CUDA 10.1.

  1. Change python/Lib/site-packages/torch/include/csrc/jit/script/module.h
  • L466, 476, 493, 506, 536
    -static constexpr *
    +static const *
  1. Change python/Lib/site-packages/torch/include/csrc/jit/argument_spec.h
  • L190
    -static constexpr size_t DEPTH_LIMIT = 128;
    +static const size_t DEPTH_LIMIT = 128;
  1. Change python/Lib/site-packages/torch/include/pybind11/cast.h
  • L1449
    -explicit operator type&() { return *(this->value); }
    +explicit operator type& () { return *((type*)(this->value)); }

If you are using CUDA 10.2 with pre-compiled pytorch 1.4 and torchvision 0.5, you need to check
Pytorch Issue [(https://github.com/pytorch/pytorch/issues/33203)] for patching the pytorch source code in addition.

Instructions To Reproduce the Issue:

Please include the following (depending on what the issue is):

  1. Any changes you made (git diff) or code you wrote
https://github.com/facebookresearch/pytorch3d/pull/9
  1. The exact command(s) you ran:
  2. What you observed (including the full logs):
<put logs here>

Please also simplify the steps as much as possible so they do not require additional resources to
run, such as a private dataset.

@srxdev0619
Copy link

Hi,

I get the following errors while trying to install Pytorch3d

c:/users/shahrukh/anaconda3/lib/site-packages/torch/include\c10/util/BFloat16.h(48): warning: calling a __host__ function from a __host__ __device__ function is not allowed

C:\Users\ShahRukh\Research\pytorch3d\pytorch3d\csrc\rasterize_meshes\geometry_utils.cuh(231): error: identifier "kEpsilon" is undefined in device code

C:/Users/ShahRukh/Research/pytorch3d/pytorch3d/csrc/rasterize_meshes/rasterize_meshes.cu(391): error: identifier "kEpsilon" is undefined in device code

C:/Users/ShahRukh/Research/pytorch3d/pytorch3d/csrc/rasterize_meshes/rasterize_meshes.cu(427): error: identifier "kEpsilon" is undefined in device code

C:/Users/ShahRukh/Research/pytorch3d/pytorch3d/csrc/rasterize_meshes/rasterize_meshes.cu(427): error: calling a __host__ function("pow<float, double, void> ") from a __global__ function("RasterizeMeshesBackwardCudaKernel") is not allowed

C:/Users/ShahRukh/Research/pytorch3d/pytorch3d/csrc/rasterize_meshes/rasterize_meshes.cu(427): error: identifier "pow<float, double, void> " is undefined in device code

C:/Users/ShahRukh/Research/pytorch3d/pytorch3d/csrc/rasterize_meshes/rasterize_meshes.cu(133): error: identifier "kEpsilon" is undefined in device code

C:/Users/ShahRukh/Research/pytorch3d/pytorch3d/csrc/rasterize_meshes/rasterize_meshes.cu(133): error: identifier "kEpsilon" is undefined in device code

C:/Users/ShahRukh/Research/pytorch3d/pytorch3d/csrc/rasterize_meshes/rasterize_meshes.cu(141): error: identifier "kEpsilon" is undefined in device code
8 errors detected in the compilation of "C:/Users/ShahRukh/AppData/Local/Temp/tmpxft_000026f0_00000000-10_rasterize_meshes.cpp1.ii".
    rasterize_meshes.cu
    error: command 'C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.1\\bin\\nvcc.exe' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\users\shahrukh\anaconda3\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\ShahRukh\\Research\\pytorch3d\\setup.py'"'"'; __file__='"'"'C:\\Users\\ShahRukh\\Research\\pytorch3d\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' develop --no-deps Check the logs for full command output.

The installation commands I ran were the following, in the order of execution

conda install -c pytorch pytorch torchvision cudatoolkit=10.1
conda install -c conda-forge -c fvcore fvcore
pip install scikit-image matplotlib imageio
git clone https://github.com/facebookresearch/pytorch3d.git
cd pytorch3d
pip install -e .

I'm using Visual Studio 2019 Community. It'd be great if these errors could be fixed. Thank you!

@yuanluxu
Copy link
Contributor Author

Hi @srxdev0619, I believe I fixed this issue in my fork. You can clone my folk and re-compile it.
https://github.com/yuanluxu/pytorch3d

@srxdev0619
Copy link

Yes! The fix works perfectly, thank you so much!

@ZM-J
Copy link

ZM-J commented Dec 30, 2020

Hi! I followed your instructions, but still failed to compile mmcv-full.

When I set types as constexpr in Lib\site-packages\torch\include\torch\csrc\jit\api, it shows:

  [28/34] C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin\nvcc --use-local-env -Xcompiler /MD -Xcompiler /wd4819 -Xcompiler /wd4251 -Xcompiler /wd4244 -Xcomp
iler /wd4267 -Xcompiler /wd4275 -Xcompiler /wd4018 -Xcompiler /wd4190 -Xcompiler /EHsc -Xcudafe --diag_suppress=base_class_has_different_dll_interface -Xcudafe --diag_sup
press=field_without_dll_interface -Xcudafe --diag_suppress=dll_interface_conflict_none_assumed -Xcudafe --diag_suppress=dll_interface_conflict_dllexport_assumed -DMMCV_WI
TH_CUDA -IC:\Users\ADMINI~1\AppData\Local\Temp\pip-install-wzd40w8w\mmcv-full\mmcv\ops\csrc -Id:\software\anaconda3\envs\ipercore\lib\site-packages\torch\include -Id:\sof
tware\anaconda3\envs\ipercore\lib\site-packages\torch\include\torch\csrc\api\include -Id:\software\anaconda3\envs\ipercore\lib\site-packages\torch\include\TH -Id:\softwar
e\anaconda3\envs\ipercore\lib\site-packages\torch\include\THC "-IC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\include" -Id:\software\anaconda3\envs\ipercore\i
nclude -Id:\software\anaconda3\envs\ipercore\include "-ID:\Software\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\ATLMFC\include" "-ID:\Software\Micros
oft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" "-ID:\Windows Kits\10\include\10.0.190
41.0\ucrt" "-ID:\Windows Kits\10\include\10.0.19041.0\shared" "-ID:\Windows Kits\10\include\10.0.19041.0\um" "-ID:\Windows Kits\10\include\10.0.19041.0\winrt" "-ID:\Windo
ws Kits\10\include\10.0.19041.0\cppwinrt" -c C:\Users\ADMINI~1\AppData\Local\Temp\pip-install-wzd40w8w\mmcv-full\mmcv\ops\csrc\pytorch\psamask_cuda.cu -o C:\Users\ADMINI~
1\AppData\Local\Temp\pip-install-wzd40w8w\mmcv-full\build\temp.win-amd64-3.6\Release\mmcv/ops/csrc/pytorch\psamask_cuda.obj -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_
CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=_ext -D_GLIBCXX_USE_CXX11_ABI=0 -gencode=arch=
compute_75,code=sm_75
  FAILED: C:/Users/ADMINI~1/AppData/Local/Temp/pip-install-wzd40w8w/mmcv-full/build/temp.win-amd64-3.6/Release/mmcv/ops/csrc/pytorch/psamask_cuda.obj
  C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin\nvcc --use-local-env -Xcompiler /MD -Xcompiler /wd4819 -Xcompiler /wd4251 -Xcompiler /wd4244 -Xcompiler /wd
4267 -Xcompiler /wd4275 -Xcompiler /wd4018 -Xcompiler /wd4190 -Xcompiler /EHsc -Xcudafe --diag_suppress=base_class_has_different_dll_interface -Xcudafe --diag_suppress=fi
eld_without_dll_interface -Xcudafe --diag_suppress=dll_interface_conflict_none_assumed -Xcudafe --diag_suppress=dll_interface_conflict_dllexport_assumed -DMMCV_WITH_CUDA 
-IC:\Users\ADMINI~1\AppData\Local\Temp\pip-install-wzd40w8w\mmcv-full\mmcv\ops\csrc -Id:\software\anaconda3\envs\ipercore\lib\site-packages\torch\include -Id:\software\an
aconda3\envs\ipercore\lib\site-packages\torch\include\torch\csrc\api\include -Id:\software\anaconda3\envs\ipercore\lib\site-packages\torch\include\TH -Id:\software\anacon
da3\envs\ipercore\lib\site-packages\torch\include\THC "-IC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\include" -Id:\software\anaconda3\envs\ipercore\include -
Id:\software\anaconda3\envs\ipercore\include "-ID:\Software\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\ATLMFC\include" "-ID:\Software\Microsoft Visu
al Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" "-ID:\Windows Kits\10\include\10.0.19041.0\ucr
t" "-ID:\Windows Kits\10\include\10.0.19041.0\shared" "-ID:\Windows Kits\10\include\10.0.19041.0\um" "-ID:\Windows Kits\10\include\10.0.19041.0\winrt" "-ID:\Windows Kits\
10\include\10.0.19041.0\cppwinrt" -c C:\Users\ADMINI~1\AppData\Local\Temp\pip-install-wzd40w8w\mmcv-full\mmcv\ops\csrc\pytorch\psamask_cuda.cu -o C:\Users\ADMINI~1\AppDat
a\Local\Temp\pip-install-wzd40w8w\mmcv-full\build\temp.win-amd64-3.6\Release\mmcv/ops/csrc/pytorch\psamask_cuda.obj -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSI
ONS__ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=_ext -D_GLIBCXX_USE_CXX11_ABI=0 -gencode=arch=compute_
75,code=sm_75
  d:/software/anaconda3/envs/ipercore/lib/site-packages/torch/include\c10/util/ThreadLocalDebugInfo.h(12): warning: modifier is ignored on an enum specifier
  
  d:/software/anaconda3/envs/ipercore/lib/site-packages/torch/include\ATen/core/boxing/impl/boxing.h(100): warning: integer conversion resulted in a change of sign
  
  d:/software/anaconda3/envs/ipercore/lib/site-packages/torch/include\ATen/record_function.h(13): warning: modifier is ignored on an enum specifier
  
  d:/software/anaconda3/envs/ipercore/lib/site-packages/torch/include\ATen/core/op_registration/op_whitelist.h(39): warning: integer conversion resulted in a change of si
gn
  
  d:/software/anaconda3/envs/ipercore/lib/site-packages/torch/include\torch/csrc/jit/ir/ir.h(1347): error: member "torch::jit::ProfileOptionalOp::Kind" may not be initial
ized
  
  d:/software/anaconda3/envs/ipercore/lib/site-packages/torch/include\torch/csrc/jit/api/module.h(485): error: member "torch::jit::detail::ModulePolicy::all_slots" may no
t be initialized
  
  d:/software/anaconda3/envs/ipercore/lib/site-packages/torch/include\torch/csrc/jit/api/module.h(498): error: member "torch::jit::detail::ParameterPolicy::all_slots" may
 not be initialized
  
  d:/software/anaconda3/envs/ipercore/lib/site-packages/torch/include\torch/csrc/jit/api/module.h(512): error: member "torch::jit::detail::BufferPolicy::all_slots" may no
t be initialized
  
  d:/software/anaconda3/envs/ipercore/lib/site-packages/torch/include\torch/csrc/jit/api/module.h(525): error: member "torch::jit::detail::AttributePolicy::all_slots" may
 not be initialized
  
  5 errors detected in the compilation of "C:/Users/ADMINI~1/AppData/Local/Temp/tmpxft_00004eac_00000000-7_psamask_cuda.cpp1.ii".
  psamask_cuda.cu

and when I set them as const, it shows:

  [31/34] C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin\nvcc --use-local-env -Xcompiler /MD -Xcompiler /wd4819 -Xcompiler /wd4251 -Xcompiler /wd4244 -Xcomp
iler /wd4267 -Xcompiler /wd4275 -Xcompiler /wd4018 -Xcompiler /wd4190 -Xcompiler /EHsc -Xcudafe --diag_suppress=base_class_has_different_dll_interface -Xcudafe --diag_sup
press=field_without_dll_interface -Xcudafe --diag_suppress=dll_interface_conflict_none_assumed -Xcudafe --diag_suppress=dll_interface_conflict_dllexport_assumed -DMMCV_WI
TH_CUDA -IC:\Users\ADMINI~1\AppData\Local\Temp\pip-install-5w_ltf2i\mmcv-full\mmcv\ops\csrc -Id:\software\anaconda3\envs\ipercore\lib\site-packages\torch\include -Id:\sof
tware\anaconda3\envs\ipercore\lib\site-packages\torch\include\torch\csrc\api\include -Id:\software\anaconda3\envs\ipercore\lib\site-packages\torch\include\TH -Id:\softwar
e\anaconda3\envs\ipercore\lib\site-packages\torch\include\THC "-IC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\include" -Id:\software\anaconda3\envs\ipercore\i
nclude -Id:\software\anaconda3\envs\ipercore\include "-ID:\Software\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\ATLMFC\include" "-ID:\Software\Micros
oft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" "-ID:\Windows Kits\10\include\10.0.190
41.0\ucrt" "-ID:\Windows Kits\10\include\10.0.19041.0\shared" "-ID:\Windows Kits\10\include\10.0.19041.0\um" "-ID:\Windows Kits\10\include\10.0.19041.0\winrt" "-ID:\Windo
ws Kits\10\include\10.0.19041.0\cppwinrt" -c C:\Users\ADMINI~1\AppData\Local\Temp\pip-install-5w_ltf2i\mmcv-full\mmcv\ops\csrc\pytorch\psamask_cuda.cu -o C:\Users\ADMINI~
1\AppData\Local\Temp\pip-install-5w_ltf2i\mmcv-full\build\temp.win-amd64-3.6\Release\mmcv/ops/csrc/pytorch\psamask_cuda.obj -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_
CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=_ext -D_GLIBCXX_USE_CXX11_ABI=0 -gencode=arch=
compute_75,code=sm_75
  FAILED: C:/Users/ADMINI~1/AppData/Local/Temp/pip-install-5w_ltf2i/mmcv-full/build/temp.win-amd64-3.6/Release/mmcv/ops/csrc/pytorch/psamask_cuda.obj
  C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin\nvcc --use-local-env -Xcompiler /MD -Xcompiler /wd4819 -Xcompiler /wd4251 -Xcompiler /wd4244 -Xcompiler /wd
4267 -Xcompiler /wd4275 -Xcompiler /wd4018 -Xcompiler /wd4190 -Xcompiler /EHsc -Xcudafe --diag_suppress=base_class_has_different_dll_interface -Xcudafe --diag_suppress=fi
eld_without_dll_interface -Xcudafe --diag_suppress=dll_interface_conflict_none_assumed -Xcudafe --diag_suppress=dll_interface_conflict_dllexport_assumed -DMMCV_WITH_CUDA 
-IC:\Users\ADMINI~1\AppData\Local\Temp\pip-install-5w_ltf2i\mmcv-full\mmcv\ops\csrc -Id:\software\anaconda3\envs\ipercore\lib\site-packages\torch\include -Id:\software\an
aconda3\envs\ipercore\lib\site-packages\torch\include\torch\csrc\api\include -Id:\software\anaconda3\envs\ipercore\lib\site-packages\torch\include\TH -Id:\software\anacon
da3\envs\ipercore\lib\site-packages\torch\include\THC "-IC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\include" -Id:\software\anaconda3\envs\ipercore\include -
Id:\software\anaconda3\envs\ipercore\include "-ID:\Software\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\ATLMFC\include" "-ID:\Software\Microsoft Visu
al Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" "-ID:\Windows Kits\10\include\10.0.19041.0\ucr
t" "-ID:\Windows Kits\10\include\10.0.19041.0\shared" "-ID:\Windows Kits\10\include\10.0.19041.0\um" "-ID:\Windows Kits\10\include\10.0.19041.0\winrt" "-ID:\Windows Kits\
10\include\10.0.19041.0\cppwinrt" -c C:\Users\ADMINI~1\AppData\Local\Temp\pip-install-5w_ltf2i\mmcv-full\mmcv\ops\csrc\pytorch\psamask_cuda.cu -o C:\Users\ADMINI~1\AppDat
a\Local\Temp\pip-install-5w_ltf2i\mmcv-full\build\temp.win-amd64-3.6\Release\mmcv/ops/csrc/pytorch\psamask_cuda.obj -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSI
ONS__ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=_ext -D_GLIBCXX_USE_CXX11_ABI=0 -gencode=arch=compute_
75,code=sm_75
  d:/software/anaconda3/envs/ipercore/lib/site-packages/torch/include\c10/util/ThreadLocalDebugInfo.h(12): warning: modifier is ignored on an enum specifier
  
  d:/software/anaconda3/envs/ipercore/lib/site-packages/torch/include\ATen/core/boxing/impl/boxing.h(100): warning: integer conversion resulted in a change of sign
  
  d:/software/anaconda3/envs/ipercore/lib/site-packages/torch/include\ATen/record_function.h(13): warning: modifier is ignored on an enum specifier
  
  d:/software/anaconda3/envs/ipercore/lib/site-packages/torch/include\ATen/core/op_registration/op_whitelist.h(39): warning: integer conversion resulted in a change of si
gn
  
  d:/software/anaconda3/envs/ipercore/lib/site-packages/torch/include\torch/csrc/jit/ir/ir.h(1347): error: member "torch::jit::ProfileOptionalOp::Kind" may not be initial
ized

So, I think that we may replace constexpr * in torch/include\torch/csrc/jit/ir/ir.h to const * as well. However, when I did this, it shows:

  d:\software\anaconda3\envs\ipercore\lib\site-packages\torch\include\torch/csrc/jit/ir/ir.h(1347): error C2864: torch::jit::ProfileOptionalOp::Kind: Static data members with in-class initialization expressions must have an immutable constant integral type, or must be designated as "inline"
  d:\software\anaconda3\envs\ipercore\lib\site-packages\torch\include\torch/csrc/jit/ir/ir.h(1347): note: The type is “const c10::Symbol”

Could you help me?

BTW, I use Windows 10 1909, with CUDA 10.1. I use Visual Studio Community 2019 with MSVC v142 as compilers and libraries. My python version is 3.6.6 and my pytorch version is 1.7.1.

@ZM-J
Copy link

ZM-J commented Dec 30, 2020

I think this answer has solved my problem: Just comment out the line.

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

4 participants