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);}}