| 58 | } |
| 59 | |
| 60 | int FindBestCudaDevice() { |
| 61 | const int num_devices = GetNumCudaDevices(); |
| 62 | THROW_CHECK_GT(num_devices, 0) << "No CUDA devices available"; |
| 63 | std::vector<cudaDeviceProp> all_devices(num_devices); |
| 64 | std::vector<int> indices(num_devices); |
| 65 | for (int id = 0; id < num_devices; ++id) { |
| 66 | indices[id] = id; |
| 67 | cudaGetDeviceProperties(&all_devices[id], id); |
| 68 | } |
| 69 | std::sort(indices.begin(), indices.end(), [&](int a, int b) { |
| 70 | return CompareCudaDevice(all_devices[a], all_devices[b]); |
| 71 | }); |
| 72 | const int selected = indices[0]; |
| 73 | VLOG(2) << "Found " << num_devices << " CUDA device(s), " |
| 74 | << "selected device " << selected << " with name " |
| 75 | << all_devices[selected].name; |
| 76 | return selected; |
| 77 | } |
| 78 | |
| 79 | void SetBestCudaDevice(const int gpu_index) { |
| 80 | const int num_cuda_devices = GetNumCudaDevices(); |
no test coverage detected