1 Star 1 Fork 0

Jason/Hands-On-GPU-Accelerated-Computer-Vision-with-OpenCV-and-CUDA

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
01_variable_addition_value.cu 772 Bytes
一键复制 编辑 原始数据 按行查看 历史
bhaumik2450 提交于 2018-09-05 23:50 +08:00 . Add files via upload
#include <iostream>
#include <cuda.h>
#include <cuda_runtime.h>
#include <stdio.h>
//Definition of kernel function to add two variables
__global__ void gpuAdd(int d_a, int d_b, int *d_c) {
*d_c = d_a + d_b;
}
//main function
int main(void) {
//Defining host variable to store answer
int h_c;
//Defining device pointer
int *d_c;
//Allocating memory for device pointer
cudaMalloc((void**)&d_c, sizeof(int));
//Kernel call by passing 1 and 4 as inputs and storing answer in d_c
//<< <1,1> >> means 1 block is executed with 1 thread per block
gpuAdd << <1, 1 >> > (1, 4, d_c);
//Copy result from device memory to host memory
cudaMemcpy(&h_c, d_c, sizeof(int), cudaMemcpyDeviceToHost);
printf("1 + 4 = %d\n", h_c);
//Free up memory
cudaFree(d_c);
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/jason921121/Hands-On-GPU-Accelerated-Computer-Vision-with-OpenCV-and-CUDA.git
git@gitee.com:jason921121/Hands-On-GPU-Accelerated-Computer-Vision-with-OpenCV-and-CUDA.git
jason921121
Hands-On-GPU-Accelerated-Computer-Vision-with-OpenCV-and-CUDA
Hands-On-GPU-Accelerated-Computer-Vision-with-OpenCV-and-CUDA
master

搜索帮助