MCPcopy Create free account
hub / github.com/davisking/dlib / choose_backward_data_algorithm

Method choose_backward_data_algorithm

dlib/cuda/cudnn_dlibapi.cpp:978–1049  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

976 }
977
978 void tensor_conv::
979 choose_backward_data_algorithm (
980 const tensor& gradient_input,
981 const tensor& data_gradient
982 )
983 {
984 if (backward_data_algo >= 0)
985 return;
986
987 const auto find = [&](bool& benchmarked) {
988 cudnnConvolutionBwdDataAlgo_t backward_data_best_algo;
989#if CUDNN_MAJOR >= 8
990 int num_possible_algorithms = 0;
991 CHECK_CUDNN(cudnnGetConvolutionBackwardFilterAlgorithmMaxCount(context(), &num_possible_algorithms));
992 std::vector<cudnnConvolutionBwdDataAlgoPerf_t> perf_results(num_possible_algorithms);
993 int num_algorithms = 0;
994 cudnnStatus_t status = cudnnFindConvolutionBackwardDataAlgorithm(
995 context(),
996 (const cudnnFilterDescriptor_t)filter_handle,
997 descriptor(gradient_input),
998 (const cudnnConvolutionDescriptor_t)conv_handle,
999 descriptor(data_gradient),
1000 num_possible_algorithms,
1001 &num_algorithms,
1002 perf_results.data());
1003 // Benchmarking needs memory that the GPU may not have to spare at the moment, so
1004 // fall back to the heuristics of cuDNN then.
1005 if (is_out_of_memory(status))
1006 {
1007 benchmarked = false;
1008 status = cudnnGetConvolutionBackwardDataAlgorithm_v7(
1009 context(),
1010 (const cudnnFilterDescriptor_t)filter_handle,
1011 descriptor(gradient_input),
1012 (const cudnnConvolutionDescriptor_t)conv_handle,
1013 descriptor(data_gradient),
1014 num_possible_algorithms,
1015 &num_algorithms,
1016 perf_results.data());
1017 }
1018 CHECK_CUDNN(status);
1019 perf_results.resize(num_algorithms);
1020 backward_data_best_algo = pick_best_algorithm(perf_results);
1021#else
1022 CHECK_CUDNN(cudnnGetConvolutionBackwardDataAlgorithm(
1023 context(),
1024 (const cudnnFilterDescriptor_t)filter_handle,
1025 descriptor(gradient_input),
1026 (const cudnnConvolutionDescriptor_t)conv_handle,
1027 descriptor(data_gradient),
1028 dnn_prefer_fastest_algorithms()?CUDNN_CONVOLUTION_BWD_DATA_PREFER_FASTEST:CUDNN_CONVOLUTION_BWD_DATA_NO_WORKSPACE,
1029 std::numeric_limits<size_t>::max(),
1030 &backward_data_best_algo));
1031#endif
1032 return static_cast<int>(backward_data_best_algo);
1033 };
1034
1035 const auto get_workspace_size = [&](int algo) {

Callers

nothing calls this directly

Calls 9

descriptorFunction · 0.85
is_out_of_memoryFunction · 0.85
pick_best_algorithmFunction · 0.85
choose_algorithmFunction · 0.85
contextFunction · 0.70
maxFunction · 0.50
dataMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected