在CUDA编程中,也定义了错误类型 cudaError_t ,这个错误值一般是runtime API的返回值。当且仅当这个API返回值为cudaSuccess时,才说明这个API调用正确,使用范例如下
cudaError_t cuda_ret;
cuda_ret = cudaMalloc((void**)&d_input, num_elements * sizeof(unsigned int));
if(cuda_ret != cudaSuccess) FATAL("Unable to allocate device memory");
cuda_ret = cudaDeviceSynchronize();
if(cuda_ret != cudaSuccess) FATAL("Unable to synchronize data");