__syncthreads() and atomicAdd are undefined in visual studio 2015

I created a new cuda8.0 solution in vs2015 through the default project template. And then I tried to copy the codes in cdpSimplePrint from the samples project into my new solution. I added the helper_cuda.h header file into my new solution. However, either the itellisense or the compiler both give the error that __syncthreads() and atomicAdd are undefined.

Severity Code Description Project File Line Suppression State
Error (active) identifier “__syncthreads” is undefined CUDAPractical1 d:\ProgrammingAndStudy\CUDAPractical1\CUDAPractical1\kernel.cu 51
Severity Code Description Project File Line Suppression State
Error (active) identifier “atomicAdd” is undefined CUDAPractical1 d:\ProgrammingAndStudy\CUDAPractical1\CUDAPractical1\kernel.cu 68

I have already added these headers into the cu file.

#include <cuda.h>
#include <cuda_runtime.h>
#include <device_launch_parameters.h>
#include <device_functions.h>
#include <cuda_runtime_api.h>

I checked the header file of ____syncthreads() and atomicAdd, then I added some macros in my cu file, but some strange errors occured.

Error:
Severity Code Description Project File Line Suppression State
Error kernel launch from device or global functions requires separate compilation mode CUDAPractical1 D:\ProgrammingAndStudy\CUDAPractical1\kernel.cu 91

#include "cuda_runtime.h"
#include "device_launch_parameters.h"
//for __syncthreads()
#ifndef __CUDACC_RTC__ 
#define __CUDACC_RTC__
#endif // !(__CUDACC_RTC__)
//for atomicAdd
#ifndef __CUDACC__
#define __CUDACC__
#endif // !__CUDACC__

#include <device_functions.h>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <helper_cuda.h>

I think you are making trouble for yourself. Take a look at any of the cuda sample projects, and you will likely see similar clashes with intellisense. For proper code, this intellisense incompatibility with CUDA does not prevent you from writing/compiling/running proper code. So one approach would be just to ignore the intellisense errors.

Defining things like CUDACC_RTC like this is a bad idea.

If you insist on doing it, I would wrap it in an INTELLISENSE ifdef, so that it does not impact normal compilation of your code.

[url]How to get VS 2010 to recognize certain CUDA functions - Stack Overflow

Thank you for your reply. But my problem is not only the intellisense error but also the compiler error.

Show me the output from nvcc that says that __syncthreads() is undefined.

The window you are looking at in VS2015 that has these column headers:

Severity	Code	Description	Project	File	Line	Suppression State

is not output from nvcc. Note that by default, VS2015 puts both Intellisense and actual compile errors (from the host code compiler, i.e. cl.exe) in that window, but this behavior is customizable. Actual nvcc compiler output errors do not show up in that window.

If you are actually compiling a cu file with the host code compiler then your project is set up incorrectly.

If you are compiling the cu file with nvcc, nvcc will not generate that error.

Thank you very much. When I select the build only option in the error output window, the error left is:
Error kernel launch from device or global functions requires separate compilation mode

I will try to figure out it first.

Hi, I am having this same issue, where __syncthreads, atomicInc, and __popc are undefined, and my project will not compile. (Windows 10, visual studio, cuda 8) did you solve this problem? Thanks!

I think you should try to make your error list window to show the “build only” errors first. Because the default setting of visual studio will show both of the intellisense errors and the true errors at the same time,