13 #include <helper_cuda.h>
19 void DtCheck(T result,
char const *
const func,
const char *
const file,
int const line,
DtDe* theDe)
25 theDe->DT_LOG_WARN <<
"CUDA error at " << file <<
":" << line <<
26 "code=" <<
static_cast<unsigned int>(result) <<
"(" << _cudaGetErrorEnum(result) <<
27 ") \"" << func <<
"\"" << std::endl;
37 #define DtCheckCudaErrors(val, theDe) DtCheck((val), #val, __FILE__, __LINE__, theDe)
42 int current_device = 0, sm_per_multiproc = 0;
43 int max_perf_device = 0;
44 int device_count = 0, best_SM_arch = 0;
45 int devices_prohibited = 0;
47 uint64_t max_compute_perf = 0;
48 cudaDeviceProp deviceProp;
51 if (device_count == 0)
55 theDe->DT_LOG_WARN <<
"gpuGetMaxGflopsDeviceId() CUDA error:" <<
56 " no devices supporting CUDA. Try updating your NVidia driver to a more recent one that support the CUDA version of this application." << std::endl;
62 while (current_device < device_count)
64 cudaGetDeviceProperties(&deviceProp, current_device);
68 if (deviceProp.computeMode != cudaComputeModeProhibited)
70 if (deviceProp.major > 0 && deviceProp.major < 9999)
72 best_SM_arch =
MAX(best_SM_arch, deviceProp.major);
83 if (devices_prohibited == device_count)
87 theDe->DT_LOG_WARN <<
"gpuGetMaxGflopsDeviceId() CUDA error:" <<
88 " all devices have compute mode prohibited." << std::endl;
96 while (current_device < device_count)
98 cudaGetDeviceProperties(&deviceProp, current_device);
102 if (deviceProp.computeMode != cudaComputeModeProhibited)
104 if (deviceProp.major == 9999 && deviceProp.minor == 9999)
106 sm_per_multiproc = 1;
111 _ConvertSMVer2Cores(deviceProp.major, deviceProp.minor);
114 uint64_t compute_perf = (uint64_t)deviceProp.multiProcessorCount *
115 sm_per_multiproc * deviceProp.clockRate;
117 if (compute_perf > max_compute_perf)
120 if (best_SM_arch > 2)
123 if (deviceProp.major == best_SM_arch)
125 max_compute_perf = compute_perf;
126 max_perf_device = current_device;
131 max_compute_perf = compute_perf;
132 max_perf_device = current_device;
140 return max_perf_device;