Guest User

Untitled

a guest
Aug 10th, 2012
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. CUDA: atomicAdd takes too much time, serializing threads
  2. __global__ void mykernel(..., unsigned int *gColCnt) {
  3. ...
  4.  
  5. __shared__ unsigned int sColCnt;
  6. __shared__ unsigned int sIndex;
  7.  
  8. if (threadIdx.x == 0) {
  9. sColCnt = 0;
  10. }
  11.  
  12. __syncthreads();
  13.  
  14. unsigned int index = 0;
  15. if (colliding)
  16. index = atomicAdd(&sColCnt, 1); //!!Time Consuming!!
  17.  
  18. __syncthreads();
  19.  
  20. if (threadIdx.x == 0)
  21. sIndex = atomicAdd(gColCnt, sColCnt);
  22.  
  23. __syncthreads();
  24.  
  25. if (sColCnt + sIndex > outputSize) { //output buffer is not enough
  26. //printf("Exceeds outputsize: %d + %d > %dn", sColCnt, sIndex, outputSize);
  27. return;
  28. }
  29.  
  30. if (colliding) {
  31. output[sIndex + index] = make_uint2(startId, toId);
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment