| 765 | // cudnnConvolutionFwdAlgoPerf_t, pick the best one to use. |
| 766 | template <typename T> |
| 767 | decltype(std::declval<T>().algo) pick_best_algorithm(const std::vector<T> &perf_results) |
| 768 | { |
| 769 | DLIB_CASSERT(!perf_results.empty()); |
| 770 | CHECK_CUDNN(perf_results[0].status); |
| 771 | if (dnn_prefer_fastest_algorithms()) |
| 772 | return perf_results[0].algo; |
| 773 | |
| 774 | // Otherwise we find the algorithm that has a good status and uses the least amount |
| 775 | // of memory. |
| 776 | size_t best_memory = std::numeric_limits<size_t>::max(); |
| 777 | decltype(std::declval<T>().algo) best_alg; |
| 778 | for (auto&& perf : perf_results) |
| 779 | { |
| 780 | if (perf.status == CUDNN_STATUS_SUCCESS && perf.memory < best_memory) |
| 781 | { |
| 782 | best_memory = perf.memory; |
| 783 | best_alg = perf.algo; |
| 784 | } |
| 785 | } |
| 786 | return best_alg; |
| 787 | } |
| 788 | |
| 789 | // Whether cuDNN failed for lack of memory, which benchmarking the algorithms can run into |
| 790 | // when the rest of the program is using the GPU at the same time. |
no test coverage detected