Advertisement
pai

Function.cu

pai
Mar 9th, 2012
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. // The code that runs on CPU Properly.
  2. void CPU_function(int row,int col,int window_sizes[],int num_window)
  3. {
  4.  
  5. int i;
  6. long int d=0;
  7. int win;
  8. if(col!=0)
  9. {
  10. // Variable window loop
  11. for(win=0;win<num_window;win++)
  12. {
  13. for(i=first_index[win];i<col;i++)
  14. {
  15. d=(key_column[row*MAX_LIMIT+first_index[win]])-(key_column[row*MAX_LIMIT+col]);
  16. if(d<=t_window[win])
  17. {
  18. if(key_column[row*MAX_LIMIT+last_index[win]]!=0)
  19. {
  20. printf("\nScore=%d",score[win]);
  21. first_index[win]++;
  22. last_index[win]=first_index[win]+window_sizes[win]-1;
  23. }
  24. break;
  25. }
  26. else
  27. {
  28. first_index[win]++;
  29. last_index[win]=first_index[win]+window_sizes[win]-1;
  30. }
  31. }
  32.  
  33. }//Variable window loop end
  34.  
  35. }
  36.  
  37. }
  38.  
  39.  
  40. //Thread Organization set
  41.  
  42. dim3 block(num_winow,num_threads);
  43. dim3 grid(1,1)
  44. /*
  45. My Question below
  46.  
  47. Usually num_window will be a small value say 3 and usually less than 30 and the number of threads I need is keep on varies for each num_window.
  48.  
  49. Example: when num_window[0]=3 (window of size= 3), I need 45 threads
  50. when num_window[1]=5 (window of size=4 ) I need 35 threads.
  51.  
  52. How to get such variable number of threads for each num_window values.????
  53.  
  54. */
  55.  
  56. // The corresponding CUDA code for running on GPU that I wrote.
  57.  
  58. __global__ void GPU_Function(int row,int col,long int *d_key_column,int *d_num_window,int *d_first_index,int *d_last_index,int *d_t_window,int *d_score,int *d_window_sizes,int D_MAX_LIMIT,long int * d_update_score,int *d_x,int *d_y)
  59. {
  60. long int i,j,k=0;
  61. long int d=-1;
  62. i=threadIdx.x;
  63. j=threadIdx.y;
  64. k=threadIdx.y+d_window_sizes[i];// For each window_sizes
  65. if(col!=0)
  66. {
  67. if(i<*d_num_window)
  68. {
  69. if(j<D_MAX_LIMIT-d_window_sizes[i]+1)
  70. {
  71. d=( d_key_column[row*D_MAX_LIMIT+k]) - (d_key_column[row*D_MAX_LIMIT+j]);
  72. if(d>=0&& d<=d_t_window[i])
  73. d_update_score[j]=d_score[i];
  74. }
  75. }
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement