cudnn_frontend_Heuristics.h
vector
cudnn.h
cudnn_backend.h
cudnn_frontend_OperationGraph.h
cudnn_frontend_EngineConfig.h
cudnn_frontend_utils.h
cudnn_frontend_Filters.h
cudnn_frontend.h
functional
limits
cudnn_frontend_Engine.h
cudnn_frontend_EngineConfig.h
cudnn_frontend_MatMulDesc.h
cudnn_frontend_Heuristics.h
cudnn.h
cudnn_frontend_PointWiseDesc.h
string
cudnn_frontend_Logging.h
cudnn_frontend_Tensor.h
exception
fstream
cudnn_frontend_Filters.h
ostream
cudnn_frontend_Operation.h
vector
cudnn_frontend_ConvDesc.h
cudnn_frontend_OperationGraph.h
cudnn_backend.h
utility
array
sstream
cudnn_frontend_ReductionDesc.h
iostream
algorithm
cstring
cudnn_frontend_utils.h
memory
cudnn_backend_base.h
cudnn_frontend_Heuristics.h
cudnn_frontend_get_plan.h
cudnn_frontend_EngineConfigGenerator.h
cudnn_frontend.h
cudnn_frontend_find_plan.h
cudnn_frontend::EngineHeuristics_v8
cudnn_frontend::EngineHeuristicsBuilder_v8
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<vector>

    #include<cudnn.h>
    #include<cudnn_backend.h>

    #include"cudnn_frontend_OperationGraph.h"
    #include"cudnn_frontend_EngineConfig.h"
    #include"cudnn_frontend_utils.h"
    #include"cudnn_frontend_Filters.h"

    namespacecudnn_frontend{
    classEngineHeuristics_v8:publicBackendDescriptor{
    public:
    friendclassEngineHeuristicsBuilder_v8;
    std::string
    describe()constoverride{
    std::stringstreamss;
    ss<<"CUDNN_BACKEND_ENGINEHEUR_DESCRIPTOR:";
    returnss.str();
    }

    EngineHeuristics_v8(EngineHeuristics_v8&&from)=default;
    EngineHeuristics_v8&
    operator= (EngineHeuristics_v8&&from)=default;

    ~EngineHeuristics_v8()=default;

    auto
    getEngineConfig(int64_tcount=1)->std::vector<ManagedOpaqueDescriptor>&{
    cudnnStatus_tstatus;
    for(autoi=0u;i<count;++i){
    ManagedOpaqueDescriptorengConfig=nullptr;
    engConfig=make_shared_backend_pointer(CUDNN_BACKEND_ENGINECFG_DESCRIPTOR);
    if(engConfig->is_good()==false){
    set_error_and_throw_exception(
    this,
    engConfig->get_status(),
    "CUDNN_BACKEND_ENGINEHEUR_DESCRIPTOR:CUDNN_BACKEND_ENGINECFG_DESCRIPTORcudnnCreateFailed");
    returnm_heuristic_results;
    };
    m_heuristic_results.emplace_back(engConfig);
    }
    std::vector<cudnnBackendDescriptor_t>heuristic_results_;
    for(std::uint32_ti=0;i<m_heuristic_results.size();i++){
    heuristic_results_.emplace_back(m_heuristic_results[i]->get_backend_descriptor());
    }
    int64_tresult=-1;
    status=cudnnBackendGetAttribute(pointer->get_backend_descriptor(),
    CUDNN_ATTR_ENGINEHEUR_RESULTS,
    CUDNN_TYPE_BACKEND_DESCRIPTOR,
    count,
    &result,
    heuristic_results_.data());
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    this,status,"CUDNN_BACKEND_ENGINEHEUR_DESCRIPTOR:GetAttributeCUDNN_ATTR_ENGINEHEUR_RESULTSFailed");
    };
    returnm_heuristic_results;
    }

    auto
    getEngineConfigCount(void)const->int64_t{
    cudnnStatus_tstatus;
    int64_tcount=-1;
    status=cudnnBackendGetAttribute(pointer->get_backend_descriptor(),
    CUDNN_ATTR_ENGINEHEUR_RESULTS,
    CUDNN_TYPE_BACKEND_DESCRIPTOR,
    0,
    &count,
    nullptr);
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    this,
    status,
    "CUDNN_BACKEND_ENGINEHEUR_DESCRIPTOR:GetAttributeCUDNN_ATTR_ENGINEHEUR_RESULTSCountFailed");
    };
    returncount;
    }
    private:
    EngineHeuristics_v8()=default;
    EngineHeuristics_v8(EngineHeuristics_v8const&)=delete;
    EngineHeuristics_v8&
    operator=(EngineHeuristics_v8const&)=delete;

    cudnnBackendHeurMode_tmode=CUDNN_HEUR_MODE_INSTANT;
    ManagedOpaqueDescriptoropGraph=nullptr;
    std::vector<ManagedOpaqueDescriptor>m_heuristic_results;
    std::stringopGraphTag;
    };

    classEngineHeuristicsBuilder_v8{
    public:
    auto
    setOperationGraph(OperationGraph_v8&opGraph_)->EngineHeuristicsBuilder_v8&{
    m_heuristics.opGraph=opGraph_.get_desc();
    m_heuristics.opGraphTag=opGraph_.getTag();
    return*this;
    }
    auto
    setHeurMode(cudnnBackendHeurMode_tmode_)->EngineHeuristicsBuilder_v8&{
    m_heuristics.mode=mode_;
    return*this;
    }
    EngineHeuristics_v8&&
    build(){
    if(m_heuristics.opGraph==nullptr){
    set_error_and_throw_exception(&m_heuristics,
    CUDNN_STATUS_BAD_PARAM,
    "CUDNN_BACKEND_ENGINEHEUR_DESCRIPTOR:CheckandSetthe"
    "CUDNN_ATTR_ENGINEHEUR_OPERATION_GRAPHfieldforheuristic");
    returnstd::move(m_heuristics);
    };

    //Createadescriptor.Memoryallocationhappenshere.
    autostatus=m_heuristics.initialize_managed_backend_pointer(CUDNN_BACKEND_ENGINEHEUR_DESCRIPTOR);
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    &m_heuristics,status,"CUDNN_BACKEND_ENGINEHEUR_DESCRIPTOR:cudnnCreateFailed");
    returnstd::move(m_heuristics);
    };

    status=cudnnBackendSetAttribute(m_heuristics.pointer->get_backend_descriptor(),
    CUDNN_ATTR_ENGINEHEUR_OPERATION_GRAPH,
    CUDNN_TYPE_BACKEND_DESCRIPTOR,
    1,
    &(m_heuristics.opGraph->get_backend_descriptor()));
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    &m_heuristics,
    status,
    "CUDNN_BACKEND_ENGINEHEUR_DESCRIPTOR:SetAttributeCUDNN_ATTR_ENGINEHEUR_OPERATION_GRAPHFailed");
    returnstd::move(m_heuristics);
    };
    status=cudnnBackendSetAttribute(m_heuristics.pointer->get_backend_descriptor(),
    CUDNN_ATTR_ENGINEHEUR_MODE,
    CUDNN_TYPE_HEUR_MODE,
    1,
    &m_heuristics.mode);
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    &m_heuristics,
    status,
    "CUDNN_BACKEND_ENGINEHEUR_DESCRIPTOR:SetAttributeCUDNN_ATTR_ENGINEHEUR_MODEFailed");
    returnstd::move(m_heuristics);
    };

    //Finalizingthedescriptor
    status=cudnnBackendFinalize(m_heuristics.pointer->get_backend_descriptor());
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    &m_heuristics,status,"CUDNN_BACKEND_ENGINEHEUR_DESCRIPTOR:cudnnFinalizefailed");
    returnstd::move(m_heuristics);
    };

    getLogger()<<"[cudnn_frontend]"<<m_heuristics<<std::endl;
    returnstd::move(m_heuristics);
    }

    explicitEngineHeuristicsBuilder_v8()=default;
    ~EngineHeuristicsBuilder_v8()=default;
    EngineHeuristicsBuilder_v8(EngineHeuristicsBuilder_v8&&)=delete;
    EngineHeuristicsBuilder_v8(EngineHeuristicsBuilder_v8const&)=delete;
    EngineHeuristicsBuilder_v8&
    operator=(EngineHeuristicsBuilder_v8const&)=delete;

    private:
    EngineHeuristics_v8m_heuristics;
    };

    template<std::size_tSIZE>
    EngineConfigList
    get_heuristics_list(std::array<cudnnBackendHeurMode_t,SIZE>modes,
    OperationGraph_v8&opGraph,
    std::function<bool(cudnnBackendDescriptor_t)>filter_fn){
    (void)modes;
    EngineConfigListfiltered_configs;

    for(automode:modes){
    autoheuristics=EngineHeuristicsBuilder_v8()
    .setOperationGraph(opGraph)
    .setHeurMode(mode)
    .build();

    auto&engine_config=heuristics.getEngineConfig(heuristics.getEngineConfigCount());
    cudnn_frontend::filter(engine_config,filtered_configs,filter_fn);
    }

    returnfiltered_configs;
    }
    }