Advertisement
Guest User

Untitled

a guest
Nov 1st, 2010
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include "cutil.h"
  4.  
  5. __global__ void full_coalesced_read(int *d_array,int size)
  6. {
  7. int x=d_array[blockIdx.x*blockDim.x+threadIdx.x];
  8. }
  9.  
  10. __global__ void partial_coalesced_read(int *d_array,int size)
  11. {
  12. int x=d_array[blockIdx.x*blockDim.x+threadIdx.x+1];
  13. }
  14.  
  15. int main(int argc, char** argv)
  16. {
  17. CUT_DEVICE_INIT(argc,argv);
  18.  
  19. int *d_array;
  20. int size=512;
  21.  
  22. cudaMalloc((void **)&d_array,sizeof(int)*(size*2));
  23.  
  24. unsigned int timer=0,timer1=0;
  25. CUT_SAFE_CALL( cutCreateTimer( &timer));
  26. CUT_SAFE_CALL( cutCreateTimer( &timer1));
  27.  
  28. float avg_timer=0,avg_timer1=0;
  29. for(int i=0;i<100;i++ )
  30. {
  31. CUT_SAFE_CALL( cutStartTimer( timer));
  32. full_coalesced_read<<<size/512,512>>>(d_array,size);
  33. cudaThreadSynchronize();
  34. CUT_SAFE_CALL( cutStopTimer( timer));
  35. avg_timer += cutGetTimerValue( timer);
  36. }
  37. for(int i=0;i<100;i++ )
  38. {
  39. CUT_SAFE_CALL( cutStartTimer( timer1));
  40. partial_coalesced_read<<<size/512,512>>>(d_array,size);
  41. cudaThreadSynchronize();
  42. CUT_SAFE_CALL( cutStopTimer( timer1));
  43. avg_timer1 += cutGetTimerValue( timer1);
  44. }
  45.  
  46. printf( "Time with coalesced reads : %f (ms)\n", avg_timer / 100);
  47. printf( "Time with uncoalesced reads : %f (ms)\n", avg_timer1 / 100);
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement