cudnn_frontend_OperationGraph.h
algorithm
array
functional
memory
sstream
utility
vector
cudnn.h
cudnn_backend.h
cudnn_frontend_Operation.h
cudnn_frontend_utils.h
cudnn_frontend_Heuristics.h
cudnn_frontend_Engine.h
cudnn_frontend.h
cudnn_frontend_ExecutionPlanCache.h
functional
limits
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_Engine.h
cudnn_frontend_EngineConfig.h
cudnn_frontend_Heuristics.h
cudnn_frontend_get_plan.h
cudnn_frontend_EngineConfigGenerator.h
cudnn_frontend_ExecutionPlanCache.h
cudnn_frontend_ExecutionPlan.h
cudnn_frontend_OperationGraph.h
cudnn_frontend.h
cudnn_frontend_find_plan.h
cudnn_frontend::OperationGraph_v8
cudnn_frontend::OperationGraphBuilder_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<vector>

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

    #include"cudnn_frontend_Operation.h"
    #include"cudnn_frontend_utils.h"

    namespacecudnn_frontend{

    classOperationGraph_v8:publicBackendDescriptor{
    public:
    friendclassOperationGraphBuilder_v8;
    std::string
    describe()constoverride{
    std::stringstreamss;
    ss<<"CUDNN_BACKEND_OPERATIONGRAPH_DESCRIPTOR:";
    returnss.str();
    }

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

    ~OperationGraph_v8()=default;

    auto
    getEngineCount(void)const->int64_t{
    int64_tglobal_count=-1;
    autostatus=cudnnBackendGetAttribute(pointer->get_backend_descriptor(),
    CUDNN_ATTR_OPERATIONGRAPH_ENGINE_GLOBAL_COUNT,
    CUDNN_TYPE_INT64,
    1,
    NULL,
    &global_count);
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(this,
    status,
    "CUDNN_BACKEND_OPERATIONGRAPH_DESCRIPTOR:GetAttribute"
    "CUDNN_ATTR_OPERATIONGRAPH_ENGINE_GLOBAL_COUNTFailed");
    }
    returnglobal_count;
    }
    uint64_t
    getOpCount()const{
    returnnumOps;
    }

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

    feature_vector_t
    getFeatureVector()const{
    if(numOps!=1){
    return{};
    }else{
    returnfeature_vectors[0];
    }

    }

    private:
    OperationGraph_v8()=default;
    OperationGraph_v8(OperationGraph_v8const&)=delete;
    OperationGraph_v8&
    operator=(OperationGraph_v8const&)=delete;

    cudnnHandle_thandle=nullptr;
    std::array<ManagedOpaqueDescriptor,10>ops{};
    int64_tnumOps=-1;
    std::stringopGraphTag="";
    std::vector<feature_vector_t>feature_vectors;
    };

    classOperationGraphBuilder_v8{
    public:
    auto
    setHandle(cudnnHandle_thandle_)->OperationGraphBuilder_v8&{
    m_operationGraph.handle=handle_;
    return*this;
    }
    auto
    setOperationGraph(int64_tnumOps_,Operation_v8const**ops_)->OperationGraphBuilder_v8&{
    m_operationGraph.numOps=numOps_;
    m_operationGraph.feature_vectors.resize(numOps_);
    for(autoi=0u;i<numOps_;i++){
    m_operationGraph.ops[i]=ops_[i]->get_desc();
    m_operationGraph.opGraphTag+=ops_[i]->getTag()+'_';
    m_operationGraph.feature_vectors[i]=ops_[i]->getFeatureVector();
    }
    return*this;
    }
    OperationGraph_v8&&
    build(){
    if(m_operationGraph.numOps<=0){
    set_error_and_throw_exception(
    &m_operationGraph,
    CUDNN_STATUS_BAD_PARAM,
    "CUDNN_BACKEND_OPERATIONGRAPH_DESCRIPTOR:CheckandSettheCUDNN_ATTR_OPERATIONGRAPH_OPSCountfield");
    returnstd::move(m_operationGraph);
    }
    if(m_operationGraph.ops[0]==nullptr){
    set_error_and_throw_exception(
    &m_operationGraph,
    CUDNN_STATUS_BAD_PARAM,
    "CUDNN_BACKEND_OPERATIONGRAPH_DESCRIPTOR:CheckandsetCUDNN_ATTR_OPERATIONGRAPH_OPSfield");
    returnstd::move(m_operationGraph);
    }
    if(m_operationGraph.handle==nullptr){
    set_error_and_throw_exception(
    &m_operationGraph,
    CUDNN_STATUS_BAD_PARAM,
    "CUDNN_BACKEND_OPERATIONGRAPH_DESCRIPTOR:CheckandSetCUDNN_ATTR_OPERATIONGRAPH_HANDLE");
    returnstd::move(m_operationGraph);
    }

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

    std::array<cudnnBackendDescriptor_t,10>ops_raw{nullptr};
    for(autoi=0u;i<m_operationGraph.numOps;i++){
    ops_raw[i]=m_operationGraph.ops[i]->get_backend_descriptor();
    }

    status=cudnnBackendSetAttribute(m_operationGraph.pointer->get_backend_descriptor(),
    CUDNN_ATTR_OPERATIONGRAPH_OPS,
    CUDNN_TYPE_BACKEND_DESCRIPTOR,
    m_operationGraph.numOps,
    ops_raw.data());
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    &m_operationGraph,
    status,
    "CUDNN_BACKEND_OPERATIONGRAPH_DESCRIPTOR:SetAttributeCUDNN_ATTR_OPERATIONGRAPH_OPSFailed");
    returnstd::move(m_operationGraph);
    }
    status=cudnnBackendSetAttribute(m_operationGraph.pointer->get_backend_descriptor(),
    CUDNN_ATTR_OPERATIONGRAPH_HANDLE,
    CUDNN_TYPE_HANDLE,
    1,
    &m_operationGraph.handle);
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    &m_operationGraph,
    status,
    "CUDNN_BACKEND_OPERATIONGRAPH_DESCRIPTOR:SetAttributeCUDNN_ATTR_OPERATIONGRAPH_HANDLEFailed");
    returnstd::move(m_operationGraph);
    }

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

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

    explicitOperationGraphBuilder_v8()=default;
    ~OperationGraphBuilder_v8()=default;
    OperationGraphBuilder_v8(OperationGraphBuilder_v8&&)=delete;
    OperationGraphBuilder_v8(OperationGraphBuilder_v8const&)=delete;
    OperationGraphBuilder_v8&
    operator=(OperationGraphBuilder_v8const&)=delete;

    private:
    OperationGraph_v8m_operationGraph;
    };

    usingOperationGraph=OperationGraph_v8;
    usingOperationGraphBuilder=OperationGraphBuilder_v8;
    }