Error in Building Pytorch from Source : Error C2059: syntax error: 'bad suffix on number'

I am trying to build Pytorch from source using CUDA10.0. I am facing the following issue.

Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Copyright (C) Microsoft Corporation.  All rights reserved.

[227/5493] Building C object confu-deps\XNNPACK\CMakeFiles\XNNPACK.dir\src\subgraph\sigmoid.c.obj
cl : Command line warning D9025 : overriding '/O2' with '/O1'
[228/5493] Building C object confu-deps\XNNPACK\CMakeFiles\XNNPACK.dir\src\subgraph\square-root.c.obj
cl : Command line warning D9025 : overriding '/O2' with '/O1'
[229/5493] Building C object confu-deps\XNNPACK\CMakeFiles\XNNPACK.dir\src\subgraph\softmax.c.obj
cl : Command line warning D9025 : overriding '/O2' with '/O1'
[230/5493] Building C object confu-deps\XNNPACK\CMakeFiles\XNNPACK.dir\src\subgraph\multiply2.c.obj
cl : Command line warning D9025 : overriding '/O2' with '/O1'
[232/5493] Building C object confu-deps\XNNPACK\CMakeFiles\XNNPACK.dir\src\subgraph\prelu.c.obj
cl : Command line warning D9025 : overriding '/O2' with '/O1'
[234/5493] Building C object confu-deps\XNNPACK\CMakeFiles\XNNPACK.dir\src\subgraph\negate.c.obj
cl : Command line warning D9025 : overriding '/O2' with '/O1'
[235/5493] Building C object confu-deps\XNNPACK\CMakeFiles\XNNPACK.dir\src\operators\average-pooling-nhwc.c.obj
FAILED: confu-deps/XNNPACK/CMakeFiles/XNNPACK.dir/src/operators/average-pooling-nhwc.c.obj
C:\PROGRA~2\MICROS~3\2017\COMMUN~1\VC\Tools\MSVC\1411~1.255\bin\HostX64\x64\cl.exe  /nologo -DCPUINFO_SUPPORTED_PLATFORM=1 -DFXDIV_USE_INLINE_ASSEMBLY=0 -DWIN32_LEAN_AND_MEAN -DXNN_ENABLE_ASSEMBLY=1 -DXNN_ENABLE_MEMOPT=1 -DXNN_ENABLE_SPARSE=1 -DXNN_LOG_LEVEL=0 -D_WIN32_WINNT=0x0601 -Drestrict="" -I..\third_party\XNNPACK\include -I..\third_party\XNNPACK\src -I..\third_party\cpuinfo\deps\clog\include -I..\third_party\cpuinfo\include -I..\third_party\pthreadpool\include -I..\third_party\FXdiv\include -I..\third_party\FP16\include -I..\third_party\protobuf\src /DWIN32 /D_WINDOWS /w /bigobj /MD /O2 /Ob2 /DNDEBUG /w /bigobj /wd4146  /O1 /showIncludes /Foconfu-deps\XNNPACK\CMakeFiles\XNNPACK.dir\src\operators\average-pooling-nhwc.c.obj /Fdconfu-deps\XNNPACK\CMakeFiles\XNNPACK.dir\XNNPACK.pdb /FS -c ..\third_party\XNNPACK\src\operators\average-pooling-nhwc.c
cl : Command line warning D9025 : overriding '/O2' with '/O1'
..\third_party\XNNPACK\src\xnnpack/params-init.h(825): error C2059: syntax error: 'bad suffix on number'
..\third_party\XNNPACK\src\xnnpack/params-init.h(840): error C2059: syntax error: 'bad suffix on number'
..\third_party\XNNPACK\src\operators\average-pooling-nhwc.c(157): error C2059: syntax error: 'bad suffix on number'
[237/5493] Building C object confu-deps\XNNPACK\CMakeFiles\XNNPACK.dir\src\operators\binary-elementwise-nd.c.obj
FAILED: confu-deps/XNNPACK/CMakeFiles/XNNPACK.dir/src/operators/binary-elementwise-nd.c.obj
C:\PROGRA~2\MICROS~3\2017\COMMUN~1\VC\Tools\MSVC\1411~1.255\bin\HostX64\x64\cl.exe  /nologo -DCPUINFO_SUPPORTED_PLATFORM=1 -DFXDIV_USE_INLINE_ASSEMBLY=0 -DWIN32_LEAN_AND_MEAN -DXNN_ENABLE_ASSEMBLY=1 -DXNN_ENABLE_MEMOPT=1 -DXNN_ENABLE_SPARSE=1 -DXNN_LOG_LEVEL=0 -D_WIN32_WINNT=0x0601 -Drestrict="" -I..\third_party\XNNPACK\include -I..\third_party\XNNPACK\src -I..\third_party\cpuinfo\deps\clog\include -I..\third_party\cpuinfo\include -I..\third_party\pthreadpool\include -I..\third_party\FXdiv\include -I..\third_party\FP16\include -I..\third_party\protobuf\src /DWIN32 /D_WINDOWS /w /bigobj /MD /O2 /Ob2 /DNDEBUG /w /bigobj /wd4146  /O1 /showIncludes /Foconfu-deps\XNNPACK\CMakeFiles\XNNPACK.dir\src\operators\binary-elementwise-nd.c.obj /Fdconfu-deps\XNNPACK\CMakeFiles\XNNPACK.dir\XNNPACK.pdb /FS -c ..\third_party\XNNPACK\src\operators\binary-elementwise-nd.c
cl : Command line warning D9025 : overriding '/O2' with '/O1'
..\third_party\XNNPACK\src\xnnpack/params-init.h(825): error C2059: syntax error: 'bad suffix on number'
..\third_party\XNNPACK\src\xnnpack/params-init.h(840): error C2059: syntax error: 'bad suffix on number'
..\third_party\XNNPACK\src\operators\binary-elementwise-nd.c(206): error C2059: syntax error: 'bad suffix on number'
..\third_party\XNNPACK\src\operators\binary-elementwise-nd.c(214): error C2059: syntax error: 'bad suffix on number'
[238/5493] Building C object confu-deps\XNNPACK\CMakeFiles\XNNPACK.dir\src\operators\argmax-pooling-nhwc.c.obj
FAILED: confu-deps/XNNPACK/CMakeFiles/XNNPACK.dir/src/operators/argmax-pooling-nhwc.c.obj
C:\PROGRA~2\MICROS~3\2017\COMMUN~1\VC\Tools\MSVC\1411~1.255\bin\HostX64\x64\cl.exe  /nologo -DCPUINFO_SUPPORTED_PLATFORM=1 -DFXDIV_USE_INLINE_ASSEMBLY=0 -DWIN32_LEAN_AND_MEAN -DXNN_ENABLE_ASSEMBLY=1 -DXNN_ENABLE_MEMOPT=1 -DXNN_ENABLE_SPARSE=1 -DXNN_LOG_LEVEL=0 -D_WIN32_WINNT=0x0601 -Drestrict="" -I..\third_party\XNNPACK\include -I..\third_party\XNNPACK\src -I..\third_party\cpuinfo\deps\clog\include -I..\third_party\cpuinfo\include -I..\third_party\pthreadpool\include -I..\third_party\FXdiv\include -I..\third_party\FP16\include -I..\third_party\protobuf\src /DWIN32 /D_WINDOWS /w /bigobj /MD /O2 /Ob2 /DNDEBUG /w /bigobj /wd4146  /O1 /showIncludes /Foconfu-deps\XNNPACK\CMakeFiles\XNNPACK.dir\src\operators\argmax-pooling-nhwc.c.obj /Fdconfu-deps\XNNPACK\CMakeFiles\XNNPACK.dir\XNNPACK.pdb /FS -c ..\third_party\XNNPACK\src\operators\argmax-pooling-nhwc.c
cl : Command line warning D9025 : overriding '/O2' with '/O1'
..\third_party\XNNPACK\src\xnnpack/params-init.h(825): error C2059: syntax error: 'bad suffix on number'
..\third_party\XNNPACK\src\xnnpack/params-init.h(840): error C2059: syntax error: 'bad suffix on number'
[239/5493] Building C object confu-deps\XNNPACK\CMakeFiles\XNNPACK.dir\src\operators\constant-pad-nd.c.obj
FAILED: confu-deps/XNNPACK/CMakeFiles/XNNPACK.dir/src/operators/constant-pad-nd.c.obj
C:\PROGRA~2\MICROS~3\2017\COMMUN~1\VC\Tools\MSVC\1411~1.255\bin\HostX64\x64\cl.exe  /nologo -DCPUINFO_SUPPORTED_PLATFORM=1 -DFXDIV_USE_INLINE_ASSEMBLY=0 -DWIN32_LEAN_AND_MEAN -DXNN_ENABLE_ASSEMBLY=1 -DXNN_ENABLE_MEMOPT=1 -DXNN_ENABLE_SPARSE=1 -DXNN_LOG_LEVEL=0 -D_WIN32_WINNT=0x0601 -Drestrict="" -I..\third_party\XNNPACK\include -I..\third_party\XNNPACK\src -I..\third_party\cpuinfo\deps\clog\include -I..\third_party\cpuinfo\include -I..\third_party\pthreadpool\include -I..\third_party\FXdiv\include -I..\third_party\FP16\include -I..\third_party\protobuf\src /DWIN32 /D_WINDOWS /w /bigobj /MD /O2 /Ob2 /DNDEBUG /w /bigobj /wd4146  /O1 /showIncludes /Foconfu-deps\XNNPACK\CMakeFiles\XNNPACK.dir\src\operators\constant-pad-nd.c.obj /Fdconfu-deps\XNNPACK\CMakeFiles\XNNPACK.dir\XNNPACK.pdb /FS -c ..\third_party\XNNPACK\src\operators\constant-pad-nd.c
cl : Command line warning D9025 : overriding '/O2' with '/O1'
..\third_party\XNNPACK\src\xnnpack/params-init.h(825): error C2059: syntax error: 'bad suffix on number'
..\third_party\XNNPACK\src\xnnpack/params-init.h(840): error C2059: syntax error: 'bad suffix on number'
[240/5493] Building C object confu-deps\XNNPACK\CMakeFiles\XNNPACK.dir\src\operators\channel-shuffle-nc.c.obj
cl : Command line warning D9025 : overriding '/O2' with '/O1'
[241/5493] Building C object confu-deps\XNNPACK\CMakeFiles\XNNPACK.dir\src\operators\convolution-nhwc.c.obj
FAILED: confu-deps/XNNPACK/CMakeFiles/XNNPACK.dir/src/operators/convolution-nhwc.c.obj
C:\PROGRA~2\MICROS~3\2017\COMMUN~1\VC\Tools\MSVC\1411~1.255\bin\HostX64\x64\cl.exe  /nologo -DCPUINFO_SUPPORTED_PLATFORM=1 -DFXDIV_USE_INLINE_ASSEMBLY=0 -DWIN32_LEAN_AND_MEAN -DXNN_ENABLE_ASSEMBLY=1 -DXNN_ENABLE_MEMOPT=1 -DXNN_ENABLE_SPARSE=1 -DXNN_LOG_LEVEL=0 -D_WIN32_WINNT=0x0601 -Drestrict="" -I..\third_party\XNNPACK\include -I..\third_party\XNNPACK\src -I..\third_party\cpuinfo\deps\clog\include -I..\third_party\cpuinfo\include -I..\third_party\pthreadpool\include -I..\third_party\FXdiv\include -I..\third_party\FP16\include -I..\third_party\protobuf\src /DWIN32 /D_WINDOWS /w /bigobj /MD /O2 /Ob2 /DNDEBUG /w /bigobj /wd4146  /O1 /showIncludes /Foconfu-deps\XNNPACK\CMakeFiles\XNNPACK.dir\src\operators\convolution-nhwc.c.obj /Fdconfu-deps\XNNPACK\CMakeFiles\XNNPACK.dir\XNNPACK.pdb /FS -c ..\third_party\XNNPACK\src\operators\convolution-nhwc.c
cl : Command line warning D9025 : overriding '/O2' with '/O1'
..\third_party\XNNPACK\src\xnnpack/params-init.h(825): error C2059: syntax error: 'bad suffix on number'
..\third_party\XNNPACK\src\xnnpack/params-init.h(840): error C2059: syntax error: 'bad suffix on number'
[242/5493] Linking C static library lib\clog.lib
ninja: build stopped: subcommand failed.

Please let me know if you need any other details.

It seems XNNPACK is failing during the compilation. In case you don’t need this 3rd party library, you could disable it via USE_XNNPACK=0.

Using set USE_XNNPACK=0 that works but now I am getting this error @ptrblck.

FAILED: third_party/gloo/gloo/CMakeFiles/gloo_cuda.dir/gloo_cuda_generated_cuda.cu.obj
cmd.exe /C "cd /D C:\Users\Dell\Desktop\Pytorch\pytorch\build\third_party\gloo\gloo\CMakeFiles\gloo_cuda.dir && C:\Users\Dell\Anaconda3\Library\bin\cmake.exe -E make_directory C:/Users/Dell/Desktop/Pytorch/pytorch/build/third_party/gloo/gloo/CMakeFiles/gloo_cuda.dir//. && C:\Users\Dell\Anaconda3\Library\bin\cmake.exe -D verbose:BOOL=OFF -D build_configuration:STRING=Release -D generated_file:STRING=C:/Users/Dell/Desktop/Pytorch/pytorch/build/third_party/gloo/gloo/CMakeFiles/gloo_cuda.dir//./gloo_cuda_generated_cuda.cu.obj -D generated_cubin_file:STRING=C:/Users/Dell/Desktop/Pytorch/pytorch/build/third_party/gloo/gloo/CMakeFiles/gloo_cuda.dir//./gloo_cuda_generated_cuda.cu.obj.cubin.txt -P C:/Users/Dell/Desktop/Pytorch/pytorch/build/third_party/gloo/gloo/CMakeFiles/gloo_cuda.dir//gloo_cuda_generated_cuda.cu.obj.Release.cmake"
Failed to run C:/Program Files (x86)/Microsoft Visual Studio/2017/Commu (The system cannot find the file specified.
).
CMake Error at gloo_cuda_generated_cuda.cu.obj.Release.cmake:217 (message):
  Error generating
  C:/Users/Dell/Desktop/Pytorch/pytorch/build/third_party/gloo/gloo/CMakeFiles/gloo_cuda.dir//./gloo_cuda_generated_cuda.cu.obj

and to resolve this I used
set USE_DISTRIBUTED=0

But now I am getting error as:

FAILED: bin/caffe2_nvrtc.dll lib/caffe2_nvrtc.lib
cmd.exe /C "cd . && C:\Users\Dell\Anaconda3\Library\bin\cmake.exe -E vs_link_dll --intdir=caffe2\CMakeFiles\caffe2_nvrtc.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100162~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100162~1.0\x64\mt.exe --manifests  -- C:\PROGRA~2\MICROS~3\2017\COMMUN~1\VC\Tools\MSVC\1416~1.270\bin\Hostx64\x64\link.exe /nologo caffe2\CMakeFiles\caffe2_nvrtc.dir\__\aten\src\ATen\cuda\nvrtc_stub\ATenNVRTC.cpp.obj  /out:bin\caffe2_nvrtc.dll /implib:lib\caffe2_nvrtc.lib /pdb:bin\caffe2_nvrtc.pdb /dll /version:0.0 /machine:x64 /ignore:4049 /ignore:4217 /INCREMENTAL:NO  "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\lib\x64\cuda.lib"  "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\lib\x64\nvrtc.lib"  -DELAYLOAD:nvcuda.dll  delayimp.lib  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib  && cd ."
LINK: command "C:\PROGRA~2\MICROS~3\2017\COMMUN~1\VC\Tools\MSVC\1416~1.270\bin\Hostx64\x64\link.exe /nologo caffe2\CMakeFiles\caffe2_nvrtc.dir\__\aten\src\ATen\cuda\nvrtc_stub\ATenNVRTC.cpp.obj /out:bin\caffe2_nvrtc.dll /implib:lib\caffe2_nvrtc.lib /pdb:bin\caffe2_nvrtc.pdb /dll /version:0.0 /machine:x64 /ignore:4049 /ignore:4217 /INCREMENTAL:NO C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\lib\x64\cuda.lib C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\lib\x64\nvrtc.lib -DELAYLOAD:nvcuda.dll delayimp.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:bin\caffe2_nvrtc.dll.manifest" failed (exit code 1120) with the following output:
   Creating library lib\caffe2_nvrtc.lib and object lib\caffe2_nvrtc.exp
ATenNVRTC.cpp.obj : error LNK2019: unresolved external symbol nvrtcGetCUBINSize referenced in function load_nvrtc
ATenNVRTC.cpp.obj : error LNK2019: unresolved external symbol nvrtcGetCUBIN referenced in function load_nvrtc
bin\caffe2_nvrtc.dll : fatal error LNK1120: 2 unresolved externals
[931/3940] Generating ../aten/src/ATen/CPUFunctio...orBody.h, ../aten/src/ATen/core/TensorMethods.cppninja: build stopped: subcommand failed.

The error message “C2059: syntax error: ‘bad suffix on number’” usually occurs when there is a problem with the syntax of a number or a literal in your code.

In the context of building PyTorch from source, this error is most likely caused by an incorrect version of the Visual Studio compiler. PyTorch requires the use of the Visual Studio 2019 compiler, and if you are using an older version, you may encounter this error.

To fix this error, you can try the following steps:

Check that you have the correct version of the Visual Studio compiler installed. You can download and install Visual Studio 2019 Community edition from the official Microsoft website.

Make sure that the correct version of the compiler is being used in the build process. You can set the compiler version by running the following command in the command prompt before building PyTorch:

arduino
Copy code
set “CMAKE_CXX_COMPILER=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64\cl.exe”
Note that the exact path to the compiler may vary depending on your installation.

If you are using a different build system, such as CMake, make sure that it is configured to use the correct version of the Visual Studio compiler.
If these steps do not resolve the issue, you may need to provide more details about the specific error message and your build environment to diagnose the problem further.

Regards,
Rachel Gomez