title: Atomic operations in CUDA kernels on mapped pinned host memory: to do or not to do?
body: <p>In <a href="http://docs.nvidia.com/cuda/cuda-c-programming-guide/#atomic-functions" rel="nofollow">CUDA programming guide</a> it is stated that atomic operations on mapped pinned host memory <em>"are not atomic from the point of view of the host or other devices."</em> What I get from this sentence is that if the host memory region is accessed only by one GPU, it is fine to do atomic on the mapped pinned host memory (even from within multiple simultaneous kernels).</p>
  
  <p>On the other hand, in the book <a href="http://www.cudahandbook.com/" rel="nofollow">the CUDA Handbook</a> by <em>Nicholas Wilt</em> at page 128 it is stated that:</p>
  
  <blockquote>
    <p>Do not try to use atomics on mapped pinned host memory, either for the host (locked compare-exchange) or the device (<code>atomicAdd()</code>). On the CPU side, the facilities to enforce mutual exclusion for locked operations are not visible to peripherals on the PCI express bus. Conversely, on the GPU side, atomic operations only work on local device memory locations because they are implemented using the GPU's local memory controller.</p>
  </blockquote>
  
  <p>Is is safe to do atomic <strong>from inside a CUDA kernel</strong> on mapped pinned host memory? Can we rely on PCI-e bus to keep the atomicity of atomics' read-modify-write?</p>