cudnn_frontend_find_plan.h
cudnn_frontend_EngineConfigGenerator.h
iomanip
set
valarray
iomanip
functional
cudnn_frontend_VariantPack.h
limits
iterator
cudnn_frontend_Engine.h
cstdint
cudnn_frontend_EngineConfig.h
cudnn_frontend_MatMulDesc.h
cudnn_frontend_Heuristics.h
cudnn.h
cmath
cassert
cudnn_frontend_PointWiseDesc.h
stdexcept
numeric
string
map
cudnn_frontend_Errata.h
cudnn_frontend_Logging.h
cudnn_frontend_Tensor.h
cudnn_frontend_EngineConfigGenerator.h
exception
fstream
cudnn_frontend_Filters.h
ostream
cudnn_frontend_ExecutionPlanCache.h
cudnn_frontend_Operation.h
cudnn_frontend_Reorder_Tensor.h
ios
cstdio
cudnn_frontend_ExecutionPlan.h
contrib/nlohmann/json/json.hpp
tuple
vector
cudnn_frontend_ConvDesc.h
cudnn_frontend_OperationGraph.h
cudnn_backend.h
utility
array
sstream
cudnn_frontend.h
cudnn_frontend_find_plan.h
cudnn_frontend_ReductionDesc.h
iosfwd
cstdlib
clocale
cctype
iostream
cstddef
unordered_map
mutex
type_traits
set
forward_list
algorithm
cstring
cudnn_frontend_utils.h
memory
istream
initializer_list
cudnn_frontend_EngineFallbackList.h
cudnn_backend_base.h
cudnn_frontend

    /*
    *Copyright(c)2021,NVIDIACORPORATION.Allrightsreserved.
    *
    *Permissionisherebygranted,freeofcharge,toanypersonobtaininga
    *copyofthissoftwareandassociateddocumentationfiles(the"Software"),
    *todealintheSoftwarewithoutrestriction,includingwithoutlimitation
    *therightstouse,copy,modify,merge,publish,distribute,sublicense,
    *and/orsellcopiesoftheSoftware,andtopermitpersonstowhomthe
    *Softwareisfurnishedtodoso,subjecttothefollowingconditions:
    *
    *Theabovecopyrightnoticeandthispermissionnoticeshallbeincludedin
    *allcopiesorsubstantialportionsoftheSoftware.
    *
    *THESOFTWAREISPROVIDED"ASIS",WITHOUTWARRANTYOFANYKIND,EXPRESSOR
    *IMPLIED,INCLUDINGBUTNOTLIMITEDTOTHEWARRANTIESOFMERCHANTABILITY,
    *FITNESSFORAPARTICULARPURPOSEANDNONINFRINGEMENT.INNOEVENTSHALL
    *THEAUTHORSORCOPYRIGHTHOLDERSBELIABLEFORANYCLAIM,DAMAGESOROTHER
    *LIABILITY,WHETHERINANACTIONOFCONTRACT,TORTOROTHERWISE,ARISING
    *FROM,OUTOFORINCONNECTIONWITHTHESOFTWAREORTHEUSEOROTHER
    *DEALINGSINTHESOFTWARE.
    */

    #pragmaonce

    #include<cudnn_frontend_EngineConfigGenerator.h>
    #include<iomanip>
    #include<set>

    namespacecudnn_frontend{

    template<CudnnFindSamplingTechniquesamplingTechnique>
    auto
    time_sorted_plan(cudnnHandle_thandle,executionPlans_tplans,VariantPackconst&variantPack)->executionPlans_t{
    executionPlans_ttime_sorted_plans;

    autoplan_cmp=[](constExecutionPlan&a,constExecutionPlan&b){returna.getExecutionTime()<b.getExecutionTime();};
    std::set<std::reference_wrapper<ExecutionPlan>,decltype(plan_cmp)>timed_execution_plans(plan_cmp);

    constintmaxIterCount=
    (samplingTechnique==CudnnFindSamplingTechnique::CUDNN_FIND_SAMPLE_ONCE)
    ?1
    :(samplingTechnique==CudnnFindSamplingTechnique::CUDNN_FIND_SAMPLE_MEDIAN_OF_THREE)?3:100;
    constfloatthreshhold=0.95f;

    cudaEvent_tstart,stop;
    cudaEventCreate(&start);
    cudaEventCreate(&stop);
    cudaDeviceSynchronize();

    for(auto&plan:plans){
    floattime_ms=0.0f;
    floatfinal_time_ms=0.0f;
    floatmin_time_ms=std::numeric_limits<float>::max();

    //Warm-uprun
    autowarmup_status=::cudnnBackendExecute(handle,plan.get_raw_desc(),variantPack.get_raw_desc());
    if(warmup_status!=CUDNN_STATUS_SUCCESS){
    getLogger()<<"[cudnn_frontend]Plan"<<plan.getTag()<<"failedwith"<<to_string(warmup_status)<<std::endl;
    continue;
    }
    cudaDeviceSynchronize();

    for(inti=0;i<maxIterCount;i++){
    cudaEventRecord(start);

    ::cudnnBackendExecute(handle,plan.get_raw_desc(),variantPack.get_raw_desc());

    cudaEventRecord(stop);
    cudaEventSynchronize(stop);
    cudaEventElapsedTime(&time_ms,start,stop);

    if(samplingTechnique==CudnnFindSamplingTechnique::CUDNN_FIND_SAMPLE_TILL_STABLE){
    final_time_ms=std::min(min_time_ms,time_ms);
    if(time_ms/min_time_ms<threshhold){
    min_time_ms=final_time_ms;
    }else{
    break;
    }
    }else{
    final_time_ms=i==(maxIterCount/2)?time_ms:final_time_ms;
    }
    }
    getLogger()<<"[cudnn_frontend]Plan"<<plan.getTag()<<"took"<<std::setw(10)<<final_time_ms<<std::endl;
    plan.setExecutionTime(final_time_ms);
    timed_execution_plans.insert(plan);
    }

    for(ExecutionPlan&plan:timed_execution_plans){
    time_sorted_plans.emplace_back(std::move(plan));
    }

    cudaEventDestroy(start);
    cudaEventDestroy(stop);

    getLogger()<<"[cudnn_frontend]Auto-tuningreturns"<<time_sorted_plans.size()<<"plans."<<std::endl;

    returntime_sorted_plans;
    }

    template<CudnnFindSamplingTechniquesamplingTechnique>
    auto
    EngineConfigGenerator::cudnnFindPlan(cudnnHandle_thandle,
    cudnn_frontend::OperationGraph&opGraph,
    cudnn_frontend::VariantPackconst&variantPack)->executionPlans_t{
    executionPlans_tplans=cudnnGetPlan(handle,opGraph);
    returntime_sorted_plan<samplingTechnique>(handle,std::move(plans),variantPack);
    }

    template<CudnnFindSamplingTechniquesamplingTechnique>
    auto
    EngineConfigGenerator::cudnnFindPlan(cudnnHandle_thandle,
    cudnn_frontend::OperationGraph&opGraph,
    cudnn_frontend::VariantPackconst&variantPack,
    Predicatepred)->executionPlans_t{
    executionPlans_tplans=cudnnGetPlan(handle,opGraph,pred);
    returntime_sorted_plan<samplingTechnique>(handle,std::move(plans),variantPack);
    }

    template<CudnnFindSamplingTechniquesamplingTechnique>
    auto
    EngineConfigGenerator::cudnnFindPlanAndCache(cudnnHandle_thandle,
    cudnn_frontend::OperationGraph&opGraph,
    cudnn_frontend::VariantPackconst&variantPack,
    cudnn_frontend::ExecutionPlanCache&cache,
    Predicatepred)->cudnn_frontend::ExecutionPlan{
    autosorted_plans=cudnnFindPlan<samplingTechnique>(handle,opGraph,variantPack,pred);
    if(cache.is_fastest_plan_stable(opGraph,sorted_plans.front().getTag())){
    cache.add_plan_to_cache(opGraph,sorted_plans.front());
    }
    returnsorted_plans.front();
    }

    }