cudnn_frontend_ConvDesc.h
algorithm
array
functional
memory
sstream
utility
cudnn.h
cudnn_backend.h
cudnn_frontend_utils.h
cudnn_frontend.h
cudnn_frontend_Operation.h
cudnn_frontend_Reorder_Tensor.h
functional
cudnn.h
string
cudnn_frontend_Logging.h
exception
fstream
ostream
vector
cudnn_frontend_ConvDesc.h
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_get_plan.h
cudnn_frontend_EngineConfigGenerator.h
cudnn_frontend_ExecutionPlanCache.h
cudnn_frontend_Operation.h
cudnn_frontend_Reorder_Tensor.h
cudnn_frontend_ExecutionPlan.h
cudnn_frontend_ConvDesc.h
cudnn_frontend_OperationGraph.h
cudnn_frontend.h
cudnn_frontend_find_plan.h
cudnn_frontend::ConvDesc_v8
cudnn_frontend::ConvDescBuilder_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{

    classConvDesc_v8:publicBackendDescriptor{
    public:
    friendclassConvDescBuilder_v8;
    std::string
    describe()constoverride{
    std::stringstreamss;
    charsep='';
    ss<<"CUDNN_BACKEND_CONVOLUTION_DESCRIPTOR:"
    <<"Datatype:"<<to_string(compute_precision)<<"Mode:"<<std::to_string(mode)
    <<"NumDimensions:"<<nDims;
    ss<<"PadLower[";
    for(autoi=0;i<nDims;i++){
    ss<<sep<<padLower[i];
    sep=',';
    }
    ss<<"]PadUpper[";
    for(autoi=0;i<nDims;i++){
    ss<<sep<<padUpper[i];
    sep=',';
    }
    ss<<"]Dilation[";
    for(autoi=0;i<nDims;i++){
    ss<<sep<<dilation[i];
    sep=',';
    }
    ss<<"]Stride[";
    for(autoi=0;i<nDims;i++){
    ss<<sep<<stride[i];
    sep=',';
    }
    ss<<"]";
    returnss.str();
    }

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

    ~ConvDesc_v8()=default;

    cudnnDataType_t
    getComputePrecision()const{
    returncompute_precision;
    }

    int64_t
    getDimensionCount()const{
    returnnDims;
    }

    int64_tconst*
    getPadding()const{
    returnpadLower;
    }
    int64_tconst*
    getStride()const{
    returnstride;
    }
    int64_tconst*
    getDilation()const{
    returndilation;
    }

    cudnnConvolutionMode_t
    getMathMode()const{
    returnmode;
    }

    private:
    ConvDesc_v8()=default;
    ConvDesc_v8(ConvDesc_v8const&)=delete;
    ConvDesc_v8&
    operator=(ConvDesc_v8const&)=delete;

    cudnnDataType_tcompute_precision=CUDNN_DATA_FLOAT;
    cudnnConvolutionMode_tmode=CUDNN_CONVOLUTION;
    int64_tnDims=-1;
    int64_tpadLower[CUDNN_DIM_MAX+1]={0};
    int64_tpadUpper[CUDNN_DIM_MAX+1]={0};
    int64_tdilation[CUDNN_DIM_MAX+1]={0};
    int64_tstride[CUDNN_DIM_MAX+1]={-1};
    };

    classConvDescBuilder_v8{
    public:
    auto
    setDataType(cudnnDataType_tdata_type_)->ConvDescBuilder_v8&{
    returnsetComputePrecision(data_type_);
    }
    auto
    setComputePrecision(cudnnDataType_tdata_type_)->ConvDescBuilder_v8&{
    m_convDesc.compute_precision=data_type_;
    return*this;
    }
    auto
    setPrePadding(int64_tndims,int64_tconst*padding)->ConvDescBuilder_v8&{
    std::copy(padding,padding+ndims,m_convDesc.padLower);
    return*this;
    }
    auto
    setPostPadding(int64_tndims,int64_tconst*padding)->ConvDescBuilder_v8&{
    std::copy(padding,padding+ndims,m_convDesc.padUpper);
    return*this;
    }
    auto
    setDilation(int64_tndims,int64_tconst*dilation)->ConvDescBuilder_v8&{
    std::copy(dilation,dilation+ndims,m_convDesc.dilation);
    return*this;
    }
    auto
    setStrides(int64_tndims,int64_tconst*strides)->ConvDescBuilder_v8&{
    std::copy(strides,strides+ndims,m_convDesc.stride);
    return*this;
    }
    auto
    setNDims(int64_tnDims_)->ConvDescBuilder_v8&{
    m_convDesc.nDims=nDims_;
    return*this;
    }
    auto
    setMathMode(cudnnConvolutionMode_tmode_)->ConvDescBuilder_v8&{
    m_convDesc.mode=mode_;
    return*this;
    }
    ConvDesc_v8&&
    build(){
    //Sanitycheckifnon-defaultfieldshavebeensetcorrectly.
    if(m_convDesc.nDims<=0){
    set_error_and_throw_exception(
    &m_convDesc,
    CUDNN_STATUS_BAD_PARAM,
    "CUDNN_BACKEND_CONVOLUTION_DESCRIPTOR:CheckandSettheCUDNN_ATTR_CONVOLUTION_SPATIAL_DIMSfield");
    returnstd::move(m_convDesc);
    };
    if(m_convDesc.stride[0]<=0){
    set_error_and_throw_exception(
    &m_convDesc,
    CUDNN_STATUS_BAD_PARAM,
    "CUDNN_BACKEND_CONVOLUTION_DESCRIPTOR:CheckandSettheCUDNN_ATTR_CONVOLUTION_FILTER_STRIDESfield");
    returnstd::move(m_convDesc);
    }

    //Createadescriptor.Memoryallocationhappenshere.
    autostatus=m_convDesc.initialize_managed_backend_pointer(CUDNN_BACKEND_CONVOLUTION_DESCRIPTOR);
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    &m_convDesc,status,"CUDNN_BACKEND_CONVOLUTION_DESCRIPTOR:Baddescriptorcreated");
    returnstd::move(m_convDesc);
    }

    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    &m_convDesc,status,"CUDNN_BACKEND_CONVOLUTION_DESCRIPTOR:cudnnCreateFailed");
    returnstd::move(m_convDesc);
    }

    //OnceCreatedletssetthedescriptorparameters.
    status=cudnnBackendSetAttribute(m_convDesc.pointer->get_backend_descriptor(),
    CUDNN_ATTR_CONVOLUTION_COMP_TYPE,
    CUDNN_TYPE_DATA_TYPE,
    1,
    &m_convDesc.compute_precision);
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    &m_convDesc,
    status,
    "CUDNN_BACKEND_CONVOLUTION_DESCRIPTOR:SetAttributeCUDNN_ATTR_CONVOLUTION_COMP_TYPEFailed");
    returnstd::move(m_convDesc);
    }

    status=cudnnBackendSetAttribute(m_convDesc.pointer->get_backend_descriptor(),
    CUDNN_ATTR_CONVOLUTION_CONV_MODE,
    CUDNN_TYPE_CONVOLUTION_MODE,
    1,
    &m_convDesc.mode);
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    &m_convDesc,
    status,
    "CUDNN_BACKEND_CONVOLUTION_DESCRIPTOR:SetAttributeCUDNN_ATTR_CONVOLUTION_CONV_MODEFailed");
    returnstd::move(m_convDesc);
    }

    status=cudnnBackendSetAttribute(m_convDesc.pointer->get_backend_descriptor(),
    CUDNN_ATTR_CONVOLUTION_SPATIAL_DIMS,
    CUDNN_TYPE_INT64,
    1,
    &m_convDesc.nDims);
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    &m_convDesc,
    status,
    "CUDNN_BACKEND_CONVOLUTION_DESCRIPTOR:SetAttributeCUDNN_ATTR_CONVOLUTION_SPATIAL_DIMSFailed");
    returnstd::move(m_convDesc);
    }

    status=cudnnBackendSetAttribute(m_convDesc.pointer->get_backend_descriptor(),
    CUDNN_ATTR_CONVOLUTION_PRE_PADDINGS,
    CUDNN_TYPE_INT64,
    m_convDesc.nDims,
    m_convDesc.padLower);
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    &m_convDesc,
    status,
    "CUDNN_BACKEND_CONVOLUTION_DESCRIPTOR:SetAttributeCUDNN_ATTR_CONVOLUTION_PRE_PADDINGSFailed");
    returnstd::move(m_convDesc);
    }

    status=cudnnBackendSetAttribute(m_convDesc.pointer->get_backend_descriptor(),
    CUDNN_ATTR_CONVOLUTION_POST_PADDINGS,
    CUDNN_TYPE_INT64,
    m_convDesc.nDims,
    m_convDesc.padUpper);
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    &m_convDesc,
    status,
    "CUDNN_BACKEND_CONVOLUTION_DESCRIPTOR:SetAttributeCUDNN_ATTR_CONVOLUTION_POST_PADDINGSFailed");
    returnstd::move(m_convDesc);
    }

    status=cudnnBackendSetAttribute(m_convDesc.pointer->get_backend_descriptor(),
    CUDNN_ATTR_CONVOLUTION_DILATIONS,
    CUDNN_TYPE_INT64,
    m_convDesc.nDims,
    m_convDesc.dilation);
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    &m_convDesc,
    status,
    "CUDNN_BACKEND_CONVOLUTION_DESCRIPTOR:SetAttributeCUDNN_ATTR_CONVOLUTION_DILATIONSFailed");
    returnstd::move(m_convDesc);
    }

    status=cudnnBackendSetAttribute(m_convDesc.pointer->get_backend_descriptor(),
    CUDNN_ATTR_CONVOLUTION_FILTER_STRIDES,
    CUDNN_TYPE_INT64,
    m_convDesc.nDims,
    m_convDesc.stride);
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    &m_convDesc,
    status,
    "CUDNN_BACKEND_CONVOLUTION_DESCRIPTOR:SetAttributeCUDNN_ATTR_CONVOLUTION_FILTER_STRIDESFailed");
    returnstd::move(m_convDesc);
    }

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

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

    explicitConvDescBuilder_v8()=default;
    ~ConvDescBuilder_v8()=default;
    ConvDescBuilder_v8(ConvDescBuilder_v8&&)=delete;
    ConvDescBuilder_v8(ConvDescBuilder_v8const&)=delete;
    ConvDescBuilder_v8&
    operator=(ConvDescBuilder_v8const&)=delete;

    private:
    ConvDesc_v8m_convDesc;
    };
    }