当前位置:网站首页>CUDA programming based on Visual Studio 2015 (1): basic configuration
CUDA programming based on Visual Studio 2015 (1): basic configuration
2022-08-02 16:32:00 【Zhi Zhao】
一、CUDA简介
CUDA是一种由NVIDIA推出的通用并行计算架构,该架构使GPU能够解决复杂的计算问题.它包含了CUDA指令集架构(ISA)以及GPU内部的并行计算引擎.开发人员可以使用C语言来为CUDA架构编写程序,所编写出的程序可以在支持CUDA的处理器上以超高性能运行.
目前为止,基于 CUDA 的 GPU 销量已达数以百万计,软件开发商、科学家以及研究人员正在各个领域中运用 CUDA,其中包括图像与视频处理、计算生物学和化学、流体力学模拟、CT 图像再现、Seismic analysis and ray tracing, etc.
二、CUDA的下载和安装
下载CUDA应用程序时,It is necessary to determine the corresponding driver version of the computer graphics card in advanceCUDA版本.
1)进入控制面板,找到NVIDIA控制面板,双击进入.
2)点击“帮助”按钮下的“系统信息”,Get the model of the graphics cardGeForce 920M,驱动程序版本为376.51.
3)通过CUDA官网提供的信息,获取CUDAVersion corresponding to the graphics card driver version.
CUDA Toolkit and Corresponding Driver Versions
4)搜索对应的CUDA版本并下载.
5)安装CUDA
Many installation tutorial articles can be found online,Among them, I think a blog post is better,It also mentioned how to configure the deep learning librarycuDNN,If you just do parallel computing, you don't need to install this library.
三、创建CUDA项目
1)点击“文件”,选择“新建”,“项目”,定位到“Visual C++”选项卡.
2)选择“空项目”,Solutions and names can be entered by yourself,如图中所示,The location where the project is saved can be changed by yourself.
3)选择“源文件”,点击鼠标右键,选择“添加”→“新建项”,再选择“CUDA C/C++ File”,就可以创建一个.cu文件.
4)选中“Example_1”,点击鼠标右键,选择“生成依赖项“→“生成自定义”→选择“CUDA”CUDA8.0→确定.
5)选中“Hello_GPU.cu”文件,点击鼠标右键,选择“属性”→“配置属性”→“常规”→“项类型”→“CUDA C/C++”.
6)选中“Example_1”,点击鼠标右键,选择“属性“→“VC++目录”,在“包含目录”中添加:C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\include
在“库目录”中添加:C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib\x64
(x64Indicates that the computer's operating system is 64位,The above two paths are installed by themselvesCUDA的位置有关).
点击“CUDA C/C++”选项,选择“Common”,Set the target machine platform to “64-bit”.
7)选中“Example_1”,点击鼠标右键,选择“属性“→“链接器”→“输入”→“附加依赖项”.
添加自己需要的.lib文件名称,例如:
cublas.lib
cuda.lib
cudart.lib
cufft.lib
.libThe location of the file is shown in the image below.
上面其实就是“库目录”下的文件.
到此,Visual Studio 2015里面所有为CUDAThe options set by programming have been completed,接下来可以利用CUDA编程调用GPUImplement the function of parallel operation.
四、CUDA的C代码
CPU和GPU实现的功能相同,There are differences in the way the program is executed.
#include<stdio.h>
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
void cpu()
{
printf("hello,cpu\n");
}
__global__ void gpu()
{
printf("hello,gpu\n");
}
int main()
{
cpu();
gpu << <1, 1 >> >();
cudaDeviceSynchronize();
}
程序运行结果如图
In order to solve the problem that the console flashes back after the program is running,可以进行下面的设置.
选中“Example_1”,点击鼠标右键,选择“属性“→“链接器”→“系统”→“子系统”,在“子系统里面”选择“控制台”.
All like-minded friends,If you think this blog post is well written or just solved your problem,请动动手指,点个赞 再走.
If you have any questions, please comment below the article,I will answer point by point,Both can solve your problem,There may also be ideas for solutions to others.If you have any questions, you can privately message me!
边栏推荐
猜你喜欢
随机推荐
【交换机端口安全技术 】
Object.defineProperty方法(详解)
Technical Selection of Message Queuing
Template series-union set
MATLAB中dist与pdist、pdist2的区别与联系
ssm整合
Oauth2.0 Supplement
GC垃圾回收ZGC
【TCP 和 UDP 基本原理】
H3C 交换机配置端口组、DHCP、DHCP中继、管理用户
这几年让你大呼惊人的AI应用,都离不开这项技术
test2
mongodb连接本地服务失败的问题
三大特殊类(String Object 包装类)与异常
【软件测试】selenium自动化测试1
Mysql索引优化一
Oauth2.0 security (take WeChat authorized login as an example)
移动端UI自动化相关环境配置
APP版本更新通知流程测试要点
【网络设备远程登陆配置SSH/Telnet 】