Guest User

Untitled

a guest
Feb 9th, 2012
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <iostream>
  3. const int N = 1024;
  4.  
  5.  
  6. __global__
  7. void hello(int *b)
  8. {
  9. b[threadIdx.x]=24;
  10. }
  11.  
  12. int main()
  13. {
  14.  
  15. int b[N];
  16. for(int i=0;i<N;i++)
  17. {
  18. b[i]=1;
  19. }
  20.  
  21. int *bd;
  22.  
  23. const int isize = N*sizeof(int);
  24.  
  25.  
  26. cudaMalloc( (void**)&bd, isize );
  27.  
  28. cudaMemcpy( bd, b, isize, cudaMemcpyHostToDevice );
  29.  
  30. hello<<<N,N>>>(bd);
  31. cudaMemcpy( b, bd, isize, cudaMemcpyDeviceToHost );
  32. cudaFree( bd );
  33. std::cout<<b[1]<<std::endl;
  34.  
  35. return EXIT_SUCCESS;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment