VS2010下如何配置CUDA4.2
2015-05-09 12:43
274 查看
经过各种努力,终于搞定一个CUDA工程。闲话少说,进入正题。
首先,新建一个win32 console application。记住,要建一个空的工程,不能带预编译头。
然后,添加.cu文件。
下面就是各种繁琐的环境配置了。
第一:右键单击工程的名字,在弹出的快捷菜单中,选择 Build Customizations,然后勾选第一项,如下图
第二:右键单击.cu文件,选择属性,然后General->Item Type->CUDA C/C++,确定
第三:仍然右键单击.cu文件,选择属性,CUDA C/C++->common,进行相应配置,不过貌似默认已经配好了
第四:project->properties->linker设置general和input,具体见下图
测试代码:
#include <stdio.h>
#include <stdlib.h>
#include <cuda_runtime.h>
//初始化CUDA
int count=0;
bool InitCUDA()
{
printf("Start to detecte devices.........\n");//显示检测到的设备数
cudaGetDeviceCount(&count);//检测计算能力大于等于1.0 的设备数
if(count == 0){
fprintf(stderr, "There is no device.\n");
return false;
}
printf("%d device/s detected.\n",count);//显示检测到的设备数
int i;
for(i = 0; i < count; i++){//依次验证检测到的设备是否支持CUDA
cudaDeviceProp prop;
if(cudaGetDeviceProperties(&prop, i) == cudaSuccess) {//获得设备属性并验证是否正确
if(prop.major >= 1)//验证主计算能力,即计算能力的第一位数是否大于1
{
printf("Device %d: %s supportsCUDA %d.%d.\n",i+1,prop.name,prop.major,prop.minor);//显示检测到的设备支持的CUDA 版本
break;
}
}
}
if(i == count) {//没有支持CUDA1.x 的设备
fprintf(stderr, "There is no device supporting CUDA 1.x.\n");
return false;
}
cudaSetDevice(i);//设置设备为主叫线程的当前设备
return true;
}
int main()
{
if(!InitCUDA()) {//初始化失败返回系统int argc, char** argv
return 0;
}
printf("Hello GPU! CUDA has been initialized.\n");
//exit(argc ? EXIT_SUCCESS : EXIT_FAILURE);
return 0;//返回系统
}
运行结果:
首先,新建一个win32 console application。记住,要建一个空的工程,不能带预编译头。
然后,添加.cu文件。
下面就是各种繁琐的环境配置了。
第一:右键单击工程的名字,在弹出的快捷菜单中,选择 Build Customizations,然后勾选第一项,如下图
第二:右键单击.cu文件,选择属性,然后General->Item Type->CUDA C/C++,确定
第三:仍然右键单击.cu文件,选择属性,CUDA C/C++->common,进行相应配置,不过貌似默认已经配好了
第四:project->properties->linker设置general和input,具体见下图
测试代码:
#include <stdio.h>
#include <stdlib.h>
#include <cuda_runtime.h>
//初始化CUDA
int count=0;
bool InitCUDA()
{
printf("Start to detecte devices.........\n");//显示检测到的设备数
cudaGetDeviceCount(&count);//检测计算能力大于等于1.0 的设备数
if(count == 0){
fprintf(stderr, "There is no device.\n");
return false;
}
printf("%d device/s detected.\n",count);//显示检测到的设备数
int i;
for(i = 0; i < count; i++){//依次验证检测到的设备是否支持CUDA
cudaDeviceProp prop;
if(cudaGetDeviceProperties(&prop, i) == cudaSuccess) {//获得设备属性并验证是否正确
if(prop.major >= 1)//验证主计算能力,即计算能力的第一位数是否大于1
{
printf("Device %d: %s supportsCUDA %d.%d.\n",i+1,prop.name,prop.major,prop.minor);//显示检测到的设备支持的CUDA 版本
break;
}
}
}
if(i == count) {//没有支持CUDA1.x 的设备
fprintf(stderr, "There is no device supporting CUDA 1.x.\n");
return false;
}
cudaSetDevice(i);//设置设备为主叫线程的当前设备
return true;
}
int main()
{
if(!InitCUDA()) {//初始化失败返回系统int argc, char** argv
return 0;
}
printf("Hello GPU! CUDA has been initialized.\n");
//exit(argc ? EXIT_SUCCESS : EXIT_FAILURE);
return 0;//返回系统
}
运行结果:
相关文章推荐
- VS2010下如何配置CUDA4.2
- GPU学习日记(一)------VS2010下如何配置CUDA4.2
- VS2010下如何配置CUDA4.2
- ZZ 如何在Ubuntu 12.04上配置CUDA 4.2
- VS2010下如何配置CUDA4.2
- cuda第0课环境配置+建立第一个程序:cuda4.2+VS2010+GeForce8500GT
- 如何在Ubuntu 12.04上配置CUDA 4.2
- 关于VS2010+cuda4.2+opencv2.4.3的配置
- Win7(32位)+VS2010+CUDA4.2配置
- VS2010下如何配置CUDA4.2
- GPU(CUDA)学习日记(四)----------VS2010 + win7 32位 + CUDA 4.2 环境配置以及一些小问题的解决
- GPU(CUDA)学习日记(四)----------VS2010 + win7 32位 + CUDA 4.2 环境配置以及一些小问题的解决
- CUDA之VS2010中配置CUDA5.0
- Qt简介以及如何配置Qt使用VS2010进行开发
- CUDA5.5+vs2010 环境配置
- VS2010 CUDA 5.5 Win7 64位配置以及项目创建配置
- Linux Mint 13/Ubuntu 12.04 配置CUDA 4.2 & OpenCV 2.4.2 方法
- VS2017如何配置OpenGL(与VS2010,2012等配置有所不同)
- VS2010 CUDA 5.5 VA_X Win7 64位配置
- VS2010 CUDA8.0 工程配置