Issue with cooperative groups namespace with VS2017

Dear all,

I am having some issues using the cooperative groups namespace in my CUDA application with VS 2017 pro. I can run the reduction example from CUDA samples that also uses cooperative_groups (other GPU architectures have been tested). SO I assume this is a configuration issue. Intellisense detects both as an error, but the reduction example compiles fine. CUDA version =10.
Any help would be appreciated.

The error is reproducible with the following code:

main.cpp


#include “test.cu”

int main()
{

return 0;

}


test.cu


#include <cooperative_groups.h>

using namespace cooperative_groups;


Output:


1>------ Build started: Project: testingcoopgroupsnamespace, Configuration: Debug x64 ------
1>Compiling CUDA source file test.cu…
1>
1>source\repos\testingcoopgroupsnamespace\testingcoopgroupsnamespace>“C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin\nvcc.exe” -gencode=arch=compute_35,code=“sm_35,compute_35” --use-local-env -ccbin “C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64” -x cu -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\include" -G --keep-dir x64\Debug -maxrregcount=0 --machine 64 --compile -cudart static -g -D_MBCS -Xcompiler “/EHsc /W3 /nologo /Od /Fdx64\Debug\vc141.pdb /FS /Zi /RTC1 /MDd " -o x64\Debug\test.cu.obj “\source\repos\testingcoopgroupsnamespace\testingcoopgroupsnamespace\test.cu”
1>source/repos/testingcoopgroupsnamespace/testingcoopgroupsnamespace/test.cu(4): error : name must be a namespace name
1>test.cu
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\BuildCustomizations\CUDA 10.0.targets(712,9): error MSB3721: The command ““C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin\nvcc.exe” -gencode=arch=compute_35,code=“sm_35,compute_35” --use-local-env -ccbin “C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64” -x cu -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\include” -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\include” -G --keep-dir x64\Debug -maxrregcount=0 --machine 64 --compile -cudart static -g -D_MBCS -Xcompiler “/EHsc /W3 /nologo /Od /Fdx64\Debug\vc141.pdb /FS /Zi /RTC1 /MDd " -o x64\Debug\test.cu.obj “source\repos\testingcoopgroupsnamespace\testingcoopgroupsnamespace\test.cu”” exited with code 1.
1>Done building project “testingcoopgroupsnamespace.vcxproj” – FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I had some Intellisense errors in VS 2017 (release 15.4.5) with Cuda Toolkit 9.1, like ‘E00029-expected expression’. I could safely ignore these errors, as my code is working properly. See https://stackoverflow.com/questions/15205458/visual-studio-cu-file-shows-syntax-error-but-compiles-successfully

Thanks for the reply, I understand intellisense has some issues with cuda syntax, but I cannot ignore the errors as the code doesn’t compile. I can live with the red squiggly lines.

What happens when you create a file named program.cu with this:

#include <cooperative_groups.h>

using namespace cooperative_groups;

int main(void)
    {
    return 0;
    }

And compile in a cmd window with:

nvcc program.cu -o program

?

Using nvcc program.cu -o program -ccbin “…” where “…” is the directory containing cl.exe
it creates a program.lib, program.exp and program.exe files?

Yes, it should do it.
And if your environment variables are set correctly, you wouldn’t need to pass -ccbin.

Okay so I guess it is a configuration or setting in VS2017, which is the issue, however I still have no idea how to fix this issue. I went through all the properties and compared against the working CUDA sample “reduction” which uses coordinate groups and they seem to be the same.
Do you have any ideas how to fix this problem is VS?

On an aside, would I just need to add a new variable with the path to the folder containing cl.exe?-Done

Thanks for the help.

I wouldn’t really know what is this specific problem in VS2017 because, for me, it actually fixed some problems when I tried to link cuFFT in a nvcc command line (go figure).

What I could suggest is that you start a new and empty CUDA project. If VS presents you with a template source code, go to the Solutions tree and delete whatever file is in there. Create your own empty source file, add to the solution, put a few lines like these above, and compile. See what happens.

As stated by HannesF99, IntelliSense gets a bit quirky, so I just turn it off and things work fine.

Thanks I’ll give it a go, but ideally I need to know how to get this to work in the C++ project as it will ultimately be used in a C++/CLI project.
Thanks again.