cudnn_frontend_Errata.h
contrib/nlohmann/json/json.hpp
../include/cudnn_frontend_Logging.h
cstdlib
fstream
cudnn_frontend.h
valarray
functional
limits
iterator
cstdint
cudnn.h
cmath
cassert
stdexcept
numeric
string
map
cudnn_frontend_Errata.h
../include/cudnn_frontend_Logging.h
exception
fstream
ostream
ios
cstdio
contrib/nlohmann/json/json.hpp
tuple
vector
utility
array
iosfwd
cstdlib
clocale
cctype
iostream
cstddef
unordered_map
type_traits
forward_list
algorithm
cstring
memory
istream
initializer_list
cudnn_backend_base.h
cudnn_frontend_get_plan.h
cudnn_frontend_Errata.h
cudnn_frontend_EngineConfigGenerator.h
cudnn_frontend.h
cudnn_frontend_find_plan.h
cudnn_frontend
nlohmann::json using json = nlohmann::json json

    /*
    *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.
    */

    #include"contrib/nlohmann/json/json.hpp"

    #include"../include/cudnn_frontend_Logging.h"

    #include<cstdlib>
    #include<fstream>
    #pragmaonce

    usingjson=nlohmann::json;

    namespacecudnn_frontend{

    //Loadsthejsonhandlefromthejsonfile
    //jsonfileisdefinedbyenvironmentvariable
    //CUDNN_ERRATA_JSON_FILE.Iftheenvironmentvariable
    //isnotsetthevaluesetintheAPIisconsidered.
    staticbool
    load_from_config(json&json_handle,conststd::string&errata_json){
    constchar*err_json=std::getenv("CUDNN_ERRATA_JSON_FILE");
    if(err_json==NULL&&errata_json==""){returnfalse;}
    if(err_json==NULL){err_json=errata_json.c_str();}
    std::ifstreamifs(err_json,std::ifstream::in);
    if(!ifs.is_open()||!ifs.good()){returnfalse;}
    ifs>>json_handle;
    returntrue;
    }

    template<typenameT>
    staticbool
    check_rule(constjson&json_handle,conststd::string&executionPlanTag,
    cudnnHandle_thandle,Tfn){
    std::stringoperation=json_handle["operation"];
    int64_tengine=json_handle["engine"];
    uint64_tcudnn_start=0;
    uint64_tcudnn_end=-1;
    if(json_handle.contains("cudnn_version_start")){
    cudnn_start=json_handle["cudnn_version_start"];
    }
    if(json_handle.contains("cudnn_version_end")){
    cudnn_end=json_handle["cudnn_version_end"];
    }
    std::stringtag_prefix=operation+"_eng"+std::to_string(engine)+"_";
    std::stringmod_tag=executionPlanTag+"_";
    boolblocked=
    tag_prefix.size()<=mod_tag.size()&&
    std::equal(tag_prefix.begin(),tag_prefix.end(),mod_tag.begin())&&
    CUDNN_VERSION>=cudnn_start&&
    CUDNN_VERSION<cudnn_end;

    if(blocked&&json_handle.contains("knob")){//Shortcircuitifoperationandenginedonotmatch
    for(auto&kv:json_handle["knob"]){
    blocked=blocked&&
    (executionPlanTag.find(kv)!=std::string::npos);
    }
    }

    blocked=blocked&&fn();
    returnblocked;

    (void)handle;
    }

    //Takesinaninitialzedjsonhandleandchecksifitsatisfiesthe
    //conditionforrunningit.ReturnstrueifthegivenexecutionPlanTag
    //isfaulty.
    template<typenameT>
    staticbool
    check_errata(constjson&json_handle,conststd::string&executionPlanTag,
    cudnnHandle_thandle,Tfn){

    cudnn_frontend::getLogger()<<"[cudnn_frontend]"<<"Verifying"<<executionPlanTag;
    for(autoconst&rule:json_handle["rules"]){
    if(check_rule<T>(rule,executionPlanTag,handle,fn)){
    cudnn_frontend::getLogger()<<".Blocking."<<std::endl;
    returntrue;
    }
    }

    cudnn_frontend::getLogger()<<".Passed."<<std::endl;
    returnfalse;
    }

    }