Invalid command option for nvcc in PyTorch?

I am trying to build a PyTorch cpp/cuda extension library on Windows. This library makes use of CMake. I am getting the “nvcc fatal : A single input file is required for a non-link phase when an outputfile is specified” error message.

As I understand, this error invariably comes because of invalid command line options. CMake apparently gets these options from the Caffe2Targets.cmake file in PyTorch distribution. I am reproducing what I believe are the relevant lines from that file.

set_target_properties(torch_cuda PROPERTIES
  INTERFACE_COMPILE_OPTIONS "/Z7;/EHa;/DNOMINMAX;/wd4267;/wd4251;/wd4522;/wd4522;/wd4838;/wd4305;/wd4244;/wd4190;/wd4101;/wd4996;/wd4275;/bigobj"
  • First question: Cuda documentation specifies that the command options begin with “-” or “–”. But, all these begin with a “/”; is that the issue? Since PyTorch is widely used, I would be surprised if use of “/” is the cause though.
  • Second question: When I searched for options like “Z7”, “EHa” etc. in cuda documentation, they did not even show up. Are they valid options at all? If not, I wonder why this file in PyTorch distribution lists them?
  • Third question: Assuming they are indeed valid options, are they documented somewhere else? My real goal is to search that documentation to determine which of those listed options is not valid, and then delete it from the file to solve the “nvcc fatal” error I am currently getting.
    Thanks!

The compiler options you are showing are options for MSVC, that is, the host compiler supported by CUDA on Windows. For a full list of the supported compiler options, please consult Microsoft’s documentation here:

As a user of MSVC I can tell you that /Z7 is a debug related switch (line information, I think), and each of the /wd switches suppresses the warning indicated by the four digit warning ID that follows it. I think /EHa is related to exception handling.

But, those options are indeed getting passed to nvcc as shown in the command that gets executed; is that as expected? Assuming those arguments such as /Z7, EHa etc. are indeed meant to be passed to the nvcc command as happens below, any idea what in this command could be causing the “nvcc fatal A single input file is required…” error? Thanks.

"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\bin\nvcc.exe" -gencode=arch=compute_61,code=\"sm_61,compute_61\" --use-local-env -ccbi
  n "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.27.29110\bin\HostX64\x64" -x cu -r
  dc=true -IC:\projects\detect3d\instseg\spconv\include -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\inc
  lude" -I"C:\Users\victoryc\AppData\Local\Continuum\anaconda3\envs\instseg\Lib\site-packages\torch\include" -I"C:\User
  s\victoryc\AppData\Local\Continuum\anaconda3\envs\instseg\Lib\site-packages\torch\include\torch\csrc\api\include" -I"
  C:\Program Files\NVIDIA Corporation\NvToolsExt\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\i
  nclude"     --keep-dir x64\Release -maxrregcount=0  --machine 64 --compile -cudart static --expt-relaxed-constexpr /Z
  7 /EHa /wd4267 /wd4251 /wd4522 /wd4838 /wd4305 /wd4244 /wd4190 /wd4101 /wd4996 /wd4275 /bigobj -Xcompiler=-Ob2    -D_
  _CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ -DNDEBUG -DNOMINMAX -DTV_WINDO
  WS -DSPCONV_CUDA -DAT_PARALLEL_OPENMP=1 -D"CMAKE_INTDIR=\"Release\"" -Dcuhash_EXPORTS -D"VERSION_INFO=\"1.1\"" -DWIN3
  2 -D_WINDOWS -DNDEBUG -DNOMINMAX -DTV_WINDOWS -DSPCONV_CUDA -DAT_PARALLEL_OPENMP=1 -D"CMAKE_INTDIR=\"Release\"" -Dcuh
  ash_EXPORTS -D_WINDLL -D_MBCS -Xcompiler "/EHsc /W3 /nologo /O2 /Fdcuhash.dir\Release\vc142.pdb /FS /Zi  /MD /GR" -o
  cuhash.dir\Release\/hash_table.cu.obj "C:\projects\detect3d\instseg\spconv\src\cuhash\hash_table.cu"
  nvcc fatal   : A single input file is required for a non-link phase when an outputfile is specified

nvcc provides a mechanism for passing compiler options to the host compiler: the -Xcompiler switch. The commandline shown is missing that switch just before the MSVC compile options starting with /Z7, but does insert it before two further sets of MSVC switches!

You would want to investigate the details of this commandline construction failure. Some of those MSVC switches seem to be potentially contradictory, such as -Ob2 and /O2, /Z7 and /Zi, and /EHa and /EHsc, so possibly there is more than one bug that needs to be addressed. Maybe release build and debug build switches are getting mashed together?

nvcc treats everything on the commandline that it does not recognize as a valid nvcc compiler switch as a filename, which is the immediate cause of the error reported.