code_junkie

CUDA memory troubles

Nov 12th, 2011
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. nvcc text.cu -cubin
  2.  
  3. __global__ void string_search(char** texts, int* lengths, char* symbol, int* matches, int symbolLength)
  4. {
  5. int localMatches = 0;
  6. int blockId = blockIdx.x + blockIdx.y * gridDim.x;
  7. int threadId = threadIdx.x + threadIdx.y * blockDim.x;
  8. int blockThreads = blockDim.x * blockDim.y;
  9.  
  10. __shared__ int localMatchCounts[32];
  11.  
  12. bool breaking = false;
  13. for(int i = 0; i < (lengths[blockId] - (symbolLength - 1)); i += blockThreads)
  14. {
  15. if(texts[blockId][i] == symbol[0])
  16. {
  17. for(int j = 1; j < symbolLength; j++)
  18. {
  19. if(texts[blockId][i + j] != symbol[j])
  20. {
  21. breaking = true;
  22. break;
  23. }
  24. }
  25. if (breaking) continue;
  26. localMatches++;
  27. }
  28. }
  29.  
  30. localMatchCounts[threadId] = localMatches;
  31.  
  32. __syncthreads();
  33.  
  34. if(threadId == 0)
  35. {
  36. int sum = 0;
  37. for(int i = 0; i < 32; i++)
  38. {
  39. sum += localMatchCounts[i];
  40. }
  41. matches[blockId] = sum;
  42. }
  43. }
  44.  
  45. localMatchCounts[threadId] = localMatches;
  46.  
  47. localMatchCounts[threadId] = 5;
Add Comment
Please, Sign In to add comment