Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- __global__ void mykernel (int *a, int *b, int *c)
- {
- //printf("Hi, from device.\n");
- *c = *a + *b;
- }
- int main(void)
- {
- printf("Hi, from host.\n");
- int a=3,b=6,c;
- int *d_a,*d_b,*d_c;
- cudaMalloc((void **)&d_a,sizeof(int));
- cudaMalloc((void **)&d_b,sizeof(int));
- cudaMalloc((void **)&d_c,sizeof(int));
- printf("Here 1\n");
- cudaMemcpy(d_a,&a,sizeof(int),cudaMemcpyHostToDevice);
- cudaMemcpy(d_b,&b,sizeof(int),cudaMemcpyHostToDevice);
- printf("d_a = %d, a = %d\n",*d_a,a);
- //mykernel<<<1,1>>>(d_a,d_b,d_c);
- cudaMemcpy(&c,d_c,sizeof(int),cudaMemcpyHostToDevice);
- printf("Yolo %d %d\n", c, *d_c);
- cudaFree(d_a); cudaFree(d_b); cudaFree(d_c);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement