onnxruntime_c_api.h 325 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429
  1. // Copyright (c) Microsoft Corporation. All rights reserved.
  2. // Licensed under the MIT License.
  3. // See docs\c_cxx\README.md on generating the Doxygen documentation from this file
  4. /** \mainpage ONNX Runtime
  5. *
  6. * ONNX Runtime is a high-performance inference and training graph execution engine for deep learning models.
  7. *
  8. * ONNX Runtime's C, C++ APIs offer an easy to use interface to onboard and execute onnx models.
  9. * - \subpage c_cpp_api "Core C, C++ APIs"
  10. * - \subpage training_c_cpp_api "Training C, C++ APIs for on-device training"
  11. *
  12. * \page c_cpp_api Core C, C++ APIs
  13. * <h1>C</h1>
  14. *
  15. * ::OrtApi - Click here to go to the structure with all C API functions.
  16. *
  17. * <h1>C++</h1>
  18. *
  19. * ::Ort - Click here to go to the namespace holding all of the C++ wrapper classes
  20. *
  21. * It is a set of header only wrapper classes around the C API. The goal is to turn the C style return value error codes into C++ exceptions, and to
  22. * automate memory management through standard C++ RAII principles.
  23. *
  24. * \addtogroup Global
  25. * ONNX Runtime C API
  26. * @{
  27. */
  28. #pragma once
  29. #include <stdbool.h>
  30. #include <stdint.h>
  31. #include <stdlib.h>
  32. #include <string.h>
  33. /** \brief The API version defined in this header
  34. *
  35. * This value is used by some API functions to behave as this version of the header expects.
  36. */
  37. #define ORT_API_VERSION 23
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. //! @}
  42. // SAL2 Definitions
  43. #ifndef _MSC_VER
  44. #define _In_
  45. #define _In_z_
  46. #define _In_opt_
  47. #define _In_opt_z_
  48. #define _Out_
  49. #define _Out_opt_
  50. #define _Outptr_
  51. #define _Outptr_opt_
  52. #define _Inout_
  53. #define _Inout_opt_
  54. #define _Frees_ptr_opt_
  55. #define _Ret_maybenull_
  56. #define _Ret_notnull_
  57. #define _Check_return_
  58. #define _Outptr_result_maybenull_
  59. #define _Outptr_result_maybenull_z_
  60. #define _In_reads_(X)
  61. #define _In_reads_opt_
  62. #define _Inout_updates_(X)
  63. #define _Out_writes_(X)
  64. #define _Out_writes_opt_(X)
  65. #define _Inout_updates_all_(X)
  66. #define _Out_writes_bytes_all_(X)
  67. #define _Out_writes_all_(X)
  68. #define _Success_(X)
  69. #define _Outptr_result_buffer_maybenull_(X)
  70. #define ORT_ALL_ARGS_NONNULL __attribute__((nonnull))
  71. #else
  72. #include <specstrings.h>
  73. #define ORT_ALL_ARGS_NONNULL
  74. #endif
  75. #ifdef _WIN32
  76. // Define ORT_DLL_IMPORT if your program is dynamically linked to Ort.
  77. // dllexport is not used, we use a .def file.
  78. #ifdef ORT_DLL_IMPORT
  79. #define ORT_EXPORT __declspec(dllimport)
  80. #else
  81. #define ORT_EXPORT
  82. #endif
  83. #define ORT_API_CALL _stdcall
  84. #define ORT_MUST_USE_RESULT
  85. #define ORTCHAR_T wchar_t
  86. #else
  87. // To make symbols visible on macOS/iOS
  88. #ifdef __APPLE__
  89. #define ORT_EXPORT __attribute__((visibility("default")))
  90. #else
  91. #define ORT_EXPORT
  92. #endif
  93. #define ORT_API_CALL
  94. #define ORT_MUST_USE_RESULT __attribute__((warn_unused_result))
  95. #define ORTCHAR_T char
  96. #endif
  97. /// ORTCHAR_T, ORT_TSTR are reserved specifically for path handling.
  98. /// All other strings are UTF-8 encoded, use char and std::string
  99. #ifndef ORT_TSTR
  100. #ifdef _WIN32
  101. #define ORT_TSTR(X) L##X
  102. // When X is a macro, L##X is not defined. In this case, we need to use ORT_TSTR_ON_MACRO.
  103. #define ORT_TSTR_ON_MACRO(X) L"" X
  104. #else
  105. #define ORT_TSTR(X) X
  106. #define ORT_TSTR_ON_MACRO(X) X
  107. #endif
  108. #endif
  109. // On Windows, ORT_FILE is a wchar_t version of the __FILE__ macro.
  110. // Otherwise, ORT_FILE is equivalent to __FILE__.
  111. #ifndef ORT_FILE
  112. #define ORT_FILE_INTERNAL(x) ORT_TSTR(x)
  113. #define ORT_FILE ORT_FILE_INTERNAL(__FILE__)
  114. #endif
  115. // Any pointer marked with _In_ or _Out_, cannot be NULL.
  116. // Windows users should use unicode paths when possible to bypass the MAX_PATH limitation
  117. // Every pointer marked with _In_ or _Out_, cannot be NULL. Caller should ensure that.
  118. // for ReleaseXXX(...) functions, they can accept NULL pointer.
  119. #ifdef __cplusplus
  120. // For any compiler with C++11 support, MSVC 2015 and greater, or Clang version supporting noexcept.
  121. // Such complex condition is needed because compilers set __cplusplus value differently.
  122. #ifndef __has_feature
  123. #define __has_feature(x) 0
  124. #endif
  125. #if ((__cplusplus >= 201103L) || (_MSC_VER >= 1900) || (defined(__has_feature) && __has_feature(cxx_noexcept)))
  126. #define NO_EXCEPTION noexcept
  127. #else
  128. #define NO_EXCEPTION throw()
  129. #endif
  130. #else
  131. #define NO_EXCEPTION
  132. #endif
  133. // __VA_ARGS__ on Windows and Linux are different
  134. #define ORT_API(RETURN_TYPE, NAME, ...) RETURN_TYPE ORT_API_CALL NAME(__VA_ARGS__) NO_EXCEPTION
  135. #define ORT_API_T(RETURN_TYPE, NAME, ...) \
  136. RETURN_TYPE(ORT_API_CALL* NAME)(__VA_ARGS__) NO_EXCEPTION
  137. #define ORT_API_STATUS(NAME, ...) \
  138. _Success_(return == 0) _Check_return_ _Ret_maybenull_ OrtStatusPtr ORT_API_CALL NAME(__VA_ARGS__) \
  139. NO_EXCEPTION ORT_MUST_USE_RESULT
  140. // XXX: Unfortunately, SAL annotations are known to not work with function pointers
  141. #define ORT_API2_STATUS(NAME, ...) \
  142. _Check_return_ _Ret_maybenull_ OrtStatusPtr(ORT_API_CALL* NAME)(__VA_ARGS__) NO_EXCEPTION ORT_MUST_USE_RESULT
  143. // Used in *.cc files. Almost as same as ORT_API_STATUS, except without ORT_MUST_USE_RESULT and ORT_EXPORT
  144. #define ORT_API_STATUS_IMPL(NAME, ...) \
  145. _Success_(return == 0) _Check_return_ _Ret_maybenull_ OrtStatusPtr ORT_API_CALL NAME(__VA_ARGS__) NO_EXCEPTION
  146. #define ORT_CLASS_RELEASE(X) void(ORT_API_CALL * Release##X)(_Frees_ptr_opt_ Ort##X * input)
  147. #ifdef __DOXYGEN__
  148. #undef ORT_API_STATUS
  149. #define ORT_API_STATUS(NAME, ...) OrtStatus* NAME(__VA_ARGS__)
  150. #undef ORT_API2_STATUS
  151. #define ORT_API2_STATUS(NAME, ...) OrtStatus* NAME(__VA_ARGS__)
  152. #undef ORT_CLASS_RELEASE
  153. #define ORT_CLASS_RELEASE(X) void Release##X(Ort##X* input)
  154. #undef NO_EXCEPTION
  155. #define NO_EXCEPTION
  156. #endif
  157. /** \addtogroup Global
  158. * ONNX Runtime C API
  159. * @{
  160. */
  161. /** Copied from TensorProto::DataType
  162. * Currently, Ort doesn't support complex64, complex128
  163. */
  164. typedef enum ONNXTensorElementDataType {
  165. ONNX_TENSOR_ELEMENT_DATA_TYPE_UNDEFINED,
  166. ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT, // maps to c type float
  167. ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8, // maps to c type uint8_t
  168. ONNX_TENSOR_ELEMENT_DATA_TYPE_INT8, // maps to c type int8_t
  169. ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT16, // maps to c type uint16_t
  170. ONNX_TENSOR_ELEMENT_DATA_TYPE_INT16, // maps to c type int16_t
  171. ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32, // maps to c type int32_t
  172. ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64, // maps to c type int64_t
  173. ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING, // maps to c++ type std::string
  174. ONNX_TENSOR_ELEMENT_DATA_TYPE_BOOL,
  175. ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16,
  176. ONNX_TENSOR_ELEMENT_DATA_TYPE_DOUBLE, // maps to c type double
  177. ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT32, // maps to c type uint32_t
  178. ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT64, // maps to c type uint64_t
  179. ONNX_TENSOR_ELEMENT_DATA_TYPE_COMPLEX64, // complex with float32 real and imaginary components
  180. ONNX_TENSOR_ELEMENT_DATA_TYPE_COMPLEX128, // complex with float64 real and imaginary components
  181. ONNX_TENSOR_ELEMENT_DATA_TYPE_BFLOAT16, // Non-IEEE floating-point format based on IEEE754 single-precision
  182. // float 8 types were introduced in onnx 1.14, see https://onnx.ai/onnx/technical/float8.html
  183. ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT8E4M3FN, // Non-IEEE floating-point format based on IEEE754 single-precision
  184. ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT8E4M3FNUZ, // Non-IEEE floating-point format based on IEEE754 single-precision
  185. ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT8E5M2, // Non-IEEE floating-point format based on IEEE754 single-precision
  186. ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT8E5M2FNUZ, // Non-IEEE floating-point format based on IEEE754 single-precision
  187. // Int4 types were introduced in ONNX 1.16. See https://onnx.ai/onnx/technical/int4.html
  188. ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT4, // maps to a pair of packed uint4 values (size == 1 byte)
  189. ONNX_TENSOR_ELEMENT_DATA_TYPE_INT4 // maps to a pair of packed int4 values (size == 1 byte)
  190. } ONNXTensorElementDataType;
  191. // Synced with onnx TypeProto oneof
  192. typedef enum ONNXType {
  193. ONNX_TYPE_UNKNOWN,
  194. ONNX_TYPE_TENSOR,
  195. ONNX_TYPE_SEQUENCE,
  196. ONNX_TYPE_MAP,
  197. ONNX_TYPE_OPAQUE,
  198. ONNX_TYPE_SPARSETENSOR,
  199. ONNX_TYPE_OPTIONAL
  200. } ONNXType;
  201. // These types are synced with internal
  202. // SparseFormatFlags
  203. typedef enum OrtSparseFormat {
  204. ORT_SPARSE_UNDEFINED = 0,
  205. ORT_SPARSE_COO = 0x1,
  206. ORT_SPARSE_CSRC = 0x2,
  207. ORT_SPARSE_BLOCK_SPARSE = 0x4
  208. } OrtSparseFormat;
  209. // Enum allows to query sparse tensor indices
  210. enum OrtSparseIndicesFormat {
  211. ORT_SPARSE_COO_INDICES,
  212. ORT_SPARSE_CSR_INNER_INDICES,
  213. ORT_SPARSE_CSR_OUTER_INDICES,
  214. ORT_SPARSE_BLOCK_SPARSE_INDICES
  215. };
  216. /** \brief Logging severity levels
  217. *
  218. * In typical API usage, specifying a logging severity level specifies the minimum severity of log messages to show.
  219. */
  220. typedef enum OrtLoggingLevel {
  221. ORT_LOGGING_LEVEL_VERBOSE, ///< Verbose informational messages (least severe).
  222. ORT_LOGGING_LEVEL_INFO, ///< Informational messages.
  223. ORT_LOGGING_LEVEL_WARNING, ///< Warning messages.
  224. ORT_LOGGING_LEVEL_ERROR, ///< Error messages.
  225. ORT_LOGGING_LEVEL_FATAL, ///< Fatal error messages (most severe).
  226. } OrtLoggingLevel;
  227. typedef enum OrtErrorCode {
  228. ORT_OK,
  229. ORT_FAIL,
  230. ORT_INVALID_ARGUMENT,
  231. ORT_NO_SUCHFILE,
  232. ORT_NO_MODEL,
  233. ORT_ENGINE_ERROR,
  234. ORT_RUNTIME_EXCEPTION,
  235. ORT_INVALID_PROTOBUF,
  236. ORT_MODEL_LOADED,
  237. ORT_NOT_IMPLEMENTED,
  238. ORT_INVALID_GRAPH,
  239. ORT_EP_FAIL,
  240. ORT_MODEL_LOAD_CANCELED,
  241. ORT_MODEL_REQUIRES_COMPILATION,
  242. ORT_NOT_FOUND,
  243. } OrtErrorCode;
  244. typedef enum OrtOpAttrType {
  245. ORT_OP_ATTR_UNDEFINED = 0,
  246. ORT_OP_ATTR_INT,
  247. ORT_OP_ATTR_INTS,
  248. ORT_OP_ATTR_FLOAT,
  249. ORT_OP_ATTR_FLOATS,
  250. ORT_OP_ATTR_STRING,
  251. ORT_OP_ATTR_STRINGS,
  252. ORT_OP_ATTR_GRAPH,
  253. ORT_OP_ATTR_TENSOR,
  254. } OrtOpAttrType;
  255. //! @}
  256. #define ORT_RUNTIME_CLASS(X) \
  257. struct Ort##X; \
  258. typedef struct Ort##X Ort##X
  259. /** \addtogroup Global
  260. * ONNX Runtime C API
  261. * @{
  262. */
  263. // The actual types defined have an Ort prefix
  264. ORT_RUNTIME_CLASS(Env);
  265. ORT_RUNTIME_CLASS(Status); // nullptr for Status* indicates success
  266. ORT_RUNTIME_CLASS(MemoryInfo);
  267. ORT_RUNTIME_CLASS(IoBinding);
  268. ORT_RUNTIME_CLASS(Session); // Don't call ReleaseSession from Dllmain (because session owns a thread pool)
  269. ORT_RUNTIME_CLASS(Value);
  270. ORT_RUNTIME_CLASS(RunOptions);
  271. ORT_RUNTIME_CLASS(TypeInfo);
  272. ORT_RUNTIME_CLASS(TensorTypeAndShapeInfo);
  273. ORT_RUNTIME_CLASS(MapTypeInfo);
  274. ORT_RUNTIME_CLASS(SequenceTypeInfo);
  275. ORT_RUNTIME_CLASS(OptionalTypeInfo);
  276. ORT_RUNTIME_CLASS(SessionOptions);
  277. ORT_RUNTIME_CLASS(CustomOpDomain);
  278. ORT_RUNTIME_CLASS(ModelMetadata);
  279. ORT_RUNTIME_CLASS(ThreadPoolParams);
  280. ORT_RUNTIME_CLASS(ThreadingOptions);
  281. ORT_RUNTIME_CLASS(ArenaCfg);
  282. ORT_RUNTIME_CLASS(PrepackedWeightsContainer);
  283. ORT_RUNTIME_CLASS(TensorRTProviderOptionsV2);
  284. ORT_RUNTIME_CLASS(NvTensorRtRtxProviderOptions);
  285. ORT_RUNTIME_CLASS(CUDAProviderOptionsV2);
  286. ORT_RUNTIME_CLASS(CANNProviderOptions);
  287. ORT_RUNTIME_CLASS(DnnlProviderOptions);
  288. ORT_RUNTIME_CLASS(Op);
  289. ORT_RUNTIME_CLASS(OpAttr);
  290. ORT_RUNTIME_CLASS(Logger);
  291. ORT_RUNTIME_CLASS(ShapeInferContext);
  292. ORT_RUNTIME_CLASS(LoraAdapter);
  293. ORT_RUNTIME_CLASS(ValueInfo);
  294. ORT_RUNTIME_CLASS(Node);
  295. ORT_RUNTIME_CLASS(Graph);
  296. ORT_RUNTIME_CLASS(Model);
  297. ORT_RUNTIME_CLASS(ModelCompilationOptions);
  298. ORT_RUNTIME_CLASS(HardwareDevice);
  299. ORT_RUNTIME_CLASS(EpDevice);
  300. ORT_RUNTIME_CLASS(KeyValuePairs);
  301. ORT_RUNTIME_CLASS(SyncStream); // Opaque class to create an onnxruntime::Stream.
  302. ORT_RUNTIME_CLASS(ExternalInitializerInfo);
  303. #ifdef _MSC_VER
  304. typedef _Return_type_success_(return == 0) OrtStatus* OrtStatusPtr;
  305. #else
  306. typedef OrtStatus* OrtStatusPtr;
  307. #endif
  308. /** \brief Memory allocation interface
  309. *
  310. * Structure of function pointers that defines a memory allocator. This can be created and filled in by the user for custom allocators.
  311. *
  312. * When an allocator is passed to any function, be sure that the allocator object is not destroyed until the last allocated object using it is freed.
  313. */
  314. typedef struct OrtAllocator {
  315. uint32_t version; ///< Must be initialized to ORT_API_VERSION
  316. /// Returns a pointer to an allocated block of `size` bytes
  317. void*(ORT_API_CALL* Alloc)(struct OrtAllocator* this_, size_t size);
  318. /// Free a block of memory previously allocated with OrtAllocator::Alloc
  319. void(ORT_API_CALL* Free)(struct OrtAllocator* this_, void* p);
  320. /// Return a pointer to an ::OrtMemoryInfo that describes this allocator
  321. const struct OrtMemoryInfo*(ORT_API_CALL* Info)(const struct OrtAllocator* this_);
  322. /**
  323. * @brief Optional allocation function to use for memory allocations made during session initialization.
  324. * Use this function if you want to separate allocations made by ORT during Run() calls from
  325. * those made during session initialization. This allows for separate memory management strategies for these
  326. * allocations.
  327. *
  328. * \return pointer to an allocated block of `size` bytes. nullptr if size was 0 or allocation failed.
  329. *
  330. * \since 1.18
  331. */
  332. void*(ORT_API_CALL* Reserve)(struct OrtAllocator* this_, size_t size);
  333. /**
  334. * @brief Function used to get the statistics of the allocator.
  335. *
  336. * Return a pointer to the OrtKeyValuePairs structure that contains the statistics of the allocator.
  337. * The user should call OrtApi::ReleaseKeyValuePairs when done.
  338. *
  339. * Current known keys are:
  340. * - Limit: Bytes limit of the allocator. -1 if no limit is set.
  341. * - InUse: Number of bytes in use.
  342. * - TotalAllocated: The total number of allocated bytes by the allocator.
  343. * - MaxInUse: The maximum bytes in use.
  344. * - NumAllocs: Number of allocations.
  345. * - NumReserves: Number of reserves. (Number of calls to Reserve() in arena-based allocators)
  346. * - NumArenaExtensions: Number of arena extensions (Relevant only for arena based allocators)
  347. * - NumArenaShrinkages: Number of arena shrinkages (Relevant only for arena based allocators)
  348. * - MaxAllocSize: The max single allocation seen.
  349. *
  350. * The allocator is free to add other entries as appropriate.
  351. *
  352. * \note Implementation of this function is optional and GetStats may be set to a nullptr.
  353. * If the OrtAllocator is wrapping an internal ORT allocator that does not implement GetStats
  354. * the returned OrtKeyValuePairs instance will be empty.
  355. *
  356. * \since 1.23
  357. */
  358. ORT_API2_STATUS(GetStats, _In_ const struct OrtAllocator* this_, _Outptr_ OrtKeyValuePairs** out);
  359. /** \brief Allocate using a stream.
  360. *
  361. * If the allocator is stream aware this performs allocation using a stream.
  362. *
  363. * Alloc will be used if this is nullptr.
  364. *
  365. * \param[in] this_ OrtAllocator instance
  366. * \param[in] size Size of the allocation in bytes. nullptr if size was 0 or allocation failed.
  367. * \param[in] stream The stream to allocate on.
  368. *
  369. * \return pointer to an allocated block of `size` bytes
  370. *
  371. * \note Implementation of this function is optional and AllocOnStream may be set to a nullptr.
  372. * \since 1.23
  373. */
  374. void*(ORT_API_CALL* AllocOnStream)(struct OrtAllocator* this_, size_t size, OrtSyncStream* stream);
  375. } OrtAllocator;
  376. typedef void(ORT_API_CALL* OrtLoggingFunction)(
  377. void* param, OrtLoggingLevel severity, const char* category, const char* logid, const char* code_location,
  378. const char* message);
  379. /** \brief Graph optimization level
  380. *
  381. * Refer to https://www.onnxruntime.ai/docs/performance/graph-optimizations.html#graph-optimization-levels
  382. * for an in-depth understanding of the Graph Optimization Levels.
  383. */
  384. typedef enum GraphOptimizationLevel {
  385. ORT_DISABLE_ALL = 0,
  386. ORT_ENABLE_BASIC = 1,
  387. ORT_ENABLE_EXTENDED = 2,
  388. ORT_ENABLE_LAYOUT = 3,
  389. ORT_ENABLE_ALL = 99
  390. } GraphOptimizationLevel;
  391. typedef enum ExecutionMode {
  392. ORT_SEQUENTIAL = 0,
  393. ORT_PARALLEL = 1,
  394. } ExecutionMode;
  395. /** \brief Language projection identifiers
  396. * /see OrtApi::SetLanguageProjection
  397. */
  398. typedef enum OrtLanguageProjection {
  399. ORT_PROJECTION_C = 0,
  400. ORT_PROJECTION_CPLUSPLUS = 1,
  401. ORT_PROJECTION_CSHARP = 2,
  402. ORT_PROJECTION_PYTHON = 3,
  403. ORT_PROJECTION_JAVA = 4,
  404. ORT_PROJECTION_WINML = 5,
  405. ORT_PROJECTION_NODEJS = 6,
  406. } OrtLanguageProjection;
  407. struct OrtKernelInfo;
  408. typedef struct OrtKernelInfo OrtKernelInfo;
  409. struct OrtKernelContext;
  410. typedef struct OrtKernelContext OrtKernelContext;
  411. struct OrtCustomOp;
  412. typedef struct OrtCustomOp OrtCustomOp;
  413. typedef enum OrtAllocatorType {
  414. OrtInvalidAllocator = -1,
  415. OrtDeviceAllocator = 0,
  416. OrtArenaAllocator = 1,
  417. OrtReadOnlyAllocator = 2,
  418. } OrtAllocatorType;
  419. /** \brief Memory types for allocated memory, execution provider specific types should be extended in each provider.
  420. */
  421. // Whenever this struct is updated, please also update the MakeKey function in onnxruntime / core / framework / execution_provider.cc
  422. typedef enum OrtMemType {
  423. /// Any CPU memory used by non-CPU execution provider
  424. OrtMemTypeCPUInput = -2,
  425. /// CPU accessible memory outputted by non-CPU execution provider, i.e. HOST_ACCESSIBLE
  426. OrtMemTypeCPUOutput = -1,
  427. /// CPU accessible memory allocated by non-CPU execution provider, i.e. HOST_ACCESSIBLE
  428. OrtMemTypeCPU = OrtMemTypeCPUOutput,
  429. /// The default allocator for execution provider
  430. OrtMemTypeDefault = 0,
  431. } OrtMemType;
  432. /** \brief This matches OrtDevice::MemoryType values */
  433. typedef enum OrtDeviceMemoryType {
  434. OrtDeviceMemoryType_DEFAULT = 0, ///< Device memory
  435. OrtDeviceMemoryType_HOST_ACCESSIBLE = 5, ///< Shared/pinned memory for transferring between CPU and the device
  436. } OrtDeviceMemoryType;
  437. /** \brief This mimics OrtDevice type constants so they can be returned in the API
  438. */
  439. typedef enum OrtMemoryInfoDeviceType {
  440. OrtMemoryInfoDeviceType_CPU = 0,
  441. OrtMemoryInfoDeviceType_GPU = 1,
  442. OrtMemoryInfoDeviceType_FPGA = 2,
  443. OrtMemoryInfoDeviceType_NPU = 3,
  444. } OrtMemoryInfoDeviceType;
  445. typedef enum OrtHardwareDeviceType {
  446. OrtHardwareDeviceType_CPU,
  447. OrtHardwareDeviceType_GPU,
  448. OrtHardwareDeviceType_NPU
  449. } OrtHardwareDeviceType;
  450. /** \brief These are the default EP selection policies used by ORT when doing automatic EP selection.
  451. */
  452. typedef enum OrtExecutionProviderDevicePolicy {
  453. OrtExecutionProviderDevicePolicy_DEFAULT,
  454. OrtExecutionProviderDevicePolicy_PREFER_CPU,
  455. OrtExecutionProviderDevicePolicy_PREFER_NPU,
  456. OrtExecutionProviderDevicePolicy_PREFER_GPU,
  457. OrtExecutionProviderDevicePolicy_MAX_PERFORMANCE,
  458. OrtExecutionProviderDevicePolicy_MAX_EFFICIENCY,
  459. OrtExecutionProviderDevicePolicy_MIN_OVERALL_POWER,
  460. } OrtExecutionProviderDevicePolicy;
  461. /** \brief Delegate to allow providing custom OrtEpDevice selection logic
  462. *
  463. * This delegate is called by the EP selection code to allow the user to provide custom device selection logic.
  464. * The user can use this to select OrtEpDevice instances from the list of available devices.
  465. *
  466. * \param ep_devices The list of available devices.
  467. * \param num_devices The number of available devices.
  468. * \param model_metadata The model metadata.
  469. * \param runtime_metadata The runtime metadata. May be nullptr.
  470. * \param selected Pre-allocated array to populate with selected OrtEpDevice pointers from ep_devices.
  471. * \param max_selected The maximum number of devices that can be selected in the pre-allocated array.
  472. Currently the maximum is 8.
  473. * \param num_selected The number of selected devices.
  474. * \param state Opaque pointer. Required to use the delegate from other languages like C# and python.
  475. *
  476. * \return OrtStatus* Selection status. Return nullptr on success.
  477. * Use CreateStatus to provide error info. Use ORT_FAIL as the error code.
  478. * ORT will release the OrtStatus* if not null.
  479. */
  480. typedef OrtStatus*(ORT_API_CALL* EpSelectionDelegate)(_In_ const OrtEpDevice** ep_devices,
  481. _In_ size_t num_devices,
  482. _In_ const OrtKeyValuePairs* model_metadata,
  483. _In_opt_ const OrtKeyValuePairs* runtime_metadata,
  484. _Inout_ const OrtEpDevice** selected,
  485. _In_ size_t max_selected,
  486. _Out_ size_t* num_selected,
  487. _In_ void* state);
  488. /** \brief Function called by ORT to write a buffer to a custom destination (e.g., file, stream, etc.).
  489. *
  490. * \param state Opaque pointer holding the user's state.
  491. * \param buffer The buffer to write.
  492. * \param buffer_num_bytes The size of the buffer in bytes.
  493. *
  494. * \return OrtStatus* Write status. Return nullptr on success.
  495. * Use CreateStatus to provide error info. Use ORT_FAIL as the error code.
  496. * ORT will release the OrtStatus* if not null.
  497. */
  498. typedef OrtStatus*(ORT_API_CALL* OrtWriteBufferFunc)(_In_ void* state,
  499. _In_ const void* buffer,
  500. _In_ size_t buffer_num_bytes);
  501. /** \brief Function called by ORT to allow user to specify how an initializer should be saved, that is, either
  502. * written to an external file or stored within the model. ORT calls this function for every initializer when
  503. * generating a model.
  504. *
  505. * If the function implementation sets the `new_external_info` output parameter to NULL, ORT stores the initializer data
  506. * within the generated model.
  507. *
  508. * Otherwise, if the function implementation sets `new_external_info` to a valid OrtExternalInitializerInfo instance,
  509. * ORT assumes that this function stores the initializer data in a file. In this case, ORT configures the model's
  510. * initializer to point to the location specified by the `new_external_info` output parameter.
  511. *
  512. * \param[in] state Opaque pointer holding the user's state.
  513. * \param[in] initializer_name The initializer's name as a null-terminated string.
  514. * \param[in] initializer_value OrtValue containing the initializer's data, type, and shape.
  515. * \param[in] external_info If the initializer is originally stored in an external file, `external_info` contains
  516. * the file path, file offset, and the data's byte size within the file. Otherwise,
  517. * `external_info` is NULL if the initializer is not originally stored in a file.
  518. * \param[out] new_external_info Output parameter set to a new OrtExternalInitializerInfo instance indicating the
  519. * location where the function implementation stored the initializer data.
  520. * The function implementation must use `OrtApi::CreateExternalInitializerInfo()` to
  521. * create the instance.
  522. * If the function implementation sets `new_external_info` to NULL,
  523. * ORT stores the initializers within the model.
  524. *
  525. * \note ORT takes ownership of the `new_external_info` output parameter.
  526. *
  527. * \return OrtStatus* Write status. Return nullptr on success.
  528. * Use CreateStatus to provide error info. Use ORT_FAIL as the error code.
  529. * ORT will release the OrtStatus* if not null.
  530. */
  531. typedef OrtStatus*(ORT_API_CALL* OrtGetInitializerLocationFunc)(
  532. _In_ void* state,
  533. _In_ const char* initializer_name,
  534. _In_ const OrtValue* initializer_value,
  535. _In_opt_ const OrtExternalInitializerInfo* external_info,
  536. _Outptr_result_maybenull_ OrtExternalInitializerInfo** new_external_info);
  537. /** \brief Algorithm to use for cuDNN Convolution Op
  538. */
  539. typedef enum OrtCudnnConvAlgoSearch {
  540. OrtCudnnConvAlgoSearchExhaustive, // expensive exhaustive benchmarking using cudnnFindConvolutionForwardAlgorithmEx
  541. OrtCudnnConvAlgoSearchHeuristic, // lightweight heuristic based search using cudnnGetConvolutionForwardAlgorithm_v7
  542. OrtCudnnConvAlgoSearchDefault, // default algorithm using CUDNN_CONVOLUTION_FWD_ALGO_IMPLICIT_PRECOMP_GEMM
  543. } OrtCudnnConvAlgoSearch;
  544. /** \brief CUDA Provider Options
  545. *
  546. * \see OrtApi::SessionOptionsAppendExecutionProvider_CUDA
  547. */
  548. typedef struct OrtCUDAProviderOptions {
  549. #ifdef __cplusplus
  550. OrtCUDAProviderOptions()
  551. : device_id{},
  552. cudnn_conv_algo_search{OrtCudnnConvAlgoSearchExhaustive},
  553. gpu_mem_limit{SIZE_MAX},
  554. arena_extend_strategy{},
  555. do_copy_in_default_stream{1},
  556. has_user_compute_stream{},
  557. user_compute_stream{},
  558. default_memory_arena_cfg{},
  559. tunable_op_enable{false},
  560. tunable_op_tuning_enable{false},
  561. tunable_op_max_tuning_duration_ms{} {}
  562. #endif
  563. /** \brief CUDA device Id
  564. * Defaults to 0.
  565. */
  566. int device_id;
  567. /** \brief CUDA Convolution algorithm search configuration.
  568. * See enum OrtCudnnConvAlgoSearch for more details.
  569. * Defaults to OrtCudnnConvAlgoSearchExhaustive.
  570. */
  571. OrtCudnnConvAlgoSearch cudnn_conv_algo_search;
  572. /** \brief CUDA memory limit (To use all possible memory pass in maximum size_t)
  573. * Defaults to SIZE_MAX.
  574. * \note If a ::OrtArenaCfg has been applied, it will override this field
  575. */
  576. size_t gpu_mem_limit;
  577. /** \brief Strategy used to grow the memory arena
  578. * 0 = kNextPowerOfTwo<br>
  579. * 1 = kSameAsRequested<br>
  580. * Defaults to 0.
  581. * \note If a ::OrtArenaCfg has been applied, it will override this field
  582. */
  583. int arena_extend_strategy;
  584. /** \brief Flag indicating if copying needs to take place on the same stream as the compute stream in the CUDA EP
  585. * 0 = Use separate streams for copying and compute.
  586. * 1 = Use the same stream for copying and compute.
  587. * Defaults to 1.
  588. * WARNING: Setting this to 0 may result in data races for some models.
  589. * Please see issue #4829 for more details.
  590. */
  591. int do_copy_in_default_stream;
  592. /** \brief Flag indicating if there is a user provided compute stream
  593. * Defaults to 0.
  594. */
  595. int has_user_compute_stream;
  596. /** \brief User provided compute stream.
  597. * If provided, please set `has_user_compute_stream` to 1.
  598. */
  599. void* user_compute_stream;
  600. /** \brief CUDA memory arena configuration parameters
  601. */
  602. OrtArenaCfg* default_memory_arena_cfg;
  603. /** \brief Enable TunableOp for using.
  604. * Set it to 1/0 to enable/disable TunableOp. Otherwise, it is disabled by default.
  605. * This option can be overridden by environment variable ORT_CUDA_TUNABLE_OP_ENABLE.
  606. */
  607. int tunable_op_enable;
  608. /** \brief Enable TunableOp for tuning.
  609. * Set it to 1/0 to enable/disable TunableOp tuning. Otherwise, it is disabled by default.
  610. * This option can be overridden by environment variable ORT_CUDA_TUNABLE_OP_TUNING_ENABLE.
  611. */
  612. int tunable_op_tuning_enable;
  613. /** \brief Max tuning duration time limit for each instance of TunableOp.
  614. * Defaults to 0 to disable the limit.
  615. */
  616. int tunable_op_max_tuning_duration_ms;
  617. } OrtCUDAProviderOptions;
  618. /** \brief ROCM Provider Options
  619. *
  620. * \see OrtApi::SessionOptionsAppendExecutionProvider_ROCM
  621. */
  622. typedef struct OrtROCMProviderOptions {
  623. #ifdef __cplusplus
  624. OrtROCMProviderOptions()
  625. : device_id{},
  626. miopen_conv_exhaustive_search{0},
  627. gpu_mem_limit{SIZE_MAX},
  628. arena_extend_strategy{},
  629. do_copy_in_default_stream{1},
  630. has_user_compute_stream{},
  631. user_compute_stream{},
  632. default_memory_arena_cfg{},
  633. enable_hip_graph{false},
  634. tunable_op_enable{false},
  635. tunable_op_tuning_enable{false},
  636. tunable_op_max_tuning_duration_ms{} {}
  637. #endif
  638. /** \brief ROCM device Id
  639. * Defaults to 0.
  640. */
  641. int device_id;
  642. /** \brief ROCM MIOpen Convolution algorithm exhaustive search option.
  643. * Defaults to 0 (false).
  644. */
  645. int miopen_conv_exhaustive_search;
  646. /** \brief ROCM memory limit (To use all possible memory pass in maximum size_t)
  647. * Defaults to SIZE_MAX.
  648. * \note If a ::OrtArenaCfg has been applied, it will override this field
  649. */
  650. size_t gpu_mem_limit;
  651. /** \brief Strategy used to grow the memory arena
  652. * 0 = kNextPowerOfTwo<br>
  653. * 1 = kSameAsRequested<br>
  654. * Defaults to 0.
  655. * \note If a ::OrtArenaCfg has been applied, it will override this field
  656. */
  657. int arena_extend_strategy;
  658. /** \brief Flag indicating if copying needs to take place on the same stream as the compute stream in the ROCM EP
  659. * 0 = Use separate streams for copying and compute.
  660. * 1 = Use the same stream for copying and compute.
  661. * Defaults to 1.
  662. * WARNING: Setting this to 0 may result in data races for some models.
  663. * Please see issue #4829 for more details.
  664. */
  665. int do_copy_in_default_stream;
  666. /** \brief Flag indicating if there is a user provided compute stream
  667. * Defaults to 0.
  668. */
  669. int has_user_compute_stream;
  670. /** \brief User provided compute stream.
  671. * If provided, please set `has_user_compute_stream` to 1.
  672. */
  673. void* user_compute_stream;
  674. /** \brief ROCM memory arena configuration parameters
  675. */
  676. OrtArenaCfg* default_memory_arena_cfg;
  677. int enable_hip_graph;
  678. /** \brief Enable TunableOp for using.
  679. * Set it to 1/0 to enable/disable TunableOp. Otherwise, it is disabled by default.
  680. * This option can be overridden by environment variable ORT_ROCM_TUNABLE_OP_ENABLE.
  681. */
  682. int tunable_op_enable;
  683. /** \brief Enable TunableOp for tuning.
  684. * Set it to 1/0 to enable/disable TunableOp tuning. Otherwise, it is disabled by default.
  685. * This option can be overridden by environment variable ORT_ROCM_TUNABLE_OP_TUNING_ENABLE.
  686. */
  687. int tunable_op_tuning_enable;
  688. /** \brief Max tuning duration time limit for each instance of TunableOp.
  689. * Defaults to 0 to disable the limit.
  690. */
  691. int tunable_op_max_tuning_duration_ms;
  692. } OrtROCMProviderOptions;
  693. /** \brief TensorRT Provider Options
  694. *
  695. * \see OrtApi::SessionOptionsAppendExecutionProvider_TensorRT
  696. */
  697. typedef struct OrtTensorRTProviderOptions {
  698. int device_id; ///< CUDA device id (0 = default device)
  699. int has_user_compute_stream; // indicator of user specified CUDA compute stream.
  700. void* user_compute_stream; // user specified CUDA compute stream.
  701. int trt_max_partition_iterations; // maximum iterations for TensorRT parser to get capability
  702. int trt_min_subgraph_size; // minimum size of TensorRT subgraphs
  703. size_t trt_max_workspace_size; // maximum workspace size for TensorRT.
  704. int trt_fp16_enable; // enable TensorRT FP16 precision. Default 0 = false, nonzero = true
  705. int trt_int8_enable; // enable TensorRT INT8 precision. Default 0 = false, nonzero = true
  706. const char* trt_int8_calibration_table_name; // TensorRT INT8 calibration table name.
  707. int trt_int8_use_native_calibration_table; // use native TensorRT generated calibration table. Default 0 = false, nonzero = true
  708. int trt_dla_enable; // enable DLA. Default 0 = false, nonzero = true
  709. int trt_dla_core; // DLA core number. Default 0
  710. int trt_dump_subgraphs; // dump TRT subgraph. Default 0 = false, nonzero = true
  711. int trt_engine_cache_enable; // enable engine caching. Default 0 = false, nonzero = true
  712. const char* trt_engine_cache_path; // specify engine cache path
  713. int trt_engine_decryption_enable; // enable engine decryption. Default 0 = false, nonzero = true
  714. const char* trt_engine_decryption_lib_path; // specify engine decryption library path
  715. int trt_force_sequential_engine_build; // force building TensorRT engine sequentially. Default 0 = false, nonzero = true
  716. // This is the legacy struct and don't add new fields here.
  717. // For new field that can be represented by string, please add it in include/onnxruntime/core/providers/tensorrt/tensorrt_provider_options.h
  718. // For non-string field, need to create a new separate api to handle it.
  719. } OrtTensorRTProviderOptions;
  720. /** \brief MIGraphX Provider Options
  721. *
  722. * \see OrtApi::SessionOptionsAppendExecutionProvider_MIGraphX
  723. */
  724. typedef struct OrtMIGraphXProviderOptions {
  725. int device_id; // hip device id.
  726. int migraphx_fp16_enable; // MIGraphX FP16 precision. Default 0 = false, nonzero = true
  727. int migraphx_fp8_enable; // MIGraphX FP8 precision. Default 0 = false, nonzero = true
  728. int migraphx_int8_enable; // MIGraphX INT8 precision. Default 0 = false, nonzero = true
  729. int migraphx_use_native_calibration_table; // MIGraphx INT8 cal table. Default 0 = false, nonzero = true
  730. const char* migraphx_int8_calibration_table_name; // MIGraphx INT8 calibration table name
  731. int migraphx_save_compiled_model; // migraphx save compiled model. Default 0 = false, nonzero = true
  732. const char* migraphx_save_model_path; // migraphx model path name
  733. int migraphx_load_compiled_model; // migraphx int8 cal table. Default 0 = false, nonzero = true
  734. const char* migraphx_load_model_path; // migraphx model path name
  735. bool migraphx_exhaustive_tune; // MIGraphX tuned compile. Default = false, nonzero = true
  736. /** \brief MIGraphX memory limit (To use all possible memory pass in maximum size_t)
  737. * Defaults to SIZE_MAX.
  738. * \note If a ::OrtArenaCfg has been applied, it will override this field
  739. */
  740. size_t migraphx_mem_limit;
  741. /** \brief Strategy used to grow the memory arena
  742. * 0 = kNextPowerOfTwo<br>
  743. * 1 = kSameAsRequested<br>
  744. * Defaults to 0.
  745. * \note If a ::OrtArenaCfg has been applied, it will override this field
  746. */
  747. int migraphx_arena_extend_strategy;
  748. // This is the legacy struct and don't add new fields here.
  749. } OrtMIGraphXProviderOptions;
  750. /** \brief OpenVINO Provider Options
  751. * \brief This Struct is frozen since ORT 1.13.0. Its maintained part of Legacy API for compatibility.
  752. * \brief For latest OpenVINO Provider Options update to the ProviderOptions map.
  753. * \brief Latest OpenVINO Provider Options are listed in the
  754. * \htmlonly
  755. * <a href="https://onnxruntime.ai/docs/execution-providers/OpenVINO-ExecutionProvider.html#summary-of-options">onnxruntime document.</a>
  756. * \endhtmlonly
  757. * \see OrtApi::SessionOptionsAppendExecutionProvider()
  758. */
  759. typedef struct OrtOpenVINOProviderOptions {
  760. #ifdef __cplusplus
  761. OrtOpenVINOProviderOptions() : device_type{},
  762. enable_npu_fast_compile{},
  763. device_id{},
  764. num_of_threads{},
  765. cache_dir{},
  766. context{},
  767. enable_opencl_throttling{},
  768. enable_dynamic_shapes{} {}
  769. #endif
  770. /** \brief Device type string
  771. *
  772. * Valid settings are one of: "CPU_FP32", "CPU_FP16", "GPU_FP32", "GPU_FP16"
  773. */
  774. const char* device_type;
  775. unsigned char enable_npu_fast_compile; ///< 0 = disabled, nonzero = enabled
  776. const char* device_id;
  777. size_t num_of_threads; ///< 0 = Use default number of threads
  778. const char* cache_dir; // path is set to empty by default
  779. void* context;
  780. unsigned char enable_opencl_throttling; ///< 0 = disabled, nonzero = enabled
  781. unsigned char enable_dynamic_shapes; ///< 0 = disabled, nonzero = enabled
  782. } OrtOpenVINOProviderOptions;
  783. struct OrtApi;
  784. typedef struct OrtApi OrtApi;
  785. struct OrtTrainingApi;
  786. typedef struct OrtTrainingApi OrtTrainingApi;
  787. struct OrtModelEditorApi;
  788. typedef struct OrtModelEditorApi OrtModelEditorApi;
  789. struct OrtCompileApi;
  790. typedef struct OrtCompileApi OrtCompileApi;
  791. struct OrtEpApi;
  792. typedef struct OrtEpApi OrtEpApi;
  793. /** \brief The helper interface to get the right version of OrtApi
  794. *
  795. * Get a pointer to this structure through ::OrtGetApiBase
  796. */
  797. struct OrtApiBase {
  798. /** \brief Get a pointer to the requested version of the ::OrtApi
  799. *
  800. * \param[in] version Must be ::ORT_API_VERSION
  801. * \return The ::OrtApi for the version requested, nullptr will be returned if this version is unsupported, for example when using a runtime
  802. * older than the version created with this header file.
  803. *
  804. * One can call GetVersionString() to get the version of the Onnxruntime library for logging
  805. * and error reporting purposes.
  806. */
  807. const OrtApi*(ORT_API_CALL* GetApi)(uint32_t version)NO_EXCEPTION;
  808. /** \brief Returns a null terminated string of the version of the Onnxruntime library (eg: "1.8.1")
  809. *
  810. * \return UTF-8 encoded version string. Do not deallocate the returned buffer.
  811. */
  812. const char*(ORT_API_CALL* GetVersionString)(void)NO_EXCEPTION;
  813. };
  814. typedef struct OrtApiBase OrtApiBase;
  815. /** \brief The Onnxruntime library's entry point to access the C API
  816. *
  817. * Call this to get the a pointer to an ::OrtApiBase
  818. */
  819. ORT_EXPORT const OrtApiBase* ORT_API_CALL OrtGetApiBase(void) NO_EXCEPTION;
  820. /** \brief Thread work loop function
  821. *
  822. * Onnxruntime will provide the working loop on custom thread creation
  823. * Argument is an onnxruntime built-in type which will be provided when thread pool calls OrtCustomCreateThreadFn
  824. */
  825. typedef void (*OrtThreadWorkerFn)(void* ort_worker_fn_param);
  826. typedef const struct OrtCustomHandleType {
  827. char __place_holder;
  828. }* OrtCustomThreadHandle;
  829. /** \brief Ort custom thread creation function
  830. *
  831. * The function should return a thread handle to be used in onnxruntime thread pools
  832. * Onnxruntime will throw exception on return value of nullptr or 0, indicating that the function failed to create a thread
  833. */
  834. typedef OrtCustomThreadHandle (*OrtCustomCreateThreadFn)(void* ort_custom_thread_creation_options, OrtThreadWorkerFn ort_thread_worker_fn, void* ort_worker_fn_param);
  835. /** \brief Custom thread join function
  836. *
  837. * Onnxruntime thread pool destructor will call the function to join a custom thread.
  838. * Argument ort_custom_thread_handle is the value returned by OrtCustomCreateThreadFn
  839. */
  840. typedef void (*OrtCustomJoinThreadFn)(OrtCustomThreadHandle ort_custom_thread_handle);
  841. typedef OrtStatus*(ORT_API_CALL* RegisterCustomOpsFn)(OrtSessionOptions* options, const OrtApiBase* api);
  842. /** \brief Callback function for RunAsync
  843. *
  844. * \param[in] user_data User specific data that passed back to the callback
  845. * \param[out] outputs On succeed, outputs host inference results, on error, the value will be nullptr
  846. * \param[out] num_outputs Number of outputs, on error, the value will be zero
  847. * \param[out] status On error, status will provide details
  848. */
  849. typedef void (*RunAsyncCallbackFn)(void* user_data, OrtValue** outputs, size_t num_outputs, OrtStatusPtr status);
  850. /** \brief The C API
  851. *
  852. * All C API functions are defined inside this structure as pointers to functions.
  853. * Call OrtApiBase::GetApi to get a pointer to it
  854. *
  855. * \nosubgrouping
  856. */
  857. /*
  858. * Public enum for compiled model compatibility across EPs.
  859. */
  860. typedef enum OrtCompiledModelCompatibility {
  861. OrtCompiledModelCompatibility_EP_NOT_APPLICABLE = 0,
  862. OrtCompiledModelCompatibility_EP_SUPPORTED_OPTIMAL,
  863. OrtCompiledModelCompatibility_EP_SUPPORTED_PREFER_RECOMPILATION,
  864. OrtCompiledModelCompatibility_EP_UNSUPPORTED,
  865. } OrtCompiledModelCompatibility;
  866. struct OrtApi {
  867. /// \name OrtStatus
  868. /// @{
  869. /**
  870. * \brief Create an OrtStatus from a null terminated string
  871. *
  872. * \param[in] code
  873. * \param[in] msg A null-terminated string. Its contents will be copied.
  874. * \return A new OrtStatus object, must be destroyed with OrtApi::ReleaseStatus
  875. */
  876. OrtStatus*(ORT_API_CALL* CreateStatus)(OrtErrorCode code, _In_ const char* msg)NO_EXCEPTION ORT_ALL_ARGS_NONNULL;
  877. /** \brief Get OrtErrorCode from OrtStatus
  878. *
  879. * \param[in] status
  880. * \return OrtErrorCode that \p status was created with
  881. */
  882. OrtErrorCode(ORT_API_CALL* GetErrorCode)(_In_ const OrtStatus* status) NO_EXCEPTION ORT_ALL_ARGS_NONNULL;
  883. /** \brief Get error string from OrtStatus
  884. *
  885. * \param[in] status
  886. * \return The error message inside the `status`. Do not free the returned value.
  887. */
  888. const char*(ORT_API_CALL* GetErrorMessage)(_In_ const OrtStatus* status)NO_EXCEPTION ORT_ALL_ARGS_NONNULL;
  889. /// @}
  890. /// \name OrtEnv
  891. /// @{
  892. /** \brief Create an OrtEnv
  893. *
  894. * \note Invoking this function will return the same instance of the environment as that returned by a previous call
  895. * to another env creation function; all arguments to this function will be ignored.
  896. * \param[in] log_severity_level The log severity level.
  897. * \param[in] logid The log identifier.
  898. * \param[out] out Returned newly created OrtEnv. Must be freed with OrtApi::ReleaseEnv
  899. *
  900. * \snippet{doc} snippets.dox OrtStatus Return Value
  901. */
  902. ORT_API2_STATUS(CreateEnv, OrtLoggingLevel log_severity_level, _In_ const char* logid, _Outptr_ OrtEnv** out);
  903. /** \brief Create an OrtEnv
  904. *
  905. * \note Invoking this function will return the same instance of the environment as that returned by a previous call
  906. * to another env creation function; all arguments to this function will be ignored. If you want to provide your
  907. * own logging function, consider setting it using the SetUserLoggingFunction API instead.
  908. * \param[in] logging_function A pointer to a logging function.
  909. * \param[in] logger_param A pointer to arbitrary data passed as the ::OrtLoggingFunction `param` parameter to
  910. * `logging_function`. This parameter is optional.
  911. * \param[in] log_severity_level The log severity level.
  912. * \param[in] logid The log identifier.
  913. * \param[out] out Returned newly created OrtEnv. Must be freed with OrtApi::ReleaseEnv
  914. *
  915. * \snippet{doc} snippets.dox OrtStatus Return Value
  916. */
  917. ORT_API2_STATUS(CreateEnvWithCustomLogger, _In_ OrtLoggingFunction logging_function, _In_opt_ void* logger_param,
  918. _In_ OrtLoggingLevel log_severity_level, _In_ const char* logid, _Outptr_ OrtEnv** out);
  919. /** \brief Enable Telemetry
  920. *
  921. * \note Telemetry events are on by default since they are lightweight
  922. * \param[in] env
  923. *
  924. * \snippet{doc} snippets.dox OrtStatus Return Value
  925. */
  926. ORT_API2_STATUS(EnableTelemetryEvents, _In_ const OrtEnv* env);
  927. /** \brief Disable Telemetry
  928. *
  929. * \see OrtApi::EnableTelemetryEvents
  930. * \param[in] env
  931. *
  932. * \snippet{doc} snippets.dox OrtStatus Return Value
  933. */
  934. ORT_API2_STATUS(DisableTelemetryEvents, _In_ const OrtEnv* env);
  935. /// @}
  936. /// \name OrtSession
  937. /// @{
  938. /** \brief Create an OrtSession from a model file
  939. *
  940. * \param[in] env
  941. * \param[in] model_path
  942. * \param[in] options
  943. * \param[out] out Returned newly created OrtSession. Must be freed with OrtApi::ReleaseSession
  944. *
  945. * \snippet{doc} snippets.dox OrtStatus Return Value
  946. */
  947. // TODO: document the path separator convention? '/' vs '\'
  948. // TODO: should specify the access characteristics of model_path. Is this read only during the
  949. // execution of CreateSession, or does the OrtSession retain a handle to the file/directory
  950. // and continue to access throughout the OrtSession lifetime?
  951. // What sort of access is needed to model_path : read or read/write?
  952. ORT_API2_STATUS(CreateSession, _In_ const OrtEnv* env, _In_ const ORTCHAR_T* model_path,
  953. _In_ const OrtSessionOptions* options, _Outptr_ OrtSession** out);
  954. /** \brief Create an OrtSession from memory
  955. *
  956. * \param[in] env
  957. * \param[in] model_data
  958. * \param[in] model_data_length
  959. * \param[in] options
  960. * \param[out] out Returned newly created OrtSession. Must be freed with OrtApi::ReleaseSession
  961. *
  962. * \snippet{doc} snippets.dox OrtStatus Return Value
  963. */
  964. ORT_API2_STATUS(CreateSessionFromArray, _In_ const OrtEnv* env,
  965. _In_ const void* model_data, size_t model_data_length,
  966. _In_ const OrtSessionOptions* options, _Outptr_ OrtSession** out);
  967. /** \brief Run the model in an ::OrtSession
  968. *
  969. * Will not return until the model run has completed. Multiple threads might be used to run the model based on
  970. * the options in the ::OrtSession and settings used when creating the ::OrtEnv
  971. *
  972. * \param[in] session
  973. * \param[in] run_options If nullptr, will use a default ::OrtRunOptions
  974. * \param[in] input_names Array of null terminated UTF8 encoded strings of the input names
  975. * \param[in] inputs Array of ::OrtValue%s of the input values
  976. * \param[in] input_len Number of elements in the input_names and inputs arrays
  977. * \param[in] output_names Array of null terminated UTF8 encoded strings of the output names
  978. * \param[in] output_names_len Number of elements in the output_names and outputs array
  979. * \param[out] outputs Array of ::OrtValue%s that the outputs are stored in. This can also be
  980. * an array of nullptr values, in this case ::OrtValue objects will be allocated and pointers
  981. * to them will be set into the `outputs` array.
  982. *
  983. * \snippet{doc} snippets.dox OrtStatus Return Value
  984. */
  985. ORT_API2_STATUS(Run, _Inout_ OrtSession* session, _In_opt_ const OrtRunOptions* run_options,
  986. _In_reads_(input_len) const char* const* input_names,
  987. _In_reads_(input_len) const OrtValue* const* inputs, size_t input_len,
  988. _In_reads_(output_names_len) const char* const* output_names, size_t output_names_len,
  989. _Inout_updates_all_(output_names_len) OrtValue** outputs);
  990. /// @}
  991. /// \name OrtSessionOptions
  992. /// @{
  993. /** \brief Create an ::OrtSessionOptions object
  994. *
  995. * To use additional providers, you must build ORT with the extra providers enabled. Then call one of these
  996. * functions to enable them in the session:<br>
  997. * OrtSessionOptionsAppendExecutionProvider_CPU<br>
  998. * OrtSessionOptionsAppendExecutionProvider_CUDA<br>
  999. * OrtSessionOptionsAppendExecutionProvider_(remaining providers...)<br>
  1000. * The order they are called indicates the preference order as well. In other words call this method
  1001. * on your most preferred execution provider first followed by the less preferred ones.
  1002. * If none are called Ort will use its internal CPU execution provider.
  1003. *
  1004. * \param[out] options The newly created OrtSessionOptions. Must be freed with OrtApi::ReleaseSessionOptions
  1005. *
  1006. * \snippet{doc} snippets.dox OrtStatus Return Value
  1007. */
  1008. ORT_API2_STATUS(CreateSessionOptions, _Outptr_ OrtSessionOptions** options);
  1009. /** \brief Set filepath to save optimized model after graph level transformations
  1010. *
  1011. * \param[in] options
  1012. * \param[in] optimized_model_filepath
  1013. *
  1014. * \snippet{doc} snippets.dox OrtStatus Return Value
  1015. */
  1016. ORT_API2_STATUS(SetOptimizedModelFilePath, _Inout_ OrtSessionOptions* options,
  1017. _In_ const ORTCHAR_T* optimized_model_filepath);
  1018. /** \brief Create a copy of an existing ::OrtSessionOptions
  1019. *
  1020. * \param[in] in_options OrtSessionOptions to copy
  1021. * \param[out] out_options Returned newly created ::OrtSessionOptions. Must be freed with OrtApi::ReleaseSessionOptions
  1022. *
  1023. * \snippet{doc} snippets.dox OrtStatus Return Value
  1024. */
  1025. ORT_API2_STATUS(CloneSessionOptions, _In_ const OrtSessionOptions* in_options,
  1026. _Outptr_ OrtSessionOptions** out_options);
  1027. /** \brief Set execution mode
  1028. *
  1029. * Controls whether you want to execute operators in your graph sequentially or in parallel. Usually when the model
  1030. * has many branches, setting this option to ExecutionMode.ORT_PARALLEL will give you better performance.
  1031. * See [docs/ONNX_Runtime_Perf_Tuning.md] for more details.
  1032. *
  1033. * \param[in] options
  1034. * \param[in] execution_mode
  1035. *
  1036. * \snippet{doc} snippets.dox OrtStatus Return Value
  1037. */
  1038. ORT_API2_STATUS(SetSessionExecutionMode, _Inout_ OrtSessionOptions* options, ExecutionMode execution_mode);
  1039. /** \brief Enable profiling for a session
  1040. *
  1041. * \param[in] options
  1042. * \param[in] profile_file_prefix
  1043. *
  1044. * \snippet{doc} snippets.dox OrtStatus Return Value
  1045. */
  1046. ORT_API2_STATUS(EnableProfiling, _Inout_ OrtSessionOptions* options, _In_ const ORTCHAR_T* profile_file_prefix);
  1047. /** \brief Disable profiling for a session
  1048. *
  1049. * \param[in] options
  1050. *
  1051. * \snippet{doc} snippets.dox OrtStatus Return Value
  1052. */
  1053. ORT_API2_STATUS(DisableProfiling, _Inout_ OrtSessionOptions* options);
  1054. /** \brief Enable the memory pattern optimization
  1055. *
  1056. * The idea is if the input shapes are the same, we could trace the internal memory allocation
  1057. * and generate a memory pattern for future request. So next time we could just do one allocation
  1058. * with a big chunk for all the internal memory allocation.
  1059. * \note Memory pattern optimization is only available when Sequential Execution mode is enabled (see OrtApi::SetSessionExecutionMode)
  1060. *
  1061. * \see OrtApi::DisableMemPattern
  1062. *
  1063. * \param[in] options
  1064. *
  1065. * \snippet{doc} snippets.dox OrtStatus Return Value
  1066. */
  1067. ORT_API2_STATUS(EnableMemPattern, _Inout_ OrtSessionOptions* options);
  1068. /** \brief Disable the memory pattern optimization
  1069. *
  1070. * \see OrtApi::EnableMemPattern
  1071. *
  1072. * \param[in] options
  1073. *
  1074. * \snippet{doc} snippets.dox OrtStatus Return Value
  1075. */
  1076. ORT_API2_STATUS(DisableMemPattern, _Inout_ OrtSessionOptions* options);
  1077. /** \brief Enable the memory arena on CPU
  1078. *
  1079. * Arena may pre-allocate memory for future usage.
  1080. *
  1081. * \param[in] options
  1082. *
  1083. * \snippet{doc} snippets.dox OrtStatus Return Value
  1084. */
  1085. ORT_API2_STATUS(EnableCpuMemArena, _Inout_ OrtSessionOptions* options);
  1086. /** \brief Disable the memory arena on CPU
  1087. *
  1088. * \param[in] options
  1089. *
  1090. * \snippet{doc} snippets.dox OrtStatus Return Value
  1091. */
  1092. ORT_API2_STATUS(DisableCpuMemArena, _Inout_ OrtSessionOptions* options);
  1093. /** \brief Set session log id
  1094. *
  1095. * \param[in] options
  1096. * \param[in] logid The log identifier.
  1097. *
  1098. * \snippet{doc} snippets.dox OrtStatus Return Value
  1099. */
  1100. ORT_API2_STATUS(SetSessionLogId, _Inout_ OrtSessionOptions* options, const char* logid);
  1101. /** \brief Set session log verbosity level
  1102. *
  1103. * Applies to session load, initialization, etc
  1104. *
  1105. * \param[in] options
  1106. * \param[in] session_log_verbosity_level \snippet{doc} snippets.dox Log Verbosity Level
  1107. *
  1108. * \snippet{doc} snippets.dox OrtStatus Return Value
  1109. */
  1110. ORT_API2_STATUS(SetSessionLogVerbosityLevel, _Inout_ OrtSessionOptions* options, int session_log_verbosity_level);
  1111. /** \brief Set session log severity level
  1112. *
  1113. * \param[in] options
  1114. * \param[in] session_log_severity_level The log severity level (refer to ::OrtLoggingLevel for possible values).
  1115. *
  1116. * \snippet{doc} snippets.dox OrtStatus Return Value
  1117. */
  1118. ORT_API2_STATUS(SetSessionLogSeverityLevel, _Inout_ OrtSessionOptions* options, int session_log_severity_level);
  1119. /** \brief Set the optimization level to apply when loading a graph
  1120. *
  1121. * Please see https://onnxruntime.ai/docs/performance/model-optimizations/graph-optimizations.html for an in-depth explanation
  1122. * \param[in,out] options The session options object
  1123. * \param[in] graph_optimization_level The optimization level
  1124. *
  1125. * \snippet{doc} snippets.dox OrtStatus Return Value
  1126. */
  1127. ORT_API2_STATUS(SetSessionGraphOptimizationLevel, _Inout_ OrtSessionOptions* options,
  1128. GraphOptimizationLevel graph_optimization_level);
  1129. /** \brief Sets the number of threads used to parallelize the execution within nodes
  1130. *
  1131. * When running a single node operation, ex. add, this sets the maximum number of threads to use.
  1132. *
  1133. * \note If built with OpenMP, this has no effect on the number of threads used. In this case
  1134. * use the OpenMP env variables to configure the number of intra op num threads.
  1135. *
  1136. * \param[in] options
  1137. * \param[in] intra_op_num_threads Number of threads to use<br>
  1138. * A value of 0 will use the default number of threads<br>
  1139. *
  1140. * \snippet{doc} snippets.dox OrtStatus Return Value
  1141. */
  1142. ORT_API2_STATUS(SetIntraOpNumThreads, _Inout_ OrtSessionOptions* options, int intra_op_num_threads);
  1143. /** \brief Sets the number of threads used to parallelize the execution of the graph
  1144. *
  1145. * If nodes can be run in parallel, this sets the maximum number of threads to use to run them in parallel.
  1146. *
  1147. * \note If sequential execution is enabled this value is ignored, it acts as if it was set to 1.
  1148. *
  1149. * \param[in] options
  1150. * \param[in] inter_op_num_threads Number of threads to use<br>
  1151. * A value of 0 will use the default number of threads<br>
  1152. *
  1153. * \snippet{doc} snippets.dox OrtStatus Return Value
  1154. */
  1155. ORT_API2_STATUS(SetInterOpNumThreads, _Inout_ OrtSessionOptions* options, int inter_op_num_threads);
  1156. /// @}
  1157. /// \name OrtCustomOpDomain
  1158. /// @{
  1159. /** \brief Create a custom op domain
  1160. *
  1161. * \param[in] domain
  1162. * \param[out] out Newly created domain. Must be freed with OrtApi::ReleaseCustomOpDomain
  1163. *
  1164. * \snippet{doc} snippets.dox OrtStatus Return Value
  1165. */
  1166. ORT_API2_STATUS(CreateCustomOpDomain, _In_ const char* domain, _Outptr_ OrtCustomOpDomain** out);
  1167. /** \brief Add a custom op to a custom op domain
  1168. *
  1169. * \note The OrtCustomOp* pointer must remain valid until the ::OrtCustomOpDomain using it is released
  1170. *
  1171. * \param[in] custom_op_domain
  1172. * \param[in] op
  1173. *
  1174. * \snippet{doc} snippets.dox OrtStatus Return Value
  1175. */
  1176. ORT_API2_STATUS(CustomOpDomain_Add, _Inout_ OrtCustomOpDomain* custom_op_domain, _In_ const OrtCustomOp* op);
  1177. /// @}
  1178. /// \name OrtSessionOptions
  1179. /// @{
  1180. /** \brief Add custom op domain to a session options
  1181. *
  1182. * \note The OrtCustomOpDomain* must not be deleted until all sessions using it are released
  1183. *
  1184. * \param[in] options
  1185. * \param[in] custom_op_domain
  1186. *
  1187. * \snippet{doc} snippets.dox OrtStatus Return Value
  1188. */
  1189. ORT_API2_STATUS(AddCustomOpDomain, _Inout_ OrtSessionOptions* options, _In_ OrtCustomOpDomain* custom_op_domain);
  1190. /** \deprecated Use OrtApi::RegisterCustomOpsLibrary_V2.
  1191. *
  1192. * Registers custom ops from a shared library.
  1193. *
  1194. * Loads a shared library (dll on windows, so on linux, etc) named 'library_path' and looks for this entry point:
  1195. * OrtStatus* RegisterCustomOps(OrtSessionOptions * options, const OrtApiBase* api);
  1196. * It then passes in the provided session options to this function along with the api base.
  1197. * The handle to the loaded library is returned in library_handle. It can be freed by the caller after all sessions using the passed in
  1198. * session options are destroyed, or if an error occurs and it is non null.
  1199. *
  1200. * \param[in] options
  1201. * \param[in] library_path
  1202. * \param[out] library_handle OS specific handle to the loaded library (Use FreeLibrary on Windows, dlclose on Linux, etc.. to unload)
  1203. *
  1204. * \snippet{doc} snippets.dox OrtStatus Return Value
  1205. */
  1206. ORT_API2_STATUS(RegisterCustomOpsLibrary, _Inout_ OrtSessionOptions* options, _In_ const char* library_path, _Outptr_ void** library_handle);
  1207. /// @}
  1208. /// \name OrtSession
  1209. /// @{
  1210. /** \brief Get input count for a session
  1211. *
  1212. * This number must also match the number of inputs passed to OrtApi::Run
  1213. *
  1214. * \see OrtApi::SessionGetInputTypeInfo, OrtApi::SessionGetInputName, OrtApi::Session
  1215. *
  1216. * \param[in] session
  1217. * \param[out] out Number of inputs
  1218. *
  1219. * \snippet{doc} snippets.dox OrtStatus Return Value
  1220. */
  1221. ORT_API2_STATUS(SessionGetInputCount, _In_ const OrtSession* session, _Out_ size_t* out);
  1222. /** \brief Get output count for a session
  1223. *
  1224. * This number must also match the number of outputs returned by OrtApi::Run
  1225. *
  1226. * \see OrtApi::SessionGetOutputTypeInfo, OrtApi::SessionGetOutputName, OrtApi::Session
  1227. *
  1228. * \param[in] session
  1229. * \param[out] out Number of outputs
  1230. *
  1231. * \snippet{doc} snippets.dox OrtStatus Return Value
  1232. */
  1233. ORT_API2_STATUS(SessionGetOutputCount, _In_ const OrtSession* session, _Out_ size_t* out);
  1234. /** \brief Get overridable initializer count
  1235. *
  1236. * \see OrtApi::SessionGetOverridableInitializerTypeInfo, OrtApi::SessionGetOverridableInitializerName
  1237. *
  1238. * \param[in] session
  1239. * \param[in] out
  1240. *
  1241. * \snippet{doc} snippets.dox OrtStatus Return Value
  1242. */
  1243. ORT_API2_STATUS(SessionGetOverridableInitializerCount, _In_ const OrtSession* session, _Out_ size_t* out);
  1244. /** \brief Get input type information
  1245. *
  1246. * \param[in] session
  1247. * \param[in] index Must be between 0 (inclusive) and what OrtApi::SessionGetInputCount returns (exclusive)
  1248. * \param[out] type_info Must be freed with OrtApi::ReleaseTypeInfo
  1249. *
  1250. * \snippet{doc} snippets.dox OrtStatus Return Value
  1251. */
  1252. ORT_API2_STATUS(SessionGetInputTypeInfo, _In_ const OrtSession* session, size_t index, _Outptr_ OrtTypeInfo** type_info);
  1253. /** \brief Get output type information
  1254. *
  1255. * \param[in] session
  1256. * \param[in] index Must be between 0 (inclusive) and what OrtApi::SessionGetOutputCount returns (exclusive)
  1257. * \param[out] type_info Must be freed with OrtApi::ReleaseTypeInfo
  1258. *
  1259. * \snippet{doc} snippets.dox OrtStatus Return Value
  1260. */
  1261. ORT_API2_STATUS(SessionGetOutputTypeInfo, _In_ const OrtSession* session, size_t index, _Outptr_ OrtTypeInfo** type_info);
  1262. /** \brief Get overridable initializer type information
  1263. *
  1264. * \param[in] session
  1265. * \param[in] index Must be between 0 (inclusive) and what OrtApi::SessionGetOverridableInitializerCount returns (exclusive)
  1266. * \param[out] type_info Must be freed with OrtApi::ReleaseTypeInfo
  1267. *
  1268. * \snippet{doc} snippets.dox OrtStatus Return Value
  1269. */
  1270. ORT_API2_STATUS(SessionGetOverridableInitializerTypeInfo, _In_ const OrtSession* session, size_t index, _Outptr_ OrtTypeInfo** type_info);
  1271. /** \brief Get input name
  1272. *
  1273. * \param[in] session
  1274. * \param[in] index Must be between 0 (inclusive) and what OrtApi::SessionGetInputCount returns (exclusive)
  1275. * \param[in] allocator
  1276. * \param[out] value Set to a null terminated UTF-8 encoded string allocated using `allocator`. Must be freed using `allocator`.
  1277. *
  1278. * \snippet{doc} snippets.dox OrtStatus Return Value
  1279. */
  1280. ORT_API2_STATUS(SessionGetInputName, _In_ const OrtSession* session, size_t index, _Inout_ OrtAllocator* allocator, _Outptr_ char** value);
  1281. /** \brief Get output name
  1282. *
  1283. * \param[in] session
  1284. * \param[in] index Must be between 0 (inclusive) and what OrtApi::SessionGetOutputCount returns (exclusive)
  1285. * \param[in] allocator
  1286. * \param[out] value Set to a null terminated UTF-8 encoded string allocated using `allocator`. Must be freed using `allocator`.
  1287. *
  1288. * \snippet{doc} snippets.dox OrtStatus Return Value
  1289. */
  1290. ORT_API2_STATUS(SessionGetOutputName, _In_ const OrtSession* session, size_t index, _Inout_ OrtAllocator* allocator, _Outptr_ char** value);
  1291. /** \brief Get overridable initializer name
  1292. *
  1293. * \param[in] session
  1294. * \param[in] index Must be between 0 (inclusive) and what OrtApi::SessionGetOverridableInitializerCount returns (exclusive)
  1295. * \param[in] allocator
  1296. * \param[out] value Set to a null terminated UTF-8 encoded string allocated using `allocator`. Must be freed using `allocator`.
  1297. *
  1298. * \snippet{doc} snippets.dox OrtStatus Return Value
  1299. */
  1300. ORT_API2_STATUS(SessionGetOverridableInitializerName, _In_ const OrtSession* session, size_t index,
  1301. _Inout_ OrtAllocator* allocator, _Outptr_ char** value);
  1302. /// @}
  1303. /// \name OrtRunOptions
  1304. /// @{
  1305. /** \brief Create an OrtRunOptions
  1306. *
  1307. * \param[out] out Returned newly created ::OrtRunOptions. Must be freed with OrtApi::ReleaseRunOptions
  1308. *
  1309. * \snippet{doc} snippets.dox OrtStatus Return Value
  1310. */
  1311. ORT_API2_STATUS(CreateRunOptions, _Outptr_ OrtRunOptions** out);
  1312. /** \brief Set per-run log verbosity level
  1313. *
  1314. * \see OrtApi::RunOptionsGetRunLogVerbosityLevel
  1315. *
  1316. * \param[in] options
  1317. * \param[in] log_verbosity_level \snippet{doc} snippets.dox Log Verbosity Level
  1318. *
  1319. * \snippet{doc} snippets.dox OrtStatus Return Value
  1320. */
  1321. ORT_API2_STATUS(RunOptionsSetRunLogVerbosityLevel, _Inout_ OrtRunOptions* options, int log_verbosity_level);
  1322. /** \brief Set per-run log severity level
  1323. *
  1324. * \see OrtApi::RunOptionsGetRunLogSeverityLevel
  1325. *
  1326. * \param[in] options
  1327. * \param[in] log_severity_level The log severity level (refer to ::OrtLoggingLevel for possible values).
  1328. */
  1329. ORT_API2_STATUS(RunOptionsSetRunLogSeverityLevel, _Inout_ OrtRunOptions* options, int log_severity_level);
  1330. /** \brief Set per-run tag
  1331. *
  1332. * This is used in a per-run log identifier.
  1333. *
  1334. * \see OrtApi::RunOptionsGetRunTag
  1335. *
  1336. * \param[in] options
  1337. * \param[in] run_tag The run tag.
  1338. */
  1339. ORT_API2_STATUS(RunOptionsSetRunTag, _Inout_ OrtRunOptions* options, _In_ const char* run_tag);
  1340. /** \brief Get per-run log verbosity level
  1341. *
  1342. * \see OrtApi::RunOptionsSetRunLogVerbosityLevel
  1343. *
  1344. * \param[in] options
  1345. * \param[out] log_verbosity_level \snippet{doc} snippets.dox Log Verbosity Level
  1346. *
  1347. * \snippet{doc} snippets.dox OrtStatus Return Value
  1348. */
  1349. ORT_API2_STATUS(RunOptionsGetRunLogVerbosityLevel, _In_ const OrtRunOptions* options,
  1350. _Out_ int* log_verbosity_level);
  1351. /** \brief Get per-run log severity level
  1352. *
  1353. * \see OrtApi::RunOptionsSetRunLogSeverityLevel
  1354. *
  1355. * \param[in] options
  1356. * \param[out] log_severity_level The log severity level (refer to ::OrtLoggingLevel for possible values).
  1357. */
  1358. ORT_API2_STATUS(RunOptionsGetRunLogSeverityLevel, _In_ const OrtRunOptions* options, _Out_ int* log_severity_level);
  1359. /** \brief Get per-run tag
  1360. *
  1361. * This is used in a per-run log identifier.
  1362. *
  1363. * \see OrtApi::RunOptionsSetRunTag
  1364. *
  1365. * \param[in] options
  1366. * \param[out] run_tag The run tag.
  1367. * Do not free this value, it is owned by `options`. It will be invalidated if the run tag
  1368. * changes (i.e., with OrtApi::RunOptionsSetRunTag) or `options` is freed.
  1369. */
  1370. ORT_API2_STATUS(RunOptionsGetRunTag, _In_ const OrtRunOptions* options, _Out_ const char** run_tag);
  1371. /** \brief Set terminate flag
  1372. *
  1373. * If a currently executing session needs to be force terminated, this can be called from another thread to force it to fail with an error.
  1374. *
  1375. * \param[in] options
  1376. *
  1377. * \snippet{doc} snippets.dox OrtStatus Return Value
  1378. */
  1379. ORT_API2_STATUS(RunOptionsSetTerminate, _Inout_ OrtRunOptions* options);
  1380. /** \brief Clears the terminate flag
  1381. *
  1382. * Used so the OrtRunOptions instance can be used in a new OrtApi::Run call without it instantly terminating
  1383. *
  1384. * \param[in] options
  1385. *
  1386. * \snippet{doc} snippets.dox OrtStatus Return Value
  1387. */
  1388. ORT_API2_STATUS(RunOptionsUnsetTerminate, _Inout_ OrtRunOptions* options);
  1389. /// @}
  1390. /// \name OrtValue
  1391. /// @{
  1392. /** \brief Create a tensor
  1393. *
  1394. * Create a tensor using a supplied ::OrtAllocator
  1395. *
  1396. * \param[in] allocator
  1397. * \param[in] shape Pointer to the tensor shape dimensions.
  1398. * \param[in] shape_len The number of tensor shape dimensions.
  1399. * \param[in] type
  1400. * \param[out] out Returns newly created ::OrtValue. Must be freed with OrtApi::ReleaseValue
  1401. *
  1402. * \snippet{doc} snippets.dox OrtStatus Return Value
  1403. */
  1404. ORT_API2_STATUS(CreateTensorAsOrtValue, _Inout_ OrtAllocator* allocator, _In_ const int64_t* shape, size_t shape_len,
  1405. ONNXTensorElementDataType type, _Outptr_ OrtValue** out);
  1406. /** \brief Create a tensor backed by a user supplied buffer
  1407. *
  1408. * Create a tensor with user's buffer. You can fill the buffer either before calling this function or after.
  1409. * p_data is owned by caller. ReleaseValue won't release p_data.
  1410. *
  1411. * If you wish to transfer ownership of p_data to ORT use CreateTensorWithDataAndDeleterAsOrtValue.
  1412. *
  1413. * \param[in] info Memory description of where the p_data buffer resides (CPU vs GPU etc).
  1414. * \param[in] p_data Pointer to the data buffer.
  1415. * \param[in] p_data_len The number of bytes in the data buffer.
  1416. * \param[in] shape Pointer to the tensor shape dimensions.
  1417. * \param[in] shape_len The number of tensor shape dimensions.
  1418. * \param[in] type The data type.
  1419. * \param[out] out Returns newly created ::OrtValue. Must be freed with OrtApi::ReleaseValue
  1420. *
  1421. * \snippet{doc} snippets.dox OrtStatus Return Value
  1422. */
  1423. ORT_API2_STATUS(CreateTensorWithDataAsOrtValue, _In_ const OrtMemoryInfo* info, _Inout_ void* p_data,
  1424. size_t p_data_len, _In_ const int64_t* shape, size_t shape_len, ONNXTensorElementDataType type,
  1425. _Outptr_ OrtValue** out);
  1426. /** \brief Return if an ::OrtValue is a tensor type
  1427. *
  1428. * \param[in] value A tensor type (string tensors are not supported)
  1429. * \param[out] out Set to 1 iff ::OrtValue is a tensor, 0 otherwise
  1430. *
  1431. * \snippet{doc} snippets.dox OrtStatus Return Value
  1432. */
  1433. ORT_API2_STATUS(IsTensor, _In_ const OrtValue* value, _Out_ int* out);
  1434. /** \brief Get a pointer to the raw data inside a tensor
  1435. *
  1436. * Used to read/write/modify the internal tensor data directly.
  1437. * \note The returned pointer is valid until the \p value is destroyed.
  1438. *
  1439. * \param[in] value A tensor type (string tensors are not supported)
  1440. * \param[out] out Filled in with a pointer to the internal storage
  1441. *
  1442. * \snippet{doc} snippets.dox OrtStatus Return Value
  1443. */
  1444. ORT_API2_STATUS(GetTensorMutableData, _In_ OrtValue* value, _Outptr_ void** out);
  1445. /** \brief Set all strings at once in a string tensor
  1446. *
  1447. * \param[in,out] value A tensor of type ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING
  1448. * \param[in] s An array of strings. Each string in this array must be null terminated.
  1449. * \param[in] s_len Count of strings in s (Must match the size of \p value's tensor shape)
  1450. *
  1451. * \snippet{doc} snippets.dox OrtStatus Return Value
  1452. */
  1453. ORT_API2_STATUS(FillStringTensor, _Inout_ OrtValue* value, _In_ const char* const* s, size_t s_len);
  1454. /** \brief Get total byte length for all strings in a string tensor
  1455. *
  1456. * Typically used with OrtApi::GetStringTensorContent
  1457. *
  1458. * \param[in] value A tensor of type ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING
  1459. * \param[out] len Total byte length of all strings (does not include trailing nulls)
  1460. *
  1461. * \snippet{doc} snippets.dox OrtStatus Return Value
  1462. */
  1463. ORT_API2_STATUS(GetStringTensorDataLength, _In_ const OrtValue* value, _Out_ size_t* len);
  1464. /** \brief Get all strings from a string tensor
  1465. *
  1466. * An example of the results:<br>
  1467. * Given \p value is a string tensor with the strings { "This" "is" "a" "test" }<br>
  1468. * \p s must have a size of 11 bytes<br>
  1469. * \p offsets must have 4 elements<br>
  1470. * After the call, these values will be filled in:<br>
  1471. * \p s will contain "Thisisatest"<br>
  1472. * \p offsets will contain { 0, 4, 6, 7 }<br>
  1473. * The length of the last string is just s_len - offsets[last]
  1474. *
  1475. * \param[in] value A tensor of type ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING
  1476. * \param[in] s Buffer to sequentially write all tensor strings to. Each string is NOT null-terminated.
  1477. * \param[in] s_len Number of bytes of buffer pointed to by \p s (Get it from OrtApi::GetStringTensorDataLength)
  1478. * \param[out] offsets Array of start offsets into the strings written to \p s
  1479. * \param[in] offsets_len Number of elements in offsets
  1480. *
  1481. * \snippet{doc} snippets.dox OrtStatus Return Value
  1482. */
  1483. ORT_API2_STATUS(GetStringTensorContent, _In_ const OrtValue* value, _Out_writes_bytes_all_(s_len) void* s,
  1484. size_t s_len, _Out_writes_all_(offsets_len) size_t* offsets, size_t offsets_len);
  1485. /// @}
  1486. /// \name OrtTypeInfo
  1487. /// @{
  1488. /** \brief Get ::OrtTensorTypeAndShapeInfo from an ::OrtTypeInfo
  1489. *
  1490. * \param[in] type_info
  1491. * \param[out] out Do not free this value, it will be valid until type_info is freed.
  1492. * If type_info does not represent tensor, this value will be set to nullptr.
  1493. *
  1494. * \snippet{doc} snippets.dox OrtStatus Return Value
  1495. */
  1496. ORT_API2_STATUS(CastTypeInfoToTensorInfo, _In_ const OrtTypeInfo* type_info,
  1497. _Outptr_result_maybenull_ const OrtTensorTypeAndShapeInfo** out);
  1498. /** \brief Get ::ONNXType from ::OrtTypeInfo
  1499. *
  1500. * \param[in] type_info
  1501. * \param[out] out
  1502. *
  1503. * \snippet{doc} snippets.dox OrtStatus Return Value
  1504. */
  1505. ORT_API2_STATUS(GetOnnxTypeFromTypeInfo, _In_ const OrtTypeInfo* type_info, _Out_ enum ONNXType* out);
  1506. /// @}
  1507. /// \name OrtTensorTypeAndShapeInfo
  1508. /// @{
  1509. /** \brief Create an ::OrtTensorTypeAndShapeInfo object
  1510. *
  1511. * \param[out] out Returns newly created ::OrtTensorTypeAndShapeInfo. Must be freed with OrtApi::ReleaseTensorTypeAndShapeInfo
  1512. *
  1513. * \snippet{doc} snippets.dox OrtStatus Return Value
  1514. */
  1515. ORT_API2_STATUS(CreateTensorTypeAndShapeInfo, _Outptr_ OrtTensorTypeAndShapeInfo** out);
  1516. /** \brief Set element type in ::OrtTensorTypeAndShapeInfo
  1517. *
  1518. * \param[in] info
  1519. * \param[in] type
  1520. *
  1521. * \snippet{doc} snippets.dox OrtStatus Return Value
  1522. */
  1523. ORT_API2_STATUS(SetTensorElementType, _Inout_ OrtTensorTypeAndShapeInfo* info, enum ONNXTensorElementDataType type);
  1524. /** \brief Set shape information in ::OrtTensorTypeAndShapeInfo
  1525. *
  1526. * \param[in] info
  1527. * \param[in] dim_values Array with `dim_count` elements. Can contain negative values.
  1528. * \param[in] dim_count Number of elements in `dim_values`
  1529. *
  1530. * \snippet{doc} snippets.dox OrtStatus Return Value
  1531. */
  1532. ORT_API2_STATUS(SetDimensions, OrtTensorTypeAndShapeInfo* info, _In_ const int64_t* dim_values, size_t dim_count);
  1533. /** \brief Get element type in ::OrtTensorTypeAndShapeInfo
  1534. *
  1535. * \see OrtApi::SetTensorElementType
  1536. *
  1537. * \param[in] info
  1538. * \param[out] out
  1539. *
  1540. * \snippet{doc} snippets.dox OrtStatus Return Value
  1541. */
  1542. ORT_API2_STATUS(GetTensorElementType, _In_ const OrtTensorTypeAndShapeInfo* info,
  1543. _Out_ enum ONNXTensorElementDataType* out);
  1544. /** \brief Get dimension count in ::OrtTensorTypeAndShapeInfo
  1545. *
  1546. * \see OrtApi::GetDimensions
  1547. *
  1548. * \param[in] info
  1549. * \param[out] out
  1550. *
  1551. * \snippet{doc} snippets.dox OrtStatus Return Value
  1552. */
  1553. ORT_API2_STATUS(GetDimensionsCount, _In_ const OrtTensorTypeAndShapeInfo* info, _Out_ size_t* out);
  1554. /** \brief Get dimensions in ::OrtTensorTypeAndShapeInfo
  1555. *
  1556. * \param[in] info
  1557. * \param[out] dim_values Array with `dim_values_length` elements. On return, filled with the dimensions stored in the ::OrtTensorTypeAndShapeInfo
  1558. * \param[in] dim_values_length Number of elements in `dim_values`. Use OrtApi::GetDimensionsCount to get this value
  1559. *
  1560. * \snippet{doc} snippets.dox OrtStatus Return Value
  1561. */
  1562. ORT_API2_STATUS(GetDimensions, _In_ const OrtTensorTypeAndShapeInfo* info, _Out_ int64_t* dim_values,
  1563. size_t dim_values_length);
  1564. /** \brief Get symbolic dimension names in ::OrtTensorTypeAndShapeInfo
  1565. *
  1566. * \param[in] info
  1567. * \param[in] dim_params Array with `dim_params_length` elements. On return filled with pointers to null terminated strings of the dimension names
  1568. * \param[in] dim_params_length Number of elements in `dim_params`. Use OrtApi::GetDimensionsCount to get this value
  1569. *
  1570. * \snippet{doc} snippets.dox OrtStatus Return Value
  1571. */
  1572. ORT_API2_STATUS(GetSymbolicDimensions, _In_ const OrtTensorTypeAndShapeInfo* info,
  1573. _Out_writes_all_(dim_params_length) const char* dim_params[], size_t dim_params_length);
  1574. /** \brief Get total number of elements in a tensor shape from an ::OrtTensorTypeAndShapeInfo
  1575. *
  1576. * Return the number of elements specified by the tensor shape (all dimensions multiplied by each other).
  1577. * For 0 dimensions, 1 is returned. If any dimension is less than 0, the result is always -1.
  1578. *
  1579. * Examples:<br>
  1580. * [] = 1<br>
  1581. * [1,3,4] = 12<br>
  1582. * [2,0,4] = 0<br>
  1583. * [-1,3,4] = -1<br>
  1584. *
  1585. * \param[in] info
  1586. * \param[out] out Number of elements
  1587. *
  1588. * \snippet{doc} snippets.dox OrtStatus Return Value
  1589. */
  1590. ORT_API2_STATUS(GetTensorShapeElementCount, _In_ const OrtTensorTypeAndShapeInfo* info, _Out_ size_t* out);
  1591. /// @}
  1592. /// \name OrtValue
  1593. /// @{
  1594. /** \brief Get type and shape information from a tensor ::OrtValue
  1595. *
  1596. * \param[in] value Must be a tensor (not a map/sequence/etc) or will return failure
  1597. * \param[out] out Newly created ::OrtTensorTypeAndShapeInfo. Must be freed with OrtApi::ReleaseTensorTypeAndShapeInfo
  1598. *
  1599. * \snippet{doc} snippets.dox OrtStatus Return Value
  1600. */
  1601. ORT_API2_STATUS(GetTensorTypeAndShape, _In_ const OrtValue* value, _Outptr_ OrtTensorTypeAndShapeInfo** out);
  1602. /** \brief Get type information of an OrtValue
  1603. *
  1604. * \param[in] value
  1605. * \param[out] out Newly created ::OrtTypeInfo. Must be freed with OrtApi::ReleaseTypeInfo
  1606. *
  1607. * \snippet{doc} snippets.dox OrtStatus Return Value
  1608. */
  1609. ORT_API2_STATUS(GetTypeInfo, _In_ const OrtValue* value, _Outptr_result_maybenull_ OrtTypeInfo** out);
  1610. /** \brief Get ONNXType of an ::OrtValue
  1611. *
  1612. * \param[in] value
  1613. * \param[out] out
  1614. *
  1615. * \snippet{doc} snippets.dox OrtStatus Return Value
  1616. */
  1617. ORT_API2_STATUS(GetValueType, _In_ const OrtValue* value, _Out_ enum ONNXType* out);
  1618. /// @}
  1619. /// \name OrtMemoryInfo
  1620. /// @{
  1621. /** \brief Create an ::OrtMemoryInfo
  1622. *
  1623. * \param[in] name
  1624. * \param[in] type
  1625. * \param[in] id
  1626. * \param[in] mem_type
  1627. * \param[out] out Newly created ::OrtMemoryInfo. Must be freed with OrtAPi::ReleaseMemoryInfo
  1628. *
  1629. * \snippet{doc} snippets.dox OrtStatus Return Value
  1630. */
  1631. ORT_API2_STATUS(CreateMemoryInfo, _In_ const char* name, enum OrtAllocatorType type, int id,
  1632. enum OrtMemType mem_type, _Outptr_ OrtMemoryInfo** out);
  1633. /** \brief Create an ::OrtMemoryInfo for CPU memory
  1634. *
  1635. * Special case version of OrtApi::CreateMemoryInfo for CPU based memory. Same as using OrtApi::CreateMemoryInfo with name = "Cpu" and id = 0.
  1636. *
  1637. * \param[in] type
  1638. * \param[in] mem_type
  1639. * \param[out] out
  1640. *
  1641. * \snippet{doc} snippets.dox OrtStatus Return Value
  1642. */
  1643. ORT_API2_STATUS(CreateCpuMemoryInfo, enum OrtAllocatorType type, enum OrtMemType mem_type,
  1644. _Outptr_ OrtMemoryInfo** out);
  1645. /** \brief Compare ::OrtMemoryInfo objects for equality
  1646. *
  1647. * Compares all settings of each ::OrtMemoryInfo for equality
  1648. *
  1649. * \param[in] info1
  1650. * \param[in] info2
  1651. * \param[out] out Set to 0 if equal, -1 if not equal
  1652. *
  1653. * \snippet{doc} snippets.dox OrtStatus Return Value
  1654. */
  1655. ORT_API2_STATUS(CompareMemoryInfo, _In_ const OrtMemoryInfo* info1, _In_ const OrtMemoryInfo* info2, _Out_ int* out);
  1656. /** \brief Get name from ::OrtMemoryInfo
  1657. *
  1658. * \param[in] ptr
  1659. * \param[out] out Writes null terminated string to this pointer. Do NOT free the returned pointer. It is valid for the lifetime of the ::OrtMemoryInfo
  1660. *
  1661. * \snippet{doc} snippets.dox OrtStatus Return Value
  1662. */
  1663. ORT_API2_STATUS(MemoryInfoGetName, _In_ const OrtMemoryInfo* ptr, _Out_ const char** out);
  1664. /** \brief Get the device id from ::OrtMemoryInfo
  1665. */
  1666. ORT_API2_STATUS(MemoryInfoGetId, _In_ const OrtMemoryInfo* ptr, _Out_ int* out);
  1667. /** \brief Get the ::OrtMemType from ::OrtMemoryInfo
  1668. */
  1669. ORT_API2_STATUS(MemoryInfoGetMemType, _In_ const OrtMemoryInfo* ptr, _Out_ OrtMemType* out);
  1670. /** \brief Get the ::OrtAllocatorType from ::OrtMemoryInfo
  1671. */
  1672. ORT_API2_STATUS(MemoryInfoGetType, _In_ const OrtMemoryInfo* ptr, _Out_ OrtAllocatorType* out);
  1673. /// @}
  1674. /// \name OrtAllocator
  1675. /// @{
  1676. /// \brief Calls OrtAllocator::Alloc function
  1677. ORT_API2_STATUS(AllocatorAlloc, _Inout_ OrtAllocator* ort_allocator, size_t size, _Outptr_ void** out);
  1678. /// \brief Calls OrtAllocator::Free function
  1679. ORT_API2_STATUS(AllocatorFree, _Inout_ OrtAllocator* ort_allocator, void* p);
  1680. /// \brief Calls OrtAllocator::Info function
  1681. ORT_API2_STATUS(AllocatorGetInfo, _In_ const OrtAllocator* ort_allocator, _Outptr_ const struct OrtMemoryInfo** out);
  1682. /** \brief Get the default allocator
  1683. *
  1684. * The default allocator is a CPU based, non-arena. Always returns the same pointer to the same default allocator.
  1685. *
  1686. * \param[out] out Returned value should NOT be freed
  1687. *
  1688. * \snippet{doc} snippets.dox OrtStatus Return Value
  1689. */
  1690. ORT_API2_STATUS(GetAllocatorWithDefaultOptions, _Outptr_ OrtAllocator** out);
  1691. /// @}
  1692. /// \name OrtSessionOptions
  1693. /// @{
  1694. /** \brief Override session symbolic dimensions
  1695. *
  1696. * Override symbolic dimensions (by specific denotation strings) with actual values if known at session initialization time to enable
  1697. * optimizations that can take advantage of fixed values (such as memory planning, etc)
  1698. *
  1699. * \param[in] options
  1700. * \param[in] dim_denotation
  1701. * \param[in] dim_value
  1702. *
  1703. * \snippet{doc} snippets.dox OrtStatus Return Value
  1704. */
  1705. ORT_API2_STATUS(AddFreeDimensionOverride, _Inout_ OrtSessionOptions* options, _In_ const char* dim_denotation,
  1706. _In_ int64_t dim_value);
  1707. /// @}
  1708. /// \name OrtValue
  1709. /// @{
  1710. /* Internal information (not seen in Doxygen)
  1711. *
  1712. * APIs to support non-tensor types - map and sequence.
  1713. * Currently only the following types are supported
  1714. * Note: the following types should be kept in sync with data_types.h
  1715. * Map types
  1716. * =========
  1717. * std::map<std::string, std::string>
  1718. * std::map<std::string, int64_t>
  1719. * std::map<std::string, float>
  1720. * std::map<std::string, double>
  1721. * std::map<int64_t, std::string>
  1722. * std::map<int64_t, int64_t>
  1723. * std::map<int64_t, float>
  1724. * std::map<int64_t, double>
  1725. *
  1726. * Sequence types
  1727. * ==============
  1728. * std::vector<std::string>
  1729. * std::vector<int64_t>
  1730. * std::vector<float>
  1731. * std::vector<double>
  1732. * std::vector<std::map<std::string, float>>
  1733. * std::vector<std::map<int64_t, float>
  1734. */
  1735. /** \brief Get non tensor data from an ::OrtValue
  1736. *
  1737. * If `value` is of type ONNX_TYPE_MAP, you need to retrieve the keys and values
  1738. * separately. Use index=0 to retrieve keys and index=1 to retrieve values.
  1739. * If `value` is of type ONNX_TYPE_SEQUENCE, use index to retrieve the index'th element
  1740. * of the sequence.
  1741. *
  1742. * \param[in] value
  1743. * \param[in] index See above for usage based on `value` type
  1744. * \param[in] allocator Allocator used to allocate ::OrtValue
  1745. * \param[out] out Created ::OrtValue that holds the element requested. Must be freed with OrtApi::ReleaseValue
  1746. *
  1747. * \snippet{doc} snippets.dox OrtStatus Return Value
  1748. */
  1749. ORT_API2_STATUS(GetValue, _In_ const OrtValue* value, int index, _Inout_ OrtAllocator* allocator,
  1750. _Outptr_ OrtValue** out);
  1751. /** \brief Get non tensor value count from an ::OrtValue
  1752. *
  1753. * If `value` is of type ONNX_TYPE_MAP 2 will always be returned. For ONNX_TYPE_SEQUENCE
  1754. * the number of elements in the sequence will be returned
  1755. *
  1756. * \param[in] value
  1757. * \param[out] out
  1758. *
  1759. * \snippet{doc} snippets.dox OrtStatus Return Value
  1760. */
  1761. ORT_API2_STATUS(GetValueCount, _In_ const OrtValue* value, _Out_ size_t* out);
  1762. /** \brief Create a map or sequence ::OrtValue
  1763. *
  1764. * To construct a map (ONNX_TYPE_MAP), use num_values = 2 and `in` should be an array of 2 ::OrtValue%s
  1765. * representing keys and values.<br>
  1766. *
  1767. * To construct a sequence (ONNX_TYPE_SEQUENCE), use num_values = N where N is the number of the elements in the
  1768. * sequence. 'in' should be an array of N ::OrtValue%s.
  1769. *
  1770. * \param[in] in See above for details
  1771. * \param[in] num_values
  1772. * \param[in] value_type Must be either ONNX_TYPE_MAP or ONNX_TYPE_SEQUENCE
  1773. * \param[out] out Newly created ::OrtValue. Must be freed with OrtApi::ReleaseValue
  1774. *
  1775. * \snippet{doc} snippets.dox OrtStatus Return Value
  1776. */
  1777. ORT_API2_STATUS(CreateValue, _In_reads_(num_values) const OrtValue* const* in, size_t num_values,
  1778. enum ONNXType value_type, _Outptr_ OrtValue** out);
  1779. /** \brief Create an opaque (custom user defined type) ::OrtValue
  1780. *
  1781. * Constructs an ::OrtValue that contains a value of non-standard type created for
  1782. * experiments or while awaiting standardization. ::OrtValue in this case would contain
  1783. * an internal representation of the Opaque type. Opaque types are distinguished from
  1784. * each other by two strings 1) domain and 2) type name. The combination of the two
  1785. * must be unique, so the type representation is properly identified internally. The combination
  1786. * must be properly registered from within ORT at both compile/run time or by another API.
  1787. *
  1788. * To construct the ::OrtValue pass domain and type names, also a pointer to a data container
  1789. * the type of which must be known to both ORT and the client program. That data container may or may
  1790. * not match the internal representation of the Opaque type. The sizeof(data_container) is passed for
  1791. * verification purposes.
  1792. *
  1793. * \param[in] domain_name Null terminated string of the domain name
  1794. * \param[in] type_name Null terminated string of the type name
  1795. * \param[in] data_container User pointer Data to populate ::OrtValue
  1796. * \param[in] data_container_size Size in bytes of what `data_container` points to
  1797. * \param[out] out Newly created ::OrtValue. Must be freed with OrtApi::ReleaseValue
  1798. *
  1799. * \snippet{doc} snippets.dox OrtStatus Return Value
  1800. */
  1801. ORT_API2_STATUS(CreateOpaqueValue, _In_z_ const char* domain_name, _In_z_ const char* type_name,
  1802. _In_ const void* data_container, size_t data_container_size, _Outptr_ OrtValue** out);
  1803. /** \brief Get internal data from an opaque (custom user defined type) ::OrtValue
  1804. *
  1805. * Copies internal data from an opaque value into a user provided buffer
  1806. *
  1807. * \see OrtApi::CreateOpaqueValue
  1808. *
  1809. * \param[in] domain_name Null terminated string of the domain name
  1810. * \param[in] type_name Null terminated string of the type name
  1811. * \param[in] in The opaque ::OrtValue
  1812. * \param[out] data_container Buffer to copy data into
  1813. * \param[out] data_container_size Size in bytes of the buffer pointed to by data_container. Must match the size of the internal buffer.
  1814. *
  1815. * \snippet{doc} snippets.dox OrtStatus Return Value
  1816. */
  1817. ORT_API2_STATUS(GetOpaqueValue, _In_ const char* domain_name, _In_ const char* type_name, _In_ const OrtValue* in,
  1818. _Out_ void* data_container, size_t data_container_size);
  1819. /// @}
  1820. /// \name OrtKernelInfo
  1821. /// Custom operator APIs.
  1822. /// @{
  1823. /** \brief Get a float stored as an attribute in the graph node
  1824. *
  1825. * \param[in] info ::OrtKernelInfo instance
  1826. * \param[in] name Null terminated string of the name of the attribute
  1827. * \param[out] out Pointer to memory where the attribute will be stored
  1828. *
  1829. * \snippet{doc} snippets.dox OrtStatus Return Value
  1830. */
  1831. ORT_API2_STATUS(KernelInfoGetAttribute_float, _In_ const OrtKernelInfo* info, _In_ const char* name,
  1832. _Out_ float* out);
  1833. /** \brief Fetch a 64-bit int stored as an attribute in the graph node
  1834. *
  1835. * \param[in] info ::OrtKernelInfo instance
  1836. * \param[in] name Null terminated string of the name of the attribute
  1837. * \param[out] out Pointer to memory where the attribute will be stored
  1838. *
  1839. * \snippet{doc} snippets.dox OrtStatus Return Value
  1840. */
  1841. ORT_API2_STATUS(KernelInfoGetAttribute_int64, _In_ const OrtKernelInfo* info, _In_ const char* name,
  1842. _Out_ int64_t* out);
  1843. /** \brief Fetch a string stored as an attribute in the graph node
  1844. *
  1845. * If `out` is nullptr, the value of `size` is set to the true size of the string
  1846. * attribute, and a success status is returned.
  1847. *
  1848. * If the `size` parameter is greater than or equal to the actual string attribute's size,
  1849. * the value of `size` is set to the true size of the string attribute, the provided memory
  1850. * is filled with the attribute's contents, and a success status is returned.
  1851. *
  1852. * If the `size` parameter is less than the actual string attribute's size and `out`
  1853. * is not nullptr, the value of `size` is set to the true size of the string attribute
  1854. * and a failure status is returned.)
  1855. *
  1856. * \param[in] info ::OrtKernelInfo instance
  1857. * \param[in] name Null terminated string of the name of the attribute
  1858. * \param[out] out Pointer to memory where the attribute will be stored
  1859. * \param[in,out] size See above comments for details
  1860. *
  1861. * \snippet{doc} snippets.dox OrtStatus Return Value
  1862. */
  1863. ORT_API2_STATUS(KernelInfoGetAttribute_string, _In_ const OrtKernelInfo* info, _In_ const char* name, _Out_ char* out,
  1864. _Inout_ size_t* size);
  1865. /// @}
  1866. /// \name OrtKernelContext
  1867. /// Custom operator APIs.
  1868. /// @{
  1869. /** \brief Used for custom operators, get the input count of a kernel
  1870. *
  1871. * \see ::OrtCustomOp
  1872. */
  1873. ORT_API2_STATUS(KernelContext_GetInputCount, _In_ const OrtKernelContext* context, _Out_ size_t* out);
  1874. /** \brief Used for custom operators, get the output count of a kernel
  1875. *
  1876. * \see ::OrtCustomOp
  1877. */
  1878. ORT_API2_STATUS(KernelContext_GetOutputCount, _In_ const OrtKernelContext* context, _Out_ size_t* out);
  1879. /** \brief Used for custom operators, get an input of a kernel
  1880. *
  1881. * The function attempts fetches the input of the kernel. If the input is optional
  1882. * and not present, the function returns success and out is set to nullptr.
  1883. *
  1884. * \param[in] context ::OrtKernelContext instance
  1885. * \param[in] index See KernelContext_GetInputCount for boundaries check.
  1886. * \param[out] out OrtValue if the input is present otherwise is set nullptr
  1887. *
  1888. * \snippet{doc} snippets.dox OrtStatus Return Value
  1889. */
  1890. ORT_API2_STATUS(KernelContext_GetInput, _In_ const OrtKernelContext* context, _In_ size_t index,
  1891. _Out_ const OrtValue** out);
  1892. /** \brief Used for custom operators, get an output of a kernel
  1893. *
  1894. * The function attempts fetches the output of the kernel. If the output is optional
  1895. * and not present, the function returns success and out is set to nullptr.
  1896. *
  1897. * \param[in] context ::OrtKernelContext instance
  1898. * \param[in] index See KernelContext_GetOutputCount for boundaries check.
  1899. * \param[in] dim_values output dimensions
  1900. * \param[in] dim_count number of dimensions
  1901. * \param[out] out a ptr to OrtValue to output otherwise set to nullptr
  1902. *
  1903. * \snippet{doc} snippets.dox OrtStatus Return Value
  1904. */
  1905. ORT_API2_STATUS(KernelContext_GetOutput, _Inout_ OrtKernelContext* context, _In_ size_t index,
  1906. _In_ const int64_t* dim_values, size_t dim_count, _Outptr_ OrtValue** out);
  1907. /// @}
  1908. /// \name OrtEnv
  1909. /// @{
  1910. ORT_CLASS_RELEASE(Env);
  1911. /// @}
  1912. /// \name OrtStatus
  1913. /// @{
  1914. ORT_CLASS_RELEASE(Status);
  1915. /// @}
  1916. /// \name OrtMemoryInfo
  1917. /// @{
  1918. ORT_CLASS_RELEASE(MemoryInfo);
  1919. /// @}
  1920. /// \name OrtSession
  1921. /// @{
  1922. ORT_CLASS_RELEASE(Session); // Don't call ReleaseSession from Dllmain (because session owns a thread pool)
  1923. /// @}
  1924. /// \name OrtValue
  1925. /// @{
  1926. ORT_CLASS_RELEASE(Value);
  1927. /// @}
  1928. /// \name OrtRunOptions
  1929. /// @{
  1930. ORT_CLASS_RELEASE(RunOptions);
  1931. /// @}
  1932. /// \name OrtTypeInfo
  1933. /// @{
  1934. ORT_CLASS_RELEASE(TypeInfo);
  1935. /// @}
  1936. /// \name OrtTensorTypeAndShapeInfo
  1937. /// @{
  1938. ORT_CLASS_RELEASE(TensorTypeAndShapeInfo);
  1939. /// @}
  1940. /// \name OrtSessionOptions
  1941. /// @{
  1942. ORT_CLASS_RELEASE(SessionOptions);
  1943. /// @}
  1944. /// \name OrtCustomOpDomain
  1945. /// @{
  1946. ORT_CLASS_RELEASE(CustomOpDomain);
  1947. /// @}
  1948. /// \name OrtTypeInfo
  1949. /// @{
  1950. /** \brief Get denotation from type information
  1951. *
  1952. * Augments ::OrtTypeInfo to return denotations on the type.
  1953. *
  1954. * This is used by WinML to determine if an input/output is intended to be an Image or a Tensor.
  1955. *
  1956. * \param[in] type_info
  1957. * \param[out] denotation Pointer to the null terminated denotation string is written to this pointer. This pointer is valid until the object is destroyed or the name is changed, do not free.
  1958. * \param[out] len Length in bytes of the string returned in `denotation`
  1959. *
  1960. * \snippet{doc} snippets.dox OrtStatus Return Value
  1961. */
  1962. ORT_API2_STATUS(GetDenotationFromTypeInfo, _In_ const OrtTypeInfo* type_info, _Out_ const char** const denotation,
  1963. _Out_ size_t* len);
  1964. /** \brief Get detailed map information from an ::OrtTypeInfo
  1965. *
  1966. * This augments ::OrtTypeInfo to return an ::OrtMapTypeInfo when the type is a map.
  1967. * The OrtMapTypeInfo has additional information about the map's key type and value type.
  1968. *
  1969. * This is used by WinML to support model reflection APIs.
  1970. *
  1971. * \param[out] type_info
  1972. * \param[out] out A pointer to the ::OrtMapTypeInfo. Do not free this value. If type_info
  1973. * does not contain a map, this value will be set to nullptr.
  1974. *
  1975. * \snippet{doc} snippets.dox OrtStatus Return Value
  1976. */
  1977. ORT_API2_STATUS(CastTypeInfoToMapTypeInfo, _In_ const OrtTypeInfo* type_info,
  1978. _Outptr_result_maybenull_ const OrtMapTypeInfo** out);
  1979. /** \brief Cast ::OrtTypeInfo to an ::OrtSequenceTypeInfo
  1980. *
  1981. * This api augments ::OrtTypeInfo to return an ::OrtSequenceTypeInfo when the type is a sequence.
  1982. * The ::OrtSequenceTypeInfo has additional information about the sequence's element type.
  1983. *
  1984. * This is used by WinML to support model reflection APIs.
  1985. *
  1986. * \param[in] type_info
  1987. * \param[out] out A pointer to the OrtSequenceTypeInfo. Do not free this value. If type_info
  1988. * doesn not contain a sequence, this value will be set to nullptr.
  1989. *
  1990. * \snippet{doc} snippets.dox OrtStatus Return Value
  1991. */
  1992. ORT_API2_STATUS(CastTypeInfoToSequenceTypeInfo, _In_ const OrtTypeInfo* type_info,
  1993. _Outptr_result_maybenull_ const OrtSequenceTypeInfo** out);
  1994. /// @}
  1995. /// \name OrtMapTypeInfo
  1996. /// @{
  1997. /** \brief Get key type from an ::OrtMapTypeInfo
  1998. *
  1999. * Key types are restricted to being scalar types.
  2000. *
  2001. * This is used by WinML to support model reflection APIs.
  2002. *
  2003. * \param[in] map_type_info
  2004. * \param[out] out
  2005. *
  2006. * \snippet{doc} snippets.dox OrtStatus Return Value
  2007. */
  2008. ORT_API2_STATUS(GetMapKeyType, _In_ const OrtMapTypeInfo* map_type_info, _Out_ enum ONNXTensorElementDataType* out);
  2009. /** \brief Get the value type from an ::OrtMapTypeInfo
  2010. *
  2011. * \param[in] map_type_info
  2012. * \param[out] type_info A copy of the OrtTypeInfo for the map value type.
  2013. * The user must free this value with ReleaseTypeInfo.
  2014. *
  2015. * \snippet{doc} snippets.dox OrtStatus Return Value
  2016. */
  2017. ORT_API2_STATUS(GetMapValueType, _In_ const OrtMapTypeInfo* map_type_info, _Outptr_ OrtTypeInfo** type_info);
  2018. /// @}
  2019. /// \name OrtSequenceTypeInfo
  2020. /// @{
  2021. /** \brief Get element type from an ::OrtSequenceTypeInfo
  2022. *
  2023. * This is used by WinML to support model reflection APIs.
  2024. *
  2025. * \param[in] sequence_type_info
  2026. * \param[out] type_info A copy of the OrtTypeInfo for the sequence element type.
  2027. * The user must free this value with ReleaseTypeInfo.
  2028. *
  2029. * \snippet{doc} snippets.dox OrtStatus Return Value
  2030. */
  2031. ORT_API2_STATUS(GetSequenceElementType, _In_ const OrtSequenceTypeInfo* sequence_type_info,
  2032. _Outptr_ OrtTypeInfo** type_info);
  2033. /// @}
  2034. /// \name OrtMapTypeInfo
  2035. /// @{
  2036. ORT_CLASS_RELEASE(MapTypeInfo);
  2037. /// @}
  2038. /// \name OrtSequenceTypeInfo
  2039. /// @{
  2040. ORT_CLASS_RELEASE(SequenceTypeInfo);
  2041. /// @}
  2042. /// \name OrtSession
  2043. /// @{
  2044. /** \brief End profiling and return filename of the profile data
  2045. *
  2046. * Profiling is turned on through OrtApi::EnableProfiling
  2047. *
  2048. * \param[in] session
  2049. * \param[in] allocator
  2050. * \param[out] out Null terminated string of the filename, allocated using `allocator`. Must be freed using `allocator`
  2051. *
  2052. * \snippet{doc} snippets.dox OrtStatus Return Value
  2053. */
  2054. ORT_API2_STATUS(SessionEndProfiling, _In_ OrtSession* session, _Inout_ OrtAllocator* allocator, _Outptr_ char** out);
  2055. /** \brief Get ::OrtModelMetadata from an ::OrtSession
  2056. *
  2057. * \param[in] session
  2058. * \param[out] out Newly created ::OrtModelMetadata. Must be freed using OrtApi::ReleaseModelMetadata
  2059. *
  2060. * \snippet{doc} snippets.dox OrtStatus Return Value
  2061. */
  2062. ORT_API2_STATUS(SessionGetModelMetadata, _In_ const OrtSession* session, _Outptr_ OrtModelMetadata** out);
  2063. /// @}
  2064. /// \name OrtModelMetadata
  2065. /// @{
  2066. /** \brief Get `producer name` from an ::OrtModelMetadata
  2067. *
  2068. * \param[in] model_metadata
  2069. * \param[in] allocator
  2070. * \param[out] value Set to a null terminated string allocated using `allocator`. Must be freed using `allocator`
  2071. *
  2072. * \snippet{doc} snippets.dox OrtStatus Return Value
  2073. */
  2074. ORT_API2_STATUS(ModelMetadataGetProducerName, _In_ const OrtModelMetadata* model_metadata,
  2075. _Inout_ OrtAllocator* allocator, _Outptr_ char** value);
  2076. /** \brief Get `graph name` from an ::OrtModelMetadata
  2077. *
  2078. * \param[in] model_metadata
  2079. * \param[in] allocator
  2080. * \param[out] value Set to a null terminated string allocated using `allocator`. Must be freed using `allocator`
  2081. *
  2082. * \snippet{doc} snippets.dox OrtStatus Return Value
  2083. */
  2084. ORT_API2_STATUS(ModelMetadataGetGraphName, _In_ const OrtModelMetadata* model_metadata,
  2085. _Inout_ OrtAllocator* allocator, _Outptr_ char** value);
  2086. /** \brief Get `domain` from an ::OrtModelMetadata
  2087. *
  2088. * \param[in] model_metadata
  2089. * \param[in] allocator
  2090. * \param[out] value Set to a null terminated string allocated using `allocator`. Must be freed using `allocator`
  2091. *
  2092. * \snippet{doc} snippets.dox OrtStatus Return Value
  2093. */
  2094. ORT_API2_STATUS(ModelMetadataGetDomain, _In_ const OrtModelMetadata* model_metadata, _Inout_ OrtAllocator* allocator,
  2095. _Outptr_ char** value);
  2096. /** \brief Get `description` from an ::OrtModelMetadata
  2097. *
  2098. * \param[in] model_metadata
  2099. * \param[in] allocator
  2100. * \param[out] value Set to a null terminated string allocated using `allocator`. Must be freed using `allocator`
  2101. *
  2102. * \snippet{doc} snippets.dox OrtStatus Return Value
  2103. */
  2104. ORT_API2_STATUS(ModelMetadataGetDescription, _In_ const OrtModelMetadata* model_metadata,
  2105. _Inout_ OrtAllocator* allocator, _Outptr_ char** value);
  2106. /** \brief Return data for a key in the custom metadata map in an ::OrtModelMetadata
  2107. *
  2108. * \param[in] model_metadata
  2109. * \param[in] allocator
  2110. * \param[in] key Null terminated string
  2111. * \param[out] value Set to a null terminated string allocated using `allocator`. Must be freed using `allocator`
  2112. * `value` will be set to nullptr if the given key is not found in the custom metadata map.
  2113. *
  2114. * \snippet{doc} snippets.dox OrtStatus Return Value
  2115. */
  2116. ORT_API2_STATUS(ModelMetadataLookupCustomMetadataMap, _In_ const OrtModelMetadata* model_metadata,
  2117. _Inout_ OrtAllocator* allocator, _In_ const char* key, _Outptr_result_maybenull_ char** value);
  2118. /** \brief Get version number from an ::OrtModelMetadata
  2119. *
  2120. * \param[in] model_metadata
  2121. * \param[out] value Set to the version number
  2122. *
  2123. * \snippet{doc} snippets.dox OrtStatus Return Value
  2124. */
  2125. ORT_API2_STATUS(ModelMetadataGetVersion, _In_ const OrtModelMetadata* model_metadata, _Out_ int64_t* value);
  2126. ORT_CLASS_RELEASE(ModelMetadata);
  2127. /// @}
  2128. /// \name OrtEnv
  2129. /// @{
  2130. /** \brief Create an OrtEnv
  2131. *
  2132. * Create an environment with global threadpools that will be shared across sessions.
  2133. * Use this in conjunction with OrtApi::DisablePerSessionThreads or else the session will use
  2134. * its own thread pools.
  2135. *
  2136. * \param[in] log_severity_level The log severity level.
  2137. * \param[in] logid The log identifier.
  2138. * \param[in] tp_options
  2139. * \param[out] out Returned newly created OrtEnv. Must be freed with OrtApi::ReleaseEnv
  2140. *
  2141. * \snippet{doc} snippets.dox OrtStatus Return Value
  2142. */
  2143. ORT_API2_STATUS(CreateEnvWithGlobalThreadPools, OrtLoggingLevel log_severity_level, _In_ const char* logid,
  2144. _In_ const OrtThreadingOptions* tp_options, _Outptr_ OrtEnv** out);
  2145. /// @}
  2146. /// \name OrtSessionOptions
  2147. /// @{
  2148. /** \brief Use global thread pool on a session
  2149. *
  2150. * Disable using per session thread pool and use the shared global threadpool.
  2151. * This should be used in conjunction with OrtApi::CreateEnvWithGlobalThreadPools.
  2152. *
  2153. * \param[in] options
  2154. *
  2155. * \snippet{doc} snippets.dox OrtStatus Return Value
  2156. */
  2157. ORT_API2_STATUS(DisablePerSessionThreads, _Inout_ OrtSessionOptions* options);
  2158. /// @}
  2159. /// \name OrtThreadingOptions
  2160. /// @{
  2161. /** \brief Create an ::OrtThreadingOptions
  2162. *
  2163. * \param[out] out Newly created ::OrtThreadingOptions. Must be freed with OrtApi::ReleaseThreadingOptions
  2164. * \snippet{doc} snippets.dox OrtStatus Return Value
  2165. */
  2166. ORT_API2_STATUS(CreateThreadingOptions, _Outptr_ OrtThreadingOptions** out);
  2167. ORT_CLASS_RELEASE(ThreadingOptions);
  2168. /// @}
  2169. /// \name OrtModelMetadata
  2170. /// @{
  2171. /**
  2172. *
  2173. * \param[in] model_metadata
  2174. * \param[in] allocator
  2175. * \param[out] keys Array of null terminated strings (array count = num_keys) allocated using `allocator`.
  2176. * The strings and the pointer array must be freed using `allocator`
  2177. * `keys` will be set to nullptr if the custom metadata map is empty.
  2178. * \param[out] num_keys Set to the number of elements in the `keys` array
  2179. *
  2180. * \snippet{doc} snippets.dox OrtStatus Return Value
  2181. */
  2182. ORT_API2_STATUS(ModelMetadataGetCustomMetadataMapKeys, _In_ const OrtModelMetadata* model_metadata,
  2183. _Inout_ OrtAllocator* allocator, _Outptr_result_buffer_maybenull_(*num_keys) char*** keys, _Out_ int64_t* num_keys);
  2184. /// @}
  2185. /// \name OrtSessionOptions
  2186. /// @{
  2187. /**
  2188. *
  2189. * Override symbolic dimensions (by specific name strings) with actual values
  2190. * if known at session initialization time to enable optimizations that can
  2191. * take advantage of fixed values (such as memory planning, etc)
  2192. *
  2193. */
  2194. ORT_API2_STATUS(AddFreeDimensionOverrideByName,
  2195. _Inout_ OrtSessionOptions* options, _In_ const char* dim_name,
  2196. _In_ int64_t dim_value);
  2197. /// @}
  2198. /// \name Misc
  2199. /// @{
  2200. /** \brief Get the names of all available providers
  2201. *
  2202. * \note The providers in the list are not guaranteed to be usable. They may fail to load due to missing system dependencies.
  2203. * For example, if the CUDA/cuDNN libraries are not installed, the CUDA provider will report an error when it is added to the session options.
  2204. *
  2205. * \param[out] out_ptr Set to a pointer to an array of null terminated strings of the available providers. The entries and the
  2206. * array itself must be freed using OrtApi::ReleaseAvailableProviders
  2207. * \param[out] provider_length Set to the number of entries in the `out_ptr` array
  2208. *
  2209. * \snippet{doc} snippets.dox OrtStatus Return Value
  2210. */
  2211. ORT_API2_STATUS(GetAvailableProviders, _Outptr_ char*** out_ptr, _Out_ int* provider_length);
  2212. /** \brief Release data from OrtApi::GetAvailableProviders. This API will never fail
  2213. * so you can rely on it in a noexcept code.
  2214. *
  2215. * \param[in] ptr The `out_ptr` result from OrtApi::GetAvailableProviders.
  2216. * \param[in] providers_length The `provider_length` result from OrtApi::GetAvailableProviders
  2217. *
  2218. * \snippet{doc} snippets.dox OrtStatus Return Value
  2219. */
  2220. ORT_API2_STATUS(ReleaseAvailableProviders, _In_ char** ptr,
  2221. _In_ int providers_length);
  2222. /// @}
  2223. /// \name OrtValue
  2224. /// @{
  2225. /** \brief Get the length of a single string in a string tensor
  2226. *
  2227. * \param[in] value A string tensor
  2228. * \param[in] index Index of the string in the tensor
  2229. * \param[out] out Set to number of bytes of the string element
  2230. *
  2231. * \snippet{doc} snippets.dox OrtStatus Return Value
  2232. */
  2233. ORT_API2_STATUS(GetStringTensorElementLength, _In_ const OrtValue* value, size_t index, _Out_ size_t* out);
  2234. /** \brief Get a single string from a string tensor
  2235. *
  2236. * \param[in] value A string tensor
  2237. * \param[in] s_len Number of bytes in the `s` buffer. Must match the value returned by OrtApi::GetStringTensorElementLength.
  2238. * \param[in] index Index of the string in the tensor
  2239. * \param[out] s The string element contents in UTF-8 encoding. The string is NOT null-terminated.
  2240. *
  2241. * \snippet{doc} snippets.dox OrtStatus Return Value
  2242. */
  2243. ORT_API2_STATUS(GetStringTensorElement, _In_ const OrtValue* value, size_t s_len, size_t index, _Out_writes_bytes_all_(s_len) void* s);
  2244. /** \brief Set a single string in a string tensor
  2245. *
  2246. * \param[in] value A string tensor
  2247. * \param[in] s A null terminated UTF-8 encoded string
  2248. * \param[in] index Index of the string in the tensor to set
  2249. *
  2250. * \snippet{doc} snippets.dox OrtStatus Return Value
  2251. */
  2252. ORT_API2_STATUS(FillStringTensorElement, _Inout_ OrtValue* value, _In_ const char* s, size_t index);
  2253. /// @}
  2254. /// \name OrtSessionOptions
  2255. /// @{
  2256. /** \brief Set a session configuration entry as a pair of strings
  2257. *
  2258. * If a configuration with same key exists, this will overwrite the configuration with the given config_value.
  2259. *
  2260. * The config_key and the format of config_value are defined in onnxruntime_session_options_config_keys.h
  2261. *
  2262. * \param[in] options
  2263. * \param[in] config_key A null terminated string representation of the config key
  2264. * \param[in] config_value A null terminated string representation of the config value
  2265. *
  2266. * \snippet{doc} snippets.dox OrtStatus Return Value
  2267. */
  2268. ORT_API2_STATUS(AddSessionConfigEntry, _Inout_ OrtSessionOptions* options,
  2269. _In_z_ const char* config_key, _In_z_ const char* config_value);
  2270. /// @}
  2271. /// \name OrtAllocator
  2272. /// @{
  2273. /** \brief Create an allocator for an ::OrtSession following an ::OrtMemoryInfo
  2274. *
  2275. * The allocator wraps the internal allocator from the OrtSession and becomes invalid when the session does.
  2276. *
  2277. * \param[in] session
  2278. * \param[in] mem_info valid ::OrtMemoryInfo instance
  2279. * \param[out] out Newly created ::OrtAllocator. Must be freed with OrtApi::ReleaseAllocator
  2280. *
  2281. * \snippet{doc} snippets.dox OrtStatus Return Value
  2282. */
  2283. ORT_API2_STATUS(CreateAllocator, _In_ const OrtSession* session, _In_ const OrtMemoryInfo* mem_info,
  2284. _Outptr_ OrtAllocator** out);
  2285. /** \brief Release an ::OrtAllocator obtained from OrtApi::CreateAllocator
  2286. */
  2287. ORT_CLASS_RELEASE(Allocator);
  2288. /// @}
  2289. /// \name OrtSession
  2290. /// @{
  2291. /** \brief Run a model using Io Bindings for the inputs & outputs
  2292. *
  2293. * \see OrtApi::Run
  2294. *
  2295. * \param[in] session
  2296. * \param[in] run_options
  2297. * \param[in] binding_ptr
  2298. *
  2299. * \snippet{doc} snippets.dox OrtStatus Return Value
  2300. */
  2301. ORT_API2_STATUS(RunWithBinding, _Inout_ OrtSession* session, _In_ const OrtRunOptions* run_options, _In_ const OrtIoBinding* binding_ptr);
  2302. /** \brief Create an ::OrtIoBinding instance
  2303. *
  2304. * An IoBinding object allows one to bind pre-allocated ::OrtValue%s to input names.
  2305. * Thus if you want to use a raw on device buffer as input or output you can avoid
  2306. * extra copy during runtime.
  2307. *
  2308. * \param[in] session
  2309. * \param[out] out Newly created ::OrtIoBinding. Must be freed with OrtApi::ReleaseIoBinding
  2310. *
  2311. * \snippet{doc} snippets.dox OrtStatus Return Value
  2312. */
  2313. ORT_API2_STATUS(CreateIoBinding, _Inout_ OrtSession* session, _Outptr_ OrtIoBinding** out);
  2314. /// @}
  2315. /// \name OrtIoBinding
  2316. /// @{
  2317. /** \brief Release an ::OrtIoBinding obtained from OrtApi::CreateIoBinding
  2318. */
  2319. ORT_CLASS_RELEASE(IoBinding);
  2320. /** \brief Bind an ::OrtValue to an ::OrtIoBinding input
  2321. *
  2322. * When using OrtApi::RunWithBinding this value is used for the named input
  2323. *
  2324. * \param[in] binding_ptr
  2325. * \param[in] name Name for the model input
  2326. * \param[in] val_ptr ::OrtValue of Tensor type.
  2327. *
  2328. * \snippet{doc} snippets.dox OrtStatus Return Value
  2329. */
  2330. ORT_API2_STATUS(BindInput, _Inout_ OrtIoBinding* binding_ptr, _In_ const char* name, _In_ const OrtValue* val_ptr);
  2331. /** \brief Bind an ::OrtValue to an ::OrtIoBinding output
  2332. *
  2333. * When using OrtApi::RunWithBinding this value is used for the named output
  2334. *
  2335. * \param[in] binding_ptr
  2336. * \param[in] name Null terminated string of the model output name
  2337. * \param[in] val_ptr ::OrtValue of Tensor type.
  2338. *
  2339. * \snippet{doc} snippets.dox OrtStatus Return Value
  2340. */
  2341. ORT_API2_STATUS(BindOutput, _Inout_ OrtIoBinding* binding_ptr, _In_ const char* name, _In_ const OrtValue* val_ptr);
  2342. /** \brief Bind an ::OrtIoBinding output to a device
  2343. *
  2344. * Binds the ::OrtValue to a device which is specified by ::OrtMemoryInfo.
  2345. * You can either create an instance of ::OrtMemoryInfo with a device id or obtain one from the allocator that you have created/are using
  2346. * This is useful when one or more outputs have dynamic shapes and, it is hard to pre-allocate and bind a chunk of
  2347. * memory within ::OrtValue ahead of time.
  2348. *
  2349. * \see OrtApi::RunWithBinding
  2350. *
  2351. * \param[in] binding_ptr
  2352. * \param[in] name Null terminated string of the device name
  2353. * \param[in] mem_info_ptr
  2354. *
  2355. * \snippet{doc} snippets.dox OrtStatus Return Value
  2356. */
  2357. ORT_API2_STATUS(BindOutputToDevice, _Inout_ OrtIoBinding* binding_ptr, _In_ const char* name, _In_ const OrtMemoryInfo* mem_info_ptr);
  2358. /** \brief Get the names of an ::OrtIoBinding's outputs
  2359. *
  2360. * Returns the names of the outputs in the order they were bound. This is useful after running the model
  2361. * with bound outputs because the returned names are in order in which output ::OrtValue are returned. This is useful if
  2362. * the order of outputs and their names is not known.
  2363. *
  2364. * \param[in] binding_ptr
  2365. * \param[in] allocator Allocator used to allocate continuous buffers for output strings and lengths.
  2366. * \param[out] buffer Returns an array of non-null terminated UTF-8 strings. The number of strings stored is returned in the count parameter.
  2367. * This buffer is allocated using `allocator` and must be freed using it.
  2368. * \param[out] lengths Returns an array of `count` lengths of the strings returned in `buffer`
  2369. * This buffer is allocated using `allocator` and must be freed using it.
  2370. * \param[out] count Number of strings returned. If `binding_ptr` has no bound outputs, zero is returned,
  2371. * no memory allocation is performed and buffer and lengths are set to nullptr.
  2372. *
  2373. * \snippet{doc} snippets.dox OrtStatus Return Value
  2374. */
  2375. ORT_API2_STATUS(GetBoundOutputNames, _In_ const OrtIoBinding* binding_ptr, _In_ OrtAllocator* allocator,
  2376. _Out_ char** buffer, _Out_writes_all_(count) size_t** lengths, _Out_ size_t* count);
  2377. /** \brief Get the output ::OrtValue objects from an ::OrtIoBinding
  2378. *
  2379. * Returns an array of pointers to individually allocated ::OrtValue%s that contain results of a model execution with OrtApi::RunWithBinding
  2380. * The array contains the same number of ::OrtValue%s and they are in the same order as they were bound with OrtApi::BindOutput
  2381. * or OrtApi::BindOutputToDevice.
  2382. *
  2383. * The returned ::OrtValue%s must be released using OrtApi::ReleaseValue after they are no longer needed.
  2384. * The array is allocated using the specified instance of the allocator and must be freed using the same allocator after
  2385. * all the ::OrtValue%s contained therein are individually released.
  2386. *
  2387. * \param[in] binding_ptr
  2388. * \param[in] allocator Allocator used to allocate output array
  2389. * \param[out] output Set to the allocated array of allocated ::OrtValue outputs. Set to nullptr if there are 0 outputs.
  2390. * \param[out] output_count Set to number of ::OrtValue%s returned
  2391. *
  2392. * \snippet{doc} snippets.dox OrtStatus Return Value
  2393. */
  2394. ORT_API2_STATUS(GetBoundOutputValues, _In_ const OrtIoBinding* binding_ptr, _In_ OrtAllocator* allocator,
  2395. _Out_writes_all_(output_count) OrtValue*** output, _Out_ size_t* output_count);
  2396. /** \brief Clears any previously set Inputs for an ::OrtIoBinding
  2397. */
  2398. void(ORT_API_CALL* ClearBoundInputs)(_Inout_ OrtIoBinding* binding_ptr) NO_EXCEPTION ORT_ALL_ARGS_NONNULL;
  2399. /** \brief Clears any previously set Outputs for an ::OrtIoBinding
  2400. */
  2401. void(ORT_API_CALL* ClearBoundOutputs)(_Inout_ OrtIoBinding* binding_ptr) NO_EXCEPTION ORT_ALL_ARGS_NONNULL;
  2402. /// @}
  2403. /// \name OrtValue
  2404. /// @{
  2405. /** \brief Direct memory access to a specified tensor element
  2406. *
  2407. * For example, given a tensor with shape of [3,224,224], a pointer to the element at location [2,150,128] can be retrieved
  2408. *
  2409. * This function only works for numeric type tensors (No strings, etc).
  2410. * This is a no-copy method whose returned pointer is valid until the passed in ::OrtValue is free'd.
  2411. *
  2412. * \param[in] value
  2413. * \param[in] location_values Pointer to an array of index values that specify an element's location relative to its shape
  2414. * \param[in] location_values_count Number of elements in location_values. Must match the number of elements in the tensor's shape.
  2415. * \param[out] out Set to a pointer to the element specified
  2416. *
  2417. * \snippet{doc} snippets.dox OrtStatus Return Value
  2418. */
  2419. ORT_API2_STATUS(TensorAt, _Inout_ OrtValue* value, const int64_t* location_values, size_t location_values_count, _Outptr_ void** out);
  2420. /// @}
  2421. /// \name OrtEnv
  2422. /// @{
  2423. /** \brief Create an allocator and register it with the ::OrtEnv
  2424. *
  2425. * Enables sharing the allocator between multiple sessions that use the same env instance.
  2426. * Lifetime of the created allocator will be valid for the duration of the environment.
  2427. * Returns an error if an allocator with the same ::OrtMemoryInfo is already registered.
  2428. *
  2429. * See https://onnxruntime.ai/docs/get-started/with-c.html for details.
  2430. *
  2431. * \param[in] env ::OrtEnv instance
  2432. * \param[in] mem_info
  2433. * \param[in] arena_cfg Pass nullptr for defaults
  2434. *
  2435. * \snippet{doc} snippets.dox OrtStatus Return Value
  2436. */
  2437. ORT_API2_STATUS(CreateAndRegisterAllocator, _Inout_ OrtEnv* env, _In_ const OrtMemoryInfo* mem_info,
  2438. _In_ const OrtArenaCfg* arena_cfg);
  2439. /** \brief Set language projection
  2440. *
  2441. * Set the language projection for collecting telemetry data when Env is created.
  2442. *
  2443. * The default is ORT_PROJECTION_C, which means it will classify the language not in the list to C also.
  2444. *
  2445. * \param[in] ort_env
  2446. * \param[in] projection
  2447. *
  2448. * \snippet{doc} snippets.dox OrtStatus Return Value
  2449. */
  2450. ORT_API2_STATUS(SetLanguageProjection, _In_ const OrtEnv* ort_env, _In_ OrtLanguageProjection projection);
  2451. /// @}
  2452. /// \name OrtSession
  2453. /// @{
  2454. /** \brief Return the time that profiling was started
  2455. *
  2456. * \note The timer precision varies per platform. On Windows and MacOS, the precision will be ~100ns
  2457. *
  2458. * \param[in] session
  2459. * \param[out] out nanoseconds of profiling's start time
  2460. *
  2461. * \snippet{doc} snippets.dox OrtStatus Return Value
  2462. */
  2463. ORT_API2_STATUS(SessionGetProfilingStartTimeNs, _In_ const OrtSession* session, _Outptr_ uint64_t* out);
  2464. /// @}
  2465. /// \name OrtThreadingOptions
  2466. /// @{
  2467. /** \brief Set global intra-op thread count
  2468. *
  2469. * This configures the global thread pool options to be used in the call to OrtApi::CreateEnvWithGlobalThreadPools
  2470. *
  2471. * \param[in] tp_options
  2472. * \param[in] intra_op_num_threads Number of threads, special values:<br>
  2473. * 0 = Use default thread count<br>
  2474. * 1 = The invoking thread will be used; no threads will be created in the thread pool.
  2475. *
  2476. * \snippet{doc} snippets.dox OrtStatus Return Value
  2477. */
  2478. ORT_API2_STATUS(SetGlobalIntraOpNumThreads, _Inout_ OrtThreadingOptions* tp_options, int intra_op_num_threads);
  2479. /** \brief Set global inter-op thread count
  2480. *
  2481. * This configures the global thread pool options to be used in the call to OrtApi::CreateEnvWithGlobalThreadPools
  2482. *
  2483. * \param[in] tp_options
  2484. * \param[in] inter_op_num_threads Number of threads, special values:<br>
  2485. * 0 = Use default thread count<br>
  2486. * 1 = The invoking thread will be used; no threads will be created in the thread pool.
  2487. *
  2488. * \snippet{doc} snippets.dox OrtStatus Return Value
  2489. */
  2490. ORT_API2_STATUS(SetGlobalInterOpNumThreads, _Inout_ OrtThreadingOptions* tp_options, int inter_op_num_threads);
  2491. /** \brief Set global spin control options
  2492. *
  2493. * This will configure the global thread pool options to be used in the call to OrtApi::CreateEnvWithGlobalThreadPools.
  2494. * Allow spinning of thread pools when their queues are empty. This will set the value for both
  2495. * inter_op and intra_op threadpools.
  2496. *
  2497. * \param[in] tp_options
  2498. * \param[in] allow_spinning Valid values are 0 or 1.<br>
  2499. * 0 = It won't spin (recommended if CPU usage is high)<br>
  2500. * 1 = Threadpool will spin to wait for queue to become non-empty
  2501. *
  2502. * \snippet{doc} snippets.dox OrtStatus Return Value
  2503. */
  2504. ORT_API2_STATUS(SetGlobalSpinControl, _Inout_ OrtThreadingOptions* tp_options, int allow_spinning);
  2505. /// @}
  2506. /// \name OrtSessionOptions
  2507. /// @{
  2508. /** \brief Add a pre-allocated initializer to a session
  2509. *
  2510. * If a model contains an initializer with a name that is same as the name passed to this call,
  2511. * ORT will use this initializer instance instead of deserializing one from the model file. This
  2512. * is useful when you want to share the same initializer across sessions.
  2513. *
  2514. * \param[in] options
  2515. * \param[in] name Null terminated string of the initializer name
  2516. * \param[in] val ::OrtValue containing the initializer. Its lifetime and the underlying initializer buffer must be
  2517. * managed by the user (created using the OrtApi::CreateTensorWithDataAsOrtValue) and it must outlive the session object
  2518. * to which it is added.
  2519. *
  2520. * \snippet{doc} snippets.dox OrtStatus Return Value
  2521. */
  2522. ORT_API2_STATUS(AddInitializer, _Inout_ OrtSessionOptions* options, _In_z_ const char* name,
  2523. _In_ const OrtValue* val);
  2524. /// @}
  2525. /// \name OrtEnv
  2526. /// @{
  2527. /**
  2528. * Create a custom environment with global threadpools and logger that will be shared across sessions.
  2529. * Use this in conjunction with OrtApi::DisablePerSessionThreads or else the session will use
  2530. * its own thread pools.
  2531. *
  2532. * \param[in] logging_function A pointer to a logging function.
  2533. * \param[in] logger_param A pointer to arbitrary data passed as the ::OrtLoggingFunction `param` parameter to
  2534. * `logging_function`.
  2535. * \param[in] log_severity_level The log severity level.
  2536. * \param[in] logid The log identifier.
  2537. * \param[in] tp_options
  2538. * \param[out] out Newly created OrtEnv. Must be freed with OrtApi::ReleaseEnv
  2539. *
  2540. * \snippet{doc} snippets.dox OrtStatus Return Value
  2541. */
  2542. ORT_API2_STATUS(CreateEnvWithCustomLoggerAndGlobalThreadPools, OrtLoggingFunction logging_function, _In_opt_ void* logger_param, OrtLoggingLevel log_severity_level,
  2543. _In_ const char* logid, _In_ const struct OrtThreadingOptions* tp_options, _Outptr_ OrtEnv** out);
  2544. /// @}
  2545. /// \name OrtSessionOptions
  2546. /// @{
  2547. /** \brief Append CUDA provider to session options
  2548. *
  2549. * If CUDA is not available (due to a non CUDA enabled build, or if CUDA is not installed on the system), this function will return failure.
  2550. *
  2551. * \param[in] options
  2552. * \param[in] cuda_options
  2553. *
  2554. * \snippet{doc} snippets.dox OrtStatus Return Value
  2555. */
  2556. ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_CUDA,
  2557. _In_ OrtSessionOptions* options, _In_ const OrtCUDAProviderOptions* cuda_options);
  2558. /** \brief Append ROCM execution provider to the session options
  2559. *
  2560. * If ROCM is not available (due to a non ROCM enabled build, or if ROCM is not installed on the system), this function will return failure.
  2561. *
  2562. * \param[in] options
  2563. * \param[in] rocm_options
  2564. *
  2565. * \snippet{doc} snippets.dox OrtStatus Return Value
  2566. */
  2567. ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_ROCM,
  2568. _In_ OrtSessionOptions* options, _In_ const OrtROCMProviderOptions* rocm_options);
  2569. /** \brief Append OpenVINO execution provider to the session options
  2570. *
  2571. * If OpenVINO is not available (due to a non OpenVINO enabled build, or if OpenVINO is not installed on the system), this function will fail.
  2572. *
  2573. * \param[in] options
  2574. * \param[in] provider_options
  2575. *
  2576. * \snippet{doc} snippets.dox OrtStatus Return Value
  2577. */
  2578. ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_OpenVINO,
  2579. _In_ OrtSessionOptions* options, _In_ const OrtOpenVINOProviderOptions* provider_options);
  2580. /// @}
  2581. /// \name OrtThreadingOptions
  2582. /// @{
  2583. /** \brief Set threading flush-to-zero and denormal-as-zero
  2584. *
  2585. * Sets global thread pool options to be used in the call to OrtApi::CreateEnvWithGlobalThreadPools.
  2586. * Flush-to-zero and denormal-as-zero are applied to threads in both intra and inter global thread pool.
  2587. * \note This option is not needed if the models used have no denormals. Having no denormals is recommended as this option may hurt model accuracy.
  2588. *
  2589. * \param[in] tp_options
  2590. *
  2591. * \snippet{doc} snippets.dox OrtStatus Return Value
  2592. */
  2593. ORT_API2_STATUS(SetGlobalDenormalAsZero, _Inout_ OrtThreadingOptions* tp_options);
  2594. /// @}
  2595. /// \name OrtArenaCfg
  2596. /// @{
  2597. /** \deprecated Use OrtApi::CreateArenaCfgV2
  2598. *
  2599. * This will create the configuration of an arena that can eventually be used to define an arena based allocator's behavior
  2600. *
  2601. * \param[in] max_mem Use 0 to allow ORT to choose the default
  2602. * \param[in] arena_extend_strategy Use -1 to allow ORT to choose the default, 0 = kNextPowerOfTwo, 1 = kSameAsRequested
  2603. * \param[in] initial_chunk_size_bytes Use -1 to allow ORT to choose the default
  2604. * \param[in] max_dead_bytes_per_chunk Use -1 to allow ORT to choose the default
  2605. * \param[in] out A pointer to an OrtArenaCfg instance
  2606. *
  2607. * \snippet{doc} snippets.dox OrtStatus Return Value
  2608. */
  2609. ORT_API2_STATUS(CreateArenaCfg, _In_ size_t max_mem, int arena_extend_strategy, int initial_chunk_size_bytes,
  2610. int max_dead_bytes_per_chunk, _Outptr_ OrtArenaCfg** out);
  2611. ORT_CLASS_RELEASE(ArenaCfg);
  2612. /// @}
  2613. /// \name OrtModelMetadata
  2614. /// @{
  2615. /**
  2616. * Use this to obtain the description of the graph present in the model
  2617. * (doc_string field of the GraphProto message within the ModelProto message).
  2618. * If it doesn't exist, an empty string will be returned.
  2619. *
  2620. * \param[in] model_metadata An instance of ::OrtModelMetadata
  2621. * \param[in] allocator Allocator used to allocate the string that will be returned back
  2622. * \param[out] value Set to a null terminated string allocated using `allocator`. The caller is responsible for freeing it using `allocator`
  2623. *
  2624. * \snippet{doc} snippets.dox OrtStatus Return Value
  2625. */
  2626. ORT_API2_STATUS(ModelMetadataGetGraphDescription, _In_ const OrtModelMetadata* model_metadata,
  2627. _Inout_ OrtAllocator* allocator, _Outptr_ char** value);
  2628. /// @}
  2629. /// \name OrtSessionOptions
  2630. /// @{
  2631. /** \brief Append TensorRT provider to session options
  2632. *
  2633. * If TensorRT is not available (due to a non TensorRT enabled build, or if TensorRT is not installed on the system), this function will return failure.
  2634. *
  2635. * \param[in] options
  2636. * \param[in] tensorrt_options
  2637. *
  2638. * \snippet{doc} snippets.dox OrtStatus Return Value
  2639. */
  2640. ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_TensorRT,
  2641. _In_ OrtSessionOptions* options, _In_ const OrtTensorRTProviderOptions* tensorrt_options);
  2642. /// @}
  2643. /// \name Misc
  2644. /// @{
  2645. /** \brief Set current GPU device ID
  2646. *
  2647. * Set the current device id of the GPU execution provider (CUDA/tensorrt/rocm). The device id should be less
  2648. * than the total number of devices available. This is only useful when multiple-GPUs are installed and it is
  2649. * required to restrict execution to a single GPU.
  2650. *
  2651. * \param[in] device_id
  2652. *
  2653. * \snippet{doc} snippets.dox OrtStatus Return Value
  2654. */
  2655. ORT_API2_STATUS(SetCurrentGpuDeviceId, _In_ int device_id);
  2656. /** \brief Get current GPU device ID
  2657. *
  2658. * Get the current device id of the GPU execution provider (CUDA/tensorrt/rocm).
  2659. *
  2660. * \see OrtApi::SetCurrentGpuDeviceId
  2661. *
  2662. * \param[out] device_id
  2663. *
  2664. * \snippet{doc} snippets.dox OrtStatus Return Value
  2665. */
  2666. ORT_API2_STATUS(GetCurrentGpuDeviceId, _In_ int* device_id);
  2667. /// @}
  2668. /// \name OrtKernelInfo
  2669. /// Custom operator APIs.
  2670. /// @{
  2671. /** \brief Fetch an array of int64_t values stored as an attribute in the graph node
  2672. *
  2673. *
  2674. * If `out` is nullptr, the value of `size` is set to the true size of the attribute
  2675. * array's size, and a success status is returned.
  2676. *
  2677. * If the `size` parameter is greater than or equal to the actual attribute array's size,
  2678. * the value of `size` is set to the true size of the attribute array's size,
  2679. * the provided memory is filled with the attribute's contents,
  2680. * and a success status is returned.
  2681. *
  2682. * If the `size` parameter is less than the actual attribute array's size and `out`
  2683. * is not nullptr, the value of `size` is set to the true size of the attribute array's size
  2684. * and a failure status is returned.)
  2685. *
  2686. * \param[in] info instance
  2687. * \param[in] name name of the attribute to be parsed
  2688. * \param[out] out pointer to memory where the attribute's contents are to be stored
  2689. * \param[in, out] size actual size of attribute array
  2690. *
  2691. * \snippet{doc} snippets.dox OrtStatus Return Value
  2692. */
  2693. ORT_API2_STATUS(KernelInfoGetAttributeArray_float, _In_ const OrtKernelInfo* info, _In_ const char* name,
  2694. _Out_ float* out, _Inout_ size_t* size);
  2695. /** \brief Fetch an array of int64_t values stored as an attribute in the graph node
  2696. *
  2697. * If `out` is nullptr, the value of `size` is set to the true size of the attribute
  2698. * array's size, and a success status is returned.
  2699. *
  2700. * If the `size` parameter is greater than or equal to the actual attribute array's size,
  2701. * the value of `size` is set to the true size of the attribute array's size,
  2702. * the provided memory is filled with the attribute's contents,
  2703. * and a success status is returned.
  2704. *
  2705. * If the `size` parameter is less than the actual attribute array's size and `out`
  2706. * is not nullptr, the value of `size` is set to the true size of the attribute array's size
  2707. * and a failure status is returned.)
  2708. *
  2709. * \param[in] info instance
  2710. * \param[in] name name of the attribute to be parsed
  2711. * \param[out] out pointer to memory where the attribute's contents are to be stored
  2712. * \param[in, out] size actual size of attribute array
  2713. *
  2714. * \snippet{doc} snippets.dox OrtStatus Return Value
  2715. */
  2716. ORT_API2_STATUS(KernelInfoGetAttributeArray_int64, _In_ const OrtKernelInfo* info, _In_ const char* name,
  2717. _Out_ int64_t* out, _Inout_ size_t* size);
  2718. /// @}
  2719. /// \name OrtArenaCfg
  2720. /// @{
  2721. /** \brief Create an ::OrtArenaCfg
  2722. *
  2723. * Create the configuration of an arena that can eventually be used to define an arena based allocator's behavior.
  2724. *
  2725. * Supported keys are (See https://onnxruntime.ai/docs/get-started/with-c.html for details on what the
  2726. * following parameters mean and how to choose these values.):
  2727. * "max_mem": Maximum memory that can be allocated by the arena based allocator.
  2728. * Use 0 for ORT to pick the best value. Default is 0.
  2729. * "arena_extend_strategy": 0 = kNextPowerOfTwo, 1 = kSameAsRequested.
  2730. * Use -1 to allow ORT to choose the default.
  2731. * "initial_chunk_size_bytes": (Possible) Size of the first allocation in the arena.
  2732. * Only relevant if arena strategy is `kNextPowerOfTwo`. Use -1 to allow ORT to choose the default.
  2733. * Ultimately, the first allocation size is determined by the allocation memory request.
  2734. * "max_dead_bytes_per_chunk": Threshold of unused memory in an allocated chunk of arena memory after
  2735. * crossing which the current chunk is chunked into 2.
  2736. * "initial_growth_chunk_size_bytes": (Possible) Size of the second allocation in the arena.
  2737. * Only relevant if arena strategy is `kNextPowerOfTwo`. Use -1 to allow ORT to choose the default.
  2738. * "max_power_of_two_extend_bytes": The maximum extend size if arena strategy is `kNextPowerOfTwo`.
  2739. * It is not an allocation limit, it is only a limit for extension when requested byte is less than the limit.
  2740. * When requested bytes is more than the limit, allocator will still return as requested.
  2741. * Use -1 to allow ORT to choose the default 1GB for max_power_of_two_extend_bytes.
  2742. * Ultimately, the allocation size is determined by the allocation memory request.
  2743. * Further allocation sizes are governed by the arena extend strategy.
  2744. *
  2745. * \param[in] arena_config_keys Keys to configure the arena
  2746. * \param[in] arena_config_values Values to configure the arena
  2747. * \param[in] num_keys Number of keys in `arena_config_keys` and `arena_config_values`
  2748. * \param[out] out Newly created ::OrtArenaCfg. Must be freed with OrtApi::ReleaseArenaCfg
  2749. *
  2750. * \snippet{doc} snippets.dox OrtStatus Return Value
  2751. */
  2752. ORT_API2_STATUS(CreateArenaCfgV2, _In_reads_(num_keys) const char* const* arena_config_keys,
  2753. _In_reads_(num_keys) const size_t* arena_config_values, _In_ size_t num_keys,
  2754. _Outptr_ OrtArenaCfg** out);
  2755. /// @}
  2756. /// \name OrtRunOptions
  2757. /// @{
  2758. /** \brief Set a single run configuration entry as a pair of strings
  2759. *
  2760. * If a configuration with same key exists, this will overwrite the configuration with the given config_value
  2761. *
  2762. * The config_key and the format of config_value are defined in onnxruntime_run_options_config_keys.h
  2763. *
  2764. * \param[in] options
  2765. * \param[in] config_key A null terminated string representation of the config key
  2766. * \param[in] config_value A null terminated string representation of the config value
  2767. *
  2768. * \snippet{doc} snippets.dox OrtStatus Return Value
  2769. */
  2770. ORT_API2_STATUS(AddRunConfigEntry, _Inout_ OrtRunOptions* options,
  2771. _In_z_ const char* config_key, _In_z_ const char* config_value);
  2772. /// @}
  2773. /// \name OrtPrepackedWeightsContainer
  2774. /// @{
  2775. /** \brief Create an ::OrtPrepackedWeightsContainer
  2776. *
  2777. * This container will hold pre-packed buffers of shared initializers for sharing between sessions
  2778. * (i.e.) if there are shared initializers that can be shared between sessions, the pre-packed buffers
  2779. * of these (if any) may possibly be shared to provide memory footprint savings. Pass this container
  2780. * to sessions that you would like to share pre-packed buffers of shared initializers at session
  2781. * creation time.
  2782. *
  2783. * \param[out] out Newly created ::OrtPrepackedWeightsContainer. Must be freed with OrtApi::ReleasePrepackedWeightsContainer
  2784. *
  2785. * \snippet{doc} snippets.dox OrtStatus Return Value
  2786. */
  2787. ORT_API2_STATUS(CreatePrepackedWeightsContainer, _Outptr_ OrtPrepackedWeightsContainer** out);
  2788. /** \brief Release OrtPrepackedWeightsContainer instance
  2789. *
  2790. * \note instance must not be released until the sessions using it are released
  2791. */
  2792. ORT_CLASS_RELEASE(PrepackedWeightsContainer);
  2793. /// @}
  2794. /// \name OrtSession
  2795. /// @{
  2796. /** \brief Create session with prepacked weights container
  2797. *
  2798. * Same functionality offered by OrtApi::CreateSession except that a container that contains
  2799. * pre-packed weights' buffers is written into/read from by the created session.
  2800. * This is useful when used in conjunction with OrtApi::AddInitializer which injects
  2801. * shared initializer info into sessions. Wherever possible, the pre-packed versions of these
  2802. * shared initializers are cached in this container so that multiple sessions can just re-use
  2803. * these instead of duplicating these in memory.
  2804. *
  2805. * \param[in] env OrtEnv instance instance
  2806. * \param[in] model_path Null terminated string of the path (wchar on Windows, char otherwise)
  2807. * \param[in] options
  2808. * \param[in] prepacked_weights_container
  2809. * \param[out] out Newly created ::OrtSession. Must be freed with OrtApi::ReleaseSession
  2810. *
  2811. * \snippet{doc} snippets.dox OrtStatus Return Value
  2812. */
  2813. ORT_API2_STATUS(CreateSessionWithPrepackedWeightsContainer, _In_ const OrtEnv* env, _In_ const ORTCHAR_T* model_path,
  2814. _In_ const OrtSessionOptions* options,
  2815. _Inout_ OrtPrepackedWeightsContainer* prepacked_weights_container,
  2816. _Outptr_ OrtSession** out);
  2817. /** \brief Create session from memory with prepacked weights container
  2818. *
  2819. * Same functionality offered by OrtApi::CreateSessionFromArray except that a container that contains
  2820. * pre-packed weights' buffers is written into/read from by the created session.
  2821. * This is useful when used in conjunction with OrtApi::AddInitializer which injects
  2822. * shared initializer info into sessions. Wherever possible, the pre-packed versions of these
  2823. * shared initializers are cached in this container so that multiple sessions can just re-use
  2824. * these instead of duplicating these in memory.
  2825. *
  2826. * \param[in] env
  2827. * \param[in] model_data Array of bytes holding the model
  2828. * \param[in] model_data_length Number of bytes in `model_data_model`
  2829. * \param[in] options
  2830. * \param[in] prepacked_weights_container
  2831. * \param[out] out Newly created ::OrtSession. Must be freed with OrtApi::ReleaseSession
  2832. *
  2833. * \snippet{doc} snippets.dox OrtStatus Return Value
  2834. */
  2835. ORT_API2_STATUS(CreateSessionFromArrayWithPrepackedWeightsContainer, _In_ const OrtEnv* env,
  2836. _In_ const void* model_data, size_t model_data_length,
  2837. _In_ const OrtSessionOptions* options,
  2838. _Inout_ OrtPrepackedWeightsContainer* prepacked_weights_container,
  2839. _Outptr_ OrtSession** out);
  2840. /// @}
  2841. /// \name OrtSessionOptions
  2842. /// @{
  2843. /** \brief Append TensorRT execution provider to the session options
  2844. *
  2845. * If TensorRT is not available (due to a non TensorRT enabled build), this function will return failure.
  2846. *
  2847. * This is slightly different from OrtApi::SessionOptionsAppendExecutionProvider_TensorRT, it takes an
  2848. * ::OrtTensorRTProviderOptions which is publicly defined. This takes an opaque ::OrtTensorRTProviderOptionsV2
  2849. * which must be created with OrtApi::CreateTensorRTProviderOptions.
  2850. *
  2851. * For OrtApi::SessionOptionsAppendExecutionProvider_TensorRT, the user needs to instantiate ::OrtTensorRTProviderOptions
  2852. * as well as allocate/release buffers for some members of ::OrtTensorRTProviderOptions.
  2853. * Here, OrtApi::CreateTensorRTProviderOptions and Ortapi::ReleaseTensorRTProviderOptions will do the memory management for you.
  2854. *
  2855. * \param[in] options
  2856. * \param[in] tensorrt_options
  2857. *
  2858. * \snippet{doc} snippets.dox OrtStatus Return Value
  2859. */
  2860. ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_TensorRT_V2,
  2861. _In_ OrtSessionOptions* options, _In_ const OrtTensorRTProviderOptionsV2* tensorrt_options);
  2862. /// @}
  2863. /// \name OrtTensorRTProviderOptionsV2
  2864. /// @{
  2865. /** \brief Create an OrtTensorRTProviderOptionsV2
  2866. *
  2867. * \param[out] out Newly created ::OrtTensorRTProviderOptionsV2. Must be released with OrtApi::ReleaseTensorRTProviderOptions
  2868. *
  2869. * \snippet{doc} snippets.dox OrtStatus Return Value
  2870. */
  2871. ORT_API2_STATUS(CreateTensorRTProviderOptions, _Outptr_ OrtTensorRTProviderOptionsV2** out);
  2872. /** \brief Set options in a TensorRT Execution Provider.
  2873. *
  2874. * Please refer to https://onnxruntime.ai/docs/execution-providers/TensorRT-ExecutionProvider.html#cc
  2875. * to know the available keys and values. Key should be in null terminated string format of the member of ::OrtTensorRTProviderOptionsV2
  2876. * and value should be its related range. Recreates the options and only sets the supplied values.
  2877. *
  2878. * For example, key="trt_max_workspace_size" and value="2147483648"
  2879. *
  2880. * \param[in] tensorrt_options
  2881. * \param[in] provider_options_keys Array of UTF-8 null-terminated string for provider options keys
  2882. * \param[in] provider_options_values Array of UTF-8 null-terminated string for provider options values
  2883. * \param[in] num_keys Number of elements in the `provider_option_keys` and `provider_options_values` arrays
  2884. *
  2885. * \snippet{doc} snippets.dox OrtStatus Return Value
  2886. */
  2887. ORT_API2_STATUS(UpdateTensorRTProviderOptions, _Inout_ OrtTensorRTProviderOptionsV2* tensorrt_options,
  2888. _In_reads_(num_keys) const char* const* provider_options_keys,
  2889. _In_reads_(num_keys) const char* const* provider_options_values,
  2890. _In_ size_t num_keys);
  2891. /** \brief Get serialized TensorRT provider options string.
  2892. *
  2893. * For example, "trt_max_workspace_size=2147483648;trt_max_partition_iterations=10;trt_int8_enable=1;......"
  2894. *
  2895. * \param tensorrt_options - OrtTensorRTProviderOptionsV2 instance
  2896. * \param allocator - a ptr to an instance of OrtAllocator obtained with OrtApi::CreateAllocator or OrtApi::GetAllocatorWithDefaultOptions
  2897. * the specified allocator will be used to allocate continuous buffers for output strings and lengths.
  2898. * \param ptr - is a UTF-8 null terminated string allocated using 'allocator'. The caller is responsible for using the same allocator to free it.
  2899. *
  2900. * \snippet{doc} snippets.dox OrtStatus Return Value
  2901. */
  2902. ORT_API2_STATUS(GetTensorRTProviderOptionsAsString, _In_ const OrtTensorRTProviderOptionsV2* tensorrt_options, _Inout_ OrtAllocator* allocator, _Outptr_ char** ptr);
  2903. /** \brief Release an ::OrtTensorRTProviderOptionsV2
  2904. *
  2905. * \note This is an exception in the naming convention of other Release* functions, as the name of the method does not have the V2 suffix, but the type does
  2906. */
  2907. void(ORT_API_CALL* ReleaseTensorRTProviderOptions)(_Frees_ptr_opt_ OrtTensorRTProviderOptionsV2* input);
  2908. /// @}
  2909. /// \name OrtSessionOptions
  2910. /// @{
  2911. /** \brief Enable custom operators
  2912. *
  2913. * See onnxruntime-extensions: https://github.com/microsoft/onnxruntime-extensions.git
  2914. *
  2915. * \snippet{doc} snippets.dox OrtStatus Return Value
  2916. */
  2917. ORT_API2_STATUS(EnableOrtCustomOps, _Inout_ OrtSessionOptions* options);
  2918. /// @}
  2919. /// \name OrtAllocator
  2920. /// @{
  2921. /** \brief Register a custom allocator
  2922. *
  2923. * Enables sharing between multiple sessions that use the same env instance.
  2924. * Returns an error if an allocator with the same ::OrtMemoryInfo is already registered.
  2925. *
  2926. * The behavior of this is exactly the same as OrtApi::CreateAndRegisterAllocator except
  2927. * instead of ORT creating an allocator based on provided info, in this case
  2928. * ORT uses the user-provided custom allocator.
  2929. * See https://onnxruntime.ai/docs/get-started/with-c.html for details.
  2930. *
  2931. * \param[in] env
  2932. * \param[in] allocator User provided allocator
  2933. *
  2934. * \snippet{doc} snippets.dox OrtStatus Return Value
  2935. */
  2936. ORT_API2_STATUS(RegisterAllocator, _Inout_ OrtEnv* env, _In_ OrtAllocator* allocator);
  2937. /** \brief Unregister a custom allocator
  2938. *
  2939. * It is an error if you provide an ::OrtMemoryInfo not corresponding to any
  2940. * registered allocators for sharing.
  2941. *
  2942. * \param[in] env
  2943. * \param[in] mem_info
  2944. *
  2945. * \snippet{doc} snippets.dox OrtStatus Return Value
  2946. */
  2947. ORT_API2_STATUS(UnregisterAllocator, _Inout_ OrtEnv* env,
  2948. _In_ const OrtMemoryInfo* mem_info);
  2949. /// @}
  2950. /// \name OrtValue
  2951. /// @{
  2952. /** \brief Sets *out to 1 iff an ::OrtValue is a SparseTensor, and 0 otherwise
  2953. *
  2954. * \param[in] value existing ::OrtValue
  2955. * \param[out] out unless an error occurs, contains 1 iff the value contains an instance
  2956. * of sparse tensor or 0 otherwise.
  2957. *
  2958. * \snippet{doc} snippets.dox OrtStatus Return Value
  2959. */
  2960. ORT_API2_STATUS(IsSparseTensor, _In_ const OrtValue* value, _Out_ int* out);
  2961. /** \brief Create an ::OrtValue with a sparse tensor that is empty.
  2962. *
  2963. * Use FillSparseTensor<Format>() functions to populate sparse tensor with non-zero values and
  2964. * format specific indices data.
  2965. * Use ReleaseValue to destroy the sparse tensor, this will also release the buffer inside the output value
  2966. * if any was allocated.
  2967. * \param[in,out] allocator allocator to use when performing an allocation. Allocation will be performed
  2968. * by FillSparseTensor<Format>() APIs. The lifespan of the allocator instance must eclipse the lifespan
  2969. * this sparse tensor instance as the same allocator will be used to free memory.
  2970. * \param[in] dense_shape shape of the original dense tensor
  2971. * \param[in] dense_shape_len number of shape dimensions being passed
  2972. * \param[in] type must be one of TENSOR_ELEMENT_DATA_TYPE_xxxx
  2973. * \param[out] out Should be freed by calling ReleaseValue
  2974. *
  2975. * \snippet{doc} snippets.dox OrtStatus Return Value
  2976. */
  2977. ORT_API2_STATUS(CreateSparseTensorAsOrtValue, _Inout_ OrtAllocator* allocator, _In_ const int64_t* dense_shape,
  2978. size_t dense_shape_len, ONNXTensorElementDataType type, _Outptr_ OrtValue** out);
  2979. /**
  2980. * This fills populates an empty tensor that was created using OrtApi::CreateSparseTensorAsOrtValue.
  2981. * This will allocate required memory and copy the supplied NNZ values and COO indices into that memory allocation.
  2982. * Memory allocation is performed using the allocator that was specified with OrtApi::CreateSparseTensorAsOrtValue.
  2983. *
  2984. * \param[in,out] ort_value ::OrtValue to populate with data
  2985. * \param[in] data_mem_info serves to identify the location of the data to be copied. If the allocator specified
  2986. * at the creation time has memory info that is not the same as mem_info argument to this function a X-device copy will be performed.
  2987. * String data is assumed to be on CPU and will only be copied into a CPU allocated buffer.
  2988. * \param[in] values_shape pointer to values shape array
  2989. * \param[in] values_shape_len length of the values_shape
  2990. * \param[in] values pointer to an array of values. For strings, pass const char**.
  2991. * \param[in] indices_data pointer to a location of COO indices
  2992. * \param[in] indices_num number of COO indices
  2993. *
  2994. * \snippet{doc} snippets.dox OrtStatus Return Value
  2995. */
  2996. ORT_API2_STATUS(FillSparseTensorCoo, _Inout_ OrtValue* ort_value, _In_ const OrtMemoryInfo* data_mem_info,
  2997. _In_ const int64_t* values_shape, size_t values_shape_len, _In_ const void* values,
  2998. _In_ const int64_t* indices_data, size_t indices_num);
  2999. /**
  3000. * This fills populates an empty tensor that was created using OrtApi::CreateSparseTensorAsOrtValue.
  3001. * This will allocate required memory and copy the supplied NNZ values and CSR indices into that memory allocation.
  3002. * Memory allocation is performed using the allocator that was specified with OrtApi::CreateSparseTensorAsOrtValue.
  3003. *
  3004. * \param[in,out] ort_value ::OrtValue to populate with data
  3005. * \param[in] data_mem_info serves to identify the location of the data to be copied. If the allocator specified
  3006. * at the creation time has memory info that is not the same as mem_info argument to this function a X-device copy will be performed.
  3007. * String data is assumed to be on CPU and will only be copied into a CPU allocated buffer.
  3008. * \param[in] values_shape pointer to values shape array
  3009. * \param[in] values_shape_len length of the values_shape
  3010. * \param[in] values - pointer to an array of values. For strings, pass const char**.
  3011. * \param[in] inner_indices_data pointer to a location of CSR inner indices
  3012. * \param[in] inner_indices_num number of CSR inner indices
  3013. * \param[in] outer_indices_data pointer to a location of CSR outer indices
  3014. * \param[in] outer_indices_num number of CSR outer indices
  3015. *
  3016. * \snippet{doc} snippets.dox OrtStatus Return Value
  3017. */
  3018. ORT_API2_STATUS(FillSparseTensorCsr, _Inout_ OrtValue* ort_value, _In_ const OrtMemoryInfo* data_mem_info,
  3019. _In_ const int64_t* values_shape, size_t values_shape_len, _In_ const void* values,
  3020. _In_ const int64_t* inner_indices_data, size_t inner_indices_num,
  3021. _In_ const int64_t* outer_indices_data, size_t outer_indices_num);
  3022. /**
  3023. * This fills populates an empty tensor that was created using OrtApi::CreateSparseTensorAsOrtValue.
  3024. * This will allocate required memory and copy the supplied NNZ values and BlockSparse indices into that memory allocation.
  3025. * Memory allocation is performed using the allocator that was specified with OrtApi::CreateSparseTensorAsOrtValue.
  3026. *
  3027. * \param[in,out] ort_value ::OrtValue to populate with data
  3028. * \param[in] data_mem_info serves to identify the location of the data to be copied. If the allocator specified
  3029. * at the creation time has memory info that is not the same as mem_info argument to this function a X-device copy will be performed.
  3030. * String data is assumed to be on CPU and will only be copied into a CPU allocated buffer.
  3031. * \param[in] values_shape
  3032. * \param[in] values_shape_len
  3033. * \param[in] values structure with values information
  3034. * \param[in] indices_shape_data pointer to a location of indices shape
  3035. * \param[in] indices_shape_len length of the block sparse indices shape
  3036. * \param[in] indices_data pointer to a location of indices data. Shape will determine the length of the indices data.
  3037. *
  3038. * \snippet{doc} snippets.dox OrtStatus Return Value
  3039. */
  3040. ORT_API2_STATUS(FillSparseTensorBlockSparse, _Inout_ OrtValue* ort_value, _In_ const OrtMemoryInfo* data_mem_info,
  3041. _In_ const int64_t* values_shape, size_t values_shape_len, _In_ const void* values,
  3042. _In_ const int64_t* indices_shape_data, size_t indices_shape_len,
  3043. _In_ const int32_t* indices_data);
  3044. /**
  3045. * Create an ::OrtValue with a sparse tensor. This is the first step.
  3046. * Next, use Use<Format>Indices() functions to supply sparse tensor with
  3047. * format specific indices data and set its sparse format to a specific enum value.
  3048. * This will not perform memory allocations. It will
  3049. * use supplied user buffer which should outlive the created sparse tensor.
  3050. * Use OrtApi::ReleaseValue to destroy the sparse tensor. It would not release the supplied values buffer.
  3051. * This function can not be used to map strings from the user allocated memory. Strings must always be copied
  3052. * and have UTF-8 encoding. Therefore, use OrtApi::CreateSparseTensorAsOrtValue above and then fill it with data
  3053. * using appropriate Make*() function.
  3054. *
  3055. * \param[in] info memory info where sparse values reside.
  3056. * \param[in,out] p_data pointer to a user allocated buffer with values. To create a full sparse tensor with no non-zero
  3057. * values, pass nullptr
  3058. * \param[in] dense_shape shape of the original dense tensor
  3059. * \param[in] dense_shape_len number of shape dimensions being passed
  3060. * \param[in] values_shape shape of the values data. To create a fully sparse tensor with no non-zero values,
  3061. * pass {0} shape.
  3062. * \param[in] values_shape_len number of values shape dimensions
  3063. * \param[in] type must be one of TENSOR_ELEMENT_DATA_TYPE_xxxx
  3064. * \param[out] out Should be freed by calling ReleaseValue
  3065. *
  3066. * \snippet{doc} snippets.dox OrtStatus Return Value
  3067. */
  3068. ORT_API2_STATUS(CreateSparseTensorWithValuesAsOrtValue, _In_ const OrtMemoryInfo* info, _Inout_ void* p_data,
  3069. _In_ const int64_t* dense_shape, size_t dense_shape_len,
  3070. _In_ const int64_t* values_shape, size_t values_shape_len,
  3071. ONNXTensorElementDataType type, _Outptr_ OrtValue** out);
  3072. /**
  3073. * This assigns Coo format indices to the SparseTensor that was created by
  3074. * OrtApi::CreateSparseTensorWithValuesAsOrtValue above. It also sets OrtSparseFormat to
  3075. * ORT_SPARSE_COO. This will not allocate any additional memory for data. The life span of
  3076. * indices_data buffer should eclipse the life span of this ::OrtValue.
  3077. *
  3078. * \param[in,out] ort_value ::OrtValue instance constructed with OrtApi::CreateSparseTensorWithValuesAsOrtValue
  3079. * \param[in,out] indices_data pointer to a user pre-allocated buffer or nullptr for fully sparse tensors.
  3080. * \param[in] indices_num number of COO indices. Should either be 0 for fully sparse tensors, be equal
  3081. * to the number of nnz values specified to OrtApi::CreateSparseTensorWithValuesAsOrtValue for 1-D {nnz} indices or
  3082. * be twice as number of nnz values for a 2-D indices {nnz, 2}
  3083. *
  3084. * \snippet{doc} snippets.dox OrtStatus Return Value
  3085. */
  3086. ORT_API2_STATUS(UseCooIndices, _Inout_ OrtValue* ort_value, _Inout_ int64_t* indices_data, size_t indices_num);
  3087. /**
  3088. * The assigns CSR format indices to the SparseTensor that was created by
  3089. * OrtApi::CreateSparseTensorWithValuesAsOrtValue above. It also sets OrtSparseFormat to
  3090. * ORT_SPARSE_CSRC. This will not allocate any additional memory for data. The life spans of
  3091. * inner_data and outer_data buffers should eclipse the life span of this ::OrtValue.
  3092. *
  3093. * \param[in,out] ort_value ::OrtValue instance constructed with OrtApi::CreateSparseTensorWithValuesAsOrtValue
  3094. * \param[in,out] inner_data pointer to a user pre-allocated buffer or nullptr for fully sparse tensors.
  3095. * \param[in] inner_num number of inner CSR indices. Should either be 0 for fully sparse tensors or be equal
  3096. * to the number of nnz values specified to OrtApi::CreateSparseTensorWithValuesAsOrtValue.
  3097. * \param[in,out] outer_data pointer to user pre-allocated buffer or nullptr for fully sparse tensors.
  3098. * \param[in] outer_num number of CSR outer indices. Should either be 0 for fully sparse tensors or
  3099. * equal to rows + 1 of the dense shape.
  3100. *
  3101. * \snippet{doc} snippets.dox OrtStatus Return Value
  3102. */
  3103. ORT_API2_STATUS(UseCsrIndices, _Inout_ OrtValue* ort_value, _Inout_ int64_t* inner_data, size_t inner_num,
  3104. _Inout_ int64_t* outer_data, size_t outer_num);
  3105. /**
  3106. * The assigns BlockSparse format indices to the SparseTensor that was created by
  3107. * OrtApi::CreateSparseTensorWithValuesAsOrtValue above. It also sets OrtSparseFormat to
  3108. * ORT_SPARSE_BLOCK_SPARSE. This will not allocate any additional memory for data. The life span of
  3109. * indices_data buffer must eclipse the lifespan of this ::OrtValue.
  3110. *
  3111. * \param[in,out] ort_value OrtValue instance constructed with OrtApi::CreateSparseTensorWithValuesAsOrtValue
  3112. * \param[in] indices_shape pointer to indices shape. Use {0} for fully sparse tensors
  3113. * \param[in] indices_shape_len length of the indices shape
  3114. * \param[in,out] indices_data pointer to user pre-allocated buffer or nullptr for fully sparse tensors.
  3115. *
  3116. * \snippet{doc} snippets.dox OrtStatus Return Value
  3117. */
  3118. ORT_API2_STATUS(UseBlockSparseIndices, _Inout_ OrtValue* ort_value, const int64_t* indices_shape, size_t indices_shape_len, _Inout_ int32_t* indices_data);
  3119. /** \brief Returns sparse tensor format enum iff a given ort value contains an instance of sparse tensor.
  3120. *
  3121. * \param[in] ort_value ::OrtValue that contains an instance of sparse tensor
  3122. * \param[out] out pointer to out parameter
  3123. *
  3124. * \snippet{doc} snippets.dox OrtStatus Return Value
  3125. */
  3126. ORT_API2_STATUS(GetSparseTensorFormat, _In_ const OrtValue* ort_value, _Out_ enum OrtSparseFormat* out);
  3127. /** \brief Returns data type and shape of sparse tensor values (nnz) iff ::OrtValue contains a SparseTensor.
  3128. *
  3129. * \param[in] ort_value An ::OrtValue that contains a fully constructed sparse tensor
  3130. * \param[out] out Must be freed by OrtApi::ReleaseTensorTypeAndShapeInfo
  3131. *
  3132. * \snippet{doc} snippets.dox OrtStatus Return Value
  3133. */
  3134. ORT_API2_STATUS(GetSparseTensorValuesTypeAndShape, _In_ const OrtValue* ort_value, _Outptr_ OrtTensorTypeAndShapeInfo** out);
  3135. /** \brief Returns numeric data for sparse tensor values (nnz). For string values use GetStringTensor*().
  3136. *
  3137. * \param[in] ort_value an instance of ::OrtValue containing sparse tensor
  3138. * \param[out] out returns a pointer to values data. Do not attempt to free this ptr.
  3139. *
  3140. * \snippet{doc} snippets.dox OrtStatus Return Value
  3141. */
  3142. ORT_API2_STATUS(GetSparseTensorValues, _In_ const OrtValue* ort_value, _Outptr_ const void** out);
  3143. /** \brief Returns data type, shape for the type of indices specified by indices_format.
  3144. *
  3145. * \param[in] ort_value ::OrtValue containing sparse tensor.
  3146. * \param[in] indices_format One of the indices formats. It is an error to request a format that the sparse
  3147. * tensor does not contain.
  3148. * \param[out] out an instance of ::OrtTensorTypeAndShapeInfo. Must be freed by OrtApi::ReleaseTensorTypeAndShapeInfo
  3149. *
  3150. * \snippet{doc} snippets.dox OrtStatus Return Value
  3151. */
  3152. ORT_API2_STATUS(GetSparseTensorIndicesTypeShape, _In_ const OrtValue* ort_value, enum OrtSparseIndicesFormat indices_format, _Outptr_ OrtTensorTypeAndShapeInfo** out);
  3153. /** \brief Returns indices data for the type of the indices specified by indices_format
  3154. *
  3155. * \param[in] ort_value ::OrtValue containing sparse tensor.
  3156. * \param[in] indices_format One of the indices formats. It is an error to request a format that the sparse tensor does not contain.
  3157. * \param[out] num_indices Pointer to where the number of indices entries is returned
  3158. * \param[out] indices Returned pointer to the indices data. Do not free the returned pointer as it refers to internal data owned by the ::OrtValue
  3159. *
  3160. * \snippet{doc} snippets.dox OrtStatus Return Value
  3161. */
  3162. ORT_API2_STATUS(GetSparseTensorIndices, _In_ const OrtValue* ort_value, enum OrtSparseIndicesFormat indices_format, _Out_ size_t* num_indices, _Outptr_ const void** indices);
  3163. /// @}
  3164. /// \name OrtSessionOptions
  3165. /// @{
  3166. /**
  3167. * \brief Sets out to 1 iff an optional type OrtValue has an element, 0 otherwise (OrtValue is None)
  3168. * Use this API to find if the optional type OrtValue is None or not.
  3169. * If the optional type OrtValue is not None, use the OrtValue just like any other OrtValue.
  3170. * For example, if you get an OrtValue that corresponds to Optional(tensor) and
  3171. * if HasValue() returns true, use it as tensor and so on.
  3172. * \param[in] value Input OrtValue.
  3173. * \param[out] out indicating if the input OrtValue contains data (1) or if it is a None (0)
  3174. *
  3175. * \snippet{doc} snippets.dox OrtStatus Return Value
  3176. */
  3177. ORT_API2_STATUS(HasValue, _In_ const OrtValue* value, _Out_ int* out);
  3178. /// @}
  3179. /// \name OrtKernelContext
  3180. /// Custom operator APIs.
  3181. /// @{
  3182. /** \brief Used for custom operators, gets the GPU compute stream to use to launch the custom a GPU kernel
  3183. * \see ::OrtCustomOp
  3184. * \param[in] context OrtKernelContext instance
  3185. * \param[out] out Returns pointer to a GPU compute stream that can be used to launch the custom GPU kernel.
  3186. * If retrieving the GPU compute stream is not relevant (GPU not enabled in the build, kernel partitioned to
  3187. * some other EP), then a nullptr is returned as the output param.
  3188. * Do not free or mutate the returned pointer as it refers to internal data owned by the underlying session.
  3189. * Only use it for custom kernel launching.
  3190. *
  3191. * \snippet{doc} snippets.dox OrtStatus Return Value
  3192. */
  3193. ORT_API2_STATUS(KernelContext_GetGPUComputeStream, _In_ const OrtKernelContext* context, _Outptr_ void** out);
  3194. /// @}
  3195. /// \name GetTensorMemoryInfo
  3196. /// @{
  3197. /** \brief Returns a pointer to the ::OrtMemoryInfo of a Tensor
  3198. * \param[in] value ::OrtValue containing tensor.
  3199. * \param[out] mem_info ::OrtMemoryInfo of the tensor. Do NOT free the returned pointer. It is valid for the lifetime of the ::OrtValue
  3200. *
  3201. * \snippet{doc} snippets.dox OrtStatus Return Value
  3202. */
  3203. ORT_API2_STATUS(GetTensorMemoryInfo, _In_ const OrtValue* value, _Out_ const OrtMemoryInfo** mem_info);
  3204. /// @}
  3205. /// \name GetExecutionProviderApi
  3206. /// @{
  3207. /** \brief Get a pointer to the requested version of the Execution Provider specific
  3208. * API extensions to the OrtApi
  3209. * \param[in] provider_name The name of the execution provider name. Currently only the following
  3210. * values are supported: "DML".
  3211. * \param[in] version Must be ::ORT_API_VERSION.
  3212. * \param[out] provider_api A void pointer containing a reference to the execution provider versioned api structure.
  3213. * For example, the provider_api pointer can be cast to the OrtDmlApi* when the provider_name is "DML".
  3214. *
  3215. * \snippet{doc} snippets.dox OrtStatus Return Value
  3216. */
  3217. ORT_API2_STATUS(GetExecutionProviderApi, _In_ const char* provider_name, _In_ uint32_t version, _Outptr_ const void** provider_api);
  3218. /// @}
  3219. /// \name SessionOptions
  3220. /// @{
  3221. /** \brief Set custom thread creation function
  3222. *
  3223. * \param[in] options Session options
  3224. * \param[in] ort_custom_create_thread_fn Custom thread creation function
  3225. *
  3226. * \snippet{doc} snippets.dox OrtStatus Return Value
  3227. */
  3228. ORT_API2_STATUS(SessionOptionsSetCustomCreateThreadFn, _Inout_ OrtSessionOptions* options, _In_ OrtCustomCreateThreadFn ort_custom_create_thread_fn);
  3229. /** \brief Set creation options for custom thread
  3230. *
  3231. * \param[in] options Session options
  3232. * \param[in] ort_custom_thread_creation_options Custom thread creation options (can be nullptr)
  3233. *
  3234. * \snippet{doc} snippets.dox OrtStatus Return Value
  3235. */
  3236. ORT_API2_STATUS(SessionOptionsSetCustomThreadCreationOptions, _Inout_ OrtSessionOptions* options, _In_ void* ort_custom_thread_creation_options);
  3237. /** \brief Set custom thread join function
  3238. *
  3239. * \param[in] options Session options
  3240. * \param[in] ort_custom_join_thread_fn Custom join thread function, must not be nullptr when ort_custom_create_thread_fn is set
  3241. *
  3242. * \snippet{doc} snippets.dox OrtStatus Return Value
  3243. */
  3244. ORT_API2_STATUS(SessionOptionsSetCustomJoinThreadFn, _Inout_ OrtSessionOptions* options, _In_ OrtCustomJoinThreadFn ort_custom_join_thread_fn);
  3245. /// @}
  3246. /// \name OrtThreadingOptions
  3247. /// @{
  3248. /** \brief Set custom thread creation function for global thread pools
  3249. *
  3250. * \param[inout] tp_options
  3251. * \param[in] ort_custom_create_thread_fn Custom thread creation function
  3252. *
  3253. * \snippet{doc} snippets.dox OrtStatus Return Value
  3254. */
  3255. ORT_API2_STATUS(SetGlobalCustomCreateThreadFn, _Inout_ OrtThreadingOptions* tp_options, _In_ OrtCustomCreateThreadFn ort_custom_create_thread_fn);
  3256. /** \brief Set custom thread creation options for global thread pools
  3257. *
  3258. * \param[inout] tp_options
  3259. * \param[in] ort_custom_thread_creation_options Custom thread creation options (can be nullptr)
  3260. *
  3261. * \snippet{doc} snippets.dox OrtStatus Return Value
  3262. */
  3263. ORT_API2_STATUS(SetGlobalCustomThreadCreationOptions, _Inout_ OrtThreadingOptions* tp_options, _In_ void* ort_custom_thread_creation_options);
  3264. /** \brief Set custom thread join function for global thread pools
  3265. *
  3266. * \param[inout] tp_options
  3267. * \param[in] ort_custom_join_thread_fn Custom thread join function, must not be nullptr when global ort_custom_create_thread_fn is set
  3268. *
  3269. * \snippet{doc} snippets.dox OrtStatus Return Value
  3270. */
  3271. ORT_API2_STATUS(SetGlobalCustomJoinThreadFn, _Inout_ OrtThreadingOptions* tp_options, _In_ OrtCustomJoinThreadFn ort_custom_join_thread_fn);
  3272. /// @}
  3273. /** \brief Synchronize bound inputs. The call may be necessary for some providers, such as cuda,
  3274. * in case the system that allocated bound memory operated on a different stream. However, the
  3275. * operation is provider specific and could be a no-op.
  3276. *
  3277. * \param[inout] binding_ptr
  3278. *
  3279. * \snippet{doc} snippets.dox OrtStatus Return Value
  3280. */
  3281. ORT_API2_STATUS(SynchronizeBoundInputs, _Inout_ OrtIoBinding* binding_ptr);
  3282. /** \brief Synchronize bound outputs. The call may be necessary for some providers, such as cuda,
  3283. * in case the system that allocated bound memory operated on a different stream. However, the
  3284. * operation is provider specific and could be a no-op.
  3285. *
  3286. * \param[inout] binding_ptr
  3287. *
  3288. * \snippet{doc} snippets.dox OrtStatus Return Value
  3289. */
  3290. ORT_API2_STATUS(SynchronizeBoundOutputs, _Inout_ OrtIoBinding* binding_ptr);
  3291. /// \name OrtSessionOptions
  3292. /// @{
  3293. /** \brief Append CUDA execution provider to the session options
  3294. *
  3295. * If CUDA is not available (due to a non CUDA enabled build), this function will return failure.
  3296. *
  3297. * This is slightly different from OrtApi::SessionOptionsAppendExecutionProvider_CUDA, it takes an
  3298. * ::OrtCUDAProviderOptions which is publicly defined. This takes an opaque ::OrtCUDAProviderOptionsV2
  3299. * which must be created with OrtApi::CreateCUDAProviderOptions.
  3300. *
  3301. * For OrtApi::SessionOptionsAppendExecutionProvider_CUDA, the user needs to instantiate ::OrtCUDAProviderOptions
  3302. * as well as allocate/release buffers for some members of ::OrtCUDAProviderOptions.
  3303. * Here, OrtApi::CreateCUDAProviderOptions and Ortapi::ReleaseCUDAProviderOptions will do the memory management for you.
  3304. *
  3305. * \param[in] options
  3306. * \param[in] cuda_options
  3307. *
  3308. * \snippet{doc} snippets.dox OrtStatus Return Value
  3309. *
  3310. * \since Version 1.11.
  3311. */
  3312. ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_CUDA_V2,
  3313. _In_ OrtSessionOptions* options, _In_ const OrtCUDAProviderOptionsV2* cuda_options);
  3314. /// @}
  3315. /// \name OrtCUDAProviderOptionsV2
  3316. /// @{
  3317. /** \brief Create an OrtCUDAProviderOptionsV2
  3318. *
  3319. * \param[out] out Newly created ::OrtCUDAProviderOptionsV2. Must be released with OrtApi::ReleaseCudaProviderOptions
  3320. *
  3321. * \snippet{doc} snippets.dox OrtStatus Return Value
  3322. *
  3323. * \since Version 1.11.
  3324. */
  3325. ORT_API2_STATUS(CreateCUDAProviderOptions, _Outptr_ OrtCUDAProviderOptionsV2** out);
  3326. /** \brief Set options in a CUDA Execution Provider.
  3327. *
  3328. * Please refer to https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html#configuration-options
  3329. * to know the available keys and values. Key should be in null terminated string format of the member of ::OrtCUDAProviderOptionsV2
  3330. * and value should be its related range. Recreates the options and only sets the supplied values.
  3331. *
  3332. * For example, key="device_id" and value="0"
  3333. *
  3334. * \param[in] cuda_options
  3335. * \param[in] provider_options_keys Array of UTF-8 null-terminated string for provider options keys
  3336. * \param[in] provider_options_values Array of UTF-8 null-terminated string for provider options values
  3337. * \param[in] num_keys Number of elements in the `provider_option_keys` and `provider_options_values` arrays
  3338. *
  3339. * \snippet{doc} snippets.dox OrtStatus Return Value
  3340. *
  3341. * \since Version 1.11.
  3342. */
  3343. ORT_API2_STATUS(UpdateCUDAProviderOptions, _Inout_ OrtCUDAProviderOptionsV2* cuda_options,
  3344. _In_reads_(num_keys) const char* const* provider_options_keys,
  3345. _In_reads_(num_keys) const char* const* provider_options_values,
  3346. _In_ size_t num_keys);
  3347. /**
  3348. * Get serialized CUDA provider options string.
  3349. *
  3350. * For example, "device_id=0;arena_extend_strategy=0;......"
  3351. *
  3352. * \param cuda_options - OrtCUDAProviderOptionsV2 instance
  3353. * \param allocator - a ptr to an instance of OrtAllocator obtained with CreateAllocator() or GetAllocatorWithDefaultOptions()
  3354. * the specified allocator will be used to allocate continuous buffers for output strings and lengths.
  3355. * \param ptr - is a UTF-8 null terminated string allocated using 'allocator'. The caller is responsible for using the same allocator to free it.
  3356. *
  3357. * \snippet{doc} snippets.dox OrtStatus Return Value
  3358. *
  3359. * \since Version 1.11.
  3360. */
  3361. ORT_API2_STATUS(GetCUDAProviderOptionsAsString, _In_ const OrtCUDAProviderOptionsV2* cuda_options, _Inout_ OrtAllocator* allocator, _Outptr_ char** ptr);
  3362. /** \brief Release an ::OrtCUDAProviderOptionsV2
  3363. *
  3364. * \note This is an exception in the naming convention of other Release* functions, as the name of the method does not have the V2 suffix, but the type does
  3365. *
  3366. * \since Version 1.11.
  3367. */
  3368. void(ORT_API_CALL* ReleaseCUDAProviderOptions)(_Frees_ptr_opt_ OrtCUDAProviderOptionsV2* input);
  3369. /// @}
  3370. /** \brief Append MIGraphX provider to session options
  3371. *
  3372. * If MIGraphX is not available (due to a non MIGraphX enabled build, or if MIGraphX is not installed on the system), this function will return failure.
  3373. *
  3374. * \param[in] options
  3375. * \param[in] migraphx_options
  3376. *
  3377. * \snippet{doc} snippets.dox OrtStatus Return Value
  3378. *
  3379. * \since Version 1.11.
  3380. */
  3381. ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_MIGraphX,
  3382. _In_ OrtSessionOptions* options, _In_ const OrtMIGraphXProviderOptions* migraphx_options);
  3383. /** \brief Replace initialized Tensors with external data with the data provided in initializers.
  3384. *
  3385. * The function will find the initialized TensorProtos with external data in the graph with the provided names and
  3386. * replace them with the provided tensors. The API verifies that the TensorProto being replaced
  3387. * has an external data reference and has the same name, dimensions and data type as its replacement. The replacement
  3388. * will occur before any of the optimizations take place. The data will be copied into the graph
  3389. * since TensorProto can't refer to the user provided buffers.
  3390. *
  3391. * Once the model has been loaded, the OrtValue(s) added to SessionOptions instance will be removed
  3392. * from the internal SessionOptions copy to save memory, the user provided buffers can then be deallocated
  3393. * and the SessionOptions instance that refers to them can be destroyed.
  3394. *
  3395. * \param[in] options
  3396. * \param[in] initializer_names Array of null terminated UTF-8 encoded strings of the initializers names.
  3397. * \param[in] initializers Array of ::OrtValue type
  3398. * \param[in] num_initializers Number of elements in the initializer_names and initializers
  3399. *
  3400. * \snippet{doc} snippets.dox OrtStatus Return Value
  3401. *
  3402. * \since Version 1.12.
  3403. */
  3404. ORT_API2_STATUS(AddExternalInitializers, _In_ OrtSessionOptions* options,
  3405. _In_reads_(num_initializers) const char* const* initializer_names,
  3406. _In_reads_(num_initializers) const OrtValue* const* initializers, size_t num_initializers);
  3407. /** \brief: Create attribute of onnxruntime operator
  3408. *
  3409. * \param[in] name Name of the attribute
  3410. * \param[in] data Data content of the attribute
  3411. * \param[in] len Number of bytes stored in data for ORT_OP_ATTR_STRING.
  3412. Number of elements if data represents an array (e.g., ORT_OP_ATTR_INTS). Otherwise, set to 1.
  3413. * \param[in] type Data type
  3414. * \param[out] op_attr Attribute that has been created, which must be released by OrtApi::ReleaseOpAttr
  3415. *
  3416. * \since Version 1.12.
  3417. */
  3418. ORT_API2_STATUS(CreateOpAttr,
  3419. _In_ const char* name,
  3420. _In_ const void* data,
  3421. _In_ int len,
  3422. _In_ OrtOpAttrType type,
  3423. _Outptr_ OrtOpAttr** op_attr);
  3424. /* \brief: Release op attribute
  3425. *
  3426. * \param[in] opAttr Attribute created by OrtApi::CreateOpAttr
  3427. *
  3428. * \since Version 1.12.
  3429. */
  3430. ORT_CLASS_RELEASE(OpAttr);
  3431. /** \brief: Create onnxruntime native operator
  3432. *
  3433. * \param[in] info Kernel info
  3434. * \param[in] op_name Operator name
  3435. * \param[in] domain Operator domain
  3436. * \param[in] version Operator opset version
  3437. * \param[in] type_constraint_names Name of the type constraints, such as "T" or "T1"
  3438. * \param[in] type_constraint_values Type of each constraints
  3439. * \param[in] type_constraint_count Number of constraints
  3440. * \param[in] attr_values Attributes used to initialize the operator
  3441. * \param[in] attr_count Number of the attributes
  3442. * \param[in] input_count Number of inputs
  3443. * \param[in] output_count Number of outputs
  3444. * \param[out] ort_op Operator that has been created
  3445. *
  3446. * \since Version 1.12.
  3447. */
  3448. ORT_API2_STATUS(CreateOp,
  3449. _In_ const OrtKernelInfo* info,
  3450. _In_z_ const char* op_name,
  3451. _In_z_ const char* domain,
  3452. int version,
  3453. _In_reads_(type_constraint_count) const char** type_constraint_names,
  3454. _In_reads_(type_constraint_count) const ONNXTensorElementDataType* type_constraint_values,
  3455. int type_constraint_count,
  3456. _In_reads_(attr_count) const OrtOpAttr* const* attr_values,
  3457. int attr_count,
  3458. int input_count,
  3459. int output_count,
  3460. _Outptr_ OrtOp** ort_op);
  3461. /** \brief: Invoke the operator created by OrtApi::CreateOp
  3462. * The inputs must follow the order as specified in onnx specification
  3463. *
  3464. * \param[in] context Kernel context
  3465. * \param[in] ort_op Operator that has been created
  3466. * \param[in] input_values Array of inputs
  3467. * \param[in] input_count Number of inputs
  3468. * \param[in] output_values Array of outputs
  3469. * \param[in] output_count Number of outputs
  3470. *
  3471. * \since Version 1.12.
  3472. */
  3473. ORT_API2_STATUS(InvokeOp,
  3474. _In_ const OrtKernelContext* context,
  3475. _In_ const OrtOp* ort_op,
  3476. _In_ const OrtValue* const* input_values,
  3477. _In_ int input_count,
  3478. _Inout_ OrtValue* const* output_values,
  3479. _In_ int output_count);
  3480. /* \brief: Release an onnxruntime operator
  3481. *
  3482. * \param[in] Op Operator created by OrtApi::CreateOp
  3483. *
  3484. * \since Version 1.12.
  3485. */
  3486. ORT_CLASS_RELEASE(Op);
  3487. /** \brief: Append execution provider to the session options.
  3488. * \param[in] options
  3489. * \param[in] provider_name - provider to add.
  3490. * \param[in] provider_options_keys - keys to configure the provider options
  3491. * \param[in] provider_options_values - values to configure the provider options
  3492. * \param[in] num_keys - number of keys passed in
  3493. *
  3494. * Currently supported provider names:
  3495. * QNNExecutionProvider (or QNN)
  3496. * OpenVINOExecutionProvider (or OpenVINO)
  3497. * XnnpackExecutionProvider (or XNNPACK)
  3498. * WebNNExecutionProvider (or WEBNN)
  3499. * WebGpuExecutionProvider (or WebGPU)
  3500. * AzureExecutionProvider (or AZURE)
  3501. * JsExecutionProvider (or JS)
  3502. * VitisAIExecutionProvider (or VitisAI)
  3503. * CoreMLExecutionProvider (or CoreML)
  3504. *
  3505. * Note: If an execution provider has a dedicated SessionOptionsAppendExecutionProvider_<provider name> function
  3506. * that should be used to add it.
  3507. *
  3508. * QNN supported keys:
  3509. * "backend_type": Type of QNN backend. Specifies a backend path that is the associated QNN backend library file
  3510. * name. E.g., given backend type "htp", on Windows, the backend path would be "QnnHtp.dll", and on other
  3511. * platforms, it would be "libQnnHtp.so". Mutually exclusive with "backend_path".
  3512. * Available options:
  3513. * -# "cpu"
  3514. * -# "gpu"
  3515. * -# "htp": Default.
  3516. * -# "saver"
  3517. * -# "ir"
  3518. * "backend_path": File path to QNN backend library. Mutually exclusive with "backend_type".
  3519. * "profiling_level": QNN profiling level.
  3520. * Available options:
  3521. * -# "off": Default.
  3522. * -# "basic"
  3523. * -# "detailed"
  3524. * "profiling_file_path": QNN profiling file path if ETW not enabled.
  3525. * "rpc_control_latency": QNN RPC control latency.
  3526. * "vtcm_mb": QNN VTCM size in MB. default to 0(not set).
  3527. * "htp_performance_mode": QNN performance mode.
  3528. * Available options:
  3529. * -# "burst"
  3530. * -# "balanced"
  3531. * -# "default": Default.
  3532. * -# "high_performance"
  3533. * -# "high_power_saver"
  3534. * -# "low_balanced"
  3535. * -# "extreme_power_saver"
  3536. * -# "low_power_saver"
  3537. * -# "power_saver"
  3538. * -# "sustained_high_performance"
  3539. * "dump_qnn_ir_dlc": Use the QnnIr backend library to write .dlc files for each subgraph dispatched to QNN. When
  3540. * enabled, inference results will be incorrect. Use only for debugging.
  3541. * -# "0": Default: disabled
  3542. * -# "1": enabled
  3543. * "dump_qnn_ir_dlc_dir": Set the directory into which QnnIr will be configured to write QNN graphs as .dlc files.
  3544. * Default is current working directory.
  3545. * "qnn_ir_backend_path": File path to the QnnIr backend library. If "dump_qnn_ir_dlc" is enabled, use this path
  3546. * instead of looking for the Ir backend in the standard location.
  3547. * "qnn_saver_path": File path to the QNN Saver backend library. If specified, QNN Saver will be enabled and will
  3548. * dump QNN API calls to disk for replay/debugging. QNN Saver produces incorrect model inference results and
  3549. * may alter model/EP partitioning. Use only for debugging.
  3550. * "qnn_context_priority": QNN context priority.
  3551. * Available options:
  3552. * -# "low"
  3553. * -# "normal": Default.
  3554. * -# "normal_high"
  3555. * -# "high"
  3556. * "htp_graph_finalization_optimization_mode": Set the optimization mode for graph finalization on the HTP backend.
  3557. * Available options:
  3558. * -# "0": Default.
  3559. * -# "1": Faster preparation time, less optimal graph.
  3560. * -# "2": Longer preparation time, more optimal graph.
  3561. * -# "3": Longest preparation time, most likely even more optimal graph. See QNN SDK documentation for specific
  3562. * details.
  3563. * "soc_model": The SoC model number. Refer to the QNN SDK documentation for valid values.
  3564. * Defaults to "0" (unknown).
  3565. * "htp_arch": The minimum HTP architecture the driver will use to select compatible QNN operators.
  3566. * Available options:
  3567. * -# "0": Default (none).
  3568. * -# "68"
  3569. * -# "69"
  3570. * -# "73"
  3571. * -# "75"
  3572. * "device_id": The ID of the device to use when setting 'htp_arch'. Defaults to "0" (for single device).
  3573. * "enable_htp_fp16_precision": Used for float32 model for HTP backend.
  3574. * Enable the float32 model to be inferenced with fp16 precision. Otherwise, it will be fp32 precision.
  3575. * -# "0": With fp32 precision.
  3576. * -# "1": Default. With fp16 precision.
  3577. * "offload_graph_io_quantization": Offload graph input quantization and graph output dequantization to another
  3578. * execution provider (typically CPU EP).
  3579. * -# "0": Disabled. QNN EP will handle quantization and dequantization of graph I/O.
  3580. * -# "1": Enabled. This is the default value.
  3581. * "enable_htp_spill_fill_buffer": Enable HTP spill fill buffer setting. The flag is used while generating context
  3582. * binary.
  3583. * -# "0": Default. Disabled.
  3584. * -# "1": Enabled.
  3585. * "enable_htp_shared_memory_allocator": Enable the QNN HTP shared memory allocator. Requires libcdsprpc.so/dll to
  3586. * be available.
  3587. * -# "0": Default. Disabled.
  3588. * -# "1": Enabled.
  3589. * "dump_json_qnn_graph": Set to "1" to dump QNN graphs generated by QNN EP as JSON files. Each graph partition
  3590. * assigned to QNN EP is dumped to a separate file.
  3591. * "json_qnn_graph_dir": Directory in which to dump QNN JSON graphs. If not specified, QNN graphs are dumped in the
  3592. * program's current working directory. Ignored if "dump_json_qnn_graph" is not set.
  3593. * "op_packages": QNN UDO op_package for QNN EP, allowed format:
  3594. *   "<op_type>:<op_package_path>:<interface>[:<target>],<op_type2>:<op_package_path2>:<interface2>[:<target>]",
  3595. *   where op_type is the name of the operation, op_package_path is the path to the op package shared library,
  3596. * interface is the symbol name to register the op life cycle functions, and target is the backend type. For more
  3597. * details, refer to: https://docs.qualcomm.com/bundle/publicresource/topics/80-63442-50/op_packages.html
  3598. *
  3599. * XNNPACK supported keys:
  3600. * "intra_op_num_threads": number of thread-pool size to use for XNNPACK execution provider.
  3601. * default value is 0, which means to use the session thread-pool size.
  3602. *
  3603. * \since Version 1.12.
  3604. */
  3605. ORT_API2_STATUS(SessionOptionsAppendExecutionProvider, _In_ OrtSessionOptions* options,
  3606. _In_ const char* provider_name,
  3607. _In_reads_(num_keys) const char* const* provider_options_keys,
  3608. _In_reads_(num_keys) const char* const* provider_options_values,
  3609. _In_ size_t num_keys);
  3610. /* \brief: Get a copy of kernel info
  3611. *
  3612. * \param[in] info Kernel info
  3613. * \param[out] info_copy Copy of kernel info
  3614. *
  3615. * \since Version 1.12.
  3616. */
  3617. ORT_API2_STATUS(CopyKernelInfo,
  3618. _In_ const OrtKernelInfo* info,
  3619. _Outptr_ OrtKernelInfo** info_copy);
  3620. /* \brief: Release kernel info
  3621. *
  3622. * \param[in] KernelInfo A copy of kernel info returned by CopyKernelInfo
  3623. *
  3624. * \since Version 1.12.
  3625. */
  3626. ORT_CLASS_RELEASE(KernelInfo);
  3627. /// \name Ort Training
  3628. /// @{
  3629. /** \brief Gets the Training C Api struct
  3630. *
  3631. * Call this function to access the ::OrtTrainingApi structure that holds pointers to functions that enable
  3632. * training with onnxruntime.
  3633. * \note A NULL pointer will be returned and no error message will be printed if the training api
  3634. * is not supported with this build. A NULL pointer will be returned and an error message will be
  3635. * printed if the provided version is unsupported, for example when using a runtime older than the
  3636. * version created with this header file.
  3637. *
  3638. * \param[in] version Must be ::ORT_API_VERSION
  3639. * \return The ::OrtTrainingApi struct for the version requested.
  3640. *
  3641. * \since Version 1.13
  3642. */
  3643. const OrtTrainingApi*(ORT_API_CALL* GetTrainingApi)(uint32_t version)NO_EXCEPTION;
  3644. /// @}
  3645. /** \brief Append CANN provider to session options
  3646. *
  3647. * If CANN is not available (due to a non CANN enabled build, or if CANN is not installed on the system), this function will return failure.
  3648. *
  3649. * \param[in] options
  3650. * \param[in] cann_options
  3651. *
  3652. * \snippet{doc} snippets.dox OrtStatus Return Value
  3653. *
  3654. * \since Version 1.13.
  3655. */
  3656. ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_CANN,
  3657. _In_ OrtSessionOptions* options, _In_ const OrtCANNProviderOptions* cann_options);
  3658. /** \brief Create an OrtCANNProviderOptions
  3659. *
  3660. * \param[out] out created ::OrtCANNProviderOptions. Must be released with OrtApi::ReleaseCANNProviderOptions
  3661. *
  3662. * \snippet{doc} snippets.dox OrtStatus Return Value
  3663. *
  3664. * \since Version 1.13.
  3665. */
  3666. ORT_API2_STATUS(CreateCANNProviderOptions, _Outptr_ OrtCANNProviderOptions** out);
  3667. /** \brief Set options in a CANN Execution Provider.
  3668. *
  3669. * \param[in] cann_options
  3670. * \param[in] provider_options_keys Array of UTF-8 null-terminated string for provider options keys
  3671. * \param[in] provider_options_values Array of UTF-8 null-terminated string for provider options values
  3672. * \param[in] num_keys Number of elements in the `provider_option_keys` and `provider_options_values` arrays
  3673. *
  3674. * \snippet{doc} snippets.dox OrtStatus Return Value
  3675. *
  3676. * \since Version 1.13.
  3677. */
  3678. ORT_API2_STATUS(UpdateCANNProviderOptions, _Inout_ OrtCANNProviderOptions* cann_options,
  3679. _In_reads_(num_keys) const char* const* provider_options_keys,
  3680. _In_reads_(num_keys) const char* const* provider_options_values,
  3681. _In_ size_t num_keys);
  3682. /** \brief Get serialized CANN provider options string.
  3683. *
  3684. * \param[in] cann_options OrtCANNProviderOptions instance
  3685. * \param[in] allocator a ptr to an instance of OrtAllocator obtained with CreateAllocator()
  3686. * or GetAllocatorWithDefaultOptions(), the specified allocator will be used to allocate
  3687. * continuous buffers for output strings and lengths.
  3688. * \param[out] ptr is a UTF-8 null terminated string allocated using 'allocator'.
  3689. * The caller is responsible for using the same allocator to free it.
  3690. *
  3691. * \snippet{doc} snippets.dox OrtStatus Return Value
  3692. *
  3693. * \since Version 1.13.
  3694. */
  3695. ORT_API2_STATUS(GetCANNProviderOptionsAsString, _In_ const OrtCANNProviderOptions* cann_options,
  3696. _Inout_ OrtAllocator* allocator, _Outptr_ char** ptr);
  3697. /** \brief Release an OrtCANNProviderOptions
  3698. *
  3699. * \param[in] input The pointer of OrtCANNProviderOptions which will been deleted
  3700. *
  3701. * \since Version 1.13.
  3702. */
  3703. void(ORT_API_CALL* ReleaseCANNProviderOptions)(_Frees_ptr_opt_ OrtCANNProviderOptions* input);
  3704. /* \brief Get OrtDevice type from MemoryInfo
  3705. *
  3706. * \since Version 1.14
  3707. */
  3708. void(ORT_API_CALL* MemoryInfoGetDeviceType)(_In_ const OrtMemoryInfo* ptr, _Out_ OrtMemoryInfoDeviceType* out);
  3709. /* \brief Update the OrtEnv instance with custom log severity level
  3710. *
  3711. * \param[in] ort_env The OrtEnv instance being used
  3712. * \param[in] log_severity_level The log severity level.
  3713. *
  3714. * \since Version 1.14.
  3715. */
  3716. ORT_API2_STATUS(UpdateEnvWithCustomLogLevel, _In_ OrtEnv* ort_env, OrtLoggingLevel log_severity_level);
  3717. /* \brief Set affinities for intra op threads
  3718. *
  3719. * Affinity string follows format:
  3720. * logical_processor_id,logical_processor_id;logical_processor_id,logical_processor_id
  3721. * Semicolon isolates configurations among threads, while comma split processors where ith thread expected to attach to.
  3722. * e.g. 1,2,3;4,5
  3723. * specifies affinities for two threads, with the 1st thread attach to the 1st, 2nd, and 3rd processor, and 2nd thread to the 4th and 5th.
  3724. * To ease the configuration, an "interval" is also allowed:
  3725. * e.g. 1-8;8-16;17-24
  3726. * orders that the 1st thread runs on first eight processors, 2nd thread runs on next eight processors, and so forth.
  3727. * Note:
  3728. * 1. Once set, the number of thread affinities must equal to intra_op_num_threads - 1,
  3729. * ort does not set affinity on the main thread which is started and managed by the calling app;
  3730. * 2. For windows, ort will infer the group id from a logical processor id, for example, assuming there are two groups with each has 64 logical processors,
  3731. * an id of 64 will be inferred as the last processor of the 1st group, while 65 will be interpreted as the 1st processor of the second group.
  3732. * Hence 64-65 is an invalid configuration, because a windows thread cannot be attached to processors across group boundary.
  3733. *
  3734. * \since Version 1.14
  3735. */
  3736. ORT_API2_STATUS(SetGlobalIntraOpThreadAffinity, _Inout_ OrtThreadingOptions* tp_options, const char* affinity_string);
  3737. /** \brief Register custom ops from a shared library.
  3738. *
  3739. * Loads a shared library (.dll on windows, .so on linux, etc) named 'library_name' and looks for this entry point:
  3740. * OrtStatus* RegisterCustomOps(OrtSessionOptions * options, const OrtApiBase* api);
  3741. * It then passes in the provided session options to this function along with the api base.
  3742. *
  3743. * The handle to the loaded library is automatically released by ORT when the last OrtSession that references the
  3744. * library handle is released. If no OrtSession is created, then the library handle is released when the provided
  3745. * OrtSessionOptions is released.
  3746. *
  3747. * \param[in] options The session options.
  3748. * \param[in] library_name The name of the shared library to load and register. Refer to OS-specific dynamic library
  3749. * loading utilities (e.g., LoadLibraryEx on Windows or dlopen on Linux/MacOS) for information
  3750. * on the format of library names and search paths.
  3751. *
  3752. * \snippet{doc} snippets.dox OrtStatus Return Value
  3753. * \since Version 1.14
  3754. */
  3755. ORT_API2_STATUS(RegisterCustomOpsLibrary_V2, _Inout_ OrtSessionOptions* options, _In_ const ORTCHAR_T* library_name);
  3756. /** \brief Register custom ops by calling a RegisterCustomOpsFn function.
  3757. *
  3758. * Searches for registration_func_name and if found calls it.
  3759. *
  3760. * The library containing the function must either be linked against or previously loaded by the executable.
  3761. *
  3762. * If you want ONNX Runtime to load the library and manage its lifetime, use RegisterCustomOpsLibrary_V2.
  3763. *
  3764. * RegisterCustomOpsUsingFunction can be used in scenarios where it may not be possible for ONNX Runtime to load
  3765. * the library from a path. e.g. mobile platforms where the library must be linked into the app.
  3766. *
  3767. * The registration function must have the signature of RegisterCustomOpsFn:
  3768. * OrtStatus* (*fn)(OrtSessionOptions* options, const OrtApiBase* api);
  3769. *
  3770. * See https://onnxruntime.ai/docs/reference/operators/add-custom-op.html for details on how the registration
  3771. * function should be implemented.
  3772. *
  3773. * \param[in] options OrtSessionOptions that is passed through as the first argument in the call to the
  3774. * registration function.
  3775. * \param[in] registration_func_name Name of registration function to use.
  3776. *
  3777. * \snippet{doc} snippets.dox OrtStatus Return Value
  3778. * \since Version 1.14
  3779. */
  3780. ORT_API2_STATUS(RegisterCustomOpsUsingFunction, _Inout_ OrtSessionOptions* options,
  3781. _In_ const char* registration_func_name);
  3782. /// \name OrtKernelInfo
  3783. /// Custom operator APIs.
  3784. /// @{
  3785. /** \brief Get the number of inputs from ::OrtKernelInfo.
  3786. *
  3787. * Used in the CreateKernel callback of an OrtCustomOp to query the number of inputs
  3788. * during kernel/session creation.
  3789. *
  3790. * \param[in] info Instance of ::OrtKernelInfo.
  3791. * \param[out] out Pointer to variable assigned with the result on success.
  3792. *
  3793. * \snippet{doc} snippets.dox OrtStatus Return Value
  3794. * \since Version 1.14
  3795. */
  3796. ORT_API2_STATUS(KernelInfo_GetInputCount, _In_ const OrtKernelInfo* info, _Out_ size_t* out);
  3797. /** \brief Get the number of outputs from ::OrtKernelInfo.
  3798. *
  3799. * Used in the CreateKernel callback of an OrtCustomOp to query the number of outputs
  3800. * during kernel/session creation.
  3801. *
  3802. * \param[in] info Instance of ::OrtKernelInfo.
  3803. * \param[out] out Pointer to variable assigned with the result on success.
  3804. *
  3805. * \snippet{doc} snippets.dox OrtStatus Return Value
  3806. * \since Version 1.14
  3807. */
  3808. ORT_API2_STATUS(KernelInfo_GetOutputCount, _In_ const OrtKernelInfo* info, _Out_ size_t* out);
  3809. /** \brief Get the name of a ::OrtKernelInfo's input.
  3810. *
  3811. * Used in the CreateKernel callback of an OrtCustomOp to query an input's name
  3812. * during kernel/session creation.
  3813. *
  3814. * If `out` is nullptr, the value of `size` is set to the size of the name
  3815. * string (including null-terminator), and a success status is returned.
  3816. *
  3817. * If the `size` parameter is greater than or equal to the name string's size,
  3818. * the value of `size` is set to the true size of the string (including null-terminator),
  3819. * the provided memory is filled with the string's contents, and a success status is returned.
  3820. *
  3821. * If the `size` parameter is less than the actual string's size and `out`
  3822. * is not nullptr, the value of `size` is set to the true size of the string
  3823. * and a failure status is returned.
  3824. *
  3825. * \param[in] info An instance of ::OrtKernelInfo.
  3826. * \param[in] index The index of the input name to get. Returns a failure status if out-of-bounds.
  3827. * \param[out] out Memory location into which to write the UTF-8 null-terminated string representing the input's name.
  3828. * \param[in,out] size Pointer to the size of the `out` buffer. See above comments for details.
  3829. *
  3830. * \snippet{doc} snippets.dox OrtStatus Return Value
  3831. * \since Version 1.14
  3832. */
  3833. ORT_API2_STATUS(KernelInfo_GetInputName, _In_ const OrtKernelInfo* info, size_t index, _Out_ char* out,
  3834. _Inout_ size_t* size);
  3835. /** \brief Get the name of a ::OrtKernelInfo's output.
  3836. *
  3837. * Used in the CreateKernel callback of an OrtCustomOp to query an output's name
  3838. * during kernel/session creation.
  3839. *
  3840. * If `out` is nullptr, the value of `size` is set to the size of the name
  3841. * string (including null-terminator), and a success status is returned.
  3842. *
  3843. * If the `size` parameter is greater than or equal to the name string's size,
  3844. * the value of `size` is set to the true size of the string (including null-terminator),
  3845. * the provided memory is filled with the string's contents, and a success status is returned.
  3846. *
  3847. * If the `size` parameter is less than the actual string's size and `out`
  3848. * is not nullptr, the value of `size` is set to the true size of the string
  3849. * and a failure status is returned.
  3850. *
  3851. * \param[in] info An instance of ::OrtKernelInfo.
  3852. * \param[in] index The index of the output name to get. Returns a failure status if out-of-bounds.
  3853. * \param[out] out Memory location into which to write the UTF-8 null-terminated string representing the output's
  3854. * name.
  3855. * \param[in,out] size Pointer to the size of the `out` buffer. See above comments for details.
  3856. *
  3857. * \snippet{doc} snippets.dox OrtStatus Return Value
  3858. * \since Version 1.14
  3859. */
  3860. ORT_API2_STATUS(KernelInfo_GetOutputName, _In_ const OrtKernelInfo* info, size_t index, _Out_ char* out,
  3861. _Inout_ size_t* size);
  3862. /** \brief Get the type information for a ::OrtKernelInfo's input.
  3863. *
  3864. * Used in the CreateKernel callback of an OrtCustomOp to query the shape and type information
  3865. * of an input during kernel/session creation.
  3866. *
  3867. * \param[in] info An instance of ::OrtKernelInfo.
  3868. * \param[in] index Which input to get the type information for
  3869. * \param[out] type_info Pointer set to the resulting ::OrtTypeInfo. Must be freed with OrtApi::ReleaseTypeInfo.
  3870. *
  3871. * \snippet{doc} snippets.dox OrtStatus Return Value
  3872. * \since Version 1.14
  3873. */
  3874. ORT_API2_STATUS(KernelInfo_GetInputTypeInfo, _In_ const OrtKernelInfo* info, size_t index,
  3875. _Outptr_ OrtTypeInfo** type_info);
  3876. /** \brief Get the type information for a ::OrtKernelInfo's output.
  3877. *
  3878. * Used in the CreateKernel callback of an OrtCustomOp to query the shape and type information
  3879. * of an output during kernel/session creation.
  3880. *
  3881. * \param[in] info An instance of ::OrtKernelInfo.
  3882. * \param[in] index Which input to get the type information for
  3883. * \param[out] type_info Pointer set to the resulting ::OrtTypeInfo. Must be freed with OrtApi::ReleaseTypeInfo.
  3884. *
  3885. * \snippet{doc} snippets.dox OrtStatus Return Value
  3886. * \since Version 1.14
  3887. */
  3888. ORT_API2_STATUS(KernelInfo_GetOutputTypeInfo, _In_ const OrtKernelInfo* info, size_t index,
  3889. _Outptr_ OrtTypeInfo** type_info);
  3890. /** \brief Get a ::OrtValue tensor stored as an attribute in the graph node.
  3891. *
  3892. * Used in the CreateKernel callback of an OrtCustomOp to get a tensor attribute.
  3893. *
  3894. * \param[in] info ::OrtKernelInfo instance.
  3895. * \param[in] name UTF-8 null-terminated string representing the attribute's name.
  3896. * \param[in] allocator Allocator used to allocate the internal tensor state.
  3897. * \param[out] out Returns newly created ::OrtValue. Must be freed with OrtApi::ReleaseValue,
  3898. * which will also free internal tensor state allocated with the provided allocator.
  3899. *
  3900. * \snippet{doc} snippets.dox OrtStatus Return Value
  3901. */
  3902. ORT_API2_STATUS(KernelInfoGetAttribute_tensor, _In_ const OrtKernelInfo* info, _In_z_ const char* name,
  3903. _Inout_ OrtAllocator* allocator, _Outptr_ OrtValue** out);
  3904. /// @}
  3905. /// \name OrtSessionOptions
  3906. /// Custom operator APIs
  3907. /// @{
  3908. /** \brief Checks if the given session configuration entry exists.
  3909. *
  3910. * The config_key formats are defined in onnxruntime_session_options_config_keys.h
  3911. *
  3912. * Can be used in a custom operator library to check for session configuration entries
  3913. * that target one or more custom operators in the library. Example: The config entry
  3914. * custom_op.myop.some_key targets a custom op named "myop".
  3915. *
  3916. * \param[in] options The ::OrtSessionOptions instance.
  3917. * \param[in] config_key A null-terminated UTF-8 string representation of the configuration key.
  3918. * \param[out] out Pointer set to 1 if the entry exists and 0 otherwise.
  3919. *
  3920. * \snippet{doc} snippets.dox OrtStatus Return Value
  3921. * \since Version 1.14
  3922. */
  3923. ORT_API2_STATUS(HasSessionConfigEntry, _In_ const OrtSessionOptions* options,
  3924. _In_z_ const char* config_key, _Out_ int* out);
  3925. /** \brief Get a session configuration value.
  3926. *
  3927. * Returns a failure status if the configuration key does not exist.
  3928. * The config_key and the format of config_value are defined in onnxruntime_session_options_config_keys.h
  3929. *
  3930. * If `config_value` is nullptr, the value of `size` is set to the true size of the string
  3931. * value (including null-terminator), and a success status is returned.
  3932. *
  3933. * If the `size` parameter is greater than or equal to the actual string value's size,
  3934. * the value of `size` is set to the true size of the string value, the provided memory
  3935. * is filled with the value's contents, and a success status is returned.
  3936. *
  3937. * If the `size` parameter is less than the actual string value's size and `config_value`
  3938. * is not nullptr, the value of `size` is set to the true size of the string value
  3939. * and a failure status is returned.
  3940. *
  3941. * Can be used in a custom operator library to get session configuration entries
  3942. * that target one or more custom operators in the library. Example: The config entry
  3943. * custom_op.myop.some_key targets a custom op named "myop".
  3944. *
  3945. * \param[in] options The session options.
  3946. * \param[in] config_key A null-terminated UTF-8 string representation of the config key.
  3947. * \param[in] config_value Pointer to memory where the null-terminated UTF-8 string value will be stored.
  3948. * \param[in,out] size Pointer to the size of the `config_value` buffer. See above comments for details.
  3949. *
  3950. * \snippet{doc} snippets.dox OrtStatus Return Value
  3951. * \since Version 1.14
  3952. */
  3953. ORT_API2_STATUS(GetSessionConfigEntry, _In_ const OrtSessionOptions* options,
  3954. _In_z_ const char* config_key, _Out_ char* config_value, _Inout_ size_t* size);
  3955. /// @}
  3956. /** \brief Append dnnl provider to session options
  3957. *
  3958. * If oneDNN is not available, this function will return failure.
  3959. *
  3960. * \param[in] options
  3961. * \param[in] dnnl_options
  3962. *
  3963. * \snippet{doc} snippets.dox OrtStatus Return Value
  3964. *
  3965. * \since Version 1.15.
  3966. */
  3967. ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_Dnnl,
  3968. _In_ OrtSessionOptions* options, _In_ const OrtDnnlProviderOptions* dnnl_options);
  3969. /** \brief Create an OrtDnnlProviderOptions
  3970. *
  3971. * \param[out] out Newly created ::OrtDnnlProviderOptions. Must be released with OrtApi::ReleaseDnnlProviderOptions
  3972. *
  3973. * \snippet{doc} snippets.dox OrtStatus Return Value
  3974. *
  3975. * \since Version 1.15.
  3976. */
  3977. ORT_API2_STATUS(CreateDnnlProviderOptions, _Outptr_ OrtDnnlProviderOptions** out);
  3978. /** \brief Set options in a oneDNN Execution Provider.
  3979. *
  3980. * Key should be in null terminated string format of the member of ::OrtDnnlProviderOptions
  3981. * and value should be its related range.
  3982. *
  3983. * For example, key="use_arena" and value="1"
  3984. *
  3985. * \param[in] dnnl_options
  3986. * \param[in] provider_options_keys Array of UTF-8 null-terminated string for provider options keys
  3987. * \param[in] provider_options_values Array of UTF-8 null-terminated string for provider options values
  3988. * \param[in] num_keys Number of elements in the `provider_option_keys` and `provider_options_values` arrays
  3989. *
  3990. * \snippet{doc} snippets.dox OrtStatus Return Value
  3991. *
  3992. * \since Version 1.15.
  3993. */
  3994. ORT_API2_STATUS(UpdateDnnlProviderOptions, _Inout_ OrtDnnlProviderOptions* dnnl_options,
  3995. _In_reads_(num_keys) const char* const* provider_options_keys,
  3996. _In_reads_(num_keys) const char* const* provider_options_values,
  3997. _In_ size_t num_keys);
  3998. /**
  3999. * Get serialized oneDNN provider options string.
  4000. *
  4001. * For example, "use_arena=1;......"
  4002. *
  4003. * \param dnnl_options - OrtDnnlProviderOptions instance
  4004. * \param allocator - a ptr to an instance of OrtAllocator obtained with CreateAllocator() or GetAllocatorWithDefaultOptions()
  4005. * the specified allocator will be used to allocate continuous buffers for output strings and lengths.
  4006. * \param ptr - is a UTF-8 null terminated string allocated using 'allocator'. The caller is responsible for using the same allocator to free it.
  4007. *
  4008. * \snippet{doc} snippets.dox OrtStatus Return Value
  4009. *
  4010. * \since Version 1.15.
  4011. */
  4012. ORT_API2_STATUS(GetDnnlProviderOptionsAsString, _In_ const OrtDnnlProviderOptions* dnnl_options, _Inout_ OrtAllocator* allocator, _Outptr_ char** ptr);
  4013. /** \brief Release an ::OrtDnnlProviderOptions
  4014. *
  4015. * \since Version 1.15.
  4016. */
  4017. void(ORT_API_CALL* ReleaseDnnlProviderOptions)(_Frees_ptr_opt_ OrtDnnlProviderOptions* input);
  4018. /// \name OrtKernelInfo
  4019. /// Custom operator APIs.
  4020. /// @{
  4021. /** \brief Get the graph node name from ::OrtKernelInfo.
  4022. *
  4023. * If `out` is nullptr, the value of `size` is set to the size of the name
  4024. * string (including null-terminator), and a success status is returned.
  4025. *
  4026. * If the `size` parameter is greater than or equal to the name string's size,
  4027. * the value of `size` is set to the true size of the string (including null-terminator),
  4028. * the provided memory is filled with the string's contents, and a success status is returned.
  4029. *
  4030. * If the `size` parameter is less than the actual string's size and `out`
  4031. * is not nullptr, the value of `size` is set to the true size of the string
  4032. * and a failure status is returned.
  4033. *
  4034. * Can be used in a custom operator's CreateKernel callback to get the name of the operator's node name in the graph.
  4035. *
  4036. * \param[in] info An instance of ::OrtKernelInfo.
  4037. * \param[out] out Memory location into which to write the UTF-8 null-terminated string representing the name.
  4038. * \param[in,out] size Pointer to the size of the `out` buffer. See above comments for details.
  4039. *
  4040. * \snippet{doc} snippets.dox OrtStatus Return Value
  4041. * \since Version 1.15
  4042. */
  4043. ORT_API2_STATUS(KernelInfo_GetNodeName, _In_ const OrtKernelInfo* info, _Out_ char* out, _Inout_ size_t* size);
  4044. /** \brief Get the session logger from ::OrtKernelInfo.
  4045. *
  4046. * Used in the CreateKernel callback of an OrtCustomOp to get a logger that can be used to log
  4047. * messages.
  4048. *
  4049. * \param[in] info An instance of ::OrtKernelInfo.
  4050. * \param[out] logger Pointer set to the session's ::OrtLogger. Owned by ONNX Runtime, so do not free.
  4051. *
  4052. * \snippet{doc} snippets.dox OrtStatus Return Value
  4053. * \since Version 1.15
  4054. */
  4055. ORT_API2_STATUS(KernelInfo_GetLogger, _In_ const OrtKernelInfo* info, _Outptr_ const OrtLogger** logger);
  4056. /// @}
  4057. /// \name OrtKernelContext
  4058. /// Custom operator APIs.
  4059. /// @{
  4060. /** \brief Get the runtime logger from ::OrtKernelContext.
  4061. *
  4062. * Used in the KernelCompute callback of an OrtCustomOp to get a logger that can be used to log
  4063. * messages during inference.
  4064. *
  4065. * \param[in] context An instance of ::OrtKernelContext.
  4066. * \param[out] logger Pointer set to the kernel context's ::OrtLogger. Owned by ONNX Runtime, so do not free.
  4067. *
  4068. * \snippet{doc} snippets.dox OrtStatus Return Value
  4069. * \since Version 1.15
  4070. */
  4071. ORT_API2_STATUS(KernelContext_GetLogger, _In_ const OrtKernelContext* context, _Outptr_ const OrtLogger** logger);
  4072. /// @}
  4073. /// \name OrtLogger
  4074. /// Custom operator APIs.
  4075. /// @{
  4076. /** \brief Logs a message at the given severity level using the provided ::OrtLogger.
  4077. *
  4078. * Only messages with a severity level equal or greater than the ::OrtLogger's logging severity level
  4079. * are logged. Use OrtApi::Logger_GetLoggingSeverityLevel to get the ::OrtLogger's logging severity
  4080. * level.
  4081. *
  4082. * Can be used in custom operators to log messages with the logger retrieved via OrtApi::KernelInfo_GetLogger.
  4083. *
  4084. * \param[in] logger The ::OrtLogger instance.
  4085. * \param[in] log_severity_level The message's severity level.
  4086. * \param[in] message The message to log.
  4087. * \param[in] file_path The filepath of the file in which the message is logged. Usually the value of ORT_FILE.
  4088. * \param[in] line_number The file line number in which the message is logged. Usually the value of __LINE__.
  4089. * \param[in] func_name The name of the function in which the message is logged. Usually the value of __FUNCTION__.
  4090. *
  4091. * \snippet{doc} snippets.dox OrtStatus Return Value
  4092. * \since Version 1.15
  4093. */
  4094. ORT_API2_STATUS(Logger_LogMessage, _In_ const OrtLogger* logger, OrtLoggingLevel log_severity_level,
  4095. _In_z_ const char* message, _In_z_ const ORTCHAR_T* file_path, int line_number,
  4096. _In_z_ const char* func_name);
  4097. /** \brief Get the logging severity level of the ::OrtLogger.
  4098. *
  4099. * Can be used in a custom operator to get the logging severity level of the ::OrtLogger associated with
  4100. * the ::OrtKernelInfo.
  4101. *
  4102. * \param[in] logger The ::OrtLogger instance.
  4103. * \param[out] out Pointer to variable assigned with the logging severity level on success.
  4104. *
  4105. * \snippet{doc} snippets.dox OrtStatus Return Value
  4106. * \since Version 1.15
  4107. */
  4108. ORT_API2_STATUS(Logger_GetLoggingSeverityLevel, _In_ const OrtLogger* logger, _Out_ OrtLoggingLevel* out);
  4109. /// @}
  4110. /** \brief Get a ::OrtValue tensor stored as a constant initializer in the graph node.
  4111. *
  4112. * Used in the CreateKernel callback of an OrtCustomOp to get a tensor value.
  4113. *
  4114. * \param[in] info ::OrtKernelInfo instance.
  4115. * \param[in] index The node index.
  4116. * \param[out] is_constant Is it a constant node input or not.
  4117. * \param[out] out The OrtValue tensor value.
  4118. *
  4119. * \snippet{doc} snippets.dox OrtStatus Return Value
  4120. *
  4121. * \since Version 1.15.
  4122. */
  4123. ORT_API2_STATUS(KernelInfoGetConstantInput_tensor, _In_ const OrtKernelInfo* info, size_t index, _Out_ int* is_constant, _Outptr_ const OrtValue** out);
  4124. /** \brief Get Optional Type information from an ::OrtTypeInfo
  4125. *
  4126. * This augments ::OrtTypeInfo to return an ::OrtOptionalTypeInfo when the type is optional.
  4127. * The OrtOptionalTypeInfo also has a nested ::OrtTypeInfo that describes the type of the optional value.
  4128. * ::OrtOptionalTypeInfo type can only appear within model metadata to describe inputs/outputs.
  4129. * The actual OrtValues that are supplied in place of optional type inputs should contain
  4130. * specific type that is described by ::OrtOptionalTypeInfo.
  4131. *
  4132. * So the picture: ::OrtTypeInfo -> ::OrtOptionalTypeInfo -> ::OrtTypeInfo (describes the type that can be supplied
  4133. * in place of the optional type when creating the actual ::OrtValue).
  4134. *
  4135. * \param[in] type_info
  4136. * \param[out] out A pointer to the ::OrtOptionalTypeInfo. Do not free this value,
  4137. * it is owned by OrtTypeInfo instance. When the type_info does not represent
  4138. * optional type, nullptr is returned in out.
  4139. *
  4140. * \snippet{doc} snippets.dox OrtStatus Return Value
  4141. *
  4142. * \since Version 1.15.
  4143. */
  4144. ORT_API2_STATUS(CastTypeInfoToOptionalTypeInfo, _In_ const OrtTypeInfo* type_info,
  4145. _Outptr_result_maybenull_ const OrtOptionalTypeInfo** out);
  4146. /** \brief Get OrtTypeInfo for the allowed contained type from an ::OrtOptionalTypeInfo.
  4147. *
  4148. * This augments ::OrtOptionalTypeInfo to return an ::OrtTypeInfo for the contained type.
  4149. * The OrtOptionalTypeInfo has a nested ::OrtTypeInfo that describes the type of the optional value.
  4150. * ::OrtOptionalTypeInfo type can only appear within model metadata to describe inputs/outputs.
  4151. * The actual OrtValues that are supplied in place of optional type inputs should contain
  4152. * specific type that is described by the returned ::OrtTypeInfo.
  4153. *
  4154. * \param[in] optional_type_info
  4155. * \param[out] out A copy of ::OrtTypeInfo for what the optional value could be.
  4156. * The user must free this value with ReleaseTypeInfo.
  4157. *
  4158. * \snippet{doc} snippets.dox OrtStatus Return Value
  4159. *
  4160. * \since Version 1.15.
  4161. */
  4162. ORT_API2_STATUS(GetOptionalContainedTypeInfo, _In_ const OrtOptionalTypeInfo* optional_type_info,
  4163. _Outptr_ OrtTypeInfo** out);
  4164. /** \brief Set a single string in a string tensor
  4165. * Do not zero terminate the string data.
  4166. *
  4167. * \param[in] value A string tensor
  4168. * \param[in] index - flat index of the element
  4169. * \param[in] length_in_bytes length of the buffer in utf-8 bytes (without the null terminator)
  4170. * \param[inout] buffer - address of return value
  4171. *
  4172. * \snippet{doc} snippets.dox OrtStatus Return Value
  4173. */
  4174. ORT_API2_STATUS(GetResizedStringTensorElementBuffer, _Inout_ OrtValue* value, _In_ size_t index, _In_ size_t length_in_bytes, _Inout_ char** buffer);
  4175. /** \brief Get Allocator from KernelContext for a specific memoryInfo. Please use C API ReleaseAllocator to release out object
  4176. *
  4177. * \param[in] context OrtKernelContext instance
  4178. * \param[in] mem_info OrtMemoryInfo instance
  4179. * \param[out] out A pointer to OrtAllocator.
  4180. *
  4181. * \snippet{doc} snippets.dox OrtStatus Return Value
  4182. *
  4183. * \since Version 1.15.
  4184. */
  4185. ORT_API2_STATUS(KernelContext_GetAllocator, _In_ const OrtKernelContext* context, _In_ const OrtMemoryInfo* mem_info, _Outptr_ OrtAllocator** out);
  4186. /** \brief Returns a null terminated string of the build info including git info and cxx flags
  4187. *
  4188. * \return UTF-8 encoded version string. Do not deallocate the returned buffer.
  4189. *
  4190. * \since Version 1.15.
  4191. */
  4192. const char*(ORT_API_CALL* GetBuildInfoString)(void);
  4193. /// \name OrtROCMProviderOptions
  4194. /// @{
  4195. /** \brief Create an OrtROCMProviderOptions
  4196. *
  4197. * \param[out] out Newly created ::OrtROCMProviderOptions. Must be released with OrtApi::ReleaseROCMProviderOptions
  4198. *
  4199. * \snippet{doc} snippets.dox OrtStatus Return Value
  4200. *
  4201. * \since Version 1.16.
  4202. */
  4203. ORT_API2_STATUS(CreateROCMProviderOptions, _Outptr_ OrtROCMProviderOptions** out);
  4204. /** \brief Set options in a ROCm Execution Provider.
  4205. *
  4206. * Please refer to https://onnxruntime.ai/docs/execution-providers/ROCm-ExecutionProvider.html
  4207. * to know the available keys and values. Key should be in null terminated string format of the member of
  4208. * ::OrtROCMProviderOptions and value should be its related range.
  4209. *
  4210. * For example, key="device_id" and value="0"
  4211. *
  4212. * \param[in] rocm_options
  4213. * \param[in] provider_options_keys Array of UTF-8 null-terminated string for provider options keys
  4214. * \param[in] provider_options_values Array of UTF-8 null-terminated string for provider options values
  4215. * \param[in] num_keys Number of elements in the `provider_option_keys` and `provider_options_values` arrays
  4216. *
  4217. * \snippet{doc} snippets.dox OrtStatus Return Value
  4218. *
  4219. * \since Version 1.16.
  4220. */
  4221. ORT_API2_STATUS(UpdateROCMProviderOptions, _Inout_ OrtROCMProviderOptions* rocm_options,
  4222. _In_reads_(num_keys) const char* const* provider_options_keys,
  4223. _In_reads_(num_keys) const char* const* provider_options_values,
  4224. _In_ size_t num_keys);
  4225. /**
  4226. * Get serialized ROCm provider options string.
  4227. *
  4228. * For example, "device_id=0;arena_extend_strategy=0;......"
  4229. *
  4230. * \param rocm_options - OrtROCMProviderOptions instance
  4231. * \param allocator - a ptr to an instance of OrtAllocator obtained with CreateAllocator() or GetAllocatorWithDefaultOptions()
  4232. * the specified allocator will be used to allocate continuous buffers for output strings and lengths.
  4233. * \param ptr - is a UTF-8 null terminated string allocated using 'allocator'. The caller is responsible for using the same allocator to free it.
  4234. *
  4235. * \snippet{doc} snippets.dox OrtStatus Return Value
  4236. *
  4237. * \since Version 1.16.
  4238. */
  4239. ORT_API2_STATUS(GetROCMProviderOptionsAsString, _In_ const OrtROCMProviderOptions* rocm_options, _Inout_ OrtAllocator* allocator, _Outptr_ char** ptr);
  4240. /** \brief Release an ::OrtROCMProviderOptions
  4241. *
  4242. * \note This is an exception in the naming convention of other Release* functions, as the name of the method does not have the V2 suffix, but the type does
  4243. *
  4244. * \since Version 1.16.
  4245. */
  4246. void(ORT_API_CALL* ReleaseROCMProviderOptions)(_Frees_ptr_opt_ OrtROCMProviderOptions* input);
  4247. /** \brief Create an allocator with specific type and register it with the ::OrtEnv
  4248. * This API enhance CreateAndRegisterAllocator that it can create an allocator with specific type, not just CPU allocator
  4249. * Enables sharing the allocator between multiple sessions that use the same env instance.
  4250. * Lifetime of the created allocator will be valid for the duration of the environment.
  4251. * Returns an error if an allocator with the same ::OrtMemoryInfo is already registered.
  4252. * \param[in] env OrtEnv instance
  4253. * \param[in] provider_type ExecutionProvider type
  4254. * \param[in] mem_info OrtMemoryInfo instance
  4255. * \param[in] arena_cfg Arena configuration
  4256. * \param[in] provider_options_keys key of the provider options map
  4257. * \param[in] provider_options_values value of the provider options map
  4258. * \param[in] num_keys Length of the provider options map
  4259. */
  4260. ORT_API2_STATUS(CreateAndRegisterAllocatorV2, _Inout_ OrtEnv* env, _In_ const char* provider_type,
  4261. _In_ const OrtMemoryInfo* mem_info, _In_ const OrtArenaCfg* arena_cfg,
  4262. _In_reads_(num_keys) const char* const* provider_options_keys, _In_reads_(num_keys) const char* const* provider_options_values, _In_ size_t num_keys);
  4263. /** \brief Run the model asynchronously in a thread owned by intra op thread pool
  4264. *
  4265. * \param[in] session
  4266. * \param[in] run_options If nullptr, will use a default ::OrtRunOptions
  4267. * \param[in] input_names Array of null terminated UTF8 encoded strings of the input names
  4268. * \param[in] input Array of ::OrtValue%s of the input values
  4269. * \param[in] input_len Number of elements in the input_names and inputs arrays
  4270. * \param[in] output_names Array of null terminated UTF8 encoded strings of the output names
  4271. * \param[in] output_names_len Number of elements in the output_names and outputs array
  4272. * \param[out] output OrtValue* array of size output_names_len.
  4273. * On calling RunAsync, output[i] could either be a null or a pointer to a preallocated OrtValue.
  4274. * Later, the output array will be passed to run_async_callback with all null(s) filled with valid
  4275. * OrtValue pointer(s) allocated by onnxruntime.
  4276. * NOTE: it is customer's duty to finally release the output array and each of its member,
  4277. * regardless of whether the member (OrtValue*) is allocated by onnxruntime or preallocated by the customer.
  4278. * \param[in] run_async_callback Callback function on model run completion
  4279. * \param[in] user_data User data that pass back to run_async_callback
  4280. */
  4281. ORT_API2_STATUS(RunAsync, _Inout_ OrtSession* session, _In_opt_ const OrtRunOptions* run_options,
  4282. _In_reads_(input_len) const char* const* input_names,
  4283. _In_reads_(input_len) const OrtValue* const* input, size_t input_len,
  4284. _In_reads_(output_names_len) const char* const* output_names, size_t output_names_len,
  4285. _Inout_updates_all_(output_names_len) OrtValue** output,
  4286. _In_ RunAsyncCallbackFn run_async_callback, _In_opt_ void* user_data);
  4287. /**
  4288. * Update TensorRT EP provider option where its data type is pointer, for example 'user_compute_stream'.
  4289. * If the data type of the provider option can be represented by string please use UpdateTensorRTProviderOptions.
  4290. *
  4291. * Note: It's caller's responsibility to properly manage the lifetime of the instance pointed by this pointer.
  4292. *
  4293. * \param tensorrt_options - OrtTensorRTProviderOptionsV2 instance
  4294. * \param key - Name of the provider option
  4295. * \param value - A pointer to the instance that will be assigned to this provider option
  4296. *
  4297. * \since Version 1.16.
  4298. */
  4299. ORT_API2_STATUS(UpdateTensorRTProviderOptionsWithValue, _Inout_ OrtTensorRTProviderOptionsV2* tensorrt_options, _In_ const char* key, _In_ void* value);
  4300. /**
  4301. * Get TensorRT EP provider option where its data type is pointer.
  4302. * If the data type of the provider option can be represented by string please use GetTensorRTProviderOptionsAsString.
  4303. *
  4304. * \param tensorrt_options - OrtTensorRTProviderOptionsV2 instance
  4305. * \param key - Name of the provider option
  4306. * \param ptr - A pointer to the instance that is kept by the provider option
  4307. *
  4308. * \since Version 1.16.
  4309. */
  4310. ORT_API2_STATUS(GetTensorRTProviderOptionsByName, _In_ const OrtTensorRTProviderOptionsV2* tensorrt_options, _In_ const char* key, _Outptr_ void** ptr);
  4311. /**
  4312. * Update CUDA EP provider option where its data type is pointer, for example 'user_compute_stream'.
  4313. * If the data type of the provider option can be represented by string please use UpdateCUDAProviderOptions.
  4314. *
  4315. * Note: It's caller's responsibility to properly manage the lifetime of the instance pointed by this pointer.
  4316. *
  4317. * \param cuda_options - OrtCUDAProviderOptionsV2 instance
  4318. * \param key - Name of the provider option
  4319. * \param value - A pointer to the instance that will be assigned to this provider option
  4320. *
  4321. * \since Version 1.16.
  4322. */
  4323. ORT_API2_STATUS(UpdateCUDAProviderOptionsWithValue, _Inout_ OrtCUDAProviderOptionsV2* cuda_options, _In_ const char* key, _In_ void* value);
  4324. /**
  4325. * Get CUDA EP provider option where its data type is pointer.
  4326. * If the data type of the provider option can be represented by string please use GetCUDAProviderOptionsAsString.
  4327. *
  4328. * \param cuda_options - OrtCUDAProviderOptionsV2 instance
  4329. * \param key - Name of the provider option
  4330. * \param ptr - A pointer to the instance that is kept by the provider option
  4331. *
  4332. * \since Version 1.16.
  4333. */
  4334. ORT_API2_STATUS(GetCUDAProviderOptionsByName, _In_ const OrtCUDAProviderOptionsV2* cuda_options, _In_ const char* key, _Outptr_ void** ptr);
  4335. /**
  4336. * Get a EP resource.
  4337. * E.g. a cuda stream or a cublas handle
  4338. *
  4339. * \param context - Kernel context
  4340. * \param resource_version - Version of the resource
  4341. * \param resource_id - Type of resource
  4342. * \param resource - A pointer to returned resource
  4343. *
  4344. * \since Version 1.16.
  4345. */
  4346. ORT_API2_STATUS(KernelContext_GetResource, _In_ const OrtKernelContext* context, _In_ int resource_version,
  4347. _In_ int resource_id, _Outptr_ void** resource);
  4348. /** \brief Set user logging function
  4349. *
  4350. * By default the logger created by the CreateEnv* functions is used to create the session logger as well.
  4351. * This function allows a user to override this default session logger with a logger of their own choosing. This way
  4352. * the user doesn't have to create a separate environment with a custom logger. This addresses the problem when
  4353. * the user already created an env but now wants to use a different logger for a specific session (for debugging or
  4354. * other reasons).
  4355. *
  4356. * \param[in] options
  4357. * \param[in] user_logging_function A pointer to a logging function.
  4358. * \param[in] user_logging_param A pointer to arbitrary data passed as the ::OrtLoggingFunction `param` parameter to
  4359. * `user_logging_function`. This parameter is optional.
  4360. *
  4361. * \snippet{doc} snippets.dox OrtStatus Return Value
  4362. *
  4363. * \since Version 1.17.
  4364. */
  4365. ORT_API2_STATUS(SetUserLoggingFunction, _Inout_ OrtSessionOptions* options,
  4366. _In_ OrtLoggingFunction user_logging_function, _In_opt_ void* user_logging_param);
  4367. /**
  4368. * Get number of input from OrtShapeInferContext
  4369. *
  4370. * \param[in] context
  4371. * \param[out] out The number of inputs
  4372. *
  4373. * \since Version 1.17.
  4374. */
  4375. ORT_API2_STATUS(ShapeInferContext_GetInputCount, _In_ const OrtShapeInferContext* context, _Out_ size_t* out);
  4376. /**
  4377. * Get type and shape info of an input
  4378. *
  4379. * \param[in] context
  4380. * \param[in] index The index of the input
  4381. * \param[out] info Type shape info of the input
  4382. *
  4383. * \since Version 1.17.
  4384. */
  4385. ORT_API2_STATUS(ShapeInferContext_GetInputTypeShape, _In_ const OrtShapeInferContext* context, _In_ size_t index, _Outptr_ OrtTensorTypeAndShapeInfo** info);
  4386. /**
  4387. * Get attribute from OrtShapeInferContext. Note that OrtShapeInferContext is a per-node context, one could only read attribute from current node.
  4388. *
  4389. * \param[in] context
  4390. * \param[in] attr_name Name of the attribute
  4391. * \param[out] attr Handle of the attribute fetched
  4392. *
  4393. * \since Version 1.17.
  4394. */
  4395. ORT_API2_STATUS(ShapeInferContext_GetAttribute, _In_ const OrtShapeInferContext* context, _In_ const char* attr_name, _Outptr_ const OrtOpAttr** attr);
  4396. /**
  4397. * Set type and shape info of an output
  4398. *
  4399. * \param[in] context
  4400. * \param[in] index The index of the output
  4401. * \param[out] info Type shape info of the output
  4402. *
  4403. * \since Version 1.17.
  4404. */
  4405. ORT_API2_STATUS(ShapeInferContext_SetOutputTypeShape, _In_ const OrtShapeInferContext* context, _In_ size_t index, _In_ const OrtTensorTypeAndShapeInfo* info);
  4406. /**
  4407. * Set symbolic shape to type shape info
  4408. *
  4409. * \param[in] info Type shape info
  4410. * \param[in] dim_params Symbolic strings
  4411. * \param[in] dim_params_length Number of strings
  4412. *
  4413. * \since Version 1.17.
  4414. */
  4415. ORT_API2_STATUS(SetSymbolicDimensions, _In_ OrtTensorTypeAndShapeInfo* info, _In_ const char* dim_params[], _In_ size_t dim_params_length);
  4416. /**
  4417. * Read contents of an attribute to data
  4418. *
  4419. * \param[in] op_attr
  4420. * \param[in] type Attribute type
  4421. * \param[out] data Memory address to save raw content of the attribute
  4422. * \param[in] len Number of bytes allowed to store in data
  4423. * \param[out] out Number of bytes required to save the data when the call failed, or the real number of bytes saved to data on success
  4424. *
  4425. * \note Does not support reading graph attributes. Refer to Node_GetSubgraphs.
  4426. *
  4427. * \since Version 1.17.
  4428. */
  4429. ORT_API2_STATUS(ReadOpAttr, _In_ const OrtOpAttr* op_attr, _In_ OrtOpAttrType type, _Inout_ void* data, _In_ size_t len, _Out_ size_t* out);
  4430. /** \brief Set whether to use deterministic compute.
  4431. *
  4432. * Default is false. If set to true, this will enable deterministic compute for GPU kernels where possible.
  4433. * Note that this most likely will have a performance cost.
  4434. *
  4435. * \param[in] options
  4436. * \param[in] value
  4437. *
  4438. * \since Version 1.17.
  4439. */
  4440. ORT_API2_STATUS(SetDeterministicCompute, _Inout_ OrtSessionOptions* options, bool value);
  4441. /**
  4442. * Run fn in parallel
  4443. *
  4444. * \param[in] context
  4445. * \param[in] fn Function accepting usr_data and an integer as iterator
  4446. * \param[in] total The number of times fn is to be invoked
  4447. * \param[in] num_batch Number of batches by which the "total" is to be divided in maximum. When zero, there is no limit
  4448. * \param[in] usr_data User data to be passed back to fn
  4449. *
  4450. * \since Version 1.17.
  4451. */
  4452. ORT_API2_STATUS(KernelContext_ParallelFor, _In_ const OrtKernelContext* context, _In_ void (*fn)(void*, size_t), _In_ size_t total, _In_ size_t num_batch, _In_ void* usr_data);
  4453. /** \brief Append OpenVINO execution provider to the session options
  4454. *
  4455. * If OpenVINO is not available (due to a non OpenVINO enabled build, or if OpenVINO is not installed on the system), this function will fail.
  4456. *
  4457. * \param[in] options
  4458. * \param[in] provider_options_keys
  4459. * \param[in] provider_options_values
  4460. * \param[in] num_keys
  4461. *
  4462. * \snippet{doc} snippets.dox OrtStatus Return Value
  4463. *
  4464. * \since Version 1.17.
  4465. */
  4466. ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_OpenVINO_V2,
  4467. _In_ OrtSessionOptions* options,
  4468. _In_reads_(num_keys) const char* const* provider_options_keys,
  4469. _In_reads_(num_keys) const char* const* provider_options_values,
  4470. _In_ size_t num_keys);
  4471. /** \brief Append VitisAI provider to session options
  4472. *
  4473. * If VitisAI is not available (due to a non VitisAI enabled build, or if VitisAI is not installed on the system), this function will return failure.
  4474. *
  4475. * \param[in] options
  4476. * \param[in] provider_options_keys
  4477. * \param[in] provider_options_values
  4478. * \param[in] num_keys
  4479. *
  4480. * \snippet{doc} snippets.dox OrtStatus Return Value
  4481. *
  4482. * \since Version 1.18.
  4483. */
  4484. ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_VitisAI,
  4485. _In_ OrtSessionOptions* options,
  4486. _In_reads_(num_keys) const char* const* provider_options_keys,
  4487. _In_reads_(num_keys) const char* const* provider_options_values,
  4488. _In_ size_t num_keys);
  4489. /** \brief Get scratch buffer from the corresponding allocator under the specific OrtMemoryInfo object.
  4490. * NOTE: callers are responsible to release this scratch buffer from the corresponding allocator
  4491. * \param[in] context OrtKernelContext instance
  4492. * \param[in] mem_info OrtMemoryInfo instance
  4493. * \param[in] count_or_bytes How many bytes is this scratch buffer
  4494. * \param[out] out A pointer to the scratch buffer
  4495. *
  4496. * \snippet{doc} snippets.dox OrtStatus Return Value
  4497. *
  4498. * \since Version 1.18.
  4499. */
  4500. ORT_API2_STATUS(KernelContext_GetScratchBuffer, _In_ const OrtKernelContext* context, _In_ const OrtMemoryInfo* mem_info, _In_ size_t count_or_bytes, _Outptr_ void** out);
  4501. /** \brief Get allocator from KernelInfo for a specific memory type. Please use C API ReleaseAllocator to release out object
  4502. *
  4503. * \param[in] info OrtKernelInfo instance
  4504. * \param[in] mem_type OrtMemType object
  4505. * \param[out] out A pointer to OrtAllocator
  4506. *
  4507. * \snippet{doc} snippets.dox OrtStatus Return Value
  4508. *
  4509. * \since Version 1.18.
  4510. */
  4511. ORT_API2_STATUS(KernelInfoGetAllocator, _In_ const OrtKernelInfo* info, _In_ OrtMemType mem_type, _Outptr_ OrtAllocator** out);
  4512. /** \brief Replace initialized Tensors with external data with the provided files in memory
  4513. *
  4514. * The function will find the initialized TensorProtos with external data in the graph with the provided
  4515. * external file names and the file content in memory. The API gets the external file name, offset, data length
  4516. * from TensorProto, and locate the tensor data from the file in memory buffer.
  4517. * It creates a Tensor to replace the existing Tensor in graph. The replacement
  4518. * will occur before any of the optimizations take place. The data will be copied into the graph
  4519. * since TensorProto can't refer to the user provided buffers.
  4520. *
  4521. * \param[in] options
  4522. * \param[in] external_initializer_file_names Array of null terminated UTF-8 encoded strings of the file names
  4523. * which holds the external initializers.
  4524. * \param[in] external_initializer_file_buffer_array Array of pointers to the buffer of the file content.
  4525. * The buffer can be freed after session creation.
  4526. * \param[in] external_initializer_file_lengths Array of size_t to indicate the length of file content
  4527. * \param[in] num_external_initializer_files Number of external files
  4528. *
  4529. * \snippet{doc} snippets.dox OrtStatus Return Value
  4530. *
  4531. * \since Version 1.18.
  4532. */
  4533. ORT_API2_STATUS(AddExternalInitializersFromFilesInMemory, _In_ OrtSessionOptions* options,
  4534. _In_reads_(num_external_initializer_files) const ORTCHAR_T* const* external_initializer_file_names,
  4535. _In_reads_(num_external_initializer_files) char* const* external_initializer_file_buffer_array,
  4536. _In_reads_(num_external_initializer_files) const size_t* external_initializer_file_lengths,
  4537. size_t num_external_initializer_files);
  4538. /** \brief Create an OrtLoraAdapter
  4539. *
  4540. * The function attempts to locate file specified by adapter_file_path, read it and create an OrtLoraAdapter
  4541. * instance. The adapter_file_path should be a valid path to a file that contains a valid Lora Adapter
  4542. * format. The function attempts to validate the format at load time. The file will always be memory mapped, unless
  4543. * the platform does not support memory mapping, in which case the file will be read into memory.
  4544. *
  4545. * \param[in] adapter_file_path adapter file path.
  4546. * \param[in] allocator optional pointer to a device allocator. If specified
  4547. * data is copied to the device at some point before Run() is invoked. If nullptr, data stays on CPU.
  4548. * The data would still be copied to device if required by the model at inference time.
  4549. * \param[out] out A pointer to a newly created OrtLoraAdapter instance. Must be released with
  4550. * OrtApi::ReleaseLoraAdapter.
  4551. *
  4552. * \snippet{doc} snippets.dox OrtStatus Return Value
  4553. *
  4554. * \since Version 1.20.
  4555. */
  4556. ORT_API2_STATUS(CreateLoraAdapter, const ORTCHAR_T* adapter_file_path, _In_ OrtAllocator* allocator,
  4557. _Outptr_ OrtLoraAdapter** out);
  4558. /** \brief Create an OrtLoraAdapter
  4559. *
  4560. * The function copies the bytes from the array and creates an OrtLoraAdapter instance.
  4561. *
  4562. *
  4563. * \param[in] bytes pointer to a valid Lora Adapter format buffer.
  4564. * \param[in] num_bytes length of bytes buffer.
  4565. * \param[in] allocator optional pointer to a device allocator. If specified
  4566. * data is copied to the device at some point before Run() is invoked. If nullptr, data stays on CPU.
  4567. * The data would still be copied to device if required by the model at inference time.
  4568. * \param[out] out A pointer to a newly created OrtLoraAdapter instance. Must be released with
  4569. * OrtApi::ReleaseLoraAdapter.
  4570. *
  4571. * \snippet{doc} snippets.dox OrtStatus Return Value
  4572. *
  4573. * \since Version 1.20.
  4574. */
  4575. ORT_API2_STATUS(CreateLoraAdapterFromArray, _In_ const void* bytes, size_t num_bytes, _In_ OrtAllocator* allocator,
  4576. _Outptr_ OrtLoraAdapter** out);
  4577. /** \brief Release an ::OrtLoraAdapter obtained from OrtApi::CreateLoraAdapter
  4578. */
  4579. ORT_CLASS_RELEASE(LoraAdapter);
  4580. /** \brief Add the Lora Adapter to the list of active adapters.
  4581. *
  4582. * The function adds the Lora Adapter to the list of active adapters. The Lora Adapter must be created with
  4583. * OrtApi::CreateLoraAdapter or FromArray. The Lora Adapter will be used by the session to run the model.
  4584. * The instance of the OrtRunOptions can then be used to customize the Run() calls.
  4585. * More than one OrtLoraAdapter can be active at the same time. Lora Parameters that belong to different
  4586. * Lora adapters that will be active at the same time must not overlap.
  4587. * This setting does not affect RunWithBinding.
  4588. *
  4589. * \param[in] options OrtRunOptions instance
  4590. * \param[in] adapter OrtLoraAdapter instance
  4591. *
  4592. * \snippet{doc} snippets.dox OrtStatus Return Value
  4593. *
  4594. * \since Version 1.20.
  4595. */
  4596. ORT_API2_STATUS(RunOptionsAddActiveLoraAdapter, _Inout_ OrtRunOptions* options, _In_ const OrtLoraAdapter* adapter);
  4597. /// @}
  4598. /// \name OrtEpDynamicOptions
  4599. /// @{
  4600. /** \brief Set DynamicOptions for EPs (Execution Providers)
  4601. *
  4602. * Valid options can be found in `include\onnxruntime\core\session\onnxruntime_session_options_config_keys.h`
  4603. * Look for `kOrtEpDynamicOptions`
  4604. *
  4605. * \param[in] sess OrtSession
  4606. * \param[in] keys Array of null terminated UTF8 encoded strings of EP dynamic option keys
  4607. * \param[in] values Array of null terminated UTF8 encoded string of EP dynamic option values
  4608. * \param[in] kv_len Number of elements in the keys and values arrays
  4609. *
  4610. * \snippet{doc} snippets.dox OrtStatus Return Value
  4611. *
  4612. * \since Version 1.20.
  4613. */
  4614. ORT_API2_STATUS(SetEpDynamicOptions, _Inout_ OrtSession* sess, _In_reads_(kv_len) const char* const* keys,
  4615. _In_reads_(kv_len) const char* const* values, _In_ size_t kv_len);
  4616. /// @}
  4617. /** \brief Release an OrtValueInfo instance if it was not added to an OrtGraph.
  4618. * \since Version 1.22.
  4619. */
  4620. ORT_CLASS_RELEASE(ValueInfo);
  4621. /** \brief Release an OrtNode if it was not added to an OrtGraph.
  4622. * \since Version 1.22.
  4623. */
  4624. ORT_CLASS_RELEASE(Node);
  4625. /** \brief Release an OrtGraph.
  4626. * \snippet{doc} snippets.dox OrtStatus Return Value
  4627. * \since Version 1.22.
  4628. */
  4629. ORT_CLASS_RELEASE(Graph);
  4630. /** \brief Release an OrtModel.
  4631. * \snippet{doc} snippets.dox OrtStatus Return Value
  4632. * \since Version 1.22.
  4633. */
  4634. ORT_CLASS_RELEASE(Model);
  4635. /** \brief Get the value name from an OrtValueInfo instance.
  4636. * \param[in] value_info The OrtValueInfo instance.
  4637. * \param[out] name The name of the OrtValueInfo
  4638. * \snippet{doc} snippets.dox OrtStatus Return Value
  4639. * \since Version 1.22.
  4640. */
  4641. ORT_API2_STATUS(GetValueInfoName, _In_ const OrtValueInfo* value_info, _Out_ const char** name);
  4642. /** \brief Get the type information from an OrtValueInfo instance.
  4643. * \param[in] value_info The OrtValueInfo instance.
  4644. * \param[out] type_info The type info of the OrtValueInfo
  4645. * \snippet{doc} snippets.dox OrtStatus Return Value
  4646. * \since Version 1.22.
  4647. */
  4648. ORT_API2_STATUS(GetValueInfoTypeInfo, _In_ const OrtValueInfo* value_info, _Outptr_ const OrtTypeInfo** type_info);
  4649. /** \brief Get the Model Editor API instance
  4650. *
  4651. * Get the Model Editor API instance to create a new model or augment an existing model.
  4652. *
  4653. * \return Model Editor API struct
  4654. *
  4655. * \since Version 1.22.
  4656. */
  4657. const OrtModelEditorApi*(ORT_API_CALL* GetModelEditorApi)();
  4658. /** \brief Create an OrtValue for a Tensor that uses pre-existing memory.
  4659. *
  4660. * ORT will take ownership of the memory and free it using the provided deleter when no longer in use.
  4661. *
  4662. * \param[in] deleter OrtAllocator instance that will be used to free the memory.
  4663. * Only the OrtAllocator:Info and OrtAllocator::Release functions are required.
  4664. * The OrtMemoryInfo returned by OrtAllocator::Info must match the location of p_data.
  4665. * \param[in] p_data Pointer to the memory that will be used by the Tensor. ORT will take ownership of the memory.
  4666. * \param[in] p_data_len Length of the memory in bytes.
  4667. * \param[in] shape Dimensions of the Tensor. All values should be > 0.
  4668. * \param[in] shape_len Number of dimensions in the shape array.
  4669. * \param[in] type Data type of the Tensor.
  4670. * \param[out] out Newly created ::OrtValue. Must be freed with OrtApi::ReleaseValue
  4671. *
  4672. * \snippet{doc} snippets.dox OrtStatus Return Value
  4673. *
  4674. * \since Version 1.22.
  4675. */
  4676. ORT_API2_STATUS(CreateTensorWithDataAndDeleterAsOrtValue, _In_ OrtAllocator* deleter,
  4677. _In_ void* p_data, size_t p_data_len,
  4678. _In_ const int64_t* shape, size_t shape_len,
  4679. ONNXTensorElementDataType type,
  4680. _Outptr_ OrtValue** out);
  4681. /** \brief sets load cancellation flag to abort session loading process.
  4682. *
  4683. * \param[in] options instance that was passed to the session at creation time.
  4684. * \param[in] cancel setting this to true after model loading process was initiated will
  4685. * attempt to cancel the loading process. If cancellation is successful, CreateSession()
  4686. * CreateSessionFromArray() or any other session creation API that take session options as an
  4687. * argument will return an OrtStatus indicating that session loading was canceled at user request,
  4688. * error code ORT_MODEL_LOAD_CANCELED.
  4689. * The APIs above would not return any valid Session instance. This is the best case effort and the result
  4690. * is not guaranteed. The session may have already been created and initialized
  4691. * before the cancellation request was issued.
  4692. *
  4693. * \snippet{doc} snippets.dox OrtStatus Return Value
  4694. *
  4695. * \since Version 1.22.
  4696. */
  4697. ORT_API2_STATUS(SessionOptionsSetLoadCancellationFlag, _Inout_ OrtSessionOptions* options,
  4698. _In_ bool cancel);
  4699. /** \brief Get the Compile API instance.
  4700. *
  4701. * Get the Compile API instance to compile ONNX models. Execution providers that support compilation fuse a subgraph
  4702. * into an EPContext node that wraps a provider-specific binary representation of the subgraph.
  4703. * For more details about the EPContext design, refer to:
  4704. * \htmlonly
  4705. * <a href="https://onnxruntime.ai/docs/execution-providers/EP-Context-Design.html">EPContext design document.</a>
  4706. * \endhtmlonly
  4707. *
  4708. * \return Compile API struct instance.
  4709. *
  4710. * \since Version 1.22.
  4711. */
  4712. const OrtCompileApi*(ORT_API_CALL* GetCompileApi)();
  4713. //
  4714. // OrtKeyValuePairs
  4715. //
  4716. /** \brief Create an OrtKeyValuePairs instance.
  4717. *
  4718. * \param[out] out A pointer to a newly created OrtKeyValuePairs instance.
  4719. *
  4720. * \note Must be released by calling ReleaseKeyValuePairs.
  4721. *
  4722. * \since Version 1.22.
  4723. */
  4724. void(ORT_API_CALL* CreateKeyValuePairs)(_Outptr_ OrtKeyValuePairs** out);
  4725. /** \brief Add a key-value pair to the OrtKeyValuePairs instance.
  4726. *
  4727. * If a pair with the same key already exists, it is overwritten.
  4728. *
  4729. * \param[in] kvps OrtKeyValuePairs instance.
  4730. * \param[in] key Key to be added.
  4731. * \param[in] value Value to be added.
  4732. *
  4733. * \note The `key` and `value` are copied internally.
  4734. *
  4735. * \since Version 1.22.
  4736. */
  4737. void(ORT_API_CALL* AddKeyValuePair)(_In_ OrtKeyValuePairs* kvps, _In_ const char* key, _In_ const char* value);
  4738. /** \brief Get the value associated with a key in the OrtKeyValuePairs instance.
  4739. *
  4740. * \param[in] kvps OrtKeyValuePairs instance.
  4741. * \param[in] key Key to be searched.
  4742. *
  4743. * \return The value associated with the key, or nullptr if the key does not exist.
  4744. *
  4745. * \since Version 1.22.
  4746. */
  4747. const char*(ORT_API_CALL* GetKeyValue)(_In_ const OrtKeyValuePairs* kvps, _In_ const char* key);
  4748. /** \brief Get all the key-value pairs from the OrtKeyValuePairs instance.
  4749. *
  4750. * \param[in] kvps OrtKeyValuePairs instance.
  4751. * \param[out] keys Array of keys from `kvps`.
  4752. * \param[out] values Array of values from `kvps`.
  4753. * \param[out] num_entries Number of entries in `keys` and `values`.
  4754. *
  4755. * \since Version 1.22.
  4756. */
  4757. void(ORT_API_CALL* GetKeyValuePairs)(_In_ const OrtKeyValuePairs* kvps,
  4758. _Outptr_ const char* const** keys, _Outptr_ const char* const** values,
  4759. _Out_ size_t* num_entries);
  4760. /** \brief Remove a key-value pair from the OrtKeyValuePairs instance.
  4761. *
  4762. * \param[in] kvps OrtKeyValuePairs instance.
  4763. * \param[in] key Key to be removed. No error if not found.
  4764. *
  4765. * \since Version 1.22.
  4766. */
  4767. void(ORT_API_CALL* RemoveKeyValuePair)(_In_ OrtKeyValuePairs* kvps, _In_ const char* key);
  4768. /** \brief Release an OrtKeyValuePairs instance.
  4769. *
  4770. * \param[in] input OrtKeyValuePairs instance to be released.
  4771. *
  4772. * \since Version 1.22.
  4773. */
  4774. ORT_CLASS_RELEASE(KeyValuePairs);
  4775. /** \brief Register an execution provider library with ORT.
  4776. *
  4777. * The library must export 'CreateEpFactories' and 'ReleaseEpFactory' functions.
  4778. * See OrtEpApi for more details.
  4779. *
  4780. * \param[in] env The OrtEnv instance to register the library in.
  4781. * \param[in] registration_name The name to register the execution provider library under.
  4782. * \param[in] path The path to the execution provider library.
  4783. *
  4784. * \snippet{doc} snippets.dox OrtStatus Return Value
  4785. *
  4786. * \since Version 1.22.
  4787. */
  4788. ORT_API2_STATUS(RegisterExecutionProviderLibrary, _In_ OrtEnv* env, _In_ const char* registration_name,
  4789. _In_ const ORTCHAR_T* path);
  4790. /** \brief Unregister an execution provider library with ORT.
  4791. *
  4792. * ORT will call ReleaseEpFactory for all factories created by the library, and unload the library.
  4793. *
  4794. * You <b>MUST</b> ensure there are no Session instances using execution providers created by the library
  4795. * before calling this function.
  4796. *
  4797. * \param[in] env The OrtEnv instance to unregister the library from.
  4798. * \param[in] registration_name The name the execution provider library was registered under.
  4799. *
  4800. * \snippet{doc} snippets.dox OrtStatus Return Value
  4801. *
  4802. * \since Version 1.22.
  4803. */
  4804. ORT_API2_STATUS(UnregisterExecutionProviderLibrary, _In_ OrtEnv* env, _In_ const char* registration_name);
  4805. /** \brief Get the list of available OrtEpDevice instances.
  4806. *
  4807. * Each OrtEpDevice instance contains details of the execution provider and the device it will use.
  4808. *
  4809. * \param[in] env The OrtEnv instance to query.
  4810. * \param[out] ep_devices The OrtEpDevice instances that the execution provider will use.
  4811. * \param[out] num_ep_devices The number of OrtEpDevice instances returned.
  4812. *
  4813. * \snippet{doc} snippets.dox OrtStatus Return Value
  4814. *
  4815. * \since Version 1.22.
  4816. */
  4817. ORT_API2_STATUS(GetEpDevices, _In_ const OrtEnv* env,
  4818. _Outptr_ const OrtEpDevice* const** ep_devices, _Out_ size_t* num_ep_devices);
  4819. /** \brief Append the execution provider that is responsible for the selected OrtEpDevice instances
  4820. * to the session options.
  4821. *
  4822. * \param[in] session_options Session options to add execution provider to.
  4823. * \param[in] env Environment that execution providers were registered with.
  4824. * \param[in] ep_devices One or more OrtEpDevice instances to create an execution provider for.
  4825. * Obtain from GetEpDevices. All OrtEpDevice instances must be from the same execution
  4826. * provider. It is only necessary to provide multiple OrtEpDevices if you want to use the
  4827. * same execution provider for multiple devices.
  4828. * e.g. the EP is capable of running on GPU and NPU.
  4829. * \param[in] num_ep_devices Number of OrtEpDevice instances.
  4830. * \param[in] ep_option_keys Optional keys to configure the execution provider.
  4831. * \param[in] ep_option_vals Optional values to configure the execution provider.
  4832. * \param[in] num_ep_options Number of execution provide options to add.
  4833. *
  4834. * \snippet{doc} snippets.dox OrtStatus Return Value
  4835. *
  4836. * \since Version 1.22.
  4837. */
  4838. ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_V2, _In_ OrtSessionOptions* session_options,
  4839. _In_ OrtEnv* env,
  4840. _In_reads_(num_ep_devices) const OrtEpDevice* const* ep_devices, _In_ size_t num_ep_devices,
  4841. _In_reads_(num_op_options) const char* const* ep_option_keys,
  4842. _In_reads_(num_op_options) const char* const* ep_option_vals,
  4843. size_t num_ep_options);
  4844. /** \brief Set the execution provider selection policy for the session.
  4845. *
  4846. * Allows users to specify a device selection policy for automatic execution provider (EP) selection.
  4847. * If custom selection is required please use SessionOptionsSetEpSelectionPolicyDelegate instead.
  4848. *
  4849. * \param[in] session_options The OrtSessionOptions instance.
  4850. * \param[in] policy The device selection policy to use (see OrtExecutionProviderDevicePolicy).
  4851. *
  4852. * \since Version 1.22
  4853. */
  4854. ORT_API2_STATUS(SessionOptionsSetEpSelectionPolicy, _In_ OrtSessionOptions* session_options,
  4855. _In_ OrtExecutionProviderDevicePolicy policy);
  4856. /** \brief Set the execution provider selection policy delegate for the session.
  4857. *
  4858. * Allows users to provide a custom device selection policy for automatic execution provider (EP) selection.
  4859. *
  4860. * \param[in] session_options The OrtSessionOptions instance.
  4861. * \param[in] delegate Delegate callback for custom selection.
  4862. * \param[in] delegate_state Optional state that will be passed to the delegate callback. nullptr if not required.
  4863. *
  4864. * \since Version 1.22
  4865. */
  4866. ORT_API2_STATUS(SessionOptionsSetEpSelectionPolicyDelegate, _In_ OrtSessionOptions* session_options,
  4867. _In_ EpSelectionDelegate delegate,
  4868. _In_opt_ void* delegate_state);
  4869. /** \brief Get the hardware device type.
  4870. *
  4871. * \param[in] device The OrtHardwareDevice instance to query.
  4872. * \return The hardware device type.
  4873. *
  4874. * \since Version 1.22.
  4875. */
  4876. OrtHardwareDeviceType(ORT_API_CALL* HardwareDevice_Type)(_In_ const OrtHardwareDevice* device);
  4877. /** \brief Get the hardware device's vendor identifier.
  4878. *
  4879. * \param[in] device The OrtHardwareDevice instance to query.
  4880. * \return The hardware device vendor identifier.
  4881. *
  4882. * \since Version 1.22.
  4883. */
  4884. uint32_t(ORT_API_CALL* HardwareDevice_VendorId)(_In_ const OrtHardwareDevice* device);
  4885. /** \brief Get the hardware device's vendor name.
  4886. *
  4887. * \param[in] device The OrtHardwareDevice instance to query.
  4888. * \return The hardware device's vendor name.
  4889. *
  4890. * \since Version 1.22.
  4891. */
  4892. const char*(ORT_API_CALL* HardwareDevice_Vendor)(_In_ const OrtHardwareDevice* device);
  4893. /** \brief Get the hardware device's unique identifier.
  4894. *
  4895. * \param[in] device The OrtHardwareDevice instance to query.
  4896. * \return The device id.
  4897. *
  4898. * \note This is not a unique identifier. It identifies the hardware type when combined with vendor id.
  4899. * \since Version 1.22.
  4900. */
  4901. uint32_t(ORT_API_CALL* HardwareDevice_DeviceId)(_In_ const OrtHardwareDevice* device);
  4902. /** \brief Get hardware device metadata.
  4903. *
  4904. * \param[in] device The OrtHardwareDevice instance to query.
  4905. * \return An OrtKeyValuePairs instance containing the metadata for the device.
  4906. * Note: ORT owns the instance so the user must not call ReleaseKeyValuePairs with it.
  4907. *
  4908. * \since Version 1.22.
  4909. */
  4910. const OrtKeyValuePairs*(ORT_API_CALL* HardwareDevice_Metadata)(_In_ const OrtHardwareDevice* device);
  4911. /** \brief Get the execution provider name.
  4912. *
  4913. * \param[in] ep_device The OrtEpDevice instance to query.
  4914. * \return The execution provider name.
  4915. *
  4916. * \since Version 1.22.
  4917. */
  4918. const char*(ORT_API_CALL* EpDevice_EpName)(_In_ const OrtEpDevice* ep_device);
  4919. /** \brief Get the execution provider's vendor name.
  4920. *
  4921. * \param[in] ep_device The OrtEpDevice instance to query.
  4922. * \return The execution provider's vendor name.
  4923. *
  4924. * \since Version 1.22.
  4925. */
  4926. const char*(ORT_API_CALL* EpDevice_EpVendor)(_In_ const OrtEpDevice* ep_device);
  4927. /** \brief Get the metadata for the OrtEpDevice.
  4928. *
  4929. * \param[in] ep_device The OrtEpDevice instance to query.
  4930. * \return An OrtKeyValuePairs instance containing the metadata for the device.
  4931. *
  4932. * \since Version 1.22.
  4933. */
  4934. const OrtKeyValuePairs*(ORT_API_CALL* EpDevice_EpMetadata)(_In_ const OrtEpDevice* ep_device);
  4935. /** \brief Get the execution provider options for the OrtEpDevice.
  4936. *
  4937. * \param[in] ep_device The OrtEpDevice instance to query.
  4938. * \return An OrtKeyValuePairs instance containing the execution provider options for the device.
  4939. *
  4940. * \since Version 1.22.
  4941. */
  4942. const OrtKeyValuePairs*(ORT_API_CALL* EpDevice_EpOptions)(_In_ const OrtEpDevice* ep_device);
  4943. /** \brief Get the OrtHardwareDevice instance for the OrtEpDevice.
  4944. *
  4945. * \param[in] ep_device The OrtEpDevice instance to query.
  4946. * \return The OrtHardwareDevice instance for the device.
  4947. *
  4948. * \since Version 1.22.
  4949. */
  4950. const OrtHardwareDevice*(ORT_API_CALL* EpDevice_Device)(_In_ const OrtEpDevice* ep_device);
  4951. /** \brief Get the OrtEpApi instance for implementing an execution provider.
  4952. *
  4953. * \since Version 1.22.
  4954. */
  4955. const OrtEpApi*(ORT_API_CALL* GetEpApi)();
  4956. /** \brief Compute total size in bytes of the tensor data contained in an OrtValue.
  4957. *
  4958. * Returns the total number of bytes used to store the tensor data. For numeric tensors,
  4959. * this is sizeof(element_type) * total_element_count. OrtValues that are not tensors or
  4960. * that are tensors that contain strings will cause an error to be returned.
  4961. *
  4962. * \param[in] ort_value OrtValue instance containing a tensor
  4963. * \param[out] size The total size of the tensor data in bytes
  4964. *
  4965. * \snippet{doc} snippets.dox OrtStatus Return Value
  4966. *
  4967. * \since Version 1.23
  4968. */
  4969. ORT_API2_STATUS(GetTensorSizeInBytes, _In_ const OrtValue* ort_value, _Out_ size_t* size);
  4970. /** \brief Calls OrtAllocator::GetStats function
  4971. *
  4972. * Return a pointer to the OrtKeyValuePairs structure that contains the statistics of the allocator
  4973. * and the user should call OrtApi::ReleaseKeyValuePairs.
  4974. *
  4975. * NOTE: If the allocator does not implement this function, the OrtKeyValuePairs instance will be empty.
  4976. *
  4977. * \param[in] ort_allocator The allocator to get stats from
  4978. * \param[out] out A pointer to the OrtKeyValuePairs instance that contains the stats
  4979. *
  4980. * \snippet{doc} snippets.dox OrtStatus Return Value
  4981. *
  4982. * \since Version 1.23.
  4983. */
  4984. ORT_API2_STATUS(AllocatorGetStats, _In_ const OrtAllocator* ort_allocator, _Outptr_ OrtKeyValuePairs** out);
  4985. /** \brief Create an ::OrtMemoryInfo
  4986. *
  4987. * \param[in] name Arbitrary name.
  4988. * \param[in] device_type Device type.
  4989. * \param[in] vendor_id PCI Vendor ID. Use 0 for a generic allocator (e.g. WebGPU).
  4990. * \param[in] device_id Device ID if there are multiple devices of the same type. e.g. 2 GPU devices.
  4991. * \param[in] mem_type Memory type. Use OrtDeviceMemoryType_DEFAULT for device memory, and
  4992. * OrtDeviceMemoryType_HOST_ACCESSIBLE (if applicable) for memory used to transfer between the
  4993. * device and the CPU. Use the device_type and device_id of the GPU/NPU that the memory is also
  4994. * accessible to.
  4995. * \param[in] alignment Alignment of the memory if required. Pass 0 for default alignment.
  4996. * \param[in] allocator_type Allocator type. If OrtAllocatorType::OrtArenaAllocator, the ORT arena will be used.
  4997. * Caveat: Support for OrtArenaAllocator is currently limited to usage of internal ORT
  4998. * allocators via CreateAllocator/CreateAndRegisterAllocator/CreateAndRegisterAllocatorV2.
  4999. * \param[out] out Newly created ::OrtMemoryInfo. Must be freed with OrtApi::ReleaseMemoryInfo
  5000. *
  5001. * \snippet{doc} snippets.dox OrtStatus Return Value
  5002. *
  5003. * \since Version 1.23
  5004. */
  5005. ORT_API2_STATUS(CreateMemoryInfo_V2, _In_ const char* name, _In_ enum OrtMemoryInfoDeviceType device_type,
  5006. _In_ uint32_t vendor_id, _In_ int32_t device_id, _In_ enum OrtDeviceMemoryType mem_type,
  5007. _In_ size_t alignment, enum OrtAllocatorType allocator_type,
  5008. _Outptr_ OrtMemoryInfo** out);
  5009. /** \brief Get the device memory type from ::OrtMemoryInfo
  5010. *
  5011. * \param[in] ptr The OrtMemoryInfo instance to query.
  5012. * \return The device memory type.
  5013. *
  5014. * \since Version 1.23
  5015. */
  5016. ORT_API_T(OrtDeviceMemoryType, MemoryInfoGetDeviceMemType, _In_ const OrtMemoryInfo* ptr);
  5017. /** \brief Get the vendor id from ::OrtMemoryInfo
  5018. *
  5019. * \param[in] ptr The OrtMemoryInfo instance to query.
  5020. * \return The vendor id.
  5021. *
  5022. * \since Version 1.23
  5023. */
  5024. ORT_API_T(uint32_t, MemoryInfoGetVendorId, _In_ const OrtMemoryInfo* ptr);
  5025. /// \name OrtValueInfo
  5026. /// @{
  5027. /** \brief Get the OrtNode that produces the value represented by the given OrtValueInfo.
  5028. * Optionally returns the associated output index.
  5029. *
  5030. * \param[in] value_info The OrtValueInfo instance.
  5031. * \param[out] producer_node Output parameter set to the OrtNode that produces the OrtValueInfo.
  5032. * \param[out] producer_output_index Optional output parameter set to the OrtNode instance's output index
  5033. * that produces the value. Ignored if set to NULL.
  5034. * \snippet{doc} snippets.dox OrtStatus Return Value
  5035. * \since Version 1.23.
  5036. */
  5037. ORT_API2_STATUS(ValueInfo_GetValueProducer, _In_ const OrtValueInfo* value_info,
  5038. _Outptr_ const OrtNode** producer_node, _Out_opt_ size_t* producer_output_index);
  5039. /** \brief Get the number of consumers of a value as a node input.
  5040. *
  5041. * Only nodes are considered "consumers" by this function. To check if an OrtValueInfo is a graph output,
  5042. * call ValueInfo_IsGraphOutput().
  5043. *
  5044. * A single OrtNode may use a single value for more than one input (e.g., Mul(x, x)), so the returned
  5045. * `num_consumers` may be larger than the number of unique OrtNode instances that consume the value.
  5046. *
  5047. * \param[in] value_info The OrtValueInfo instance.
  5048. * \param[out] num_consumers Output parameter set to the number of consumers of the value.
  5049. *
  5050. * \snippet{doc} snippets.dox OrtStatus Return Value
  5051. *
  5052. * \since Version 1.23.
  5053. */
  5054. ORT_API2_STATUS(ValueInfo_GetValueNumConsumers, _In_ const OrtValueInfo* value_info, _Out_ size_t* num_consumers);
  5055. /** \brief Returns information (OrtNode and input index) for all consumer nodes that use the value as an input.
  5056. *
  5057. * Only nodes are considered "consumers" by this function.
  5058. *
  5059. * Caller provides 2 pre-allocated arrays that will be filled with the OrtNode and input index values.
  5060. * Use ValueInfo_GetValueNumConsumers() to get the number of consumers of the value.
  5061. *
  5062. * An OrtNode instance may appear multiple times if it uses the given value more than once.
  5063. * Example: For a node MulNode(x, x) that consumes the value 'x' twice, the following is returned:
  5064. * - nodes: [MulNode, MulNode]
  5065. * - input_indices: [0, 1]
  5066. *
  5067. * \param[in] value_info The OrtValueInfo instance.
  5068. * \param[out] nodes Pre-allocated array of size `num_consumers` that is filled with OrtNode instances.
  5069. * \param[out] input_indices Pre-allocated array of `num_consumers` elements that is filled
  5070. * with input indices. Index is set to -1 for an "implicit" input to a consumer node
  5071. * that contains a subgraph (e.g., If, Loop) with nodes that use the value internally.
  5072. * \param[in] num_consumers The size of the `consumer_nodes` and `consumer_input_indices` arrays.
  5073. * Typical usage sets this to the value of ValueInfo_GetValueNumConsumers().
  5074. * An error status is returned if `num_consumers` is less than the number of actual
  5075. * consumers.
  5076. *
  5077. * \snippet{doc} snippets.dox OrtStatus Return Value
  5078. *
  5079. * \since Version 1.23.
  5080. */
  5081. ORT_API2_STATUS(ValueInfo_GetValueConsumers, _In_ const OrtValueInfo* value_info,
  5082. _Out_writes_all_(num_consumers) const OrtNode** nodes,
  5083. _Out_writes_all_(num_consumers) int64_t* input_indices,
  5084. _In_ size_t num_consumers);
  5085. /** \brief Get the underlying initializer value, as an OrtValue, from the given OrtValueInfo.
  5086. *
  5087. * Sets the output parameter to NULL if the given OrtValueInfo does not represent an initializer.
  5088. * Does not return an error status in this case.
  5089. *
  5090. * Supports initializers defined in an outer scope (i.e., a parent graph).
  5091. *
  5092. * Supports initializers stored in an external file. For external initializers, ORT memory maps
  5093. * the initializer data on the first call to this function. If caller needs custom memory mapping,
  5094. * use ValueInfo_GetExternalInitializerInfo to get the location of the initializer data.
  5095. *
  5096. * \param[in] value_info The OrtValueInfo instance.
  5097. * \param[out] initializer_value Output parameter set to the initializer value or NULL. Do not cache the OrtValue
  5098. * as it is released when the owning OrtGraph is released.
  5099. *
  5100. * \snippet{doc} snippets.dox OrtStatus Return Value
  5101. *
  5102. * \since Version 1.23.
  5103. */
  5104. ORT_API2_STATUS(ValueInfo_GetInitializerValue, _In_ const OrtValueInfo* value_info,
  5105. _Outptr_ const OrtValue** initializer_value);
  5106. /** \brief Get information about an external initializer (e.g., filepath, file offset, byte size).
  5107. *
  5108. * Sets the output parameter `info` to NULL if the given OrtValueInfo does not represent an initializer
  5109. * with external data. In this case, a NULL status (non-error) is returned.
  5110. *
  5111. * \param[in] value_info The OrtValueInfo instance.
  5112. * \param[out] info Output parameter set to an OrtExternalInitializerInfo instance that can be used to query
  5113. * file path, file offset, etc. ORT sets this to NULL if the OrtValueInfo does not represent
  5114. * an external initializer.
  5115. * Must release with ReleaseExternalInitializerInfo.
  5116. *
  5117. * \snippet{doc} snippets.dox OrtStatus Return Value
  5118. *
  5119. * \since Version 1.23.
  5120. */
  5121. ORT_API2_STATUS(ValueInfo_GetExternalInitializerInfo, _In_ const OrtValueInfo* value_info,
  5122. _Outptr_result_maybenull_ OrtExternalInitializerInfo** info);
  5123. /** \brief Returns a boolean indicating if the given value is a required graph input.
  5124. *
  5125. * For ONNX IR version < 4, all graph inputs without a matching initializer are required.
  5126. *
  5127. * For ONNX IR version >=4, a graph input with a matching initializer is an optional graph input
  5128. * with the initializer serving as the default value.
  5129. *
  5130. * \param[in] value_info The OrtValueInfo instance representing the graph value.
  5131. * \param[out] is_required_graph_input Output parameter set to true if the graph value is a required graph input.
  5132. *
  5133. * \snippet{doc} snippets.dox OrtStatus Return Value
  5134. *
  5135. * \since Version 1.23.
  5136. */
  5137. ORT_API2_STATUS(ValueInfo_IsRequiredGraphInput, _In_ const OrtValueInfo* value_info,
  5138. _Out_ bool* is_required_graph_input);
  5139. /** \brief Returns a boolean indicating if the given value is an optional graph input.
  5140. *
  5141. * Optional graph inputs were introduced in ONNX IR version 4. For ONNX IR version >=4, a graph input with a
  5142. * matching initializer is an optional graph input with the initializer serving as the default value.
  5143. * The matching initializer is also known as a non-constant initializer.
  5144. *
  5145. * \param[in] value_info The OrtValueInfo instance representing the graph value.
  5146. * \param[out] is_optional_graph_input Output parameter set to true if the graph value is an optional graph input.
  5147. *
  5148. * \snippet{doc} snippets.dox OrtStatus Return Value
  5149. *
  5150. * \since Version 1.23.
  5151. */
  5152. ORT_API2_STATUS(ValueInfo_IsOptionalGraphInput, _In_ const OrtValueInfo* value_info,
  5153. _Out_ bool* is_optional_graph_input);
  5154. /** \brief Returns a boolean indicating if the given value is a graph output.
  5155. *
  5156. * \param[in] value_info The OrtValueInfo instance representing the graph value.
  5157. * \param[out] is_graph_output Output parameter set to true if the graph value is a graph output.
  5158. *
  5159. * \snippet{doc} snippets.dox OrtStatus Return Value
  5160. *
  5161. * \since Version 1.23.
  5162. */
  5163. ORT_API2_STATUS(ValueInfo_IsGraphOutput, _In_ const OrtValueInfo* value_info, _Out_ bool* is_graph_output);
  5164. /** \brief Returns a boolean indicating if the given value is a constant initializer.
  5165. *
  5166. * For ONNX IR version < 4, all initializers are constant.
  5167. *
  5168. * For ONNX IR version >=4, an initializer that serves as the default value for a matching graph input is not a
  5169. * constant initializer.
  5170. *
  5171. * \param[in] value_info The OrtValueInfo instance representing the graph value.
  5172. * \param[out] is_constant_initializer Output parameter set to true if the graph value is a constant initializer.
  5173. *
  5174. * \snippet{doc} snippets.dox OrtStatus Return Value
  5175. *
  5176. * \since Version 1.23.
  5177. */
  5178. ORT_API2_STATUS(ValueInfo_IsConstantInitializer, _In_ const OrtValueInfo* value_info,
  5179. _Out_ bool* is_constant_initializer);
  5180. /** \brief Returns a boolean indicating if the given value is defined in an outer scope.
  5181. *
  5182. * Certain operator types (e.g., If and Loop) contain nested subgraphs. This function enables
  5183. * determining whether a value is defined in a parent node's graph.
  5184. *
  5185. * \param[in] value_info The OrtValueInfo instance representing the graph value.
  5186. * \param[out] is_from_outer_scope Output parameter set to true if the value is defined in an outer
  5187. * scope (i.e., a parent graph).
  5188. *
  5189. * \snippet{doc} snippets.dox OrtStatus Return Value
  5190. *
  5191. * \since Version 1.23.
  5192. */
  5193. ORT_API2_STATUS(ValueInfo_IsFromOuterScope, _In_ const OrtValueInfo* value_info,
  5194. _Out_ bool* is_from_outer_scope);
  5195. /// @}
  5196. /// \name OrtGraph
  5197. /// @{
  5198. /** \brief Returns a graph's name.
  5199. *
  5200. * \param[in] graph The OrtGraph instance.
  5201. * \param[out] graph_name Output parameter set to the graph's name.
  5202. *
  5203. * \snippet{doc} snippets.dox OrtStatus Return Value
  5204. *
  5205. * \since Version 1.23.
  5206. */
  5207. ORT_API2_STATUS(Graph_GetName, _In_ const OrtGraph* graph, _Outptr_ const char** graph_name);
  5208. /** \brief Get the filepath to the model from which an OrtGraph is constructed.
  5209. *
  5210. * \note The model's filepath is empty if the filepath is unknown, such as when the model is loaded from bytes
  5211. * via CreateSessionFromArray.
  5212. *
  5213. * \param[in] graph The OrtGraph instance.
  5214. * \param[out] model_path Output parameter set to the model's null-terminated filepath.
  5215. * Set to an empty path string if unknown.
  5216. *
  5217. * \snippet{doc} snippets.dox OrtStatus Return Value
  5218. *
  5219. * \since Version 1.23.
  5220. */
  5221. ORT_API2_STATUS(Graph_GetModelPath, _In_ const OrtGraph* graph, _Outptr_ const ORTCHAR_T** model_path);
  5222. /** \brief Returns the ONNX IR version.
  5223. *
  5224. * \param[in] graph The OrtGraph instance.
  5225. * \param[out] onnx_ir_version Output parameter set to the ONNX IR version.
  5226. *
  5227. * \snippet{doc} snippets.dox OrtStatus Return Value
  5228. *
  5229. * \since Version 1.23.
  5230. */
  5231. ORT_API2_STATUS(Graph_GetOnnxIRVersion, _In_ const OrtGraph* graph, _Out_ int64_t* onnx_ir_version);
  5232. /** \brief Returns the number of operator sets that the graph's model uses.
  5233. *
  5234. * \note An operator set is uniquely identified by the (domain, opset_version) pair. All models must have at
  5235. * least one entry that specifies which entry of the ONNX operator set is used. The ONNX domain is represented by
  5236. * an empty string.
  5237. *
  5238. * \param[in] graph The OrtGraph instance.
  5239. * \param[out] num_operator_sets Output parameter set to the number of operator sets that the graph's model uses.
  5240. *
  5241. * \snippet{doc} snippets.dox OrtStatus Return Value
  5242. *
  5243. * \since Version 1.23.
  5244. */
  5245. ORT_API2_STATUS(Graph_GetNumOperatorSets, _In_ const OrtGraph* graph, _Out_ size_t* num_operator_sets);
  5246. /** \brief Returns the operator sets that the graph's model uses.
  5247. *
  5248. * \note An operator set is uniquely identified by the (domain, opset_version) pair. All models must have at
  5249. * least one entry that specifies which entry of the ONNX operator set is used. The ONNX domain is represented by
  5250. * an empty string.
  5251. *
  5252. * \param[in] graph The OrtGraph instance.
  5253. * \param[out] domains Pre-allocated array of `num_operator_sets` elements that is filled with
  5254. * null-terminated domain names.
  5255. * \param[out] opset_versions Pre-allocated array of `num_operator_sets` elements that is filled with
  5256. * the opset version of the corresponding domain in the `domains` array.
  5257. * \param[in] num_operator_sets The size of the `domains` and `opset_versions` arrays.
  5258. * Typical usage sets this to the result of Graph_GetNumOperatorSets().
  5259. * An error status is returned if `num_operator_sets` is less than the actual number
  5260. * of operator sets.
  5261. *
  5262. * \snippet{doc} snippets.dox OrtStatus Return Value
  5263. *
  5264. * \since Version 1.23.
  5265. */
  5266. ORT_API2_STATUS(Graph_GetOperatorSets, _In_ const OrtGraph* graph,
  5267. _Out_writes_(num_operator_sets) const char** domains,
  5268. _Out_writes_(num_operator_sets) int64_t* opset_versions, _In_ size_t num_operator_sets);
  5269. /** \brief Returns the number of graph inputs.
  5270. *
  5271. * \note The count includes initializers that are included in the list of graph inputs.
  5272. *
  5273. * \param[in] graph The OrtGraph instance.
  5274. * \param[out] num_inputs Output parameter set to the number of graph inputs.
  5275. *
  5276. * \snippet{doc} snippets.dox OrtStatus Return Value
  5277. *
  5278. * \since Version 1.23.
  5279. */
  5280. ORT_API2_STATUS(Graph_GetNumInputs, _In_ const OrtGraph* graph, _Out_ size_t* num_inputs);
  5281. /** \brief Returns the graph's inputs as OrtValueInfo instances.
  5282. *
  5283. * \note The result includes initializers that are included in the list of graph inputs.
  5284. *
  5285. * \param[in] graph The OrtGraph instance.
  5286. * \param[out] inputs Pre-allocated array of `num_inputs` elements that is filled with the graph's inputs.
  5287. * \param[in] num_inputs The size of the `inputs` array.
  5288. * Typical usage sets this to the result of Graph_GetNumInputs(). An error status is
  5289. * returned if `num_inputs` is less than the number of graph inputs.
  5290. *
  5291. * \snippet{doc} snippets.dox OrtStatus Return Value
  5292. *
  5293. * \since Version 1.23.
  5294. */
  5295. ORT_API2_STATUS(Graph_GetInputs, _In_ const OrtGraph* graph,
  5296. _Out_writes_(num_inputs) const OrtValueInfo** inputs, _In_ size_t num_inputs);
  5297. /** \brief Returns the number of graph outputs.
  5298. *
  5299. * \param[in] graph The OrtGraph instance.
  5300. * \param[out] num_outputs Output parameter set to the number of graph outputs.
  5301. *
  5302. * \snippet{doc} snippets.dox OrtStatus Return Value
  5303. *
  5304. * \since Version 1.23.
  5305. */
  5306. ORT_API2_STATUS(Graph_GetNumOutputs, _In_ const OrtGraph* graph, _Out_ size_t* num_outputs);
  5307. /** \brief Returns the graph's outputs as OrtValueInfo instances.
  5308. *
  5309. * \param[in] graph The OrtGraph instance.
  5310. * \param[out] outputs Pre-allocated array of `num_outputs` elements that is filled with the graph's outputs.
  5311. * \param[in] num_outputs The size of the `outputs` array.
  5312. * Typical usage sets this to the result of Graph_GetNumOutputs(). An error status is
  5313. * returned if `num_outputs` is less than the number of graph outputs.
  5314. *
  5315. * \snippet{doc} snippets.dox OrtStatus Return Value
  5316. *
  5317. * \since Version 1.23.
  5318. */
  5319. ORT_API2_STATUS(Graph_GetOutputs, _In_ const OrtGraph* graph,
  5320. _Out_writes_(num_outputs) const OrtValueInfo** outputs, _In_ size_t num_outputs);
  5321. /** \brief Returns the number of graph initializers.
  5322. *
  5323. * Counts constant and non-constant initializers.
  5324. *
  5325. * \param[in] graph The OrtGraph instance.
  5326. * \param[out] num_initializers Output parameter set to the number of graph initializers.
  5327. *
  5328. * \snippet{doc} snippets.dox OrtStatus Return Value
  5329. *
  5330. * \since Version 1.23.
  5331. */
  5332. ORT_API2_STATUS(Graph_GetNumInitializers, _In_ const OrtGraph* graph, _Out_ size_t* num_initializers);
  5333. /** \brief Returns the graph's initializers as OrtValueInfo instances.
  5334. *
  5335. * Includes constant and non-constant initializers.
  5336. *
  5337. * For ONNX IR version < 4, all initializers are constant.
  5338. *
  5339. * For ONNX IR version >= 4, an initializer with a name that matches a graph input is considered a
  5340. * non-constant initializer.
  5341. *
  5342. * Call ValueInfo_GetInitializerValue to get the initializer's data.
  5343. *
  5344. * \param[in] graph The OrtGraph instance.
  5345. * \param[out] initializers Pre-allocated array of `num_outputs` elements that is filled with the initializers.
  5346. * \param[in] num_initializers The size of the `initializers` array. Typical usage sets this to the
  5347. * result of Graph_GetNumInitializers(). An error status is returned if
  5348. * `num_initializers` is less than the number of graph initializers.
  5349. *
  5350. * \snippet{doc} snippets.dox OrtStatus Return Value
  5351. *
  5352. * \since Version 1.23.
  5353. */
  5354. ORT_API2_STATUS(Graph_GetInitializers, _In_ const OrtGraph* graph,
  5355. _Out_writes_(num_initializers) const OrtValueInfo** initializers,
  5356. _In_ size_t num_initializers);
  5357. /** \brief Returns the number of graph nodes.
  5358. *
  5359. * \param[in] graph The OrtGraph instance.
  5360. * \param[out] num_nodes Output parameter set to the number of graph nodes.
  5361. *
  5362. * \snippet{doc} snippets.dox OrtStatus Return Value
  5363. *
  5364. * \since Version 1.23.
  5365. */
  5366. ORT_API2_STATUS(Graph_GetNumNodes, _In_ const OrtGraph* graph, _Out_ size_t* num_nodes);
  5367. /** \brief Returns the graph's nodes as OrtNode instances.
  5368. *
  5369. * The nodes are sorted using a stable topological ordering. Callers are responsible for maintaining their
  5370. * own node ordering if a different order is required.
  5371. *
  5372. * \param[in] graph The OrtGraph instance.
  5373. * \param[out] nodes Pre-allocated array of `num_nodes` elements that is filled with the graph's nodes.
  5374. * \param[in] num_nodes The size of the `nodes` array. Typical usage sets this to the
  5375. * result of Graph_GetNumNodes(). An error status is returned if
  5376. * `num_nodes` is less than the number of graph nodes.
  5377. *
  5378. * \snippet{doc} snippets.dox OrtStatus Return Value
  5379. *
  5380. * \since Version 1.23.
  5381. */
  5382. ORT_API2_STATUS(Graph_GetNodes, _In_ const OrtGraph* graph,
  5383. _Out_writes_(num_nodes) const OrtNode** nodes, _In_ size_t num_nodes);
  5384. /** \brief Get the parent node for the given graph, if any exists.
  5385. *
  5386. * Certain operator types (e.g., If and Loop) contain nested subgraphs. This function enables
  5387. * access to the parent node (e.g., the If and Loop node) from a nested subgraph.
  5388. *
  5389. * \param[in] graph The OrtGraph instance.
  5390. * \param[out] node Output parameter that is set to the graph's parent node.
  5391. * Set to NULL if a parent node does not exist (e.g., for a top-level graph).
  5392. *
  5393. * \snippet{doc} snippets.dox OrtStatus Return Value
  5394. *
  5395. * \since Version 1.23.
  5396. */
  5397. ORT_API2_STATUS(Graph_GetParentNode, _In_ const OrtGraph* graph, _Outptr_result_maybenull_ const OrtNode** node);
  5398. /** \brief Returns an OrtGraph that contains a subset of nodes in the source OrtGraph.
  5399. *
  5400. * \note The lifetime of "dst_graph" is tied to that of "src_graph", as they both internally reference
  5401. * the same underlying graph.
  5402. *
  5403. * \param[in] src_graph The source OrtGraph instance.
  5404. * \param[in] nodes A subset of the nodes/OrtNodes in 'graph'.
  5405. * \param[in] num_nodes Number of nodes.
  5406. * \param[out] dst_graph An OrtGraph created from a given set of nodes. Must be released by calling ReleaseGraph.
  5407. *
  5408. * \snippet{doc} snippets.dox OrtStatus Return Value
  5409. *
  5410. * \since Version 1.23.
  5411. */
  5412. ORT_API2_STATUS(Graph_GetGraphView, _In_ const OrtGraph* src_graph, _In_ const OrtNode** nodes,
  5413. _In_ size_t num_nodes, _Outptr_ OrtGraph** dst_graph);
  5414. /// @}
  5415. /// \name OrtNode
  5416. /// @{
  5417. /** \brief Returns a node's identifier.
  5418. *
  5419. * The node's identifier is only unique in the node's parent graph. Different nested subgraphs
  5420. * (e.g., subgraphs contained by If and Loop nodes) may reuse identifiers.
  5421. *
  5422. * \param[in] node The OrtNode instance.
  5423. * \param[out] node_id Output parameter set to the node's identifier.
  5424. *
  5425. * \snippet{doc} snippets.dox OrtStatus Return Value
  5426. *
  5427. * \since Version 1.23.
  5428. */
  5429. ORT_API2_STATUS(Node_GetId, _In_ const OrtNode* node, _Out_ size_t* node_id);
  5430. /** \brief Returns a node's name. Can be an empty string.
  5431. *
  5432. * \param[in] node The OrtNode instance.
  5433. * \param[out] node_name Output parameter set to the node's name.
  5434. *
  5435. * \snippet{doc} snippets.dox OrtStatus Return Value
  5436. *
  5437. * \since Version 1.23.
  5438. */
  5439. ORT_API2_STATUS(Node_GetName, _In_ const OrtNode* node, _Outptr_ const char** node_name);
  5440. /** \brief Returns a node's operator type (e.g., "Conv").
  5441. *
  5442. * \param[in] node The OrtNode instance.
  5443. * \param[out] operator_type Output parameter set to the name of the node's operator type.
  5444. *
  5445. * \snippet{doc} snippets.dox OrtStatus Return Value
  5446. *
  5447. * \since Version 1.23.
  5448. */
  5449. ORT_API2_STATUS(Node_GetOperatorType, _In_ const OrtNode* node, _Outptr_ const char** operator_type);
  5450. /** \brief Returns a node's domain name.
  5451. *
  5452. * \param[in] node The OrtNode instance.
  5453. * \param[out] domain_name Output parameter set to the node's domain name.
  5454. *
  5455. * \snippet{doc} snippets.dox OrtStatus Return Value
  5456. *
  5457. * \since Version 1.23.
  5458. */
  5459. ORT_API2_STATUS(Node_GetDomain, _In_ const OrtNode* node, _Outptr_ const char** domain_name);
  5460. /** \brief Get the opset version in which the given node's operator type was first defined.
  5461. *
  5462. * \param[in] node The OrtNode instance.
  5463. * \param[out] since_version The opset version in which the node's operator type was first defined.
  5464. *
  5465. * \snippet{doc} snippets.dox OrtStatus Return Value
  5466. *
  5467. * \since Version 1.23.
  5468. */
  5469. ORT_API2_STATUS(Node_GetSinceVersion, _In_ const OrtNode* node, _Out_ int* since_version);
  5470. /** \brief Returns the number of node inputs.
  5471. *
  5472. * \param[in] node The OrtNode instance.
  5473. * \param[out] num_inputs Output parameter set to the number of node inputs.
  5474. *
  5475. * \snippet{doc} snippets.dox OrtStatus Return Value
  5476. *
  5477. * \since Version 1.23.
  5478. */
  5479. ORT_API2_STATUS(Node_GetNumInputs, _In_ const OrtNode* node, _Out_ size_t* num_inputs);
  5480. /** \brief Returns the node's inputs as OrtValueInfo instances.
  5481. *
  5482. * \param[in] node The OrtNode instance.
  5483. * \param[out] inputs Pre-allocated array of `num_inputs` elements that is filled with the node's inputs.
  5484. * \param[in] num_inputs The size of the `inputs` array.
  5485. * Typical usage sets this to the result of Node_GetNumInputs(). An error status is
  5486. * returned if `num_inputs` is less than the number of node inputs.
  5487. *
  5488. * \snippet{doc} snippets.dox OrtStatus Return Value
  5489. *
  5490. * \since Version 1.23.
  5491. */
  5492. ORT_API2_STATUS(Node_GetInputs, _In_ const OrtNode* node,
  5493. _Out_writes_(num_inputs) const OrtValueInfo** inputs, _In_ size_t num_inputs);
  5494. /** \brief Returns the number of node outputs.
  5495. *
  5496. * \param[in] node The OrtNode instance.
  5497. * \param[out] num_outputs Output parameter set to the number of node outputs.
  5498. *
  5499. * \snippet{doc} snippets.dox OrtStatus Return Value
  5500. *
  5501. * \since Version 1.23.
  5502. */
  5503. ORT_API2_STATUS(Node_GetNumOutputs, _In_ const OrtNode* node, _Out_ size_t* num_outputs);
  5504. /** \brief Returns the node's outputs as OrtValueInfo instances.
  5505. *
  5506. * \param[in] node The OrtNode instance.
  5507. * \param[out] outputs Pre-allocated array of `num_outputs` elements that is filled with the node's outputs.
  5508. * \param[in] num_outputs The size of the `outputs` array.
  5509. * Typical usage sets this to the result of Node_GetNumOutputs(). An error status is
  5510. * returned if `num_outputs` is less than the number of node outputs.
  5511. *
  5512. * \snippet{doc} snippets.dox OrtStatus Return Value
  5513. *
  5514. * \since Version 1.23.
  5515. */
  5516. ORT_API2_STATUS(Node_GetOutputs, _In_ const OrtNode* node,
  5517. _Out_writes_(num_outputs) const OrtValueInfo** outputs, _In_ size_t num_outputs);
  5518. /** \brief Returns the number of node implicit inputs.
  5519. *
  5520. * Certain operator types (e.g., If and Loop) contain nested subgraphs. The internal nodes within the nested subgraphs
  5521. * may use values from the outer scope. Those "outer scope" values are considered implicit inputs to the node that
  5522. * contains the subgraphs (e.g., the If or Loop node).
  5523. *
  5524. * \param[in] node The OrtNode instance.
  5525. * \param[out] num_implicit_inputs Output parameter set to the number of node implicit inputs.
  5526. *
  5527. * \snippet{doc} snippets.dox OrtStatus Return Value
  5528. *
  5529. * \since Version 1.23.
  5530. */
  5531. ORT_API2_STATUS(Node_GetNumImplicitInputs, _In_ const OrtNode* node, _Out_ size_t* num_implicit_inputs);
  5532. /** \brief Get the implicit inputs, as OrtValueInfo instances, that are used within the given node's subgraphs.
  5533. *
  5534. * \note Only certain operator types (e.g., If and Loop) contain nested subgraphs.
  5535. * The internal nodes within the nested subgraphs may use values from the outer scope. Those "outer scope" values
  5536. * are considered implicit inputs to the node that contains the subgraphs (e.g., the If or Loop node).
  5537. *
  5538. * \param[in] node The OrtNode instance.
  5539. * \param[out] implicit_inputs Pre-allocated array of `num_implicit_inputs` elements that is filled the node's
  5540. * implicit inputs.
  5541. * \param[in] num_implicit_inputs The size of the `implicit_inputs` array. Typical usage sets this to the result
  5542. * of Node_GetNumImplicitInputs(). An error status is returned if
  5543. * `num_implicit_inputs` is less than the number of node implicit inputs.
  5544. *
  5545. * \snippet{doc} snippets.dox OrtStatus Return Value
  5546. *
  5547. * \since Version 1.23.
  5548. */
  5549. ORT_API2_STATUS(Node_GetImplicitInputs, _In_ const OrtNode* node,
  5550. _Out_writes_(num_implicit_inputs) const OrtValueInfo** implicit_inputs,
  5551. _In_ size_t num_implicit_inputs);
  5552. /** \brief Returns the number of node attributes.
  5553. *
  5554. * \param[in] node The OrtNode instance.
  5555. * \param[out] num_attributes Output parameter set to the number of node attributes.
  5556. *
  5557. * \snippet{doc} snippets.dox OrtStatus Return Value
  5558. *
  5559. * \since Version 1.23.
  5560. */
  5561. ORT_API2_STATUS(Node_GetNumAttributes, _In_ const OrtNode* node, _Out_ size_t* num_attributes);
  5562. /** \brief Returns a node's attributes as OrtOpAttr instances.
  5563. *
  5564. * \param[in] node The OrtNode instance.
  5565. * \param[out] attributes Pre-allocated array of `num_attributes` elements that is filled with the node's attributes.
  5566. * \param[in] num_attributes The size of the `num_attributes` array.
  5567. * Typical usage sets this to the result of Node_GetNumAttributes(). An error status is
  5568. * returned if `num_attributes` is less than the number of node attributes.
  5569. *
  5570. * \note ONNX Runtime automatically sets optional (unset) attributes to their default values if the default value
  5571. * is a constant expression that does not depend on other tensor/model characteristics. Conv's 'kernel_shape'
  5572. * attribute is an example of an optional attribute that does not have a constant default value. This function
  5573. * does not provide any unset optional attributes without a constant default value.
  5574. *
  5575. * \snippet{doc} snippets.dox OrtStatus Return Value
  5576. *
  5577. * \since Version 1.23.
  5578. */
  5579. ORT_API2_STATUS(Node_GetAttributes, _In_ const OrtNode* node,
  5580. _Out_writes_(num_attributes) const OrtOpAttr** attributes, _In_ size_t num_attributes);
  5581. /** \brief Gets the OrtNode's attribute as OrtOpAttr by name.
  5582. *
  5583. * \param[in] node The OrtNode instance.
  5584. * \param[in] attribute_name The name of the attribute
  5585. * \param[out] attribute Output parameter set to the OrtOpAttr instance if an attribute by the given name exists.
  5586. * For an unset optional attribute, `attribute` is set to NULL and a non-error status is
  5587. * returned. For an invalid attribute name, `attribute` is set to NULL and an error status with
  5588. * code ORT_NOT_FOUND is returned.
  5589. *
  5590. * \note ONNX Runtime automatically sets optional (unset) attributes to their default values if the default value
  5591. * is a constant expression that does not depend on other tensor/model characteristics. Conv's 'kernel_shape'
  5592. * attribute is an example of an optional attribute that does not have a constant default value. This function
  5593. * does not provide any unset optional attributes without a constant default value.
  5594. *
  5595. * \snippet{doc} snippets.dox OrtStatus Return Value
  5596. *
  5597. * \since Version 1.23.
  5598. */
  5599. ORT_API2_STATUS(Node_GetAttributeByName, _In_ const OrtNode* node, _In_ const char* attribute_name,
  5600. _Outptr_result_maybenull_ const OrtOpAttr** attribute);
  5601. /** \brief Get the OrtNode's 'TENSOR' attribute as an OrtValue.
  5602. *
  5603. * \param[in] attribute The OrtOpAttr instance.
  5604. * \param[out] attr_tensor If successful, contains the 'TENSOR' attribute as a newly created OrtValue.
  5605. Must be freed with OrtApi::ReleaseValue.
  5606. *
  5607. * \snippet{doc} snippets.dox OrtStatus Return Value
  5608. *
  5609. * \since Version 1.23.
  5610. */
  5611. ORT_API2_STATUS(OpAttr_GetTensorAttributeAsOrtValue, _In_ const OrtOpAttr* attribute,
  5612. _Outptr_result_maybenull_ OrtValue** attr_tensor);
  5613. /** \brief Get the attribute type as OrtOpAttrType from an OrtOpAttr.
  5614. *
  5615. * \param[in] attribute The OrtOpAttr instance.
  5616. * \param[out] type Output the attribute type as OrtOpAttrType.
  5617. *
  5618. * \snippet{doc} snippets.dox OrtStatus Return Value
  5619. *
  5620. * \since Version 1.23.
  5621. */
  5622. ORT_API2_STATUS(OpAttr_GetType, _In_ const OrtOpAttr* attribute, _Out_ OrtOpAttrType* type);
  5623. /** \brief Get the attribute name from an OrtOpAttr.
  5624. *
  5625. * \param[in] attribute The OrtOpAttr instance.
  5626. * \param[out] name Output parameter set to the attribute's name. The name is a null-terminated string.
  5627. *
  5628. * \snippet{doc} snippets.dox OrtStatus Return Value
  5629. *
  5630. * \since Version 1.23.
  5631. */
  5632. ORT_API2_STATUS(OpAttr_GetName, _In_ const OrtOpAttr* attribute, _Outptr_ const char** name);
  5633. /** \brief Returns the number of subgraphs contained by the given node.
  5634. *
  5635. * \note Only certain operator types (e.g., If and Loop) contain nested subgraphs.
  5636. *
  5637. * \param[in] node The OrtNode instance.
  5638. * \param[out] num_subgraphs Output parameter set to the number of node subgraphs.
  5639. *
  5640. * \snippet{doc} snippets.dox OrtStatus Return Value
  5641. *
  5642. * \since Version 1.23.
  5643. */
  5644. ORT_API2_STATUS(Node_GetNumSubgraphs, _In_ const OrtNode* node, _Out_ size_t* num_subgraphs);
  5645. /** \brief Get the subgraphs, as OrtGraph instances, contained by the given node.
  5646. *
  5647. * \note Only certain operator types (e.g., If and Loop) contain nested subgraphs. ONNX nodes store subgraphs in
  5648. * their attributes, however, this function must be used to obtain subgraphs from an OrtNode.
  5649. *
  5650. * \param[in] node The OrtNode instance.
  5651. * \param[out] subgraphs Pre-allocated array of `num_subgraphs` elements that is filled with the node's subgraphs.
  5652. * \param[in] num_subgraphs The size of the `num_subgraphs` array.
  5653. * Typical usage sets this to the result of Node_GetNumSubgraphs(). An error status is
  5654. * returned if `num_subgraphs` is less than the number of node subgraphs.
  5655. * \param[out] attribute_names Optional pre-allocated array of `num_subgraphs` elements that is filled with the
  5656. * attribute names that correspond to the subgraphs. Ignored if set to NULL.
  5657. *
  5658. * \snippet{doc} snippets.dox OrtStatus Return Value
  5659. *
  5660. * \since Version 1.23.
  5661. */
  5662. ORT_API2_STATUS(Node_GetSubgraphs, _In_ const OrtNode* node,
  5663. _Out_writes_(num_subgraphs) const OrtGraph** subgraphs, _In_ size_t num_subgraphs,
  5664. _Out_writes_opt_(num_subgraphs) const char** attribute_names);
  5665. /** \brief Get the node's parent OrtGraph instance.
  5666. *
  5667. * Can return NULL if the OrtNode was created without an owning graph.
  5668. *
  5669. * \param[in] node The OrtNode instance.
  5670. * \param[out] graph Output parameter set to the node's OrtGraph. Can be set to NULL
  5671. * if the node is not currently contained by a graph.
  5672. *
  5673. * \snippet{doc} snippets.dox OrtStatus Return Value
  5674. *
  5675. * \since Version 1.23.
  5676. */
  5677. ORT_API2_STATUS(Node_GetGraph, _In_ const OrtNode* node, _Outptr_result_maybenull_ const OrtGraph** graph);
  5678. /** \brief Returns the execution provider name that this node is assigned to run on.
  5679. * Returns NULL if the node has not been assigned to any execution provider yet.
  5680. * For plugin execution providers, the name is the one returned by OrtEp::GetName.
  5681. *
  5682. * \param[in] node The OrtNode instance.
  5683. * \param[out] out Output execution provider type and can be NULL if node has not been assigned.
  5684. *
  5685. * \snippet{doc} snippets.dox OrtStatus Return Value
  5686. *
  5687. * \since Version 1.23.
  5688. */
  5689. ORT_API2_STATUS(Node_GetEpName, _In_ const OrtNode* node, _Outptr_result_maybenull_ const char** out);
  5690. /// @}
  5691. /// \name OrtExternalInitializerInfo
  5692. /// @{
  5693. /** \brief Release an OrtExternalInitializerInfo instance.
  5694. *
  5695. * \param[in] input OrtExternalInitializerInfo instance to be released.
  5696. *
  5697. * \since Version 1.23.
  5698. */
  5699. ORT_CLASS_RELEASE(ExternalInitializerInfo);
  5700. /** \brief Get the relative path to the file that stores the initializer's data.
  5701. *
  5702. * \note The path is relative to the filesystem directory where the ONNX model was stored.
  5703. * Caller can use Graph_GetModelPath to get the model's full path and construct the absolute path to the
  5704. * external initializer file if necessary.
  5705. *
  5706. * \param[in] info The OrtExternalInitializerInfo instance.
  5707. * \return The relative path to the file that stores the initializer's data. Do NOT free this pointer.
  5708. *
  5709. * \since Version 1.23.
  5710. */
  5711. ORT_API_T(const ORTCHAR_T*, ExternalInitializerInfo_GetFilePath, _In_ const OrtExternalInitializerInfo* info);
  5712. /** \brief Get the byte offset within the file where the initializer's data is stored.
  5713. *
  5714. * \param[in] info The OrtExternalInitializerInfo instance.
  5715. * \return The byte offset where the initializer's data is stored within the file.
  5716. *
  5717. * \since Version 1.23.
  5718. */
  5719. ORT_API_T(int64_t, ExternalInitializerInfo_GetFileOffset, _In_ const OrtExternalInitializerInfo* info);
  5720. /** \brief Get the size in bytes of the initializer's data within the file.
  5721. *
  5722. * \param[in] info The OrtExternalInitializerInfo instance.
  5723. * \return The size in bytes of the initializer's data within the file.
  5724. *
  5725. * \since Version 1.23.
  5726. */
  5727. ORT_API_T(size_t, ExternalInitializerInfo_GetByteSize, _In_ const OrtExternalInitializerInfo* info);
  5728. /// @}
  5729. /// \name OrtRunOptions
  5730. /// @{
  5731. /** \brief Get a run configuration entry.
  5732. *
  5733. * If a run configuration entry with key `config_key` doesn't exist, `config_value` will be set to NULL.
  5734. *
  5735. * `config_key`s are defined in onnxruntime_run_options_config_keys.h.
  5736. *
  5737. * \param[in] options The OrtRunOptions instance.
  5738. * \param[in] config_key The configuration entry key. A null-terminated string.
  5739. * \return The configuration entry value. Either a null-terminated string if the entry was found. nullptr otherwise.
  5740. *
  5741. * \snippet{doc} snippets.dox OrtStatus Return Value
  5742. *
  5743. * \since Version 1.23
  5744. */
  5745. ORT_API_T(const char*, GetRunConfigEntry, _In_ const OrtRunOptions* options,
  5746. _In_z_ const char* config_key);
  5747. /// @}
  5748. /** \brief Get the OrtMemoryInfo for the device.
  5749. *
  5750. * \param[in] ep_device The OrtEpDevice instance to query.
  5751. * \param[in] memory_type The memory type to return.
  5752. * \return A pointer to the OrtMemoryInfo for the device. This may be nullptr if not set.
  5753. * If memory_type is OrtDeviceMemoryType_DEFAULT and nullptr is returned the EP uses CPU memory.
  5754. *
  5755. * \since Version 1.23
  5756. */
  5757. ORT_API_T(const OrtMemoryInfo*, EpDevice_MemoryInfo, _In_ const OrtEpDevice* ep_device,
  5758. _In_ OrtDeviceMemoryType memory_type);
  5759. /** \brief Create/replace a shared allocator for the OrtEpDevice in the OrtEnv.
  5760. *
  5761. * OrtEpDevice maps to the EP factory, and the factory provides the allocator implementation.
  5762. *
  5763. * Both OrtDeviceMemoryType_DEFAULT and OrtDeviceMemoryType_HOST_ACCESSIBLE are optional for an EP to provide.
  5764. * It is EP implementation dependent as to what is available.
  5765. *
  5766. * If a shared allocator already exists for the OrtEpDevice and OrtDeviceMemoryType, it is replaced. This allows
  5767. * changing the shared allocator configuration from the default. e.g. adding an arena.
  5768. *
  5769. * \param[in] env The OrtEnv instance to create the shared allocator in.
  5770. * \param[in] ep_device The OrtEpDevice instance to create the shared allocator for.
  5771. * \param[in] mem_type The memory type to use for the shared allocator.
  5772. * \param[in] allocator_type The type of allocator to create. Only OrtDeviceAllocator is valid currently.
  5773. * \param[in] allocator_options Optional key-value pairs to configure the allocator. If arena based, see
  5774. * include/onnxruntime/core/framework/allocator.h for the keys and values that can be
  5775. * used.
  5776. * \param[out] allocator A pointer to the created shared allocator. Owned by the OrtEnv instance.
  5777. *
  5778. * \snippet{doc} snippets.dox OrtStatus Return Value
  5779. *
  5780. * \since Version 1.23
  5781. */
  5782. ORT_API2_STATUS(CreateSharedAllocator, _In_ OrtEnv* env, _In_ const OrtEpDevice* ep_device,
  5783. _In_ OrtDeviceMemoryType mem_type, _In_ OrtAllocatorType allocator_type,
  5784. _In_opt_ const OrtKeyValuePairs* allocator_options,
  5785. _Outptr_opt_ OrtAllocator** allocator);
  5786. /** \brief Get a shared allocator from the OrtEnv.
  5787. *
  5788. * By default there is a shared allocator created for all OrtEpDevice instances, so if you get the OrtMemoryInfo
  5789. * from the OrtEpDevice using EpDevice_MemoryInfo a shared allocator is guaranteed to exist.
  5790. *
  5791. * This will also match and return custom allocators added with RegisterAllocator.
  5792. *
  5793. * It is not an error to not find a matching allocator.
  5794. *
  5795. * \param[in] env The OrtEnv instance to get the shared allocator from.
  5796. * \param[in] mem_info The OrtMemoryInfo instance to get the shared allocator for.
  5797. * \param[out] allocator A pointer to the shared allocator, or nullptr if no shared allocator exists for
  5798. * the given memory info.
  5799. *
  5800. * \snippet{doc} snippets.dox OrtStatus Return Value
  5801. *
  5802. * \since Version 1.23
  5803. */
  5804. ORT_API2_STATUS(GetSharedAllocator, _In_ OrtEnv* env, _In_ const OrtMemoryInfo* mem_info,
  5805. _Outptr_result_maybenull_ OrtAllocator** allocator);
  5806. /** \brief Release a shared allocator from the OrtEnv for the OrtEpDevice and memory type.
  5807. *
  5808. * This will release the shared allocator for the given OrtEpDevice and memory type.
  5809. * If no shared allocator exists, this is a no-op.
  5810. *
  5811. * \param[in] env The OrtEnv instance to release the shared allocator from.
  5812. * \param[in] ep_device The OrtEpDevice instance to release the shared allocator for.
  5813. * \param[in] mem_type The memory type of the shared allocator to release.
  5814. *
  5815. * \snippet{doc} snippets.dox OrtStatus Return Value
  5816. *
  5817. * \since Version 1.23
  5818. */
  5819. ORT_API2_STATUS(ReleaseSharedAllocator, _In_ OrtEnv* env, _In_ const OrtEpDevice* ep_device,
  5820. _In_ OrtDeviceMemoryType mem_type);
  5821. /** \brief Get a const pointer to the raw data inside a tensor
  5822. *
  5823. * Used to read the internal tensor data directly.
  5824. * \note The returned pointer is valid until the OrtValue is destroyed.
  5825. *
  5826. * \param[in] value A tensor type (string tensors are not supported)
  5827. * \param[out] out Filled in with a pointer to the internal storage
  5828. *
  5829. * \snippet{doc} snippets.dox OrtStatus Return Value
  5830. *
  5831. * \since Version 1.23
  5832. */
  5833. ORT_API2_STATUS(GetTensorData, _In_ const OrtValue* value, _Outptr_ const void** out);
  5834. /** \brief Get Session configuration entries.
  5835. *
  5836. * \param[in] options The session options.
  5837. * \param[out] out A pointer to a newly created OrtKeyValuePairs instance.
  5838. *
  5839. * An OrtKeyValuePairs instance containing all session configuration entries.
  5840. * Note: the user should call OrtApi::ReleaseKeyValuePairs.
  5841. *
  5842. * \since Version 1.23.
  5843. */
  5844. ORT_API2_STATUS(GetSessionOptionsConfigEntries, _In_ const OrtSessionOptions* options, _Outptr_ OrtKeyValuePairs** out);
  5845. /** \brief Get the OrtMemoryInfo for each input of the session.
  5846. *
  5847. * The memory info can be used to determine where the input tensors are required.
  5848. *
  5849. * The session must be fully initialized before calling this function as the input locations are not known until
  5850. * this has occurred.
  5851. *
  5852. * \param[in] session The OrtSession instance.
  5853. * \param[out] inputs_memory_info Pre-allocated array of size `num_inputs` that will be filled with the
  5854. * OrtMemoryInfo* value for each input.
  5855. * The order is the same as returned by SessionGetInputName.
  5856. * \param[in] num_inputs The number of inputs in the session. Must match SessionGetInputCount.
  5857. *
  5858. * \snippet{doc} snippets.dox OrtStatus Return Value
  5859. *
  5860. * \since Version 1.23
  5861. */
  5862. ORT_API2_STATUS(SessionGetMemoryInfoForInputs, _In_ const OrtSession* session,
  5863. _Out_writes_(num_inputs) const OrtMemoryInfo** inputs_memory_info,
  5864. _In_ size_t num_inputs);
  5865. /** \brief Get the OrtMemoryInfo for each output of the session.
  5866. *
  5867. * The memory info can be used to determine the device the output tensors are produced on.
  5868. * The user can pre-allocate an OrtValue using this information or use IOBinding to keep the data on the device.
  5869. * ORT will copy the output to CPU otherwise.
  5870. *
  5871. * The session must be fully initialized before calling this function as the output locations are not known until
  5872. * this has occurred.
  5873. *
  5874. * \param[in] session The OrtSession instance.
  5875. * \param[out] outputs_memory_info Pre-allocated array of size `num_outputs` that will be filled with
  5876. * OrtMemoryInfo* values for each output.
  5877. * The order is the same as returned by SessionGetOutputName.
  5878. * \param[in] num_outputs The number of outputs in the session. Must match SessionGetOutputCount.
  5879. *
  5880. * \snippet{doc} snippets.dox OrtStatus Return Value
  5881. *
  5882. * \since Version 1.23
  5883. */
  5884. ORT_API2_STATUS(SessionGetMemoryInfoForOutputs, _In_ const OrtSession* session,
  5885. _Out_writes_(num_outputs) const OrtMemoryInfo** outputs_memory_info,
  5886. _In_ size_t num_outputs);
  5887. /** \brief Get the OrtEpDevice (if available) for each input of the session.
  5888. *
  5889. * An OrtEpDevice will be available if auto EP selection is enabled by calling
  5890. * SessionOptionsSetEpSelectionPolicy or SessionOptionsSetEpSelectionPolicyDelegate,
  5891. * or if the OrtEpDevice was manually added to the session using SessionOptionsAppendExecutionProvider_V2.
  5892. *
  5893. * If an OrtEpDevice is not available for the input a nullptr is returned.
  5894. *
  5895. * The returned OrtEpDevice can be used to create an OrtSyncStream via CreateSyncStreamForEpDevice to asynchronously
  5896. * provide input to the inference session Run.
  5897. *
  5898. * The session must be fully initialized before calling this function as the assigned EPs are not known until
  5899. * this has occurred.
  5900. *
  5901. * \param[in] session The OrtSession instance.
  5902. * \param[out] inputs_ep_devices Pre-allocated array of size `num_inputs` that will be filled with
  5903. * OrtEpDevice* values for each input.
  5904. * The order is the same as returned by SessionGetInputName.
  5905. * \param[in] num_inputs The number of inputs in the session. Must match SessionGetInputCount.
  5906. *
  5907. * \snippet{doc} snippets.dox OrtStatus Return Value
  5908. *
  5909. * \since Version 1.23
  5910. */
  5911. ORT_API2_STATUS(SessionGetEpDeviceForInputs, _In_ const OrtSession* session,
  5912. _Out_writes_(num_inputs) const OrtEpDevice** inputs_ep_devices,
  5913. _In_ size_t num_inputs);
  5914. /** \brief Create an OrtSyncStream for the given OrtEpDevice.
  5915. *
  5916. * The OrtSyncStream can be used to enable asynchronous operations.
  5917. * e.g. async usage of CopyTensors to provide input to an OrtSession Run call.
  5918. *
  5919. * An error code of ORT_NOT_IMPLEMENTED will be returned if the EP does not support OrtSyncStream.
  5920. *
  5921. * \param[in] ep_device The OrtEpDevice instance to create the sync stream for.
  5922. * \param[in] stream_options Options for OrtSyncStream creation. May be nullptr.
  5923. * \param[out] stream Output parameter set to the created OrtSyncStream instance.
  5924. *
  5925. * \snippet{doc} snippets.dox OrtStatus Return Value
  5926. *
  5927. * \since Version 1.23
  5928. */
  5929. ORT_API2_STATUS(CreateSyncStreamForEpDevice, _In_ const OrtEpDevice* ep_device,
  5930. _In_opt_ const OrtKeyValuePairs* stream_options,
  5931. _Outptr_ OrtSyncStream** stream);
  5932. /** \brief Get the native handle of the sync stream.
  5933. *
  5934. * This returns the native handle for the stream. e.g. cudaStream_t for CUDA streams.
  5935. *
  5936. * \param[in] stream The OrtSyncStream instance to get the handle from.
  5937. *
  5938. * \returns The native handle of the stream.
  5939. *
  5940. * \since Version 1.23
  5941. */
  5942. ORT_API_T(void*, SyncStream_GetHandle, _In_ OrtSyncStream* stream);
  5943. ORT_CLASS_RELEASE(SyncStream);
  5944. /** \brief Copy OrtValue instances containing Tensors between devices.
  5945. *
  5946. * The overall copy must be between a single source device and a single destination device. i.e.
  5947. * - all src_tensors must have matching OrtMemoryInfo,
  5948. * - all dst_tensors must have matching OrtMemoryInfo.
  5949. *
  5950. * OrtValue instances can be created by:
  5951. * - Use GetSharedAllocator to get the shared allocator for the OrtMemoryInfo if you need to allocate memory
  5952. * on the device.
  5953. * - Use CreateTensorAsOrtValue, CreateTensorWithDataAsOrtValue or CreateTensorWithDataAndDeleterAsOrtValue
  5954. * to create an OrtValue containing a tensor depending on whether you have existing data or not, and whether
  5955. * you want ORT to free the existing data once it is done with the OrtValue.
  5956. *
  5957. * \param[in] env The OrtEnv instance to use. The data transfer implementation is provided by an execution provider
  5958. * that is registered in this OrtEnv.
  5959. * \param[in] src_tensors Array of OrtValue instances containing the source tensors to copy.
  5960. * \param[in] dst_tensors Array of OrtValue instances to copy the source tensors to.
  5961. * \param[in] stream Optional OrtSyncStream that can be used to perform the copy asynchronously. May be nullptr.
  5962. * \param[in] num_tensors The number of tensors to copy. The size of `src_tensors` and `dst_tensors` must match.
  5963. *
  5964. * \snippet{doc} snippets.dox OrtStatus Return Value
  5965. *
  5966. * \since Version 1.23
  5967. */
  5968. ORT_API2_STATUS(CopyTensors, _In_ const OrtEnv* env,
  5969. _In_reads_(num_tensors) const OrtValue* const* src_tensors,
  5970. _In_reads_(num_tensors) OrtValue* const* dst_tensors,
  5971. _In_opt_ OrtSyncStream* stream,
  5972. _In_ size_t num_tensors);
  5973. /** \brief Get ::OrtModelMetadata from an ::OrtGraph
  5974. *
  5975. * \param[in] graph The OrtGraph instance.
  5976. * \param[out] out Newly created ::OrtModelMetadata. Must be freed using OrtApi::ReleaseModelMetadata.
  5977. *
  5978. * \snippet{doc} snippets.dox OrtStatus Return Value
  5979. *
  5980. * \since Version 1.23.
  5981. */
  5982. ORT_API2_STATUS(Graph_GetModelMetadata, _In_ const OrtGraph* graph, _Outptr_ OrtModelMetadata** out);
  5983. /** \brief Validate a compiled model's compatibility information for one or more EP devices.
  5984. *
  5985. * \param[in] ep_devices The EP devices to validate against (e.g., from GetEpDevices).
  5986. * All devices must belong to the same execution provider.
  5987. * \param[in] num_ep_devices The number of EP devices provided.
  5988. * \param[in] compatibility_info The compatibility info string produced when the model was compiled.
  5989. * \param[out] out_status The resulting compatibility status for the EP devices.
  5990. *
  5991. * \snippet{doc} snippets.dox OrtStatus Return Value
  5992. *
  5993. * \since Version 1.23.
  5994. */
  5995. ORT_API2_STATUS(GetModelCompatibilityForEpDevices,
  5996. _In_reads_(num_ep_devices) const OrtEpDevice* const* ep_devices,
  5997. _In_ size_t num_ep_devices,
  5998. _In_ const char* compatibility_info,
  5999. _Out_ OrtCompiledModelCompatibility* out_status);
  6000. /// \name OrtExternalInitializerInfo
  6001. /// @{
  6002. /** \brief Creates an OrtExternalInitializerInfo instance.
  6003. *
  6004. * \param[in] filepath The relative path to the file that stores the initializer's data. ORT copies this path string.
  6005. * \param[in] file_offset The byte offset where the initializer's data is stored within the file.
  6006. * \param[in] byte_size The size in bytes of the initializer's data within the file.
  6007. * \param[out] out Output parameter set to the new OrtExternalInitializerInfo instance.
  6008. * Must be released by calling ReleaseExternalInitializerInfo().
  6009. *
  6010. * \snippet{doc} snippets.dox OrtStatus Return Value
  6011. *
  6012. * \since Version 1.23.
  6013. */
  6014. ORT_API2_STATUS(CreateExternalInitializerInfo, _In_ const ORTCHAR_T* filepath, _In_ int64_t file_offset,
  6015. _In_ size_t byte_size, _Outptr_ OrtExternalInitializerInfo** out);
  6016. /// @}
  6017. };
  6018. /*
  6019. * Steps to use a custom op:
  6020. * 1 Create an OrtCustomOpDomain with the domain name used by the custom ops
  6021. * 2 Create an OrtCustomOp structure for each op and add them to the domain
  6022. * 3 Call OrtAddCustomOpDomain to add the custom domain of ops to the session options
  6023. */
  6024. // Specifies some characteristics of inputs/outputs of custom ops:
  6025. // Specify if the inputs/outputs are one of:
  6026. // 1) Non-optional (input/output must be present in the node)
  6027. // 2) Optional (input/output may be absent in the node)
  6028. // 3) Variadic: A variadic input or output specifies N (i.e., the minimum arity) or more operands.
  6029. // Only the last input or output of a custom op may be marked as variadic.
  6030. // The homogeneity of the variadic input or output determines whether all operands must be of the same
  6031. // tensor element type.
  6032. typedef enum OrtCustomOpInputOutputCharacteristic {
  6033. INPUT_OUTPUT_REQUIRED = 0,
  6034. INPUT_OUTPUT_OPTIONAL,
  6035. INPUT_OUTPUT_VARIADIC,
  6036. } OrtCustomOpInputOutputCharacteristic;
  6037. /*
  6038. * The OrtCustomOp structure defines a custom op's schema and its kernel callbacks. The callbacks are filled in by
  6039. * the implementor of the custom op.
  6040. */
  6041. struct OrtCustomOp {
  6042. uint32_t version; // Must be initialized to ORT_API_VERSION
  6043. // This callback creates the kernel, which is a user defined
  6044. // parameter that is passed to the Kernel* callbacks below. It is
  6045. // recommended to use CreateKernelV2 which allows for a safe error
  6046. // propagation by returning an OrtStatusPtr.
  6047. void*(ORT_API_CALL* CreateKernel)(_In_ const struct OrtCustomOp* op, _In_ const OrtApi* api,
  6048. _In_ const OrtKernelInfo* info);
  6049. // Returns the name of the op
  6050. const char*(ORT_API_CALL* GetName)(_In_ const struct OrtCustomOp* op);
  6051. // Returns the type of the execution provider, return nullptr to use CPU execution provider
  6052. const char*(ORT_API_CALL* GetExecutionProviderType)(_In_ const struct OrtCustomOp* op);
  6053. // Returns the count and types of the input & output tensors
  6054. ONNXTensorElementDataType(ORT_API_CALL* GetInputType)(_In_ const struct OrtCustomOp* op, _In_ size_t index);
  6055. size_t(ORT_API_CALL* GetInputTypeCount)(_In_ const struct OrtCustomOp* op);
  6056. ONNXTensorElementDataType(ORT_API_CALL* GetOutputType)(_In_ const struct OrtCustomOp* op, _In_ size_t index);
  6057. size_t(ORT_API_CALL* GetOutputTypeCount)(_In_ const struct OrtCustomOp* op);
  6058. // Perform a computation step. It is recommended to use
  6059. // KernelComputeV2 which allows for a safe error propagation by
  6060. // returning an OrtStatusPtr.
  6061. void(ORT_API_CALL* KernelCompute)(_In_ void* op_kernel, _In_ OrtKernelContext* context);
  6062. void(ORT_API_CALL* KernelDestroy)(_In_ void* op_kernel);
  6063. // Returns the characteristics of the input & output tensors
  6064. OrtCustomOpInputOutputCharacteristic(ORT_API_CALL* GetInputCharacteristic)(_In_ const struct OrtCustomOp* op, _In_ size_t index);
  6065. OrtCustomOpInputOutputCharacteristic(ORT_API_CALL* GetOutputCharacteristic)(_In_ const struct OrtCustomOp* op, _In_ size_t index);
  6066. // Returns the memory type of the input tensors. This API allows the custom op
  6067. // to place the inputs on specific devices. By default, it returns
  6068. // OrtMemTypeDefault, which means the input is placed on the default device for
  6069. // the execution provider. If the inputs need to be with different memory types,
  6070. // this function can be overridden to return the specific memory types.
  6071. OrtMemType(ORT_API_CALL* GetInputMemoryType)(_In_ const struct OrtCustomOp* op, _In_ size_t index);
  6072. // Returns the minimum number of input arguments expected for the variadic input.
  6073. // Applicable only for custom ops that have a variadic input.
  6074. int(ORT_API_CALL* GetVariadicInputMinArity)(_In_ const struct OrtCustomOp* op);
  6075. // Returns true (non-zero) if all arguments of a variadic input have to be of the same type (homogeneous),
  6076. // and false (zero) otherwise.
  6077. // Applicable only for custom ops that have a variadic input.
  6078. int(ORT_API_CALL* GetVariadicInputHomogeneity)(_In_ const struct OrtCustomOp* op);
  6079. // Returns the minimum number of output values expected for the variadic output.
  6080. // Applicable only for custom ops that have a variadic output.
  6081. int(ORT_API_CALL* GetVariadicOutputMinArity)(_In_ const struct OrtCustomOp* op);
  6082. // Returns true (non-zero) if all outputs values of a variadic output have to be of the same type (homogeneous),
  6083. // and false (zero) otherwise.
  6084. // Applicable only for custom ops that have a variadic output.
  6085. int(ORT_API_CALL* GetVariadicOutputHomogeneity)(_In_ const struct OrtCustomOp* op);
  6086. // Create the kernel state which is passed to each compute call.
  6087. OrtStatusPtr(ORT_API_CALL* CreateKernelV2)(_In_ const struct OrtCustomOp* op, _In_ const OrtApi* api,
  6088. _In_ const OrtKernelInfo* info,
  6089. _Out_ void** kernel);
  6090. // Perform the computation step.
  6091. OrtStatusPtr(ORT_API_CALL* KernelComputeV2)(_In_ void* op_kernel, _In_ OrtKernelContext* context);
  6092. OrtStatusPtr(ORT_API_CALL* InferOutputShapeFn)(_In_ const struct OrtCustomOp* op, _In_ OrtShapeInferContext*);
  6093. // Get start range
  6094. int(ORT_API_CALL* GetStartVersion)(_In_ const struct OrtCustomOp* op);
  6095. int(ORT_API_CALL* GetEndVersion)(_In_ const struct OrtCustomOp* op);
  6096. // Get the inplace_map that defines which output can reuse which input
  6097. // Callers will provide 2 raw int* and pass in their address, this function will fill these 2 arrays
  6098. // when return, output (*output_index)[i] may reuse the input (*input_index[i]).
  6099. // The return value is the size of these 2 arrays.
  6100. // Callers are responsible to delete these 2 arrays after use by calling OrtCustomOp::ReleaseMayInplace().
  6101. size_t(ORT_API_CALL* GetMayInplace)(_Out_ int** input_index, _Out_ int** output_index);
  6102. // Release the pointer input_index and output_index allocated from GetMayInplace() function.
  6103. // If GetMayInplace() is defined, this function MUST be defined as well.
  6104. void(ORT_API_CALL* ReleaseMayInplace)(_Frees_ptr_opt_ int* input_index, _Frees_ptr_opt_ int* output_index);
  6105. // Same as GetMayInplace() and ReleaseMayInplace()
  6106. size_t(ORT_API_CALL* GetAliasMap)(_Out_ int** input_index, _Out_ int** output_index);
  6107. void(ORT_API_CALL* ReleaseAliasMap)(_Frees_ptr_opt_ int* input_index, _Frees_ptr_opt_ int* output_index);
  6108. };
  6109. /**
  6110. * ORT Model Editor API
  6111. */
  6112. /**
  6113. * \brief The OrtModelEditorApi struct provides functions to create or edit an ONNX model.
  6114. *
  6115. * See onnxruntime/test/shared_lib/test_model_editor_api.cc for example usage.
  6116. *
  6117. * \since Version 1.22.
  6118. */
  6119. struct OrtModelEditorApi {
  6120. // Model building/editing requires a full build. We return nullptr from GetModelEditorApi if this is a minimal
  6121. // build, so it doesn't matter if there are no function pointers in this struct as a user will never get an
  6122. // OrtModelEditorApi instance. We do however need a dummy field to avoid empty struct warning.
  6123. #if defined(ORT_MINIMAL_BUILD)
  6124. const bool not_defined_in_this_build;
  6125. #else
  6126. /** \brief Create an OrtTypeInfo instance for a Tensor.
  6127. *
  6128. * Create an OrtTypeInfo instance for a Tensor to use as graph inputs/outputs with the Model Editor API.
  6129. *
  6130. * User can release `tensor_info` after creating the OrtTypeInfo.
  6131. *
  6132. * \param[in] tensor_info Tensor type and shape information.
  6133. * \param[out] type_info TypeInfo instance for the tensor.
  6134. *
  6135. * \snippet{doc} snippets.dox OrtStatus Return Value
  6136. *
  6137. * \since Version 1.22.
  6138. */
  6139. ORT_API2_STATUS(CreateTensorTypeInfo, _In_ const OrtTensorTypeAndShapeInfo* tensor_info,
  6140. _Outptr_ OrtTypeInfo** type_info);
  6141. /** \brief Create an OrtTypeInfo instance for a SparseTensor.
  6142. *
  6143. * Create an OrtTypeInfo instance for a SparseTensor to use as graph inputs/outputs with the Model Editor API.
  6144. *
  6145. * User can release `tensor_info` after creating the OrtTypeInfo.
  6146. *
  6147. * \param[in] tensor_info SparseTensor type and shape information.
  6148. * \param[out] type_info TypeInfo instance for the tensor.
  6149. *
  6150. * \snippet{doc} snippets.dox OrtStatus Return Value
  6151. *
  6152. * \since Version 1.22.
  6153. */
  6154. ORT_API2_STATUS(CreateSparseTensorTypeInfo, _In_ const OrtTensorTypeAndShapeInfo* tensor_info,
  6155. _Outptr_ OrtTypeInfo** type_info);
  6156. /** \brief Create an OrtTypeInfo instance for a Map.
  6157. *
  6158. * Create an OrtTypeInfo instance for a Map to use as graph inputs/outputs with the Model Editor API.
  6159. *
  6160. * User can release `map_value_type` after creating the OrtTypeInfo.
  6161. *
  6162. * \param[in] map_key_type Key type for the map.
  6163. * \param[in] map_value_type Value type for the map.
  6164. * \param[out] type_info TypeInfo instance for the map.
  6165. *
  6166. * \snippet{doc} snippets.dox OrtStatus Return Value
  6167. *
  6168. * \since Version 1.22.
  6169. */
  6170. ORT_API2_STATUS(CreateMapTypeInfo, ONNXTensorElementDataType map_key_type, _In_ const OrtTypeInfo* map_value_type,
  6171. _Outptr_ OrtTypeInfo** type_info);
  6172. /** \brief Create an OrtTypeInfo instance for a Sequence.
  6173. *
  6174. * Create an OrtTypeInfo instance for a Sequence to use as graph inputs/outputs with the Model Editor API.
  6175. *
  6176. * User can release `sequence_type` after creating the OrtTypeInfo.
  6177. *
  6178. * \param[in] sequence_type Sequence type and shape information.
  6179. * \param[out] type_info TypeInfo instance for the sequence.
  6180. *
  6181. * \snippet{doc} snippets.dox OrtStatus Return Value
  6182. *
  6183. * \since Version 1.22.
  6184. */
  6185. ORT_API2_STATUS(CreateSequenceTypeInfo, _In_ const OrtTypeInfo* sequence_type, _Outptr_ OrtTypeInfo** type_info);
  6186. /** \brief Create an OrtTypeInfo instance for an Optional.
  6187. *
  6188. * Create an OrtTypeInfo instance for an Optional to use as graph inputs/outputs with the Model Editor API.
  6189. *
  6190. * User can release `contained_type` after creating the OrtTypeInfo.
  6191. *
  6192. * \param[in] contained_type Tensor type and shape information.
  6193. * \param[out] type_info TypeInfo instance for the tensor.
  6194. *
  6195. * \snippet{doc} snippets.dox OrtStatus Return Value
  6196. *
  6197. * \since Version 1.22.
  6198. */
  6199. ORT_API2_STATUS(CreateOptionalTypeInfo, _In_ const OrtTypeInfo* contained_type, _Outptr_ OrtTypeInfo** type_info);
  6200. /** \brief Create an OrtValueInfo for use as an OrtGraph input or output.
  6201. *
  6202. * \param[in] name The name of the input or output.
  6203. * \param[in] type_info The type information for the input or output. The provided value is copied.
  6204. * \param[out] value_info The OrtValueInfo instance.
  6205. *
  6206. * \snippet{doc} snippets.dox OrtStatus Return Value
  6207. *
  6208. * \since Version 1.22.
  6209. */
  6210. ORT_API2_STATUS(CreateValueInfo, _In_ const char* name, _In_ const OrtTypeInfo* type_info,
  6211. _Outptr_ OrtValueInfo** value_info);
  6212. /** \brief Create an OrtNode to add to an OrtGraph.
  6213. *
  6214. * Create an OrtNode.
  6215. *
  6216. * Create attributes with CreateOpAttr. OrtOpAttr instances are copied.
  6217. *
  6218. * \param[in] operator_name The name of the operator.
  6219. * \param[in] domain_name The domain of the operator. Use an empty string for ONNX operators.
  6220. * \param[in] node_name The name of the node.
  6221. * \param[in] input_names The names of the inputs.
  6222. * \param[in] input_names_len The number of input names.
  6223. * \param[in] output_names The names of the outputs.
  6224. * \param[in] output_names_len The number of output names.
  6225. * \param[in] attributes The optional attributes of the node.
  6226. * \param[in] attribs_len The number of attributes. May be zero.
  6227. * \param[out] node The OrtNode instance.
  6228. *
  6229. * \snippet{doc} snippets.dox OrtStatus Return Value
  6230. *
  6231. * \since Version 1.22.
  6232. */
  6233. ORT_API2_STATUS(CreateNode, _In_ const char* operator_name, _In_ const char* domain_name, _In_ const char* node_name,
  6234. _In_reads_(input_names_len) const char* const* input_names, size_t input_names_len,
  6235. _In_reads_(output_names_len) const char* const* output_names, size_t output_names_len,
  6236. _In_reads_(attribs_len) _In_opt_ OrtOpAttr** attributes, _In_ size_t attribs_len,
  6237. _Outptr_ OrtNode** node);
  6238. /** \brief Create an OrtGraph
  6239. * \snippet{doc} snippets.dox OrtStatus Return Value
  6240. * \since Version 1.22.
  6241. */
  6242. ORT_API2_STATUS(CreateGraph, _Outptr_ OrtGraph** graph);
  6243. /** \brief Set the inputs for the OrtGraph.
  6244. *
  6245. * Set the graph inputs. This will replace any existing inputs with the new values.
  6246. * The OrtGraph takes ownership of the OrtValueInfo instances and you should NOT call ReleaseOrtValueInfo.
  6247. *
  6248. * \param[in] graph The OrtGraph instance to update.
  6249. * \param[in] inputs The input OrtValueInfo instances.
  6250. * \param[in] inputs_len The number of input OrtValueInfo instances.
  6251. *
  6252. * \snippet{doc} snippets.dox OrtStatus Return Value
  6253. *
  6254. * \since Version 1.22.
  6255. */
  6256. ORT_API2_STATUS(SetGraphInputs, _Inout_ OrtGraph* graph,
  6257. _In_reads_(inputs_len) _In_ OrtValueInfo** inputs, _In_ size_t inputs_len);
  6258. /** \brief Set the outputs for the OrtGraph.
  6259. *
  6260. * Set the graph outputs. This will replace any existing outputs with the new values.
  6261. * The OrtGraph takes ownership of the OrtValueInfo instances provided and you should NOT call ReleaseOrtValueInfo.
  6262. *
  6263. * \param[in] graph The OrtGraph instance to update.
  6264. * \param[in] outputs The output OrtValueInfo instances.
  6265. * \param[in] outputs_len The number of output OrtValueInfo instances.
  6266. *
  6267. * \snippet{doc} snippets.dox OrtStatus Return Value
  6268. *
  6269. * \since Version 1.22.
  6270. */
  6271. ORT_API2_STATUS(SetGraphOutputs, _Inout_ OrtGraph* graph,
  6272. _In_reads_(outputs_len) _In_ OrtValueInfo** outputs, _In_ size_t outputs_len);
  6273. /** \brief Add an initializer to the OrtGraph
  6274. *
  6275. * ORT will take ownership of the OrtValue and you should NOT call ReleaseOrtValue.
  6276. *
  6277. * Two options:
  6278. *
  6279. * Allocated memory:
  6280. * Use CreateTensorAsOrtValue (allocates memory) and populate the tensor with the data.
  6281. * Set `data_is_external` to false.
  6282. *
  6283. * Pre-existing memory:
  6284. * Use CreateTensorWithDataAsOrtValue or CreateTensorWithDataAndDeleterAsOrtValue to create an OrtValue
  6285. * with a tensor that contains a pointer to the existing data.
  6286. * Set `data_is_external` to true.
  6287. *
  6288. * The pointer must remain valid for the duration of the inference session.
  6289. * If using CreateTensorWithDataAsOrtValue you are responsible for freeing the memory after the inference session
  6290. * is released.
  6291. * If using CreateTensorWithDataAndDeleterAsOrtValue, ORT will free the memory using the provided deleter as
  6292. * soon as the OrtValue is no longer in use.
  6293. *
  6294. * NOTE: A tensor containing pre-existing memory MUST have 128 bytes of data or more.
  6295. * For smaller tensors use CreateTensorAsOrtValue.
  6296. *
  6297. * ONNX shape inferencing does not support external data. An initializer involved in shape inferencing is
  6298. * typically small (a single value or limited by the rank of a tensor) and uses less than 128 bytes of
  6299. * memory, so this limit acts as a simple catch-all rule to avoid issues.
  6300. * e.g. Reshape's `shape`, Clip's `min` and `max`, various ops `axes`.
  6301. *
  6302. * \param[in] graph The OrtGraph instance to update.
  6303. * \param[in] name The value name for the initializer.
  6304. * \param[in] tensor The OrtValue instance containing the tensor data.
  6305. * \param[in] data_is_external Set to true if the data is external and should not be copied.
  6306. *
  6307. * \snippet{doc} snippets.dox OrtStatus Return Value
  6308. *
  6309. * \since Version 1.22.
  6310. */
  6311. ORT_API2_STATUS(AddInitializerToGraph, _Inout_ OrtGraph* graph, _In_ const char* name, _In_ OrtValue* tensor,
  6312. bool data_is_external);
  6313. /** \brief Add an OrtNode to an OrtGraph
  6314. *
  6315. * Add the node to the graph. The OrtGraph will take ownership of OrtNode and you should NOT call ReleaseOrtNode.
  6316. *
  6317. * \param[in] graph The OrtGraph instance to update.
  6318. * \param[in] node The OrtNode instance to add to the graph.
  6319. *
  6320. * \snippet{doc} snippets.dox OrtStatus Return Value
  6321. *
  6322. * \since Version 1.22.
  6323. */
  6324. ORT_API2_STATUS(AddNodeToGraph, _Inout_ OrtGraph* graph, _In_ OrtNode* node);
  6325. /** \brief Create an OrtModel.
  6326. *
  6327. * Create an OrtModel.
  6328. *
  6329. * This can be used to build a new model, or to augment an existing model.
  6330. *
  6331. * \param[in] domain_names The domain names for the model.
  6332. * If augmenting an existing model add additional domains if needed.
  6333. * \param[in] opset_versions The opset versions for the model.
  6334. * If augmenting an existing model add additional opset versions if needed.
  6335. * \param[in] opset_entries_len The number of domain_names and opset_versions entries.
  6336. * Domain and opset entries should be 1:1
  6337. * \param[out] model The OrtModel instance.
  6338. *
  6339. * \snippet{doc} snippets.dox OrtStatus Return Value
  6340. *
  6341. * \since Version 1.22.
  6342. */
  6343. ORT_API2_STATUS(CreateModel,
  6344. _In_reads_(opset_entries_len) const char* const* domain_names,
  6345. _In_reads_(opset_entries_len) const int* opset_versions,
  6346. size_t opset_entries_len,
  6347. _Outptr_ OrtModel** model);
  6348. /** \brief Add an OrtGraph to an OrtModel.
  6349. *
  6350. * Add the graph to a model. This should be called once when creating a new model.
  6351. *
  6352. * The OrtModel takes ownership of the OrtGraph and you should NOT call ReleaseOrtGraph.
  6353. *
  6354. * \param[in] model The OrtModel instance to update.
  6355. * \param[in] graph The OrtGraph instance to add to the model.
  6356. *
  6357. * \snippet{doc} snippets.dox OrtStatus Return Value
  6358. *
  6359. * \since Version 1.22.
  6360. */
  6361. ORT_API2_STATUS(AddGraphToModel, _Inout_ OrtModel* model, _In_ OrtGraph* graph);
  6362. /** \brief Create an OrtSession using the OrtModel.
  6363. *
  6364. * Create an inference session using the OrtModel instance.
  6365. * The OrtModel should have been populated with an OrtGraph containing nodes and initializers, and SetGraphInputs
  6366. * and SetGraphOutputs must have been called.
  6367. * This will validate the model, run optimizers, and prepare the session for inferencing.
  6368. *
  6369. * ReleaseOrtModel must be called to free the OrtModel after session creation.
  6370. *
  6371. * \param[in] env The OrtEnv instance.
  6372. * \param[in] model The OrtModel instance.
  6373. * \param[in] options The OrtSessionOptions instance.
  6374. * \param[out] out The OrtSession instance.
  6375. *
  6376. * \snippet{doc} snippets.dox OrtStatus Return Value
  6377. *
  6378. * \since Version 1.22.
  6379. */
  6380. ORT_API2_STATUS(CreateSessionFromModel, _In_ const OrtEnv* env, _In_ const OrtModel* model,
  6381. _In_ const OrtSessionOptions* options, _Outptr_ OrtSession** out);
  6382. /** \brief Create an OrtSession to augment an existing model.
  6383. *
  6384. * Create an OrtSession with an existing model that will be augmented with additional nodes and initializers.
  6385. * Nodes can be added before or after the existing nodes in the model. ONNX Runtime will connect the nodes when the
  6386. * model is finalized.
  6387. *
  6388. * To add nodes and initializers to the existing model, first create an OrtModel using CreateModel.
  6389. * Add nodes and initializers to the OrtModel using AddNodeToGraph and AddInitializerToGraph.
  6390. * Graph inputs/outputs should be updated with SetGraphInputs and SetGraphOutputs as needed to reflect changes made
  6391. * by the new nodes. The list of graph inputs/outputs should be for the overall model and not just the new nodes.
  6392. *
  6393. * Add the new information from the OrtModel to the original model using ApplyModelToSession, and prepare the
  6394. * session for inferencing by calling FinalizeModelEditorSession.
  6395. *
  6396. * \param{in} env The OrtEnv instance.
  6397. * \param{in} model_path The path to the existing ONNX model to augment.
  6398. * \param{in} options The OrtSessionOptions instance.
  6399. * \param{out} out The created OrtSession instance.
  6400. * \snippet{doc} snippets.dox OrtStatus Return Value
  6401. *
  6402. * \since Version 1.22.
  6403. */
  6404. ORT_API2_STATUS(CreateModelEditorSession, _In_ const OrtEnv* env, _In_ const ORTCHAR_T* model_path,
  6405. _In_ const OrtSessionOptions* options,
  6406. _Outptr_ OrtSession** out);
  6407. /** \brief Create an OrtSession to augment an existing model.
  6408. *
  6409. * Create an OrtSession with an existing model that will be augmented with additional nodes and initializers.
  6410. * Nodes can be added before or after the existing nodes in the model. ONNX Runtime will connect the nodes when the
  6411. * model is finalized.
  6412. *
  6413. * To add nodes and initializers to the existing model, first create an OrtModel using CreateModel.
  6414. * Add nodes and initializers to the OrtModel using AddNodeToGraph and AddInitializerToGraph.
  6415. * Graph inputs/outputs should be updated with SetGraphInputs and SetGraphOutputs as needed to reflect changes made
  6416. * by the new nodes. The list of graph inputs/outputs should be for the overall model and not just the new nodes.
  6417. *
  6418. * Add the new information from the OrtModel to the original model using ApplyModelToSession, and prepare the
  6419. * session for inferencing by calling FinalizeModelEditorSession.
  6420. *
  6421. * \param{in} env The OrtEnv instance.
  6422. * \param{in} model_data The model data for the existing model to augment.
  6423. * \param{in} model_data_length The length of the model data.
  6424. * \param{in} options The OrtSessionOptions instance.
  6425. * \param{out} out The created OrtSession instance.
  6426. *
  6427. * \snippet{doc} snippets.dox OrtStatus Return Value
  6428. *
  6429. * \since Version 1.22.
  6430. */
  6431. ORT_API2_STATUS(CreateModelEditorSessionFromArray, _In_ const OrtEnv* env,
  6432. _In_ const void* model_data, size_t model_data_length,
  6433. _In_ const OrtSessionOptions* options,
  6434. _Outptr_ OrtSession** out);
  6435. /** \brief Query the session for the opset version of a domain.
  6436. *
  6437. * When using the Model Editor API to augment a model, any new nodes must conform to the opset version of the
  6438. * original model. To do that the user must be able to discover that opset version.
  6439. * Returns an error if the domain is not used in the model.
  6440. *
  6441. * \param[in] session OrtSession to query
  6442. * \param[in] domain Domain to query. The ONNX domain is an empty string.
  6443. * \param[out] opset The opset version of the domain.
  6444. *
  6445. * \snippet{doc} snippets.dox OrtStatus Return Value
  6446. *
  6447. * \since Version 1.22.
  6448. */
  6449. ORT_API2_STATUS(SessionGetOpsetForDomain, _In_ const OrtSession* session, _In_ const char* domain, _Out_ int* opset);
  6450. /** \brief Apply changes to augment the ONNX model in a session created using CreateModelEditorSession[FromArray]
  6451. *
  6452. * Adds new nodes and updates graph inputs/outputs using `model` to augment the original ONNX model in the session.
  6453. * All changes will be validated.
  6454. * Call FinalizeModelEditorSession to prepare the session for inferencing.
  6455. *
  6456. * Existing input/outputs will only be updated if the OrtGraph inputs/outputs are set in the OrtModel.
  6457. * i.e. you don't need to call SetGraphInputs/SetGraphOutputs if they are unchanged.
  6458. *
  6459. * ReleaseOrtModel must be called to free the OrtModel after it is applied to the session.
  6460. *
  6461. * \param[in] session OrtSession to update. Session must have been created using CreateModelEditorSession[FromArray].
  6462. * \param[in] model OrtModel containing new nodes, new initializers, and updated graph input and/or output info.
  6463. *
  6464. * \snippet{doc} snippets.dox OrtStatus Return Value
  6465. *
  6466. * \since Version 1.22.
  6467. */
  6468. ORT_API2_STATUS(ApplyModelToModelEditorSession, _Inout_ OrtSession* session, _In_ OrtModel* model);
  6469. /** \brief Finalize the Model Editor session that was created using CreateModelEditorSession[FromArray].
  6470. *
  6471. * Finalize the Model Editor session that augmented an ONNX model by adding new nodes.
  6472. * This will run optimizers and prepare the session for inferencing.
  6473. *
  6474. * \param[in] session OrtSession to finalize. Session must have been created using CreateModelEditorSession[FromArray].
  6475. * \param[in] options OrtSessionOptions to use for the session.
  6476. * \param[in] prepacked_weights_container Optional OrtPrepackedWeightsContainer to use for the session.
  6477. Set to nullptr if not used.
  6478. * \snippet{doc} snippets.dox OrtStatus Return Value
  6479. *
  6480. * \since Version 1.22.
  6481. */
  6482. ORT_API2_STATUS(FinalizeModelEditorSession, _Inout_ OrtSession* session, _In_ const OrtSessionOptions* options,
  6483. _In_opt_ OrtPrepackedWeightsContainer* prepacked_weights_container);
  6484. #endif // !defined(ORT_MINIMAL_BUILD)
  6485. };
  6486. /**
  6487. * ORT Compile API
  6488. */
  6489. /** \brief Flags representing options to enable when compiling a model.
  6490. */
  6491. typedef enum OrtCompileApiFlags {
  6492. // Default. Do not enable any additional compilation options.
  6493. OrtCompileApiFlags_NONE = 0,
  6494. // Force compilation to return an error (ORT_FAIL) if no nodes were compiled.
  6495. // Otherwise, a model with basic optimizations (ORT_ENABLE_BASIC) is still generated by default.
  6496. OrtCompileApiFlags_ERROR_IF_NO_NODES_COMPILED = 1 << 0,
  6497. // Force compilation to return an error (ORT_FAIL) if a file with the same filename as the output model exists.
  6498. // Otherwise, compilation will automatically overwrite the output file if it exists.
  6499. OrtCompileApiFlags_ERROR_IF_OUTPUT_FILE_EXISTS = 1 << 1,
  6500. } OrtCompileApiFlags;
  6501. /**
  6502. * \brief The OrtCompileApi struct provides functions to compile ONNX models.
  6503. *
  6504. * Execution providers that support compilation fuse a subgraph into an EPContext node that wraps a provider-specific
  6505. * binary representation of the subgraph.
  6506. * For more details about the EPContext design, refer to:
  6507. * \htmlonly
  6508. * <a href="https://onnxruntime.ai/docs/execution-providers/EP-Context-Design.html">EPContext design document.</a>
  6509. * \endhtmlonly
  6510. *
  6511. * Example (error handling not shown):
  6512. * OrtStatus* status = NULL;
  6513. * OrtCompileApi* compile_api = ort_api->GetCompileApi();
  6514. * OrtModelCompilationOptions* compile_options = NULL;
  6515. *
  6516. * status = compile_api->CreateModelCompilationOptionsFromSessionOptions(env, session_options, &compile_options);
  6517. * status = compile_api->ModelCompilationOptions_SetInputModelPath(compile_options, ORT_TSTR("model.onnx"));
  6518. * status = compile_api->ModelCompilationOptions_SetOutputModelPath(compile_options, ORT_TSTR("model.compiled.onnx"));
  6519. * status = compile_api->CompileModel(env, compile_options);
  6520. * compile_api->ReleaseModelCompilationOptions(compile_options);
  6521. *
  6522. * \since Version 1.22.
  6523. */
  6524. struct OrtCompileApi {
  6525. /// \name OrtModelCompilationOptions
  6526. /// @{
  6527. ORT_CLASS_RELEASE(ModelCompilationOptions);
  6528. /** \brief Creates an OrtModelCompilationOptions object from an existing OrtSessionOptions object.
  6529. *
  6530. * An OrtModelCompilationOptions object contains the settings used to generate a compiled ONNX model.
  6531. * The OrtSessionOptions object has the execution providers with which the model will be compiled.
  6532. *
  6533. * ReleaseOrtModelCompilationsOptions must be called to free the OrtModelCompilationOptions after calling
  6534. * CompileModel.
  6535. *
  6536. * \note By default, the GraphOptimizationLevel is set to ORT_DISABLE_ALL. Use
  6537. * ModelCompilationOptions_SetGraphOptimizationLevel to enable graph optimizations.
  6538. *
  6539. * \param[in] env OrtEnv object.
  6540. * \param[in] session_options The OrtSessionOptions instance from which to create the OrtModelCompilationOptions.
  6541. * \param[out] out The created OrtModelCompilationOptions instance.
  6542. * \snippet{doc} snippets.dox OrtStatus Return Value
  6543. *
  6544. * \since Version 1.22.
  6545. */
  6546. ORT_API2_STATUS(CreateModelCompilationOptionsFromSessionOptions, _In_ const OrtEnv* env,
  6547. _In_ const OrtSessionOptions* session_options, _Outptr_ OrtModelCompilationOptions** out);
  6548. /** \brief Sets the file path to the input ONNX model to compile.
  6549. *
  6550. * The input model's location (e.g., file path or memory buffer) must be set with either
  6551. * ModelCompilationOptions_SetInputModelPath or ModelCompilationOptions_SetInputModelFromBuffer.
  6552. *
  6553. * \param[in] model_compile_options The OrtModelCompilationOptions instance.
  6554. * \param[in] input_model_path Null terminated string of the path (wchar on Windows, char otherwise).
  6555. *
  6556. * \snippet{doc} snippets.dox OrtStatus Return Value
  6557. *
  6558. * \since Version 1.22.
  6559. */
  6560. ORT_API2_STATUS(ModelCompilationOptions_SetInputModelPath, _In_ OrtModelCompilationOptions* model_compile_options,
  6561. _In_ const ORTCHAR_T* input_model_path);
  6562. /** \brief Sets the buffer that stores the bytes of the loaded ONNX model to compile.
  6563. *
  6564. * The input model's location (e.g., file path or memory buffer) must be set with either
  6565. * ModelCompilationOptions_SetInputModelPath or ModelCompilationOptions_SetInputModelFromBuffer.
  6566. *
  6567. * \param[in] model_compile_options The OrtModelCompilationOptions instance.
  6568. * \param[in] input_model_data Buffer containing the loaded ONNX model bytes.
  6569. * \param[in] input_model_data_size The number of bytes in the `input_model_data` buffer.
  6570. *
  6571. * \snippet{doc} snippets.dox OrtStatus Return Value
  6572. *
  6573. * \since Version 1.22.
  6574. */
  6575. ORT_API2_STATUS(ModelCompilationOptions_SetInputModelFromBuffer,
  6576. _In_ OrtModelCompilationOptions* model_compile_options,
  6577. _In_ const void* input_model_data,
  6578. size_t input_model_data_size);
  6579. /** \brief Sets the file path for the output ONNX model generated by CompileModel.
  6580. *
  6581. * The output model's location (e.g., file path or memory buffer) can be set with either
  6582. * ModelCompilationOptions_SetOutputModelPath or ModelCompilationOptions_SetOutputModelBuffer.
  6583. *
  6584. * If the output model's location is not set, ONNX Runtime will generate an output file with a path based on
  6585. * the input model's file path. Examples:
  6586. * /Path/my_model.onnx -> /Path/my_model_ctx.onnx
  6587. * /Path/my_model -> /Path/my_model_ctx.onnx
  6588. *
  6589. * \param[in] model_compile_options The OrtModelCompilationOptions instance.
  6590. * \param[in] output_model_path Null terminated string of the path (wchar on Windows, char otherwise).
  6591. *
  6592. * \snippet{doc} snippets.dox OrtStatus Return Value
  6593. *
  6594. * \since Version 1.22.
  6595. */
  6596. ORT_API2_STATUS(ModelCompilationOptions_SetOutputModelPath, _In_ OrtModelCompilationOptions* model_compile_options,
  6597. _In_ const ORTCHAR_T* output_model_path);
  6598. /** \brief Optionally sets the file that should store external initializers for the compiled ONNX model.
  6599. * If not set, initializers are stored within the model.
  6600. *
  6601. * Only initializers for nodes that were not compiled are stored in the external initializers file.
  6602. * Compiled nodes contain their initializer data within the `ep_cache_context` attribute of EPContext nodes.
  6603. * Refer to ModelCompilationOptions_SetEpContextEmbedMode.
  6604. *
  6605. * \param[in] model_compile_options The OrtModelCompilationOptions instance.
  6606. * \param[in] external_initializers_file_path Null terminated string of the path to the file.
  6607. * \param[in] external_initializers_size_threshold Initializers larger than this threshold are stored in the file.
  6608. *
  6609. * \snippet{doc} snippets.dox OrtStatus Return Value
  6610. *
  6611. * \since Version 1.22.
  6612. */
  6613. ORT_API2_STATUS(ModelCompilationOptions_SetOutputModelExternalInitializersFile,
  6614. _In_ OrtModelCompilationOptions* model_compile_options,
  6615. _In_ const ORTCHAR_T* external_initializers_file_path,
  6616. size_t external_initializers_size_threshold);
  6617. /** \brief Configures model compilation to store the output compiled ONNX model in a buffer.
  6618. *
  6619. * The caller passes an OrtAllocator that ONNX Runtime uses to allocate memory for the buffer.
  6620. *
  6621. * The output model's location (e.g., file path or memory buffer) can be set with either
  6622. * ModelCompilationOptions_SetOutputModelPath or ModelCompilationOptions_SetOutputModelBuffer.
  6623. *
  6624. * If the output model's location is not set, ONNX Runtime will generate an output file with a path based on
  6625. * the input model's file path. Examples:
  6626. * /Path/my_model.onnx -> /Path/my_model_ctx.onnx
  6627. * /Path/my_model -> /Path/my_model_ctx.onnx
  6628. *
  6629. * \param[in] model_compile_options The OrtModelCompilationOptions instance.
  6630. * \param[in] allocator The allocator used to allocate the buffer for the compiled model.
  6631. * \param[out] output_model_buffer_ptr Pointer to the buffer that stores the compiled model.
  6632. * \param[out] output_model_buffer_size_ptr Pointer set to the size of output model in bytes.
  6633. *
  6634. * \snippet{doc} snippets.dox OrtStatus Return Value
  6635. *
  6636. * \since Version 1.22.
  6637. */
  6638. ORT_API2_STATUS(ModelCompilationOptions_SetOutputModelBuffer,
  6639. _In_ OrtModelCompilationOptions* model_compile_options,
  6640. _Inout_ OrtAllocator* allocator,
  6641. _Outptr_ void** output_model_buffer_ptr,
  6642. _Out_ size_t* output_model_buffer_size_ptr);
  6643. /** \brief Enables or disables the embedding of EPContext binary data into the `ep_cache_context` attribute
  6644. * of EPContext nodes. Defaults to false.
  6645. *
  6646. * If enabled, the `ep_cache_context` attribute of EPContext nodes will store the context binary data, which may
  6647. * include weights for compiled subgraphs.
  6648. *
  6649. * If disabled, the `ep_cache_context` attribute of EPContext nodes will contain the path to the file containing the
  6650. * context binary data. The path is set by the execution provider creating the EPContext node.
  6651. *
  6652. * More details relate to EPContext design refers to:
  6653. * \htmlonly
  6654. * <a href="https://onnxruntime.ai/docs/execution-providers/EP-Context-Design.html">EPContext design document.</a>
  6655. * \endhtmlonly
  6656. *
  6657. * \param[in] model_compile_options The OrtModelCompilationOptions instance.
  6658. * \param[in] embed_ep_context_in_model True to embed EPContext binary data into the EPContext node
  6659. * `ep_cache_context` attributes.
  6660. *
  6661. * \snippet{doc} snippets.dox OrtStatus Return Value
  6662. *
  6663. * \since Version 1.22.
  6664. */
  6665. ORT_API2_STATUS(ModelCompilationOptions_SetEpContextEmbedMode, _In_ OrtModelCompilationOptions* model_compile_options,
  6666. bool embed_ep_context_in_model);
  6667. /** \brief Compiles an input ONNX model with the given compilation options.
  6668. *
  6669. * \param[in] env OrtEnv object.
  6670. * \param[in] model_options The compilation options that defines compilation options for a model.
  6671. *
  6672. * \snippet{doc} snippets.dox OrtStatus Return Value
  6673. *
  6674. * \since Version 1.22.
  6675. */
  6676. ORT_API2_STATUS(CompileModel, _In_ const OrtEnv* env, _In_ const OrtModelCompilationOptions* model_options);
  6677. /** \brief Sets flags from OrtCompileApiFlags that represent one or more boolean options to enable.
  6678. *
  6679. * \param[in] model_compile_options The OrtModelCompilationOptions instance.
  6680. * \param[in] flags bitwise OR of flags in OrtCompileApiFlags to enable.
  6681. *
  6682. * \snippet{doc} snippets.dox OrtStatus Return Value
  6683. *
  6684. * \since Version 1.23.
  6685. */
  6686. ORT_API2_STATUS(ModelCompilationOptions_SetFlags, _In_ OrtModelCompilationOptions* model_compile_options,
  6687. uint32_t flags);
  6688. /** Sets information related to EP context binary file.
  6689. *
  6690. * EP uses this information to decide the location and context binary file name.
  6691. * Used while compiling model with input and output in memory buffer
  6692. *
  6693. * \param[in] model_compile_options The OrtModelCompilationOptions instance.
  6694. * \param[in] output_directory Null terminated string of the path (wchar on Windows, char otherwise).
  6695. * \param[in] model_name Null terminated string of the model name (wchar on Windows, char otherwise).
  6696. *
  6697. * \snippet{doc} snippets.dox OrtStatus Return Value
  6698. *
  6699. * \since Version 1.23.
  6700. */
  6701. ORT_API2_STATUS(ModelCompilationOptions_SetEpContextBinaryInformation,
  6702. _In_ OrtModelCompilationOptions* model_compile_options,
  6703. _In_ const ORTCHAR_T* output_directory,
  6704. _In_ const ORTCHAR_T* model_name);
  6705. /** Set the graph optimization level.
  6706. *
  6707. * \param[in] model_compile_options The OrtModelCompilationOptions instance.
  6708. * \param[in] graph_optimization_level The graph optimization level.
  6709. *
  6710. * \snippet{doc} snippets.dox OrtStatus Return Value
  6711. *
  6712. * \since Version 1.23.
  6713. */
  6714. ORT_API2_STATUS(ModelCompilationOptions_SetGraphOptimizationLevel,
  6715. _In_ OrtModelCompilationOptions* model_compile_options,
  6716. _In_ GraphOptimizationLevel graph_optimization_level);
  6717. /** \brief Sets a OrtWriteBufferFunc function that is called by ORT to write out the output model's serialized
  6718. * ONNX bytes.
  6719. *
  6720. * The provided write function may be called repeatedly until then entire output model has been written out. Each call
  6721. * to the write function is expected to consume the entire input buffer.
  6722. *
  6723. * The output model's destination (e.g., file path, memory buffer, or stream) can be set with any of the functions
  6724. * that begin with ModelCompilationOptions_SetOutputModel____.
  6725. *
  6726. * \param[in] model_compile_options The OrtModelCompilationOptions instance.
  6727. * \param[in] write_func The OrtWriteBufferFunc function called by ORT when writing out the model.
  6728. * \param[in] state Opaque state passed as the first argument to OrtWriteBufferFunc. Can be NULL.
  6729. *
  6730. * \snippet{doc} snippets.dox OrtStatus Return Value
  6731. *
  6732. * \since Version 1.23.
  6733. */
  6734. ORT_API2_STATUS(ModelCompilationOptions_SetOutputModelWriteFunc,
  6735. _In_ OrtModelCompilationOptions* model_compile_options,
  6736. _In_ OrtWriteBufferFunc write_func, _In_ void* state);
  6737. /** \brief Sets a OrtGetInitializerLocationFunc function that is called by ORT for every initializer in the generated
  6738. * model. Allows implementer to specify whether initializers should be stored within the model or externally.
  6739. *
  6740. * \param[in] model_compile_options The OrtModelCompilationOptions instance.
  6741. * \param[in] get_initializer_location_func The OrtGetInitializerLocationFunc function called by ORT when
  6742. * to determine the location of the initializer.
  6743. * \param[in] state Opaque state passed as the first argument to OrtGetInitializerLocationFunc. Can be NULL.
  6744. *
  6745. * \snippet{doc} snippets.dox OrtStatus Return Value
  6746. *
  6747. * \since Version 1.23.
  6748. */
  6749. ORT_API2_STATUS(ModelCompilationOptions_SetOutputModelGetInitializerLocationFunc,
  6750. _In_ OrtModelCompilationOptions* model_compile_options,
  6751. _In_ OrtGetInitializerLocationFunc get_initializer_location_func, _In_ void* state);
  6752. };
  6753. /*
  6754. * This is the old way to add the CUDA provider to the session, please use SessionOptionsAppendExecutionProvider_CUDA above to access the latest functionality
  6755. * This function always exists, but will only succeed if Onnxruntime was built with CUDA support and the CUDA provider shared library exists
  6756. *
  6757. * \param device_id CUDA device id, starts from zero.
  6758. */
  6759. ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_CUDA, _In_ OrtSessionOptions* options, int device_id);
  6760. /*
  6761. * This is the old way to add the ROCm provider to the session, please use
  6762. * SessionOptionsAppendExecutionProvider_ROCM above to access the latest functionality
  6763. * This function always exists, but will only succeed if Onnxruntime was built with
  6764. * HIP support and the ROCm provider shared library exists
  6765. *
  6766. * \param device_id HIP device id, starts from zero.
  6767. */
  6768. ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_ROCM, _In_ OrtSessionOptions* options, int device_id);
  6769. /*
  6770. * This is the old way to add the MIGraphX provider to the session, please use
  6771. * SessionOptionsAppendExecutionProvider_MIGraphX above to access the latest functionality
  6772. * This function always exists, but will only succeed if Onnxruntime was built with
  6773. * HIP support and the MIGraphX provider shared library exists
  6774. *
  6775. * \param device_id HIP device id, starts from zero.
  6776. */
  6777. ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_MIGraphX, _In_ OrtSessionOptions* options, int device_id);
  6778. /*
  6779. * This is the old way to add the oneDNN provider to the session, please use
  6780. * SessionOptionsAppendExecutionProvider_oneDNN above to access the latest functionality
  6781. * This function always exists, but will only succeed if Onnxruntime was built with
  6782. * oneDNN support and the oneDNN provider shared library exists
  6783. *
  6784. * \param use_arena zero: false. non-zero: true.
  6785. */
  6786. ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_Dnnl, _In_ OrtSessionOptions* options, int use_arena);
  6787. /*
  6788. * This is the old way to add the TensorRT provider to the session, please use SessionOptionsAppendExecutionProvider_TensorRT_V2 above to access the latest functionality
  6789. * This function always exists, but will only succeed if Onnxruntime was built with TensorRT support and the TensorRT provider shared library exists
  6790. *
  6791. * \param device_id CUDA device id, starts from zero.
  6792. */
  6793. ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_Tensorrt, _In_ OrtSessionOptions* options, int device_id);
  6794. #ifdef __cplusplus
  6795. }
  6796. #endif
  6797. /// @}
  6798. #include "onnxruntime_ep_c_api.h"