title: atomic operation disrupting all kernels
body: <p>I am running some image processing operations on GPU and I need the histogram of the output. 
  I have written and tested the processing kernels. Also I have tested the histogram kernel for samples of the output pictures separately. They both work fine but when I put all of them in one loop I get nothing. </p>
  
  <p>This is my histogram kernel:</p>
  
  <pre><code>__global__ void histogram(int n, uchar* color, uchar* mask, int* bucket, int ch, int W, int bin)
  {
      unsigned int X = blockIdx.x*blockDim.x+threadIdx.x;
      unsigned int Y = blockIdx.y*blockDim.y+threadIdx.y;
  
      int l = (256%bin==0)?256/bin: 256/bin+1;
      int c;
  
      if (X+Y*W &lt; n &amp;&amp; mask[X+Y*W])
      {
          c = color[(X+Y*W)*3]/bin;
          atomicAdd(&amp;bucket[c], 1);
  
          c = color[(X+Y*W)*3+1]/bin;
          atomicAdd(&amp;bucket[c+l], 1);
  
          c = color[(X+Y*W)*3+2]/bin;
          atomicAdd(&amp;bucket[c+l*2], 1);
      }
  }
  </code></pre>
  
  <p>It is updating histogram vectors for red, green, and blue.('l' is the length of the vectors)
  When I comment out atomicAdds it again produces the output but of course not the histogram.
  Why don't they work together?</p>
  
  <p>Edit:</p>
  
  <p>This is the loop:</p>
  
  <pre><code>    cudaMemcpy(frame_in_gpu,frame_in.data, W*H*3*sizeof(uchar),cudaMemcpyHostToDevice);
      cuda_process(frame_in_gpu, frame_out_gpu, W, H, dimGrid,dimBlock);
      cuda_histogram(W*H, frame_in_gpu, mask_gpu, hist, 3, W, bin, dimg_histogram, dimb_histogram);
  </code></pre>
  
  <p>Then I copy the output to host memory and write it to a video.
  These are c codes that only call their kernels with dimGrid and dimBlock that are given as inputs. Also:</p>
  
  <pre><code>dim3 dimBlock(32,32);
  dim3 dimGrid(W/32,H/32);
  dim3 dimb_Histogram(16,16);
  dim3 dimg_Histogram(W/16,H/16);
  </code></pre>
  
  <p>I changed this for histogram because it worked better with it. Does it matter?</p>
  
  <p>Edit2:
  I am using  -arch=sm_11 option for compilation. I just read it somewhere. Could anyone tell me how I should choose it?</p>