I'd like a small function to detect whether a given computer has a CUDA-enabled GPU available, such as the following.
#include <stdio.h>
#include <cuda_runtime.h>
int main() {
int deviceCount;
struct cudaDeviceProp properties;
cudaError_t cudaResultCode = cudaGetDeviceCount(&deviceCount);
if (cudaResultCode != cudaSuccess)
deviceCount = 0;
printf("%d GPU CUDA device(s) found\n", deviceCount);
}
On a machine without a GPU plugged in (but with the CUDA libraries installed), this code triggers the driver to log a message to stderr.
$ ./a.out
FATAL: Error inserting nvidia (/lib/modules/2.6.32-504.16.2.el6.x86_64/extra/nvidia.ko): No such device
0 GPU CUDA device(s) found
Is there any way to prevent this message from being printed by the driver? (on machines with no GPU and without closing stderr or other hacks like that)