cudnn_frontend_VariantPack.h
algorithm
array
functional
memory
set
sstream
utility
cudnn.h
cudnn_backend.h
cudnn_frontend_utils.h
cudnn_frontend.h
functional
cudnn_frontend_VariantPack.h
cudnn.h
string
cudnn_frontend_Logging.h
exception
fstream
ostream
vector
cudnn_backend.h
utility
array
sstream
iostream
set
algorithm
cstring
cudnn_frontend_utils.h
memory
cudnn_backend_base.h
cudnn_frontend_VariantPack.h
cudnn_frontend_get_plan.h
cudnn_frontend_EngineConfigGenerator.h
cudnn_frontend.h
cudnn_frontend_find_plan.h
cudnn_frontend::VariantPack_v8
cudnn_frontend::VariantPackBuilder_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<set>
    #include<sstream>
    #include<utility>

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

    #include"cudnn_frontend_utils.h"

    namespacecudnn_frontend{

    classVariantPack_v8:publicBackendDescriptor{
    public:
    friendclassVariantPackBuilder_v8;
    std::string
    describe()constoverride{
    std::stringstreamss;
    ss<<"CUDNN_BACKEND_VARIANT_PACK_DESCRIPTOR:"
    <<"has"<<num_ptrs<<"datapointers";
    returnss.str();
    }

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

    ~VariantPack_v8()=default;

    private:
    VariantPack_v8()=default;
    VariantPack_v8(VariantPack_v8const&)=delete;
    VariantPack_v8&
    operator=(VariantPack_v8const&)=delete;

    void*workspace=nullptr;
    void*data_pointers[10]={nullptr};
    int64_tuid[10]={-1};
    int64_tnum_ptrs=-1;
    };

    classVariantPackBuilder_v8{
    public:
    auto
    setDataPointers(int64_tnum_ptr,void**ptrs)->VariantPackBuilder_v8&{
    std::copy(ptrs,ptrs+num_ptr,m_variant_pack.data_pointers);
    m_variant_pack.num_ptrs=num_ptr;
    return*this;
    }
    auto
    setUids(int64_tnum_uids,int64_t*uid)->VariantPackBuilder_v8&{
    std::copy(uid,uid+num_uids,m_variant_pack.uid);
    return*this;
    }
    auto
    setDataPointers(std::set<std::pair<uint64_t,void*>>const&data_pointers)->VariantPackBuilder_v8&{
    autoi=0;
    for(auto&data_pointer:data_pointers){
    m_variant_pack.uid[i]=data_pointer.first;
    m_variant_pack.data_pointers[i]=data_pointer.second;
    i++;
    }
    m_variant_pack.num_ptrs=data_pointers.size();
    return*this;
    }
    auto
    setWorkspacePointer(void*ws)->VariantPackBuilder_v8&{
    m_variant_pack.workspace=ws;
    return*this;
    }
    VariantPack_v8&&
    build(){
    //Createadescriptor.Memoryallocationhappenshere.
    autostatus=m_variant_pack.initialize_managed_backend_pointer(CUDNN_BACKEND_VARIANT_PACK_DESCRIPTOR);
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    &m_variant_pack,status,"CUDNN_BACKEND_VARIANT_PACK_DESCRIPTOR:cudnnCreateFailed");
    returnstd::move(m_variant_pack);
    }

    status=cudnnBackendSetAttribute(m_variant_pack.pointer->get_backend_descriptor(),
    CUDNN_ATTR_VARIANT_PACK_DATA_POINTERS,
    CUDNN_TYPE_VOID_PTR,
    m_variant_pack.num_ptrs,
    m_variant_pack.data_pointers);
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    &m_variant_pack,
    status,
    "CUDNN_BACKEND_VARIANT_PACK_DESCRIPTOR:SetAttributeCUDNN_ATTR_VARIANT_PACK_DATA_POINTERSFailed");
    returnstd::move(m_variant_pack);
    }

    status=cudnnBackendSetAttribute(m_variant_pack.pointer->get_backend_descriptor(),
    CUDNN_ATTR_VARIANT_PACK_UNIQUE_IDS,
    CUDNN_TYPE_INT64,
    m_variant_pack.num_ptrs,
    m_variant_pack.uid);
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    &m_variant_pack,
    status,
    "CUDNN_BACKEND_VARIANT_PACK_DESCRIPTOR:SetAttributeCUDNN_ATTR_VARIANT_PACK_UNIQUE_IDSFailed");
    returnstd::move(m_variant_pack);
    }

    status=cudnnBackendSetAttribute(m_variant_pack.pointer->get_backend_descriptor(),
    CUDNN_ATTR_VARIANT_PACK_WORKSPACE,
    CUDNN_TYPE_VOID_PTR,
    1,
    &m_variant_pack.workspace);
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    &m_variant_pack,
    status,
    "CUDNN_BACKEND_VARIANT_PACK_DESCRIPTOR:SetAttributeCUDNN_ATTR_VARIANT_PACK_WORKSPACEFailed");
    returnstd::move(m_variant_pack);
    }

    //Finalizingthedescriptor
    status=cudnnBackendFinalize(m_variant_pack.pointer->get_backend_descriptor());
    if(status!=CUDNN_STATUS_SUCCESS){
    set_error_and_throw_exception(
    &m_variant_pack,status,"CUDNN_BACKEND_VARIANT_PACK_DESCRIPTOR:cudnnFinalizeFailed");
    returnstd::move(m_variant_pack);
    }
    getLogger()<<"[cudnn_frontend]"<<m_variant_pack<<std::endl;
    returnstd::move(m_variant_pack);
    }

    explicitVariantPackBuilder_v8()=default;
    ~VariantPackBuilder_v8()=default;
    VariantPackBuilder_v8(VariantPackBuilder_v8&&)=delete;
    VariantPackBuilder_v8(VariantPackBuilder_v8const&)=delete;
    VariantPackBuilder_v8&
    operator=(VariantPackBuilder_v8const&)=delete;

    private:
    VariantPack_v8m_variant_pack;
    };
    }