cudnn_frontend_EngineFallbackList.h
cudnn.h
numeric
cudnn_frontend.h
cudnn.h
numeric
cudnn_frontend_EngineFallbackList.h
cudnn_frontend_get_plan.h
cudnn_frontend_EngineConfigGenerator.h
cudnn_frontend.h
cudnn_frontend_find_plan.h
cudnn_frontend_EngineFallbackList.h
cudnn_frontend::EngineFallbackList_v8
cudnn_frontend::EngineFallbackListBuilder_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<cudnn.h>
    #include<numeric>

    namespacecudnn_frontend{

    autostaticget_fallback_engine_list(cudnnBackendDescriptorType_tmode,conststd::string&opGraphTag)->std::vector<int>{
    automajor_version=cudnnGetVersion()/1000;

    autominor_version=(cudnnGetVersion()/100)%10;
    if(major_version>=8){
    if(minor_version<=2){
    if(mode==CUDNN_BACKEND_OPERATION_CONVOLUTION_FORWARD_DESCRIPTOR){
    if(opGraphTag.find("bias")==std::string::npos){
    std::vector<int>engine_list(50);
    std::iota(engine_list.begin(),engine_list.end(),0);
    returnengine_list;
    }else{
    return{11,0};
    }
    }elseif(mode==CUDNN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_DATA_DESCRIPTOR){
    std::vector<int>engine_list(61);
    std::iota(engine_list.begin(),engine_list.end(),0);
    returnengine_list;
    }elseif(mode==CUDNN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_FILTER_DESCRIPTOR){
    return{0,1,20};
    }else{
    return{};
    }
    }else{
    if(mode==CUDNN_BACKEND_OPERATION_CONVOLUTION_FORWARD_DESCRIPTOR){
    if(opGraphTag.find("bias")==std::string::npos){
    return{0,1,28};
    }else{
    return{};
    }
    }elseif(mode==CUDNN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_DATA_DESCRIPTOR){
    return{0,1,25};
    }elseif(mode==CUDNN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_FILTER_DESCRIPTOR){
    return{0,1,20};
    }else{
    return{};
    }
    }
    }else{
    return{};
    }
    }

    classEngineFallbackList_v8:publicBackendDescriptor{
    public:
    friendclassEngineFallbackListBuilder_v8;

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

    auto
    getFallbackList()->std::vector<ManagedOpaqueDescriptor>&{
    returnm_engine_configs;
    }

    ~EngineFallbackList_v8()=default;

    EngineFallbackList_v8(EngineFallbackList_v8&&from)
    :BackendDescriptor(from.get_desc(),from.get_status(),from.get_error()),
    opGraph(from.opGraph),
    mode(from.mode),
    num_ops(from.num_ops),
    opGraphTag(from.opGraphTag){
    m_engine_configs.swap(from.m_engine_configs);
    }

    private:
    EngineFallbackList_v8()=default;
    EngineFallbackList_v8(EngineFallbackList_v8const&)=delete;
    EngineFallbackList_v8&
    operator=(EngineFallbackList_v8const&)=delete;

    ManagedOpaqueDescriptoropGraph=nullptr;
    cudnnBackendDescriptorType_tmode;
    uint64_tnum_ops;
    std::vector<ManagedOpaqueDescriptor>m_engine_configs;
    std::stringopGraphTag;
    };

    classEngineFallbackListBuilder_v8{
    public:
    auto
    setOperationGraph(OperationGraph_v8&opGraph_)->EngineFallbackListBuilder_v8&{
    m_fallback_list.opGraph=opGraph_.get_desc();
    m_fallback_list.opGraphTag=opGraph_.getTag();
    m_fallback_list.num_ops=opGraph_.getOpCount();
    return*this;
    }
    auto
    setOperation(cudnnBackendDescriptorType_tmode)->EngineFallbackListBuilder_v8&{
    m_fallback_list.mode=mode;
    return*this;
    }
    EngineFallbackList_v8&&
    build(){
    if(m_fallback_list.opGraph==nullptr){
    set_error_and_throw_exception(&m_fallback_list,
    CUDNN_STATUS_BAD_PARAM,
    "CUDNN_BACKEND_ENGINEHEUR_DESCRIPTOR:CheckandSetthe"
    "CUDNN_ATTR_ENGINEHEUR_OPERATION_GRAPHfieldforheuristic");
    returnstd::move(m_fallback_list);
    };
    autofallback_engine_list=get_fallback_engine_list(m_fallback_list.mode,m_fallback_list.opGraphTag);
    for(std::uint32_ti=0;i<fallback_engine_list.size();i++){
    #ifndefNV_CUDNN_DISABLE_EXCEPTION
    try{
    #endif
    autoengine=cudnn_frontend::EngineBuilder_v8()
    .setGlobalEngineIdx(fallback_engine_list[i])
    .setOperationGraph(m_fallback_list.opGraph)
    .build();
    autoengine_config=cudnn_frontend::EngineConfigBuilder_v8().setEngine(engine).build();
    m_fallback_list.m_engine_configs.emplace_back(engine_config.get_desc());
    #ifndefNV_CUDNN_DISABLE_EXCEPTION
    }catch(cudnn_frontend::cudnnException&e){
    continue;
    }
    #endif
    }
    getLogger()<<"[cudnn_frontend]"<<m_fallback_list<<std::endl;
    returnstd::move(m_fallback_list);
    }

    explicitEngineFallbackListBuilder_v8()=default;
    ~EngineFallbackListBuilder_v8()=default;
    EngineFallbackListBuilder_v8(EngineFallbackListBuilder_v8&&)=delete;
    EngineFallbackListBuilder_v8(EngineFallbackListBuilder_v8const&)=delete;
    EngineFallbackListBuilder_v8&
    operator=(EngineFallbackListBuilder_v8const&)=delete;

    private:
    EngineFallbackList_v8m_fallback_list;
    };
    }