cudnn_frontend_EngineConfig.h
algorithm
array
functional
memory
sstream
utility
cudnn.h
cudnn_backend.h
cudnn_frontend_Engine.h
cudnn_frontend_utils.h
cudnn_frontend_Heuristics.h
cudnn_frontend.h
functional
limits
cudnn_frontend_Engine.h
cudnn_frontend_EngineConfig.h
cudnn_frontend_MatMulDesc.h
cudnn.h
cudnn_frontend_PointWiseDesc.h
string
cudnn_frontend_Logging.h
cudnn_frontend_Tensor.h
exception
fstream
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_EngineConfig.h
cudnn_frontend_Heuristics.h
cudnn_frontend_get_plan.h
cudnn_frontend_EngineConfigGenerator.h
cudnn_frontend.h
cudnn_frontend_find_plan.h
cudnn_frontend::EngineConfig_v8
cudnn_frontend::EngineConfigBuilder_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<algorithm>
    #include<array>
    #include<functional>
    #include<memory>
    #include<sstream>
    #include<utility>

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

    #include"cudnn_frontend_Engine.h"
    #include"cudnn_frontend_utils.h"

    namespacecudnn_frontend{
    classEngineConfig_v8:publicBackendDescriptor{
    public:
    friendclassEngineConfigBuilder_v8;

    std::string
    describe()constoverride{
    std::stringstreamss;
    ss<<"CUDNN_BACKEND_ENGINECFG_DESCRIPTOR:";
    ss<<"Numberofknobs:"<<numKnobs;
    returnss.str();
    }

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

    EngineConfig_v8(EngineConfig_v8&&from)=default;

    ~EngineConfig_v8()=default;

    std::stringconst&
    getTag()const{
    returnopGraphTag;
    }

    private:
    EngineConfig_v8():BackendDescriptor(){
    cudnnStatus_tstatus;
    for(uint64_ti=0;i<bChoices.size();i++){
    bChoices[i]=make_shared_backend_pointer(CUDNN_BACKEND_KNOB_CHOICE_DESCRIPTOR);
    if(bChoices[i]->is_good()==false){
    status=bChoices[i]->get_status();
    set_error_and_throw_exception(
    this,
    status,
    "CUDNN_BACKEND_ENGINECFG_DESCRIPTOR:CUDNN_BACKEND_KNOB_CHOICE_DESCRIPTORcudnnCreateFailed");
    break;
    }
    }
    }
    EngineConfig_v8(EngineConfig_v8const&)=delete;
    EngineConfig_v8&
    operator=(EngineConfig_v8const&)=delete;

    ManagedOpaqueDescriptorengine=nullptr;
    int64_tnumKnobs=0;
    std::stringopGraphTag;
    boolset_knobs_attr=false;
    std::array<ManagedOpaqueDescriptor,CUDNN_KNOB_TYPE_COUNTS>bChoices={};
    };

    classEngineConfigBuilder_v8{
    public:
    auto
    setEngine(Engine_v8const&engine_)->EngineConfigBuilder_v8&{
    m_engine_config.engine=engine_.get_desc();
    m_engine_config.opGraphTag=engine_.getTag();
    auto&knobs=engine_.getFinalizedKnobs();
    m_engine_config.numKnobs=knobs.size();

    m_engine_config.set_knobs_attr=engine_.knobs_set();

    for(std::uint32_ti=0;i<knobs.size();i++){
    cudnnStatus_tstatus;
    cudnnBackendKnobType_ttype=knobs[i].getKnobType();
    int64_tvalue=knobs[i].getChoice();
    status=cudnnBackendSetAttribute(m_engine_config.bChoices[i]->get_backend_descriptor(),
    CUDNN_ATTR_KNOB_CHOICE_KNOB_TYPE,
    CUDNN_TYPE_KNOB_TYPE,
    1,
    &type);
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(&m_engine_config,
    status,
    "CUDNN_BACKEND_ENGINECFG_DESCRIPTOR:"
    "CUDNN_BACKEND_KNOB_CHOICE_DESCRIPTORSetAttribute"
    "CUDNN_ATTR_KNOB_CHOICE_KNOB_TYPEFailed");
    }
    status=cudnnBackendSetAttribute(m_engine_config.bChoices[i]->get_backend_descriptor(),
    CUDNN_ATTR_KNOB_CHOICE_KNOB_VALUE,
    CUDNN_TYPE_INT64,
    1,
    &value);
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(&m_engine_config,
    status,
    "CUDNN_BACKEND_ENGINECFG_DESCRIPTOR:"
    "CUDNN_BACKEND_KNOB_CHOICE_DESCRIPTORSetAttribute"
    "CUDNN_ATTR_KNOB_CHOICE_KNOB_VALUEFailed");
    }
    status=cudnnBackendFinalize(m_engine_config.bChoices[i]->get_backend_descriptor());
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    &m_engine_config,
    status,
    "CUDNN_BACKEND_ENGINECFG_DESCRIPTOR:CUDNN_BACKEND_KNOB_CHOICE_DESCRIPTORcudnnFinalizeFailed");
    }
    }

    return*this;
    }
    EngineConfig_v8&&
    build(){
    if(m_engine_config.status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(&m_engine_config,
    m_engine_config.status,
    "CUDNN_BACKEND_ENGINECFG_DESCRIPTOR:isnotcreatedproperly");
    returnstd::move(m_engine_config);
    }
    if(m_engine_config.engine==nullptr){
    set_error_and_throw_exception(
    &m_engine_config,
    CUDNN_STATUS_BAD_PARAM,
    "CUDNN_BACKEND_ENGINECFG_DESCRIPTOR:CheckandSettheCUDNN_ATTR_ENGINECFG_ENGINE.");
    returnstd::move(m_engine_config);
    }
    //Createadescriptor.Memoryallocationhappenshere.
    autostatus=m_engine_config.initialize_managed_backend_pointer(CUDNN_BACKEND_ENGINECFG_DESCRIPTOR);
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    &m_engine_config,status,"CUDNN_BACKEND_ENGINECFG_DESCRIPTOR:cudnnCreateFailed");
    returnstd::move(m_engine_config);
    }

    status=cudnnBackendSetAttribute(m_engine_config.pointer->get_backend_descriptor(),
    CUDNN_ATTR_ENGINECFG_ENGINE,
    CUDNN_TYPE_BACKEND_DESCRIPTOR,
    1,
    &(m_engine_config.engine->get_backend_descriptor()));
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    &m_engine_config,
    status,
    "CUDNN_BACKEND_ENGINECFG_DESCRIPTOR:SetAttributeCUDNN_ATTR_ENGINECFG_ENGINEFailed");
    returnstd::move(m_engine_config);
    }

    if(m_engine_config.set_knobs_attr&&m_engine_config.numKnobs>0){
    std::array<cudnnBackendDescriptor_t,CUDNN_KNOB_TYPE_COUNTS>bChoices_;
    for(autoi=0;i<m_engine_config.numKnobs;i++){
    bChoices_[i]=m_engine_config.bChoices[i]->get_backend_descriptor();
    }
    status=cudnnBackendSetAttribute(m_engine_config.pointer->get_backend_descriptor(),
    CUDNN_ATTR_ENGINECFG_KNOB_CHOICES,
    CUDNN_TYPE_BACKEND_DESCRIPTOR,
    m_engine_config.numKnobs,
    bChoices_.data());
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    &m_engine_config,
    status,
    "CUDNN_BACKEND_ENGINECFG_DESCRIPTOR:SetAttributeCUDNN_ATTR_ENGINECFG_KNOB_CHOICESFailed");
    returnstd::move(m_engine_config);
    }
    }

    //Finalizingthedescriptor
    status=cudnnBackendFinalize(m_engine_config.pointer->get_backend_descriptor());
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    &m_engine_config,status,"CUDNN_BACKEND_ENGINECFG_DESCRIPTOR:cudnnFinalizeFailed");
    returnstd::move(m_engine_config);
    }
    getLogger()<<"[cudnn_frontend]"<<m_engine_config<<std::endl;
    returnstd::move(m_engine_config);
    }

    explicitEngineConfigBuilder_v8()=default;
    ~EngineConfigBuilder_v8()=default;
    EngineConfigBuilder_v8(EngineConfigBuilder_v8&&)=delete;
    EngineConfigBuilder_v8(EngineConfigBuilder_v8const&)=delete;
    EngineConfigBuilder_v8&
    operator=(EngineConfigBuilder_v8const&)=delete;

    private:
    EngineConfig_v8m_engine_config;
    };

    usingEngineConfigList=std::vector<ManagedOpaqueDescriptor>;
    }