amrex
amrex copied to clipboard
AMREX build errors with CUDA on Windows and Visual Studio 2019
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
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
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.
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
Maybe @ax3l has some experience with this?
This might help. https://github.com/robertmaynard/amrex_tutorial.
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.
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
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.