10 #ifndef vtk_m_cont_cuda_ChooseCudaDevice_h
11 #define vtk_m_cont_cuda_ChooseCudaDevice_h
39 compute_info(cudaDeviceProp prop,
int index)
42 this->
Major = prop.major;
46 prop.multiProcessorCount * prop.maxThreadsPerMultiProcessor * (prop.clockRate / 100000.0);
49 if (this->
Major >= 9999)
57 bool operator<(
const compute_info other)
const
61 if ((this->
Major >= 3 && other.Major >= 3) || (this->Major == other.Major))
63 return betterPerformance(other);
66 return this->
Major > other.Major;
69 bool betterPerformance(
const compute_info other)
const
77 return this->
Index < other.Index;
84 int GetIndex()
const {
return Index; }
96 static int FindFastestDeviceId()
98 auto cudaDeviceConfig =
dynamic_cast<
99 vtkm::cont::internal::RuntimeDeviceConfiguration<vtkm::cont::DeviceAdapterTagCuda>&
>(
103 cudaDeviceConfig.GetMaxDevices(numDevices);
106 std::multiset<compute_info> devices;
107 std::vector<cudaDeviceProp> cudaProp;
108 cudaDeviceConfig.GetCudaDeviceProp(cudaProp);
109 for (
int i = 0; i < numDevices; ++i)
111 if (cudaProp[i].computeMode != cudaComputeModeProhibited)
113 devices.emplace(cudaProp[i], i);
117 return devices.size() > 0 ? devices.begin()->GetIndex() : 0;
121 static void SetFastestDeviceId()
123 auto deviceId = FindFastestDeviceId();
126 .SetDeviceInstance(deviceId);