checkGPU.cpp:
#include<iostream>
#include "cuda_runtime_api.h"
#include "device_launch_parameters.h"
#include <stdio.h>
int main()
{
cudaDeviceProp prop;
int count;
cudaGetDeviceCount(&count);
// cudaGetDeviceCount(&count);//获取设备数
for(int i=0;i<count;i++)
{
cudaGetDeviceProperties(&prop,i);//将第i个GPU数据放到prop中
std::cout<<"显卡名称:"<<prop.name<<std::endl;
std::cout<<"显存大小:"<<prop.totalGlobalMem/1024/1024<<" MB"<<std::endl;
std::cout<<"一个block的共享内存大小:"<<prop.sharedMemPerBlock/1024<<" KB"<<std::endl;
std::cout<<"block最大线程数:"<<prop.maxThreadsPerBlock<<std::endl;
}
system("pause");
return 0;
}
makefile:
.PHONY: clean, all
CC=gcc
CXX=g++
CFLAGS=-Wall -g -O3
INCLUDE=-I./ \
-I/usr/local/cuda-9.0/include
LIBS =-L/usr/lib -lcuda
OBJS= checkGPU.o
all:
make checkGPU
checkGPU: checkGPU.o
$(CXX) -std=c++11 checkGPU.o -o checkGPU $(LIBS) $(OBJS)
.cpp.o:
$(CXX) -std=c++11 $(INCLUDE) -fPIC -c $< -o $@
clean:
-rm *.o
-rm checkGPU
наконец, сделайте это, ошибка:
Undefined reference to ‘cudaGetDeviceCount’ Undefined reference to ‘cudaGetDeviceProperties’