1.新建->项目->Visual C++->空项目
2.点击源文件->右键->添加新建项->c++文件
3.将以下代码拷入:
#include <iostream>
// Required to include CUDA vector types
#include <cuda_runtime.h>
extern int cudamain();
int main(){
std::cout << "hello" << std::endl;
int test;
test = cudamain();
std::cin >> test;
return 0;
}
4.点击源文件->右键->添加新建项->NVIDIA CUDA 9.2->cuda c++ file
5.将以下代码拷入:
#include <stdio.h>
#include <iostream>
int cudamain() {
int nDevices;
cudaGetDeviceCount(&nDevices);
for (int i = 0; i < nDevices; i++) {
cudaDeviceProp prop;
cudaGetDeviceProperties(&prop, i);
printf("Device Number: %d\n", i);
printf(" Device name: %s\n", prop.name);
printf(" Memory Clock Rate (KHz): %d\n",
prop.memoryClockRate);
printf(" Memory Bus Width (bits): %d\n",
prop.memoryBusWidth);
printf(" Peak Memory Bandwidth (GB/s): %f\n\n",
2.0*prop.memoryClockRate*(prop.memoryBusWidth / 8) / 1.0e6);
}
int s;
std::cin >> s;
return 0;
}
6.右键工程->生成依赖项->生成自定义->选中cuda9.2->确定
7.右键.cu文件->属性->在线类型中选择为cuda
8.右键工程->属性->链接器->输入->添加cudart_static.lib
9.右键工程生成,运行即可