Guest User

Untitled

a guest
Nov 24th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. float mRandom(){return 666f;}
  6.  
  7. __global__ void checkPoint ( float* X )
  8. {
  9. int idx = blockIdx.x * blockDim.x + threadIdx.x;
  10. X[idx] = mRandom();
  11. }
  12.  
  13. int main(int argc, char * argv [])
  14. {
  15. setlocale(0, "rus");
  16. int N=16*1024*1024, n=0, numBytes=N*sizeof ( POINT );
  17. float *X = new float [N];
  18. for (int i=0; i<N; i++) X[i]=1;
  19. float *cdev = NULL;
  20. cudaMalloc ( (void**)&cdev, numBytes );
  21. dim3 threads = dim3(256, 1);
  22. dim3 blocks = dim3(N / threads.x, 1);
  23. cudaMemcpy ( cdev, X, numBytes, cudaMemcpyHostToDevice );
  24. checkPoint<<<blocks, threads>>>(cdev);
  25. cudaMemcpy ( X, cdev, numBytes, cudaMemcpyDeviceToHost );
  26. for (int i=0; i<300; i++)cout<<X[i]<<endl;
  27. cudaFree(cdev);
  28. delete X;
  29. system("pause");
  30. return 0;
  31. }
Add Comment
Please, Sign In to add comment