# atomicAdd 

**URL:** <https://forums.developer.nvidia.com/t/atomicadd/30691>\
**Category:** CUDA Programming and Performance\
**Created:** [September 7, 2013, 9:49am UTC](https://forums.developer.nvidia.com/t/atomicadd/30691 "2013-09-07T09:49:43Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![a\_goryachih](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@a\_goryachih](https://forums.developer.nvidia.com/u/a_goryachih)\
**Post date:** [September 7, 2013, 9:49am UTC](https://forums.developer.nvidia.com/t/atomicadd/30691/1 "2013-09-07T09:49:43Z")

</div>

I tried to use atomicAdd, but I got message “Error: unsupported operation”.  
Do you have any idea?

---

<div class="post-metadata">

**Author:** ![a\_goryachih](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@a\_goryachih](https://forums.developer.nvidia.com/u/a_goryachih)\
**Post date:** [September 18, 2013, 9:34am UTC](https://forums.developer.nvidia.com/t/atomicadd/30691/2 "2013-09-18T09:34:33Z")

</div>

In VS2009 I set “GPU Architecture” in Project-\>Properties-\>Configuration Properties-\>CUDA Runtime API-\>GPU to “compute\_20,sm\_20” (or higher). But it did’t help.

---

<div class="post-metadata">

**Author:** ![pasoleatis](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@pasoleatis](https://forums.developer.nvidia.com/u/pasoleatis)\
**Post date:** [September 18, 2013, 10:40am UTC](https://forums.developer.nvidia.com/t/atomicadd/30691/3 "2013-09-18T10:40:53Z")

</div>

What is your gpu?

---

<div class="post-metadata">

**Author:** ![a\_goryachih](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@a\_goryachih](https://forums.developer.nvidia.com/u/a_goryachih)\
**Post date:** [September 23, 2013, 11:30am UTC](https://forums.developer.nvidia.com/t/atomicadd/30691/4 "2013-09-23T11:30:40Z")

</div>

Tesla C2050

---

<div class="post-metadata">

**Author:** ![pasoleatis](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@pasoleatis](https://forums.developer.nvidia.com/u/pasoleatis)\
**Post date:** [September 23, 2013, 12:10pm UTC](https://forums.developer.nvidia.com/t/atomicadd/30691/5 "2013-09-23T12:10:20Z")

</div>

The only explanation is that the architecture was not set correctly. In linux we just add the flag -arch=sm\_20, I am not sure how does this translate to Visual Studio.

---

<div class="post-metadata">

**Author:** ![Tiomat](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Tiomat](https://forums.developer.nvidia.com/u/Tiomat)\
**Post date:** [September 23, 2013, 2:03pm UTC](https://forums.developer.nvidia.com/t/atomicadd/30691/6 "2013-09-23T14:03:08Z")

</div>

Assuming you meant VS2008, then you should have three options called ‘GPU Architecture(X)’ where X is 1, 2 or 3 in the options page you mentioned (CUDA Runtime API-\>GPU). The Visual Studio compiler compiles for each of those to allow for multiple versions, so if any one of those three has a value of sm\_1X then you will get that error. If all of your options are sm\_20 or above then something fishy is going on.

If you aren’t sure whether it is doing it right, you can goto the tab ‘CUDA Runtime API-\>Command Line’ and copy/paste the big block of text into here for someone to check.

---

<div class="post-metadata">

**Author:** ![a\_goryachih](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@a\_goryachih](https://forums.developer.nvidia.com/u/a_goryachih)\
**Post date:** [September 24, 2013, 2:19am UTC](https://forums.developer.nvidia.com/t/atomicadd/30691/7 "2013-09-24T02:19:58Z")

</div>

Usually I use only GPU Architecture1 with value “sm\_20”, other have value “0”.  
Command Line:  
echo “C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\bin\nvcc.exe” -gencode=arch=compute\_20,code="sm\_20,compute\_20" --machine 64 -ccbin “c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin” -Xcompiler “/EHsc /W3 /nologo /O2 /Zi /MT " -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\include” -maxrregcount=0 --compile -o “x64\Debug/MyCUDA.vcproj.obj” MyCUDA.vcproj

cd “x64\Debug”  
findstr /L /I “"x64\Debug/MyCUDA.vcproj.obj"” “MyCUDA.device-link.options” \>nul 2\>&1  
IF ERRORLEVEL 1 echo “x64\Debug/MyCUDA.vcproj.obj”\>\> “MyCUDA.device-link.options”  
cd "c:\Projects\MyCUDA\MyCUDA"  
“C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\bin\nvcc.exe” -gencode=arch=compute\_20,code="sm\_20,compute\_20" --machine 64 -ccbin “c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin” -Xcompiler “/EHsc /W3 /nologo /O2 /Zi /MT " -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\include” -maxrregcount=0 --compile -o “x64\Debug/MyCUDA.vcproj.obj” “c:\Projects\MyCUDA\MyCUDA\MyCUDA.vcproj”

---

<div class="post-metadata">

**Author:** ![Tiomat](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Tiomat](https://forums.developer.nvidia.com/u/Tiomat)\
**Post date:** [September 24, 2013, 10:46am UTC](https://forums.developer.nvidia.com/t/atomicadd/30691/8 "2013-09-24T10:46:33Z")

</div>

Well if you are only compiling for one arch and that is \>2.0 that shows that it is not an architecture problem, out of curiosity what are you trying to atomicAdd? If it is not a compile problem maybe there is some quirk or limitation on atomicAdd that you have accidently found?

---

<div class="post-metadata">

**Author:** ![a\_goryachih](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@a\_goryachih](https://forums.developer.nvidia.com/u/a_goryachih)\
**Post date:** [September 25, 2013, 8:31am UTC](https://forums.developer.nvidia.com/t/atomicadd/30691/9 "2013-09-25T08:31:28Z")

</div>

I’m trying to do use atomicAdd for float parameters in **global** function  
float res=10;  
atomicAdd(&res,5);

---

<div class="post-metadata">

**Author:** ![pasoleatis](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@pasoleatis](https://forums.developer.nvidia.com/u/pasoleatis)\
**Post date:** [September 25, 2013, 1:41pm UTC](https://forums.developer.nvidia.com/t/atomicadd/30691/10 "2013-09-25T13:41:59Z")

</div>

Is this example [NVIDIA CUDA SDK Code Samples](http://www.naic.edu/~phil/hardware/nvidia/doc/ReleaseNotes.html#simpleAtomicIntrinsics) from nvidia sdk working ?

---

<div class="post-metadata">

**Author:** ![Tiomat](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Tiomat](https://forums.developer.nvidia.com/u/Tiomat)\
**Post date:** [September 26, 2013, 8:29am UTC](https://forums.developer.nvidia.com/t/atomicadd/30691/11 "2013-09-26T08:29:18Z")

</div>

Are you trying to do an atomic add onto a register? So a quick repo case would be

```auto
__global__ void foo()
{
    float res = 10;
    atomicAdd(&res,5);
}

```

If so I am pretty sure that is invalid, and I don’t even know what that is trying to do. atomics only really make sense when you are playing with memory shared between threads, so global or shared memory. The purpose is to remove the race condition where multiple threads update the same memory location at the same time leaving you with some undetermined output. Since each thread has its own copy of the ‘res’ register they can all uniquely update their own version with no impact. If you are trying to have each thread do the add sequentially then res would need to be declared as **shared** (that was res would end up as 10 + (5 \* numberOfThreads) ).

Tiomat
