简体   繁体   English

共享内存上的原子操作

[英]atomic operations on shared memory

how can i do an atomic operation on a shared memory? 如何在共享内存上执行原子操作?
i have something similar to this: 我有类似的东西:

__shared__ int a[10];
//set a
if(tid<5)
  a[2]++;

therefore 5 threads are incrementing a. 因此5个线程正在递增a。 how can i do this? 我怎样才能做到这一点?
i know that in this way i am serializing the execution of 5 threads, but how does this effect the warp? 我知道我以这种方式将5个线程的执行序列化,但是这对翘曲有何影响? would all the threads in the warp be serialized or just the first 5? 是将经线中的所有线程序列化还是仅将前5个线程序列化?

Replace a[2]++ with 用[2] ++替换

atomicAdd( a + 2, 1 );

if you can make a unsigned, you might prefer to use atomicInc() instead, but either one is going to kill performance. 如果您可以创建一个无符号的,则您可能更喜欢使用atomicInc(),但是任何一个都会降低性能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM