cudnn_frontend_ReductionDesc.h
algorithm
array
functional
memory
sstream
utility
cudnn.h
cudnn_backend.h
cudnn_frontend_utils.h
cudnn_frontend_Operation.h
functional
cudnn.h
string
cudnn_frontend_Logging.h
exception
fstream
ostream
vector
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_Operation.h
cudnn_frontend_ExecutionPlan.h
cudnn_frontend_OperationGraph.h
cudnn_frontend.h
cudnn_frontend_find_plan.h
cudnn_frontend_ReductionDesc.h
cudnn_frontend::ReductionDesc_v8
cudnn_frontend::ReductionDescBuilder_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_utils.h"

    namespacecudnn_frontend{
    classReductionDesc_v8:publicBackendDescriptor{
    public:
    friendclassReductionDescBuilder_v8;
    std::string
    describe()constoverride{
    std::stringstreamss;
    ss<<"CUDNN_BACKEND_REDUCTION_DESCRIPTOR:"
    <<"Mathprecision"<<(math_precision)<<"Reductionoperator"<<(reduction_op);
    returnss.str();
    }

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

    ~ReductionDesc_v8()=default;

    private:
    ReductionDesc_v8()=default;
    ReductionDesc_v8(ReductionDesc_v8const&)=delete;
    ReductionDesc_v8&
    operator=(ReductionDesc_v8const&)=delete;

    cudnnDataType_tmath_precision=CUDNN_DATA_FLOAT;
    cudnnReduceTensorOp_treduction_op=CUDNN_REDUCE_TENSOR_ADD;
    };

    classReductionDescBuilder_v8{
    public:
    auto
    setMathPrecision(cudnnDataType_tdata_type_)->ReductionDescBuilder_v8&{
    m_reductionDesc.math_precision=data_type_;
    return*this;
    }
    auto
    setReductionOp(cudnnReduceTensorOp_top_)->ReductionDescBuilder_v8&{
    m_reductionDesc.reduction_op=op_;
    return*this;
    }
    ReductionDesc_v8&&
    build(){
    //Createadescriptor.Memoryallocationhappenshere.
    autostatus=m_reductionDesc.initialize_managed_backend_pointer(CUDNN_BACKEND_REDUCTION_DESCRIPTOR);
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    &m_reductionDesc,status,"CUDNN_BACKEND_REDUCTION_DESCRIPTOR:cudnnCreateFailed");
    returnstd::move(m_reductionDesc);
    }

    //OnceCreatedletssetthedescriptorparameters.
    status=cudnnBackendSetAttribute(m_reductionDesc.pointer->get_backend_descriptor(),
    CUDNN_ATTR_REDUCTION_COMP_TYPE,
    CUDNN_TYPE_DATA_TYPE,
    1,
    &m_reductionDesc.math_precision);
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    &m_reductionDesc,
    status,
    "CUDNN_BACKEND_REDUCTION_DESCRIPTOR:SetAttributeCUDNN_ATTR_REDUCTION_COMP_TYPEFailed");
    returnstd::move(m_reductionDesc);
    }

    status=cudnnBackendSetAttribute(m_reductionDesc.pointer->get_backend_descriptor(),
    CUDNN_ATTR_REDUCTION_OPERATOR,
    CUDNN_TYPE_REDUCTION_OPERATOR_TYPE,
    1,
    &m_reductionDesc.reduction_op);
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    &m_reductionDesc,
    status,
    "CUDNN_BACKEND_REDUCTION_DESCRIPTOR:SetAttributeCUDNN_ATTR_REDUCTION_OPERATORFailed");
    returnstd::move(m_reductionDesc);
    }

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

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

    explicitReductionDescBuilder_v8()=default;
    ~ReductionDescBuilder_v8()=default;
    ReductionDescBuilder_v8(ReductionDescBuilder_v8&&)=delete;
    ReductionDescBuilder_v8(ReductionDescBuilder_v8const&)=delete;
    ReductionDescBuilder_v8&
    operator=(ReductionDescBuilder_v8const&)=delete;

    private:
    ReductionDesc_v8m_reductionDesc;
    };
    }