onnxruntime_c_api.h 208 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822
  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 18
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. //! @}
  42. // SAL2 Definitions
  43. #ifndef _WIN32
  44. #define _In_
  45. #define _In_z_
  46. #define _In_opt_
  47. #define _In_opt_z_
  48. #define _Out_
  49. #define _Outptr_
  50. #define _Out_opt_
  51. #define _Inout_
  52. #define _Inout_opt_
  53. #define _Frees_ptr_opt_
  54. #define _Ret_maybenull_
  55. #define _Ret_notnull_
  56. #define _Check_return_
  57. #define _Outptr_result_maybenull_
  58. #define _In_reads_(X)
  59. #define _Inout_updates_(X)
  60. #define _Out_writes_(X)
  61. #define _Inout_updates_all_(X)
  62. #define _Out_writes_bytes_all_(X)
  63. #define _Out_writes_all_(X)
  64. #define _Success_(X)
  65. #define _Outptr_result_buffer_maybenull_(X)
  66. #define ORT_ALL_ARGS_NONNULL __attribute__((nonnull))
  67. #else
  68. #include <specstrings.h>
  69. #define ORT_ALL_ARGS_NONNULL
  70. #endif
  71. #ifdef _WIN32
  72. // Define ORT_DLL_IMPORT if your program is dynamically linked to Ort.
  73. // dllexport is not used, we use a .def file.
  74. #ifdef ORT_DLL_IMPORT
  75. #define ORT_EXPORT __declspec(dllimport)
  76. #else
  77. #define ORT_EXPORT
  78. #endif
  79. #define ORT_API_CALL _stdcall
  80. #define ORT_MUST_USE_RESULT
  81. #define ORTCHAR_T wchar_t
  82. #else
  83. // To make symbols visible on macOS/iOS
  84. #ifdef __APPLE__
  85. #define ORT_EXPORT __attribute__((visibility("default")))
  86. #else
  87. #define ORT_EXPORT
  88. #endif
  89. #define ORT_API_CALL
  90. #define ORT_MUST_USE_RESULT __attribute__((warn_unused_result))
  91. #define ORTCHAR_T char
  92. #endif
  93. /// ORTCHAR_T, ORT_TSTR are reserved specifically for path handling.
  94. /// All other strings are UTF-8 encoded, use char and std::string
  95. #ifndef ORT_TSTR
  96. #ifdef _WIN32
  97. #define ORT_TSTR(X) L##X
  98. // When X is a macro, L##X is not defined. In this case, we need to use ORT_TSTR_ON_MACRO.
  99. #define ORT_TSTR_ON_MACRO(X) L"" X
  100. #else
  101. #define ORT_TSTR(X) X
  102. #define ORT_TSTR_ON_MACRO(X) X
  103. #endif
  104. #endif
  105. // On Windows, ORT_FILE is a wchar_t version of the __FILE__ macro.
  106. // Otherwise, ORT_FILE is equivalent to __FILE__.
  107. #ifndef ORT_FILE
  108. #define ORT_FILE_INTERNAL(x) ORT_TSTR(x)
  109. #define ORT_FILE ORT_FILE_INTERNAL(__FILE__)
  110. #endif
  111. // Any pointer marked with _In_ or _Out_, cannot be NULL.
  112. // Windows users should use unicode paths when possible to bypass the MAX_PATH limitation
  113. // Every pointer marked with _In_ or _Out_, cannot be NULL. Caller should ensure that.
  114. // for ReleaseXXX(...) functions, they can accept NULL pointer.
  115. #ifdef __cplusplus
  116. // For any compiler with C++11 support, MSVC 2015 and greater, or Clang version supporting noexcept.
  117. // Such complex condition is needed because compilers set __cplusplus value differently.
  118. #ifndef __has_feature
  119. #define __has_feature(x) 0
  120. #endif
  121. #if ((__cplusplus >= 201103L) || (_MSC_VER >= 1900) || (defined(__has_feature) && __has_feature(cxx_noexcept)))
  122. #define NO_EXCEPTION noexcept
  123. #else
  124. #define NO_EXCEPTION throw()
  125. #endif
  126. #else
  127. #define NO_EXCEPTION
  128. #endif
  129. // __VA_ARGS__ on Windows and Linux are different
  130. #define ORT_API(RETURN_TYPE, NAME, ...) RETURN_TYPE ORT_API_CALL NAME(__VA_ARGS__) NO_EXCEPTION
  131. #define ORT_API_STATUS(NAME, ...) \
  132. _Success_(return == 0) _Check_return_ _Ret_maybenull_ OrtStatusPtr ORT_API_CALL NAME(__VA_ARGS__) \
  133. NO_EXCEPTION ORT_MUST_USE_RESULT
  134. // XXX: Unfortunately, SAL annotations are known to not work with function pointers
  135. #define ORT_API2_STATUS(NAME, ...) \
  136. _Check_return_ _Ret_maybenull_ OrtStatusPtr(ORT_API_CALL* NAME)(__VA_ARGS__) NO_EXCEPTION ORT_MUST_USE_RESULT
  137. // Used in *.cc files. Almost as same as ORT_API_STATUS, except without ORT_MUST_USE_RESULT and ORT_EXPORT
  138. #define ORT_API_STATUS_IMPL(NAME, ...) \
  139. _Success_(return == 0) _Check_return_ _Ret_maybenull_ OrtStatusPtr ORT_API_CALL NAME(__VA_ARGS__) NO_EXCEPTION
  140. #define ORT_CLASS_RELEASE(X) void(ORT_API_CALL * Release##X)(_Frees_ptr_opt_ Ort##X * input)
  141. #ifdef __DOXYGEN__
  142. #undef ORT_API_STATUS
  143. #define ORT_API_STATUS(NAME, ...) OrtStatus* NAME(__VA_ARGS__)
  144. #undef ORT_API2_STATUS
  145. #define ORT_API2_STATUS(NAME, ...) OrtStatus* NAME(__VA_ARGS__)
  146. #undef ORT_CLASS_RELEASE
  147. #define ORT_CLASS_RELEASE(X) void Release##X(Ort##X* input)
  148. #undef NO_EXCEPTION
  149. #define NO_EXCEPTION
  150. #endif
  151. /** \addtogroup Global
  152. * ONNX Runtime C API
  153. * @{
  154. */
  155. /** Copied from TensorProto::DataType
  156. * Currently, Ort doesn't support complex64, complex128
  157. */
  158. typedef enum ONNXTensorElementDataType {
  159. ONNX_TENSOR_ELEMENT_DATA_TYPE_UNDEFINED,
  160. ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT, // maps to c type float
  161. ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8, // maps to c type uint8_t
  162. ONNX_TENSOR_ELEMENT_DATA_TYPE_INT8, // maps to c type int8_t
  163. ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT16, // maps to c type uint16_t
  164. ONNX_TENSOR_ELEMENT_DATA_TYPE_INT16, // maps to c type int16_t
  165. ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32, // maps to c type int32_t
  166. ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64, // maps to c type int64_t
  167. ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING, // maps to c++ type std::string
  168. ONNX_TENSOR_ELEMENT_DATA_TYPE_BOOL,
  169. ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16,
  170. ONNX_TENSOR_ELEMENT_DATA_TYPE_DOUBLE, // maps to c type double
  171. ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT32, // maps to c type uint32_t
  172. ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT64, // maps to c type uint64_t
  173. ONNX_TENSOR_ELEMENT_DATA_TYPE_COMPLEX64, // complex with float32 real and imaginary components
  174. ONNX_TENSOR_ELEMENT_DATA_TYPE_COMPLEX128, // complex with float64 real and imaginary components
  175. ONNX_TENSOR_ELEMENT_DATA_TYPE_BFLOAT16, // Non-IEEE floating-point format based on IEEE754 single-precision
  176. // float 8 types were introduced in onnx 1.14, see https://onnx.ai/onnx/technical/float8.html
  177. ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT8E4M3FN, // Non-IEEE floating-point format based on IEEE754 single-precision
  178. ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT8E4M3FNUZ, // Non-IEEE floating-point format based on IEEE754 single-precision
  179. ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT8E5M2, // Non-IEEE floating-point format based on IEEE754 single-precision
  180. ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT8E5M2FNUZ // Non-IEEE floating-point format based on IEEE754 single-precision
  181. } ONNXTensorElementDataType;
  182. // Synced with onnx TypeProto oneof
  183. typedef enum ONNXType {
  184. ONNX_TYPE_UNKNOWN,
  185. ONNX_TYPE_TENSOR,
  186. ONNX_TYPE_SEQUENCE,
  187. ONNX_TYPE_MAP,
  188. ONNX_TYPE_OPAQUE,
  189. ONNX_TYPE_SPARSETENSOR,
  190. ONNX_TYPE_OPTIONAL
  191. } ONNXType;
  192. // These types are synced with internal
  193. // SparseFormatFlags
  194. typedef enum OrtSparseFormat {
  195. ORT_SPARSE_UNDEFINED = 0,
  196. ORT_SPARSE_COO = 0x1,
  197. ORT_SPARSE_CSRC = 0x2,
  198. ORT_SPARSE_BLOCK_SPARSE = 0x4
  199. } OrtSparseFormat;
  200. // Enum allows to query sparse tensor indices
  201. enum OrtSparseIndicesFormat {
  202. ORT_SPARSE_COO_INDICES,
  203. ORT_SPARSE_CSR_INNER_INDICES,
  204. ORT_SPARSE_CSR_OUTER_INDICES,
  205. ORT_SPARSE_BLOCK_SPARSE_INDICES
  206. };
  207. /** \brief Logging severity levels
  208. *
  209. * In typical API usage, specifying a logging severity level specifies the minimum severity of log messages to show.
  210. */
  211. typedef enum OrtLoggingLevel {
  212. ORT_LOGGING_LEVEL_VERBOSE, ///< Verbose informational messages (least severe).
  213. ORT_LOGGING_LEVEL_INFO, ///< Informational messages.
  214. ORT_LOGGING_LEVEL_WARNING, ///< Warning messages.
  215. ORT_LOGGING_LEVEL_ERROR, ///< Error messages.
  216. ORT_LOGGING_LEVEL_FATAL, ///< Fatal error messages (most severe).
  217. } OrtLoggingLevel;
  218. typedef enum OrtErrorCode {
  219. ORT_OK,
  220. ORT_FAIL,
  221. ORT_INVALID_ARGUMENT,
  222. ORT_NO_SUCHFILE,
  223. ORT_NO_MODEL,
  224. ORT_ENGINE_ERROR,
  225. ORT_RUNTIME_EXCEPTION,
  226. ORT_INVALID_PROTOBUF,
  227. ORT_MODEL_LOADED,
  228. ORT_NOT_IMPLEMENTED,
  229. ORT_INVALID_GRAPH,
  230. ORT_EP_FAIL,
  231. } OrtErrorCode;
  232. typedef enum OrtOpAttrType {
  233. ORT_OP_ATTR_UNDEFINED = 0,
  234. ORT_OP_ATTR_INT,
  235. ORT_OP_ATTR_INTS,
  236. ORT_OP_ATTR_FLOAT,
  237. ORT_OP_ATTR_FLOATS,
  238. ORT_OP_ATTR_STRING,
  239. ORT_OP_ATTR_STRINGS,
  240. } OrtOpAttrType;
  241. //! @}
  242. #define ORT_RUNTIME_CLASS(X) \
  243. struct Ort##X; \
  244. typedef struct Ort##X Ort##X
  245. /** \addtogroup Global
  246. * ONNX Runtime C API
  247. * @{
  248. */
  249. // The actual types defined have an Ort prefix
  250. ORT_RUNTIME_CLASS(Env);
  251. ORT_RUNTIME_CLASS(Status); // nullptr for Status* indicates success
  252. ORT_RUNTIME_CLASS(MemoryInfo);
  253. ORT_RUNTIME_CLASS(IoBinding);
  254. ORT_RUNTIME_CLASS(Session); // Don't call ReleaseSession from Dllmain (because session owns a thread pool)
  255. ORT_RUNTIME_CLASS(Value);
  256. ORT_RUNTIME_CLASS(RunOptions);
  257. ORT_RUNTIME_CLASS(TypeInfo);
  258. ORT_RUNTIME_CLASS(TensorTypeAndShapeInfo);
  259. ORT_RUNTIME_CLASS(MapTypeInfo);
  260. ORT_RUNTIME_CLASS(SequenceTypeInfo);
  261. ORT_RUNTIME_CLASS(OptionalTypeInfo);
  262. ORT_RUNTIME_CLASS(SessionOptions);
  263. ORT_RUNTIME_CLASS(CustomOpDomain);
  264. ORT_RUNTIME_CLASS(ModelMetadata);
  265. ORT_RUNTIME_CLASS(ThreadPoolParams);
  266. ORT_RUNTIME_CLASS(ThreadingOptions);
  267. ORT_RUNTIME_CLASS(ArenaCfg);
  268. ORT_RUNTIME_CLASS(PrepackedWeightsContainer);
  269. ORT_RUNTIME_CLASS(TensorRTProviderOptionsV2);
  270. ORT_RUNTIME_CLASS(CUDAProviderOptionsV2);
  271. ORT_RUNTIME_CLASS(CANNProviderOptions);
  272. ORT_RUNTIME_CLASS(DnnlProviderOptions);
  273. ORT_RUNTIME_CLASS(Op);
  274. ORT_RUNTIME_CLASS(OpAttr);
  275. ORT_RUNTIME_CLASS(Logger);
  276. ORT_RUNTIME_CLASS(ShapeInferContext);
  277. #ifdef _WIN32
  278. typedef _Return_type_success_(return == 0) OrtStatus* OrtStatusPtr;
  279. #else
  280. typedef OrtStatus* OrtStatusPtr;
  281. #endif
  282. /** \brief Memory allocation interface
  283. *
  284. * Structure of function pointers that defines a memory allocator. This can be created and filled in by the user for custom allocators.
  285. *
  286. * 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.
  287. */
  288. typedef struct OrtAllocator {
  289. uint32_t version; ///< Must be initialized to ORT_API_VERSION
  290. void*(ORT_API_CALL* Alloc)(struct OrtAllocator* this_, size_t size); ///< Returns a pointer to an allocated block of `size` bytes
  291. void(ORT_API_CALL* Free)(struct OrtAllocator* this_, void* p); ///< Free a block of memory previously allocated with OrtAllocator::Alloc
  292. const struct OrtMemoryInfo*(ORT_API_CALL* Info)(const struct OrtAllocator* this_); ///< Return a pointer to an ::OrtMemoryInfo that describes this allocator
  293. /**
  294. * @brief Optional allocation function to use for memory allocations made during session initialization.
  295. * Use this function if you want to separate allocations made by ORT during Run() calls from
  296. * those made during session initialization. This allows for separate memory management strategies for these allocations.
  297. */
  298. void*(ORT_API_CALL* Reserve)(struct OrtAllocator* this_, size_t size); ///< Returns a pointer to an allocated block of `size` bytes
  299. } OrtAllocator;
  300. typedef void(ORT_API_CALL* OrtLoggingFunction)(
  301. void* param, OrtLoggingLevel severity, const char* category, const char* logid, const char* code_location,
  302. const char* message);
  303. /** \brief Graph optimization level
  304. *
  305. * Refer to https://www.onnxruntime.ai/docs/performance/graph-optimizations.html#graph-optimization-levels
  306. * for an in-depth understanding of the Graph Optimization Levels.
  307. */
  308. typedef enum GraphOptimizationLevel {
  309. ORT_DISABLE_ALL = 0,
  310. ORT_ENABLE_BASIC = 1,
  311. ORT_ENABLE_EXTENDED = 2,
  312. ORT_ENABLE_ALL = 99
  313. } GraphOptimizationLevel;
  314. typedef enum ExecutionMode {
  315. ORT_SEQUENTIAL = 0,
  316. ORT_PARALLEL = 1,
  317. } ExecutionMode;
  318. /** \brief Language projection identifiers
  319. * /see OrtApi::SetLanguageProjection
  320. */
  321. typedef enum OrtLanguageProjection {
  322. ORT_PROJECTION_C = 0,
  323. ORT_PROJECTION_CPLUSPLUS = 1,
  324. ORT_PROJECTION_CSHARP = 2,
  325. ORT_PROJECTION_PYTHON = 3,
  326. ORT_PROJECTION_JAVA = 4,
  327. ORT_PROJECTION_WINML = 5,
  328. ORT_PROJECTION_NODEJS = 6,
  329. } OrtLanguageProjection;
  330. struct OrtKernelInfo;
  331. typedef struct OrtKernelInfo OrtKernelInfo;
  332. struct OrtKernelContext;
  333. typedef struct OrtKernelContext OrtKernelContext;
  334. struct OrtCustomOp;
  335. typedef struct OrtCustomOp OrtCustomOp;
  336. typedef enum OrtAllocatorType {
  337. OrtInvalidAllocator = -1,
  338. OrtDeviceAllocator = 0,
  339. OrtArenaAllocator = 1
  340. } OrtAllocatorType;
  341. /** \brief Memory types for allocated memory, execution provider specific types should be extended in each provider.
  342. */
  343. // Whenever this struct is updated, please also update the MakeKey function in onnxruntime / core / framework / execution_provider.cc
  344. typedef enum OrtMemType {
  345. OrtMemTypeCPUInput = -2, ///< Any CPU memory used by non-CPU execution provider
  346. OrtMemTypeCPUOutput = -1, ///< CPU accessible memory outputted by non-CPU execution provider, i.e. CUDA_PINNED
  347. OrtMemTypeCPU = OrtMemTypeCPUOutput, ///< Temporary CPU accessible memory allocated by non-CPU execution provider, i.e. CUDA_PINNED
  348. OrtMemTypeDefault = 0, ///< The default allocator for execution provider
  349. } OrtMemType;
  350. /** \brief This mimics OrtDevice type constants so they can be returned in the API
  351. */
  352. typedef enum OrtMemoryInfoDeviceType {
  353. OrtMemoryInfoDeviceType_CPU = 0,
  354. OrtMemoryInfoDeviceType_GPU = 1,
  355. OrtMemoryInfoDeviceType_FPGA = 2
  356. } OrtMemoryInfoDeviceType;
  357. /** \brief Algorithm to use for cuDNN Convolution Op
  358. */
  359. typedef enum OrtCudnnConvAlgoSearch {
  360. OrtCudnnConvAlgoSearchExhaustive, // expensive exhaustive benchmarking using cudnnFindConvolutionForwardAlgorithmEx
  361. OrtCudnnConvAlgoSearchHeuristic, // lightweight heuristic based search using cudnnGetConvolutionForwardAlgorithm_v7
  362. OrtCudnnConvAlgoSearchDefault, // default algorithm using CUDNN_CONVOLUTION_FWD_ALGO_IMPLICIT_PRECOMP_GEMM
  363. } OrtCudnnConvAlgoSearch;
  364. /** \brief CUDA Provider Options
  365. *
  366. * \see OrtApi::SessionOptionsAppendExecutionProvider_CUDA
  367. */
  368. typedef struct OrtCUDAProviderOptions {
  369. #ifdef __cplusplus
  370. OrtCUDAProviderOptions()
  371. : device_id{},
  372. cudnn_conv_algo_search{OrtCudnnConvAlgoSearchExhaustive},
  373. gpu_mem_limit{SIZE_MAX},
  374. arena_extend_strategy{},
  375. do_copy_in_default_stream{1},
  376. has_user_compute_stream{},
  377. user_compute_stream{},
  378. default_memory_arena_cfg{},
  379. tunable_op_enable{false},
  380. tunable_op_tuning_enable{false},
  381. tunable_op_max_tuning_duration_ms{} {}
  382. #endif
  383. /** \brief CUDA device Id
  384. * Defaults to 0.
  385. */
  386. int device_id;
  387. /** \brief CUDA Convolution algorithm search configuration.
  388. * See enum OrtCudnnConvAlgoSearch for more details.
  389. * Defaults to OrtCudnnConvAlgoSearchExhaustive.
  390. */
  391. OrtCudnnConvAlgoSearch cudnn_conv_algo_search;
  392. /** \brief CUDA memory limit (To use all possible memory pass in maximum size_t)
  393. * Defaults to SIZE_MAX.
  394. * \note If a ::OrtArenaCfg has been applied, it will override this field
  395. */
  396. size_t gpu_mem_limit;
  397. /** \brief Strategy used to grow the memory arena
  398. * 0 = kNextPowerOfTwo<br>
  399. * 1 = kSameAsRequested<br>
  400. * Defaults to 0.
  401. * \note If a ::OrtArenaCfg has been applied, it will override this field
  402. */
  403. int arena_extend_strategy;
  404. /** \brief Flag indicating if copying needs to take place on the same stream as the compute stream in the CUDA EP
  405. * 0 = Use separate streams for copying and compute.
  406. * 1 = Use the same stream for copying and compute.
  407. * Defaults to 1.
  408. * WARNING: Setting this to 0 may result in data races for some models.
  409. * Please see issue #4829 for more details.
  410. */
  411. int do_copy_in_default_stream;
  412. /** \brief Flag indicating if there is a user provided compute stream
  413. * Defaults to 0.
  414. */
  415. int has_user_compute_stream;
  416. /** \brief User provided compute stream.
  417. * If provided, please set `has_user_compute_stream` to 1.
  418. */
  419. void* user_compute_stream;
  420. /** \brief CUDA memory arena configuration parameters
  421. */
  422. OrtArenaCfg* default_memory_arena_cfg;
  423. /** \brief Enable TunableOp for using.
  424. * Set it to 1/0 to enable/disable TunableOp. Otherwise, it is disabled by default.
  425. * This option can be overriden by environment variable ORT_CUDA_TUNABLE_OP_ENABLE.
  426. */
  427. int tunable_op_enable;
  428. /** \brief Enable TunableOp for tuning.
  429. * Set it to 1/0 to enable/disable TunableOp tuning. Otherwise, it is disabled by default.
  430. * This option can be overriden by environment variable ORT_CUDA_TUNABLE_OP_TUNING_ENABLE.
  431. */
  432. int tunable_op_tuning_enable;
  433. /** \brief Max tuning duration time limit for each instance of TunableOp.
  434. * Defaults to 0 to disable the limit.
  435. */
  436. int tunable_op_max_tuning_duration_ms;
  437. } OrtCUDAProviderOptions;
  438. /** \brief ROCM Provider Options
  439. *
  440. * \see OrtApi::SessionOptionsAppendExecutionProvider_ROCM
  441. */
  442. typedef struct OrtROCMProviderOptions {
  443. #ifdef __cplusplus
  444. OrtROCMProviderOptions()
  445. : device_id{},
  446. miopen_conv_exhaustive_search{0},
  447. gpu_mem_limit{SIZE_MAX},
  448. arena_extend_strategy{},
  449. do_copy_in_default_stream{1},
  450. has_user_compute_stream{},
  451. user_compute_stream{},
  452. default_memory_arena_cfg{},
  453. enable_hip_graph{false},
  454. tunable_op_enable{false},
  455. tunable_op_tuning_enable{false},
  456. tunable_op_max_tuning_duration_ms{} {}
  457. #endif
  458. /** \brief ROCM device Id
  459. * Defaults to 0.
  460. */
  461. int device_id;
  462. /** \brief ROCM MIOpen Convolution algorithm exaustive search option.
  463. * Defaults to 0 (false).
  464. */
  465. int miopen_conv_exhaustive_search;
  466. /** \brief ROCM memory limit (To use all possible memory pass in maximum size_t)
  467. * Defaults to SIZE_MAX.
  468. * \note If a ::OrtArenaCfg has been applied, it will override this field
  469. */
  470. size_t gpu_mem_limit;
  471. /** \brief Strategy used to grow the memory arena
  472. * 0 = kNextPowerOfTwo<br>
  473. * 1 = kSameAsRequested<br>
  474. * Defaults to 0.
  475. * \note If a ::OrtArenaCfg has been applied, it will override this field
  476. */
  477. int arena_extend_strategy;
  478. /** \brief Flag indicating if copying needs to take place on the same stream as the compute stream in the ROCM EP
  479. * 0 = Use separate streams for copying and compute.
  480. * 1 = Use the same stream for copying and compute.
  481. * Defaults to 1.
  482. * WARNING: Setting this to 0 may result in data races for some models.
  483. * Please see issue #4829 for more details.
  484. */
  485. int do_copy_in_default_stream;
  486. /** \brief Flag indicating if there is a user provided compute stream
  487. * Defaults to 0.
  488. */
  489. int has_user_compute_stream;
  490. /** \brief User provided compute stream.
  491. * If provided, please set `has_user_compute_stream` to 1.
  492. */
  493. void* user_compute_stream;
  494. /** \brief ROCM memory arena configuration parameters
  495. */
  496. OrtArenaCfg* default_memory_arena_cfg;
  497. int enable_hip_graph;
  498. /** \brief Enable TunableOp for using.
  499. * Set it to 1/0 to enable/disable TunableOp. Otherwise, it is disabled by default.
  500. * This option can be overriden by environment variable ORT_ROCM_TUNABLE_OP_ENABLE.
  501. */
  502. int tunable_op_enable;
  503. /** \brief Enable TunableOp for tuning.
  504. * Set it to 1/0 to enable/disable TunableOp tuning. Otherwise, it is disabled by default.
  505. * This option can be overriden by environment variable ORT_ROCM_TUNABLE_OP_TUNING_ENABLE.
  506. */
  507. int tunable_op_tuning_enable;
  508. /** \brief Max tuning duration time limit for each instance of TunableOp.
  509. * Defaults to 0 to disable the limit.
  510. */
  511. int tunable_op_max_tuning_duration_ms;
  512. } OrtROCMProviderOptions;
  513. /** \brief TensorRT Provider Options
  514. *
  515. * \see OrtApi::SessionOptionsAppendExecutionProvider_TensorRT
  516. */
  517. typedef struct OrtTensorRTProviderOptions {
  518. int device_id; ///< CUDA device id (0 = default device)
  519. int has_user_compute_stream; // indicator of user specified CUDA compute stream.
  520. void* user_compute_stream; // user specified CUDA compute stream.
  521. int trt_max_partition_iterations; // maximum iterations for TensorRT parser to get capability
  522. int trt_min_subgraph_size; // minimum size of TensorRT subgraphs
  523. size_t trt_max_workspace_size; // maximum workspace size for TensorRT.
  524. int trt_fp16_enable; // enable TensorRT FP16 precision. Default 0 = false, nonzero = true
  525. int trt_int8_enable; // enable TensorRT INT8 precision. Default 0 = false, nonzero = true
  526. const char* trt_int8_calibration_table_name; // TensorRT INT8 calibration table name.
  527. int trt_int8_use_native_calibration_table; // use native TensorRT generated calibration table. Default 0 = false, nonzero = true
  528. int trt_dla_enable; // enable DLA. Default 0 = false, nonzero = true
  529. int trt_dla_core; // DLA core number. Default 0
  530. int trt_dump_subgraphs; // dump TRT subgraph. Default 0 = false, nonzero = true
  531. int trt_engine_cache_enable; // enable engine caching. Default 0 = false, nonzero = true
  532. const char* trt_engine_cache_path; // specify engine cache path
  533. int trt_engine_decryption_enable; // enable engine decryption. Default 0 = false, nonzero = true
  534. const char* trt_engine_decryption_lib_path; // specify engine decryption library path
  535. int trt_force_sequential_engine_build; // force building TensorRT engine sequentially. Default 0 = false, nonzero = true
  536. // This is the legacy struct and don't add new fields here.
  537. // For new field that can be represented by string, please add it in include/onnxruntime/core/providers/tensorrt/tensorrt_provider_options.h
  538. // For non-string field, need to create a new separate api to handle it.
  539. } OrtTensorRTProviderOptions;
  540. /** \brief MIGraphX Provider Options
  541. *
  542. * \see OrtApi::SessionOptionsAppendExecutionProvider_MIGraphX
  543. */
  544. typedef struct OrtMIGraphXProviderOptions {
  545. int device_id; // hip device id.
  546. int migraphx_fp16_enable; // MIGraphX FP16 precision. Default 0 = false, nonzero = true
  547. int migraphx_int8_enable; // MIGraphX INT8 precision. Default 0 = false, nonzero = true
  548. int migraphx_use_native_calibration_table; // MIGraphx INT8 cal table. Default 0 = false, noznero = true
  549. const char* migraphx_int8_calibration_table_name; // MIGraphx INT8 calibration table name
  550. } OrtMIGraphXProviderOptions;
  551. /** \brief OpenVINO Provider Options
  552. *
  553. * \see OrtApi::SessionOptionsAppendExecutionProvider_OpenVINO
  554. */
  555. typedef struct OrtOpenVINOProviderOptions {
  556. #ifdef __cplusplus
  557. OrtOpenVINOProviderOptions() : device_type{},
  558. enable_npu_fast_compile{},
  559. device_id{},
  560. num_of_threads{},
  561. cache_dir{},
  562. context{},
  563. enable_opencl_throttling{},
  564. enable_dynamic_shapes{} {}
  565. #endif
  566. /** \brief Device type string
  567. *
  568. * Valid settings are one of: "CPU_FP32", "CPU_FP16", "GPU_FP32", "GPU_FP16"
  569. */
  570. const char* device_type;
  571. unsigned char enable_npu_fast_compile; ///< 0 = disabled, nonzero = enabled
  572. const char* device_id;
  573. size_t num_of_threads; ///< 0 = Use default number of threads
  574. const char* cache_dir; // path is set to empty by default
  575. void* context;
  576. unsigned char enable_opencl_throttling; ///< 0 = disabled, nonzero = enabled
  577. unsigned char enable_dynamic_shapes; ///< 0 = disabled, nonzero = enabled
  578. } OrtOpenVINOProviderOptions;
  579. struct OrtApi;
  580. typedef struct OrtApi OrtApi;
  581. struct OrtTrainingApi;
  582. typedef struct OrtTrainingApi OrtTrainingApi;
  583. /** \brief The helper interface to get the right version of OrtApi
  584. *
  585. * Get a pointer to this structure through ::OrtGetApiBase
  586. */
  587. struct OrtApiBase {
  588. /** \brief Get a pointer to the requested version of the ::OrtApi
  589. *
  590. * \param[in] version Must be ::ORT_API_VERSION
  591. * \return The ::OrtApi for the version requested, nullptr will be returned if this version is unsupported, for example when using a runtime
  592. * older than the version created with this header file.
  593. *
  594. * One can call GetVersionString() to get the version of the Onnxruntime library for logging
  595. * and error reporting purposes.
  596. */
  597. const OrtApi*(ORT_API_CALL* GetApi)(uint32_t version)NO_EXCEPTION;
  598. /** \brief Returns a null terminated string of the version of the Onnxruntime library (eg: "1.8.1")
  599. *
  600. * \return UTF-8 encoded version string. Do not deallocate the returned buffer.
  601. */
  602. const char*(ORT_API_CALL* GetVersionString)(void)NO_EXCEPTION;
  603. };
  604. typedef struct OrtApiBase OrtApiBase;
  605. /** \brief The Onnxruntime library's entry point to access the C API
  606. *
  607. * Call this to get the a pointer to an ::OrtApiBase
  608. */
  609. ORT_EXPORT const OrtApiBase* ORT_API_CALL OrtGetApiBase(void) NO_EXCEPTION;
  610. /** \brief Thread work loop function
  611. *
  612. * Onnxruntime will provide the working loop on custom thread creation
  613. * Argument is an onnxruntime built-in type which will be provided when thread pool calls OrtCustomCreateThreadFn
  614. */
  615. typedef void (*OrtThreadWorkerFn)(void* ort_worker_fn_param);
  616. typedef const struct OrtCustomHandleType {
  617. char __place_holder;
  618. }* OrtCustomThreadHandle;
  619. /** \brief Ort custom thread creation function
  620. *
  621. * The function should return a thread handle to be used in onnxruntime thread pools
  622. * Onnxruntime will throw exception on return value of nullptr or 0, indicating that the function failed to create a thread
  623. */
  624. typedef OrtCustomThreadHandle (*OrtCustomCreateThreadFn)(void* ort_custom_thread_creation_options, OrtThreadWorkerFn ort_thread_worker_fn, void* ort_worker_fn_param);
  625. /** \brief Custom thread join function
  626. *
  627. * Onnxruntime thread pool destructor will call the function to join a custom thread.
  628. * Argument ort_custom_thread_handle is the value returned by OrtCustomCreateThreadFn
  629. */
  630. typedef void (*OrtCustomJoinThreadFn)(OrtCustomThreadHandle ort_custom_thread_handle);
  631. typedef OrtStatus*(ORT_API_CALL* RegisterCustomOpsFn)(OrtSessionOptions* options, const OrtApiBase* api);
  632. /** \brief Callback function for RunAsync
  633. *
  634. * \param[in] user_data User specific data that passed back to the callback
  635. * \param[out] outputs On succeed, outputs host inference results, on error, the value will be nullptr
  636. * \param[out] num_outputs Number of outputs, on error, the value will be zero
  637. * \param[out] status On error, status will provide details
  638. */
  639. typedef void (*RunAsyncCallbackFn)(void* user_data, OrtValue** outputs, size_t num_outputs, OrtStatusPtr status);
  640. /** \brief The C API
  641. *
  642. * All C API functions are defined inside this structure as pointers to functions.
  643. * Call OrtApiBase::GetApi to get a pointer to it
  644. *
  645. * \nosubgrouping
  646. */
  647. struct OrtApi {
  648. /// \name OrtStatus
  649. /// @{
  650. /**
  651. * \brief Create an OrtStatus from a null terminated string
  652. *
  653. * \param[in] code
  654. * \param[in] msg A null-terminated string. Its contents will be copied.
  655. * \return A new OrtStatus object, must be destroyed with OrtApi::ReleaseStatus
  656. */
  657. OrtStatus*(ORT_API_CALL* CreateStatus)(OrtErrorCode code, _In_ const char* msg)NO_EXCEPTION ORT_ALL_ARGS_NONNULL;
  658. /** \brief Get OrtErrorCode from OrtStatus
  659. *
  660. * \param[in] status
  661. * \return OrtErrorCode that \p status was created with
  662. */
  663. OrtErrorCode(ORT_API_CALL* GetErrorCode)(_In_ const OrtStatus* status) NO_EXCEPTION ORT_ALL_ARGS_NONNULL;
  664. /** \brief Get error string from OrtStatus
  665. *
  666. * \param[in] status
  667. * \return The error message inside the `status`. Do not free the returned value.
  668. */
  669. const char*(ORT_API_CALL* GetErrorMessage)(_In_ const OrtStatus* status)NO_EXCEPTION ORT_ALL_ARGS_NONNULL;
  670. /// @}
  671. /// \name OrtEnv
  672. /// @{
  673. /** \brief Create an OrtEnv
  674. *
  675. * \note Invoking this function will return the same instance of the environment as that returned by a previous call
  676. * to another env creation function; all arguments to this function will be ignored.
  677. * \param[in] log_severity_level The log severity level.
  678. * \param[in] logid The log identifier.
  679. * \param[out] out Returned newly created OrtEnv. Must be freed with OrtApi::ReleaseEnv
  680. *
  681. * \snippet{doc} snippets.dox OrtStatus Return Value
  682. */
  683. ORT_API2_STATUS(CreateEnv, OrtLoggingLevel log_severity_level, _In_ const char* logid, _Outptr_ OrtEnv** out);
  684. /** \brief Create an OrtEnv
  685. *
  686. * \note Invoking this function will return the same instance of the environment as that returned by a previous call
  687. * to another env creation function; all arguments to this function will be ignored. If you want to provide your
  688. * own logging function, consider setting it using the SetUserLoggingFunction API instead.
  689. * \param[in] logging_function A pointer to a logging function.
  690. * \param[in] logger_param A pointer to arbitrary data passed as the ::OrtLoggingFunction `param` parameter to
  691. * `logging_function`. This parameter is optional.
  692. * \param[in] log_severity_level The log severity level.
  693. * \param[in] logid The log identifier.
  694. * \param[out] out Returned newly created OrtEnv. Must be freed with OrtApi::ReleaseEnv
  695. *
  696. * \snippet{doc} snippets.dox OrtStatus Return Value
  697. */
  698. ORT_API2_STATUS(CreateEnvWithCustomLogger, _In_ OrtLoggingFunction logging_function, _In_opt_ void* logger_param,
  699. _In_ OrtLoggingLevel log_severity_level, _In_ const char* logid, _Outptr_ OrtEnv** out);
  700. /** \brief Enable Telemetry
  701. *
  702. * \note Telemetry events are on by default since they are lightweight
  703. * \param[in] env
  704. *
  705. * \snippet{doc} snippets.dox OrtStatus Return Value
  706. */
  707. ORT_API2_STATUS(EnableTelemetryEvents, _In_ const OrtEnv* env);
  708. /** \brief Disable Telemetry
  709. *
  710. * \see OrtApi::EnableTelemetryEvents
  711. * \param[in] env
  712. *
  713. * \snippet{doc} snippets.dox OrtStatus Return Value
  714. */
  715. ORT_API2_STATUS(DisableTelemetryEvents, _In_ const OrtEnv* env);
  716. /// @}
  717. /// \name OrtSession
  718. /// @{
  719. /** \brief Create an OrtSession from a model file
  720. *
  721. * \param[in] env
  722. * \param[in] model_path
  723. * \param[in] options
  724. * \param[out] out Returned newly created OrtSession. Must be freed with OrtApi::ReleaseSession
  725. *
  726. * \snippet{doc} snippets.dox OrtStatus Return Value
  727. */
  728. // TODO: document the path separator convention? '/' vs '\'
  729. // TODO: should specify the access characteristics of model_path. Is this read only during the
  730. // execution of CreateSession, or does the OrtSession retain a handle to the file/directory
  731. // and continue to access throughout the OrtSession lifetime?
  732. // What sort of access is needed to model_path : read or read/write?
  733. ORT_API2_STATUS(CreateSession, _In_ const OrtEnv* env, _In_ const ORTCHAR_T* model_path,
  734. _In_ const OrtSessionOptions* options, _Outptr_ OrtSession** out);
  735. /** \brief Create an OrtSession from memory
  736. *
  737. * \param[in] env
  738. * \param[in] model_data
  739. * \param[in] model_data_length
  740. * \param[in] options
  741. * \param[out] out Returned newly created OrtSession. Must be freed with OrtApi::ReleaseSession
  742. *
  743. * \snippet{doc} snippets.dox OrtStatus Return Value
  744. */
  745. ORT_API2_STATUS(CreateSessionFromArray, _In_ const OrtEnv* env, _In_ const void* model_data, size_t model_data_length,
  746. _In_ const OrtSessionOptions* options, _Outptr_ OrtSession** out);
  747. /** \brief Run the model in an ::OrtSession
  748. *
  749. * Will not return until the model run has completed. Multiple threads might be used to run the model based on
  750. * the options in the ::OrtSession and settings used when creating the ::OrtEnv
  751. *
  752. * \param[in] session
  753. * \param[in] run_options If nullptr, will use a default ::OrtRunOptions
  754. * \param[in] input_names Array of null terminated UTF8 encoded strings of the input names
  755. * \param[in] inputs Array of ::OrtValue%s of the input values
  756. * \param[in] input_len Number of elements in the input_names and inputs arrays
  757. * \param[in] output_names Array of null terminated UTF8 encoded strings of the output names
  758. * \param[in] output_names_len Number of elements in the output_names and outputs array
  759. * \param[out] outputs Array of ::OrtValue%s that the outputs are stored in. This can also be
  760. * an array of nullptr values, in this case ::OrtValue objects will be allocated and pointers
  761. * to them will be set into the `outputs` array.
  762. *
  763. * \snippet{doc} snippets.dox OrtStatus Return Value
  764. */
  765. ORT_API2_STATUS(Run, _Inout_ OrtSession* session, _In_opt_ const OrtRunOptions* run_options,
  766. _In_reads_(input_len) const char* const* input_names,
  767. _In_reads_(input_len) const OrtValue* const* inputs, size_t input_len,
  768. _In_reads_(output_names_len) const char* const* output_names, size_t output_names_len,
  769. _Inout_updates_all_(output_names_len) OrtValue** outputs);
  770. /// @}
  771. /// \name OrtSessionOptions
  772. /// @{
  773. /** \brief Create an ::OrtSessionOptions object
  774. *
  775. * To use additional providers, you must build ORT with the extra providers enabled. Then call one of these
  776. * functions to enable them in the session:<br>
  777. * OrtSessionOptionsAppendExecutionProvider_CPU<br>
  778. * OrtSessionOptionsAppendExecutionProvider_CUDA<br>
  779. * OrtSessionOptionsAppendExecutionProvider_(remaining providers...)<br>
  780. * The order they are called indicates the preference order as well. In other words call this method
  781. * on your most preferred execution provider first followed by the less preferred ones.
  782. * If none are called Ort will use its internal CPU execution provider.
  783. *
  784. * \param[out] options The newly created OrtSessionOptions. Must be freed with OrtApi::ReleaseSessionOptions
  785. *
  786. * \snippet{doc} snippets.dox OrtStatus Return Value
  787. */
  788. ORT_API2_STATUS(CreateSessionOptions, _Outptr_ OrtSessionOptions** options);
  789. /** \brief Set filepath to save optimized model after graph level transformations
  790. *
  791. * \param[in] options
  792. * \param[in] optimized_model_filepath
  793. *
  794. * \snippet{doc} snippets.dox OrtStatus Return Value
  795. */
  796. ORT_API2_STATUS(SetOptimizedModelFilePath, _Inout_ OrtSessionOptions* options,
  797. _In_ const ORTCHAR_T* optimized_model_filepath);
  798. /** \brief Create a copy of an existing ::OrtSessionOptions
  799. *
  800. * \param[in] in_options OrtSessionOptions to copy
  801. * \param[out] out_options Returned newly created ::OrtSessionOptions. Must be freed with OrtApi::ReleaseSessionOptions
  802. *
  803. * \snippet{doc} snippets.dox OrtStatus Return Value
  804. */
  805. ORT_API2_STATUS(CloneSessionOptions, _In_ const OrtSessionOptions* in_options,
  806. _Outptr_ OrtSessionOptions** out_options);
  807. /** \brief Set execution mode
  808. *
  809. * Controls whether you want to execute operators in your graph sequentially or in parallel. Usually when the model
  810. * has many branches, setting this option to ExecutionMode.ORT_PARALLEL will give you better performance.
  811. * See [docs/ONNX_Runtime_Perf_Tuning.md] for more details.
  812. *
  813. * \param[in] options
  814. * \param[in] execution_mode
  815. *
  816. * \snippet{doc} snippets.dox OrtStatus Return Value
  817. */
  818. ORT_API2_STATUS(SetSessionExecutionMode, _Inout_ OrtSessionOptions* options, ExecutionMode execution_mode);
  819. /** \brief Enable profiling for a session
  820. *
  821. * \param[in] options
  822. * \param[in] profile_file_prefix
  823. *
  824. * \snippet{doc} snippets.dox OrtStatus Return Value
  825. */
  826. ORT_API2_STATUS(EnableProfiling, _Inout_ OrtSessionOptions* options, _In_ const ORTCHAR_T* profile_file_prefix);
  827. /** \brief Disable profiling for a session
  828. *
  829. * \param[in] options
  830. *
  831. * \snippet{doc} snippets.dox OrtStatus Return Value
  832. */
  833. ORT_API2_STATUS(DisableProfiling, _Inout_ OrtSessionOptions* options);
  834. /** \brief Enable the memory pattern optimization
  835. *
  836. * The idea is if the input shapes are the same, we could trace the internal memory allocation
  837. * and generate a memory pattern for future request. So next time we could just do one allocation
  838. * with a big chunk for all the internal memory allocation.
  839. * \note Memory pattern optimization is only available when Sequential Execution mode is enabled (see OrtApi::SetSessionExecutionMode)
  840. *
  841. * \see OrtApi::DisableMemPattern
  842. *
  843. * \param[in] options
  844. *
  845. * \snippet{doc} snippets.dox OrtStatus Return Value
  846. */
  847. ORT_API2_STATUS(EnableMemPattern, _Inout_ OrtSessionOptions* options);
  848. /** \brief Disable the memory pattern optimization
  849. *
  850. * \see OrtApi::EnableMemPattern
  851. *
  852. * \param[in] options
  853. *
  854. * \snippet{doc} snippets.dox OrtStatus Return Value
  855. */
  856. ORT_API2_STATUS(DisableMemPattern, _Inout_ OrtSessionOptions* options);
  857. /** \brief Enable the memory arena on CPU
  858. *
  859. * Arena may pre-allocate memory for future usage.
  860. *
  861. * \param[in] options
  862. *
  863. * \snippet{doc} snippets.dox OrtStatus Return Value
  864. */
  865. ORT_API2_STATUS(EnableCpuMemArena, _Inout_ OrtSessionOptions* options);
  866. /** \brief Disable the memory arena on CPU
  867. *
  868. * \param[in] options
  869. *
  870. * \snippet{doc} snippets.dox OrtStatus Return Value
  871. */
  872. ORT_API2_STATUS(DisableCpuMemArena, _Inout_ OrtSessionOptions* options);
  873. /** \brief Set session log id
  874. *
  875. * \param[in] options
  876. * \param[in] logid The log identifier.
  877. *
  878. * \snippet{doc} snippets.dox OrtStatus Return Value
  879. */
  880. ORT_API2_STATUS(SetSessionLogId, _Inout_ OrtSessionOptions* options, const char* logid);
  881. /** \brief Set session log verbosity level
  882. *
  883. * Applies to session load, initialization, etc
  884. *
  885. * \param[in] options
  886. * \param[in] session_log_verbosity_level \snippet{doc} snippets.dox Log Verbosity Level
  887. *
  888. * \snippet{doc} snippets.dox OrtStatus Return Value
  889. */
  890. ORT_API2_STATUS(SetSessionLogVerbosityLevel, _Inout_ OrtSessionOptions* options, int session_log_verbosity_level);
  891. /** \brief Set session log severity level
  892. *
  893. * \param[in] options
  894. * \param[in] session_log_severity_level The log severity level (refer to ::OrtLoggingLevel for possible values).
  895. *
  896. * \snippet{doc} snippets.dox OrtStatus Return Value
  897. */
  898. ORT_API2_STATUS(SetSessionLogSeverityLevel, _Inout_ OrtSessionOptions* options, int session_log_severity_level);
  899. /** \brief Set the optimization level to apply when loading a graph
  900. *
  901. * Please see https://onnxruntime.ai/docs/performance/model-optimizations/graph-optimizations.html for an in-depth explanation
  902. * \param[in,out] options The session options object
  903. * \param[in] graph_optimization_level The optimization level
  904. *
  905. * \snippet{doc} snippets.dox OrtStatus Return Value
  906. */
  907. ORT_API2_STATUS(SetSessionGraphOptimizationLevel, _Inout_ OrtSessionOptions* options,
  908. GraphOptimizationLevel graph_optimization_level);
  909. /** \brief Sets the number of threads used to parallelize the execution within nodes
  910. *
  911. * When running a single node operation, ex. add, this sets the maximum number of threads to use.
  912. *
  913. * \note If built with OpenMP, this has no effect on the number of threads used. In this case
  914. * use the OpenMP env variables to configure the number of intra op num threads.
  915. *
  916. * \param[in] options
  917. * \param[in] intra_op_num_threads Number of threads to use<br>
  918. * A value of 0 will use the default number of threads<br>
  919. *
  920. * \snippet{doc} snippets.dox OrtStatus Return Value
  921. */
  922. ORT_API2_STATUS(SetIntraOpNumThreads, _Inout_ OrtSessionOptions* options, int intra_op_num_threads);
  923. /** \brief Sets the number of threads used to parallelize the execution of the graph
  924. *
  925. * If nodes can be run in parallel, this sets the maximum number of threads to use to run them in parallel.
  926. *
  927. * \note If sequential execution is enabled this value is ignored, it acts as if it was set to 1.
  928. *
  929. * \param[in] options
  930. * \param[in] inter_op_num_threads Number of threads to use<br>
  931. * A value of 0 will use the default number of threads<br>
  932. *
  933. * \snippet{doc} snippets.dox OrtStatus Return Value
  934. */
  935. ORT_API2_STATUS(SetInterOpNumThreads, _Inout_ OrtSessionOptions* options, int inter_op_num_threads);
  936. /// @}
  937. /// \name OrtCustomOpDomain
  938. /// @{
  939. /** \brief Create a custom op domain
  940. *
  941. * \param[in] domain
  942. * \param[out] out Newly created domain. Must be freed with OrtApi::ReleaseCustomOpDomain
  943. *
  944. * \snippet{doc} snippets.dox OrtStatus Return Value
  945. */
  946. ORT_API2_STATUS(CreateCustomOpDomain, _In_ const char* domain, _Outptr_ OrtCustomOpDomain** out);
  947. /** \brief Add a custom op to a custom op domain
  948. *
  949. * \note The OrtCustomOp* pointer must remain valid until the ::OrtCustomOpDomain using it is released
  950. *
  951. * \param[in] custom_op_domain
  952. * \param[in] op
  953. *
  954. * \snippet{doc} snippets.dox OrtStatus Return Value
  955. */
  956. ORT_API2_STATUS(CustomOpDomain_Add, _Inout_ OrtCustomOpDomain* custom_op_domain, _In_ const OrtCustomOp* op);
  957. /// @}
  958. /// \name OrtSessionOptions
  959. /// @{
  960. /** \brief Add custom op domain to a session options
  961. *
  962. * \note The OrtCustomOpDomain* must not be deleted until all sessions using it are released
  963. *
  964. * \param[in] options
  965. * \param[in] custom_op_domain
  966. *
  967. * \snippet{doc} snippets.dox OrtStatus Return Value
  968. */
  969. ORT_API2_STATUS(AddCustomOpDomain, _Inout_ OrtSessionOptions* options, _In_ OrtCustomOpDomain* custom_op_domain);
  970. /** \deprecated Use OrtApi::RegisterCustomOpsLibrary_V2.
  971. *
  972. * Registers custom ops from a shared library.
  973. *
  974. * Loads a shared library (dll on windows, so on linux, etc) named 'library_path' and looks for this entry point:
  975. * OrtStatus* RegisterCustomOps(OrtSessionOptions * options, const OrtApiBase* api);
  976. * It then passes in the provided session options to this function along with the api base.
  977. * 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
  978. * session options are destroyed, or if an error occurs and it is non null.
  979. *
  980. * \param[in] options
  981. * \param[in] library_path
  982. * \param[out] library_handle OS specific handle to the loaded library (Use FreeLibrary on Windows, dlclose on Linux, etc.. to unload)
  983. *
  984. * \snippet{doc} snippets.dox OrtStatus Return Value
  985. */
  986. ORT_API2_STATUS(RegisterCustomOpsLibrary, _Inout_ OrtSessionOptions* options, _In_ const char* library_path, _Outptr_ void** library_handle);
  987. /// @}
  988. /// \name OrtSession
  989. /// @{
  990. /** \brief Get input count for a session
  991. *
  992. * This number must also match the number of inputs passed to OrtApi::Run
  993. *
  994. * \see OrtApi::SessionGetInputTypeInfo, OrtApi::SessionGetInputName, OrtApi::Session
  995. *
  996. * \param[in] session
  997. * \param[out] out Number of inputs
  998. *
  999. * \snippet{doc} snippets.dox OrtStatus Return Value
  1000. */
  1001. ORT_API2_STATUS(SessionGetInputCount, _In_ const OrtSession* session, _Out_ size_t* out);
  1002. /** \brief Get output count for a session
  1003. *
  1004. * This number must also match the number of outputs returned by OrtApi::Run
  1005. *
  1006. * \see OrtApi::SessionGetOutputTypeInfo, OrtApi::SessionGetOutputName, OrtApi::Session
  1007. *
  1008. * \param[in] session
  1009. * \param[out] out Number of outputs
  1010. *
  1011. * \snippet{doc} snippets.dox OrtStatus Return Value
  1012. */
  1013. ORT_API2_STATUS(SessionGetOutputCount, _In_ const OrtSession* session, _Out_ size_t* out);
  1014. /** \brief Get overridable initializer count
  1015. *
  1016. * \see OrtApi::SessionGetOverridableInitializerTypeInfo, OrtApi::SessionGetOverridableInitializerName
  1017. *
  1018. * \param[in] session
  1019. * \param[in] out
  1020. *
  1021. * \snippet{doc} snippets.dox OrtStatus Return Value
  1022. */
  1023. ORT_API2_STATUS(SessionGetOverridableInitializerCount, _In_ const OrtSession* session, _Out_ size_t* out);
  1024. /** \brief Get input type information
  1025. *
  1026. * \param[in] session
  1027. * \param[in] index Must be between 0 (inclusive) and what OrtApi::SessionGetInputCount returns (exclusive)
  1028. * \param[out] type_info Must be freed with OrtApi::ReleaseTypeInfo
  1029. *
  1030. * \snippet{doc} snippets.dox OrtStatus Return Value
  1031. */
  1032. ORT_API2_STATUS(SessionGetInputTypeInfo, _In_ const OrtSession* session, size_t index, _Outptr_ OrtTypeInfo** type_info);
  1033. /** \brief Get output type information
  1034. *
  1035. * \param[in] session
  1036. * \param[in] index Must be between 0 (inclusive) and what OrtApi::SessionGetOutputCount returns (exclusive)
  1037. * \param[out] type_info Must be freed with OrtApi::ReleaseTypeInfo
  1038. *
  1039. * \snippet{doc} snippets.dox OrtStatus Return Value
  1040. */
  1041. ORT_API2_STATUS(SessionGetOutputTypeInfo, _In_ const OrtSession* session, size_t index, _Outptr_ OrtTypeInfo** type_info);
  1042. /** \brief Get overridable initializer type information
  1043. *
  1044. * \param[in] session
  1045. * \param[in] index Must be between 0 (inclusive) and what OrtApi::SessionGetOverridableInitializerCount returns (exclusive)
  1046. * \param[out] type_info Must be freed with OrtApi::ReleaseTypeInfo
  1047. *
  1048. * \snippet{doc} snippets.dox OrtStatus Return Value
  1049. */
  1050. ORT_API2_STATUS(SessionGetOverridableInitializerTypeInfo, _In_ const OrtSession* session, size_t index, _Outptr_ OrtTypeInfo** type_info);
  1051. /** \brief Get input name
  1052. *
  1053. * \param[in] session
  1054. * \param[in] index Must be between 0 (inclusive) and what OrtApi::SessionGetInputCount returns (exclusive)
  1055. * \param[in] allocator
  1056. * \param[out] value Set to a null terminated UTF-8 encoded string allocated using `allocator`. Must be freed using `allocator`.
  1057. *
  1058. * \snippet{doc} snippets.dox OrtStatus Return Value
  1059. */
  1060. ORT_API2_STATUS(SessionGetInputName, _In_ const OrtSession* session, size_t index, _Inout_ OrtAllocator* allocator, _Outptr_ char** value);
  1061. /** \brief Get output name
  1062. *
  1063. * \param[in] session
  1064. * \param[in] index Must be between 0 (inclusive) and what OrtApi::SessionGetOutputCount returns (exclusive)
  1065. * \param[in] allocator
  1066. * \param[out] value Set to a null terminated UTF-8 encoded string allocated using `allocator`. Must be freed using `allocator`.
  1067. *
  1068. * \snippet{doc} snippets.dox OrtStatus Return Value
  1069. */
  1070. ORT_API2_STATUS(SessionGetOutputName, _In_ const OrtSession* session, size_t index, _Inout_ OrtAllocator* allocator, _Outptr_ char** value);
  1071. /** \brief Get overridable initializer name
  1072. *
  1073. * \param[in] session
  1074. * \param[in] index Must be between 0 (inclusive) and what OrtApi::SessionGetOverridableInitializerCount returns (exclusive)
  1075. * \param[in] allocator
  1076. * \param[out] value Set to a null terminated UTF-8 encoded string allocated using `allocator`. Must be freed using `allocator`.
  1077. *
  1078. * \snippet{doc} snippets.dox OrtStatus Return Value
  1079. */
  1080. ORT_API2_STATUS(SessionGetOverridableInitializerName, _In_ const OrtSession* session, size_t index,
  1081. _Inout_ OrtAllocator* allocator, _Outptr_ char** value);
  1082. /// @}
  1083. /// \name OrtRunOptions
  1084. /// @{
  1085. /** \brief Create an OrtRunOptions
  1086. *
  1087. * \param[out] out Returned newly created ::OrtRunOptions. Must be freed with OrtApi::ReleaseRunOptions
  1088. *
  1089. * \snippet{doc} snippets.dox OrtStatus Return Value
  1090. */
  1091. ORT_API2_STATUS(CreateRunOptions, _Outptr_ OrtRunOptions** out);
  1092. /** \brief Set per-run log verbosity level
  1093. *
  1094. * \see OrtApi::RunOptionsGetRunLogVerbosityLevel
  1095. *
  1096. * \param[in] options
  1097. * \param[in] log_verbosity_level \snippet{doc} snippets.dox Log Verbosity Level
  1098. *
  1099. * \snippet{doc} snippets.dox OrtStatus Return Value
  1100. */
  1101. ORT_API2_STATUS(RunOptionsSetRunLogVerbosityLevel, _Inout_ OrtRunOptions* options, int log_verbosity_level);
  1102. /** \brief Set per-run log severity level
  1103. *
  1104. * \see OrtApi::RunOptionsGetRunLogSeverityLevel
  1105. *
  1106. * \param[in] options
  1107. * \param[in] log_severity_level The log severity level (refer to ::OrtLoggingLevel for possible values).
  1108. */
  1109. ORT_API2_STATUS(RunOptionsSetRunLogSeverityLevel, _Inout_ OrtRunOptions* options, int log_severity_level);
  1110. /** \brief Set per-run tag
  1111. *
  1112. * This is used in a per-run log identifier.
  1113. *
  1114. * \see OrtApi::RunOptionsGetRunTag
  1115. *
  1116. * \param[in] options
  1117. * \param[in] run_tag The run tag.
  1118. */
  1119. ORT_API2_STATUS(RunOptionsSetRunTag, _Inout_ OrtRunOptions* options, _In_ const char* run_tag);
  1120. /** \brief Get per-run log verbosity level
  1121. *
  1122. * \see OrtApi::RunOptionsSetRunLogVerbosityLevel
  1123. *
  1124. * \param[in] options
  1125. * \param[out] log_verbosity_level \snippet{doc} snippets.dox Log Verbosity Level
  1126. *
  1127. * \snippet{doc} snippets.dox OrtStatus Return Value
  1128. */
  1129. ORT_API2_STATUS(RunOptionsGetRunLogVerbosityLevel, _In_ const OrtRunOptions* options,
  1130. _Out_ int* log_verbosity_level);
  1131. /** \brief Get per-run log severity level
  1132. *
  1133. * \see OrtApi::RunOptionsSetRunLogSeverityLevel
  1134. *
  1135. * \param[in] options
  1136. * \param[out] log_severity_level The log severity level (refer to ::OrtLoggingLevel for possible values).
  1137. */
  1138. ORT_API2_STATUS(RunOptionsGetRunLogSeverityLevel, _In_ const OrtRunOptions* options, _Out_ int* log_severity_level);
  1139. /** \brief Get per-run tag
  1140. *
  1141. * This is used in a per-run log identifier.
  1142. *
  1143. * \see OrtApi::RunOptionsSetRunTag
  1144. *
  1145. * \param[in] options
  1146. * \param[out] run_tag The run tag.
  1147. * Do not free this value, it is owned by `options`. It will be invalidated if the run tag
  1148. * changes (i.e., with OrtApi::RunOptionsSetRunTag) or `options` is freed.
  1149. */
  1150. ORT_API2_STATUS(RunOptionsGetRunTag, _In_ const OrtRunOptions* options, _Out_ const char** run_tag);
  1151. /** \brief Set terminate flag
  1152. *
  1153. * 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.
  1154. *
  1155. * \param[in] options
  1156. *
  1157. * \snippet{doc} snippets.dox OrtStatus Return Value
  1158. */
  1159. ORT_API2_STATUS(RunOptionsSetTerminate, _Inout_ OrtRunOptions* options);
  1160. /** \brief Clears the terminate flag
  1161. *
  1162. * Used so the OrtRunOptions instance can be used in a new OrtApi::Run call without it instantly terminating
  1163. *
  1164. * \param[in] options
  1165. *
  1166. * \snippet{doc} snippets.dox OrtStatus Return Value
  1167. */
  1168. ORT_API2_STATUS(RunOptionsUnsetTerminate, _Inout_ OrtRunOptions* options);
  1169. /// @}
  1170. /// \name OrtValue
  1171. /// @{
  1172. /** \brief Create a tensor
  1173. *
  1174. * Create a tensor using a supplied ::OrtAllocator
  1175. *
  1176. * \param[in] allocator
  1177. * \param[in] shape Pointer to the tensor shape dimensions.
  1178. * \param[in] shape_len The number of tensor shape dimensions.
  1179. * \param[in] type
  1180. * \param[out] out Returns newly created ::OrtValue. Must be freed with OrtApi::ReleaseValue
  1181. *
  1182. * \snippet{doc} snippets.dox OrtStatus Return Value
  1183. */
  1184. ORT_API2_STATUS(CreateTensorAsOrtValue, _Inout_ OrtAllocator* allocator, _In_ const int64_t* shape, size_t shape_len,
  1185. ONNXTensorElementDataType type, _Outptr_ OrtValue** out);
  1186. /** \brief Create a tensor backed by a user supplied buffer
  1187. *
  1188. * Create a tensor with user's buffer. You can fill the buffer either before calling this function or after.
  1189. * p_data is owned by caller. ReleaseValue won't release p_data.
  1190. *
  1191. * \param[in] info Memory description of where the p_data buffer resides (CPU vs GPU etc).
  1192. * \param[in] p_data Pointer to the data buffer.
  1193. * \param[in] p_data_len The number of bytes in the data buffer.
  1194. * \param[in] shape Pointer to the tensor shape dimensions.
  1195. * \param[in] shape_len The number of tensor shape dimensions.
  1196. * \param[in] type The data type.
  1197. * \param[out] out Returns newly created ::OrtValue. Must be freed with OrtApi::ReleaseValue
  1198. *
  1199. * \snippet{doc} snippets.dox OrtStatus Return Value
  1200. */
  1201. ORT_API2_STATUS(CreateTensorWithDataAsOrtValue, _In_ const OrtMemoryInfo* info, _Inout_ void* p_data,
  1202. size_t p_data_len, _In_ const int64_t* shape, size_t shape_len, ONNXTensorElementDataType type,
  1203. _Outptr_ OrtValue** out);
  1204. /** \brief Return if an ::OrtValue is a tensor type
  1205. *
  1206. * \param[in] value A tensor type (string tensors are not supported)
  1207. * \param[out] out Set to 1 iff ::OrtValue is a tensor, 0 otherwise
  1208. *
  1209. * \snippet{doc} snippets.dox OrtStatus Return Value
  1210. */
  1211. ORT_API2_STATUS(IsTensor, _In_ const OrtValue* value, _Out_ int* out);
  1212. /** \brief Get a pointer to the raw data inside a tensor
  1213. *
  1214. * Used to read/write/modify the internal tensor data directly.
  1215. * \note The returned pointer is valid until the \p value is destroyed.
  1216. *
  1217. * \param[in] value A tensor type (string tensors are not supported)
  1218. * \param[out] out Filled in with a pointer to the internal storage
  1219. *
  1220. * \snippet{doc} snippets.dox OrtStatus Return Value
  1221. */
  1222. ORT_API2_STATUS(GetTensorMutableData, _In_ OrtValue* value, _Outptr_ void** out);
  1223. /** \brief Set all strings at once in a string tensor
  1224. *
  1225. * \param[in,out] value A tensor of type ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING
  1226. * \param[in] s An array of strings. Each string in this array must be null terminated.
  1227. * \param[in] s_len Count of strings in s (Must match the size of \p value's tensor shape)
  1228. *
  1229. * \snippet{doc} snippets.dox OrtStatus Return Value
  1230. */
  1231. ORT_API2_STATUS(FillStringTensor, _Inout_ OrtValue* value, _In_ const char* const* s, size_t s_len);
  1232. /** \brief Get total byte length for all strings in a string tensor
  1233. *
  1234. * Typically used with OrtApi::GetStringTensorContent
  1235. *
  1236. * \param[in] value A tensor of type ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING
  1237. * \param[out] len Total byte length of all strings (does not include trailing nulls)
  1238. *
  1239. * \snippet{doc} snippets.dox OrtStatus Return Value
  1240. */
  1241. ORT_API2_STATUS(GetStringTensorDataLength, _In_ const OrtValue* value, _Out_ size_t* len);
  1242. /** \brief Get all strings from a string tensor
  1243. *
  1244. * An example of the results:<br>
  1245. * Given \p value is a string tensor with the strings { "This" "is" "a" "test" }<br>
  1246. * \p s must have a size of 11 bytes<br>
  1247. * \p offsets must have 4 elements<br>
  1248. * After the call, these values will be filled in:<br>
  1249. * \p s will contain "Thisisatest"<br>
  1250. * \p offsets will contain { 0, 4, 6, 7 }<br>
  1251. * The length of the last string is just s_len - offsets[last]
  1252. *
  1253. * \param[in] value A tensor of type ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING
  1254. * \param[in] s Buffer to sequentially write all tensor strings to. Each string is NOT null-terminated.
  1255. * \param[in] s_len Number of bytes of buffer pointed to by \p s (Get it from OrtApi::GetStringTensorDataLength)
  1256. * \param[out] offsets Array of start offsets into the strings written to \p s
  1257. * \param[in] offsets_len Number of elements in offsets
  1258. *
  1259. * \snippet{doc} snippets.dox OrtStatus Return Value
  1260. */
  1261. ORT_API2_STATUS(GetStringTensorContent, _In_ const OrtValue* value, _Out_writes_bytes_all_(s_len) void* s,
  1262. size_t s_len, _Out_writes_all_(offsets_len) size_t* offsets, size_t offsets_len);
  1263. /// @}
  1264. /// \name OrtTypeInfo
  1265. /// @{
  1266. /** \brief Get ::OrtTensorTypeAndShapeInfo from an ::OrtTypeInfo
  1267. *
  1268. * \param[in] type_info
  1269. * \param[out] out Do not free this value, it will be valid until type_info is freed.
  1270. * If type_info does not represent tensor, this value will be set to nullptr.
  1271. *
  1272. * \snippet{doc} snippets.dox OrtStatus Return Value
  1273. */
  1274. ORT_API2_STATUS(CastTypeInfoToTensorInfo, _In_ const OrtTypeInfo* type_info,
  1275. _Outptr_result_maybenull_ const OrtTensorTypeAndShapeInfo** out);
  1276. /** \brief Get ::ONNXType from ::OrtTypeInfo
  1277. *
  1278. * \param[in] type_info
  1279. * \param[out] out
  1280. *
  1281. * \snippet{doc} snippets.dox OrtStatus Return Value
  1282. */
  1283. ORT_API2_STATUS(GetOnnxTypeFromTypeInfo, _In_ const OrtTypeInfo* type_info, _Out_ enum ONNXType* out);
  1284. /// @}
  1285. /// \name OrtTensorTypeAndShapeInfo
  1286. /// @{
  1287. /** \brief Create an ::OrtTensorTypeAndShapeInfo object
  1288. *
  1289. * \param[out] out Returns newly created ::OrtTensorTypeAndShapeInfo. Must be freed with OrtApi::ReleaseTensorTypeAndShapeInfo
  1290. *
  1291. * \snippet{doc} snippets.dox OrtStatus Return Value
  1292. */
  1293. ORT_API2_STATUS(CreateTensorTypeAndShapeInfo, _Outptr_ OrtTensorTypeAndShapeInfo** out);
  1294. /** \brief Set element type in ::OrtTensorTypeAndShapeInfo
  1295. *
  1296. * \param[in] info
  1297. * \param[in] type
  1298. *
  1299. * \snippet{doc} snippets.dox OrtStatus Return Value
  1300. */
  1301. ORT_API2_STATUS(SetTensorElementType, _Inout_ OrtTensorTypeAndShapeInfo* info, enum ONNXTensorElementDataType type);
  1302. /** \brief Set shape information in ::OrtTensorTypeAndShapeInfo
  1303. *
  1304. * \param[in] info
  1305. * \param[in] dim_values Array with `dim_count` elements. Can contain negative values.
  1306. * \param[in] dim_count Number of elements in `dim_values`
  1307. *
  1308. * \snippet{doc} snippets.dox OrtStatus Return Value
  1309. */
  1310. ORT_API2_STATUS(SetDimensions, OrtTensorTypeAndShapeInfo* info, _In_ const int64_t* dim_values, size_t dim_count);
  1311. /** \brief Get element type in ::OrtTensorTypeAndShapeInfo
  1312. *
  1313. * \see OrtApi::SetTensorElementType
  1314. *
  1315. * \param[in] info
  1316. * \param[out] out
  1317. *
  1318. * \snippet{doc} snippets.dox OrtStatus Return Value
  1319. */
  1320. ORT_API2_STATUS(GetTensorElementType, _In_ const OrtTensorTypeAndShapeInfo* info,
  1321. _Out_ enum ONNXTensorElementDataType* out);
  1322. /** \brief Get dimension count in ::OrtTensorTypeAndShapeInfo
  1323. *
  1324. * \see OrtApi::GetDimensions
  1325. *
  1326. * \param[in] info
  1327. * \param[out] out
  1328. *
  1329. * \snippet{doc} snippets.dox OrtStatus Return Value
  1330. */
  1331. ORT_API2_STATUS(GetDimensionsCount, _In_ const OrtTensorTypeAndShapeInfo* info, _Out_ size_t* out);
  1332. /** \brief Get dimensions in ::OrtTensorTypeAndShapeInfo
  1333. *
  1334. * \param[in] info
  1335. * \param[out] dim_values Array with `dim_values_length` elements. On return, filled with the dimensions stored in the ::OrtTensorTypeAndShapeInfo
  1336. * \param[in] dim_values_length Number of elements in `dim_values`. Use OrtApi::GetDimensionsCount to get this value
  1337. *
  1338. * \snippet{doc} snippets.dox OrtStatus Return Value
  1339. */
  1340. ORT_API2_STATUS(GetDimensions, _In_ const OrtTensorTypeAndShapeInfo* info, _Out_ int64_t* dim_values,
  1341. size_t dim_values_length);
  1342. /** \brief Get symbolic dimension names in ::OrtTensorTypeAndShapeInfo
  1343. *
  1344. * \param[in] info
  1345. * \param[in] dim_params Array with `dim_params_length` elements. On return filled with pointers to null terminated strings of the dimension names
  1346. * \param[in] dim_params_length Number of elements in `dim_params`. Use OrtApi::GetDimensionsCount to get this value
  1347. *
  1348. * \snippet{doc} snippets.dox OrtStatus Return Value
  1349. */
  1350. ORT_API2_STATUS(GetSymbolicDimensions, _In_ const OrtTensorTypeAndShapeInfo* info,
  1351. _Out_writes_all_(dim_params_length) const char* dim_params[], size_t dim_params_length);
  1352. /** \brief Get total number of elements in a tensor shape from an ::OrtTensorTypeAndShapeInfo
  1353. *
  1354. * Return the number of elements specified by the tensor shape (all dimensions multiplied by each other).
  1355. * For 0 dimensions, 1 is returned. If any dimension is less than 0, the result is always -1.
  1356. *
  1357. * Examples:<br>
  1358. * [] = 1<br>
  1359. * [1,3,4] = 12<br>
  1360. * [2,0,4] = 0<br>
  1361. * [-1,3,4] = -1<br>
  1362. *
  1363. * \param[in] info
  1364. * \param[out] out Number of elements
  1365. *
  1366. * \snippet{doc} snippets.dox OrtStatus Return Value
  1367. */
  1368. ORT_API2_STATUS(GetTensorShapeElementCount, _In_ const OrtTensorTypeAndShapeInfo* info, _Out_ size_t* out);
  1369. /// @}
  1370. /// \name OrtValue
  1371. /// @{
  1372. /** \brief Get type and shape information from a tensor ::OrtValue
  1373. *
  1374. * \param[in] value Must be a tensor (not a map/sequence/etc) or will return failure
  1375. * \param[out] out Newly created ::OrtTensorTypeAndShapeInfo. Must be freed with OrtApi::ReleaseTensorTypeAndShapeInfo
  1376. *
  1377. * \snippet{doc} snippets.dox OrtStatus Return Value
  1378. */
  1379. ORT_API2_STATUS(GetTensorTypeAndShape, _In_ const OrtValue* value, _Outptr_ OrtTensorTypeAndShapeInfo** out);
  1380. /** \brief Get type information of an OrtValue
  1381. *
  1382. * \param[in] value
  1383. * \param[out] out Newly created ::OrtTypeInfo. Must be freed with OrtApi::ReleaseTypeInfo
  1384. *
  1385. * \snippet{doc} snippets.dox OrtStatus Return Value
  1386. */
  1387. ORT_API2_STATUS(GetTypeInfo, _In_ const OrtValue* value, _Outptr_result_maybenull_ OrtTypeInfo** out);
  1388. /** \brief Get ONNXType of an ::OrtValue
  1389. *
  1390. * \param[in] value
  1391. * \param[out] out
  1392. *
  1393. * \snippet{doc} snippets.dox OrtStatus Return Value
  1394. */
  1395. ORT_API2_STATUS(GetValueType, _In_ const OrtValue* value, _Out_ enum ONNXType* out);
  1396. /// @}
  1397. /// \name OrtMemoryInfo
  1398. /// @{
  1399. /** \brief Create an ::OrtMemoryInfo
  1400. *
  1401. * \param[in] name
  1402. * \param[in] type
  1403. * \param[in] id
  1404. * \param[in] mem_type
  1405. * \param[out] out Newly created ::OrtMemoryInfo. Must be freed with OrtAPi::ReleaseMemoryInfo
  1406. *
  1407. * \snippet{doc} snippets.dox OrtStatus Return Value
  1408. */
  1409. ORT_API2_STATUS(CreateMemoryInfo, _In_ const char* name, enum OrtAllocatorType type, int id,
  1410. enum OrtMemType mem_type, _Outptr_ OrtMemoryInfo** out);
  1411. /** \brief Create an ::OrtMemoryInfo for CPU memory
  1412. *
  1413. * Special case version of OrtApi::CreateMemoryInfo for CPU based memory. Same as using OrtApi::CreateMemoryInfo with name = "Cpu" and id = 0.
  1414. *
  1415. * \param[in] type
  1416. * \param[in] mem_type
  1417. * \param[out] out
  1418. *
  1419. * \snippet{doc} snippets.dox OrtStatus Return Value
  1420. */
  1421. ORT_API2_STATUS(CreateCpuMemoryInfo, enum OrtAllocatorType type, enum OrtMemType mem_type,
  1422. _Outptr_ OrtMemoryInfo** out);
  1423. /** \brief Compare ::OrtMemoryInfo objects for equality
  1424. *
  1425. * Compares all settings of each ::OrtMemoryInfo for equality
  1426. *
  1427. * \param[in] info1
  1428. * \param[in] info2
  1429. * \param[out] out Set to 0 if equal, -1 if not equal
  1430. *
  1431. * \snippet{doc} snippets.dox OrtStatus Return Value
  1432. */
  1433. ORT_API2_STATUS(CompareMemoryInfo, _In_ const OrtMemoryInfo* info1, _In_ const OrtMemoryInfo* info2, _Out_ int* out);
  1434. /** \brief Get name from ::OrtMemoryInfo
  1435. *
  1436. * \param[in] ptr
  1437. * \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
  1438. *
  1439. * \snippet{doc} snippets.dox OrtStatus Return Value
  1440. */
  1441. ORT_API2_STATUS(MemoryInfoGetName, _In_ const OrtMemoryInfo* ptr, _Out_ const char** out);
  1442. /** \brief Get the id from ::OrtMemoryInfo
  1443. */
  1444. ORT_API2_STATUS(MemoryInfoGetId, _In_ const OrtMemoryInfo* ptr, _Out_ int* out);
  1445. /** \brief Get the ::OrtMemType from ::OrtMemoryInfo
  1446. */
  1447. ORT_API2_STATUS(MemoryInfoGetMemType, _In_ const OrtMemoryInfo* ptr, _Out_ OrtMemType* out);
  1448. /** \brief Get the ::OrtAllocatorType from ::OrtMemoryInfo
  1449. */
  1450. ORT_API2_STATUS(MemoryInfoGetType, _In_ const OrtMemoryInfo* ptr, _Out_ OrtAllocatorType* out);
  1451. /// @}
  1452. /// \name OrtAllocator
  1453. /// @{
  1454. /// \brief Calls OrtAllocator::Alloc function
  1455. ORT_API2_STATUS(AllocatorAlloc, _Inout_ OrtAllocator* ort_allocator, size_t size, _Outptr_ void** out);
  1456. /// \brief Calls OrtAllocator::Free function
  1457. ORT_API2_STATUS(AllocatorFree, _Inout_ OrtAllocator* ort_allocator, void* p);
  1458. /// \brief Calls OrtAllocator::Info function
  1459. ORT_API2_STATUS(AllocatorGetInfo, _In_ const OrtAllocator* ort_allocator, _Outptr_ const struct OrtMemoryInfo** out);
  1460. /** \brief Get the default allocator
  1461. *
  1462. * The default allocator is a CPU based, non-arena. Always returns the same pointer to the same default allocator.
  1463. *
  1464. * \param[out] out Returned value should NOT be freed
  1465. *
  1466. * \snippet{doc} snippets.dox OrtStatus Return Value
  1467. */
  1468. ORT_API2_STATUS(GetAllocatorWithDefaultOptions, _Outptr_ OrtAllocator** out);
  1469. /// @}
  1470. /// \name OrtSessionOptions
  1471. /// @{
  1472. /** \brief Override session symbolic dimensions
  1473. *
  1474. * Override symbolic dimensions (by specific denotation strings) with actual values if known at session initialization time to enable
  1475. * optimizations that can take advantage of fixed values (such as memory planning, etc)
  1476. *
  1477. * \param[in] options
  1478. * \param[in] dim_denotation
  1479. * \param[in] dim_value
  1480. *
  1481. * \snippet{doc} snippets.dox OrtStatus Return Value
  1482. */
  1483. ORT_API2_STATUS(AddFreeDimensionOverride, _Inout_ OrtSessionOptions* options, _In_ const char* dim_denotation,
  1484. _In_ int64_t dim_value);
  1485. /// @}
  1486. /// \name OrtValue
  1487. /// @{
  1488. /* Internal information (not seen in Doxygen)
  1489. *
  1490. * APIs to support non-tensor types - map and sequence.
  1491. * Currently only the following types are supported
  1492. * Note: the following types should be kept in sync with data_types.h
  1493. * Map types
  1494. * =========
  1495. * std::map<std::string, std::string>
  1496. * std::map<std::string, int64_t>
  1497. * std::map<std::string, float>
  1498. * std::map<std::string, double>
  1499. * std::map<int64_t, std::string>
  1500. * std::map<int64_t, int64_t>
  1501. * std::map<int64_t, float>
  1502. * std::map<int64_t, double>
  1503. *
  1504. * Sequence types
  1505. * ==============
  1506. * std::vector<std::string>
  1507. * std::vector<int64_t>
  1508. * std::vector<float>
  1509. * std::vector<double>
  1510. * std::vector<std::map<std::string, float>>
  1511. * std::vector<std::map<int64_t, float>
  1512. */
  1513. /** \brief Get non tensor data from an ::OrtValue
  1514. *
  1515. * If `value` is of type ONNX_TYPE_MAP, you need to retrieve the keys and values
  1516. * separately. Use index=0 to retrieve keys and index=1 to retrieve values.
  1517. * If `value` is of type ONNX_TYPE_SEQUENCE, use index to retrieve the index'th element
  1518. * of the sequence.
  1519. *
  1520. * \param[in] value
  1521. * \param[in] index See above for usage based on `value` type
  1522. * \param[in] allocator Allocator used to allocate ::OrtValue
  1523. * \param[out] out Created ::OrtValue that holds the element requested. Must be freed with OrtApi::ReleaseValue
  1524. *
  1525. * \snippet{doc} snippets.dox OrtStatus Return Value
  1526. */
  1527. ORT_API2_STATUS(GetValue, _In_ const OrtValue* value, int index, _Inout_ OrtAllocator* allocator,
  1528. _Outptr_ OrtValue** out);
  1529. /** \brief Get non tensor value count from an ::OrtValue
  1530. *
  1531. * If `value` is of type ONNX_TYPE_MAP 2 will always be returned. For ONNX_TYPE_SEQUENCE
  1532. * the number of elements in the sequence will be returned
  1533. *
  1534. * \param[in] value
  1535. * \param[out] out
  1536. *
  1537. * \snippet{doc} snippets.dox OrtStatus Return Value
  1538. */
  1539. ORT_API2_STATUS(GetValueCount, _In_ const OrtValue* value, _Out_ size_t* out);
  1540. /** \brief Create a map or sequence ::OrtValue
  1541. *
  1542. * To construct a map (ONNX_TYPE_MAP), use num_values = 2 and `in` should be an array of 2 ::OrtValue%s
  1543. * representing keys and values.<br>
  1544. *
  1545. * To construct a sequence (ONNX_TYPE_SEQUENCE), use num_values = N where N is the number of the elements in the
  1546. * sequence. 'in' should be an array of N ::OrtValue%s.
  1547. *
  1548. * \param[in] in See above for details
  1549. * \param[in] num_values
  1550. * \param[in] value_type Must be either ONNX_TYPE_MAP or ONNX_TYPE_SEQUENCE
  1551. * \param[out] out Newly created ::OrtValue. Must be freed with OrtApi::ReleaseValue
  1552. *
  1553. * \snippet{doc} snippets.dox OrtStatus Return Value
  1554. */
  1555. ORT_API2_STATUS(CreateValue, _In_reads_(num_values) const OrtValue* const* in, size_t num_values,
  1556. enum ONNXType value_type, _Outptr_ OrtValue** out);
  1557. /** \brief Create an opaque (custom user defined type) ::OrtValue
  1558. *
  1559. * Constructs an ::OrtValue that contains a value of non-standard type created for
  1560. * experiments or while awaiting standardization. ::OrtValue in this case would contain
  1561. * an internal representation of the Opaque type. Opaque types are distinguished from
  1562. * each other by two strings 1) domain and 2) type name. The combination of the two
  1563. * must be unique, so the type representation is properly identified internally. The combination
  1564. * must be properly registered from within ORT at both compile/run time or by another API.
  1565. *
  1566. * To construct the ::OrtValue pass domain and type names, also a pointer to a data container
  1567. * the type of which must be known to both ORT and the client program. That data container may or may
  1568. * not match the internal representation of the Opaque type. The sizeof(data_container) is passed for
  1569. * verification purposes.
  1570. *
  1571. * \param[in] domain_name Null terminated string of the domain name
  1572. * \param[in] type_name Null terminated string of the type name
  1573. * \param[in] data_container User pointer Data to populate ::OrtValue
  1574. * \param[in] data_container_size Size in bytes of what `data_container` points to
  1575. * \param[out] out Newly created ::OrtValue. Must be freed with OrtApi::ReleaseValue
  1576. *
  1577. * \snippet{doc} snippets.dox OrtStatus Return Value
  1578. */
  1579. ORT_API2_STATUS(CreateOpaqueValue, _In_z_ const char* domain_name, _In_z_ const char* type_name,
  1580. _In_ const void* data_container, size_t data_container_size, _Outptr_ OrtValue** out);
  1581. /** \brief Get internal data from an opaque (custom user defined type) ::OrtValue
  1582. *
  1583. * Copies internal data from an opaque value into a user provided buffer
  1584. *
  1585. * \see OrtApi::CreateOpaqueValue
  1586. *
  1587. * \param[in] domain_name Null terminated string of the domain name
  1588. * \param[in] type_name Null terminated string of the type name
  1589. * \param[in] in The opaque ::OrtValue
  1590. * \param[out] data_container Buffer to copy data into
  1591. * \param[out] data_container_size Size in bytes of the buffer pointed to by data_container. Must match the size of the internal buffer.
  1592. *
  1593. * \snippet{doc} snippets.dox OrtStatus Return Value
  1594. */
  1595. ORT_API2_STATUS(GetOpaqueValue, _In_ const char* domain_name, _In_ const char* type_name, _In_ const OrtValue* in,
  1596. _Out_ void* data_container, size_t data_container_size);
  1597. /// @}
  1598. /// \name OrtKernelInfo
  1599. /// Custom operator APIs.
  1600. /// @{
  1601. /** \brief Get a float stored as an attribute in the graph node
  1602. *
  1603. * \param[in] info ::OrtKernelInfo instance
  1604. * \param[in] name Null terminated string of the name of the attribute
  1605. * \param[out] out Pointer to memory where the attribute will be stored
  1606. *
  1607. * \snippet{doc} snippets.dox OrtStatus Return Value
  1608. */
  1609. ORT_API2_STATUS(KernelInfoGetAttribute_float, _In_ const OrtKernelInfo* info, _In_ const char* name,
  1610. _Out_ float* out);
  1611. /** \brief Fetch a 64-bit int stored as an attribute in the graph node
  1612. *
  1613. * \param[in] info ::OrtKernelInfo instance
  1614. * \param[in] name Null terminated string of the name of the attribute
  1615. * \param[out] out Pointer to memory where the attribute will be stored
  1616. *
  1617. * \snippet{doc} snippets.dox OrtStatus Return Value
  1618. */
  1619. ORT_API2_STATUS(KernelInfoGetAttribute_int64, _In_ const OrtKernelInfo* info, _In_ const char* name,
  1620. _Out_ int64_t* out);
  1621. /** \brief Fetch a string stored as an attribute in the graph node
  1622. *
  1623. * If `out` is nullptr, the value of `size` is set to the true size of the string
  1624. * attribute, and a success status is returned.
  1625. *
  1626. * If the `size` parameter is greater than or equal to the actual string attribute's size,
  1627. * the value of `size` is set to the true size of the string attribute, the provided memory
  1628. * is filled with the attribute's contents, and a success status is returned.
  1629. *
  1630. * If the `size` parameter is less than the actual string attribute's size and `out`
  1631. * is not nullptr, the value of `size` is set to the true size of the string attribute
  1632. * and a failure status is returned.)
  1633. *
  1634. * \param[in] info ::OrtKernelInfo instance
  1635. * \param[in] name Null terminated string of the name of the attribute
  1636. * \param[out] out Pointer to memory where the attribute will be stored
  1637. * \param[in,out] size See above comments for details
  1638. *
  1639. * \snippet{doc} snippets.dox OrtStatus Return Value
  1640. */
  1641. ORT_API2_STATUS(KernelInfoGetAttribute_string, _In_ const OrtKernelInfo* info, _In_ const char* name, _Out_ char* out,
  1642. _Inout_ size_t* size);
  1643. /// @}
  1644. /// \name OrtKernelContext
  1645. /// Custom operator APIs.
  1646. /// @{
  1647. /** \brief Used for custom operators, get the input count of a kernel
  1648. *
  1649. * \see ::OrtCustomOp
  1650. */
  1651. ORT_API2_STATUS(KernelContext_GetInputCount, _In_ const OrtKernelContext* context, _Out_ size_t* out);
  1652. /** \brief Used for custom operators, get the output count of a kernel
  1653. *
  1654. * \see ::OrtCustomOp
  1655. */
  1656. ORT_API2_STATUS(KernelContext_GetOutputCount, _In_ const OrtKernelContext* context, _Out_ size_t* out);
  1657. /** \brief Used for custom operators, get an input of a kernel
  1658. *
  1659. * The function attempts fetches the input of the kernel. If the input is optional
  1660. * and not present, the function returns success and out is set to nullptr.
  1661. *
  1662. * \param[in] context ::OrtKernelContext instance
  1663. * \param[in] input index. See KernelContext_GetInputCount for boundaries check.
  1664. * \param[in, out] returns a ptr to OrtValue if the input is present
  1665. *
  1666. * \snippet{doc} snippets.dox OrtStatus Return Value
  1667. */
  1668. ORT_API2_STATUS(KernelContext_GetInput, _In_ const OrtKernelContext* context, _In_ size_t index,
  1669. _Out_ const OrtValue** out);
  1670. /** \brief Used for custom operators, get an output of a kernel
  1671. *
  1672. * The function attempts fetches the output of the kernel. If the output is optional
  1673. * and not present, the function returns success and out is set to nullptr.
  1674. *
  1675. * \param[in] context ::OrtKernelContext instance
  1676. * \param[in] output index. See KernelContext_GetOutputCount for boundaries check.
  1677. * \param[in, out] returns a ptr to OrtValue if the output is present
  1678. *
  1679. * \snippet{doc} snippets.dox OrtStatus Return Value
  1680. */
  1681. ORT_API2_STATUS(KernelContext_GetOutput, _Inout_ OrtKernelContext* context, _In_ size_t index,
  1682. _In_ const int64_t* dim_values, size_t dim_count, _Outptr_ OrtValue** out);
  1683. /// @}
  1684. /// \name OrtEnv
  1685. /// @{
  1686. ORT_CLASS_RELEASE(Env);
  1687. /// @}
  1688. /// \name OrtStatus
  1689. /// @{
  1690. ORT_CLASS_RELEASE(Status);
  1691. /// @}
  1692. /// \name OrtMemoryInfo
  1693. /// @{
  1694. ORT_CLASS_RELEASE(MemoryInfo);
  1695. /// @}
  1696. /// \name OrtSession
  1697. /// @{
  1698. ORT_CLASS_RELEASE(Session); // Don't call ReleaseSession from Dllmain (because session owns a thread pool)
  1699. /// @}
  1700. /// \name OrtValue
  1701. /// @{
  1702. ORT_CLASS_RELEASE(Value);
  1703. /// @}
  1704. /// \name OrtRunOptions
  1705. /// @{
  1706. ORT_CLASS_RELEASE(RunOptions);
  1707. /// @}
  1708. /// \name OrtTypeInfo
  1709. /// @{
  1710. ORT_CLASS_RELEASE(TypeInfo);
  1711. /// @}
  1712. /// \name OrtTensorTypeAndShapeInfo
  1713. /// @{
  1714. ORT_CLASS_RELEASE(TensorTypeAndShapeInfo);
  1715. /// @}
  1716. /// \name OrtSessionOptions
  1717. /// @{
  1718. ORT_CLASS_RELEASE(SessionOptions);
  1719. /// @}
  1720. /// \name OrtCustomOpDomain
  1721. /// @{
  1722. ORT_CLASS_RELEASE(CustomOpDomain);
  1723. /// @}
  1724. /// \name OrtTypeInfo
  1725. /// @{
  1726. /** \brief Get denotation from type information
  1727. *
  1728. * Augments ::OrtTypeInfo to return denotations on the type.
  1729. *
  1730. * This is used by WinML to determine if an input/output is intended to be an Image or a Tensor.
  1731. *
  1732. * \param[in] type_info
  1733. * \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.
  1734. * \param[out] len Length in bytes of the string returned in `denotation`
  1735. *
  1736. * \snippet{doc} snippets.dox OrtStatus Return Value
  1737. */
  1738. ORT_API2_STATUS(GetDenotationFromTypeInfo, _In_ const OrtTypeInfo* type_info, _Out_ const char** const denotation,
  1739. _Out_ size_t* len);
  1740. /** \brief Get detailed map information from an ::OrtTypeInfo
  1741. *
  1742. * This augments ::OrtTypeInfo to return an ::OrtMapTypeInfo when the type is a map.
  1743. * The OrtMapTypeInfo has additional information about the map's key type and value type.
  1744. *
  1745. * This is used by WinML to support model reflection APIs.
  1746. *
  1747. * \param[out] type_info
  1748. * \param[out] out A pointer to the ::OrtMapTypeInfo. Do not free this value. If type_info
  1749. * does not contain a map, this value will be set to nullptr.
  1750. *
  1751. * \snippet{doc} snippets.dox OrtStatus Return Value
  1752. */
  1753. ORT_API2_STATUS(CastTypeInfoToMapTypeInfo, _In_ const OrtTypeInfo* type_info,
  1754. _Outptr_result_maybenull_ const OrtMapTypeInfo** out);
  1755. /** \brief Cast ::OrtTypeInfo to an ::OrtSequenceTypeInfo
  1756. *
  1757. * This api augments ::OrtTypeInfo to return an ::OrtSequenceTypeInfo when the type is a sequence.
  1758. * The ::OrtSequenceTypeInfo has additional information about the sequence's element type.
  1759. *
  1760. * This is used by WinML to support model reflection APIs.
  1761. *
  1762. * \param[in] type_info
  1763. * \param[out] out A pointer to the OrtSequenceTypeInfo. Do not free this value. If type_info
  1764. * doesn not contain a sequence, this value will be set to nullptr.
  1765. *
  1766. * \snippet{doc} snippets.dox OrtStatus Return Value
  1767. */
  1768. ORT_API2_STATUS(CastTypeInfoToSequenceTypeInfo, _In_ const OrtTypeInfo* type_info,
  1769. _Outptr_result_maybenull_ const OrtSequenceTypeInfo** out);
  1770. /// @}
  1771. /// \name OrtMapTypeInfo
  1772. /// @{
  1773. /** \brief Get key type from an ::OrtMapTypeInfo
  1774. *
  1775. * Key types are restricted to being scalar types.
  1776. *
  1777. * This is used by WinML to support model reflection APIs.
  1778. *
  1779. * \param[in] map_type_info
  1780. * \param[out] out
  1781. *
  1782. * \snippet{doc} snippets.dox OrtStatus Return Value
  1783. */
  1784. ORT_API2_STATUS(GetMapKeyType, _In_ const OrtMapTypeInfo* map_type_info, _Out_ enum ONNXTensorElementDataType* out);
  1785. /** \brief Get the value type from an ::OrtMapTypeInfo
  1786. *
  1787. * \param[in] map_type_info
  1788. * \param[out] type_info
  1789. *
  1790. * \snippet{doc} snippets.dox OrtStatus Return Value
  1791. */
  1792. ORT_API2_STATUS(GetMapValueType, _In_ const OrtMapTypeInfo* map_type_info, _Outptr_ OrtTypeInfo** type_info);
  1793. /// @}
  1794. /// \name OrtSequenceTypeInfo
  1795. /// @{
  1796. /** \brief Get element type from an ::OrtSequenceTypeInfo
  1797. *
  1798. * This is used by WinML to support model reflection APIs.
  1799. *
  1800. * \param[in] sequence_type_info
  1801. * \param[out] type_info
  1802. *
  1803. * \snippet{doc} snippets.dox OrtStatus Return Value
  1804. */
  1805. ORT_API2_STATUS(GetSequenceElementType, _In_ const OrtSequenceTypeInfo* sequence_type_info,
  1806. _Outptr_ OrtTypeInfo** type_info);
  1807. /// @}
  1808. /// \name OrtMapTypeInfo
  1809. /// @{
  1810. ORT_CLASS_RELEASE(MapTypeInfo);
  1811. /// @}
  1812. /// \name OrtSequenceTypeInfo
  1813. /// @{
  1814. ORT_CLASS_RELEASE(SequenceTypeInfo);
  1815. /// @}
  1816. /// \name OrtSession
  1817. /// @{
  1818. /** \brief End profiling and return filename of the profile data
  1819. *
  1820. * Profiling is turned on through OrtApi::EnableProfiling
  1821. *
  1822. * \param[in] session
  1823. * \param[in] allocator
  1824. * \param[out] out Null terminated string of the filename, allocated using `allocator`. Must be freed using `allocator`
  1825. *
  1826. * \snippet{doc} snippets.dox OrtStatus Return Value
  1827. */
  1828. ORT_API2_STATUS(SessionEndProfiling, _In_ OrtSession* session, _Inout_ OrtAllocator* allocator, _Outptr_ char** out);
  1829. /** \brief Get ::OrtModelMetadata from an ::OrtSession
  1830. *
  1831. * \param[in] session
  1832. * \param[out] out Newly created ::OrtModelMetadata. Must be freed using OrtApi::ReleaseModelMetadata
  1833. *
  1834. * \snippet{doc} snippets.dox OrtStatus Return Value
  1835. */
  1836. ORT_API2_STATUS(SessionGetModelMetadata, _In_ const OrtSession* session, _Outptr_ OrtModelMetadata** out);
  1837. /// @}
  1838. /// \name OrtModelMetadata
  1839. /// @{
  1840. /** \brief Get `producer name` from an ::OrtModelMetadata
  1841. *
  1842. * \param[in] model_metadata
  1843. * \param[in] allocator
  1844. * \param[out] value Set to a null terminated string allocated using `allocator`. Must be freed using `allocator`
  1845. *
  1846. * \snippet{doc} snippets.dox OrtStatus Return Value
  1847. */
  1848. ORT_API2_STATUS(ModelMetadataGetProducerName, _In_ const OrtModelMetadata* model_metadata,
  1849. _Inout_ OrtAllocator* allocator, _Outptr_ char** value);
  1850. /** \brief Get `graph name` from an ::OrtModelMetadata
  1851. *
  1852. * \param[in] model_metadata
  1853. * \param[in] allocator
  1854. * \param[out] value Set to a null terminated string allocated using `allocator`. Must be freed using `allocator`
  1855. *
  1856. * \snippet{doc} snippets.dox OrtStatus Return Value
  1857. */
  1858. ORT_API2_STATUS(ModelMetadataGetGraphName, _In_ const OrtModelMetadata* model_metadata,
  1859. _Inout_ OrtAllocator* allocator, _Outptr_ char** value);
  1860. /** \brief Get `domain` from an ::OrtModelMetadata
  1861. *
  1862. * \param[in] model_metadata
  1863. * \param[in] allocator
  1864. * \param[out] value Set to a null terminated string allocated using `allocator`. Must be freed using `allocator`
  1865. *
  1866. * \snippet{doc} snippets.dox OrtStatus Return Value
  1867. */
  1868. ORT_API2_STATUS(ModelMetadataGetDomain, _In_ const OrtModelMetadata* model_metadata, _Inout_ OrtAllocator* allocator,
  1869. _Outptr_ char** value);
  1870. /** \brief Get `description` from an ::OrtModelMetadata
  1871. *
  1872. * \param[in] model_metadata
  1873. * \param[in] allocator
  1874. * \param[out] value Set to a null terminated string allocated using `allocator`. Must be freed using `allocator`
  1875. *
  1876. * \snippet{doc} snippets.dox OrtStatus Return Value
  1877. */
  1878. ORT_API2_STATUS(ModelMetadataGetDescription, _In_ const OrtModelMetadata* model_metadata,
  1879. _Inout_ OrtAllocator* allocator, _Outptr_ char** value);
  1880. /** \brief Return data for a key in the custom metadata map in an ::OrtModelMetadata
  1881. *
  1882. * \param[in] model_metadata
  1883. * \param[in] allocator
  1884. * \param[in] key Null terminated string
  1885. * \param[out] value Set to a null terminated string allocated using `allocator`. Must be freed using `allocator`
  1886. * `value` will be set to nullptr if the given key is not found in the custom metadata map.
  1887. *
  1888. * \snippet{doc} snippets.dox OrtStatus Return Value
  1889. */
  1890. ORT_API2_STATUS(ModelMetadataLookupCustomMetadataMap, _In_ const OrtModelMetadata* model_metadata,
  1891. _Inout_ OrtAllocator* allocator, _In_ const char* key, _Outptr_result_maybenull_ char** value);
  1892. /** \brief Get version number from an ::OrtModelMetadata
  1893. *
  1894. * \param[in] model_metadata
  1895. * \param[out] value Set to the version number
  1896. *
  1897. * \snippet{doc} snippets.dox OrtStatus Return Value
  1898. */
  1899. ORT_API2_STATUS(ModelMetadataGetVersion, _In_ const OrtModelMetadata* model_metadata, _Out_ int64_t* value);
  1900. ORT_CLASS_RELEASE(ModelMetadata);
  1901. /// @}
  1902. /// \name OrtEnv
  1903. /// @{
  1904. /** \brief Create an OrtEnv
  1905. *
  1906. * Create an environment with global threadpools that will be shared across sessions.
  1907. * Use this in conjunction with OrtApi::DisablePerSessionThreads or else the session will use
  1908. * its own thread pools.
  1909. *
  1910. * \param[in] log_severity_level The log severity level.
  1911. * \param[in] logid The log identifier.
  1912. * \param[in] tp_options
  1913. * \param[out] out Returned newly created OrtEnv. Must be freed with OrtApi::ReleaseEnv
  1914. *
  1915. * \snippet{doc} snippets.dox OrtStatus Return Value
  1916. */
  1917. ORT_API2_STATUS(CreateEnvWithGlobalThreadPools, OrtLoggingLevel log_severity_level, _In_ const char* logid,
  1918. _In_ const OrtThreadingOptions* tp_options, _Outptr_ OrtEnv** out);
  1919. /// @}
  1920. /// \name OrtSessionOptions
  1921. /// @{
  1922. /** \brief Use global thread pool on a session
  1923. *
  1924. * Disable using per session thread pool and use the shared global threadpool.
  1925. * This should be used in conjunction with OrtApi::CreateEnvWithGlobalThreadPools.
  1926. *
  1927. * \param[in] options
  1928. *
  1929. * \snippet{doc} snippets.dox OrtStatus Return Value
  1930. */
  1931. ORT_API2_STATUS(DisablePerSessionThreads, _Inout_ OrtSessionOptions* options);
  1932. /// @}
  1933. /// \name OrtThreadingOptions
  1934. /// @{
  1935. /** \brief Create an ::OrtThreadingOptions
  1936. *
  1937. * \param[out] out Newly created ::OrtThreadingOptions. Must be freed with OrtApi::ReleaseThreadingOptions
  1938. * \snippet{doc} snippets.dox OrtStatus Return Value
  1939. */
  1940. ORT_API2_STATUS(CreateThreadingOptions, _Outptr_ OrtThreadingOptions** out);
  1941. ORT_CLASS_RELEASE(ThreadingOptions);
  1942. /// @}
  1943. /// \name OrtModelMetadata
  1944. /// @{
  1945. /**
  1946. *
  1947. * \param[in] model_metadata
  1948. * \param[in] allocator
  1949. * \param[out] keys Array of null terminated strings (array count = num_keys) allocated using `allocator`.
  1950. * The strings and the pointer array must be freed using `allocator`
  1951. * `keys` will be set to nullptr if the custom metadata map is empty.
  1952. * \param[out] num_keys Set to the number of elements in the `keys` array
  1953. *
  1954. * \snippet{doc} snippets.dox OrtStatus Return Value
  1955. */
  1956. ORT_API2_STATUS(ModelMetadataGetCustomMetadataMapKeys, _In_ const OrtModelMetadata* model_metadata,
  1957. _Inout_ OrtAllocator* allocator, _Outptr_result_buffer_maybenull_(*num_keys) char*** keys, _Out_ int64_t* num_keys);
  1958. /// @}
  1959. /// \name OrtSessionOptions
  1960. /// @{
  1961. /**
  1962. *
  1963. * Override symbolic dimensions (by specific name strings) with actual values
  1964. * if known at session initialization time to enable optimizations that can
  1965. * take advantage of fixed values (such as memory planning, etc)
  1966. *
  1967. */
  1968. ORT_API2_STATUS(AddFreeDimensionOverrideByName,
  1969. _Inout_ OrtSessionOptions* options, _In_ const char* dim_name,
  1970. _In_ int64_t dim_value);
  1971. /// @}
  1972. /// \name Misc
  1973. /// @{
  1974. /** \brief Get the names of all available providers
  1975. *
  1976. * \note The providers in the list are not guaranteed to be usable. They may fail to load due to missing system dependencies.
  1977. * 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.
  1978. *
  1979. * \param[out] out_ptr Set to a pointer to an array of null terminated strings of the available providers. The entries and the
  1980. * array itself must be freed using OrtApi::ReleaseAvailableProviders
  1981. * \param[out] provider_length Set to the number of entries in the `out_ptr` array
  1982. *
  1983. * \snippet{doc} snippets.dox OrtStatus Return Value
  1984. */
  1985. ORT_API2_STATUS(GetAvailableProviders, _Outptr_ char*** out_ptr, _Out_ int* provider_length);
  1986. /** \brief Release data from OrtApi::GetAvailableProviders. This API will never fail
  1987. * so you can rely on it in a noexcept code.
  1988. *
  1989. * \param[in] ptr The `out_ptr` result from OrtApi::GetAvailableProviders.
  1990. * \param[in] providers_length The `provider_length` result from OrtApi::GetAvailableProviders
  1991. *
  1992. * \snippet{doc} snippets.dox OrtStatus Return Value
  1993. */
  1994. ORT_API2_STATUS(ReleaseAvailableProviders, _In_ char** ptr,
  1995. _In_ int providers_length);
  1996. /// @}
  1997. /// \name OrtValue
  1998. /// @{
  1999. /** \brief Get the length of a single string in a string tensor
  2000. *
  2001. * \param[in] value A string tensor
  2002. * \param[in] index Index of the string in the tensor
  2003. * \param[out] out Set to number of bytes of the string element
  2004. *
  2005. * \snippet{doc} snippets.dox OrtStatus Return Value
  2006. */
  2007. ORT_API2_STATUS(GetStringTensorElementLength, _In_ const OrtValue* value, size_t index, _Out_ size_t* out);
  2008. /** \brief Get a single string from a string tensor
  2009. *
  2010. * \param[in] value A string tensor
  2011. * \param[in] s_len Number of bytes in the `s` buffer. Must match the value returned by OrtApi::GetStringTensorElementLength.
  2012. * \param[in] index Index of the string in the tensor
  2013. * \param[out] s The string element contents in UTF-8 encoding. The string is NOT null-terminated.
  2014. *
  2015. * \snippet{doc} snippets.dox OrtStatus Return Value
  2016. */
  2017. ORT_API2_STATUS(GetStringTensorElement, _In_ const OrtValue* value, size_t s_len, size_t index, _Out_writes_bytes_all_(s_len) void* s);
  2018. /** \brief Set a single string in a string tensor
  2019. *
  2020. * \param[in] value A string tensor
  2021. * \param[in] s A null terminated UTF-8 encoded string
  2022. * \param[in] index Index of the string in the tensor to set
  2023. *
  2024. * \snippet{doc} snippets.dox OrtStatus Return Value
  2025. */
  2026. ORT_API2_STATUS(FillStringTensorElement, _Inout_ OrtValue* value, _In_ const char* s, size_t index);
  2027. /// @}
  2028. /// \name OrtSessionOptions
  2029. /// @{
  2030. /** \brief Set a session configuration entry as a pair of strings
  2031. *
  2032. * If a configuration with same key exists, this will overwrite the configuration with the given config_value.
  2033. *
  2034. * The config_key and the format of config_value are defined in onnxruntime_session_options_config_keys.h
  2035. *
  2036. * \param[in] options
  2037. * \param[in] config_key A null terminated string representation of the config key
  2038. * \param[in] config_value A null terminated string representation of the config value
  2039. *
  2040. * \snippet{doc} snippets.dox OrtStatus Return Value
  2041. */
  2042. ORT_API2_STATUS(AddSessionConfigEntry, _Inout_ OrtSessionOptions* options,
  2043. _In_z_ const char* config_key, _In_z_ const char* config_value);
  2044. /// @}
  2045. /// \name OrtAllocator
  2046. /// @{
  2047. /** \brief Create an allocator for an ::OrtSession following an ::OrtMemoryInfo
  2048. *
  2049. * \param[in] session
  2050. * \param[in] mem_info valid ::OrtMemoryInfo instance
  2051. * \param[out] out Newly created ::OrtAllocator. Must be freed with OrtApi::ReleaseAllocator
  2052. *
  2053. * \snippet{doc} snippets.dox OrtStatus Return Value
  2054. */
  2055. ORT_API2_STATUS(CreateAllocator, _In_ const OrtSession* session, _In_ const OrtMemoryInfo* mem_info,
  2056. _Outptr_ OrtAllocator** out);
  2057. /** \brief Release an ::OrtAllocator obtained from OrtApi::CreateAllocator
  2058. */
  2059. ORT_CLASS_RELEASE(Allocator);
  2060. /// @}
  2061. /// \name OrtSession
  2062. /// @{
  2063. /** \brief Run a model using Io Bindings for the inputs & outputs
  2064. *
  2065. * \see OrtApi::Run
  2066. *
  2067. * \param[in] session
  2068. * \param[in] run_options
  2069. * \param[in] binding_ptr
  2070. *
  2071. * \snippet{doc} snippets.dox OrtStatus Return Value
  2072. */
  2073. ORT_API2_STATUS(RunWithBinding, _Inout_ OrtSession* session, _In_ const OrtRunOptions* run_options, _In_ const OrtIoBinding* binding_ptr);
  2074. /** \brief Create an ::OrtIoBinding instance
  2075. *
  2076. * An IoBinding object allows one to bind pre-allocated ::OrtValue%s to input names.
  2077. * Thus if you want to use a raw on device buffer as input or output you can avoid
  2078. * extra copy during runtime.
  2079. *
  2080. * \param[in] session
  2081. * \param[out] out Newly created ::OrtIoBinding. Must be freed with OrtApi::ReleaseIoBinding
  2082. *
  2083. * \snippet{doc} snippets.dox OrtStatus Return Value
  2084. */
  2085. ORT_API2_STATUS(CreateIoBinding, _Inout_ OrtSession* session, _Outptr_ OrtIoBinding** out);
  2086. /// @}
  2087. /// \name OrtIoBinding
  2088. /// @{
  2089. /** \brief Release an ::OrtIoBinding obtained from OrtApi::CreateIoBinding
  2090. */
  2091. ORT_CLASS_RELEASE(IoBinding);
  2092. /** \brief Bind an ::OrtValue to an ::OrtIoBinding input
  2093. *
  2094. * When using OrtApi::RunWithBinding this value is used for the named input
  2095. *
  2096. * \param[in] binding_ptr
  2097. * \param[in] name Name for the model input
  2098. * \param[in] val_ptr ::OrtValue of Tensor type.
  2099. *
  2100. * \snippet{doc} snippets.dox OrtStatus Return Value
  2101. */
  2102. ORT_API2_STATUS(BindInput, _Inout_ OrtIoBinding* binding_ptr, _In_ const char* name, _In_ const OrtValue* val_ptr);
  2103. /** \brief Bind an ::OrtValue to an ::OrtIoBinding output
  2104. *
  2105. * When using OrtApi::RunWithBinding this value is used for the named output
  2106. *
  2107. * \param[in] binding_ptr
  2108. * \param[in] name Null terminated string of the model output name
  2109. * \param[in] val_ptr ::OrtValue of Tensor type.
  2110. *
  2111. * \snippet{doc} snippets.dox OrtStatus Return Value
  2112. */
  2113. ORT_API2_STATUS(BindOutput, _Inout_ OrtIoBinding* binding_ptr, _In_ const char* name, _In_ const OrtValue* val_ptr);
  2114. /** \brief Bind an ::OrtIoBinding output to a device
  2115. *
  2116. * Binds the ::OrtValue to a device which is specified by ::OrtMemoryInfo.
  2117. * You can either create an instance of ::OrtMemoryInfo with a device id or obtain one from the allocator that you have created/are using
  2118. * This is useful when one or more outputs have dynamic shapes and, it is hard to pre-allocate and bind a chunk of
  2119. * memory within ::OrtValue ahead of time.
  2120. *
  2121. * \see OrtApi::RunWithBinding
  2122. *
  2123. * \param[in] binding_ptr
  2124. * \param[in] name Null terminated string of the device name
  2125. * \param[in] mem_info_ptr
  2126. *
  2127. * \snippet{doc} snippets.dox OrtStatus Return Value
  2128. */
  2129. ORT_API2_STATUS(BindOutputToDevice, _Inout_ OrtIoBinding* binding_ptr, _In_ const char* name, _In_ const OrtMemoryInfo* mem_info_ptr);
  2130. /** \brief Get the names of an ::OrtIoBinding's outputs
  2131. *
  2132. * Returns the names of the outputs in the order they were bound. This is useful after running the model
  2133. * with bound outputs because the returned names are in order in which output ::OrtValue are returned. This is useful if
  2134. * the order of outputs and their names is not known.
  2135. *
  2136. * \param[in] binding_ptr
  2137. * \param[in] allocator Allocator used to allocate continuous buffers for output strings and lengths.
  2138. * \param[out] buffer Returns an array of non-null terminated UTF-8 strings. The number of strings stored is returned in the count parameter.
  2139. * This buffer is allocated using `allocator` and must be freed using it.
  2140. * \param[out] lengths Returns an array of `count` lengths of the strings returned in `buffer`
  2141. * This buffer is allocated using `allocator` and must be freed using it.
  2142. * \param[out] count Number of strings returned. If `binding_ptr` has no bound outputs, zero is returned,
  2143. * no memory allocation is performed and buffer and lengths are set to nullptr.
  2144. *
  2145. * \snippet{doc} snippets.dox OrtStatus Return Value
  2146. */
  2147. ORT_API2_STATUS(GetBoundOutputNames, _In_ const OrtIoBinding* binding_ptr, _In_ OrtAllocator* allocator,
  2148. _Out_ char** buffer, _Out_writes_all_(count) size_t** lengths, _Out_ size_t* count);
  2149. /** \brief Get the output ::OrtValue objects from an ::OrtIoBinding
  2150. *
  2151. * Returns an array of pointers to individually allocated ::OrtValue%s that contain results of a model execution with OrtApi::RunWithBinding
  2152. * The array contains the same number of ::OrtValue%s and they are in the same order as they were bound with OrtApi::BindOutput
  2153. * or OrtApi::BindOutputToDevice.
  2154. *
  2155. * The returned ::OrtValue%s must be released using OrtApi::ReleaseValue after they are no longer needed.
  2156. * The array is allocated using the specified instance of the allocator and must be freed using the same allocator after
  2157. * all the ::OrtValue%s contained therein are individually released.
  2158. *
  2159. * \param[in] binding_ptr
  2160. * \param[in] allocator Allocator used to allocate output array
  2161. * \param[out] output Set to the allocated array of allocated ::OrtValue outputs. Set to nullptr if there are 0 outputs.
  2162. * \param[out] output_count Set to number of ::OrtValue%s returned
  2163. *
  2164. * \snippet{doc} snippets.dox OrtStatus Return Value
  2165. */
  2166. ORT_API2_STATUS(GetBoundOutputValues, _In_ const OrtIoBinding* binding_ptr, _In_ OrtAllocator* allocator,
  2167. _Out_writes_all_(output_count) OrtValue*** output, _Out_ size_t* output_count);
  2168. /** \brief Clears any previously set Inputs for an ::OrtIoBinding
  2169. */
  2170. void(ORT_API_CALL* ClearBoundInputs)(_Inout_ OrtIoBinding* binding_ptr) NO_EXCEPTION ORT_ALL_ARGS_NONNULL;
  2171. /** \brief Clears any previously set Outputs for an ::OrtIoBinding
  2172. */
  2173. void(ORT_API_CALL* ClearBoundOutputs)(_Inout_ OrtIoBinding* binding_ptr) NO_EXCEPTION ORT_ALL_ARGS_NONNULL;
  2174. /// @}
  2175. /// \name OrtValue
  2176. /// @{
  2177. /** \brief Direct memory access to a specified tensor element
  2178. *
  2179. * For example, given a tensor with shape of [3,224,224], a pointer to the element at location [2,150,128] can be retrieved
  2180. *
  2181. * This function only works for numeric type tensors (No strings, etc).
  2182. * This is a no-copy method whose returned pointer is valid until the passed in ::OrtValue is free'd.
  2183. *
  2184. * \param[in] value
  2185. * \param[in] location_values Pointer to an array of index values that specify an element's location relative to its shape
  2186. * \param[in] location_values_count Number of elements in location_values. Must match the number of elements in the tensor's shape.
  2187. * \param[out] out Set to a pointer to the element specified
  2188. *
  2189. * \snippet{doc} snippets.dox OrtStatus Return Value
  2190. */
  2191. ORT_API2_STATUS(TensorAt, _Inout_ OrtValue* value, const int64_t* location_values, size_t location_values_count, _Outptr_ void** out);
  2192. /// @}
  2193. /// \name OrtEnv
  2194. /// @{
  2195. /** \brief Create an allocator and register it with the ::OrtEnv
  2196. *
  2197. * Enables sharing the allocator between multiple sessions that use the same env instance.
  2198. * Lifetime of the created allocator will be valid for the duration of the environment.
  2199. * Returns an error if an allocator with the same ::OrtMemoryInfo is already registered.
  2200. *
  2201. * See https://onnxruntime.ai/docs/get-started/with-c.html for details.
  2202. *
  2203. * \param[in] env ::OrtEnv instance
  2204. * \param[in] mem_info
  2205. * \param[in] arena_cfg Pass nullptr for defaults
  2206. *
  2207. * \snippet{doc} snippets.dox OrtStatus Return Value
  2208. */
  2209. ORT_API2_STATUS(CreateAndRegisterAllocator, _Inout_ OrtEnv* env, _In_ const OrtMemoryInfo* mem_info,
  2210. _In_ const OrtArenaCfg* arena_cfg);
  2211. /** \brief Set language projection
  2212. *
  2213. * Set the language projection for collecting telemetry data when Env is created.
  2214. *
  2215. * The default is ORT_PROJECTION_C, which means it will classify the language not in the list to C also.
  2216. *
  2217. * \param[in] ort_env
  2218. * \param[in] projection
  2219. *
  2220. * \snippet{doc} snippets.dox OrtStatus Return Value
  2221. */
  2222. ORT_API2_STATUS(SetLanguageProjection, _In_ const OrtEnv* ort_env, _In_ OrtLanguageProjection projection);
  2223. /// @}
  2224. /// \name OrtSession
  2225. /// @{
  2226. /** \brief Return the time that profiling was started
  2227. *
  2228. * \note The timer precision varies per platform. On Windows and MacOS, the precision will be ~100ns
  2229. *
  2230. * \param[in] session
  2231. * \param[out] out nanoseconds of profiling's start time
  2232. *
  2233. * \snippet{doc} snippets.dox OrtStatus Return Value
  2234. */
  2235. ORT_API2_STATUS(SessionGetProfilingStartTimeNs, _In_ const OrtSession* session, _Outptr_ uint64_t* out);
  2236. /// @}
  2237. /// \name OrtThreadingOptions
  2238. /// @{
  2239. /** \brief Set global intra-op thread count
  2240. *
  2241. * This configures the global thread pool options to be used in the call to OrtApi::CreateEnvWithGlobalThreadPools
  2242. *
  2243. * \param[in] tp_options
  2244. * \param[in] intra_op_num_threads Number of threads, special values:<br>
  2245. * 0 = Use default thread count<br>
  2246. * 1 = The invoking thread will be used; no threads will be created in the thread pool.
  2247. *
  2248. * \snippet{doc} snippets.dox OrtStatus Return Value
  2249. */
  2250. ORT_API2_STATUS(SetGlobalIntraOpNumThreads, _Inout_ OrtThreadingOptions* tp_options, int intra_op_num_threads);
  2251. /** \brief Set global inter-op thread count
  2252. *
  2253. * This configures the global thread pool options to be used in the call to OrtApi::CreateEnvWithGlobalThreadPools
  2254. *
  2255. * \param[in] tp_options
  2256. * \param[in] inter_op_num_threads Number of threads, special values:<br>
  2257. * 0 = Use default thread count<br>
  2258. * 1 = The invoking thread will be used; no threads will be created in the thread pool.
  2259. *
  2260. * \snippet{doc} snippets.dox OrtStatus Return Value
  2261. */
  2262. ORT_API2_STATUS(SetGlobalInterOpNumThreads, _Inout_ OrtThreadingOptions* tp_options, int inter_op_num_threads);
  2263. /** \brief Set global spin control options
  2264. *
  2265. * This will configure the global thread pool options to be used in the call to OrtApi::CreateEnvWithGlobalThreadPools.
  2266. * Allow spinning of thread pools when their queues are empty. This will set the value for both
  2267. * inter_op and intra_op threadpools.
  2268. *
  2269. * \param[in] tp_options
  2270. * \param[in] allow_spinning Valid values are 0 or 1.<br>
  2271. * 0 = It won't spin (recommended if CPU usage is high)<br>
  2272. * 1 = Threadpool will spin to wait for queue to become non-empty
  2273. *
  2274. * \snippet{doc} snippets.dox OrtStatus Return Value
  2275. */
  2276. ORT_API2_STATUS(SetGlobalSpinControl, _Inout_ OrtThreadingOptions* tp_options, int allow_spinning);
  2277. /// @}
  2278. /// \name OrtSessionOptions
  2279. /// @{
  2280. /** \brief Add a pre-allocated initializer to a session
  2281. *
  2282. * If a model contains an initializer with a name that is same as the name passed to this call,
  2283. * ORT will use this initializer instance instead of deserializing one from the model file. This
  2284. * is useful when you want to share the same initializer across sessions.
  2285. *
  2286. * \param[in] options
  2287. * \param[in] name Null terminated string of the initializer name
  2288. * \param[in] val ::OrtValue containing the initializer. Its lifetime and the underlying initializer buffer must be
  2289. * managed by the user (created using the OrtApi::CreateTensorWithDataAsOrtValue) and it must outlive the session object
  2290. * to which it is added.
  2291. *
  2292. * \snippet{doc} snippets.dox OrtStatus Return Value
  2293. */
  2294. ORT_API2_STATUS(AddInitializer, _Inout_ OrtSessionOptions* options, _In_z_ const char* name,
  2295. _In_ const OrtValue* val);
  2296. /// @}
  2297. /// \name OrtEnv
  2298. /// @{
  2299. /**
  2300. * Create a custom environment with global threadpools and logger that will be shared across sessions.
  2301. * Use this in conjunction with OrtApi::DisablePerSessionThreads or else the session will use
  2302. * its own thread pools.
  2303. *
  2304. * \param[in] logging_function A pointer to a logging function.
  2305. * \param[in] logger_param A pointer to arbitrary data passed as the ::OrtLoggingFunction `param` parameter to
  2306. * `logging_function`.
  2307. * \param[in] log_severity_level The log severity level.
  2308. * \param[in] logid The log identifier.
  2309. * \param[in] tp_options
  2310. * \param[out] out Newly created OrtEnv. Must be freed with OrtApi::ReleaseEnv
  2311. *
  2312. * \snippet{doc} snippets.dox OrtStatus Return Value
  2313. */
  2314. ORT_API2_STATUS(CreateEnvWithCustomLoggerAndGlobalThreadPools, OrtLoggingFunction logging_function, _In_opt_ void* logger_param, OrtLoggingLevel log_severity_level,
  2315. _In_ const char* logid, _In_ const struct OrtThreadingOptions* tp_options, _Outptr_ OrtEnv** out);
  2316. /// @}
  2317. /// \name OrtSessionOptions
  2318. /// @{
  2319. /** \brief Append CUDA provider to session options
  2320. *
  2321. * 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.
  2322. *
  2323. * \param[in] options
  2324. * \param[in] cuda_options
  2325. *
  2326. * \snippet{doc} snippets.dox OrtStatus Return Value
  2327. */
  2328. ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_CUDA,
  2329. _In_ OrtSessionOptions* options, _In_ const OrtCUDAProviderOptions* cuda_options);
  2330. /** \brief Append ROCM execution provider to the session options
  2331. *
  2332. * 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.
  2333. *
  2334. * \param[in] options
  2335. * \param[in] rocm_options
  2336. *
  2337. * \snippet{doc} snippets.dox OrtStatus Return Value
  2338. */
  2339. ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_ROCM,
  2340. _In_ OrtSessionOptions* options, _In_ const OrtROCMProviderOptions* rocm_options);
  2341. /** \brief Append OpenVINO execution provider to the session options
  2342. *
  2343. * 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.
  2344. *
  2345. * \param[in] options
  2346. * \param[in] provider_options
  2347. *
  2348. * \snippet{doc} snippets.dox OrtStatus Return Value
  2349. */
  2350. ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_OpenVINO,
  2351. _In_ OrtSessionOptions* options, _In_ const OrtOpenVINOProviderOptions* provider_options);
  2352. /// @}
  2353. /// \name OrtThreadingOptions
  2354. /// @{
  2355. /** \brief Set threading flush-to-zero and denormal-as-zero
  2356. *
  2357. * Sets global thread pool options to be used in the call to OrtApi::CreateEnvWithGlobalThreadPools.
  2358. * Flush-to-zero and denormal-as-zero are applied to threads in both intra and inter global thread pool.
  2359. * \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.
  2360. *
  2361. * \param[in] tp_options
  2362. *
  2363. * \snippet{doc} snippets.dox OrtStatus Return Value
  2364. */
  2365. ORT_API2_STATUS(SetGlobalDenormalAsZero, _Inout_ OrtThreadingOptions* tp_options);
  2366. /// @}
  2367. /// \name OrtArenaCfg
  2368. /// @{
  2369. /** \deprecated Use OrtApi::CreateArenaCfgV2
  2370. *
  2371. * This will create the configuration of an arena that can eventually be used to define an arena based allocator's behavior
  2372. *
  2373. * \param[in] max_mem Use 0 to allow ORT to choose the default
  2374. * \param[in] arena_extend_strategy Use -1 to allow ORT to choose the default, 0 = kNextPowerOfTwo, 1 = kSameAsRequested
  2375. * \param[in] initial_chunk_size_bytes Use -1 to allow ORT to choose the default
  2376. * \param[in] max_dead_bytes_per_chunk Use -1 to allow ORT to choose the default
  2377. * \param[in] out A pointer to an OrtArenaCfg instance
  2378. *
  2379. * \snippet{doc} snippets.dox OrtStatus Return Value
  2380. */
  2381. ORT_API2_STATUS(CreateArenaCfg, _In_ size_t max_mem, int arena_extend_strategy, int initial_chunk_size_bytes,
  2382. int max_dead_bytes_per_chunk, _Outptr_ OrtArenaCfg** out);
  2383. ORT_CLASS_RELEASE(ArenaCfg);
  2384. /// @}
  2385. /// \name OrtModelMetadata
  2386. /// @{
  2387. /**
  2388. * Use this to obtain the description of the graph present in the model
  2389. * (doc_string field of the GraphProto message within the ModelProto message).
  2390. * If it doesn't exist, an empty string will be returned.
  2391. *
  2392. * \param[in] model_metadata An instance of ::OrtModelMetadata
  2393. * \param[in] allocator Allocator used to allocate the string that will be returned back
  2394. * \param[out] value Set to a null terminated string allocated using `allocator`. The caller is responsible for freeing it using `allocator`
  2395. *
  2396. * \snippet{doc} snippets.dox OrtStatus Return Value
  2397. */
  2398. ORT_API2_STATUS(ModelMetadataGetGraphDescription, _In_ const OrtModelMetadata* model_metadata,
  2399. _Inout_ OrtAllocator* allocator, _Outptr_ char** value);
  2400. /// @}
  2401. /// \name OrtSessionOptions
  2402. /// @{
  2403. /** \brief Append TensorRT provider to session options
  2404. *
  2405. * 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.
  2406. *
  2407. * \param[in] options
  2408. * \param[in] tensorrt_options
  2409. *
  2410. * \snippet{doc} snippets.dox OrtStatus Return Value
  2411. */
  2412. ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_TensorRT,
  2413. _In_ OrtSessionOptions* options, _In_ const OrtTensorRTProviderOptions* tensorrt_options);
  2414. /// @}
  2415. /// \name Misc
  2416. /// @{
  2417. /** \brief Set current GPU device ID
  2418. *
  2419. * Set the current device id of the GPU execution provider (CUDA/tensorrt/rocm). The device id should be less
  2420. * than the total number of devices available. This is only useful when multiple-GPUs are installed and it is
  2421. * required to restrict execution to a single GPU.
  2422. *
  2423. * \param[in] device_id
  2424. *
  2425. * \snippet{doc} snippets.dox OrtStatus Return Value
  2426. */
  2427. ORT_API2_STATUS(SetCurrentGpuDeviceId, _In_ int device_id);
  2428. /** \brief Get current GPU device ID
  2429. *
  2430. * Get the current device id of the GPU execution provider (CUDA/tensorrt/rocm).
  2431. *
  2432. * \see OrtApi::SetCurrentGpuDeviceId
  2433. *
  2434. * \param[out] device_id
  2435. *
  2436. * \snippet{doc} snippets.dox OrtStatus Return Value
  2437. */
  2438. ORT_API2_STATUS(GetCurrentGpuDeviceId, _In_ int* device_id);
  2439. /// @}
  2440. /// \name OrtKernelInfo
  2441. /// Custom operator APIs.
  2442. /// @{
  2443. /** \brief Fetch an array of int64_t values stored as an attribute in the graph node
  2444. *
  2445. *
  2446. * If `out` is nullptr, the value of `size` is set to the true size of the attribute
  2447. * array's size, and a success status is returned.
  2448. *
  2449. * If the `size` parameter is greater than or equal to the actual attribute array's size,
  2450. * the value of `size` is set to the true size of the attribute array's size,
  2451. * the provided memory is filled with the attribute's contents,
  2452. * and a success status is returned.
  2453. *
  2454. * If the `size` parameter is less than the actual attribute array's size and `out`
  2455. * is not nullptr, the value of `size` is set to the true size of the attribute array's size
  2456. * and a failure status is returned.)
  2457. *
  2458. * \param[in] info instance
  2459. * \param[in] name name of the attribute to be parsed
  2460. * \param[out] out pointer to memory where the attribute's contents are to be stored
  2461. * \param[in, out] size actual size of attribute array
  2462. *
  2463. * \snippet{doc} snippets.dox OrtStatus Return Value
  2464. */
  2465. ORT_API2_STATUS(KernelInfoGetAttributeArray_float, _In_ const OrtKernelInfo* info, _In_ const char* name,
  2466. _Out_ float* out, _Inout_ size_t* size);
  2467. /** \brief Fetch an array of int64_t values stored as an attribute in the graph node
  2468. *
  2469. * If `out` is nullptr, the value of `size` is set to the true size of the attribute
  2470. * array's size, and a success status is returned.
  2471. *
  2472. * If the `size` parameter is greater than or equal to the actual attribute array's size,
  2473. * the value of `size` is set to the true size of the attribute array's size,
  2474. * the provided memory is filled with the attribute's contents,
  2475. * and a success status is returned.
  2476. *
  2477. * If the `size` parameter is less than the actual attribute array's size and `out`
  2478. * is not nullptr, the value of `size` is set to the true size of the attribute array's size
  2479. * and a failure status is returned.)
  2480. *
  2481. * \param[in] info instance
  2482. * \param[in] name name of the attribute to be parsed
  2483. * \param[out] out pointer to memory where the attribute's contents are to be stored
  2484. * \param[in, out] size actual size of attribute array
  2485. *
  2486. * \snippet{doc} snippets.dox OrtStatus Return Value
  2487. */
  2488. ORT_API2_STATUS(KernelInfoGetAttributeArray_int64, _In_ const OrtKernelInfo* info, _In_ const char* name,
  2489. _Out_ int64_t* out, _Inout_ size_t* size);
  2490. /// @}
  2491. /// \name OrtArenaCfg
  2492. /// @{
  2493. /** \brief Create an ::OrtArenaCfg
  2494. *
  2495. * Create the configuration of an arena that can eventually be used to define an arena based allocator's behavior.
  2496. *
  2497. * Supported keys are (See https://onnxruntime.ai/docs/get-started/with-c.html for details on what the
  2498. * following parameters mean and how to choose these values.):
  2499. * "max_mem": Maximum memory that can be allocated by the arena based allocator.
  2500. * Use 0 for ORT to pick the best value. Default is 0.
  2501. * "arena_extend_strategy": 0 = kNextPowerOfTwo, 1 = kSameAsRequested.
  2502. * Use -1 to allow ORT to choose the default.
  2503. * "initial_chunk_size_bytes": (Possible) Size of the first allocation in the arena.
  2504. * Only relevant if arena strategy is `kNextPowerOfTwo`. Use -1 to allow ORT to choose the default.
  2505. * Ultimately, the first allocation size is determined by the allocation memory request.
  2506. * "max_dead_bytes_per_chunk": Threshold of unused memory in an allocated chunk of arena memory after
  2507. * crossing which the current chunk is chunked into 2.
  2508. * "initial_growth_chunk_size_bytes": (Possible) Size of the second allocation in the arena.
  2509. * Only relevant if arena strategy is `kNextPowerOfTwo`. Use -1 to allow ORT to choose the default.
  2510. * "max_power_of_two_extend_bytes": The maximum enxtend size if arena strategy is `kNextPowerOfTwo`.
  2511. * It is not an allocation limit, it is only a limit for extention when requested byte is less than the limit.
  2512. * When requested bytes is more than the limit, allocator will still return as requested.
  2513. * Use -1 to allow ORT to choose the default 1GB for max_power_of_two_extend_bytes.
  2514. * Ultimately, the allocation size is determined by the allocation memory request.
  2515. * Further allocation sizes are governed by the arena extend strategy.
  2516. *
  2517. * \param[in] arena_config_keys Keys to configure the arena
  2518. * \param[in] arena_config_values Values to configure the arena
  2519. * \param[in] num_keys Number of keys in `arena_config_keys` and `arena_config_values`
  2520. * \param[out] out Newly created ::OrtArenaCfg. Must be freed with OrtApi::ReleaseArenaCfg
  2521. *
  2522. * \snippet{doc} snippets.dox OrtStatus Return Value
  2523. */
  2524. ORT_API2_STATUS(CreateArenaCfgV2, _In_reads_(num_keys) const char* const* arena_config_keys,
  2525. _In_reads_(num_keys) const size_t* arena_config_values, _In_ size_t num_keys,
  2526. _Outptr_ OrtArenaCfg** out);
  2527. /// @}
  2528. /// \name OrtRunOptions
  2529. /// @{
  2530. /** \brief Set a single run configuration entry as a pair of strings
  2531. *
  2532. * If a configuration with same key exists, this will overwrite the configuration with the given config_value
  2533. *
  2534. * The config_key and the format of config_value are defined in onnxruntime_run_options_config_keys.h
  2535. *
  2536. * \param[in] options
  2537. * \param[in] config_key A null terminated string representation of the config key
  2538. * \param[in] config_value A null terminated string representation of the config value
  2539. *
  2540. * \snippet{doc} snippets.dox OrtStatus Return Value
  2541. */
  2542. ORT_API2_STATUS(AddRunConfigEntry, _Inout_ OrtRunOptions* options,
  2543. _In_z_ const char* config_key, _In_z_ const char* config_value);
  2544. /// @}
  2545. /// \name OrtPrepackedWeightsContainer
  2546. /// @{
  2547. /** \brief Create an ::OrtPrepackedWeightsContainer
  2548. *
  2549. * This container will hold pre-packed buffers of shared initializers for sharing between sessions
  2550. * (i.e.) if there are shared initializers that can be shared between sessions, the pre-packed buffers
  2551. * of these (if any) may possibly be shared to provide memory footprint savings. Pass this container
  2552. * to sessions that you would like to share pre-packed buffers of shared initializers at session
  2553. * creation time.
  2554. *
  2555. * \param[out] out Newly created ::OrtPrepackedWeightsContainer. Must be freed with OrtApi::ReleasePrepackedWeightsContainer
  2556. *
  2557. * \snippet{doc} snippets.dox OrtStatus Return Value
  2558. */
  2559. ORT_API2_STATUS(CreatePrepackedWeightsContainer, _Outptr_ OrtPrepackedWeightsContainer** out);
  2560. /** \brief Release OrtPrepackedWeightsContainer instance
  2561. *
  2562. * \note instance must not be released until the sessions using it are released
  2563. */
  2564. ORT_CLASS_RELEASE(PrepackedWeightsContainer);
  2565. /// @}
  2566. /// \name OrtSession
  2567. /// @{
  2568. /** \brief Create session with prepacked weights container
  2569. *
  2570. * Same functionality offered by OrtApi::CreateSession except that a container that contains
  2571. * pre-packed weights' buffers is written into/read from by the created session.
  2572. * This is useful when used in conjunction with OrtApi::AddInitializer which injects
  2573. * shared initializer info into sessions. Wherever possible, the pre-packed versions of these
  2574. * shared initializers are cached in this container so that multiple sessions can just re-use
  2575. * these instead of duplicating these in memory.
  2576. *
  2577. * \param[in] env OrtEnv instance instance
  2578. * \param[in] model_path Null terminated string of the path (wchar on Windows, char otherwise)
  2579. * \param[in] options
  2580. * \param[in] prepacked_weights_container
  2581. * \param[out] out Newly created ::OrtSession. Must be freed with OrtApi::ReleaseSession
  2582. *
  2583. * \snippet{doc} snippets.dox OrtStatus Return Value
  2584. */
  2585. ORT_API2_STATUS(CreateSessionWithPrepackedWeightsContainer, _In_ const OrtEnv* env, _In_ const ORTCHAR_T* model_path,
  2586. _In_ const OrtSessionOptions* options, _Inout_ OrtPrepackedWeightsContainer* prepacked_weights_container,
  2587. _Outptr_ OrtSession** out);
  2588. /** \brief Create session from memory with prepacked weights container
  2589. *
  2590. * Same functionality offered by OrtApi::CreateSessionFromArray except that a container that contains
  2591. * pre-packed weights' buffers is written into/read from by the created session.
  2592. * This is useful when used in conjunction with OrtApi::AddInitializer which injects
  2593. * shared initializer info into sessions. Wherever possible, the pre-packed versions of these
  2594. * shared initializers are cached in this container so that multiple sessions can just re-use
  2595. * these instead of duplicating these in memory.
  2596. *
  2597. * \param[in] env
  2598. * \param[in] model_data Array of bytes holding the model
  2599. * \param[in] model_data_length Number of bytes in `model_data_model`
  2600. * \param[in] options
  2601. * \param[in] prepacked_weights_container
  2602. * \param[out] out Newly created ::OrtSession. Must be freed with OrtApi::ReleaseSession
  2603. *
  2604. * \snippet{doc} snippets.dox OrtStatus Return Value
  2605. */
  2606. ORT_API2_STATUS(CreateSessionFromArrayWithPrepackedWeightsContainer, _In_ const OrtEnv* env,
  2607. _In_ const void* model_data, size_t model_data_length,
  2608. _In_ const OrtSessionOptions* options, _Inout_ OrtPrepackedWeightsContainer* prepacked_weights_container,
  2609. _Outptr_ OrtSession** out);
  2610. /// @}
  2611. /// \name OrtSessionOptions
  2612. /// @{
  2613. /** \brief Append TensorRT execution provider to the session options
  2614. *
  2615. * If TensorRT is not available (due to a non TensorRT enabled build), this function will return failure.
  2616. *
  2617. * This is slightly different from OrtApi::SessionOptionsAppendExecutionProvider_TensorRT, it takes an
  2618. * ::OrtTensorRTProviderOptions which is publicly defined. This takes an opaque ::OrtTensorRTProviderOptionsV2
  2619. * which must be created with OrtApi::CreateTensorRTProviderOptions.
  2620. *
  2621. * For OrtApi::SessionOptionsAppendExecutionProvider_TensorRT, the user needs to instantiate ::OrtTensorRTProviderOptions
  2622. * as well as allocate/release buffers for some members of ::OrtTensorRTProviderOptions.
  2623. * Here, OrtApi::CreateTensorRTProviderOptions and Ortapi::ReleaseTensorRTProviderOptions will do the memory management for you.
  2624. *
  2625. * \param[in] options
  2626. * \param[in] tensorrt_options
  2627. *
  2628. * \snippet{doc} snippets.dox OrtStatus Return Value
  2629. */
  2630. ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_TensorRT_V2,
  2631. _In_ OrtSessionOptions* options, _In_ const OrtTensorRTProviderOptionsV2* tensorrt_options);
  2632. /// @}
  2633. /// \name OrtTensorRTProviderOptionsV2
  2634. /// @{
  2635. /** \brief Create an OrtTensorRTProviderOptionsV2
  2636. *
  2637. * \param[out] out Newly created ::OrtTensorRTProviderOptionsV2. Must be released with OrtApi::ReleaseTensorRTProviderOptions
  2638. *
  2639. * \snippet{doc} snippets.dox OrtStatus Return Value
  2640. */
  2641. ORT_API2_STATUS(CreateTensorRTProviderOptions, _Outptr_ OrtTensorRTProviderOptionsV2** out);
  2642. /** \brief Set options in a TensorRT Execution Provider.
  2643. *
  2644. * Please refer to https://onnxruntime.ai/docs/execution-providers/TensorRT-ExecutionProvider.html#cc
  2645. * to know the available keys and values. Key should be in null terminated string format of the member of ::OrtTensorRTProviderOptionsV2
  2646. * and value should be its related range. Recreates the options and only sets the supplied values.
  2647. *
  2648. * For example, key="trt_max_workspace_size" and value="2147483648"
  2649. *
  2650. * \param[in] tensorrt_options
  2651. * \param[in] provider_options_keys Array of UTF-8 null-terminated string for provider options keys
  2652. * \param[in] provider_options_values Array of UTF-8 null-terminated string for provider options values
  2653. * \param[in] num_keys Number of elements in the `provider_option_keys` and `provider_options_values` arrays
  2654. *
  2655. * \snippet{doc} snippets.dox OrtStatus Return Value
  2656. */
  2657. ORT_API2_STATUS(UpdateTensorRTProviderOptions, _Inout_ OrtTensorRTProviderOptionsV2* tensorrt_options,
  2658. _In_reads_(num_keys) const char* const* provider_options_keys,
  2659. _In_reads_(num_keys) const char* const* provider_options_values,
  2660. _In_ size_t num_keys);
  2661. /** \brief Get serialized TensorRT provider options string.
  2662. *
  2663. * For example, "trt_max_workspace_size=2147483648;trt_max_partition_iterations=10;trt_int8_enable=1;......"
  2664. *
  2665. * \param tensorrt_options - OrtTensorRTProviderOptionsV2 instance
  2666. * \param allocator - a ptr to an instance of OrtAllocator obtained with OrtApi::CreateAllocator or OrtApi::GetAllocatorWithDefaultOptions
  2667. * the specified allocator will be used to allocate continuous buffers for output strings and lengths.
  2668. * \param ptr - is a UTF-8 null terminated string allocated using 'allocator'. The caller is responsible for using the same allocator to free it.
  2669. *
  2670. * \snippet{doc} snippets.dox OrtStatus Return Value
  2671. */
  2672. ORT_API2_STATUS(GetTensorRTProviderOptionsAsString, _In_ const OrtTensorRTProviderOptionsV2* tensorrt_options, _Inout_ OrtAllocator* allocator, _Outptr_ char** ptr);
  2673. /** \brief Release an ::OrtTensorRTProviderOptionsV2
  2674. *
  2675. * \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
  2676. */
  2677. void(ORT_API_CALL* ReleaseTensorRTProviderOptions)(_Frees_ptr_opt_ OrtTensorRTProviderOptionsV2* input);
  2678. /// @}
  2679. /// \name OrtSessionOptions
  2680. /// @{
  2681. /** \brief Enable custom operators
  2682. *
  2683. * See onnxruntime-extensions: https://github.com/microsoft/onnxruntime-extensions.git
  2684. *
  2685. * \snippet{doc} snippets.dox OrtStatus Return Value
  2686. */
  2687. ORT_API2_STATUS(EnableOrtCustomOps, _Inout_ OrtSessionOptions* options);
  2688. /// @}
  2689. /// \name OrtAllocator
  2690. /// @{
  2691. /** \brief Register a custom allocator
  2692. *
  2693. * Enables sharing between multiple sessions that use the same env instance.
  2694. * Returns an error if an allocator with the same ::OrtMemoryInfo is already registered.
  2695. *
  2696. * The behavior of this is exactly the same as OrtApi::CreateAndRegisterAllocator except
  2697. * instead of ORT creating an allocator based on provided info, in this case
  2698. * ORT uses the user-provided custom allocator.
  2699. * See https://onnxruntime.ai/docs/get-started/with-c.html for details.
  2700. *
  2701. * \param[in] env
  2702. * \param[in] allocator User provided allocator
  2703. *
  2704. * \snippet{doc} snippets.dox OrtStatus Return Value
  2705. */
  2706. ORT_API2_STATUS(RegisterAllocator, _Inout_ OrtEnv* env, _In_ OrtAllocator* allocator);
  2707. /** \brief Unregister a custom allocator
  2708. *
  2709. * It is an error if you provide an ::OrtMemoryInfo not corresponding to any
  2710. * registered allocators for sharing.
  2711. *
  2712. * \param[in] env
  2713. * \param[in] mem_info
  2714. *
  2715. * \snippet{doc} snippets.dox OrtStatus Return Value
  2716. */
  2717. ORT_API2_STATUS(UnregisterAllocator, _Inout_ OrtEnv* env,
  2718. _In_ const OrtMemoryInfo* mem_info);
  2719. /// @}
  2720. /// \name OrtValue
  2721. /// @{
  2722. /** \brief Sets *out to 1 iff an ::OrtValue is a SparseTensor, and 0 otherwise
  2723. *
  2724. * \param[in] value existing ::OrtValue
  2725. * \param[out] out unless an error occurs, contains 1 iff the value contains an instance
  2726. * of sparse tensor or 0 otherwise.
  2727. *
  2728. * \snippet{doc} snippets.dox OrtStatus Return Value
  2729. */
  2730. ORT_API2_STATUS(IsSparseTensor, _In_ const OrtValue* value, _Out_ int* out);
  2731. /** \brief Create an ::OrtValue with a sparse tensor that is empty.
  2732. *
  2733. * Use FillSparseTensor<Format>() functions to populate sparse tensor with non-zero values and
  2734. * format specific indices data.
  2735. * Use ReleaseValue to destroy the sparse tensor, this will also release the buffer inside the output value
  2736. * if any was allocated.
  2737. * \param[in,out] allocator allocator to use when performing an allocation. Allocation will be performed
  2738. * by FillSparseTensor<Format>() APIs. The lifespan of the allocator instance must eclipse the lifespan
  2739. * this sparse tensor instance as the same allocator will be used to free memory.
  2740. * \param[in] dense_shape shape of the original dense tensor
  2741. * \param[in] dense_shape_len number of shape dimensions being passed
  2742. * \param[in] type must be one of TENSOR_ELEMENT_DATA_TYPE_xxxx
  2743. * \param[out] out Should be freed by calling ReleaseValue
  2744. *
  2745. * \snippet{doc} snippets.dox OrtStatus Return Value
  2746. */
  2747. ORT_API2_STATUS(CreateSparseTensorAsOrtValue, _Inout_ OrtAllocator* allocator, _In_ const int64_t* dense_shape,
  2748. size_t dense_shape_len, ONNXTensorElementDataType type, _Outptr_ OrtValue** out);
  2749. /**
  2750. * This fills populates an empty tensor that was created using OrtApi::CreateSparseTensorAsOrtValue.
  2751. * This will allocate required memory and copy the supplied NNZ values and COO indices into that memory allocation.
  2752. * Memory allocation is performed using the allocator that was specified with OrtApi::CreateSparseTensorAsOrtValue.
  2753. *
  2754. * \param[in,out] ort_value ::OrtValue to populate with data
  2755. * \param[in] data_mem_info serves to identify the location of the data to be copied. If the allocator specified
  2756. * 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.
  2757. * String data is assumed to be on CPU and will only be copied into a CPU allocated buffer.
  2758. * \param[in] values_shape pointer to values shape array
  2759. * \param[in] values_shape_len length of the values_shape
  2760. * \param[in] values pointer to an array of values. For strings, pass const char**.
  2761. * \param[in] indices_data pointer to a location of COO indices
  2762. * \param[in] indices_num number of COO indices
  2763. *
  2764. * \snippet{doc} snippets.dox OrtStatus Return Value
  2765. */
  2766. ORT_API2_STATUS(FillSparseTensorCoo, _Inout_ OrtValue* ort_value, _In_ const OrtMemoryInfo* data_mem_info,
  2767. _In_ const int64_t* values_shape, size_t values_shape_len, _In_ const void* values,
  2768. _In_ const int64_t* indices_data, size_t indices_num);
  2769. /**
  2770. * This fills populates an empty tensor that was created using OrtApi::CreateSparseTensorAsOrtValue.
  2771. * This will allocate required memory and copy the supplied NNZ values and CSR indices into that memory allocation.
  2772. * Memory allocation is performed using the allocator that was specified with OrtApi::CreateSparseTensorAsOrtValue.
  2773. *
  2774. * \param[in,out] ort_value ::OrtValue to populate with data
  2775. * \param[in] data_mem_info serves to identify the location of the data to be copied. If the allocator specified
  2776. * 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.
  2777. * String data is assumed to be on CPU and will only be copied into a CPU allocated buffer.
  2778. * \param[in] values_shape pointer to values shape array
  2779. * \param[in] values_shape_len length of the values_shape
  2780. * \param[in] values - pointer to an array of values. For strings, pass const char**.
  2781. * \param[in] inner_indices_data pointer to a location of CSR inner indices
  2782. * \param[in] inner_indices_num number of CSR inner indices
  2783. * \param[in] outer_indices_data pointer to a location of CSR outer indices
  2784. * \param[in] outer_indices_num number of CSR outer indices
  2785. *
  2786. * \snippet{doc} snippets.dox OrtStatus Return Value
  2787. */
  2788. ORT_API2_STATUS(FillSparseTensorCsr, _Inout_ OrtValue* ort_value, _In_ const OrtMemoryInfo* data_mem_info,
  2789. _In_ const int64_t* values_shape, size_t values_shape_len, _In_ const void* values,
  2790. _In_ const int64_t* inner_indices_data, size_t inner_indices_num,
  2791. _In_ const int64_t* outer_indices_data, size_t outer_indices_num);
  2792. /**
  2793. * This fills populates an empty tensor that was created using OrtApi::CreateSparseTensorAsOrtValue.
  2794. * This will allocate required memory and copy the supplied NNZ values and BlockSparse indices into that memory allocation.
  2795. * Memory allocation is performed using the allocator that was specified with OrtApi::CreateSparseTensorAsOrtValue.
  2796. *
  2797. * \param[in,out] ort_value ::OrtValue to populate with data
  2798. * \param[in] data_mem_info serves to identify the location of the data to be copied. If the allocator specified
  2799. * 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.
  2800. * String data is assumed to be on CPU and will only be copied into a CPU allocated buffer.
  2801. * \param[in] values_shape
  2802. * \param[in] values_shape_len
  2803. * \param[in] values structure with values information
  2804. * \param[in] indices_shape_data pointer to a location of indices shape
  2805. * \param[in] indices_shape_len length of the block sparse indices shape
  2806. * \param[in] indices_data pointer to a location of indices data. Shape will determine the length of the indices data.
  2807. *
  2808. * \snippet{doc} snippets.dox OrtStatus Return Value
  2809. */
  2810. ORT_API2_STATUS(FillSparseTensorBlockSparse, _Inout_ OrtValue* ort_value, _In_ const OrtMemoryInfo* data_mem_info,
  2811. _In_ const int64_t* values_shape, size_t values_shape_len, _In_ const void* values,
  2812. _In_ const int64_t* indices_shape_data, size_t indices_shape_len,
  2813. _In_ const int32_t* indices_data);
  2814. /**
  2815. * Create an ::OrtValue with a sparse tensor. This is the first step.
  2816. * Next, use Use<Format>Indices() functions to supply sparse tensor with
  2817. * format specific indices data and set its sparse format to a specific enum value.
  2818. * This will not perform memory allocations. It will
  2819. * use supplied user buffer which should outlive the created sparse tensor.
  2820. * Use OrtApi::ReleaseValue to destroy the sparse tensor. It would not release the supplied values buffer.
  2821. * This function can not be used to map strings from the user allocated memory. Strings must always be copied
  2822. * and have UTF-8 encoding. Therefore, use OrtApi::CreateSparseTensorAsOrtValue above and then fill it with data
  2823. * using appropriate Make*() function.
  2824. *
  2825. * \param[in] info memory info where sparse values reside.
  2826. * \param[in,out] p_data pointer to a user allocated buffer with values. To create a full sparse tensor with no non-zero
  2827. * values, pass nullptr
  2828. * \param[in] dense_shape shape of the original dense tensor
  2829. * \param[in] dense_shape_len number of shape dimensions being passed
  2830. * \param[in] values_shape shape of the values data. To create a fully sparse tensor with no non-zero values,
  2831. * pass {0} shape.
  2832. * \param[in] values_shape_len number of values shape dimensions
  2833. * \param[in] type must be one of TENSOR_ELEMENT_DATA_TYPE_xxxx
  2834. * \param[out] out Should be freed by calling ReleaseValue
  2835. *
  2836. * \snippet{doc} snippets.dox OrtStatus Return Value
  2837. */
  2838. ORT_API2_STATUS(CreateSparseTensorWithValuesAsOrtValue, _In_ const OrtMemoryInfo* info, _Inout_ void* p_data,
  2839. _In_ const int64_t* dense_shape, size_t dense_shape_len,
  2840. _In_ const int64_t* values_shape, size_t values_shape_len,
  2841. ONNXTensorElementDataType type, _Outptr_ OrtValue** out);
  2842. /**
  2843. * This assigns Coo format indices to the SparseTensor that was created by
  2844. * OrtApi::CreateSparseTensorWithValuesAsOrtValue above. It also sets OrtSparseFormat to
  2845. * ORT_SPARSE_COO. This will not allocate any additional memory for data. The life span of
  2846. * indices_data buffer should eclipse the life span of this ::OrtValue.
  2847. *
  2848. * \param[in,out] ort_value ::OrtValue instance constructed with OrtApi::CreateSparseTensorWithValuesAsOrtValue
  2849. * \param[in,out] indices_data pointer to a user pre-allocated buffer or nullptr for fully sparse tensors.
  2850. * \param[in] indices_num number of COO indices. Should either be 0 for fully sparse tensors, be equal
  2851. * to the number of nnz values specified to OrtApi::CreateSparseTensorWithValuesAsOrtValue for 1-D {nnz} indices or
  2852. * be twice as number of nnz values for a 2-D indices {nnz, 2}
  2853. *
  2854. * \snippet{doc} snippets.dox OrtStatus Return Value
  2855. */
  2856. ORT_API2_STATUS(UseCooIndices, _Inout_ OrtValue* ort_value, _Inout_ int64_t* indices_data, size_t indices_num);
  2857. /**
  2858. * The assigns CSR format indices to the SparseTensor that was created by
  2859. * OrtApi::CreateSparseTensorWithValuesAsOrtValue above. It also sets OrtSparseFormat to
  2860. * ORT_SPARSE_CSRC. This will not allocate any additional memory for data. The life spans of
  2861. * inner_data and outer_data buffers should eclipse the life span of this ::OrtValue.
  2862. *
  2863. * \param[in,out] ort_value ::OrtValue instance constructed with OrtApi::CreateSparseTensorWithValuesAsOrtValue
  2864. * \param[in,out] inner_data pointer to a user pre-allocated buffer or nullptr for fully sparse tensors.
  2865. * \param[in] inner_num number of inner CSR indices. Should either be 0 for fully sparse tensors or be equal
  2866. * to the number of nnz values specified to OrtApi::CreateSparseTensorWithValuesAsOrtValue.
  2867. * \param[in,out] outer_data pointer to user pre-allocated buffer or nullptr for fully sparse tensors.
  2868. * \param[in] outer_num number of CSR outer indices. Should either be 0 for fully sparse tensors or
  2869. * equal to rows + 1 of the dense shape.
  2870. *
  2871. * \snippet{doc} snippets.dox OrtStatus Return Value
  2872. */
  2873. ORT_API2_STATUS(UseCsrIndices, _Inout_ OrtValue* ort_value, _Inout_ int64_t* inner_data, size_t inner_num,
  2874. _Inout_ int64_t* outer_data, size_t outer_num);
  2875. /**
  2876. * The assigns BlockSparse format indices to the SparseTensor that was created by
  2877. * OrtApi::CreateSparseTensorWithValuesAsOrtValue above. It also sets OrtSparseFormat to
  2878. * ORT_SPARSE_BLOCK_SPARSE. This will not allocate any additional memory for data. The life span of
  2879. * indices_data buffer must eclipse the lifespan of this ::OrtValue.
  2880. *
  2881. * \param[in,out] ort_value OrtValue instance constructed with OrtApi::CreateSparseTensorWithValuesAsOrtValue
  2882. * \param[in] indices_shape pointer to indices shape. Use {0} for fully sparse tensors
  2883. * \param[in] indices_shape_len length of the indices shape
  2884. * \param[in,out] indices_data pointer to user pre-allocated buffer or nullptr for fully sparse tensors.
  2885. *
  2886. * \snippet{doc} snippets.dox OrtStatus Return Value
  2887. */
  2888. ORT_API2_STATUS(UseBlockSparseIndices, _Inout_ OrtValue* ort_value, const int64_t* indices_shape, size_t indices_shape_len, _Inout_ int32_t* indices_data);
  2889. /** \brief Returns sparse tensor format enum iff a given ort value contains an instance of sparse tensor.
  2890. *
  2891. * \param[in] ort_value ::OrtValue that contains an instance of sparse tensor
  2892. * \param[out] out pointer to out parameter
  2893. *
  2894. * \snippet{doc} snippets.dox OrtStatus Return Value
  2895. */
  2896. ORT_API2_STATUS(GetSparseTensorFormat, _In_ const OrtValue* ort_value, _Out_ enum OrtSparseFormat* out);
  2897. /** \brief Returns data type and shape of sparse tensor values (nnz) iff ::OrtValue contains a SparseTensor.
  2898. *
  2899. * \param[in] ort_value An ::OrtValue that contains a fully constructed sparse tensor
  2900. * \param[out] out Must be freed by OrtApi::ReleaseTensorTypeAndShapeInfo
  2901. *
  2902. * \snippet{doc} snippets.dox OrtStatus Return Value
  2903. */
  2904. ORT_API2_STATUS(GetSparseTensorValuesTypeAndShape, _In_ const OrtValue* ort_value, _Outptr_ OrtTensorTypeAndShapeInfo** out);
  2905. /** \brief Returns numeric data for sparse tensor values (nnz). For string values use GetStringTensor*().
  2906. *
  2907. * \param[in] ort_value an instance of ::OrtValue containing sparse tensor
  2908. * \param[out] out returns a pointer to values data. Do not attempt to free this ptr.
  2909. *
  2910. * \snippet{doc} snippets.dox OrtStatus Return Value
  2911. */
  2912. ORT_API2_STATUS(GetSparseTensorValues, _In_ const OrtValue* ort_value, _Outptr_ const void** out);
  2913. /** \brief Returns data type, shape for the type of indices specified by indices_format.
  2914. *
  2915. * \param[in] ort_value ::OrtValue containing sparse tensor.
  2916. * \param[in] indices_format One of the indices formats. It is an error to request a format that the sparse
  2917. * tensor does not contain.
  2918. * \param[out] out an instance of ::OrtTensorTypeAndShapeInfo. Must be freed by OrtApi::ReleaseTensorTypeAndShapeInfo
  2919. *
  2920. * \snippet{doc} snippets.dox OrtStatus Return Value
  2921. */
  2922. ORT_API2_STATUS(GetSparseTensorIndicesTypeShape, _In_ const OrtValue* ort_value, enum OrtSparseIndicesFormat indices_format, _Outptr_ OrtTensorTypeAndShapeInfo** out);
  2923. /** \brief Returns indices data for the type of the indices specified by indices_format
  2924. *
  2925. * \param[in] ort_value ::OrtValue containing sparse tensor.
  2926. * \param[in] indices_format One of the indices formats. It is an error to request a format that the sparse tensor does not contain.
  2927. * \param[out] num_indices Pointer to where the number of indices entries is returned
  2928. * \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
  2929. *
  2930. * \snippet{doc} snippets.dox OrtStatus Return Value
  2931. */
  2932. ORT_API2_STATUS(GetSparseTensorIndices, _In_ const OrtValue* ort_value, enum OrtSparseIndicesFormat indices_format, _Out_ size_t* num_indices, _Outptr_ const void** indices);
  2933. /// @}
  2934. /// \name OrtSessionOptions
  2935. /// @{
  2936. /**
  2937. * \brief Sets out to 1 iff an optional type OrtValue has an element, 0 otherwise (OrtValue is None)
  2938. * Use this API to find if the optional type OrtValue is None or not.
  2939. * If the optional type OrtValue is not None, use the OrtValue just like any other OrtValue.
  2940. * For example, if you get an OrtValue that corresponds to Optional(tensor) and
  2941. * if HasValue() returns true, use it as tensor and so on.
  2942. * \param[in] value Input OrtValue.
  2943. * \param[out] out indicating if the input OrtValue contains data (1) or if it is a None (0)
  2944. *
  2945. * \snippet{doc} snippets.dox OrtStatus Return Value
  2946. */
  2947. ORT_API2_STATUS(HasValue, _In_ const OrtValue* value, _Out_ int* out);
  2948. /// @}
  2949. /// \name OrtKernelContext
  2950. /// Custom operator APIs.
  2951. /// @{
  2952. /** \brief Used for custom operators, gets the GPU compute stream to use to launch the custom a GPU kernel
  2953. * \see ::OrtCustomOp
  2954. * \param[in] context OrtKernelContext instance
  2955. * \param[out] out Returns pointer to a GPU compute stream that can be used to launch the custom GPU kernel.
  2956. * If retrieving the GPU compute stream is not relevant (GPU not enabled in the build, kernel partitioned to
  2957. * some other EP), then a nullptr is returned as the output param.
  2958. * Do not free or mutate the returned pointer as it refers to internal data owned by the underlying session.
  2959. * Only use it for custom kernel launching.
  2960. *
  2961. * \snippet{doc} snippets.dox OrtStatus Return Value
  2962. */
  2963. ORT_API2_STATUS(KernelContext_GetGPUComputeStream, _In_ const OrtKernelContext* context, _Outptr_ void** out);
  2964. /// @}
  2965. /// \name GetTensorMemoryInfo
  2966. /// @{
  2967. /** \brief Returns a pointer to the ::OrtMemoryInfo of a Tensor
  2968. * \param[in] value ::OrtValue containing tensor.
  2969. * \param[out] mem_info ::OrtMemoryInfo of the tensor. Do NOT free the returned pointer. It is valid for the lifetime of the ::OrtValue
  2970. *
  2971. * \snippet{doc} snippets.dox OrtStatus Return Value
  2972. */
  2973. ORT_API2_STATUS(GetTensorMemoryInfo, _In_ const OrtValue* value, _Out_ const OrtMemoryInfo** mem_info);
  2974. /// @}
  2975. /// \name GetExecutionProviderApi
  2976. /// @{
  2977. /** \brief Get a pointer to the requested version of the Execution Provider specific
  2978. * API extensions to the OrtApi
  2979. * \param[in] provider_name The name of the execution provider name. Currently only the following
  2980. * values are supported: "DML".
  2981. * \param[in] version Must be ::ORT_API_VERSION.
  2982. * \param[out] provider_api A void pointer containing a reference to the execution provider versioned api structure.
  2983. * For example, the provider_api pointer can be cast to the OrtDmlApi* when the provider_name is "DML".
  2984. *
  2985. * \snippet{doc} snippets.dox OrtStatus Return Value
  2986. */
  2987. ORT_API2_STATUS(GetExecutionProviderApi, _In_ const char* provider_name, _In_ uint32_t version, _Outptr_ const void** provider_api);
  2988. /// @}
  2989. /// \name SessionOptions
  2990. /// @{
  2991. /** \brief Set custom thread creation function
  2992. *
  2993. * \param[in] options Session options
  2994. * \param[in] ort_custom_create_thread_fn Custom thread creation function
  2995. *
  2996. * \snippet{doc} snippets.dox OrtStatus Return Value
  2997. */
  2998. ORT_API2_STATUS(SessionOptionsSetCustomCreateThreadFn, _Inout_ OrtSessionOptions* options, _In_ OrtCustomCreateThreadFn ort_custom_create_thread_fn);
  2999. /** \brief Set creation options for custom thread
  3000. *
  3001. * \param[in] options Session options
  3002. * \param[in] ort_custom_thread_creation_options Custom thread creation options (can be nullptr)
  3003. *
  3004. * \snippet{doc} snippets.dox OrtStatus Return Value
  3005. */
  3006. ORT_API2_STATUS(SessionOptionsSetCustomThreadCreationOptions, _Inout_ OrtSessionOptions* options, _In_ void* ort_custom_thread_creation_options);
  3007. /** \brief Set custom thread join function
  3008. *
  3009. * \param[in] options Session options
  3010. * \param[in] ort_custom_join_thread_fn Custom join thread function, must not be nullptr when ort_custom_create_thread_fn is set
  3011. *
  3012. * \snippet{doc} snippets.dox OrtStatus Return Value
  3013. */
  3014. ORT_API2_STATUS(SessionOptionsSetCustomJoinThreadFn, _Inout_ OrtSessionOptions* options, _In_ OrtCustomJoinThreadFn ort_custom_join_thread_fn);
  3015. /// @}
  3016. /// \name OrtThreadingOptions
  3017. /// @{
  3018. /** \brief Set custom thread creation function for global thread pools
  3019. *
  3020. * \param[inout] tp_options
  3021. * \param[in] ort_custom_create_thread_fn Custom thread creation function
  3022. *
  3023. * \snippet{doc} snippets.dox OrtStatus Return Value
  3024. */
  3025. ORT_API2_STATUS(SetGlobalCustomCreateThreadFn, _Inout_ OrtThreadingOptions* tp_options, _In_ OrtCustomCreateThreadFn ort_custom_create_thread_fn);
  3026. /** \brief Set custom thread creation options for global thread pools
  3027. *
  3028. * \param[inout] tp_options
  3029. * \param[in] ort_custom_thread_creation_options Custom thread creation options (can be nullptr)
  3030. *
  3031. * \snippet{doc} snippets.dox OrtStatus Return Value
  3032. */
  3033. ORT_API2_STATUS(SetGlobalCustomThreadCreationOptions, _Inout_ OrtThreadingOptions* tp_options, _In_ void* ort_custom_thread_creation_options);
  3034. /** \brief Set custom thread join function for global thread pools
  3035. *
  3036. * \param[inout] tp_options
  3037. * \param[in] ort_custom_join_thread_fn Custom thread join function, must not be nullptr when global ort_custom_create_thread_fn is set
  3038. *
  3039. * \snippet{doc} snippets.dox OrtStatus Return Value
  3040. */
  3041. ORT_API2_STATUS(SetGlobalCustomJoinThreadFn, _Inout_ OrtThreadingOptions* tp_options, _In_ OrtCustomJoinThreadFn ort_custom_join_thread_fn);
  3042. /// @}
  3043. /** \brief Synchronize bound inputs. The call may be necessary for some providers, such as cuda,
  3044. * in case the system that allocated bound memory operated on a different stream. However, the
  3045. * operation is provider specific and could be a no-op.
  3046. *
  3047. * \param[inout] binding_ptr
  3048. *
  3049. * \snippet{doc} snippets.dox OrtStatus Return Value
  3050. */
  3051. ORT_API2_STATUS(SynchronizeBoundInputs, _Inout_ OrtIoBinding* binding_ptr);
  3052. /** \brief Synchronize bound outputs. The call may be necessary for some providers, such as cuda,
  3053. * in case the system that allocated bound memory operated on a different stream. However, the
  3054. * operation is provider specific and could be a no-op.
  3055. *
  3056. * \param[inout] binding_ptr
  3057. *
  3058. * \snippet{doc} snippets.dox OrtStatus Return Value
  3059. */
  3060. ORT_API2_STATUS(SynchronizeBoundOutputs, _Inout_ OrtIoBinding* binding_ptr);
  3061. /// \name OrtSessionOptions
  3062. /// @{
  3063. /** \brief Append CUDA execution provider to the session options
  3064. *
  3065. * If CUDA is not available (due to a non CUDA enabled build), this function will return failure.
  3066. *
  3067. * This is slightly different from OrtApi::SessionOptionsAppendExecutionProvider_CUDA, it takes an
  3068. * ::OrtCUDAProviderOptions which is publicly defined. This takes an opaque ::OrtCUDAProviderOptionsV2
  3069. * which must be created with OrtApi::CreateCUDAProviderOptions.
  3070. *
  3071. * For OrtApi::SessionOptionsAppendExecutionProvider_CUDA, the user needs to instantiate ::OrtCUDAProviderOptions
  3072. * as well as allocate/release buffers for some members of ::OrtCUDAProviderOptions.
  3073. * Here, OrtApi::CreateCUDAProviderOptions and Ortapi::ReleaseCUDAProviderOptions will do the memory management for you.
  3074. *
  3075. * \param[in] options
  3076. * \param[in] cuda_options
  3077. *
  3078. * \snippet{doc} snippets.dox OrtStatus Return Value
  3079. *
  3080. * \since Version 1.11.
  3081. */
  3082. ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_CUDA_V2,
  3083. _In_ OrtSessionOptions* options, _In_ const OrtCUDAProviderOptionsV2* cuda_options);
  3084. /// @}
  3085. /// \name OrtCUDAProviderOptionsV2
  3086. /// @{
  3087. /** \brief Create an OrtCUDAProviderOptionsV2
  3088. *
  3089. * \param[out] out Newly created ::OrtCUDAProviderOptionsV2. Must be released with OrtApi::ReleaseCudaProviderOptions
  3090. *
  3091. * \snippet{doc} snippets.dox OrtStatus Return Value
  3092. *
  3093. * \since Version 1.11.
  3094. */
  3095. ORT_API2_STATUS(CreateCUDAProviderOptions, _Outptr_ OrtCUDAProviderOptionsV2** out);
  3096. /** \brief Set options in a CUDA Execution Provider.
  3097. *
  3098. * Please refer to https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html#configuration-options
  3099. * to know the available keys and values. Key should be in null terminated string format of the member of ::OrtCUDAProviderOptionsV2
  3100. * and value should be its related range. Recreates the options and only sets the supplied values.
  3101. *
  3102. * For example, key="device_id" and value="0"
  3103. *
  3104. * \param[in] cuda_options
  3105. * \param[in] provider_options_keys Array of UTF-8 null-terminated string for provider options keys
  3106. * \param[in] provider_options_values Array of UTF-8 null-terminated string for provider options values
  3107. * \param[in] num_keys Number of elements in the `provider_option_keys` and `provider_options_values` arrays
  3108. *
  3109. * \snippet{doc} snippets.dox OrtStatus Return Value
  3110. *
  3111. * \since Version 1.11.
  3112. */
  3113. ORT_API2_STATUS(UpdateCUDAProviderOptions, _Inout_ OrtCUDAProviderOptionsV2* cuda_options,
  3114. _In_reads_(num_keys) const char* const* provider_options_keys,
  3115. _In_reads_(num_keys) const char* const* provider_options_values,
  3116. _In_ size_t num_keys);
  3117. /**
  3118. * Get serialized CUDA provider options string.
  3119. *
  3120. * For example, "device_id=0;arena_extend_strategy=0;......"
  3121. *
  3122. * \param cuda_options - OrtCUDAProviderOptionsV2 instance
  3123. * \param allocator - a ptr to an instance of OrtAllocator obtained with CreateAllocator() or GetAllocatorWithDefaultOptions()
  3124. * the specified allocator will be used to allocate continuous buffers for output strings and lengths.
  3125. * \param ptr - is a UTF-8 null terminated string allocated using 'allocator'. The caller is responsible for using the same allocator to free it.
  3126. *
  3127. * \snippet{doc} snippets.dox OrtStatus Return Value
  3128. *
  3129. * \since Version 1.11.
  3130. */
  3131. ORT_API2_STATUS(GetCUDAProviderOptionsAsString, _In_ const OrtCUDAProviderOptionsV2* cuda_options, _Inout_ OrtAllocator* allocator, _Outptr_ char** ptr);
  3132. /** \brief Release an ::OrtCUDAProviderOptionsV2
  3133. *
  3134. * \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
  3135. *
  3136. * \since Version 1.11.
  3137. */
  3138. void(ORT_API_CALL* ReleaseCUDAProviderOptions)(_Frees_ptr_opt_ OrtCUDAProviderOptionsV2* input);
  3139. /// @}
  3140. /** \brief Append MIGraphX provider to session options
  3141. *
  3142. * 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.
  3143. *
  3144. * \param[in] options
  3145. * \param[in] migraphx_options
  3146. *
  3147. * \snippet{doc} snippets.dox OrtStatus Return Value
  3148. *
  3149. * \since Version 1.11.
  3150. */
  3151. ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_MIGraphX,
  3152. _In_ OrtSessionOptions* options, _In_ const OrtMIGraphXProviderOptions* migraphx_options);
  3153. /** \brief Replace initialized Tensors with external data with the data provided in initializers.
  3154. *
  3155. * The function will find the initialized TensorProtos with external data in the graph with the provided names and
  3156. * replace them with the provided tensors. The API verifies that the TensorProto being replaced
  3157. * has an external data reference and has the same name, dimensions and data type as its replacement. The replacement
  3158. * will occur before any of the optimizations take place. The data will be copied into the graph
  3159. * since TensorProto can't refer to the user provided buffers.
  3160. *
  3161. * Once the model has been loaded, the OrtValue(s) added to SessionOptions instance will be removed
  3162. * from the internal SessionOptions copy to save memory, the user provided buffers can then be deallocated
  3163. * and the SessionOptions instance that refers to them can be destroyed.
  3164. *
  3165. * \param[in] options
  3166. * \param[in] initializer_names Array of null terminated UTF-8 encoded strings of the initializers names.
  3167. * \param[in] initializers Array of ::OrtValue type
  3168. * \param[in] num_initializers Number of elements in the initializer_names and initializers
  3169. *
  3170. * \snippet{doc} snippets.dox OrtStatus Return Value
  3171. *
  3172. * \since Version 1.12.
  3173. */
  3174. ORT_API2_STATUS(AddExternalInitializers, _In_ OrtSessionOptions* options,
  3175. _In_reads_(num_initializers) const char* const* initializer_names,
  3176. _In_reads_(num_initializers) const OrtValue* const* initializers, size_t num_initializers);
  3177. /** \brief: Create attribute of onnxruntime operator
  3178. *
  3179. * \param[in] name Name of the attribute
  3180. * \param[in] data Data content of the attribute
  3181. * \param[in] len Number of bytes stored in data
  3182. * \param[in] type Data type
  3183. * \param[out] op_attr Attribute that has been created, which must be released by OrtApi::ReleaseOpAttr
  3184. *
  3185. * \since Version 1.12.
  3186. */
  3187. ORT_API2_STATUS(CreateOpAttr,
  3188. _In_ const char* name,
  3189. _In_ const void* data,
  3190. _In_ int len,
  3191. _In_ OrtOpAttrType type,
  3192. _Outptr_ OrtOpAttr** op_attr);
  3193. /* \brief: Release op attribute
  3194. *
  3195. * \param[in] opAttr Attribute created by OrtApi::CreateOpAttr
  3196. *
  3197. * \since Version 1.12.
  3198. */
  3199. ORT_CLASS_RELEASE(OpAttr);
  3200. /** \brief: Create onnxruntime native operator
  3201. *
  3202. * \param[in] info Kernel info
  3203. * \param[in] op_name Operator name
  3204. * \param[in] domain Operator domain
  3205. * \param[in] version Operator opset version
  3206. * \param[in] type_constraint_names Name of the type contraints, such as "T" or "T1"
  3207. * \param[in] type_constraint_values Type of each contraints
  3208. * \param[in] type_constraint_count Number of contraints
  3209. * \param[in] attr_values Attributes used to initialize the operator
  3210. * \param[in] attr_count Number of the attributes
  3211. * \param[in] input_count Number of inputs
  3212. * \param[in] output_count Number of outputs
  3213. * \param[out] ort_op Operator that has been created
  3214. *
  3215. * \since Version 1.12.
  3216. */
  3217. ORT_API2_STATUS(CreateOp,
  3218. _In_ const OrtKernelInfo* info,
  3219. _In_z_ const char* op_name,
  3220. _In_z_ const char* domain,
  3221. int version,
  3222. _In_reads_(type_constraint_count) const char** type_constraint_names,
  3223. _In_reads_(type_constraint_count) const ONNXTensorElementDataType* type_constraint_values,
  3224. int type_constraint_count,
  3225. _In_reads_(attr_count) const OrtOpAttr* const* attr_values,
  3226. int attr_count,
  3227. int input_count,
  3228. int output_count,
  3229. _Outptr_ OrtOp** ort_op);
  3230. /** \brief: Invoke the operator created by OrtApi::CreateOp
  3231. * The inputs must follow the order as specified in onnx specification
  3232. *
  3233. * \param[in] context Kernel context
  3234. * \param[in] ort_op Operator that has been created
  3235. * \param[in] input_values Array of inputs
  3236. * \param[in] input_count Number of inputs
  3237. * \param[in] output_values Array of outputs
  3238. * \param[in] output_count Number of outputs
  3239. *
  3240. * \since Version 1.12.
  3241. */
  3242. ORT_API2_STATUS(InvokeOp,
  3243. _In_ const OrtKernelContext* context,
  3244. _In_ const OrtOp* ort_op,
  3245. _In_ const OrtValue* const* input_values,
  3246. _In_ int input_count,
  3247. _Inout_ OrtValue* const* output_values,
  3248. _In_ int output_count);
  3249. /* \brief: Release an onnxruntime operator
  3250. *
  3251. * \param[in] Op Operator created by OrtApi::CreateOp
  3252. *
  3253. * \since Version 1.12.
  3254. */
  3255. ORT_CLASS_RELEASE(Op);
  3256. /** \brief: Append execution provider to the session options.
  3257. * \param[in] options
  3258. * \param[in] provider_name - provider to add.
  3259. * \param[in] provider_options_keys - keys to configure the provider options
  3260. * \param[in] provider_options_values - values to configure the provider options
  3261. * \param[in] num_keys - number of keys passed in
  3262. *
  3263. * Currently supported providers:
  3264. * QNN
  3265. * SNPE
  3266. * XNNPACK
  3267. *
  3268. * Note: If an execution provider has a dedicated SessionOptionsAppendExecutionProvider_<provider name> function
  3269. * that should be used to add it.
  3270. *
  3271. * QNN supported keys:
  3272. * "backend_path": file path to QNN backend library.
  3273. * "profiling_level": QNN profiling level, options: "off", "basic", "detailed". Default to off.
  3274. * "profiling_file_path": QNN profiling file path if ETW not enabled.
  3275. * "rpc_control_latency": QNN RPC control latency.
  3276. * "vtcm_mb": QNN VTCM size in MB. default to 0(not set).
  3277. * "htp_performance_mode": QNN performance mode, options: "burst", "balanced", "default", "high_performance",
  3278. * "high_power_saver", "low_balanced", "extreme_power_saver", "low_power_saver", "power_saver", "sustained_high_performance". Default to "default".
  3279. * "qnn_saver_path": File path to the QNN Saver backend library. If specified, QNN Saver will be enabled and will
  3280. * dump QNN API calls to disk for replay/debugging. QNN Saver produces incorrect model inference results and
  3281. * may alter model/EP partitioning. Use only for debugging.
  3282. * "qnn_context_priority": QNN context priority, options: "low", "normal", "normal_high", "high". Default to "normal".
  3283. * "htp_graph_finalization_optimization_mode": Set the optimization mode for graph finalization on the HTP backend. Available options:
  3284. * - "0": Default.
  3285. * - "1": Faster preparation time, less optimal graph.
  3286. * - "2": Longer preparation time, more optimal graph.
  3287. * - "3": Longest preparation time, most likely even more optimal graph. See QNN SDK documentation for specific details.
  3288. * "soc_model": The SoC model number. Refer to the QNN SDK documentation for valid values. Defaults to "0" (unknown).
  3289. * "htp_arch": The minimum HTP architecture the driver will use to select compatible QNN operators. Available options:
  3290. * - "0": Default (none).
  3291. * - "68"
  3292. * - "69"
  3293. * - "73"
  3294. * - "75"
  3295. * "device_id": The ID of the device to use when setting 'htp_arch'. Defaults to "0" (for single device).
  3296. "enable_htp_fp16_precision": Only used for float32 model.
  3297. Enable the float32 model to be inferenced with fp16 precision. Otherwise, it will be fp32 precision.
  3298. - "0": Default. With fp32 precision.
  3299. - "1": With fp16 precision.
  3300. *
  3301. * SNPE supported keys:
  3302. * "runtime": SNPE runtime engine, options: "CPU", "CPU_FLOAT32", "GPU", "GPU_FLOAT32_16_HYBRID", "GPU_FLOAT16",
  3303. * "DSP", "DSP_FIXED8_TF", "AIP_FIXED_TF", "AIP_FIXED8_TF".
  3304. * Mapping to SNPE Runtime_t definition: CPU, CPU_FLOAT32 => zdl::DlSystem::Runtime_t::CPU;
  3305. * GPU, GPU_FLOAT32_16_HYBRID => zdl::DlSystem::Runtime_t::GPU;
  3306. * GPU_FLOAT16 => zdl::DlSystem::Runtime_t::GPU_FLOAT16;
  3307. * DSP, DSP_FIXED8_TF => zdl::DlSystem::Runtime_t::DSP.
  3308. * AIP_FIXED_TF, AIP_FIXED8_TF => zdl::DlSystem::Runtime_t::AIP_FIXED_TF.
  3309. * "priority": execution priority, options: "low", "normal".
  3310. * "buffer_type": ITensor or user buffers, options: "ITENSOR", user buffer with different types - "TF8", "TF16", "UINT8", "FLOAT".
  3311. * "ITENSOR" -- default, ITensor which is float only.
  3312. * "TF8" -- quantized model required, "FLOAT" -- for both quantized or non-quantized model
  3313. * "enable_init_cache": enable SNPE init caching feature, set to 1 to enabled it. Disabled by default.
  3314. * If SNPE is not available (due to a non Snpe enabled build or its dependencies not being installed), this function will fail.
  3315. *
  3316. * XNNPACK supported keys:
  3317. * "intra_op_num_threads": number of thread-pool size to use for XNNPACK execution provider.
  3318. * default value is 0, which means to use the session thread-pool size.
  3319. *
  3320. * \since Version 1.12.
  3321. */
  3322. ORT_API2_STATUS(SessionOptionsAppendExecutionProvider, _In_ OrtSessionOptions* options,
  3323. _In_ const char* provider_name,
  3324. _In_reads_(num_keys) const char* const* provider_options_keys,
  3325. _In_reads_(num_keys) const char* const* provider_options_values,
  3326. _In_ size_t num_keys);
  3327. /* \brief: Get a copy of kernel info
  3328. *
  3329. * \param[in] info Kernel info
  3330. * \param[out] info_copy Copy of kernel info
  3331. *
  3332. * \since Version 1.12.
  3333. */
  3334. ORT_API2_STATUS(CopyKernelInfo,
  3335. _In_ const OrtKernelInfo* info,
  3336. _Outptr_ OrtKernelInfo** info_copy);
  3337. /* \brief: Release kernel info
  3338. *
  3339. * \param[in] KernelInfo A copy of kernel info returned by CopyKernelInfo
  3340. *
  3341. * \since Version 1.12.
  3342. */
  3343. ORT_CLASS_RELEASE(KernelInfo);
  3344. /// \name Ort Training
  3345. /// @{
  3346. /** \brief Gets the Training C Api struct
  3347. *
  3348. * Call this function to access the ::OrtTrainingApi structure that holds pointers to functions that enable
  3349. * training with onnxruntime.
  3350. * \note A NULL pointer will be returned and no error message will be printed if the training api
  3351. * is not supported with this build. A NULL pointer will be returned and an error message will be
  3352. * printed if the provided version is unsupported, for example when using a runtime older than the
  3353. * version created with this header file.
  3354. *
  3355. * \param[in] version Must be ::ORT_API_VERSION
  3356. * \return The ::OrtTrainingApi struct for the version requested.
  3357. *
  3358. * \since Version 1.13
  3359. */
  3360. const OrtTrainingApi*(ORT_API_CALL* GetTrainingApi)(uint32_t version)NO_EXCEPTION;
  3361. /// @}
  3362. /** \brief Append CANN provider to session options
  3363. *
  3364. * 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.
  3365. *
  3366. * \param[in] options
  3367. * \param[in] cann_options
  3368. *
  3369. * \snippet{doc} snippets.dox OrtStatus Return Value
  3370. *
  3371. * \since Version 1.13.
  3372. */
  3373. ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_CANN,
  3374. _In_ OrtSessionOptions* options, _In_ const OrtCANNProviderOptions* cann_options);
  3375. /** \brief Create an OrtCANNProviderOptions
  3376. *
  3377. * \param[out] out created ::OrtCANNProviderOptions. Must be released with OrtApi::ReleaseCANNProviderOptions
  3378. *
  3379. * \snippet{doc} snippets.dox OrtStatus Return Value
  3380. *
  3381. * \since Version 1.13.
  3382. */
  3383. ORT_API2_STATUS(CreateCANNProviderOptions, _Outptr_ OrtCANNProviderOptions** out);
  3384. /** \brief Set options in a CANN Execution Provider.
  3385. *
  3386. * \param[in] cann_options
  3387. * \param[in] provider_options_keys Array of UTF-8 null-terminated string for provider options keys
  3388. * \param[in] provider_options_values Array of UTF-8 null-terminated string for provider options values
  3389. * \param[in] num_keys Number of elements in the `provider_option_keys` and `provider_options_values` arrays
  3390. *
  3391. * \snippet{doc} snippets.dox OrtStatus Return Value
  3392. *
  3393. * \since Version 1.13.
  3394. */
  3395. ORT_API2_STATUS(UpdateCANNProviderOptions, _Inout_ OrtCANNProviderOptions* cann_options,
  3396. _In_reads_(num_keys) const char* const* provider_options_keys,
  3397. _In_reads_(num_keys) const char* const* provider_options_values,
  3398. _In_ size_t num_keys);
  3399. /** \brief Get serialized CANN provider options string.
  3400. *
  3401. * \param[in] cann_options OrtCANNProviderOptions instance
  3402. * \param[in] allocator a ptr to an instance of OrtAllocator obtained with CreateAllocator()
  3403. * or GetAllocatorWithDefaultOptions(), the specified allocator will be used to allocate
  3404. * continuous buffers for output strings and lengths.
  3405. * \param[out] ptr is a UTF-8 null terminated string allocated using 'allocator'.
  3406. * The caller is responsible for using the same allocator to free it.
  3407. *
  3408. * \snippet{doc} snippets.dox OrtStatus Return Value
  3409. *
  3410. * \since Version 1.13.
  3411. */
  3412. ORT_API2_STATUS(GetCANNProviderOptionsAsString, _In_ const OrtCANNProviderOptions* cann_options,
  3413. _Inout_ OrtAllocator* allocator, _Outptr_ char** ptr);
  3414. /** \brief Release an OrtCANNProviderOptions
  3415. *
  3416. * \param[in] the pointer of OrtCANNProviderOptions which will been deleted
  3417. *
  3418. * \since Version 1.13.
  3419. */
  3420. void(ORT_API_CALL* ReleaseCANNProviderOptions)(_Frees_ptr_opt_ OrtCANNProviderOptions* input);
  3421. /* \brief Get OrtDevice type from MemoryInfo
  3422. *
  3423. * \since Version 1.14
  3424. */
  3425. void(ORT_API_CALL* MemoryInfoGetDeviceType)(_In_ const OrtMemoryInfo* ptr, _Out_ OrtMemoryInfoDeviceType* out);
  3426. /* \brief Update the OrtEnv instance with custom log severity level
  3427. *
  3428. * \param[in] ort_env The OrtEnv instance being used
  3429. * \param[in] log_severity_level The log severity level.
  3430. *
  3431. * \since Version 1.14.
  3432. */
  3433. ORT_API2_STATUS(UpdateEnvWithCustomLogLevel, _In_ OrtEnv* ort_env, OrtLoggingLevel log_severity_level);
  3434. /* \brief Set affinities for intra op threads
  3435. *
  3436. * Affinity string follows format:
  3437. * logical_processor_id,logical_processor_id;logical_processor_id,logical_processor_id
  3438. * Semicolon isolates configurations among threads, while comma split processors where ith thread expected to attach to.
  3439. * e.g. 1,2,3;4,5
  3440. * 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.
  3441. * To ease the configuration, an "interval" is also allowed:
  3442. * e.g. 1-8;8-16;17-24
  3443. * orders that the 1st thread runs on first eight processors, 2nd thread runs on next eight processors, and so forth.
  3444. * Note:
  3445. * 1. Once set, the number of thread affinities must equal to intra_op_num_threads - 1,
  3446. * ort does not set affinity on the main thread which is started and managed by the calling app;
  3447. * 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,
  3448. * 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.
  3449. * Hence 64-65 is an invalid configuration, because a windows thread cannot be attached to processors across group boundary.
  3450. *
  3451. * \since Version 1.14
  3452. */
  3453. ORT_API2_STATUS(SetGlobalIntraOpThreadAffinity, _Inout_ OrtThreadingOptions* tp_options, const char* affinity_string);
  3454. /** \brief Register custom ops from a shared library.
  3455. *
  3456. * Loads a shared library (.dll on windows, .so on linux, etc) named 'library_name' and looks for this entry point:
  3457. * OrtStatus* RegisterCustomOps(OrtSessionOptions * options, const OrtApiBase* api);
  3458. * It then passes in the provided session options to this function along with the api base.
  3459. *
  3460. * The handle to the loaded library is automatically released by ORT when the last OrtSession that references the
  3461. * library handle is released. If no OrtSession is created, then the library handle is released when the provided
  3462. * OrtSessionOptions is released.
  3463. *
  3464. * \param[in] options The session options.
  3465. * \param[in] library_name The name of the shared library to load and register. Refer to OS-specific dynamic library
  3466. * loading utilities (e.g., LoadLibraryEx on Windows or dlopen on Linux/MacOS) for information
  3467. * on the format of library names and search paths.
  3468. *
  3469. * \snippet{doc} snippets.dox OrtStatus Return Value
  3470. * \since Version 1.14
  3471. */
  3472. ORT_API2_STATUS(RegisterCustomOpsLibrary_V2, _Inout_ OrtSessionOptions* options, _In_ const ORTCHAR_T* library_name);
  3473. /** \brief Register custom ops by calling a RegisterCustomOpsFn function.
  3474. *
  3475. * Searches for registration_func_name and if found calls it.
  3476. *
  3477. * The library containing the function must either be linked against or previously loaded by the executable.
  3478. *
  3479. * If you want ONNX Runtime to load the library and manage its lifetime, use RegisterCustomOpsLibrary_V2.
  3480. *
  3481. * RegisterCustomOpsUsingFunction can be used in scenarios where it may not be possible for ONNX Runtime to load
  3482. * the library from a path. e.g. mobile platforms where the library must be linked into the app.
  3483. *
  3484. * The registration function must have the signature of RegisterCustomOpsFn:
  3485. * OrtStatus* (*fn)(OrtSessionOptions* options, const OrtApiBase* api);
  3486. *
  3487. * See https://onnxruntime.ai/docs/reference/operators/add-custom-op.html for details on how the registration
  3488. * function should be implemented.
  3489. *
  3490. * \param[in] options OrtSessionOptions that is passed through as the first argument in the call to the
  3491. * registration function.
  3492. * \param[in] registration_func_name Name of registration function to use.
  3493. *
  3494. * \snippet{doc} snippets.dox OrtStatus Return Value
  3495. * \since Version 1.14
  3496. */
  3497. ORT_API2_STATUS(RegisterCustomOpsUsingFunction, _Inout_ OrtSessionOptions* options,
  3498. _In_ const char* registration_func_name);
  3499. /// \name OrtKernelInfo
  3500. /// Custom operator APIs.
  3501. /// @{
  3502. /** \brief Get the number of inputs from ::OrtKernelInfo.
  3503. *
  3504. * Used in the CreateKernel callback of an OrtCustomOp to query the number of inputs
  3505. * during kernel/session creation.
  3506. *
  3507. * \param[in] info Instance of ::OrtKernelInfo.
  3508. * \param[out] out Pointer to variable assigned with the result on success.
  3509. *
  3510. * \snippet{doc} snippets.dox OrtStatus Return Value
  3511. * \since Version 1.14
  3512. */
  3513. ORT_API2_STATUS(KernelInfo_GetInputCount, _In_ const OrtKernelInfo* info, _Out_ size_t* out);
  3514. /** \brief Get the number of outputs from ::OrtKernelInfo.
  3515. *
  3516. * Used in the CreateKernel callback of an OrtCustomOp to query the number of outputs
  3517. * during kernel/session creation.
  3518. *
  3519. * \param[in] info Instance of ::OrtKernelInfo.
  3520. * \param[out] out Pointer to variable assigned with the result on success.
  3521. *
  3522. * \snippet{doc} snippets.dox OrtStatus Return Value
  3523. * \since Version 1.14
  3524. */
  3525. ORT_API2_STATUS(KernelInfo_GetOutputCount, _In_ const OrtKernelInfo* info, _Out_ size_t* out);
  3526. /** \brief Get the name of a ::OrtKernelInfo's input.
  3527. *
  3528. * Used in the CreateKernel callback of an OrtCustomOp to query an input's name
  3529. * during kernel/session creation.
  3530. *
  3531. * If `out` is nullptr, the value of `size` is set to the size of the name
  3532. * string (including null-terminator), and a success status is returned.
  3533. *
  3534. * If the `size` parameter is greater than or equal to the name string's size,
  3535. * the value of `size` is set to the true size of the string (including null-terminator),
  3536. * the provided memory is filled with the string's contents, and a success status is returned.
  3537. *
  3538. * If the `size` parameter is less than the actual string's size and `out`
  3539. * is not nullptr, the value of `size` is set to the true size of the string
  3540. * and a failure status is returned.
  3541. *
  3542. * \param[in] info An instance of ::OrtKernelInfo.
  3543. * \param[in] index The index of the input name to get. Returns a failure status if out-of-bounds.
  3544. * \param[out] out Memory location into which to write the UTF-8 null-terminated string representing the input's name.
  3545. * \param[in,out] size Pointer to the size of the `out` buffer. See above comments for details.
  3546. *
  3547. * \snippet{doc} snippets.dox OrtStatus Return Value
  3548. * \since Version 1.14
  3549. */
  3550. ORT_API2_STATUS(KernelInfo_GetInputName, _In_ const OrtKernelInfo* info, size_t index, _Out_ char* out,
  3551. _Inout_ size_t* size);
  3552. /** \brief Get the name of a ::OrtKernelInfo's output.
  3553. *
  3554. * Used in the CreateKernel callback of an OrtCustomOp to query an output's name
  3555. * during kernel/session creation.
  3556. *
  3557. * If `out` is nullptr, the value of `size` is set to the size of the name
  3558. * string (including null-terminator), and a success status is returned.
  3559. *
  3560. * If the `size` parameter is greater than or equal to the name string's size,
  3561. * the value of `size` is set to the true size of the string (including null-terminator),
  3562. * the provided memory is filled with the string's contents, and a success status is returned.
  3563. *
  3564. * If the `size` parameter is less than the actual string's size and `out`
  3565. * is not nullptr, the value of `size` is set to the true size of the string
  3566. * and a failure status is returned.
  3567. *
  3568. * \param[in] info An instance of ::OrtKernelInfo.
  3569. * \param[in] index The index of the output name to get. Returns a failure status if out-of-bounds.
  3570. * \param[out] out Memory location into which to write the UTF-8 null-terminated string representing the output's
  3571. * name.
  3572. * \param[in,out] size Pointer to the size of the `out` buffer. See above comments for details.
  3573. *
  3574. * \snippet{doc} snippets.dox OrtStatus Return Value
  3575. * \since Version 1.14
  3576. */
  3577. ORT_API2_STATUS(KernelInfo_GetOutputName, _In_ const OrtKernelInfo* info, size_t index, _Out_ char* out,
  3578. _Inout_ size_t* size);
  3579. /** \brief Get the type information for a ::OrtKernelInfo's input.
  3580. *
  3581. * Used in the CreateKernel callback of an OrtCustomOp to query the shape and type information
  3582. * of an input during kernel/session creation.
  3583. *
  3584. * \param[in] info An instance of ::OrtKernelInfo.
  3585. * \param[in] index Which input to get the type information for
  3586. * \param[out] type_info Pointer set to the resulting ::OrtTypeInfo. Must be freed with OrtApi::ReleaseTypeInfo.
  3587. *
  3588. * \snippet{doc} snippets.dox OrtStatus Return Value
  3589. * \since Version 1.14
  3590. */
  3591. ORT_API2_STATUS(KernelInfo_GetInputTypeInfo, _In_ const OrtKernelInfo* info, size_t index,
  3592. _Outptr_ OrtTypeInfo** type_info);
  3593. /** \brief Get the type information for a ::OrtKernelInfo's output.
  3594. *
  3595. * Used in the CreateKernel callback of an OrtCustomOp to query the shape and type information
  3596. * of an output during kernel/session creation.
  3597. *
  3598. * \param[in] info An instance of ::OrtKernelInfo.
  3599. * \param[in] index Which input to get the type information for
  3600. * \param[out] type_info Pointer set to the resulting ::OrtTypeInfo. Must be freed with OrtApi::ReleaseTypeInfo.
  3601. *
  3602. * \snippet{doc} snippets.dox OrtStatus Return Value
  3603. * \since Version 1.14
  3604. */
  3605. ORT_API2_STATUS(KernelInfo_GetOutputTypeInfo, _In_ const OrtKernelInfo* info, size_t index,
  3606. _Outptr_ OrtTypeInfo** type_info);
  3607. /** \brief Get a ::OrtValue tensor stored as an attribute in the graph node.
  3608. *
  3609. * Used in the CreateKernel callback of an OrtCustomOp to get a tensor attribute.
  3610. *
  3611. * \param[in] info ::OrtKernelInfo instance.
  3612. * \param[in] name UTF-8 null-terminated string representing the attribute's name.
  3613. * \param[in] allocator Allocator used to allocate the internal tensor state.
  3614. * \param[out] out Returns newly created ::OrtValue. Must be freed with OrtApi::ReleaseValue,
  3615. * which will also free internal tensor state allocated with the provided allocator.
  3616. *
  3617. * \snippet{doc} snippets.dox OrtStatus Return Value
  3618. */
  3619. ORT_API2_STATUS(KernelInfoGetAttribute_tensor, _In_ const OrtKernelInfo* info, _In_z_ const char* name,
  3620. _Inout_ OrtAllocator* allocator, _Outptr_ OrtValue** out);
  3621. /// @}
  3622. /// \name OrtSessionOptions
  3623. /// Custom operator APIs
  3624. /// @{
  3625. /** \brief Checks if the given session configuration entry exists.
  3626. *
  3627. * The config_key formats are defined in onnxruntime_session_options_config_keys.h
  3628. *
  3629. * Can be used in a custom operator library to check for session configuration entries
  3630. * that target one or more custom operators in the library. Example: The config entry
  3631. * custom_op.myop.some_key targets a custom op named "myop".
  3632. *
  3633. * \param[in] options The ::OrtSessionOptions instance.
  3634. * \param[in] config_key A null-terminated UTF-8 string representation of the configuration key.
  3635. * \param[out] out Pointer set to 1 if the entry exists and 0 otherwise.
  3636. *
  3637. * \snippet{doc} snippets.dox OrtStatus Return Value
  3638. * \since Version 1.14
  3639. */
  3640. ORT_API2_STATUS(HasSessionConfigEntry, _In_ const OrtSessionOptions* options,
  3641. _In_z_ const char* config_key, _Out_ int* out);
  3642. /** \brief Get a session configuration value.
  3643. *
  3644. * Returns a failure status if the configuration key does not exist.
  3645. * The config_key and the format of config_value are defined in onnxruntime_session_options_config_keys.h
  3646. *
  3647. * If `config_value` is nullptr, the value of `size` is set to the true size of the string
  3648. * value (including null-terminator), and a success status is returned.
  3649. *
  3650. * If the `size` parameter is greater than or equal to the actual string value's size,
  3651. * the value of `size` is set to the true size of the string value, the provided memory
  3652. * is filled with the value's contents, and a success status is returned.
  3653. *
  3654. * If the `size` parameter is less than the actual string value's size and `config_value`
  3655. * is not nullptr, the value of `size` is set to the true size of the string value
  3656. * and a failure status is returned.
  3657. *
  3658. * Can be used in a custom operator library to get session configuration entries
  3659. * that target one or more custom operators in the library. Example: The config entry
  3660. * custom_op.myop.some_key targets a custom op named "myop".
  3661. *
  3662. * \param[in] options The session options.
  3663. * \param[in] config_key A null-terminated UTF-8 string representation of the config key.
  3664. * \param[in] config_value Pointer to memory where the null-terminated UTF-8 string value will be stored.
  3665. * \param[in,out] size Pointer to the size of the `config_value` buffer. See above comments for details.
  3666. *
  3667. * \snippet{doc} snippets.dox OrtStatus Return Value
  3668. * \since Version 1.14
  3669. */
  3670. ORT_API2_STATUS(GetSessionConfigEntry, _In_ const OrtSessionOptions* options,
  3671. _In_z_ const char* config_key, _Out_ char* config_value, _Inout_ size_t* size);
  3672. /// @}
  3673. /** \brief Append dnnl provider to session options
  3674. *
  3675. * If oneDNN is not available, this function will return failure.
  3676. *
  3677. * \param[in] options
  3678. * \param[in] dnnl_options
  3679. *
  3680. * \snippet{doc} snippets.dox OrtStatus Return Value
  3681. *
  3682. * \since Version 1.15.
  3683. */
  3684. ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_Dnnl,
  3685. _In_ OrtSessionOptions* options, _In_ const OrtDnnlProviderOptions* dnnl_options);
  3686. /** \brief Create an OrtDnnlProviderOptions
  3687. *
  3688. * \param[out] out Newly created ::OrtDnnlProviderOptions. Must be released with OrtApi::ReleaseDnnlProviderOptions
  3689. *
  3690. * \snippet{doc} snippets.dox OrtStatus Return Value
  3691. *
  3692. * \since Version 1.15.
  3693. */
  3694. ORT_API2_STATUS(CreateDnnlProviderOptions, _Outptr_ OrtDnnlProviderOptions** out);
  3695. /** \brief Set options in a oneDNN Execution Provider.
  3696. *
  3697. * Key should be in null terminated string format of the member of ::OrtDnnlProviderOptions
  3698. * and value should be its related range.
  3699. *
  3700. * For example, key="use_arena" and value="1"
  3701. *
  3702. * \param[in] dnnl_options
  3703. * \param[in] provider_options_keys Array of UTF-8 null-terminated string for provider options keys
  3704. * \param[in] provider_options_values Array of UTF-8 null-terminated string for provider options values
  3705. * \param[in] num_keys Number of elements in the `provider_option_keys` and `provider_options_values` arrays
  3706. *
  3707. * \snippet{doc} snippets.dox OrtStatus Return Value
  3708. *
  3709. * \since Version 1.15.
  3710. */
  3711. ORT_API2_STATUS(UpdateDnnlProviderOptions, _Inout_ OrtDnnlProviderOptions* dnnl_options,
  3712. _In_reads_(num_keys) const char* const* provider_options_keys,
  3713. _In_reads_(num_keys) const char* const* provider_options_values,
  3714. _In_ size_t num_keys);
  3715. /**
  3716. * Get serialized oneDNN provider options string.
  3717. *
  3718. * For example, "use_arena=1;......"
  3719. *
  3720. * \param dnnl_options - OrtDnnlProviderOptions instance
  3721. * \param allocator - a ptr to an instance of OrtAllocator obtained with CreateAllocator() or GetAllocatorWithDefaultOptions()
  3722. * the specified allocator will be used to allocate continuous buffers for output strings and lengths.
  3723. * \param ptr - is a UTF-8 null terminated string allocated using 'allocator'. The caller is responsible for using the same allocator to free it.
  3724. *
  3725. * \snippet{doc} snippets.dox OrtStatus Return Value
  3726. *
  3727. * \since Version 1.15.
  3728. */
  3729. ORT_API2_STATUS(GetDnnlProviderOptionsAsString, _In_ const OrtDnnlProviderOptions* dnnl_options, _Inout_ OrtAllocator* allocator, _Outptr_ char** ptr);
  3730. /** \brief Release an ::OrtDnnlProviderOptions
  3731. *
  3732. * \since Version 1.15.
  3733. */
  3734. void(ORT_API_CALL* ReleaseDnnlProviderOptions)(_Frees_ptr_opt_ OrtDnnlProviderOptions* input);
  3735. /// \name OrtKernelInfo
  3736. /// Custom operator APIs.
  3737. /// @{
  3738. /** \brief Get the graph node name from ::OrtKernelInfo.
  3739. *
  3740. * If `out` is nullptr, the value of `size` is set to the size of the name
  3741. * string (including null-terminator), and a success status is returned.
  3742. *
  3743. * If the `size` parameter is greater than or equal to the name string's size,
  3744. * the value of `size` is set to the true size of the string (including null-terminator),
  3745. * the provided memory is filled with the string's contents, and a success status is returned.
  3746. *
  3747. * If the `size` parameter is less than the actual string's size and `out`
  3748. * is not nullptr, the value of `size` is set to the true size of the string
  3749. * and a failure status is returned.
  3750. *
  3751. * Can be used in a custom operator's CreateKernel callback to get the name of the operator's node name in the graph.
  3752. *
  3753. * \param[in] info An instance of ::OrtKernelInfo.
  3754. * \param[out] out Memory location into which to write the UTF-8 null-terminated string representing the name.
  3755. * \param[in,out] size Pointer to the size of the `out` buffer. See above comments for details.
  3756. *
  3757. * \snippet{doc} snippets.dox OrtStatus Return Value
  3758. * \since Version 1.15
  3759. */
  3760. ORT_API2_STATUS(KernelInfo_GetNodeName, _In_ const OrtKernelInfo* info, _Out_ char* out, _Inout_ size_t* size);
  3761. /** \brief Get the session logger from ::OrtKernelInfo.
  3762. *
  3763. * Used in the CreateKernel callback of an OrtCustomOp to get a logger that can be used to log
  3764. * messages.
  3765. *
  3766. * \param[in] info An instance of ::OrtKernelInfo.
  3767. * \param[out] logger Pointer set to the session's ::OrtLogger. Owned by ONNX Runtime, so do not free.
  3768. *
  3769. * \snippet{doc} snippets.dox OrtStatus Return Value
  3770. * \since Version 1.15
  3771. */
  3772. ORT_API2_STATUS(KernelInfo_GetLogger, _In_ const OrtKernelInfo* info, _Outptr_ const OrtLogger** logger);
  3773. /// @}
  3774. /// \name OrtKernelContext
  3775. /// Custom operator APIs.
  3776. /// @{
  3777. /** \brief Get the runtime logger from ::OrtKernelContext.
  3778. *
  3779. * Used in the KernelCompute callback of an OrtCustomOp to get a logger that can be used to log
  3780. * messages during inference.
  3781. *
  3782. * \param[in] context An instance of ::OrtKernelContext.
  3783. * \param[out] logger Pointer set to the kernel context's ::OrtLogger. Owned by ONNX Runtime, so do not free.
  3784. *
  3785. * \snippet{doc} snippets.dox OrtStatus Return Value
  3786. * \since Version 1.15
  3787. */
  3788. ORT_API2_STATUS(KernelContext_GetLogger, _In_ const OrtKernelContext* context, _Outptr_ const OrtLogger** logger);
  3789. /// @}
  3790. /// \name OrtLogger
  3791. /// Custom operator APIs.
  3792. /// @{
  3793. /** \brief Logs a message at the given severity level using the provided ::OrtLogger.
  3794. *
  3795. * Only messages with a severity level equal or greater than the ::OrtLogger's logging severity level
  3796. * are logged. Use OrtApi::Logger_GetLoggingSeverityLevel to get the ::OrtLogger's logging severity
  3797. * level.
  3798. *
  3799. * Can be used in custom operators to log messages with the logger retrieved via OrtApi::KernelInfo_GetLogger.
  3800. *
  3801. * \param[in] logger The ::OrtLogger instance.
  3802. * \param[in] log_severity_level The message's severity level.
  3803. * \param[in] message The message to log.
  3804. * \param[in] file_path The filepath of the file in which the message is logged. Usually the value of ORT_FILE.
  3805. * \param[in] line_number The file line number in which the message is logged. Usually the value of __LINE__.
  3806. * \param[in] func_name The name of the function in which the message is logged. Usually the value of __FUNCTION__.
  3807. *
  3808. * \snippet{doc} snippets.dox OrtStatus Return Value
  3809. * \since Version 1.15
  3810. */
  3811. ORT_API2_STATUS(Logger_LogMessage, _In_ const OrtLogger* logger, OrtLoggingLevel log_severity_level,
  3812. _In_z_ const char* message, _In_z_ const ORTCHAR_T* file_path, int line_number,
  3813. _In_z_ const char* func_name);
  3814. /** \brief Get the logging severity level of the ::OrtLogger.
  3815. *
  3816. * Can be used in a custom operator to get the logging serverity level of the ::OrtLogger associated with
  3817. * the ::OrtKernelInfo.
  3818. *
  3819. * \param[in] logger The ::OrtLogger instance.
  3820. * \param[out] out Pointer to variable assigned with the logging severity level on success.
  3821. *
  3822. * \snippet{doc} snippets.dox OrtStatus Return Value
  3823. * \since Version 1.15
  3824. */
  3825. ORT_API2_STATUS(Logger_GetLoggingSeverityLevel, _In_ const OrtLogger* logger, _Out_ OrtLoggingLevel* out);
  3826. /// @}
  3827. /** \brief Get a ::OrtValue tensor stored as a constant initializer in the graph node.
  3828. *
  3829. * Used in the CreateKernel callback of an OrtCustomOp to get a tensor value.
  3830. *
  3831. * \param[in] info ::OrtKernelInfo instance.
  3832. * \param[in] index The node index.
  3833. * \param[out] is_constant Is it a constant node input or not.
  3834. * \param[out] out The OrtValue tensor value.
  3835. *
  3836. * \snippet{doc} snippets.dox OrtStatus Return Value
  3837. *
  3838. * \since Version 1.15.
  3839. */
  3840. ORT_API2_STATUS(KernelInfoGetConstantInput_tensor, _In_ const OrtKernelInfo* info, size_t index, _Out_ int* is_constant, _Outptr_ const OrtValue** out);
  3841. /** \brief Get Optional Type information from an ::OrtTypeInfo
  3842. *
  3843. * This augments ::OrtTypeInfo to return an ::OrtOptionalTypeInfo when the type is optional.
  3844. * The OrtOptionalTypeInfo also has a nested ::OrtTypeInfo that describes the type of the optional value.
  3845. * ::OrtOptionalTypeInfo type can only appear within model metadata to describe inputs/outputs.
  3846. * The actual OrtValues that are supplied in place of optional type inputs should contain
  3847. * specific type that is described by ::OrtOptionalTypeInfo.
  3848. *
  3849. * So the picture: ::OrtTypeInfo -> ::OrtOptionalTypeInfo -> ::OrtTypeInfo (describes the type that can be supplied
  3850. * in place of the optional type when creating the actual ::OrtValue).
  3851. *
  3852. * \param[in] type_info
  3853. * \param[out] out A pointer to the ::OrtOptionalTypeInfo. Do not free this value,
  3854. * it is owned by OrtTypeInfo instance. When the type_info does not represent
  3855. * optional type, nullptr is returned in out.
  3856. *
  3857. * \snippet{doc} snippets.dox OrtStatus Return Value
  3858. *
  3859. * \since Version 1.15.
  3860. */
  3861. ORT_API2_STATUS(CastTypeInfoToOptionalTypeInfo, _In_ const OrtTypeInfo* type_info,
  3862. _Outptr_result_maybenull_ const OrtOptionalTypeInfo** out);
  3863. /** \brief Get OrtTypeInfo for the allowed contained type from an ::OrtOptionalTypeInfo.
  3864. *
  3865. * This augments ::OrtOptionalTypeInfo to return an ::OrtTypeInfo for the contained type.
  3866. * The OrtOptionalTypeInfo has a nested ::OrtTypeInfo that describes the type of the optional value.
  3867. * ::OrtOptionalTypeInfo type can only appear within model metadata to describe inputs/outputs.
  3868. * The actual OrtValues that are supplied in place of optional type inputs should contain
  3869. * specific type that is described by the returned ::OrtTypeInfo.
  3870. *
  3871. * \param[in] optional_type_info
  3872. * \param[out] out A pointer to the ::OrtTypeInfo for what the optional value could be.
  3873. * it is owned by OrtOptionalTypeInfo instance.
  3874. *
  3875. * \snippet{doc} snippets.dox OrtStatus Return Value
  3876. *
  3877. * \since Version 1.15.
  3878. */
  3879. ORT_API2_STATUS(GetOptionalContainedTypeInfo, _In_ const OrtOptionalTypeInfo* optional_type_info,
  3880. _Outptr_ OrtTypeInfo** out);
  3881. /** \brief Set a single string in a string tensor
  3882. * Do not zero terminate the string data.
  3883. *
  3884. * \param[in] value A string tensor
  3885. * \param[in] index - flat index of the element
  3886. * \param[in] length_in_bytes length of the buffer in utf-8 bytes (without the null terminator)
  3887. * \param[inout] buffer - address of return value
  3888. *
  3889. * \snippet{doc} snippets.dox OrtStatus Return Value
  3890. */
  3891. ORT_API2_STATUS(GetResizedStringTensorElementBuffer, _Inout_ OrtValue* value, _In_ size_t index, _In_ size_t length_in_bytes, _Inout_ char** buffer);
  3892. /** \brief Get Allocator from KernelContext for a specific memoryInfo. Please use C API ReleaseAllocator to release out object
  3893. *
  3894. * \param[in] context OrtKernelContext instance
  3895. * \param[in] mem_info OrtMemoryInfo instance
  3896. * \param[out] out A pointer to OrtAllocator.
  3897. *
  3898. * \snippet{doc} snippets.dox OrtStatus Return Value
  3899. *
  3900. * \since Version 1.15.
  3901. */
  3902. ORT_API2_STATUS(KernelContext_GetAllocator, _In_ const OrtKernelContext* context, _In_ const OrtMemoryInfo* mem_info, _Outptr_ OrtAllocator** out);
  3903. /** \brief Returns a null terminated string of the build info including git info and cxx flags
  3904. *
  3905. * \return UTF-8 encoded version string. Do not deallocate the returned buffer.
  3906. *
  3907. * \since Version 1.15.
  3908. */
  3909. const char*(ORT_API_CALL* GetBuildInfoString)(void);
  3910. /// \name OrtROCMProviderOptions
  3911. /// @{
  3912. /** \brief Create an OrtROCMProviderOptions
  3913. *
  3914. * \param[out] out Newly created ::OrtROCMProviderOptions. Must be released with OrtApi::ReleaseROCMProviderOptions
  3915. *
  3916. * \snippet{doc} snippets.dox OrtStatus Return Value
  3917. *
  3918. * \since Version 1.16.
  3919. */
  3920. ORT_API2_STATUS(CreateROCMProviderOptions, _Outptr_ OrtROCMProviderOptions** out);
  3921. /** \brief Set options in a ROCm Execution Provider.
  3922. *
  3923. * Please refer to https://onnxruntime.ai/docs/execution-providers/ROCm-ExecutionProvider.html
  3924. * to know the available keys and values. Key should be in null terminated string format of the member of
  3925. * ::OrtROCMProviderOptions and value should be its related range.
  3926. *
  3927. * For example, key="device_id" and value="0"
  3928. *
  3929. * \param[in] rocm_options
  3930. * \param[in] provider_options_keys Array of UTF-8 null-terminated string for provider options keys
  3931. * \param[in] provider_options_values Array of UTF-8 null-terminated string for provider options values
  3932. * \param[in] num_keys Number of elements in the `provider_option_keys` and `provider_options_values` arrays
  3933. *
  3934. * \snippet{doc} snippets.dox OrtStatus Return Value
  3935. *
  3936. * \since Version 1.16.
  3937. */
  3938. ORT_API2_STATUS(UpdateROCMProviderOptions, _Inout_ OrtROCMProviderOptions* rocm_options,
  3939. _In_reads_(num_keys) const char* const* provider_options_keys,
  3940. _In_reads_(num_keys) const char* const* provider_options_values,
  3941. _In_ size_t num_keys);
  3942. /**
  3943. * Get serialized ROCm provider options string.
  3944. *
  3945. * For example, "device_id=0;arena_extend_strategy=0;......"
  3946. *
  3947. * \param rocm_options - OrtROCMProviderOptions instance
  3948. * \param allocator - a ptr to an instance of OrtAllocator obtained with CreateAllocator() or GetAllocatorWithDefaultOptions()
  3949. * the specified allocator will be used to allocate continuous buffers for output strings and lengths.
  3950. * \param ptr - is a UTF-8 null terminated string allocated using 'allocator'. The caller is responsible for using the same allocator to free it.
  3951. *
  3952. * \snippet{doc} snippets.dox OrtStatus Return Value
  3953. *
  3954. * \since Version 1.16.
  3955. */
  3956. ORT_API2_STATUS(GetROCMProviderOptionsAsString, _In_ const OrtROCMProviderOptions* rocm_options, _Inout_ OrtAllocator* allocator, _Outptr_ char** ptr);
  3957. /** \brief Release an ::OrtROCMProviderOptions
  3958. *
  3959. * \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
  3960. *
  3961. * \since Version 1.16.
  3962. */
  3963. void(ORT_API_CALL* ReleaseROCMProviderOptions)(_Frees_ptr_opt_ OrtROCMProviderOptions* input);
  3964. /** \brief Create an allocator with specific type and register it with the ::OrtEnv
  3965. * This API enhance CreateAndRegisterAllocator that it can create an allocator with specific type, not just CPU allocator
  3966. * Enables sharing the allocator between multiple sessions that use the same env instance.
  3967. * Lifetime of the created allocator will be valid for the duration of the environment.
  3968. * Returns an error if an allocator with the same ::OrtMemoryInfo is already registered.
  3969. * \param[in] env OrtEnv instance
  3970. * \param[in] provider_type ExecutionProvider type
  3971. * \param[in] mem_info OrtMemoryInfo instance
  3972. * \param[in] arena_cfg Arena configuration
  3973. * \param[in] provider_options_keys key of the provider options map
  3974. * \param[in] provider_options_values value of the provider options map
  3975. * \param[in] num_keys Length of the provider options map
  3976. */
  3977. ORT_API2_STATUS(CreateAndRegisterAllocatorV2, _Inout_ OrtEnv* env, _In_ const char* provider_type, _In_ const OrtMemoryInfo* mem_info, _In_ const OrtArenaCfg* arena_cfg,
  3978. _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);
  3979. /** \brief Run the model asynchronously in a thread owned by intra op thread pool
  3980. *
  3981. * \param[in] session
  3982. * \param[in] run_options If nullptr, will use a default ::OrtRunOptions
  3983. * \param[in] input_names Array of null terminated UTF8 encoded strings of the input names
  3984. * \param[in] input Array of ::OrtValue%s of the input values
  3985. * \param[in] input_len Number of elements in the input_names and inputs arrays
  3986. * \param[in] output_names Array of null terminated UTF8 encoded strings of the output names
  3987. * \param[in] output_names_len Number of elements in the output_names and outputs array
  3988. * \param[out] output OrtValue* array of size output_names_len.
  3989. * On calling RunAsync, output[i] could either be a null or a pointer to a preallocated OrtValue.
  3990. * Later, the output array will be passed to run_async_callback with all null(s) filled with valid
  3991. * OrtValue pointer(s) allocated by onnxruntime.
  3992. * NOTE: it is customer's duty to finally release the output array and each of its member,
  3993. * regardless of whether the member (OrtValue*) is allocated by onnxruntime or preallocated by the customer.
  3994. * \param[in] run_async_callback Callback function on model run completion
  3995. * \param[in] user_data User data that pass back to run_async_callback
  3996. */
  3997. ORT_API2_STATUS(RunAsync, _Inout_ OrtSession* session, _In_opt_ const OrtRunOptions* run_options,
  3998. _In_reads_(input_len) const char* const* input_names,
  3999. _In_reads_(input_len) const OrtValue* const* input, size_t input_len,
  4000. _In_reads_(output_names_len) const char* const* output_names, size_t output_names_len,
  4001. _Inout_updates_all_(output_names_len) OrtValue** output,
  4002. _In_ RunAsyncCallbackFn run_async_callback, _In_opt_ void* user_data);
  4003. /**
  4004. * Update TensorRT EP provider option where its data type is pointer, for example 'user_compute_stream'.
  4005. * If the data type of the provider option can be represented by string please use UpdateTensorRTProviderOptions.
  4006. *
  4007. * Note: It's caller's responsibility to properly manage the lifetime of the instance pointed by this pointer.
  4008. *
  4009. * \param tensorrt_options - OrtTensorRTProviderOptionsV2 instance
  4010. * \param key - Name of the provider option
  4011. * \param value - A pointer to the instance that will be assigned to this provider option
  4012. *
  4013. * \since Version 1.16.
  4014. */
  4015. ORT_API2_STATUS(UpdateTensorRTProviderOptionsWithValue, _Inout_ OrtTensorRTProviderOptionsV2* tensorrt_options, _In_ const char* key, _In_ void* value);
  4016. /**
  4017. * Get TensorRT EP provider option where its data type is pointer.
  4018. * If the data type of the provider option can be represented by string please use GetTensorRTProviderOptionsAsString.
  4019. *
  4020. * \param tensorrt_options - OrtTensorRTProviderOptionsV2 instance
  4021. * \param key - Name of the provider option
  4022. * \param ptr - A pointer to the instance that is kept by the provider option
  4023. *
  4024. * \since Version 1.16.
  4025. */
  4026. ORT_API2_STATUS(GetTensorRTProviderOptionsByName, _In_ const OrtTensorRTProviderOptionsV2* tensorrt_options, _In_ const char* key, _Outptr_ void** ptr);
  4027. /**
  4028. * Update CUDA EP provider option where its data type is pointer, for example 'user_compute_stream'.
  4029. * If the data type of the provider option can be represented by string please use UpdateCUDAProviderOptions.
  4030. *
  4031. * Note: It's caller's responsibility to properly manage the lifetime of the instance pointed by this pointer.
  4032. *
  4033. * \param cuda_options - OrtCUDAProviderOptionsV2 instance
  4034. * \param key - Name of the provider option
  4035. * \param value - A pointer to the instance that will be assigned to this provider option
  4036. *
  4037. * \since Version 1.16.
  4038. */
  4039. ORT_API2_STATUS(UpdateCUDAProviderOptionsWithValue, _Inout_ OrtCUDAProviderOptionsV2* cuda_options, _In_ const char* key, _In_ void* value);
  4040. /**
  4041. * Get CUDA EP provider option where its data type is pointer.
  4042. * If the data type of the provider option can be represented by string please use GetCUDAProviderOptionsAsString.
  4043. *
  4044. * \param cuda_options - OrtCUDAProviderOptionsV2 instance
  4045. * \param key - Name of the provider option
  4046. * \param ptr - A pointer to the instance that is kept by the provider option
  4047. *
  4048. * \since Version 1.16.
  4049. */
  4050. ORT_API2_STATUS(GetCUDAProviderOptionsByName, _In_ const OrtCUDAProviderOptionsV2* cuda_options, _In_ const char* key, _Outptr_ void** ptr);
  4051. /**
  4052. * Get a EP resource.
  4053. * E.g. a cuda stream or a cublas handle
  4054. *
  4055. * \param context - Kernel context
  4056. * \param resouce_version - Version of the resource
  4057. * \param resource_id - Type of resource
  4058. * \param resource - A pointer to returned resource
  4059. *
  4060. * \since Version 1.16.
  4061. */
  4062. ORT_API2_STATUS(KernelContext_GetResource, _In_ const OrtKernelContext* context, _In_ int resouce_version, _In_ int resource_id, _Outptr_ void** resource);
  4063. /** \brief Set user logging function
  4064. *
  4065. * By default the logger created by the CreateEnv* functions is used to create the session logger as well.
  4066. * This function allows a user to override this default session logger with a logger of their own choosing. This way
  4067. * the user doesn't have to create a separate environment with a custom logger. This addresses the problem when
  4068. * the user already created an env but now wants to use a different logger for a specific session (for debugging or
  4069. * other reasons).
  4070. *
  4071. * \param[in] options
  4072. * \param[in] user_logging_function A pointer to a logging function.
  4073. * \param[in] user_logging_param A pointer to arbitrary data passed as the ::OrtLoggingFunction `param` parameter to
  4074. * `user_logging_function`. This parameter is optional.
  4075. *
  4076. * \snippet{doc} snippets.dox OrtStatus Return Value
  4077. *
  4078. * \since Version 1.17.
  4079. */
  4080. ORT_API2_STATUS(SetUserLoggingFunction, _Inout_ OrtSessionOptions* options,
  4081. _In_ OrtLoggingFunction user_logging_function, _In_opt_ void* user_logging_param);
  4082. /**
  4083. * Get number of input from OrtShapeInferContext
  4084. *
  4085. * \param[in] context
  4086. * \param[out] out The number of inputs
  4087. *
  4088. * \since Version 1.17.
  4089. */
  4090. ORT_API2_STATUS(ShapeInferContext_GetInputCount, _In_ const OrtShapeInferContext* context, _Out_ size_t* out);
  4091. /**
  4092. * Get type and shape info of an input
  4093. *
  4094. * \param[in] context
  4095. * \param[in] index The index of the input
  4096. * \param[out] info Type shape info of the input
  4097. *
  4098. * \since Version 1.17.
  4099. */
  4100. ORT_API2_STATUS(ShapeInferContext_GetInputTypeShape, _In_ const OrtShapeInferContext* context, _In_ size_t index, _Outptr_ OrtTensorTypeAndShapeInfo** info);
  4101. /**
  4102. * Get attribute from OrtShapeInferContext. Note that OrtShapeInferContext is a per-node context, one could only read attribute from current node.
  4103. *
  4104. * \param[in] context
  4105. * \param[in] attr_name Name of the attribute
  4106. * \param[out] attr Handle of the attribute fetched
  4107. *
  4108. * \since Version 1.17.
  4109. */
  4110. ORT_API2_STATUS(ShapeInferContext_GetAttribute, _In_ const OrtShapeInferContext* context, _In_ const char* attr_name, _Outptr_ const OrtOpAttr** attr);
  4111. /**
  4112. * Set type and shape info of an ouput
  4113. *
  4114. * \param[in] context
  4115. * \param[in] index The index of the ouput
  4116. * \param[out] info Type shape info of the output
  4117. *
  4118. * \since Version 1.17.
  4119. */
  4120. ORT_API2_STATUS(ShapeInferContext_SetOutputTypeShape, _In_ const OrtShapeInferContext* context, _In_ size_t index, _In_ const OrtTensorTypeAndShapeInfo* info);
  4121. /**
  4122. * Set symbolic shape to type shape info
  4123. *
  4124. * \param[in] info Type shape info
  4125. * \param[in] dim_params Symbolic strings
  4126. * \param[in] dim_params_length Number of strings
  4127. *
  4128. * \since Version 1.17.
  4129. */
  4130. ORT_API2_STATUS(SetSymbolicDimensions, _In_ OrtTensorTypeAndShapeInfo* info, _In_ const char* dim_params[], _In_ size_t dim_params_length);
  4131. /**
  4132. * Read contents of an attribute to data
  4133. *
  4134. * \param[in] op_attr
  4135. * \param[in] type Attribute type
  4136. * \param[out] data Memory address to save raw content of the attribute
  4137. * \param[in] len Number of bytes allowed to store in data
  4138. * \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
  4139. *
  4140. * \since Version 1.17.
  4141. */
  4142. ORT_API2_STATUS(ReadOpAttr, _In_ const OrtOpAttr* op_attr, _In_ OrtOpAttrType type, _Inout_ void* data, _In_ size_t len, _Out_ size_t* out);
  4143. /** \brief Set whether to use deterministic compute.
  4144. *
  4145. * Default is false. If set to true, this will enable deterministic compute for GPU kernels where possible.
  4146. * Note that this most likely will have a performance cost.
  4147. *
  4148. * \param[in] options
  4149. * \param[in] value
  4150. *
  4151. * \since Version 1.17.
  4152. */
  4153. ORT_API2_STATUS(SetDeterministicCompute, _Inout_ OrtSessionOptions* options, bool value);
  4154. /**
  4155. * Run fn in parallel
  4156. *
  4157. * \param[in] context
  4158. * \param[in] fn Function accepting usr_data and an integer as iterator
  4159. * \param[in] total The number of times fn is to be invoked
  4160. * \param[in] num_batch Number of batches by which the "total" is to be divided in maximum. When zero, there is no limit
  4161. * \param[in] usr_data User data to be passed back to fn
  4162. *
  4163. * \since Version 1.17.
  4164. */
  4165. 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);
  4166. /** \brief Append OpenVINO execution provider to the session options
  4167. *
  4168. * 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.
  4169. *
  4170. * \param[in] options
  4171. * \param[in] provider_options_keys
  4172. * \param[in] provider_options_values
  4173. * \param[in] num_keys
  4174. *
  4175. * \snippet{doc} snippets.dox OrtStatus Return Value
  4176. */
  4177. ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_OpenVINO_V2,
  4178. _In_ OrtSessionOptions* options,
  4179. _In_reads_(num_keys) const char* const* provider_options_keys,
  4180. _In_reads_(num_keys) const char* const* provider_options_values,
  4181. _In_ size_t num_keys);
  4182. /** \brief Append VitisAI provider to session options
  4183. *
  4184. * 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.
  4185. *
  4186. * \param[in] options
  4187. * \param[in] provider_options_keys
  4188. * \param[in] provider_options_values
  4189. * \param[in] num_keys
  4190. *
  4191. * \snippet{doc} snippets.dox OrtStatus Return Value
  4192. */
  4193. ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_VitisAI,
  4194. _In_ OrtSessionOptions* options,
  4195. _In_reads_(num_keys) const char* const* provider_options_keys,
  4196. _In_reads_(num_keys) const char* const* provider_options_values,
  4197. _In_ size_t num_keys);
  4198. /** \brief Get scratch buffer from the corresponding allocator under the sepcific OrtMemoryInfo object.
  4199. * NOTE: callers are responsible to release this scratch buffer from the corresponding allocator
  4200. * \param[in] context OrtKernelContext instance
  4201. * \param[in] mem_info OrtMemoryInfo instance
  4202. * \param[in] count_or_bytes How many bytes is this scratch buffer
  4203. * \param[out] out A pointer to the scrach buffer
  4204. * \snippet{doc} snippets.dox OrtStatus Return Value
  4205. */
  4206. ORT_API2_STATUS(KernelContext_GetScratchBuffer, _In_ const OrtKernelContext* context, _In_ const OrtMemoryInfo* mem_info, _In_ size_t count_or_bytes, _Outptr_ void** out);
  4207. /** \brief Get allocator from KernelInfo for a specific memory type. Please use C API ReleaseAllocator to release out object
  4208. *
  4209. * \param[in] info OrtKernelInfo instance
  4210. * \param[in] mem_type OrtMemType object
  4211. * \param[out] out A pointer to OrtAllocator
  4212. *
  4213. * \snippet{doc} snippets.dox OrtStatus Return Value
  4214. */
  4215. ORT_API2_STATUS(KernelInfoGetAllocator, _In_ const OrtKernelInfo* info, _In_ OrtMemType mem_type, _Outptr_ OrtAllocator** out);
  4216. /** \brief Replace initialized Tensors with external data with the provided files in memory
  4217. *
  4218. * The function will find the initialized TensorProtos with external data in the graph with the provided
  4219. * external file names and the file content in memory. The API gets the external file name, offset, data length
  4220. * from TensorProto, and locate the tensor data from the file in memory buffer.
  4221. * It creates a Tensor to replace the existing Tensor in graph. The replacement
  4222. * will occur before any of the optimizations take place. The data will be copied into the graph
  4223. * since TensorProto can't refer to the user provided buffers.
  4224. *
  4225. * \param[in] session options
  4226. * \param[in] external_initializer_file_names Array of null terminated UTF-8 encoded strings of the file names
  4227. * which holds the external initializers.
  4228. * \param[in] external_initializer_file_buffer_array Array of pointers to the buffer of the file content.
  4229. * The buffer can be freed after session creation.
  4230. * \param[in] external_initializer_file_lengths Array of size_t to indicate the length of file content
  4231. * \param[in] num_external_initializer_files Number of external files
  4232. *
  4233. * \snippet{doc} snippets.dox OrtStatus Return Value
  4234. */
  4235. ORT_API2_STATUS(AddExternalInitializersFromFilesInMemory, _In_ OrtSessionOptions* options,
  4236. _In_reads_(num_external_initializer_files) const ORTCHAR_T* const* external_initializer_file_names,
  4237. _In_reads_(num_external_initializer_files) char* const* external_initializer_file_buffer_array,
  4238. _In_reads_(num_external_initializer_files) const size_t* external_initializer_file_lengths,
  4239. size_t num_external_initializer_files);
  4240. };
  4241. /*
  4242. * Steps to use a custom op:
  4243. * 1 Create an OrtCustomOpDomain with the domain name used by the custom ops
  4244. * 2 Create an OrtCustomOp structure for each op and add them to the domain
  4245. * 3 Call OrtAddCustomOpDomain to add the custom domain of ops to the session options
  4246. */
  4247. // Specifies some characteristics of inputs/outputs of custom ops:
  4248. // Specify if the inputs/outputs are one of:
  4249. // 1) Non-optional (input/output must be present in the node)
  4250. // 2) Optional (input/output may be absent in the node)
  4251. // 3) Variadic: A variadic input or output specifies N (i.e., the minimum arity) or more operands.
  4252. // Only the last input or output of a custom op may be marked as variadic.
  4253. // The homogeneity of the variadic input or output determines whether all operands must be of the same
  4254. // tensor element type.
  4255. typedef enum OrtCustomOpInputOutputCharacteristic {
  4256. INPUT_OUTPUT_REQUIRED = 0,
  4257. INPUT_OUTPUT_OPTIONAL,
  4258. INPUT_OUTPUT_VARIADIC,
  4259. } OrtCustomOpInputOutputCharacteristic;
  4260. /*
  4261. * The OrtCustomOp structure defines a custom op's schema and its kernel callbacks. The callbacks are filled in by
  4262. * the implementor of the custom op.
  4263. */
  4264. struct OrtCustomOp {
  4265. uint32_t version; // Must be initialized to ORT_API_VERSION
  4266. // This callback creates the kernel, which is a user defined
  4267. // parameter that is passed to the Kernel* callbacks below. It is
  4268. // recommended to use CreateKernelV2 which allows for a safe error
  4269. // propagation by returning an OrtStatusPtr.
  4270. void*(ORT_API_CALL* CreateKernel)(_In_ const struct OrtCustomOp* op, _In_ const OrtApi* api,
  4271. _In_ const OrtKernelInfo* info);
  4272. // Returns the name of the op
  4273. const char*(ORT_API_CALL* GetName)(_In_ const struct OrtCustomOp* op);
  4274. // Returns the type of the execution provider, return nullptr to use CPU execution provider
  4275. const char*(ORT_API_CALL* GetExecutionProviderType)(_In_ const struct OrtCustomOp* op);
  4276. // Returns the count and types of the input & output tensors
  4277. ONNXTensorElementDataType(ORT_API_CALL* GetInputType)(_In_ const struct OrtCustomOp* op, _In_ size_t index);
  4278. size_t(ORT_API_CALL* GetInputTypeCount)(_In_ const struct OrtCustomOp* op);
  4279. ONNXTensorElementDataType(ORT_API_CALL* GetOutputType)(_In_ const struct OrtCustomOp* op, _In_ size_t index);
  4280. size_t(ORT_API_CALL* GetOutputTypeCount)(_In_ const struct OrtCustomOp* op);
  4281. // Perform a computation step. It is recommended to use
  4282. // KernelComputeV2 which allows for a safe error propagation by
  4283. // returning an OrtStatusPtr.
  4284. void(ORT_API_CALL* KernelCompute)(_In_ void* op_kernel, _In_ OrtKernelContext* context);
  4285. void(ORT_API_CALL* KernelDestroy)(_In_ void* op_kernel);
  4286. // Returns the characteristics of the input & output tensors
  4287. OrtCustomOpInputOutputCharacteristic(ORT_API_CALL* GetInputCharacteristic)(_In_ const struct OrtCustomOp* op, _In_ size_t index);
  4288. OrtCustomOpInputOutputCharacteristic(ORT_API_CALL* GetOutputCharacteristic)(_In_ const struct OrtCustomOp* op, _In_ size_t index);
  4289. // Returns the memory type of the input tensors. This API allows the custom op
  4290. // to place the inputs on specific devices. By default, it returns
  4291. // OrtMemTypeDefault, which means the input is placed on the default device for
  4292. // the execution provider. If the inputs need to be with different memory tyeps,
  4293. // this function can be overridden to return the specific memory types.
  4294. OrtMemType(ORT_API_CALL* GetInputMemoryType)(_In_ const struct OrtCustomOp* op, _In_ size_t index);
  4295. // Returns the minimum number of input arguments expected for the variadic input.
  4296. // Applicable only for custom ops that have a variadic input.
  4297. int(ORT_API_CALL* GetVariadicInputMinArity)(_In_ const struct OrtCustomOp* op);
  4298. // Returns true (non-zero) if all arguments of a variadic input have to be of the same type (homogeneous),
  4299. // and false (zero) otherwise.
  4300. // Applicable only for custom ops that have a variadic input.
  4301. int(ORT_API_CALL* GetVariadicInputHomogeneity)(_In_ const struct OrtCustomOp* op);
  4302. // Returns the minimum number of output values expected for the variadic output.
  4303. // Applicable only for custom ops that have a variadic output.
  4304. int(ORT_API_CALL* GetVariadicOutputMinArity)(_In_ const struct OrtCustomOp* op);
  4305. // Returns true (non-zero) if all outputs values of a variadic output have to be of the same type (homogeneous),
  4306. // and false (zero) otherwise.
  4307. // Applicable only for custom ops that have a variadic output.
  4308. int(ORT_API_CALL* GetVariadicOutputHomogeneity)(_In_ const struct OrtCustomOp* op);
  4309. // Create the kernel state which is passed to each compute call.
  4310. OrtStatusPtr(ORT_API_CALL* CreateKernelV2)(_In_ const struct OrtCustomOp* op, _In_ const OrtApi* api,
  4311. _In_ const OrtKernelInfo* info,
  4312. _Out_ void** kernel);
  4313. // Perform the computation step.
  4314. OrtStatusPtr(ORT_API_CALL* KernelComputeV2)(_In_ void* op_kernel, _In_ OrtKernelContext* context);
  4315. OrtStatusPtr(ORT_API_CALL* InferOutputShapeFn)(_In_ const struct OrtCustomOp* op, _In_ OrtShapeInferContext*);
  4316. // Get start range
  4317. int(ORT_API_CALL* GetStartVersion)(_In_ const struct OrtCustomOp* op);
  4318. int(ORT_API_CALL* GetEndVersion)(_In_ const struct OrtCustomOp* op);
  4319. // Get the inplace_map that defines which output can reuse which input
  4320. // Callers will provide 2 raw int* and pass in their address, this function will fill these 2 arrays
  4321. // when return, output (*output_index)[i] may reuse the input (*input_index[i]).
  4322. // The return value is the size of these 2 arrays.
  4323. // Callers are responsible to delete these 2 arrays after use by calling OrtCustomOp::ReleaseMayInplace().
  4324. size_t(ORT_API_CALL* GetMayInplace)(_Out_ int** input_index, _Out_ int** output_index);
  4325. // Release the pointer input_index and output_index allocated from GetMayInplace() function.
  4326. // If GetMayInplace() is defined, this function MUST be defined as well.
  4327. void(ORT_API_CALL* ReleaseMayInplace)(_Frees_ptr_opt_ int* input_index, _Frees_ptr_opt_ int* output_index);
  4328. // Same as GetMayInplace() and ReleaseMayInplace()
  4329. size_t(ORT_API_CALL* GetAliasMap)(_Out_ int** input_index, _Out_ int** output_index);
  4330. void(ORT_API_CALL* ReleaseAliasMap)(_Frees_ptr_opt_ int* input_index, _Frees_ptr_opt_ int* output_index);
  4331. };
  4332. /*
  4333. * This is the old way to add the CUDA provider to the session, please use SessionOptionsAppendExecutionProvider_CUDA above to access the latest functionality
  4334. * This function always exists, but will only succeed if Onnxruntime was built with CUDA support and the CUDA provider shared library exists
  4335. *
  4336. * \param device_id CUDA device id, starts from zero.
  4337. */
  4338. ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_CUDA, _In_ OrtSessionOptions* options, int device_id);
  4339. /*
  4340. * This is the old way to add the ROCm provider to the session, please use
  4341. * SessionOptionsAppendExecutionProvider_ROCM above to access the latest functionality
  4342. * This function always exists, but will only succeed if Onnxruntime was built with
  4343. * HIP support and the ROCm provider shared library exists
  4344. *
  4345. * \param device_id HIP device id, starts from zero.
  4346. */
  4347. ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_ROCM, _In_ OrtSessionOptions* options, int device_id);
  4348. /*
  4349. * This is the old way to add the MIGraphX provider to the session, please use
  4350. * SessionOptionsAppendExecutionProvider_MIGraphX above to access the latest functionality
  4351. * This function always exists, but will only succeed if Onnxruntime was built with
  4352. * HIP support and the MIGraphX provider shared library exists
  4353. *
  4354. * \param device_id HIP device id, starts from zero.
  4355. */
  4356. ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_MIGraphX, _In_ OrtSessionOptions* options, int device_id);
  4357. /*
  4358. * This is the old way to add the oneDNN provider to the session, please use
  4359. * SessionOptionsAppendExecutionProvider_oneDNN above to access the latest functionality
  4360. * This function always exists, but will only succeed if Onnxruntime was built with
  4361. * oneDNN support and the oneDNN provider shared library exists
  4362. *
  4363. * \param use_arena zero: false. non-zero: true.
  4364. */
  4365. ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_Dnnl, _In_ OrtSessionOptions* options, int use_arena);
  4366. /*
  4367. * This is the old way to add the TensorRT provider to the session, please use SessionOptionsAppendExecutionProvider_TensorRT_V2 above to access the latest functionality
  4368. * This function always exists, but will only succeed if Onnxruntime was built with TensorRT support and the TensorRT provider shared library exists
  4369. *
  4370. * \param device_id CUDA device id, starts from zero.
  4371. */
  4372. ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_Tensorrt, _In_ OrtSessionOptions* options, int device_id);
  4373. #ifdef __cplusplus
  4374. }
  4375. #endif
  4376. /// @}