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

Method choose_forward_algorithm

dlib/cuda/cudnn_dlibapi.cpp:905–976  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

903 }
904
905 void tensor_conv::
906 choose_forward_algorithm (
907 const tensor& data,
908 const tensor& output
909 )
910 {
911 if (forward_algo >= 0)
912 return;
913
914 const auto find = [&](bool& benchmarked) {
915 cudnnConvolutionFwdAlgo_t forward_best_algo;
916#if CUDNN_MAJOR >= 8
917 int num_possible_algorithms = 0;
918 CHECK_CUDNN(cudnnGetConvolutionForwardAlgorithmMaxCount(context(), &num_possible_algorithms));
919 std::vector<cudnnConvolutionFwdAlgoPerf_t> perf_results(num_possible_algorithms);
920 int num_algorithms = 0;
921 cudnnStatus_t status = cudnnFindConvolutionForwardAlgorithm(
922 context(),
923 descriptor(data),
924 (const cudnnFilterDescriptor_t)filter_handle,
925 (const cudnnConvolutionDescriptor_t)conv_handle,
926 descriptor(output),
927 num_possible_algorithms,
928 &num_algorithms,
929 perf_results.data());
930 // Benchmarking needs memory that the GPU may not have to spare at the moment, so
931 // fall back to the heuristics of cuDNN then.
932 if (is_out_of_memory(status))
933 {
934 benchmarked = false;
935 status = cudnnGetConvolutionForwardAlgorithm_v7(
936 context(),
937 descriptor(data),
938 (const cudnnFilterDescriptor_t)filter_handle,
939 (const cudnnConvolutionDescriptor_t)conv_handle,
940 descriptor(output),
941 num_possible_algorithms,
942 &num_algorithms,
943 perf_results.data());
944 }
945 CHECK_CUDNN(status);
946 perf_results.resize(num_algorithms);
947 forward_best_algo = pick_best_algorithm(perf_results);
948#else
949 CHECK_CUDNN(cudnnGetConvolutionForwardAlgorithm(
950 context(),
951 descriptor(data),
952 (const cudnnFilterDescriptor_t)filter_handle,
953 (const cudnnConvolutionDescriptor_t)conv_handle,
954 descriptor(output),
955 dnn_prefer_fastest_algorithms()?CUDNN_CONVOLUTION_FWD_PREFER_FASTEST:CUDNN_CONVOLUTION_FWD_NO_WORKSPACE,
956 std::numeric_limits<size_t>::max(),
957 &forward_best_algo));
958#endif
959 return static_cast<int>(forward_best_algo);
960 };
961
962 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