cudnn_frontend_PointWiseDesc.h
algorithm
array
functional
memory
sstream
utility
limits
cudnn.h
cudnn_backend.h
cudnn_frontend_utils.h
cudnn_frontend_Operation.h
cudnn_frontend.h
functional
limits
cudnn.h
cudnn_frontend_PointWiseDesc.h
string
cudnn_frontend_Logging.h
exception
fstream
ostream
vector
cudnn_backend.h
utility
array
sstream
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_PointWiseDesc.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::PointWiseDesc_v8
cudnn_frontend::PointWiseDescBuilder_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<limits>

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

    #include"cudnn_frontend_utils.h"

    namespacecudnn_frontend{
    classPointWiseDesc_v8:publicBackendDescriptor{
    public:
    friendclassPointWiseDescBuilder_v8;
    std::string
    describe()constoverride{
    std::stringstreamss;
    ss<<"CUDNN_BACKEND_POINTWISE_DESCRIPTOR:"
    <<"Mode:"<<(mode)<<"Mathprecision"<<(math_precision);
    returnss.str();
    }

    int64_t
    getPortCount()const{
    switch(mode){
    caseCUDNN_POINTWISE_ADD:
    caseCUDNN_POINTWISE_MUL:
    #if(CUDNN_VERSION>=8300)
    caseCUDNN_POINTWISE_DIV:
    caseCUDNN_POINTWISE_ADD_SQUARE:
    caseCUDNN_POINTWISE_SUB:
    caseCUDNN_POINTWISE_CMP_EQ:
    caseCUDNN_POINTWISE_CMP_NEQ:
    caseCUDNN_POINTWISE_CMP_GT:
    caseCUDNN_POINTWISE_CMP_GE:
    caseCUDNN_POINTWISE_CMP_LT:
    caseCUDNN_POINTWISE_CMP_LE:
    caseCUDNN_POINTWISE_LOGICAL_AND:
    caseCUDNN_POINTWISE_LOGICAL_OR:
    #endif
    caseCUDNN_POINTWISE_MIN:
    caseCUDNN_POINTWISE_MAX:
    caseCUDNN_POINTWISE_RELU_BWD:
    caseCUDNN_POINTWISE_TANH_BWD:
    caseCUDNN_POINTWISE_SIGMOID_BWD:
    caseCUDNN_POINTWISE_ELU_BWD:
    caseCUDNN_POINTWISE_GELU_BWD:
    caseCUDNN_POINTWISE_SOFTPLUS_BWD:
    caseCUDNN_POINTWISE_SWISH_BWD:
    return3;
    caseCUDNN_POINTWISE_SQRT:
    caseCUDNN_POINTWISE_RELU_FWD:
    caseCUDNN_POINTWISE_TANH_FWD:
    caseCUDNN_POINTWISE_SIGMOID_FWD:
    caseCUDNN_POINTWISE_ELU_FWD:
    caseCUDNN_POINTWISE_GELU_FWD:
    caseCUDNN_POINTWISE_SOFTPLUS_FWD:
    caseCUDNN_POINTWISE_SWISH_FWD:
    #if(CUDNN_VERSION>=8300)
    caseCUDNN_POINTWISE_EXP:
    caseCUDNN_POINTWISE_LOG:
    caseCUDNN_POINTWISE_NEG:
    caseCUDNN_POINTWISE_MOD:
    caseCUDNN_POINTWISE_POW:
    caseCUDNN_POINTWISE_ABS:
    caseCUDNN_POINTWISE_CEIL:
    caseCUDNN_POINTWISE_FLOOR:
    caseCUDNN_POINTWISE_COS:
    caseCUDNN_POINTWISE_TAN:
    caseCUDNN_POINTWISE_SIN:
    caseCUDNN_POINTWISE_RSQRT:
    caseCUDNN_POINTWISE_LOGICAL_NOT:
    #endif
    return2;
    }
    }

    cudnnPointwiseMode_t
    getPointWiseMode()const{
    returnmode;
    }

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

    ~PointWiseDesc_v8()=default;

    private:
    PointWiseDesc_v8()=default;
    PointWiseDesc_v8(PointWiseDesc_v8const&)=delete;
    PointWiseDesc_v8&
    operator=(PointWiseDesc_v8const&)=delete;

    cudnnDataType_tmath_precision=CUDNN_DATA_FLOAT;
    cudnnPointwiseMode_tmode=CUDNN_POINTWISE_ADD;
    cudnnNanPropagation_tnan_propagation=CUDNN_NOT_PROPAGATE_NAN;
    doubleupper_clip=std::numeric_limits<double>::max();
    doublelower_clip=0.0;
    doublelower_clip_slope=0.0;
    doubleelu_alpha=1.0;
    doublesoftplus_beta=1.0;
    doubleswish_beta=1.0;
    };

    classPointWiseDescBuilder_v8{
    public:
    auto
    setMathPrecision(cudnnDataType_tdata_type_)->PointWiseDescBuilder_v8&{
    m_pointWiseDesc.math_precision=data_type_;
    return*this;
    }
    auto
    setClipping(doublel,doubleu)->PointWiseDescBuilder_v8&{
    m_pointWiseDesc.upper_clip=u;
    m_pointWiseDesc.lower_clip=l;
    return*this;
    }
    auto
    setMode(cudnnPointwiseMode_tmode_)->PointWiseDescBuilder_v8&{
    m_pointWiseDesc.mode=mode_;
    return*this;
    }
    auto
    setMode(cudnnNanPropagation_tnan_mode_)->PointWiseDescBuilder_v8&{
    m_pointWiseDesc.nan_propagation=nan_mode_;
    return*this;
    }
    auto
    setReluLowerClip(doublelower_clip_)->PointWiseDescBuilder_v8&{
    m_pointWiseDesc.lower_clip=lower_clip_;
    return*this;
    }

    auto
    setReluUpperClip(doubleupper_clip_)->PointWiseDescBuilder_v8&{
    m_pointWiseDesc.upper_clip=upper_clip_;
    return*this;
    }

    auto
    setReluLowerClipSlope(doublelower_clip_slope_)->PointWiseDescBuilder_v8&{
    m_pointWiseDesc.lower_clip_slope=lower_clip_slope_;
    return*this;
    }

    auto
    setEluAlpha(doubleelu_alpha_)->PointWiseDescBuilder_v8&{
    m_pointWiseDesc.elu_alpha=elu_alpha_;
    return*this;
    }

    auto
    setSoftplusBeta(doublesoftplus_beta_)->PointWiseDescBuilder_v8&{
    m_pointWiseDesc.softplus_beta=softplus_beta_;
    return*this;
    }

    auto
    setSwishBeta(doubleswish_beta_)->PointWiseDescBuilder_v8&{
    m_pointWiseDesc.swish_beta=swish_beta_;
    return*this;
    }

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

    //OnceCreatedletssetthedescriptorparameters.
    status=cudnnBackendSetAttribute(m_pointWiseDesc.pointer->get_backend_descriptor(),
    CUDNN_ATTR_POINTWISE_MODE,
    CUDNN_TYPE_POINTWISE_MODE,
    1,
    &m_pointWiseDesc.mode);
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    &m_pointWiseDesc,
    status,
    "CUDNN_BACKEND_POINTWISE_DESCRIPTOR:CUDNN_TYPE_POINTWISE_MODESetAttributeFailed");
    returnstd::move(m_pointWiseDesc);
    }

    status=cudnnBackendSetAttribute(m_pointWiseDesc.pointer->get_backend_descriptor(),
    CUDNN_ATTR_POINTWISE_MATH_PREC,
    CUDNN_TYPE_DATA_TYPE,
    1,
    &m_pointWiseDesc.math_precision);
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    &m_pointWiseDesc,
    status,
    "CUDNN_BACKEND_POINTWISE_DESCRIPTOR:SetAttributeCUDNN_ATTR_POINTWISE_MATH_PRECFailed");
    returnstd::move(m_pointWiseDesc);
    }

    if(m_pointWiseDesc.mode==CUDNN_POINTWISE_RELU_FWD||m_pointWiseDesc.mode==CUDNN_POINTWISE_RELU_BWD){
    status=cudnnBackendSetAttribute(m_pointWiseDesc.pointer->get_backend_descriptor(),
    CUDNN_ATTR_POINTWISE_NAN_PROPAGATION,
    CUDNN_TYPE_NAN_PROPOGATION,
    1,
    &m_pointWiseDesc.nan_propagation);
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    &m_pointWiseDesc,
    status,
    "CUDNN_BACKEND_POINTWISE_DESCRIPTOR:SetAttributeCUDNN_ATTR_POINTWISE_NAN_PROPAGATIONFailed");
    returnstd::move(m_pointWiseDesc);
    }

    status=cudnnBackendSetAttribute(m_pointWiseDesc.pointer->get_backend_descriptor(),
    CUDNN_ATTR_POINTWISE_RELU_LOWER_CLIP,
    CUDNN_TYPE_DOUBLE,
    1,
    &m_pointWiseDesc.lower_clip);
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    &m_pointWiseDesc,
    status,
    "CUDNN_BACKEND_POINTWISE_DESCRIPTOR:SetAttributeCUDNN_ATTR_POINTWISE_RELU_LOWER_CLIP,Failed");
    returnstd::move(m_pointWiseDesc);
    }

    if(m_pointWiseDesc.math_precision==CUDNN_DATA_FLOAT){
    doubleclamped_upper_clip=
    std::min<double>(m_pointWiseDesc.upper_clip,std::numeric_limits<float>::max());
    status=cudnnBackendSetAttribute(m_pointWiseDesc.pointer->get_backend_descriptor(),
    CUDNN_ATTR_POINTWISE_RELU_UPPER_CLIP,
    CUDNN_TYPE_DOUBLE,
    1,
    &clamped_upper_clip);

    }else{
    status=cudnnBackendSetAttribute(m_pointWiseDesc.pointer->get_backend_descriptor(),
    CUDNN_ATTR_POINTWISE_RELU_UPPER_CLIP,
    CUDNN_TYPE_DOUBLE,
    1,
    &m_pointWiseDesc.upper_clip);
    }
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    &m_pointWiseDesc,
    status,
    "CUDNN_BACKEND_POINTWISE_DESCRIPTOR:SetAttributeCUDNN_ATTR_POINTWISE_RELU_UPPER_CLIP,Failed");
    returnstd::move(m_pointWiseDesc);
    }

    status=cudnnBackendSetAttribute(m_pointWiseDesc.pointer->get_backend_descriptor(),
    CUDNN_ATTR_POINTWISE_RELU_LOWER_CLIP_SLOPE,
    CUDNN_TYPE_DOUBLE,
    1,
    &m_pointWiseDesc.lower_clip_slope);
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(&m_pointWiseDesc,
    status,
    "CUDNN_BACKEND_POINTWISE_DESCRIPTOR:SetAttribute"
    "CUDNN_ATTR_POINTWISE_RELU_LOWER_CLIP_SLOPE,Failed");
    returnstd::move(m_pointWiseDesc);
    }
    }elseif(m_pointWiseDesc.mode==CUDNN_POINTWISE_ELU_FWD||m_pointWiseDesc.mode==CUDNN_POINTWISE_ELU_BWD){
    status=cudnnBackendSetAttribute(m_pointWiseDesc.pointer->get_backend_descriptor(),
    CUDNN_ATTR_POINTWISE_ELU_ALPHA,
    CUDNN_TYPE_DOUBLE,
    1,
    &m_pointWiseDesc.elu_alpha);
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    &m_pointWiseDesc,
    status,
    "CUDNN_BACKEND_POINTWISE_DESCRIPTOR:SetAttributeCUDNN_ATTR_POINTWISE_ELU_ALPHA,Failed");
    returnstd::move(m_pointWiseDesc);
    }
    }elseif(m_pointWiseDesc.mode==CUDNN_POINTWISE_SOFTPLUS_FWD||
    m_pointWiseDesc.mode==CUDNN_POINTWISE_SOFTPLUS_BWD){
    status=cudnnBackendSetAttribute(m_pointWiseDesc.pointer->get_backend_descriptor(),
    CUDNN_ATTR_POINTWISE_SOFTPLUS_BETA,
    CUDNN_TYPE_DOUBLE,
    1,
    &m_pointWiseDesc.softplus_beta);
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    &m_pointWiseDesc,
    status,
    "CUDNN_BACKEND_POINTWISE_DESCRIPTOR:SetAttributeCUDNN_ATTR_POINTWISE_SOFTPLUS_BETA,Failed");
    returnstd::move(m_pointWiseDesc);
    }
    }elseif(m_pointWiseDesc.mode==CUDNN_POINTWISE_SWISH_FWD||
    m_pointWiseDesc.mode==CUDNN_POINTWISE_SWISH_BWD){
    status=cudnnBackendSetAttribute(m_pointWiseDesc.pointer->get_backend_descriptor(),
    CUDNN_ATTR_POINTWISE_SWISH_BETA,
    CUDNN_TYPE_DOUBLE,
    1,
    &m_pointWiseDesc.swish_beta);
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    &m_pointWiseDesc,
    status,
    "CUDNN_BACKEND_POINTWISE_DESCRIPTOR:SetAttributeCUDNN_ATTR_POINTWISE_SWISH_BETA,Failed");
    returnstd::move(m_pointWiseDesc);
    }
    }

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

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

    explicitPointWiseDescBuilder_v8()=default;
    ~PointWiseDescBuilder_v8()=default;
    PointWiseDescBuilder_v8(PointWiseDescBuilder_v8&&)=delete;
    PointWiseDescBuilder_v8(PointWiseDescBuilder_v8const&)=delete;
    PointWiseDescBuilder_v8&
    operator=(PointWiseDescBuilder_v8const&)=delete;

    private:
    PointWiseDesc_v8m_pointWiseDesc;
    };
    }