当前位置:网站首页>CUDA_ Get the specified device

CUDA_ Get the specified device

2020-11-09 23:48:32 Li Baqian

Request computing power 2.0 equipment ( Fermi architecture ):

struct cudaDeviceProp device_prop;
int chosen_device;

memeset(device_prop, 0, sizeof(cudaDeviceProp));
device_prop.major = 2;
device_prop.minor = 0;

if(cudaChooseDevice(&chosen_device, device_prop) != cudaErrorInvalidValue)
{
	CUDA_CALL(cudaSetDevice(chosen_device));
}

cuda Error handling :

When each function returns an error code , Every function call must be error checked , And write the processing function . This makes error handling cumbersome , And cause highly indented program code :

if (cudaMalloc(..) == cudaSuccess) 
{
	if (cudaEventCreate(&event) == cudaSuccess)
	{
		
	}
}
else
{
	...
}

For repetitive programming , You can use the following macro to call CUDA Application program interface :

#define CUDA_CALL(x) {const cudaError_t a=(x); if (a != cudaSuccess) {printf("\nCUDAError:%s(err_num=%d)\n",cudaGetErrorString(a),a); cudaDeviceReset(); assert(0);}}

版权声明
本文为[Li Baqian]所创,转载请带上原文链接,感谢