amrex icon indicating copy to clipboard operation
amrex copied to clipboard

AMREX build errors with CUDA on Windows and Visual Studio 2019

Open ramsampath opened this issue 3 years ago • 8 comments

Hello,

I get the following error when enabling GPU as CUDA on amrex and when building the basic HelloWorld application

"AMReX.H:99: error: C2061: syntax error: identifier 'device'"

amrex itself however builds fine. Is there any compiler flag which has to be passed fo resolve this ?

Thank you in advance

ramsampath avatar Feb 04 '22 23:02 ramsampath

Hi,

Can you say a little more about how you are compiling the code? Based on the error message my initial guess is that the compiler you're using is not configured to compile CUDA code. If you haven't already, maybe you could troubleshoot this by trying to compile a CUDA HelloWorld code and see if that works.

Personally, I don't have experience with Visual Studio so perhaps others will have better suggestions.

Erik

etpalmer63 avatar Feb 05 '22 05:02 etpalmer63

Hello Erik,

Thank you for your response. I am using cmake and I guess there's perhaps some issue with visual studio preprocessor compiler not understanding macros xxx . This could be the issue and not sure how to resolve this and so I thought I would ask someone in this group to see if they had an experience with compiling with Visual Studio if there are any additional compiler flags to be passed.

The lines like this are causing the error which is enabled when CUDA is enabled. Otherwise its evaluated to null.

#define AMREX_GPU_HOST_DEVICE host device

Thank you again. Ram.

ramsampath avatar Feb 07 '22 05:02 ramsampath

Hi Ram,

Based off the error message, I think the preprocessor is handling the macro appropriately and replacing AMREX_GPU_HOST_DEVICE with the appropriate Cuda code. However, the error could arise after the macro is replaced, when you try to compile CUDA code, i.e. syntax like host device, with a C++ compiler.

What result did you get with the CUDA helloworld code? I was thinking something just like the example here: https://cuda-tutorial.readthedocs.io/en/latest/tutorials/tutorial01/

Since you're using CMake, I can make a best guess for compiler flags in your case:

cmake .. -DCMAKE_BUILD_TYPE=Release -DAMReX_FORTRAN=OFF -DAMReX_MPI=OFF -DAMReX_GPU_BACKEND=CUDA -DCMAKE_CXX_STANDARD=17 -DCMAKE_CUDA_STANDARD=17

Hope this helps,

Erik

etpalmer63 avatar Feb 07 '22 14:02 etpalmer63

Maybe @ax3l has some experience with this?

drummerdoc avatar Feb 07 '22 14:02 drummerdoc

This might help. https://github.com/robertmaynard/amrex_tutorial.

WeiqunZhang avatar Feb 07 '22 16:02 WeiqunZhang

Thank you for your responses. I think the problem is what erik said , for some reason perhaps instead of calling nvcc to compile the sources its using the regular visual C++ compiler. When building amrex it seems to be calling nvcc to build but when building the examples it seems to be calling the regular C++ compiler and the errors appear. This seems to happen also in the Ubuntu builds of examples.

I tried cmake .. -DCMAKE_BUILD_TYPE=Release -DAMReX_FORTRAN=OFF -DAMReX_MPI=OFF -DAMReX_GPU_BACKEND=CUDA -DCMAKE_CXX_STANDARD=17 -DCMAKE_CUDA_STANDARD=17

and still seems to have the same issue. I will keep digging into it.

Thanks Ram.

ramsampath avatar Feb 08 '22 18:02 ramsampath

Hi Ram,

Which HelloWorld example are you trying to compile? Can you post the CMakeLists.txt file associated with the project?

In the past, I found CMake would decide that all .cpp files had to be compiled with the C++ compiler. In CMakeLists.txt I had to tell it specifically to treat these files as Cuda language. You can see this in the very end of the file, amrex/Tests/SpackSmokeTest/CMakeLists.txt.

Erik

etpalmer63 avatar Feb 08 '22 19:02 etpalmer63

Thank you Erik . I will try that. Regarding the CMakeLists.txt - i am just using the one from amrex-tutorials. I will look at the CMakeLists.txt file you pointed me towards. Thank you.

ramsampath avatar Feb 08 '22 20:02 ramsampath