AtomicAdd with Visual Studio 2013

Hey All,

I hope this isn’t too redundant, as I have seen multiple posts on this, but after following their advice I still am getting

“atomicAdd” is undefined

I have done some searching and tried to set every where I could find to have the

property manager->CUDA 6.5 properties->Cuda C/C+±>device->code generation \ set to compute_20,sm_20

for:
the folder properties- Debug|64
CUDA 6.5 properties
OpenCV_Debug64 properties

and pretty much any where else in the property manager.

I have also gone in and added the command line in all the following forms:

nvcc -arch = sm_20
-arch = sm_20
and
sm_20

to each of those property sheets as well.

If anyone has any idea why this is operating the way it is I would greatly appreciate the assistance.

system is: thinkpad t420, nvs4200m, cuda 6.5.14, visual studio 2013

I look forward to hearing anything back or pointed in the correct direction.

so when you say atomicAdd is undefined, do you mean an intellisense indication of that (red underline in the IDE window, or hovering your mouse over it, or whatever), or do you mean that when you actually go to compile the code, you get an error message during the compilation process that says atomicAdd is undefined?

Both, the intellisense goes off and when i compile i get

Error 1 error MSB3721: The command ““C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\bin\nvcc.exe” -gencode=arch=compute_11,code="sm_11,compute_11" -gencode=arch=compute_20,code="sm_20,compute_20" -gencode=arch=compute_30,code="sm_30,compute_30" -gencode=arch=compute_35,code="sm_35,compute_35" -gencode=arch=compute_37,code="sm_37,compute_37" -gencode=arch=compute_50,code="sm_50,compute_50" --use-local-env --cl-version 2013 -ccbin “C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\x86_amd64” -I./ -I…/…/common/inc -Ic:\opencv\build\include\opencv2 -Ic:\opencv\build\include\opencv -Ic:\opencv\build\Include -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\include” -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\include" --opencc-options -LIST:source=on -G --keep-dir x64\Debug -maxrregcount=0 --ptxas-options=-v --machine 64 --compile -cudart static nvcc -arch = sm_20 -g -DWIN32 -DWIN32 -DWIN32 -DWIN64 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler “/EHsc /W3 /nologo /Od /Zi /RTC1 /MTd " -o x64\Debug\kernel.cu.obj “C:\Users\t420\Documents\Visual Studio 2013\Projects\CudaTest\CudaTest\kernel.cu”” exited with code 1. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\BuildCustomizations\CUDA 6.5.targets 593 9 CudaTest

2	IntelliSense: identifier "atomicAdd" is undefined	c:\Users\t420\Documents\Visual Studio 2013\Projects\CudaTest\CudaTest\kernel.cu	96	2	CudaTest

I successfully compiled the example simpleAtomicIntrinsics.

So I know its not a capability thing or a driver thing, its some kind of a setting within my project.

Thoughts…?

what sort of datatype are you trying to do an atomicAdd on ?

If you are doing an atomicAdd on float, it is only supported on cc2.x and higher:

http://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#atomicadd

and so your inclusion of this compile arch target:

gencode=arch=compute_11,code=\"sm_11,compute_11\"

would generate that error.

and the first (actual compile) error you are showing is indeterminate. You will need to enable additional verbosity settings on Visual Studio output so you can see the error that is actually being indicated by nvcc. The only thing that error string says is that nvcc failed “with an error of some kind”.

The intellisense thing is a separate issue. (and not a show-stopper)

removed the gencode = arch compute_11 and sm_11, compute_11 and still am getting the following error.

Error 1 error MSB3721: The command ““C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\bin\nvcc.exe” -gencode=arch=compute_20,code="sm_20,compute_20" -gencode=arch=compute_30,code="sm_30,compute_30" -gencode=arch=compute_35,code="sm_35,compute_35" -gencode=arch=compute_37,code="sm_37,compute_37" -gencode=arch=compute_50,code="sm_50,compute_50" --use-local-env --cl-version 2013 -ccbin “C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\x86_amd64” -I./ -I…/…/common/inc -Ic:\opencv\build\include\opencv2 -Ic:\opencv\build\include\opencv -Ic:\opencv\build\Include -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\include” -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\include" --opencc-options -LIST:source=on -G --keep-dir x64\Debug -maxrregcount=0 --ptxas-options=-v --machine 64 --compile -cudart static nvcc -arch = sm_20 -g -DWIN32 -DWIN32 -DWIN32 -DWIN64 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler “/EHsc /W3 /nologo /Od /Zi /RTC1 /MTd " -o x64\Debug\kernel.cu.obj “C:\Users\t420\Documents\Visual Studio 2013\Projects\CudaTest\CudaTest\kernel.cu”” exited with code 1. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\BuildCustomizations\CUDA 6.5.targets 593 9 CudaTest

2 IntelliSense: identifier “atomicAdd” is undefined c:\Users\t420\Documents\Visual Studio 2013\Projects\CudaTest\CudaTest\kernel.cu 98 2 CudaTest

Additionally how would I increase the verbosity of the settings within Visual Studio?

It would appear that the sample project uses:

C:\ProgramData\NVIDIA Corporation\CUDA Samples\v6.5\common\inc

as a include directory

and my project that was created by creating a 6.5 runtime enabled project (from new->project->6.5 cud runtime project) refers to:

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5

i tried to include cuda_helper.h and and helper_functions.h as that is what the sample project uses, I have copied them into the …toolkit\cuda\v6.5 directory, they were able to be found, but it has not resolved my problem.

I have further more started a new project from scratch and tried to get the atomicAdd to work but to no avail, fresh project the same problem exists.

-Could there be something with my install of the SDK? Should I attempt a reinstall? Seems a bit drastic…

Again, thank you so far with your assistance, I hope to hear more suggestions.

Thanks again.

I think it’s likely the error has nothing to do with atomic usage. You didn’t answer my question about what type of atomic you are doing (on what data type?) It might be instructive to paste here the actual line of code where you are using the atomicAdd operation as well.

when I google “visual studio verbosity” this is the 3rd hit I get:

[url]http://blogs.msdn.com/b/msbuild/archive/2005/09/29/475157.aspx[/url]

You should increase the verbosity settings until you see a compile error immediately preceding the ones you have pasted here, which is the actual error text output from the nvcc command itself, rather than the VS executive reporting “Error 1 error MSB3721…” which is simply stating that a tool it ran previously (nvcc) did not return correctly.

So this is the code to answer your first question.

global void global_compute_hist(int *d_hist, const char *d_in,int sizeD_in, int numRows, int numCols)
{
int myId = threadIdx.x + blockDim.x + blockIdx.x;
if (myId >= sizeD_in)
return;
int bin = -1;
bin = d_in[myId]; //get the value from the input data and add to histogram

atomicAdd(&d_in[bin], 1);	

}

Modifying the verbosity and nothing really changes I think. Here is the error code:

Error 1 error MSB3721: The command ““C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\bin\nvcc.exe” -gencode=arch=compute_20,code="sm_20,compute_20" -gencode=arch=compute_30,code="sm_30,compute_30" -gencode=arch=compute_35,code="sm_35,compute_35" -gencode=arch=compute_37,code="sm_37,compute_37" -gencode=arch=compute_50,code="sm_50,compute_50" --use-local-env --cl-version 2013 -ccbin “C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\x86_amd64” -I./ -I…/…/common/inc -I”/ProgramData/NVIDIA Corporation/CUDA Samples/v6.5/common/inc" -Ic:\opencv\build\include\opencv2 -Ic:\opencv\build\include\opencv -Ic:\opencv\build\Include -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\include" --opencc-options -LIST:source=on -G --keep-dir x64\Debug -maxrregcount=0 --ptxas-options=-v --machine 64 --compile -cudart static nvcc -arch = sm_20 -g -DWIN32 -DWIN32 -DWIN32 -DWIN64 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler “/EHsc /W3 /nologo /Od /Zi /RTC1 /MTd " -o x64\Debug\kernel.cu.obj “C:\Users\t420\documents\visual studio 2013\Projects\CudaTest\CudaTest\kernel.cu”” exited with code 1. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\BuildCustomizations\CUDA 6.5.targets 593 9 CudaTest

It looks the same…

Thoughts?

Why would the sample codes compile but my code does not. The property files have been made to match.

Is there something different about the 6.5 toolkit versus what the samples are built with?

I am really stumped here.

atomicAdd() is an overloaded function defined for various data types (see prototypes below), however there is no variant defined to operate on data of type ‘char’. The compiler should generate an error for the source you showed above. You should be able to see it in the build log if you adjust the verbosity level appropriately, as suggested by txbob.

sm_11_atomic_functions.h:static inline device int atomicAdd(int *address, int val)
sm_11_atomic_functions.h:static inline device unsigned int atomicAdd(unsigned int *address, unsigned int val)
sm_12_atomic_functions.h:static inline device unsigned long long int atomicAdd(unsigned long long int *address, unsigned long long int val)
sm_20_atomic_functions.h:static inline device float atomicAdd(float *address, float val)

So I finally got it to compile fine. The intellisense is still bonking. But basically I hadn’t allocated memory for the float to be operated on.

Thanks for the tip on the verbosity it led me in the right direction.