Advertisement
Guest User

Untitled

a guest
Aug 30th, 2015
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.82 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. __global__ void mykernel (int *a, int *b, int *c)
  5. {
  6.         //printf("Hi, from device.\n");
  7.         *c = *a + *b;
  8. }
  9.  
  10. int main(void)
  11. {
  12.         printf("Hi, from host.\n");
  13.         int a=3,b=6,c;
  14.         int *d_a,*d_b,*d_c;
  15.         cudaMalloc((void **)&d_a,sizeof(int));
  16.         cudaMalloc((void **)&d_b,sizeof(int));
  17.         cudaMalloc((void **)&d_c,sizeof(int));
  18.         printf("Here 1\n");
  19.         cudaMemcpy(d_a,&a,sizeof(int),cudaMemcpyHostToDevice);
  20.     cudaMemcpy(d_b,&b,sizeof(int),cudaMemcpyHostToDevice);
  21.         printf("d_a = %d, a = %d\n",*d_a,a);
  22.         //mykernel<<<1,1>>>(d_a,d_b,d_c);
  23.         cudaMemcpy(&c,d_c,sizeof(int),cudaMemcpyHostToDevice);
  24.  
  25.         printf("Yolo %d %d\n", c, *d_c);
  26.  
  27.         cudaFree(d_a); cudaFree(d_b); cudaFree(d_c);
  28.         return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement