18 #ifndef viskores_cont_cuda_ChooseCudaDevice_h
19 #define viskores_cont_cuda_ChooseCudaDevice_h
47 compute_info(cudaDeviceProp prop,
int index)
50 this->
Major = prop.major;
54 prop.multiProcessorCount * prop.maxThreadsPerMultiProcessor * (prop.clockRate / 100000.0);
57 if (this->
Major >= 9999)
65 bool operator<(
const compute_info other)
const
69 if ((this->
Major >= 3 && other.Major >= 3) || (this->Major == other.Major))
71 return betterPerformance(other);
74 return this->
Major > other.Major;
77 bool betterPerformance(
const compute_info other)
const
85 return this->
Index < other.Index;
92 int GetIndex()
const {
return Index; }
104 static int FindFastestDeviceId()
106 auto cudaDeviceConfig =
dynamic_cast<
107 viskores::cont::internal::RuntimeDeviceConfiguration<viskores::cont::DeviceAdapterTagCuda>&
>(
111 cudaDeviceConfig.GetMaxDevices(numDevices);
114 std::multiset<compute_info> devices;
115 std::vector<cudaDeviceProp> cudaProp;
116 cudaDeviceConfig.GetCudaDeviceProp(cudaProp);
117 for (
int i = 0; i < numDevices; ++i)
119 if (cudaProp[i].computeMode != cudaComputeModeProhibited)
121 devices.emplace(cudaProp[i], i);
125 return devices.size() > 0 ? devices.begin()->GetIndex() : 0;
129 static void SetFastestDeviceId()
131 auto deviceId = FindFastestDeviceId();
134 .SetDeviceInstance(deviceId);