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

Fails to compile on NVCC CUDA 11.0 #53

Closed
ghost opened this issue Feb 4, 2021 · 24 comments
Closed

Fails to compile on NVCC CUDA 11.0 #53

ghost opened this issue Feb 4, 2021 · 24 comments

Comments

@ghost
Copy link

ghost commented Feb 4, 2021

The following code snippet will not compile in Nvidia's compiler.

  #include <boost/signals2/signal.hpp>
  
  // TODO: This is an example of a library function
  void fnBoostPreprocessorHeader()
  {
  }

The compiler chokes somewhere inside of the include statement without any additional code except the snippet above. The following error is returned:

C1012 unmatched parenthesis: missing ')' BoostPreprocessorHeader in C:\vcpkg\installed\x64-windows-static\include\boost\preprocessor\slot\detail\shared.hpp on line 27

I have spoken to the nvidia compiler group and they responded with the following:

We checked the issue and confirmed that it is a Boost issue .The error is emitted by Microsoft cl.exe compiler. Something in the    Boost headers is checking for one of the CUDA macros (__CUDACC__ / __NVCC__) and enabling code that is not accepted by the Microsoft compiler used for preprocessing.
We suggest you track a ticket to Boost with this reproducer . Thank you.

Nvidia
@fmhess
Copy link
Collaborator

fmhess commented Feb 5, 2021

Would you try adding

#define BOOST_PP_VARIADICS 0

at the top of your file before the include? And also try setting it to 1? I ask this because Boost.Preprocessor also has a check for CUDA in it, related to enabling variadic support.

@ghost
Copy link
Author

ghost commented Feb 9, 2021

@fmhess Neither variation of your suggestion worked. Any other work around suggestions?

image
image

@fmhess
Copy link
Collaborator

fmhess commented Feb 9, 2021 via email

@ghost
Copy link
Author

ghost commented Feb 9, 2021

@fmhess I below is a link to the NVCC compiler.
NVCC Download

You can install the visual studio plugin to make the set up easier.

Would it be possible to get boost to start compiling against NVCC? Heterogeneous computing (i.e. GPGPU) is growing in popularity in various fields where C++ is the dominate language. Also hiding dependencies can be a very laborious process for zero gain.

Thanks for your help!
Drew

@fmhess
Copy link
Collaborator

fmhess commented Feb 9, 2021 via email

@eldiener
Copy link
Contributor

Boost preprocessor now assumes variadic macro support so BOOST_PP_VARIADICS is always set to 1.

@ghost
Copy link
Author

ghost commented Feb 10, 2021

@eldiener is this a recent change?

@fmhess
Copy link
Collaborator

fmhess commented Feb 11, 2021

I installed the latest nvcc 11.2, visual studio community 2019, and boost-1.75 and I couldn't reproduce your problem:

PS C:\Users\fhess\source\repos\CudaRuntime1\CudaRuntime1> nvcc -I C:\Users\fhess\Downloads\boost_1_75_0\boost_1_75_0\ -c .\Source.cpp
Source.cpp
PS C:\Users\fhess\source\repos\CudaRuntime1\CudaRuntime1> ls


    Directory: C:\Users\fhess\source\repos\CudaRuntime1\CudaRuntime1


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        2/11/2021   2:44 AM                x64
-a----        2/11/2021   3:18 AM           4721 CudaRuntime1.vcxproj
-a----        2/11/2021   2:40 AM            168 CudaRuntime1.vcxproj.user
------        2/11/2021   2:40 AM           3819 kernel.cu
-a----        2/11/2021   3:22 AM            131 Source.cpp
-a----        2/11/2021   3:23 AM           2140 Source.obj


PS C:\Users\fhess\source\repos\CudaRuntime1\CudaRuntime1> nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Thu_Jan_28_19:41:49_Pacific_Standard_Time_2021
Cuda compilation tools, release 11.2, V11.2.142
Build cuda_11.2.r11.2/compiler.29558016_0

Can you try nvcc 11.2 and boost-1.75 and see if your problem still exists?

@ghost
Copy link
Author

ghost commented Feb 11, 2021

Unfortunately we are no closer to finding the issue. I ran the compiler on the file from command line. The result was the same. I have added to cl.exe verison, CUDA verison, and compiler output for you.

PS C:\Users\Drew Hubley\source\repos\BoostPreprocessorHeader\BoostPreprocessorHeader> nvcc -I "C:\Users\Drew Hubley\Downloads\boost_1_75_0\boost_1_75_0" -c func.cu
func.cu
C:/Users/Drew Hubley/Downloads/boost_1_75_0/boost_1_75_0\boost/preprocessor/slot/detail/shared.hpp(27): fatal error C1012: unmatched parenthesis: missing ')'
PS C:\Users\Drew Hubley\source\repos\BoostPreprocessorHeader\BoostPreprocessorHeader> nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Mon_Nov_30_19:15:10_Pacific_Standard_Time_2020
Cuda compilation tools, release 11.2, V11.2.67
Build cuda_11.2.r11.2/compiler.29373293_0
PS C:\Users\Drew Hubley\source\repos\BoostPreprocessorHeader\BoostPreprocessorHeader> cl.exe --version
Microsoft (R) C/C++ Optimizing Compiler Version 19.27.29111 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

cl : Command line warning D9002 : ignoring unknown option '--version'
cl : Command line error D8003 : missing source filename
PS C:\Users\Drew Hubley\source\repos\BoostPreprocessorHeader\BoostPreprocessorHeader> cl.exe
Microsoft (R) C/C++ Optimizing Compiler Version 19.27.29111 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.
PS C:\Users\Drew Hubley\source\repos\BoostPreprocessorHeader\BoostPreprocessorHeader>

@fmhess
Copy link
Collaborator

fmhess commented Feb 11, 2021 via email

@ghost
Copy link
Author

ghost commented Feb 11, 2021

The CUDA compiler will default to the MSVC compiler when asked to compile a cpp file. I think the opening message with the quote from Nvidia might be a clue to what is happening. Is there anything NVCC specific in the macros?

@eldiener
Copy link
Contributor

There is no macro called BOOST_PP_TUPLE_ELEM_0_1 or BOOST_PP_TUPLE_ELEM_O_1 in the preprocessor library.

@fmhess
Copy link
Collaborator

fmhess commented Feb 11, 2021 via email

@eldiener
Copy link
Contributor

Which version of nvcc and what is the nvcc command line ?

@fmhess
Copy link
Collaborator

fmhess commented Feb 11, 2021

nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Thu_Jan_28_19:41:49_Pacific_Standard_Time_2021
Cuda compilation tools, release 11.2, V11.2.142
Build cuda_11.2.r11.2/compiler.29558016_0
nvcc -I C:\Users\fhess\Downloads\boost_1_75_0\boost_1_75_0 -E .\File.cu > myout.cpp
File.cu
C:/Users/fhess/Downloads/boost_1_75_0/boost_1_75_0\boost/preprocessor/slot/detail/shared.hpp(40): fatal error C1012: unmatched parenthesis: missing ')'

And here is an unmangled and corrected version of the contents of the File.cu test program

#include <boost/preprocessor/iterate.hpp>

#  define BOOST_PP_ITERATION_PARAMS_1 (3,(0,10,<boost/function/detail/function_iterate.hpp>))
#  include BOOST_PP_ITERATE()
#  undef BOOST_PP_ITERATION_PARAMS_1

@eldiener
Copy link
Contributor

The example runs fine with all compilers I have tested. Unfortunately there is no toolset for nvcc in bjam. This suggests some sort of bug in nvcc, most likely in its preprocessor. Maybe nvcc is emulating VC++ and VC++ has numerous workarounds to make its default non-standard preprocessor work with the preprocessor library. I could change the preprocessor configuration file for nvcc so that it acts like VC++. But what you are telling me is that nvcc when compiling a .cpp file works fine but when compiling a .cu it does not work fine, so this suggests something else. Maybe nvcc only emulates VC++ when compiling a .cu file, otherwise it invokes its own compiler.

@fmhess
Copy link
Collaborator

fmhess commented Feb 12, 2021

nvcc only defines __CUDACC__ when compiling .cu files (see https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html ). There are various places in Boost.Config and one place in Boost.Preprocessor where it checks for __CUDACC__. Also this bit from include/boost/config/compiler/nvcc.hpp might be relevant:

//
// When compiing .cu files, there's a bunch of stuff that doesn't work with msvc:
//
#if defined(_MSC_VER)
#  define BOOST_NO_CXX14_DIGIT_SEPARATORS
#  define BOOST_NO_CXX11_UNICODE_LITERALS
#endif

@ghost
Copy link
Author

ghost commented Feb 12, 2021 via email

@ghost
Copy link
Author

ghost commented Feb 12, 2021 via email

@fmhess
Copy link
Collaborator

fmhess commented Feb 12, 2021

If I add a #define __CUDACC__ before the boost include I can induce the problem to happen even when the file has a ".cpp" extension. Alternatively, if I do a #undef __CUDACC__ before the boost include I can make the problem go away even when using a ".cu" extension. So the problem is triggered by the boost headers changing behavior based on a check for the __CUDACC__ define.

@fmhess
Copy link
Collaborator

fmhess commented Feb 12, 2021

If I delete the check for (defined __NVCC__ && defined __CUDACC__) in boost/preprocessor/config/config.hpp the problem goes away.

@eldiener
Copy link
Contributor

That test was actually saying that if the VC++ default preprocessor is being used but nvcc is compiling cuda, don't use any of the many workarounds needed to deal with VC++ default's preprocessor and variadic macros. So what you are saying is that when nvcc is compiling in cuda mode, the preprocessor needs to treat it as VC++'s default preprocessor as far as dealing with variadic macro support is concerned. I am good with that change and will make it.

@eldiener
Copy link
Contributor

I have made the change on the preprocessor 'develop' branch.

@ghost
Copy link
Author

ghost commented Feb 12, 2021

Successfully accomplished a build of my entire project after applying the specified fix.

This issue was closed.
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

2 participants