A + B

有的头文件不是很清楚

#include <stdio.h>
#include <string.h>
#include <Windows.h>
#include <cuda_runtime.h>

__global__ void Calc(int a, int b, int *c)
{
    *c = a + b;
}

int main()
{
    int a, b, c;
    int *dev_c;
    scanf("%d%d", &a, &b);
    cudaMalloc(&dev_c, sizeof(int));
    Calc<<<1, 1>>>(a, b, dev_c);
    cudaMemcpy(&c, dev_c, sizeof(int), cudaMemcpyDeviceToHost);
    printf("%d\n", c);
    system("pause");
    return 0;
}

 

posted @ 2020-06-09 19:00  啦啦啦天啦噜  阅读(532)  评论(0编辑  收藏  举报