Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "cuda_runtime.h"
- #include "device_launch_parameters.h"
- #include <stdio.h>
- #include <cstdlib>
- __global__ void sum(int *c, int *a, int *b)
- {
- *c = *a + *b;
- }
- int main()
- {
- int c, a = rand() , b = rand();
- printf("a: %d\n", a);
- printf("b: %d\n", b);
- int *d_a, *d_c, *d_b;
- cudaMalloc((void**)& d_a, sizeof(int));
- cudaMalloc((void**)& d_b, sizeof(int));
- cudaMalloc((void**)& d_c, sizeof(int));
- cudaMemcpy(d_a, &a, sizeof(int), cudaMemcpyHostToDevice);
- cudaMemcpy(d_b, &b, sizeof(int), cudaMemcpyHostToDevice);
- cudaMemcpy(d_c, &c, sizeof(int), cudaMemcpyHostToDevice);
- sum <<<1,1>>> (d_c, d_a, d_b); //не понимаю ошибку // <<<gridSize, blockSize>>>
- cudaMemcpy(&c, d_c, sizeof(int), cudaMemcpyDeviceToHost);
- cudaFree(d_a);
- cudaFree(d_b);
- cudaFree(d_c);
- printf("%d", c);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement