Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <iostream>
- const int N = 1024;
- __global__
- void hello(int *b)
- {
- b[threadIdx.x]=24;
- }
- int main()
- {
- int b[N];
- for(int i=0;i<N;i++)
- {
- b[i]=1;
- }
- int *bd;
- const int isize = N*sizeof(int);
- cudaMalloc( (void**)&bd, isize );
- cudaMemcpy( bd, b, isize, cudaMemcpyHostToDevice );
- hello<<<N,N>>>(bd);
- cudaMemcpy( b, bd, isize, cudaMemcpyDeviceToHost );
- cudaFree( bd );
- std::cout<<b[1]<<std::endl;
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment