pynvml.py 258 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920
  1. #####
  2. # Copyright (c) 2011-2025, NVIDIA Corporation. All rights reserved.
  3. #
  4. # Redistribution and use in source and binary forms, with or without
  5. # modification, are permitted provided that the following conditions are met:
  6. #
  7. # * Redistributions of source code must retain the above copyright notice,
  8. # this list of conditions and the following disclaimer.
  9. # * Redistributions in binary form must reproduce the above copyright
  10. # notice, this list of conditions and the following disclaimer in the
  11. # documentation and/or other materials provided with the distribution.
  12. # * Neither the name of the NVIDIA Corporation nor the names of its
  13. # contributors may be used to endorse or promote products derived from
  14. # this software without specific prior written permission.
  15. #
  16. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  17. # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19. # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  20. # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  21. # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  22. # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  23. # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  24. # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  25. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  26. # THE POSSIBILITY OF SUCH DAMAGE.
  27. #####
  28. ##
  29. # Python bindings for the NVML library
  30. ##
  31. from ctypes import *
  32. from ctypes.util import find_library
  33. from functools import wraps
  34. import sys
  35. import os
  36. import threading
  37. import string
  38. ## C Type mappings ##
  39. ## Enums
  40. _nvmlEnableState_t = c_uint
  41. NVML_FEATURE_DISABLED = 0
  42. NVML_FEATURE_ENABLED = 1
  43. _nvmlBrandType_t = c_uint
  44. NVML_BRAND_UNKNOWN = 0
  45. NVML_BRAND_QUADRO = 1
  46. NVML_BRAND_TESLA = 2
  47. NVML_BRAND_NVS = 3
  48. NVML_BRAND_GRID = 4 # Deprecated from API reporting. Keeping definition for backward compatibility.
  49. NVML_BRAND_GEFORCE = 5
  50. NVML_BRAND_TITAN = 6
  51. NVML_BRAND_NVIDIA_VAPPS = 7 # NVIDIA Virtual Applications
  52. NVML_BRAND_NVIDIA_VPC = 8 # NVIDIA Virtual PC
  53. NVML_BRAND_NVIDIA_VCS = 9 # NVIDIA Virtual Compute Server
  54. NVML_BRAND_NVIDIA_VWS = 10 # NVIDIA RTX Virtual Workstation
  55. NVML_BRAND_NVIDIA_CLOUD_GAMING = 11 # NVIDIA Cloud Gaming
  56. NVML_BRAND_NVIDIA_VGAMING = NVML_BRAND_NVIDIA_CLOUD_GAMING # Deprecated from API reporting. Keeping definition for backward compatibility.
  57. NVML_BRAND_QUADRO_RTX = 12
  58. NVML_BRAND_NVIDIA_RTX = 13
  59. NVML_BRAND_NVIDIA = 14
  60. NVML_BRAND_GEFORCE_RTX = 15 # Unused
  61. NVML_BRAND_TITAN_RTX = 16 # Unused
  62. NVML_BRAND_COUNT = 18
  63. _nvmlTemperatureThresholds_t = c_uint
  64. NVML_TEMPERATURE_THRESHOLD_SHUTDOWN = 0
  65. NVML_TEMPERATURE_THRESHOLD_SLOWDOWN = 1
  66. NVML_TEMPERATURE_THRESHOLD_MEM_MAX = 2
  67. NVML_TEMPERATURE_THRESHOLD_GPU_MAX = 3
  68. NVML_TEMPERATURE_THRESHOLD_ACOUSTIC_MIN = 4
  69. NVML_TEMPERATURE_THRESHOLD_ACOUSTIC_CURR = 5
  70. NVML_TEMPERATURE_THRESHOLD_ACOUSTIC_MAX = 6
  71. NVML_TEMPERATURE_THRESHOLD_GPS_CURR = 7
  72. NVML_TEMPERATURE_THRESHOLD_COUNT = 8
  73. _nvmlTemperatureSensors_t = c_uint
  74. NVML_TEMPERATURE_GPU = 0
  75. NVML_TEMPERATURE_COUNT = 1
  76. _nvmlComputeMode_t = c_uint
  77. NVML_COMPUTEMODE_DEFAULT = 0
  78. NVML_COMPUTEMODE_EXCLUSIVE_THREAD = 1 ## Support Removed
  79. NVML_COMPUTEMODE_PROHIBITED = 2
  80. NVML_COMPUTEMODE_EXCLUSIVE_PROCESS = 3
  81. NVML_COMPUTEMODE_COUNT = 4
  82. _nvmlMemoryLocation_t = c_uint
  83. NVML_MEMORY_LOCATION_L1_CACHE = 0
  84. NVML_MEMORY_LOCATION_L2_CACHE = 1
  85. NVML_MEMORY_LOCATION_DEVICE_MEMORY = 2
  86. NVML_MEMORY_LOCATION_DRAM = 2
  87. NVML_MEMORY_LOCATION_REGISTER_FILE = 3
  88. NVML_MEMORY_LOCATION_TEXTURE_MEMORY = 4
  89. NVML_MEMORY_LOCATION_TEXTURE_SHM = 5
  90. NVML_MEMORY_LOCATION_CBU = 6
  91. NVML_MEMORY_LOCATION_SRAM = 7
  92. NVML_MEMORY_LOCATION_COUNT = 8
  93. NVML_NVLINK_MAX_LINKS = 18
  94. # For backwards compatibility, maintain the incorrectly-named "LANES" define
  95. NVML_NVLINK_MAX_LANES = NVML_NVLINK_MAX_LINKS
  96. _nvmlNvLinkErrorCounter_t = c_uint
  97. NVML_NVLINK_ERROR_DL_REPLAY = 0
  98. NVML_NVLINK_ERROR_DL_RECOVERY = 1
  99. NVML_NVLINK_ERROR_DL_CRC_FLIT = 2
  100. NVML_NVLINK_ERROR_DL_CRC_DATA = 3
  101. NVML_NVLINK_ERROR_DL_ECC_DATA = 4
  102. NVML_NVLINK_ERROR_COUNT = 5
  103. _nvmlNvLinkEccLaneErrorCounter_t = c_uint
  104. NVML_NVLINK_ERROR_DL_ECC_LANE0 = 0
  105. NVML_NVLINK_ERROR_DL_ECC_LANE1 = 1
  106. NVML_NVLINK_ERROR_DL_ECC_LANE2 = 2
  107. NVML_NVLINK_ERROR_DL_ECC_LANE3 = 3
  108. NVML_NVLINK_ERROR_DL_ECC_COUNT = 5
  109. _nvmlNvLinkCapability_t = c_uint
  110. NVML_NVLINK_CAP_P2P_SUPPORTED = 0
  111. NVML_NVLINK_CAP_SYSMEM_ACCESS = 1
  112. NVML_NVLINK_CAP_P2P_ATOMICS = 2
  113. NVML_NVLINK_CAP_SYSMEM_ATOMICS= 3
  114. NVML_NVLINK_CAP_SLI_BRIDGE = 4
  115. NVML_NVLINK_CAP_VALID = 5
  116. NVML_NVLINK_CAP_COUNT = 6
  117. _nvmlNvLinkUtilizationCountPktTypes_t = c_uint
  118. NVML_NVLINK_COUNTER_PKTFILTER_NOP = 0x1
  119. NVML_NVLINK_COUNTER_PKTFILTER_READ = 0x2
  120. NVML_NVLINK_COUNTER_PKTFILTER_WRITE = 0x4
  121. NVML_NVLINK_COUNTER_PKTFILTER_RATOM = 0x8
  122. NVML_NVLINK_COUNTER_PKTFILTER_NRATOM = 0x10
  123. NVML_NVLINK_COUNTER_PKTFILTER_FLUSH = 0x20
  124. NVML_NVLINK_COUNTER_PKTFILTER_RESPDATA = 0x40
  125. NVML_NVLINK_COUNTER_PKTFILTER_RESPNODATA = 0x80
  126. NVML_NVLINK_COUNTER_PKTFILTER_ALL = 0xFF
  127. _nvmlNvLinkUtilizationCountUnits_t = c_uint
  128. NVML_NVLINK_COUNTER_UNIT_CYCLES = 0
  129. NVML_NVLINK_COUNTER_UNIT_PACKETS = 1
  130. NVML_NVLINK_COUNTER_UNIT_BYTES = 2
  131. NVML_NVLINK_COUNTER_UNIT_RESERVED = 3
  132. NVML_NVLINK_COUNTER_UNIT_COUNT = 4
  133. _nvmlNvLinkDeviceType_t = c_uint
  134. NVML_NVLINK_DEVICE_TYPE_GPU = 0x00
  135. NVML_NVLINK_DEVICE_TYPE_IBMNPU = 0x01
  136. NVML_NVLINK_DEVICE_TYPE_SWITCH = 0x02
  137. NVML_NVLINK_DEVICE_TYPE_UNKNOWN = 0xFF
  138. # These are deprecated, instead use _nvmlMemoryErrorType_t
  139. _nvmlEccBitType_t = c_uint
  140. NVML_SINGLE_BIT_ECC = 0
  141. NVML_DOUBLE_BIT_ECC = 1
  142. NVML_ECC_ERROR_TYPE_COUNT = 2
  143. _nvmlEccCounterType_t = c_uint
  144. NVML_VOLATILE_ECC = 0
  145. NVML_AGGREGATE_ECC = 1
  146. NVML_ECC_COUNTER_TYPE_COUNT = 2
  147. _nvmlMemoryErrorType_t = c_uint
  148. NVML_MEMORY_ERROR_TYPE_CORRECTED = 0
  149. NVML_MEMORY_ERROR_TYPE_UNCORRECTED = 1
  150. NVML_MEMORY_ERROR_TYPE_COUNT = 2
  151. _nvmlClockType_t = c_uint
  152. NVML_CLOCK_GRAPHICS = 0
  153. NVML_CLOCK_SM = 1
  154. NVML_CLOCK_MEM = 2
  155. NVML_CLOCK_VIDEO = 3
  156. NVML_CLOCK_COUNT = 4
  157. _nvmlClockId_t = c_uint
  158. NVML_CLOCK_ID_CURRENT = 0
  159. NVML_CLOCK_ID_APP_CLOCK_TARGET = 1
  160. NVML_CLOCK_ID_APP_CLOCK_DEFAULT = 2
  161. NVML_CLOCK_ID_CUSTOMER_BOOST_MAX = 3
  162. NVML_CLOCK_ID_COUNT = 4
  163. _nvmlDriverModel_t = c_uint
  164. NVML_DRIVER_WDDM = 0
  165. NVML_DRIVER_WDM = 1
  166. NVML_DRIVER_MCDM = 2
  167. NVML_MAX_GPU_PERF_PSTATES = 16
  168. _nvmlPstates_t = c_uint
  169. NVML_PSTATE_0 = 0
  170. NVML_PSTATE_1 = 1
  171. NVML_PSTATE_2 = 2
  172. NVML_PSTATE_3 = 3
  173. NVML_PSTATE_4 = 4
  174. NVML_PSTATE_5 = 5
  175. NVML_PSTATE_6 = 6
  176. NVML_PSTATE_7 = 7
  177. NVML_PSTATE_8 = 8
  178. NVML_PSTATE_9 = 9
  179. NVML_PSTATE_10 = 10
  180. NVML_PSTATE_11 = 11
  181. NVML_PSTATE_12 = 12
  182. NVML_PSTATE_13 = 13
  183. NVML_PSTATE_14 = 14
  184. NVML_PSTATE_15 = 15
  185. NVML_PSTATE_UNKNOWN = 32
  186. _nvmlInforomObject_t = c_uint
  187. NVML_INFOROM_OEM = 0
  188. NVML_INFOROM_ECC = 1
  189. NVML_INFOROM_POWER = 2
  190. NVML_INFOROM_DEN = 3
  191. NVML_INFOROM_COUNT = 4
  192. _nvmlReturn_t = c_uint
  193. NVML_SUCCESS = 0
  194. NVML_ERROR_UNINITIALIZED = 1
  195. NVML_ERROR_INVALID_ARGUMENT = 2
  196. NVML_ERROR_NOT_SUPPORTED = 3
  197. NVML_ERROR_NO_PERMISSION = 4
  198. NVML_ERROR_ALREADY_INITIALIZED = 5
  199. NVML_ERROR_NOT_FOUND = 6
  200. NVML_ERROR_INSUFFICIENT_SIZE = 7
  201. NVML_ERROR_INSUFFICIENT_POWER = 8
  202. NVML_ERROR_DRIVER_NOT_LOADED = 9
  203. NVML_ERROR_TIMEOUT = 10
  204. NVML_ERROR_IRQ_ISSUE = 11
  205. NVML_ERROR_LIBRARY_NOT_FOUND = 12
  206. NVML_ERROR_FUNCTION_NOT_FOUND = 13
  207. NVML_ERROR_CORRUPTED_INFOROM = 14
  208. NVML_ERROR_GPU_IS_LOST = 15
  209. NVML_ERROR_RESET_REQUIRED = 16
  210. NVML_ERROR_OPERATING_SYSTEM = 17
  211. NVML_ERROR_LIB_RM_VERSION_MISMATCH = 18
  212. NVML_ERROR_IN_USE = 19
  213. NVML_ERROR_MEMORY = 20
  214. NVML_ERROR_NO_DATA = 21
  215. NVML_ERROR_VGPU_ECC_NOT_SUPPORTED = 22
  216. NVML_ERROR_INSUFFICIENT_RESOURCES = 23
  217. NVML_ERROR_FREQ_NOT_SUPPORTED = 24
  218. NVML_ERROR_ARGUMENT_VERSION_MISMATCH = 25
  219. NVML_ERROR_DEPRECATED = 26
  220. NVML_ERROR_NOT_READY = 27
  221. NVML_ERROR_GPU_NOT_FOUND = 28
  222. NVML_ERROR_INVALID_STATE = 29
  223. NVML_ERROR_RESET_TYPE_NOT_SUPPORTED = 30
  224. NVML_ERROR_UNKNOWN = 999
  225. _nvmlFanState_t = c_uint
  226. NVML_FAN_NORMAL = 0
  227. NVML_FAN_FAILED = 1
  228. _nvmlFanControlPolicy_t = c_uint
  229. NVML_FAN_POLICY_TEMPERATURE_CONTINOUS_SW = 0
  230. NVML_FAN_POLICY_MANUAL = 1
  231. _nvmlLedColor_t = c_uint
  232. NVML_LED_COLOR_GREEN = 0
  233. NVML_LED_COLOR_AMBER = 1
  234. _nvmlGpuOperationMode_t = c_uint
  235. NVML_GOM_ALL_ON = 0
  236. NVML_GOM_COMPUTE = 1
  237. NVML_GOM_LOW_DP = 2
  238. _nvmlPageRetirementCause_t = c_uint
  239. NVML_PAGE_RETIREMENT_CAUSE_MULTIPLE_SINGLE_BIT_ECC_ERRORS = 0
  240. NVML_PAGE_RETIREMENT_CAUSE_DOUBLE_BIT_ECC_ERROR = 1
  241. NVML_PAGE_RETIREMENT_CAUSE_COUNT = 2
  242. _nvmlRestrictedAPI_t = c_uint
  243. NVML_RESTRICTED_API_SET_APPLICATION_CLOCKS = 0
  244. NVML_RESTRICTED_API_SET_AUTO_BOOSTED_CLOCKS = 1
  245. NVML_RESTRICTED_API_COUNT = 2
  246. _nvmlBridgeChipType_t = c_uint
  247. NVML_BRIDGE_CHIP_PLX = 0
  248. NVML_BRIDGE_CHIP_BRO4 = 1
  249. NVML_MAX_PHYSICAL_BRIDGE = 128
  250. _nvmlValueType_t = c_uint
  251. NVML_VALUE_TYPE_DOUBLE = 0
  252. NVML_VALUE_TYPE_UNSIGNED_INT = 1
  253. NVML_VALUE_TYPE_UNSIGNED_LONG = 2
  254. NVML_VALUE_TYPE_UNSIGNED_LONG_LONG = 3
  255. NVML_VALUE_TYPE_SIGNED_LONG_LONG = 4
  256. NVML_VALUE_TYPE_SIGNED_INT = 5
  257. NVML_VALUE_TYPE_UNSIGNED_SHORT = 6
  258. NVML_VALUE_TYPE_COUNT = 7
  259. _nvmlNvlinkVersion_t = c_uint
  260. NVML_NVLINK_VERSION_INVALID = 0
  261. NVML_NVLINK_VERSION_1_0 = 1
  262. NVML_NVLINK_VERSION_2_0 = 2
  263. NVML_NVLINK_VERSION_2_2 = 3
  264. NVML_NVLINK_VERSION_3_0 = 4
  265. NVML_NVLINK_VERSION_3_1 = 5
  266. NVML_NVLINK_VERSION_4_0 = 6
  267. NVML_NVLINK_VERSION_5_0 = 7
  268. _nvmlPerfPolicyType_t = c_uint
  269. NVML_PERF_POLICY_POWER = 0
  270. NVML_PERF_POLICY_THERMAL = 1
  271. NVML_PERF_POLICY_SYNC_BOOST = 2
  272. NVML_PERF_POLICY_BOARD_LIMIT = 3
  273. NVML_PERF_POLICY_LOW_UTILIZATION = 4
  274. NVML_PERF_POLICY_RELIABILITY = 5
  275. NVML_PERF_POLICY_TOTAL_APP_CLOCKS = 10
  276. NVML_PERF_POLICY_TOTAL_BASE_CLOCKS = 11
  277. NVML_PERF_POLICY_COUNT = 12
  278. _nvmlEncoderQueryType_t = c_uint
  279. NVML_ENCODER_QUERY_H264 = 0
  280. NVML_ENCODER_QUERY_HEVC = 1
  281. NVML_ENCODER_QUERY_AV1 = 2
  282. NVML_ENCODER_QUERY_UNKNOWN = 255
  283. _nvmlFBCSessionType_t = c_uint
  284. NVML_FBC_SESSION_TYPE_UNKNOWN = 0
  285. NVML_FBC_SESSION_TYPE_TOSYS = 1
  286. NVML_FBC_SESSION_TYPE_CUDA = 2
  287. NVML_FBC_SESSION_TYPE_VID = 3
  288. NVML_FBC_SESSION_TYPE_HWENC = 4
  289. _nvmlDetachGpuState_t = c_uint
  290. NVML_DETACH_GPU_KEEP = 0
  291. NVML_DETACH_GPU_REMOVE = 1
  292. _nvmlPcieLinkState_t = c_uint
  293. NVML_PCIE_LINK_KEEP = 0
  294. NVML_PCIE_LINK_SHUT_DOWN = 1
  295. _nvmlSamplingType_t = c_uint
  296. NVML_TOTAL_POWER_SAMPLES = 0
  297. NVML_GPU_UTILIZATION_SAMPLES = 1
  298. NVML_MEMORY_UTILIZATION_SAMPLES = 2
  299. NVML_ENC_UTILIZATION_SAMPLES = 3
  300. NVML_DEC_UTILIZATION_SAMPLES = 4
  301. NVML_PROCESSOR_CLK_SAMPLES = 5
  302. NVML_MEMORY_CLK_SAMPLES = 6
  303. NVML_MODULE_POWER_SAMPLES = 7
  304. NVML_JPG_UTILIZATION_SAMPLES = 8
  305. NVML_OFA_UTILIZATION_SAMPLES = 9
  306. NVML_SAMPLINGTYPE_COUNT = 10
  307. _nvmlPcieUtilCounter_t = c_uint
  308. NVML_PCIE_UTIL_TX_BYTES = 0
  309. NVML_PCIE_UTIL_RX_BYTES = 1
  310. NVML_PCIE_UTIL_COUNT = 2
  311. _nvmlGpuTopologyLevel_t = c_uint
  312. NVML_TOPOLOGY_INTERNAL = 0
  313. NVML_TOPOLOGY_SINGLE = 10
  314. NVML_TOPOLOGY_MULTIPLE = 20
  315. NVML_TOPOLOGY_HOSTBRIDGE = 30
  316. NVML_TOPOLOGY_NODE = 40
  317. NVML_TOPOLOGY_CPU = NVML_TOPOLOGY_NODE
  318. NVML_TOPOLOGY_SYSTEM = 50
  319. _nvmlGpuP2PCapsIndex_t = c_uint
  320. NVML_P2P_CAPS_INDEX_READ = 0,
  321. NVML_P2P_CAPS_INDEX_WRITE = 1
  322. NVML_P2P_CAPS_INDEX_NVLINK =2
  323. NVML_P2P_CAPS_INDEX_ATOMICS = 3
  324. #
  325. # NVML_P2P_CAPS_INDEX_PROP is deprecated.
  326. # Use NVML_P2P_CAPS_INDEX_PCI instead.
  327. #
  328. NVML_P2P_CAPS_INDEX_PROP = 4
  329. NVML_P2P_CAPS_INDEX_PCI = 4
  330. NVML_P2P_CAPS_INDEX_UNKNOWN = 5
  331. _nvmlGpuP2PStatus_t = c_uint
  332. NVML_P2P_STATUS_OK = 0
  333. NVML_P2P_STATUS_CHIPSET_NOT_SUPPORED = 1
  334. NVML_P2P_STATUS_CHIPSET_NOT_SUPPORTED = NVML_P2P_STATUS_CHIPSET_NOT_SUPPORED
  335. NVML_P2P_STATUS_GPU_NOT_SUPPORTED = 2
  336. NVML_P2P_STATUS_IOH_TOPOLOGY_NOT_SUPPORTED =3
  337. NVML_P2P_STATUS_DISABLED_BY_REGKEY =4
  338. NVML_P2P_STATUS_NOT_SUPPORTED =5
  339. NVML_P2P_STATUS_UNKNOWN =6
  340. _nvmlDeviceArchitecture_t = c_uint
  341. NVML_DEVICE_ARCH_KEPLER = 2
  342. NVML_DEVICE_ARCH_MAXWELL = 3
  343. NVML_DEVICE_ARCH_PASCAL = 4
  344. NVML_DEVICE_ARCH_VOLTA = 5
  345. NVML_DEVICE_ARCH_TURING = 6
  346. NVML_DEVICE_ARCH_AMPERE = 7
  347. NVML_DEVICE_ARCH_ADA = 8
  348. NVML_DEVICE_ARCH_HOPPER = 9
  349. NVML_DEVICE_ARCH_BLACKWELL = 10
  350. NVML_DEVICE_ARCH_UNKNOWN = 0xffffffff
  351. # PCI bus Types
  352. _nvmlBusType_t = c_uint
  353. NVML_BUS_TYPE_UNKNOWN = 0
  354. NVML_BUS_TYPE_PCI = 1
  355. NVML_BUS_TYPE_PCIE = 2
  356. NVML_BUS_TYPE_FPCI = 3
  357. NVML_BUS_TYPE_AGP = 4
  358. _nvmlPowerSource_t = c_uint
  359. NVML_POWER_SOURCE_AC = 0x00000000
  360. NVML_POWER_SOURCE_BATTERY = 0x00000001
  361. NVML_POWER_SOURCE_UNDERSIZED = 0x00000002
  362. _nvmlAdaptiveClockInfoStatus_t = c_uint
  363. NVML_ADAPTIVE_CLOCKING_INFO_STATUS_DISABLED = 0x00000000
  364. NVML_ADAPTIVE_CLOCKING_INFO_STATUS_ENABLED = 0x00000001
  365. _nvmlClockLimitId_t = c_uint
  366. NVML_CLOCK_LIMIT_ID_RANGE_START = 0xffffff00
  367. NVML_CLOCK_LIMIT_ID_TDP = 0xffffff01
  368. NVML_CLOCK_LIMIT_ID_UNLIMITED = 0xffffff02
  369. _nvmlPcieLinkMaxSpeed_t = c_uint
  370. NVML_PCIE_LINK_MAX_SPEED_INVALID = 0x00000000
  371. NVML_PCIE_LINK_MAX_SPEED_2500MBPS = 0x00000001
  372. NVML_PCIE_LINK_MAX_SPEED_5000MBPS = 0x00000002
  373. NVML_PCIE_LINK_MAX_SPEED_8000MBPS = 0x00000003
  374. NVML_PCIE_LINK_MAX_SPEED_16000MBPS = 0x00000004
  375. NVML_PCIE_LINK_MAX_SPEED_32000MBPS = 0x00000005
  376. NVML_PCIE_LINK_MAX_SPEED_64000MBPS = 0x00000006
  377. _nvmlPcieAtomicsCapability_t = c_uint
  378. NVML_PCIE_ATOMICS_CAP_FETCHADD32 = 0x01
  379. NVML_PCIE_ATOMICS_CAP_FETCHADD64 = 0x02
  380. NVML_PCIE_ATOMICS_CAP_SWAP32 = 0x04
  381. NVML_PCIE_ATOMICS_CAP_SWAP64 = 0x08
  382. NVML_PCIE_ATOMICS_CAP_CAS32 = 0x10
  383. NVML_PCIE_ATOMICS_CAP_CAS64 = 0x20
  384. NVML_PCIE_ATOMICS_CAP_CAS128 = 0x40
  385. NVML_PCIE_ATOMICS_OPS_MAX = 7
  386. _nvmlAffinityScope_t = c_uint
  387. NVML_AFFINITY_SCOPE_NODE = 0
  388. NVML_AFFINITY_SCOPE_SOCKET = 1
  389. _nvmlDeviceGpuRecoveryAction_t = c_uint
  390. NVML_GPU_RECOVERY_ACTION_NONE = 0
  391. NVML_GPU_RECOVERY_ACTION_GPU_RESET = 1
  392. NVML_GPU_RECOVERY_ACTION_NODE_REBOOT = 2
  393. NVML_GPU_RECOVERY_ACTION_DRAIN_P2P = 3
  394. NVML_GPU_RECOVERY_ACTION_DRAIN_AND_RESET = 4
  395. NVML_GPU_RECOVERY_ACTION_GPU_RESET_BUS = 5
  396. # C preprocessor defined values
  397. nvmlFlagDefault = 0
  398. nvmlFlagForce = 1
  399. NVML_INIT_FLAG_NO_GPUS = 1
  400. NVML_INIT_FLAG_NO_ATTACH = 2
  401. NVML_MAX_GPC_COUNT = 32
  402. # buffer size
  403. NVML_DEVICE_INFOROM_VERSION_BUFFER_SIZE = 16
  404. NVML_DEVICE_UUID_BUFFER_SIZE = 80
  405. NVML_DEVICE_UUID_V2_BUFFER_SIZE = 96
  406. NVML_SYSTEM_DRIVER_VERSION_BUFFER_SIZE = 80
  407. NVML_SYSTEM_NVML_VERSION_BUFFER_SIZE = 80
  408. NVML_DEVICE_NAME_BUFFER_SIZE = 64
  409. NVML_DEVICE_NAME_V2_BUFFER_SIZE = 96
  410. NVML_DEVICE_SERIAL_BUFFER_SIZE = 30
  411. NVML_DEVICE_PART_NUMBER_BUFFER_SIZE = 80
  412. NVML_DEVICE_GPU_PART_NUMBER_BUFFER_SIZE = 80
  413. NVML_DEVICE_VBIOS_VERSION_BUFFER_SIZE = 32
  414. NVML_DEVICE_PCI_BUS_ID_BUFFER_SIZE = 32
  415. NVML_DEVICE_PCI_BUS_ID_BUFFER_V2_SIZE = 16
  416. NVML_GRID_LICENSE_BUFFER_SIZE = 128
  417. NVML_VGPU_NAME_BUFFER_SIZE = 64
  418. NVML_GRID_LICENSE_FEATURE_MAX_COUNT = 3
  419. NVML_VGPU_METADATA_OPAQUE_DATA_SIZE = sizeof(c_uint) + 256
  420. NVML_VGPU_PGPU_METADATA_OPAQUE_DATA_SIZE = 256
  421. NVML_DEVICE_GPU_FRU_PART_NUMBER_BUFFER_SIZE = 0x14 # NV2080_GPU_MAX_PRODUCT_PART_NUMBER_LENGTH
  422. NVML_PERF_MODES_BUFFER_SIZE = 2048
  423. # Format strings
  424. NVML_DEVICE_PCI_BUS_ID_LEGACY_FMT = "%04X:%02X:%02X.0"
  425. NVML_DEVICE_PCI_BUS_ID_FMT = "%08X:%02X:%02X.0"
  426. NVML_VALUE_NOT_AVAILABLE_ulonglong = c_ulonglong(-1)
  427. NVML_VALUE_NOT_AVAILABLE_uint = c_uint(-1)
  428. '''
  429. Field Identifiers.
  430. All Identifiers pertain to a device. Each ID is only used once and is guaranteed never to change.
  431. '''
  432. NVML_FI_DEV_ECC_CURRENT = 1 # Current ECC mode. 1=Active. 0=Inactive
  433. NVML_FI_DEV_ECC_PENDING = 2 # Pending ECC mode. 1=Active. 0=Inactive
  434. #ECC Count Totals
  435. NVML_FI_DEV_ECC_SBE_VOL_TOTAL = 3 # Total single bit volatile ECC errors
  436. NVML_FI_DEV_ECC_DBE_VOL_TOTAL = 4 # Total double bit volatile ECC errors
  437. NVML_FI_DEV_ECC_SBE_AGG_TOTAL = 5 # Total single bit aggregate (persistent) ECC errors
  438. NVML_FI_DEV_ECC_DBE_AGG_TOTAL = 6 # Total double bit aggregate (persistent) ECC errors
  439. #Individual ECC locations
  440. NVML_FI_DEV_ECC_SBE_VOL_L1 = 7 # L1 cache single bit volatile ECC errors
  441. NVML_FI_DEV_ECC_DBE_VOL_L1 = 8 # L1 cache double bit volatile ECC errors
  442. NVML_FI_DEV_ECC_SBE_VOL_L2 = 9 # L2 cache single bit volatile ECC errors
  443. NVML_FI_DEV_ECC_DBE_VOL_L2 = 10 # L2 cache double bit volatile ECC errors
  444. NVML_FI_DEV_ECC_SBE_VOL_DEV = 11 # Device memory single bit volatile ECC errors
  445. NVML_FI_DEV_ECC_DBE_VOL_DEV = 12 # Device memory double bit volatile ECC errors
  446. NVML_FI_DEV_ECC_SBE_VOL_REG = 13 # Register file single bit volatile ECC errors
  447. NVML_FI_DEV_ECC_DBE_VOL_REG = 14 # Register file double bit volatile ECC errors
  448. NVML_FI_DEV_ECC_SBE_VOL_TEX = 15 # Texture memory single bit volatile ECC errors
  449. NVML_FI_DEV_ECC_DBE_VOL_TEX = 16 # Texture memory double bit volatile ECC errors
  450. NVML_FI_DEV_ECC_DBE_VOL_CBU = 17 # CBU double bit volatile ECC errors
  451. NVML_FI_DEV_ECC_SBE_AGG_L1 = 18 # L1 cache single bit aggregate (persistent) ECC errors
  452. NVML_FI_DEV_ECC_DBE_AGG_L1 = 19 # L1 cache double bit aggregate (persistent) ECC errors
  453. NVML_FI_DEV_ECC_SBE_AGG_L2 = 20 # L2 cache single bit aggregate (persistent) ECC errors
  454. NVML_FI_DEV_ECC_DBE_AGG_L2 = 21 # L2 cache double bit aggregate (persistent) ECC errors
  455. NVML_FI_DEV_ECC_SBE_AGG_DEV = 22 # Device memory single bit aggregate (persistent) ECC errors
  456. NVML_FI_DEV_ECC_DBE_AGG_DEV = 23 # Device memory double bit aggregate (persistent) ECC errors
  457. NVML_FI_DEV_ECC_SBE_AGG_REG = 24 # Register File single bit aggregate (persistent) ECC errors
  458. NVML_FI_DEV_ECC_DBE_AGG_REG = 25 # Register File double bit aggregate (persistent) ECC errors
  459. NVML_FI_DEV_ECC_SBE_AGG_TEX = 26 # Texture memory single bit aggregate (persistent) ECC errors
  460. NVML_FI_DEV_ECC_DBE_AGG_TEX = 27 # Texture memory double bit aggregate (persistent) ECC errors
  461. NVML_FI_DEV_ECC_DBE_AGG_CBU = 28 # CBU double bit aggregate ECC errors
  462. # Page Retirement
  463. NVML_FI_DEV_RETIRED_SBE = 29 # Number of retired pages because of single bit errors
  464. NVML_FI_DEV_RETIRED_DBE = 30 # Number of retired pages because of double bit errors
  465. NVML_FI_DEV_RETIRED_PENDING = 31 # If any pages are pending retirement. 1=yes. 0=no.
  466. # NvLink Flit Error Counters
  467. NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_L0 = 32 # NVLink flow control CRC Error Counter for Lane 0
  468. NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_L1 = 33 # NVLink flow control CRC Error Counter for Lane 1
  469. NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_L2 = 34 # NVLink flow control CRC Error Counter for Lane 2
  470. NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_L3 = 35 # NVLink flow control CRC Error Counter for Lane 3
  471. NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_L4 = 36 # NVLink flow control CRC Error Counter for Lane 4
  472. NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_L5 = 37 # NVLink flow control CRC Error Counter for Lane 5
  473. NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_TOTAL = 38 # NVLink flow control CRC Error Counter total for all Lanes
  474. # NvLink CRC Data Error Counters
  475. NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_L0 = 39 # NVLink data CRC Error Counter for Lane 0
  476. NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_L1 = 40 # NVLink data CRC Error Counter for Lane 1
  477. NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_L2 = 41 # NVLink data CRC Error Counter for Lane 2
  478. NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_L3 = 42 # NVLink data CRC Error Counter for Lane 3
  479. NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_L4 = 43 # NVLink data CRC Error Counter for Lane 4
  480. NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_L5 = 44 # NVLink data CRC Error Counter for Lane 5
  481. NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_TOTAL = 45 # NvLink data CRC Error Counter total for all Lanes
  482. # NvLink Replay Error Counters
  483. NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_L0 = 46 # NVLink Replay Error Counter for Lane 0
  484. NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_L1 = 47 # NVLink Replay Error Counter for Lane 1
  485. NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_L2 = 48 # NVLink Replay Error Counter for Lane 2
  486. NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_L3 = 49 # NVLink Replay Error Counter for Lane 3
  487. NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_L4 = 50 # NVLink Replay Error Counter for Lane 4
  488. NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_L5 = 51 # NVLink Replay Error Counter for Lane 5
  489. NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_TOTAL = 52 # NVLink Replay Error Counter total for all Lanes
  490. # NvLink Recovery Error Counters
  491. NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_L0 = 53 # NVLink Recovery Error Counter for Lane 0
  492. NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_L1 = 54 # NVLink Recovery Error Counter for Lane 1
  493. NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_L2 = 55 # NVLink Recovery Error Counter for Lane 2
  494. NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_L3 = 56 # NVLink Recovery Error Counter for Lane 3
  495. NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_L4 = 57 # NVLink Recovery Error Counter for Lane 4
  496. NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_L5 = 58 # NVLink Recovery Error Counter for Lane 5
  497. NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_TOTAL = 59 # NVLink Recovery Error Counter total for all Lanes
  498. # NvLink Bandwidth Counters
  499. NVML_FI_DEV_NVLINK_BANDWIDTH_C0_L0 = 60 # NVLink Bandwidth Counter for Counter Set 0, Lane 0
  500. NVML_FI_DEV_NVLINK_BANDWIDTH_C0_L1 = 61 # NVLink Bandwidth Counter for Counter Set 0, Lane 1
  501. NVML_FI_DEV_NVLINK_BANDWIDTH_C0_L2 = 62 # NVLink Bandwidth Counter for Counter Set 0, Lane 2
  502. NVML_FI_DEV_NVLINK_BANDWIDTH_C0_L3 = 63 # NVLink Bandwidth Counter for Counter Set 0, Lane 3
  503. NVML_FI_DEV_NVLINK_BANDWIDTH_C0_L4 = 64 # NVLink Bandwidth Counter for Counter Set 0, Lane 4
  504. NVML_FI_DEV_NVLINK_BANDWIDTH_C0_L5 = 65 # NVLink Bandwidth Counter for Counter Set 0, Lane 5
  505. NVML_FI_DEV_NVLINK_BANDWIDTH_C0_TOTAL = 66 # NVLink Bandwidth Counter Total for Counter Set 0, All Lanes
  506. # NvLink Bandwidth Counters
  507. NVML_FI_DEV_NVLINK_BANDWIDTH_C1_L0 = 67 # NVLink Bandwidth Counter for Counter Set 1, Lane 0
  508. NVML_FI_DEV_NVLINK_BANDWIDTH_C1_L1 = 68 # NVLink Bandwidth Counter for Counter Set 1, Lane 1
  509. NVML_FI_DEV_NVLINK_BANDWIDTH_C1_L2 = 69 # NVLink Bandwidth Counter for Counter Set 1, Lane 2
  510. NVML_FI_DEV_NVLINK_BANDWIDTH_C1_L3 = 70 # NVLink Bandwidth Counter for Counter Set 1, Lane 3
  511. NVML_FI_DEV_NVLINK_BANDWIDTH_C1_L4 = 71 # NVLink Bandwidth Counter for Counter Set 1, Lane 4
  512. NVML_FI_DEV_NVLINK_BANDWIDTH_C1_L5 = 72 # NVLink Bandwidth Counter for Counter Set 1, Lane 5
  513. NVML_FI_DEV_NVLINK_BANDWIDTH_C1_TOTAL = 73 # NVLink Bandwidth Counter Total for Counter Set 1, All Lanes
  514. # Perf Policy Counters
  515. NVML_FI_DEV_PERF_POLICY_POWER = 74 # Perf Policy Counter for Power Policy
  516. NVML_FI_DEV_PERF_POLICY_THERMAL = 75 # Perf Policy Counter for Thermal Policy
  517. NVML_FI_DEV_PERF_POLICY_SYNC_BOOST = 76 # Perf Policy Counter for Sync boost Policy
  518. NVML_FI_DEV_PERF_POLICY_BOARD_LIMIT = 77 # Perf Policy Counter for Board Limit
  519. NVML_FI_DEV_PERF_POLICY_LOW_UTILIZATION = 78 # Perf Policy Counter for Low GPU Utilization Policy
  520. NVML_FI_DEV_PERF_POLICY_RELIABILITY = 79 # Perf Policy Counter for Reliability Policy
  521. NVML_FI_DEV_PERF_POLICY_TOTAL_APP_CLOCKS = 80 # Perf Policy Counter for Total App Clock Policy
  522. NVML_FI_DEV_PERF_POLICY_TOTAL_BASE_CLOCKS = 81 # Perf Policy Counter for Total Base Clocks Policy
  523. # Memory temperatures
  524. NVML_FI_DEV_MEMORY_TEMP = 82 # Memory temperature for the device
  525. # Energy Counter
  526. NVML_FI_DEV_TOTAL_ENERGY_CONSUMPTION = 83 # Total energy consumption for the GPU in mJ since the driver was last reloaded
  527. # NVLink Speed
  528. NVML_FI_DEV_NVLINK_SPEED_MBPS_L0 = 84
  529. NVML_FI_DEV_NVLINK_SPEED_MBPS_L1 = 85
  530. NVML_FI_DEV_NVLINK_SPEED_MBPS_L2 = 86
  531. NVML_FI_DEV_NVLINK_SPEED_MBPS_L3 = 87
  532. NVML_FI_DEV_NVLINK_SPEED_MBPS_L4 = 88
  533. NVML_FI_DEV_NVLINK_SPEED_MBPS_L5 = 89
  534. NVML_FI_DEV_NVLINK_SPEED_MBPS_COMMON = 90
  535. # NVLink Link Count
  536. NVML_FI_DEV_NVLINK_LINK_COUNT = 91
  537. # Page Retirement pending fields
  538. NVML_FI_DEV_RETIRED_PENDING_SBE = 92
  539. NVML_FI_DEV_RETIRED_PENDING_DBE = 93
  540. # PCIe replay and replay rollover counters
  541. NVML_FI_DEV_PCIE_REPLAY_COUNTER = 94
  542. NVML_FI_DEV_PCIE_REPLAY_ROLLOVER_COUNTER = 95
  543. # NvLink Flit Error Counters
  544. NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_L6 = 96 # NVLink flow control CRC Error Counter for Lane 6
  545. NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_L7 = 97 # NVLink flow control CRC Error Counter for Lane 7
  546. NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_L8 = 98 # NVLink flow control CRC Error Counter for Lane 8
  547. NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_L9 = 99 # NVLink flow control CRC Error Counter for Lane 9
  548. NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_L10 = 100 # NVLink flow control CRC Error Counter for Lane 10
  549. NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_L11 = 101 # NVLink flow control CRC Error Counter for Lane 11
  550. # NvLink CRC Data Error Counters
  551. NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_L6 = 102 # NVLink data CRC Error Counter for Lane 6
  552. NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_L7 = 103 # NVLink data CRC Error Counter for Lane 7
  553. NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_L8 = 104 # NVLink data CRC Error Counter for Lane 8
  554. NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_L9 = 105 # NVLink data CRC Error Counter for Lane 9
  555. NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_L10 = 106 # NVLink data CRC Error Counter for Lane 10
  556. NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_L11 = 107 # NVLink data CRC Error Counter for Lane 11
  557. # NvLink Replay Error Counters
  558. NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_L6 = 108 # NVLink Replay Error Counter for Lane 6
  559. NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_L7 = 109 # NVLink Replay Error Counter for Lane 7
  560. NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_L8 = 110 # NVLink Replay Error Counter for Lane 8
  561. NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_L9 = 111 # NVLink Replay Error Counter for Lane 9
  562. NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_L10 = 112 # NVLink Replay Error Counter for Lane 10
  563. NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_L11 = 113 # NVLink Replay Error Counter for Lane 11
  564. # NvLink Recovery Error Counters
  565. NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_L6 = 114 # NVLink Recovery Error Counter for Lane 6
  566. NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_L7 = 115 # NVLink Recovery Error Counter for Lane 7
  567. NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_L8 = 116 # NVLink Recovery Error Counter for Lane 8
  568. NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_L9 = 117 # NVLink Recovery Error Counter for Lane 9
  569. NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_L10 = 118 # NVLink Recovery Error Counter for Lane 10
  570. NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_L11 = 119 # NVLink Recovery Error Counter for Lane 11
  571. # NvLink Bandwidth Counters
  572. NVML_FI_DEV_NVLINK_BANDWIDTH_C0_L6 = 120 # NVLink Bandwidth Counter for Counter Set 0, Lane 6
  573. NVML_FI_DEV_NVLINK_BANDWIDTH_C0_L7 = 121 # NVLink Bandwidth Counter for Counter Set 0, Lane 7
  574. NVML_FI_DEV_NVLINK_BANDWIDTH_C0_L8 = 122 # NVLink Bandwidth Counter for Counter Set 0, Lane 8
  575. NVML_FI_DEV_NVLINK_BANDWIDTH_C0_L9 = 123 # NVLink Bandwidth Counter for Counter Set 0, Lane 9
  576. NVML_FI_DEV_NVLINK_BANDWIDTH_C0_L10 = 124 # NVLink Bandwidth Counter for Counter Set 0, Lane 10
  577. NVML_FI_DEV_NVLINK_BANDWIDTH_C0_L11 = 125 # NVLink Bandwidth Counter for Counter Set 0, Lane 11
  578. # NvLink Bandwidth Counters
  579. NVML_FI_DEV_NVLINK_BANDWIDTH_C1_L6 = 126 # NVLink Bandwidth Counter for Counter Set 1, Lane 6
  580. NVML_FI_DEV_NVLINK_BANDWIDTH_C1_L7 = 127 # NVLink Bandwidth Counter for Counter Set 1, Lane 7
  581. NVML_FI_DEV_NVLINK_BANDWIDTH_C1_L8 = 128 # NVLink Bandwidth Counter for Counter Set 1, Lane 8
  582. NVML_FI_DEV_NVLINK_BANDWIDTH_C1_L9 = 129 # NVLink Bandwidth Counter for Counter Set 1, Lane 9
  583. NVML_FI_DEV_NVLINK_BANDWIDTH_C1_L10 = 130 # NVLink Bandwidth Counter for Counter Set 1, Lane 10
  584. NVML_FI_DEV_NVLINK_BANDWIDTH_C1_L11 = 131 # NVLink Bandwidth Counter for Counter Set 1, Lane 11
  585. # NVLink Speed
  586. NVML_FI_DEV_NVLINK_SPEED_MBPS_L6 = 132
  587. NVML_FI_DEV_NVLINK_SPEED_MBPS_L7 = 133
  588. NVML_FI_DEV_NVLINK_SPEED_MBPS_L8 = 134
  589. NVML_FI_DEV_NVLINK_SPEED_MBPS_L9 = 135
  590. NVML_FI_DEV_NVLINK_SPEED_MBPS_L10 = 136
  591. NVML_FI_DEV_NVLINK_SPEED_MBPS_L11 = 137
  592. # NVLink Throughput Counters
  593. NVML_FI_DEV_NVLINK_THROUGHPUT_DATA_TX = 138 # NVLink TX Data throughput in KiB
  594. NVML_FI_DEV_NVLINK_THROUGHPUT_DATA_RX = 139 # NVLink RX Data throughput in KiB
  595. NVML_FI_DEV_NVLINK_THROUGHPUT_RAW_TX = 140 # NVLink TX Data + protocol overhead in KiB
  596. NVML_FI_DEV_NVLINK_THROUGHPUT_RAW_RX = 141 # NVLink RX Data + protocol overhead in KiB
  597. # Row Remapper
  598. NVML_FI_DEV_REMAPPED_COR = 142
  599. NVML_FI_DEV_REMAPPED_UNC = 143
  600. NVML_FI_DEV_REMAPPED_PENDING = 144
  601. NVML_FI_DEV_REMAPPED_FAILURE = 145
  602. #Remote device NVLink ID
  603. NVML_FI_DEV_NVLINK_REMOTE_NVLINK_ID = 146
  604. # Number of NVLinks connected to NVSwitch
  605. NVML_FI_DEV_NVSWITCH_CONNECTED_LINK_COUNT = 147
  606. # NvLink ECC Data Error Counters
  607. NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_L0 = 148 #< NVLink data ECC Error Counter for Link 0
  608. NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_L1 = 149 #< NVLink data ECC Error Counter for Link 1
  609. NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_L2 = 150 #< NVLink data ECC Error Counter for Link 2
  610. NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_L3 = 151 #< NVLink data ECC Error Counter for Link 3
  611. NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_L4 = 152 #< NVLink data ECC Error Counter for Link 4
  612. NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_L5 = 153 #< NVLink data ECC Error Counter for Link 5
  613. NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_L6 = 154 #< NVLink data ECC Error Counter for Link 6
  614. NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_L7 = 155 #< NVLink data ECC Error Counter for Link 7
  615. NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_L8 = 156 #< NVLink data ECC Error Counter for Link 8
  616. NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_L9 = 157 #< NVLink data ECC Error Counter for Link 9
  617. NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_L10 = 158 #< NVLink data ECC Error Counter for Link 10
  618. NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_L11 = 159 #< NVLink data ECC Error Counter for Link 11
  619. NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_TOTAL = 160 #< NvLink data ECC Error Counter total for all Links
  620. NVML_FI_DEV_NVLINK_ERROR_DL_REPLAY = 161
  621. NVML_FI_DEV_NVLINK_ERROR_DL_RECOVERY = 162
  622. NVML_FI_DEV_NVLINK_ERROR_DL_CRC = 163
  623. NVML_FI_DEV_NVLINK_GET_SPEED = 164
  624. NVML_FI_DEV_NVLINK_GET_STATE = 165
  625. NVML_FI_DEV_NVLINK_GET_VERSION = 166
  626. NVML_FI_DEV_NVLINK_GET_POWER_STATE = 167
  627. NVML_FI_DEV_NVLINK_GET_POWER_THRESHOLD = 168
  628. NVML_FI_DEV_PCIE_L0_TO_RECOVERY_COUNTER = 169
  629. NVML_FI_DEV_C2C_LINK_COUNT = 170
  630. NVML_FI_DEV_C2C_LINK_GET_STATUS = 171
  631. NVML_FI_DEV_C2C_LINK_GET_MAX_BW = 172
  632. NVML_FI_DEV_PCIE_COUNT_CORRECTABLE_ERRORS = 173
  633. NVML_FI_DEV_PCIE_COUNT_NAKS_RECEIVED = 174
  634. NVML_FI_DEV_PCIE_COUNT_RECEIVER_ERROR = 175
  635. NVML_FI_DEV_PCIE_COUNT_BAD_TLP = 176
  636. NVML_FI_DEV_PCIE_COUNT_NAKS_SENT = 177
  637. NVML_FI_DEV_PCIE_COUNT_BAD_DLLP = 178
  638. NVML_FI_DEV_PCIE_COUNT_NON_FATAL_ERROR = 179
  639. NVML_FI_DEV_PCIE_COUNT_FATAL_ERROR = 180
  640. NVML_FI_DEV_PCIE_COUNT_UNSUPPORTED_REQ = 181
  641. NVML_FI_DEV_PCIE_COUNT_LCRC_ERROR = 182
  642. NVML_FI_DEV_PCIE_COUNT_LANE_ERROR = 183
  643. NVML_FI_DEV_IS_RESETLESS_MIG_SUPPORTED = 184
  644. NVML_FI_DEV_POWER_AVERAGE = 185
  645. NVML_FI_DEV_POWER_INSTANT = 186
  646. NVML_FI_DEV_POWER_MIN_LIMIT = 187
  647. NVML_FI_DEV_POWER_MAX_LIMIT = 188
  648. NVML_FI_DEV_POWER_DEFAULT_LIMIT = 189
  649. NVML_FI_DEV_POWER_CURRENT_LIMIT = 190
  650. NVML_FI_DEV_ENERGY = 191
  651. NVML_FI_DEV_POWER_REQUESTED_LIMIT = 192
  652. NVML_FI_DEV_TEMPERATURE_SHUTDOWN_TLIMIT = 193
  653. NVML_FI_DEV_TEMPERATURE_SLOWDOWN_TLIMIT = 194
  654. NVML_FI_DEV_TEMPERATURE_MEM_MAX_TLIMIT = 195
  655. NVML_FI_DEV_TEMPERATURE_GPU_MAX_TLIMIT = 196
  656. NVML_FI_DEV_PCIE_COUNT_TX_BYTES = 197
  657. NVML_FI_DEV_PCIE_COUNT_RX_BYTES = 198
  658. NVML_FI_DEV_IS_MIG_MODE_INDEPENDENT_MIG_QUERY_CAPABLE = 199
  659. NVML_FI_DEV_NVLINK_GET_POWER_THRESHOLD_MAX = 200
  660. NVML_FI_DEV_NVLINK_COUNT_XMIT_PACKETS = 201
  661. NVML_FI_DEV_NVLINK_COUNT_XMIT_BYTES = 202
  662. NVML_FI_DEV_NVLINK_COUNT_RCV_PACKETS = 203
  663. NVML_FI_DEV_NVLINK_COUNT_RCV_BYTES = 204
  664. NVML_FI_DEV_NVLINK_COUNT_VL15_DROPPED = 205 # Deprecated, do not use
  665. NVML_FI_DEV_NVLINK_COUNT_MALFORMED_PACKET_ERRORS = 206
  666. NVML_FI_DEV_NVLINK_COUNT_BUFFER_OVERRUN_ERRORS = 207
  667. NVML_FI_DEV_NVLINK_COUNT_RCV_ERRORS = 208
  668. NVML_FI_DEV_NVLINK_COUNT_RCV_REMOTE_ERRORS = 209
  669. NVML_FI_DEV_NVLINK_COUNT_RCV_GENERAL_ERRORS = 210
  670. NVML_FI_DEV_NVLINK_COUNT_LOCAL_LINK_INTEGRITY_ERRORS = 211
  671. NVML_FI_DEV_NVLINK_COUNT_XMIT_DISCARDS = 212
  672. NVML_FI_DEV_NVLINK_COUNT_LINK_RECOVERY_SUCCESSFUL_EVENTS = 213
  673. NVML_FI_DEV_NVLINK_COUNT_LINK_RECOVERY_FAILED_EVENTS = 214
  674. NVML_FI_DEV_NVLINK_COUNT_LINK_RECOVERY_EVENTS = 215
  675. NVML_FI_DEV_NVLINK_COUNT_RAW_BER_LANE0 = 216 # Deprecated, do not use
  676. NVML_FI_DEV_NVLINK_COUNT_RAW_BER_LANE1 = 217 # Deprecated, do not use
  677. NVML_FI_DEV_NVLINK_COUNT_RAW_BER = 218 # Deprecated, do not use
  678. NVML_FI_DEV_NVLINK_COUNT_EFFECTIVE_ERRORS = 219
  679. NVML_FI_DEV_NVLINK_COUNT_EFFECTIVE_BER = 220
  680. NVML_FI_DEV_NVLINK_COUNT_SYMBOL_ERRORS = 221
  681. NVML_FI_DEV_NVLINK_COUNT_SYMBOL_BER = 222
  682. NVML_FI_DEV_NVLINK_GET_POWER_THRESHOLD_MIN = 223
  683. NVML_FI_DEV_NVLINK_GET_POWER_THRESHOLD_UNITS = 224 # Values are in the form NVML_NVLINK_LOW_POWER_THRESHOLD_UNIT_*
  684. NVML_FI_DEV_NVLINK_GET_POWER_THRESHOLD_SUPPORTED = 225
  685. NVML_FI_DEV_RESET_STATUS = 226 # Deprecated use NVML_FI_DEV_GET_GPU_RECOVERY_ACTION instead
  686. NVML_FI_DEV_DRAIN_AND_RESET_STATUS = 227 # Deprecated use NVML_FI_DEV_GET_GPU_RECOVERY_ACTION instead
  687. NVML_FI_DEV_PCIE_OUTBOUND_ATOMICS_MASK = 228
  688. NVML_FI_DEV_PCIE_INBOUND_ATOMICS_MASK = 229
  689. NVML_FI_DEV_GET_GPU_RECOVERY_ACTION = 230
  690. NVML_FI_DEV_C2C_LINK_ERROR_INTR = 231
  691. NVML_FI_DEV_C2C_LINK_ERROR_REPLAY = 232
  692. NVML_FI_DEV_C2C_LINK_ERROR_REPLAY_B2B = 233
  693. NVML_FI_DEV_C2C_LINK_POWER_STATE = 234
  694. NVML_FI_DEV_NVLINK_COUNT_FEC_HISTORY_0 = 235
  695. NVML_FI_DEV_NVLINK_COUNT_FEC_HISTORY_1 = 236
  696. NVML_FI_DEV_NVLINK_COUNT_FEC_HISTORY_2 = 237
  697. NVML_FI_DEV_NVLINK_COUNT_FEC_HISTORY_3 = 238
  698. NVML_FI_DEV_NVLINK_COUNT_FEC_HISTORY_4 = 239
  699. NVML_FI_DEV_NVLINK_COUNT_FEC_HISTORY_5 = 240
  700. NVML_FI_DEV_NVLINK_COUNT_FEC_HISTORY_6 = 241
  701. NVML_FI_DEV_NVLINK_COUNT_FEC_HISTORY_7 = 242
  702. NVML_FI_DEV_NVLINK_COUNT_FEC_HISTORY_8 = 243
  703. NVML_FI_DEV_NVLINK_COUNT_FEC_HISTORY_9 = 244
  704. NVML_FI_DEV_NVLINK_COUNT_FEC_HISTORY_10 = 245
  705. NVML_FI_DEV_NVLINK_COUNT_FEC_HISTORY_11 = 246
  706. NVML_FI_DEV_NVLINK_COUNT_FEC_HISTORY_12 = 247
  707. NVML_FI_DEV_NVLINK_COUNT_FEC_HISTORY_13 = 248
  708. NVML_FI_DEV_NVLINK_COUNT_FEC_HISTORY_14 = 249
  709. NVML_FI_DEV_NVLINK_COUNT_FEC_HISTORY_15 = 250
  710. NVML_FI_DEV_CLOCKS_EVENT_REASON_SW_POWER_CAP = NVML_FI_DEV_PERF_POLICY_POWER
  711. NVML_FI_DEV_CLOCKS_EVENT_REASON_SYNC_BOOST = NVML_FI_DEV_PERF_POLICY_SYNC_BOOST
  712. NVML_FI_DEV_CLOCKS_EVENT_REASON_SW_THERM_SLOWDOWN = 251
  713. NVML_FI_DEV_CLOCKS_EVENT_REASON_HW_THERM_SLOWDOWN = 252
  714. NVML_FI_DEV_CLOCKS_EVENT_REASON_HW_POWER_BRAKE_SLOWDOWN = 253
  715. NVML_FI_DEV_POWER_SYNC_BALANCING_FREQ = 254
  716. NVML_FI_DEV_POWER_SYNC_BALANCING_AF = 255
  717. NVML_FI_PWR_SMOOTHING_ENABLED = 256 # Enablement (0/DISABLED or 1/ENABLED)
  718. NVML_FI_PWR_SMOOTHING_PRIV_LVL = 257 # Current privilege level
  719. NVML_FI_PWR_SMOOTHING_IMM_RAMP_DOWN_ENABLED = 258 # Immediate ramp down enablement (0/DISABLED or 1/ENABLED)
  720. NVML_FI_PWR_SMOOTHING_APPLIED_TMP_CEIL = 259 # Applied TMP ceiling value
  721. NVML_FI_PWR_SMOOTHING_APPLIED_TMP_FLOOR = 260 # Applied TMP floor value
  722. NVML_FI_PWR_SMOOTHING_MAX_PERCENT_TMP_FLOOR_SETTING = 261 # Max % TMP Floor value
  723. NVML_FI_PWR_SMOOTHING_MIN_PERCENT_TMP_FLOOR_SETTING = 262 # Min % TMP Floor value
  724. NVML_FI_PWR_SMOOTHING_HW_CIRCUITRY_PERCENT_LIFETIME_REMAINING = 263 # HW Circuitry % lifetime remaining
  725. NVML_FI_PWR_SMOOTHING_MAX_NUM_PRESET_PROFILES = 264 # Max number of preset profiles
  726. NVML_FI_PWR_SMOOTHING_PROFILE_PERCENT_TMP_FLOOR = 265 # % TMP floor for a given profile
  727. NVML_FI_PWR_SMOOTHING_PROFILE_RAMP_UP_RATE = 266 # Ramp up rate in mW/s for a given profile
  728. NVML_FI_PWR_SMOOTHING_PROFILE_RAMP_DOWN_RATE = 267 # Ramp down rate in mW/s for a given profile
  729. NVML_FI_PWR_SMOOTHING_PROFILE_RAMP_DOWN_HYST_VAL = 268 # Ramp down hysteresis value in ms for a given profile
  730. NVML_FI_PWR_SMOOTHING_ACTIVE_PRESET_PROFILE = 269 # Active preset profile number
  731. NVML_FI_PWR_SMOOTHING_ADMIN_OVERRIDE_PERCENT_TMP_FLOOR = 270 # % TMP floor for a given profile
  732. NVML_FI_PWR_SMOOTHING_ADMIN_OVERRIDE_RAMP_UP_RATE = 271 # Ramp up rate in mW/s for a given profile
  733. NVML_FI_PWR_SMOOTHING_ADMIN_OVERRIDE_RAMP_DOWN_RATE = 272 # Ramp down rate in mW/s for a given profile
  734. NVML_FI_PWR_SMOOTHING_ADMIN_OVERRIDE_RAMP_DOWN_HYST_VAL = 273 # Ramp down hysteresis value in ms for a given profile
  735. NVML_FI_MAX = 274 # One greater than the largest field ID defined above
  736. # NVML_FI_DEV_NVLINK_GET_STATE state enums
  737. NVML_NVLINK_STATE_INACTIVE = 0x0
  738. NVML_NVLINK_STATE_ACTIVE = 0x1
  739. NVML_NVLINK_STATE_SLEEP = 0x2
  740. NVML_NVLINK_LOW_POWER_THRESHOLD_UNIT_100US = 0 # NVML_FI_DEV_NVLINK_GET_POWER_THRESHOLD_UNITS
  741. NVML_NVLINK_LOW_POWER_THRESHOLD_UNIT_50US = 1 # NVML_FI_DEV_NVLINK_GET_POWER_THRESHOLD_UNITS
  742. # NVML_FI_DEV_C2C_LINK_POWER_STATE state enums
  743. NVML_C2C_POWER_STATE_FULL_POWER = 0
  744. NVML_C2C_POWER_STATE_LOW_POWER = 1
  745. ## Enums needed for the method nvmlDeviceGetVirtualizationMode and nvmlDeviceSetVirtualizationMode
  746. NVML_GPU_VIRTUALIZATION_MODE_NONE = 0 # Represents Bare Metal GPU
  747. NVML_GPU_VIRTUALIZATION_MODE_PASSTHROUGH = 1 # Device is associated with GPU-Passthorugh
  748. NVML_GPU_VIRTUALIZATION_MODE_VGPU = 2 # Device is associated with vGPU inside virtual machine.
  749. NVML_GPU_VIRTUALIZATION_MODE_HOST_VGPU = 3 # Device is associated with VGX hypervisor in vGPU mode
  750. NVML_GPU_VIRTUALIZATION_MODE_HOST_VSGA = 4 # Device is associated with VGX hypervisor in vSGA mode
  751. ## Lib loading ##
  752. nvmlLib = None
  753. libLoadLock = threading.Lock()
  754. _nvmlLib_refcount = 0 # Incremented on each nvmlInit and decremented on nvmlShutdown
  755. ## vGPU Management
  756. _nvmlVgpuTypeId_t = c_uint
  757. _nvmlVgpuInstance_t = c_uint
  758. _nvmlVgpuVmIdType_t = c_uint
  759. NVML_VGPU_VM_ID_DOMAIN_ID = 0
  760. NVML_VGPU_VM_ID_UUID = 1
  761. _nvmlGridLicenseFeatureCode_t = c_uint
  762. NVML_GRID_LICENSE_FEATURE_CODE_UNKNOWN = 0
  763. NVML_GRID_LICENSE_FEATURE_CODE_VGPU = 1
  764. NVML_GRID_LICENSE_FEATURE_CODE_NVIDIA_RTX = 2
  765. NVML_GRID_LICENSE_FEATURE_CODE_VWORKSTATION = 2 # deprecated, use NVML_GRID_LICENSE_FEATURE_CODE_NVIDIA_RTX.
  766. NVML_GRID_LICENSE_FEATURE_CODE_GAMING = 3
  767. NVML_GRID_LICENSE_FEATURE_CODE_COMPUTE = 4
  768. _nvmlGridLicenseExpiryStatus_t = c_uint8
  769. NVML_GRID_LICENSE_EXPIRY_NOT_AVAILABLE = 0, # Expiry information not available
  770. NVML_GRID_LICENSE_EXPIRY_INVALID = 1, # Invalid expiry or error fetching expiry
  771. NVML_GRID_LICENSE_EXPIRY_VALID = 2, # Valid expiry
  772. NVML_GRID_LICENSE_EXPIRY_NOT_APPLICABLE = 3, # Expiry not applicable
  773. NVML_GRID_LICENSE_EXPIRY_PERMANENT = 4, # Permanent expiry
  774. _nvmlVgpuCapability_t = c_uint
  775. NVML_VGPU_CAP_NVLINK_P2P = 0 # vGPU P2P over NVLink is supported
  776. NVML_VGPU_CAP_GPUDIRECT = 1 # GPUDirect capability is supported
  777. NVML_VGPU_CAP_MULTI_VGPU_EXCLUSIVE = 2 # vGPU profile cannot be mixed with other vGPU profiles in same VM
  778. NVML_VGPU_CAP_EXCLUSIVE_TYPE = 3 # vGPU profile cannot run on a GPU alongside other profiles of different type
  779. NVML_VGPU_CAP_EXCLUSIVE_SIZE = 4 # vGPU profile cannot run on a GPU alongside other profiles of different size
  780. NVML_VGPU_CAP_COUNT = 5
  781. _nvmlVgpuDriverCapability_t = c_uint
  782. NVML_VGPU_DRIVER_CAP_HETEROGENEOUS_MULTI_VGPU = 0 # Supports mixing of different vGPU profiles within one guest VM
  783. NVML_VGPU_DRIVER_CAP_WARM_UPDATE = 1 # Supports FSR and warm update of vGPU host driver without terminating the running guest VM
  784. NVML_VGPU_DRIVER_CAP_COUNT = 2
  785. _nvmlDeviceVgpuCapability_t = c_uint
  786. NVML_DEVICE_VGPU_CAP_FRACTIONAL_MULTI_VGPU = 0 # Query whether the fractional vGPU profiles on this GPU can be used in multi-vGPU configurations
  787. NVML_DEVICE_VGPU_CAP_HETEROGENEOUS_TIMESLICE_PROFILES = 1 # Query whether the GPU supports concurrent execution of timesliced vGPU profiles of differing types
  788. NVML_DEVICE_VGPU_CAP_HETEROGENEOUS_TIMESLICE_SIZES = 2 # Query whether the GPU supports concurrent execution of timesliced vGPU profiles of differing framebuffer sizes
  789. NVML_DEVICE_VGPU_CAP_READ_DEVICE_BUFFER_BW = 3 # Query the GPU's read_device_buffer expected bandwidth capacity in megabytes per second
  790. NVML_DEVICE_VGPU_CAP_WRITE_DEVICE_BUFFER_BW = 4 # Query the GPU's write_device_buffer expected bandwidth capacity in megabytes per second
  791. NVML_DEVICE_VGPU_CAP_DEVICE_STREAMING = 5 # Query whether the vGPU profiles on the GPU supports migration data streaming
  792. NVML_DEVICE_VGPU_CAP_MINI_QUARTER_GPU = 6 # Set/Get support of mini-quarter vGPU profiles
  793. NVML_DEVICE_VGPU_CAP_COMPUTE_MEDIA_ENGINE_GPU = 7 # Set/Get support for compute media engine vGPU profiles
  794. NVML_DEVICE_VGPU_CAP_WARM_UPDATE = 8 # Query whether the GPU supports FSR and warm update
  795. NVML_DEVICE_VGPU_CAP_HOMOGENEOUS_PLACEMENTS = 9 # Query whether the GPU supports reporting of placements of timesliced vGPU profiles with identical framebuffer sizes
  796. NVML_DEVICE_VGPU_CAP_MIG_TIMESLICING_SUPPORTED = 10 # Query whether the GPU supports timesliced vGPU on MIG
  797. NVML_DEVICE_VGPU_CAP_MIG_TIMESLICING_ENABLED = 11 # Set/Get MIG timesliced mode reporting, without impacting the underlying functionality
  798. NVML_DEVICE_VGPU_CAP_COUNT = 12
  799. _nvmlVgpuGuestInfoState_t = c_uint
  800. NVML_VGPU_INSTANCE_GUEST_INFO_STATE_UNINITIALIZED = 0
  801. NVML_VGPU_INSTANCE_GUEST_INFO_STATE_INITIALIZED = 1
  802. _nvmlVgpuVmCompatibility_t = c_uint
  803. NVML_VGPU_VM_COMPATIBILITY_NONE = 0x0
  804. NVML_VGPU_VM_COMPATIBILITY_COLD = 0x1
  805. NVML_VGPU_VM_COMPATIBILITY_HIBERNATE = 0x2
  806. NVML_VGPU_VM_COMPATIBILITY_SLEEP = 0x4
  807. NVML_VGPU_VM_COMPATIBILITY_LIVE = 0x8
  808. _nvmlVgpuPgpuCompatibilityLimitCode_t = c_uint
  809. NVML_VGPU_COMPATIBILITY_LIMIT_NONE = 0x0
  810. NVML_VGPU_COMPATIBILITY_LIMIT_HOST_DRIVER = 0x1
  811. NVML_VGPU_COMPATIBILITY_LIMIT_GUEST_DRIVER = 0x2
  812. NVML_VGPU_COMPATIBILITY_LIMIT_GPU = 0x4
  813. NVML_VGPU_COMPATIBILITY_LIMIT_OTHER = 0x80000000
  814. _nvmlHostVgpuMode_t = c_uint
  815. NVML_HOST_VGPU_MODE_NON_SRIOV = 0
  816. NVML_HOST_VGPU_MODE_SRIOV = 1
  817. _nvmlConfComputeGpusReadyState_t = c_uint
  818. NVML_CC_ACCEPTING_CLIENT_REQUESTS_FALSE = 0
  819. NVML_CC_ACCEPTING_CLIENT_REQUESTS_TRUE = 1
  820. _nvmlConfComputeGpuCaps_t = c_uint
  821. NVML_CC_SYSTEM_GPUS_CC_NOT_CAPABLE = 0
  822. NVML_CC_SYSTEM_GPUS_CC_CAPABLE = 1
  823. _nvmlConfComputeCpuCaps_t = c_uint
  824. NVML_CC_SYSTEM_CPU_CAPS_NONE = 0
  825. NVML_CC_SYSTEM_CPU_CAPS_AMD_SEV = 1
  826. NVML_CC_SYSTEM_CPU_CAPS_INTEL_TDX = 2
  827. NVML_CC_SYSTEM_CPU_CAPS_AMD_SEV_SNP = 3
  828. NVML_CC_SYSTEM_CPU_CAPS_AMD_SNP_VTOM = 4
  829. _nvmlConfComputeDevToolsMode_t = c_uint
  830. NVML_CC_SYSTEM_DEVTOOLS_MODE_OFF = 0
  831. NVML_CC_SYSTEM_DEVTOOLS_MODE_ON = 1
  832. NVML_CC_SYSTEM_MULTIGPU_NONE = 0
  833. NVML_CC_SYSTEM_MULTIGPU_PROTECTED_PCIE = 1
  834. NVML_CC_SYSTEM_MULTIGPU_NVLE = 2
  835. NVML_CC_SYSTEM_ENVIRONMENT_UNAVAILABLE = 0
  836. NVML_CC_SYSTEM_ENVIRONMENT_SIM = 1
  837. NVML_CC_SYSTEM_ENVIRONMENT_PROD = 2
  838. _nvmlConfComputeCcFeature_t = c_uint
  839. NVML_CC_SYSTEM_FEATURE_DISABLED = 0
  840. NVML_CC_SYSTEM_FEATURE_ENABLED = 1
  841. _nvmlConfComputeCcKeyRotationThreshAttackerAdv_t = c_uint
  842. NVML_CC_KEY_ROTATION_THRESH_ATTACKER_ADVANTAGE_MIN = 50
  843. NVML_CC_KEY_ROTATION_THRESH_ATTACKER_ADVANTAGE_MAX = 65
  844. # GSP firmware
  845. NVML_GSP_FIRMWARE_VERSION_BUF_SIZE = 0x40
  846. class NVMLLibraryMismatchError(Exception):
  847. pass
  848. ## Error Checking ##
  849. class NVMLError(Exception):
  850. _valClassMapping = dict()
  851. # List of currently known error codes
  852. _errcode_to_string = {
  853. NVML_ERROR_UNINITIALIZED: "Uninitialized",
  854. NVML_ERROR_INVALID_ARGUMENT: "Invalid Argument",
  855. NVML_ERROR_NOT_SUPPORTED: "Not Supported",
  856. NVML_ERROR_NO_PERMISSION: "Insufficient Permissions",
  857. NVML_ERROR_ALREADY_INITIALIZED: "Already Initialized",
  858. NVML_ERROR_NOT_FOUND: "Not Found",
  859. NVML_ERROR_INSUFFICIENT_SIZE: "Insufficient Size",
  860. NVML_ERROR_INSUFFICIENT_POWER: "Insufficient External Power",
  861. NVML_ERROR_DRIVER_NOT_LOADED: "Driver Not Loaded",
  862. NVML_ERROR_TIMEOUT: "Timeout",
  863. NVML_ERROR_IRQ_ISSUE: "Interrupt Request Issue",
  864. NVML_ERROR_LIBRARY_NOT_FOUND: "NVML Shared Library Not Found",
  865. NVML_ERROR_FUNCTION_NOT_FOUND: "Function Not Found",
  866. NVML_ERROR_CORRUPTED_INFOROM: "Corrupted infoROM",
  867. NVML_ERROR_GPU_IS_LOST: "GPU is lost",
  868. NVML_ERROR_RESET_REQUIRED: "GPU requires restart",
  869. NVML_ERROR_OPERATING_SYSTEM: "The operating system has blocked the request.",
  870. NVML_ERROR_LIB_RM_VERSION_MISMATCH: "RM has detected an NVML/RM version mismatch.",
  871. NVML_ERROR_MEMORY: "Insufficient Memory",
  872. NVML_ERROR_UNKNOWN: "Unknown Error",
  873. }
  874. def __new__(typ, value):
  875. '''
  876. Maps value to a proper subclass of NVMLError.
  877. See _extractNVMLErrorsAsClasses function for more details
  878. '''
  879. if typ == NVMLError:
  880. typ = NVMLError._valClassMapping.get(value, typ)
  881. obj = Exception.__new__(typ)
  882. obj.value = value
  883. return obj
  884. def __str__(self):
  885. try:
  886. if self.value not in NVMLError._errcode_to_string:
  887. NVMLError._errcode_to_string[self.value] = str(nvmlErrorString(self.value))
  888. return NVMLError._errcode_to_string[self.value]
  889. except NVMLError:
  890. return "NVML Error with code %d" % self.value
  891. def __eq__(self, other):
  892. return self.value == other.value
  893. def nvmlExceptionClass(nvmlErrorCode):
  894. if nvmlErrorCode not in NVMLError._valClassMapping:
  895. raise ValueError('nvmlErrorCode %s is not valid' % nvmlErrorCode)
  896. return NVMLError._valClassMapping[nvmlErrorCode]
  897. def _extractNVMLErrorsAsClasses():
  898. '''
  899. Generates a hierarchy of classes on top of NVMLError class.
  900. Each NVML Error gets a new NVMLError subclass. This way try,except blocks can filter appropriate
  901. exceptions more easily.
  902. NVMLError is a parent class. Each NVML_ERROR_* gets it's own subclass.
  903. e.g. NVML_ERROR_ALREADY_INITIALIZED will be turned into NVMLError_AlreadyInitialized
  904. '''
  905. this_module = sys.modules[__name__]
  906. nvmlErrorsNames = [x for x in dir(this_module) if x.startswith("NVML_ERROR_")]
  907. for err_name in nvmlErrorsNames:
  908. # e.g. Turn NVML_ERROR_ALREADY_INITIALIZED into NVMLError_AlreadyInitialized
  909. class_name = "NVMLError_" + string.capwords(err_name.replace("NVML_ERROR_", ""), "_").replace("_", "")
  910. err_val = getattr(this_module, err_name)
  911. def gen_new(val):
  912. def new(typ, *args):
  913. obj = NVMLError.__new__(typ, val)
  914. return obj
  915. return new
  916. new_error_class = type(class_name, (NVMLError,), {'__new__': gen_new(err_val)})
  917. new_error_class.__module__ = __name__
  918. setattr(this_module, class_name, new_error_class)
  919. NVMLError._valClassMapping[err_val] = new_error_class
  920. _extractNVMLErrorsAsClasses()
  921. def _nvmlCheckReturn(ret):
  922. if (ret != NVML_SUCCESS):
  923. raise NVMLError(ret)
  924. return ret
  925. ## Function access ##
  926. _nvmlGetFunctionPointer_cache = dict() # function pointers are cached to prevent unnecessary libLoadLock locking
  927. def _nvmlGetFunctionPointer(name):
  928. global nvmlLib
  929. if name in _nvmlGetFunctionPointer_cache:
  930. return _nvmlGetFunctionPointer_cache[name]
  931. libLoadLock.acquire()
  932. try:
  933. # ensure library was loaded
  934. if (nvmlLib == None):
  935. raise NVMLError(NVML_ERROR_UNINITIALIZED)
  936. try:
  937. _nvmlGetFunctionPointer_cache[name] = getattr(nvmlLib, name)
  938. return _nvmlGetFunctionPointer_cache[name]
  939. except AttributeError:
  940. raise NVMLError(NVML_ERROR_FUNCTION_NOT_FOUND)
  941. finally:
  942. # lock is always freed
  943. libLoadLock.release()
  944. ## Alternative object
  945. # Allows the object to be printed
  946. # Allows mismatched types to be assigned
  947. # - like None when the Structure variant requires c_uint
  948. class nvmlFriendlyObject(object):
  949. def __init__(self, dictionary):
  950. for x in dictionary:
  951. setattr(self, x, dictionary[x])
  952. def __str__(self):
  953. return self.__dict__.__str__()
  954. def nvmlStructToFriendlyObject(struct):
  955. d = {}
  956. for x in struct._fields_:
  957. key = x[0]
  958. value = getattr(struct, key)
  959. # only need to convert from bytes if bytes, no need to check python version.
  960. d[key] = value.decode() if isinstance(value, bytes) else value
  961. obj = nvmlFriendlyObject(d)
  962. return obj
  963. # pack the object so it can be passed to the NVML library
  964. def nvmlFriendlyObjectToStruct(obj, model):
  965. for x in model._fields_:
  966. key = x[0]
  967. value = obj.__dict__[key]
  968. # any c_char_p in python3 needs to be bytes, default encoding works fine.
  969. if sys.version_info >= (3,):
  970. setattr(model, key, value.encode())
  971. else:
  972. setattr(model, key, value)
  973. return model
  974. ## Unit structures
  975. class struct_c_nvmlUnit_t(Structure):
  976. pass # opaque handle
  977. c_nvmlUnit_t = POINTER(struct_c_nvmlUnit_t)
  978. class _PrintableStructure(Structure):
  979. """
  980. Abstract class that produces nicer __str__ output than ctypes.Structure.
  981. e.g. instead of:
  982. <class_name object at 0x7fdf82fef9e0>
  983. this class will print
  984. class_name(field_name: formatted_value, field_name: formatted_value)
  985. _fmt_ dictionary of <str _field_ name> -> <str format>
  986. e.g. class that has _field_ 'hex_value', c_uint could be formatted with
  987. _fmt_ = {"hex_value" : "%08X"}
  988. to produce nicer output.
  989. Default fomratting string for all fields can be set with key "<default>" like:
  990. _fmt_ = {"<default>" : "%d MHz"} # e.g all values are numbers in MHz.
  991. If not set it's assumed to be just "%s"
  992. Exact format of returned str from this class is subject to change in the future.
  993. """
  994. _fmt_ = {}
  995. def __str__(self):
  996. result = []
  997. for x in self._fields_:
  998. key = x[0]
  999. value = getattr(self, key)
  1000. fmt = "%s"
  1001. if key in self._fmt_:
  1002. fmt = self._fmt_[key]
  1003. elif "<default>" in self._fmt_:
  1004. fmt = self._fmt_["<default>"]
  1005. result.append(("%s: " + fmt) % (key, value))
  1006. return self.__class__.__name__ + "(" + ", ".join(result) + ")"
  1007. def __getattribute__(self, name):
  1008. res = super(_PrintableStructure, self).__getattribute__(name)
  1009. # need to convert bytes to unicode for python3 don't need to for python2
  1010. # Python 2 strings are of both str and bytes
  1011. # Python 3 strings are not of type bytes
  1012. # ctypes should convert everything to the correct values otherwise
  1013. if isinstance(res, bytes):
  1014. if isinstance(res, str):
  1015. return res
  1016. return res.decode()
  1017. return res
  1018. def __setattr__(self, name, value):
  1019. if isinstance(value, str):
  1020. # encoding a python2 string returns the same value, since python2 strings are bytes already
  1021. # bytes passed in python3 will be ignored.
  1022. value = value.encode()
  1023. super(_PrintableStructure, self).__setattr__(name, value)
  1024. class c_nvmlUnitInfo_t(_PrintableStructure):
  1025. _fields_ = [
  1026. ('name', c_char * 96),
  1027. ('id', c_char * 96),
  1028. ('serial', c_char * 96),
  1029. ('firmwareVersion', c_char * 96),
  1030. ]
  1031. class c_nvmlC2cModeInfo_v1_t(_PrintableStructure):
  1032. _fields_ = [
  1033. ('isC2cEnabled', c_uint)
  1034. ]
  1035. nvmlC2cModeInfo_v1 = 0x1000008;
  1036. class c_nvmlLedState_t(_PrintableStructure):
  1037. _fields_ = [
  1038. ('cause', c_char * 256),
  1039. ('color', _nvmlLedColor_t),
  1040. ]
  1041. class c_nvmlPSUInfo_t(_PrintableStructure):
  1042. _fields_ = [
  1043. ('state', c_char * 256),
  1044. ('current', c_uint),
  1045. ('voltage', c_uint),
  1046. ('power', c_uint),
  1047. ]
  1048. class c_nvmlUnitFanInfo_t(_PrintableStructure):
  1049. _fields_ = [
  1050. ('speed', c_uint),
  1051. ('state', _nvmlFanState_t),
  1052. ]
  1053. class c_nvmlUnitFanSpeeds_t(_PrintableStructure):
  1054. _fields_ = [
  1055. ('fans', c_nvmlUnitFanInfo_t * 24),
  1056. ('count', c_uint)
  1057. ]
  1058. ## Device structures
  1059. class struct_c_nvmlDevice_t(Structure):
  1060. pass # opaque handle
  1061. c_nvmlDevice_t = POINTER(struct_c_nvmlDevice_t)
  1062. class nvmlPciInfoExt_v1_t(_PrintableStructure):
  1063. _fields_ = [
  1064. ('version', c_uint),
  1065. ('domain', c_uint),
  1066. ('bus', c_uint),
  1067. ('device', c_uint),
  1068. ('pciDeviceId', c_uint),
  1069. ('pciSubSystemId', c_uint),
  1070. ('baseClass', c_uint),
  1071. ('subClass', c_uint),
  1072. ('busId', c_char * NVML_DEVICE_PCI_BUS_ID_BUFFER_SIZE),
  1073. ]
  1074. _fmt_ = {
  1075. 'version' : "0x%04X",
  1076. 'domain' : "0x%04X",
  1077. 'bus' : "0x%02X",
  1078. 'device' : "0x%02X",
  1079. 'pciDeviceId' : "0x%08X",
  1080. 'pciSubSystemId' : "0x%08X",
  1081. 'baseClass' : "0x%01X",
  1082. 'subClass' : "0x%01X",
  1083. }
  1084. nvmlPciInfoExt_v1 = 0x1000040
  1085. # Legacy pciInfo used for _v1 and _v2
  1086. class nvmlPciInfo_v2_t(_PrintableStructure):
  1087. _fields_ = [
  1088. ('busId', c_char * NVML_DEVICE_PCI_BUS_ID_BUFFER_V2_SIZE),
  1089. ('domain', c_uint),
  1090. ('bus', c_uint),
  1091. ('device', c_uint),
  1092. ('pciDeviceId', c_uint),
  1093. # Added in 2.285
  1094. ('pciSubSystemId', c_uint),
  1095. ('reserved0', c_uint),
  1096. ('reserved1', c_uint),
  1097. ('reserved2', c_uint),
  1098. ('reserved3', c_uint),
  1099. ]
  1100. _fmt_ = {
  1101. 'domain' : "0x%04X",
  1102. 'bus' : "0x%02X",
  1103. 'device' : "0x%02X",
  1104. 'pciDeviceId' : "0x%08X",
  1105. 'pciSubSystemId' : "0x%08X",
  1106. }
  1107. class nvmlPciInfo_t(_PrintableStructure):
  1108. _fields_ = [
  1109. # Moved to the new busId location below
  1110. ('busIdLegacy', c_char * NVML_DEVICE_PCI_BUS_ID_BUFFER_V2_SIZE),
  1111. ('domain', c_uint),
  1112. ('bus', c_uint),
  1113. ('device', c_uint),
  1114. ('pciDeviceId', c_uint),
  1115. # Added in 2.285
  1116. ('pciSubSystemId', c_uint),
  1117. # New busId replaced the long deprecated and reserved fields with a
  1118. # field of the same size in 9.0
  1119. ('busId', c_char * NVML_DEVICE_PCI_BUS_ID_BUFFER_SIZE),
  1120. ]
  1121. _fmt_ = {
  1122. 'domain' : "0x%08X",
  1123. 'bus' : "0x%02X",
  1124. 'device' : "0x%02X",
  1125. 'pciDeviceId' : "0x%08X",
  1126. 'pciSubSystemId' : "0x%08X",
  1127. }
  1128. class c_nvmlSystemDriverBranchInfo_v1_t(_PrintableStructure):
  1129. _fields_ = [
  1130. ('version', c_uint),
  1131. ("branch", c_char * NVML_SYSTEM_DRIVER_VERSION_BUFFER_SIZE),
  1132. ]
  1133. SystemDriverBranchInfo_v1 = 0x1000054
  1134. class c_nvmlExcludedDeviceInfo_t(_PrintableStructure):
  1135. _fields_ = [
  1136. ('pci', nvmlPciInfo_t),
  1137. ('uuid', c_char * NVML_DEVICE_UUID_BUFFER_SIZE)
  1138. ]
  1139. class nvmlNvLinkUtilizationControl_t(_PrintableStructure):
  1140. _fields_ = [
  1141. ('units', _nvmlNvLinkUtilizationCountUnits_t),
  1142. ('pktfilter', _nvmlNvLinkUtilizationCountPktTypes_t),
  1143. ]
  1144. class c_nvmlMemory_t(_PrintableStructure):
  1145. _fields_ = [
  1146. ('total', c_ulonglong),
  1147. ('free', c_ulonglong),
  1148. ('used', c_ulonglong),
  1149. ]
  1150. _fmt_ = {'<default>': "%d B"}
  1151. class c_nvmlMemory_v2_t(_PrintableStructure):
  1152. _fields_ = [
  1153. ('version', c_uint),
  1154. ('total', c_ulonglong),
  1155. ('reserved', c_ulonglong),
  1156. ('free', c_ulonglong),
  1157. ('used', c_ulonglong),
  1158. ]
  1159. _fmt_ = {'<default>': "%d B"}
  1160. nvmlMemory_v2 = 0x02000028
  1161. class c_nvmlBAR1Memory_t(_PrintableStructure):
  1162. _fields_ = [
  1163. ('bar1Total', c_ulonglong),
  1164. ('bar1Free', c_ulonglong),
  1165. ('bar1Used', c_ulonglong),
  1166. ]
  1167. _fmt_ = {'<default>': "%d B"}
  1168. class nvmlClkMonFaultInfo_t(Structure):
  1169. _fields_ = [("clkApiDomain", c_uint),
  1170. ("clkDomainFaultMask", c_uint)
  1171. ]
  1172. MAX_CLK_DOMAINS = 32
  1173. class nvmlClkMonStatus_t(Structure):
  1174. _fields_ = [("bGlobalStatus", c_uint),
  1175. ("clkMonListSize", c_uint),
  1176. ("clkMonList", nvmlClkMonFaultInfo_t * MAX_CLK_DOMAINS)
  1177. ]
  1178. # On Windows with the WDDM driver, usedGpuMemory is reported as None
  1179. # Code that processes this structure should check for None, I.E.
  1180. #
  1181. # if (info.usedGpuMemory == None):
  1182. # # TODO handle the error
  1183. # pass
  1184. # else:
  1185. # print("Using %d MiB of memory" % (info.usedGpuMemory / 1024 / 1024))
  1186. # endif
  1187. #
  1188. # See NVML documentation for more information
  1189. class c_nvmlProcessInfo_v2_t(_PrintableStructure):
  1190. _fields_ = [
  1191. ('pid', c_uint),
  1192. ('usedGpuMemory', c_ulonglong),
  1193. ('gpuInstanceId', c_uint),
  1194. ('computeInstanceId', c_uint),
  1195. ]
  1196. _fmt_ = {'usedGpuMemory': "%d B"}
  1197. c_nvmlProcessInfo_v3_t = c_nvmlProcessInfo_v2_t
  1198. c_nvmlProcessInfo_t = c_nvmlProcessInfo_v3_t
  1199. _nvmlProcessMode_t = c_uint
  1200. NVML_PROCESS_MODE_COMPUTE = 0
  1201. NVML_PROCESS_MODE_GRAPHICS = 1
  1202. NVML_PROCESS_MODE_MPS = 2
  1203. class c_nvmlProcessDetail_v1_t(Structure):
  1204. _fields_ = [
  1205. ('pid', c_uint),
  1206. ('usedGpuMemory', c_ulonglong),
  1207. ('gpuInstanceId', c_uint),
  1208. ('computeInstanceId', c_uint),
  1209. ('usedGpuCcProtectedMemory', c_ulonglong),
  1210. ]
  1211. class c_nvmlProcessDetailList_v1_t(_PrintableStructure):
  1212. _fields_ = [
  1213. ('version', c_uint),
  1214. ('mode', _nvmlProcessMode_t),
  1215. ('numProcArrayEntries', c_uint),
  1216. ('procArray', POINTER(c_nvmlProcessDetail_v1_t)),
  1217. ]
  1218. _fmt_ = {'numProcArrayEntries': "%d B"}
  1219. c_nvmlProcessDetailList_t = c_nvmlProcessDetailList_v1_t
  1220. nvmlProcessDetailList_v1 = 0x1000018
  1221. class c_nvmlBridgeChipInfo_t(_PrintableStructure):
  1222. _fields_ = [
  1223. ('type', _nvmlBridgeChipType_t),
  1224. ('fwVersion', c_uint),
  1225. ]
  1226. class c_nvmlBridgeChipHierarchy_t(_PrintableStructure):
  1227. _fields_ = [
  1228. ('bridgeCount', c_uint),
  1229. ('bridgeChipInfo', c_nvmlBridgeChipInfo_t * 128),
  1230. ]
  1231. class c_nvmlEccErrorCounts_t(_PrintableStructure):
  1232. _fields_ = [
  1233. ('l1Cache', c_ulonglong),
  1234. ('l2Cache', c_ulonglong),
  1235. ('deviceMemory', c_ulonglong),
  1236. ('registerFile', c_ulonglong),
  1237. ]
  1238. class c_nvmlUtilization_t(_PrintableStructure):
  1239. _fields_ = [
  1240. ('gpu', c_uint),
  1241. ('memory', c_uint),
  1242. ]
  1243. _fmt_ = {'<default>': "%d %%"}
  1244. # Added in 2.285
  1245. class c_nvmlHwbcEntry_t(_PrintableStructure):
  1246. _fields_ = [
  1247. ('hwbcId', c_uint),
  1248. ('firmwareVersion', c_char * 32),
  1249. ]
  1250. class c_nvmlValue_t(Union):
  1251. _fields_ = [
  1252. ('dVal', c_double),
  1253. ('uiVal', c_uint),
  1254. ('ulVal', c_ulong),
  1255. ('ullVal', c_ulonglong),
  1256. ('sllVal', c_longlong),
  1257. ('siVal', c_int),
  1258. ('usVal', c_ushort),
  1259. ]
  1260. class c_nvmlSample_t(_PrintableStructure):
  1261. _fields_ = [
  1262. ('timeStamp', c_ulonglong),
  1263. ('sampleValue', c_nvmlValue_t),
  1264. ]
  1265. class c_nvmlViolationTime_t(_PrintableStructure):
  1266. _fields_ = [
  1267. ('referenceTime', c_ulonglong),
  1268. ('violationTime', c_ulonglong),
  1269. ]
  1270. class c_nvmlFieldValue_t(_PrintableStructure):
  1271. _fields_ = [
  1272. ('fieldId', c_uint32),
  1273. ('scopeId', c_uint32),
  1274. ('timestamp', c_int64),
  1275. ('latencyUsec', c_int64),
  1276. ('valueType', _nvmlValueType_t),
  1277. ('nvmlReturn', _nvmlReturn_t),
  1278. ('value', c_nvmlValue_t)
  1279. ]
  1280. NVML_NVLINK_TOTAL_SUPPORTED_BW_MODES = 23
  1281. nvmlNvlinkSupportedBwModes_v1 = 0x100001c
  1282. class c_nvmlNvlinkSupportedBwModes_v1_t(_PrintableStructure):
  1283. _fields_ = [
  1284. ('version', c_uint),
  1285. ('bwModes', c_uint8 * NVML_NVLINK_TOTAL_SUPPORTED_BW_MODES),
  1286. ('totalBwModes', c_uint8)
  1287. ]
  1288. def __init__(self):
  1289. super(c_nvmlNvlinkSupportedBwModes_v1_t, self).__init__(version=nvmlNvlinkSupportedBwModes_v1)
  1290. nvmlNvlinkGetBwMode_v1 = 0x100000c
  1291. class c_nvmlNvlinkGetBwMode_v1_t(_PrintableStructure):
  1292. _fields_ = [
  1293. ('version', c_uint),
  1294. ('bIsBest', c_uint),
  1295. ('bwMode', c_uint8)
  1296. ]
  1297. def __init__(self):
  1298. super(c_nvmlNvlinkGetBwMode_v1_t, self).__init__(version=nvmlNvlinkGetBwMode_v1)
  1299. nvmlNvlinkSetBwMode_v1 = 0x100000c
  1300. class c_nvmlNvlinkSetBwMode_v1_t(_PrintableStructure):
  1301. _fields_ = [
  1302. ('version', c_uint),
  1303. ('bSetBest', c_uint),
  1304. ('bwMode', c_uint8)
  1305. ]
  1306. def __init__(self):
  1307. super(c_nvmlNvlinkSetBwMode_v1_t, self).__init__(version=nvmlNvlinkSetBwMode_v1)
  1308. class c_nvmlVgpuHeterogeneousMode_v1_t(_PrintableStructure):
  1309. _fields_ = [
  1310. ('version', c_uint),
  1311. ('mode', c_uint),
  1312. ]
  1313. VgpuHeterogeneousMode_v1 = 0x1000008
  1314. class c_nvmlVgpuPlacementId_v1_t(_PrintableStructure):
  1315. _fields_ = [
  1316. ('version', c_uint),
  1317. ('placementId', c_uint),
  1318. ]
  1319. VgpuPlacementId_v1 = 0x1000008
  1320. class c_nvmlVgpuPlacementList_v1_t(_PrintableStructure):
  1321. _fields_ = [
  1322. ('version', c_uint),
  1323. ('count', c_uint),
  1324. ('placementSize', c_uint),
  1325. ('placementIds', POINTER(c_uint)),
  1326. ]
  1327. VgpuPlacementList_v1 = 0x1000018
  1328. NVML_VGPU_PGPU_HETEROGENEOUS_MODE = 0
  1329. NVML_VGPU_PGPU_HOMOGENEOUS_MODE = 1
  1330. class c_nvmlVgpuPlacementList_v2_t(_PrintableStructure):
  1331. _fields_ = [
  1332. ('version', c_uint),
  1333. ('placementSize', c_uint),
  1334. ('count', c_uint),
  1335. ('placementIds', POINTER(c_uint)),
  1336. ('mode', c_uint),
  1337. ]
  1338. VgpuPlacementList_v2 = 0x2000020
  1339. class c_nvmlVgpuTypeBar1Info_v1_t(_PrintableStructure):
  1340. _fields_ = [
  1341. ('version', c_uint),
  1342. ('bar1Size', c_ulonglong),
  1343. ]
  1344. VgpuTypeBar1Info_v1 = 0x1000010
  1345. class c_nvmlVgpuInstanceUtilizationSample_t(_PrintableStructure):
  1346. _fields_ = [
  1347. ('vgpuInstance', _nvmlVgpuInstance_t),
  1348. ('timeStamp', c_ulonglong),
  1349. ('smUtil', c_nvmlValue_t),
  1350. ('memUtil', c_nvmlValue_t),
  1351. ('encUtil', c_nvmlValue_t),
  1352. ('decUtil', c_nvmlValue_t),
  1353. ]
  1354. class c_nvmlVgpuInstanceUtilizationInfo_v1_t(_PrintableStructure):
  1355. _fields_ = [
  1356. ('timeStamp', c_ulonglong),
  1357. ('vgpuInstance', _nvmlVgpuInstance_t),
  1358. ('smUtil', c_nvmlValue_t),
  1359. ('memUtil', c_nvmlValue_t),
  1360. ('encUtil', c_nvmlValue_t),
  1361. ('decUtil', c_nvmlValue_t),
  1362. ('jpgUtil', c_nvmlValue_t),
  1363. ('ofaUtil', c_nvmlValue_t),
  1364. ]
  1365. class c_nvmlVgpuInstancesUtilizationInfo_v1_t(_PrintableStructure):
  1366. _fields_ = [
  1367. ('version', c_uint),
  1368. ('sampleValType', _nvmlValueType_t),
  1369. ('vgpuInstanceCount', c_uint),
  1370. ('lastSeenTimeStamp', c_ulonglong),
  1371. ('vgpuUtilArray', POINTER(c_nvmlVgpuInstanceUtilizationInfo_v1_t)),
  1372. ]
  1373. VgpuInstancesUtilizationInfo_v1 = 0x01000020
  1374. class c_nvmlVgpuProcessUtilizationSample_t(_PrintableStructure):
  1375. _fields_ = [
  1376. ('vgpuInstance', _nvmlVgpuInstance_t),
  1377. ('pid', c_uint),
  1378. ('processName', c_char * NVML_VGPU_NAME_BUFFER_SIZE),
  1379. ('timeStamp', c_ulonglong),
  1380. ('smUtil', c_uint),
  1381. ('memUtil', c_uint),
  1382. ('encUtil', c_uint),
  1383. ('decUtil', c_uint),
  1384. ]
  1385. class c_nvmlVgpuProcessUtilizationInfo_v1_t(_PrintableStructure):
  1386. _fields_ = [
  1387. ('processName', c_char * NVML_VGPU_NAME_BUFFER_SIZE),
  1388. ('timeStamp', c_ulonglong),
  1389. ('vgpuInstance', _nvmlVgpuInstance_t),
  1390. ('pid', c_uint),
  1391. ('smUtil', c_uint),
  1392. ('memUtil', c_uint),
  1393. ('encUtil', c_uint),
  1394. ('decUtil', c_uint),
  1395. ('jpgUtil', c_uint),
  1396. ('ofaUtil', c_uint),
  1397. ]
  1398. class c_nvmlVgpuProcessesUtilizationInfo_v1_t(_PrintableStructure):
  1399. _fields_ = [
  1400. ('version', c_uint),
  1401. ('vgpuProcessCount', c_uint),
  1402. ('lastSeenTimeStamp', c_ulonglong),
  1403. ('vgpuProcUtilArray', POINTER(c_nvmlVgpuProcessUtilizationInfo_v1_t)),
  1404. ]
  1405. VgpuProcessesUtilizationInfo_v1 = 0x01000018
  1406. class nvmlVgpuRuntimeState_v1_t(_PrintableStructure):
  1407. _fields_ = [
  1408. ('version', c_uint),
  1409. ('size', c_ulonglong),
  1410. ]
  1411. VgpuRuntimeState_v1 = 0x1000010
  1412. class c_nvmlVgpuLicenseExpiry_t(_PrintableStructure):
  1413. _fields_ = [
  1414. ('year', c_uint32),
  1415. ('month', c_uint16),
  1416. ('day', c_uint16),
  1417. ('hour', c_uint16),
  1418. ('min', c_uint16),
  1419. ('sec', c_uint16),
  1420. ('status', c_uint8),
  1421. ]
  1422. NVML_GRID_LICENSE_STATE_UNKNOWN = 0
  1423. NVML_GRID_LICENSE_STATE_UNINITIALIZED = 1
  1424. NVML_GRID_LICENSE_STATE_UNLICENSED_UNRESTRICTED = 2
  1425. NVML_GRID_LICENSE_STATE_UNLICENSED_RESTRICTED = 3
  1426. NVML_GRID_LICENSE_STATE_UNLICENSED = 4
  1427. NVML_GRID_LICENSE_STATE_LICENSED = 5
  1428. class c_nvmlVgpuLicenseInfo_t(_PrintableStructure):
  1429. _fields_ = [
  1430. ('isLicensed', c_uint8),
  1431. ('licenseExpiry', c_nvmlVgpuLicenseExpiry_t),
  1432. ('currentState', c_uint),
  1433. ]
  1434. class c_nvmlEncoderSession_t(_PrintableStructure):
  1435. _fields_ = [
  1436. ('sessionId', c_uint),
  1437. ('pid', c_uint),
  1438. ('vgpuInstance', _nvmlVgpuInstance_t),
  1439. ('codecType', c_uint),
  1440. ('hResolution', c_uint),
  1441. ('vResolution', c_uint),
  1442. ('averageFps', c_uint),
  1443. ('encodeLatency', c_uint),
  1444. ]
  1445. class c_nvmlProcessUtilizationSample_t(_PrintableStructure):
  1446. _fields_ = [
  1447. ('pid', c_uint),
  1448. ('timeStamp', c_ulonglong),
  1449. ('smUtil', c_uint),
  1450. ('memUtil', c_uint),
  1451. ('encUtil', c_uint),
  1452. ('decUtil', c_uint),
  1453. ]
  1454. class c_nvmlProcessUtilizationInfo_v1_t(_PrintableStructure):
  1455. _fields_ = [
  1456. ('timeStamp', c_ulonglong),
  1457. ('pid', c_uint),
  1458. ('smUtil', c_uint),
  1459. ('memUtil', c_uint),
  1460. ('encUtil', c_uint),
  1461. ('decUtil', c_uint),
  1462. ('jpgUtil', c_uint),
  1463. ('ofaUtil', c_uint),
  1464. ]
  1465. class c_nvmlProcessesUtilizationInfo_v1_t(_PrintableStructure):
  1466. _fields_ = [
  1467. ('version', c_uint),
  1468. ('processSamplesCount', c_uint),
  1469. ('lastSeenTimeStamp', c_ulonglong),
  1470. ('procUtilArray', POINTER(c_nvmlProcessUtilizationInfo_v1_t)),
  1471. ]
  1472. ProcessesUtilizationInfo_v1 = 0x01000018
  1473. class c_nvmlGridLicenseExpiry_t(_PrintableStructure):
  1474. _fields_ = [
  1475. ('year', c_uint32),
  1476. ('month', c_uint16),
  1477. ('day', c_uint16),
  1478. ('hour', c_uint16),
  1479. ('min', c_uint16),
  1480. ('sec', c_uint16),
  1481. ('status', c_uint8),
  1482. ]
  1483. class c_nvmlGridLicensableFeature_v4_t(_PrintableStructure):
  1484. _fields_ = [
  1485. ('featureCode', _nvmlGridLicenseFeatureCode_t),
  1486. ('featureState', c_uint),
  1487. ('licenseInfo', c_char * NVML_GRID_LICENSE_BUFFER_SIZE),
  1488. ('productName', c_char * NVML_GRID_LICENSE_BUFFER_SIZE),
  1489. ('featureEnabled', c_uint),
  1490. ('licenseExpiry', c_nvmlGridLicenseExpiry_t),
  1491. ]
  1492. class c_nvmlGridLicensableFeatures_v4_t(_PrintableStructure):
  1493. _fields_ = [
  1494. ('isGridLicenseSupported', c_int),
  1495. ('licensableFeaturesCount', c_uint),
  1496. ('gridLicensableFeatures', c_nvmlGridLicensableFeature_v4_t * NVML_GRID_LICENSE_FEATURE_MAX_COUNT),
  1497. ]
  1498. class c_nvmlGridLicensableFeature_v3_t(_PrintableStructure):
  1499. _fields_ = [
  1500. ('featureCode', _nvmlGridLicenseFeatureCode_t),
  1501. ('featureState', c_uint),
  1502. ('licenseInfo', c_char * NVML_GRID_LICENSE_BUFFER_SIZE),
  1503. ('productName', c_char * NVML_GRID_LICENSE_BUFFER_SIZE),
  1504. ('featureEnabled', c_uint),
  1505. ]
  1506. class c_nvmlGridLicensableFeatures_v3_t(_PrintableStructure):
  1507. _fields_ = [
  1508. ('isGridLicenseSupported', c_int),
  1509. ('licensableFeaturesCount', c_uint),
  1510. ('gridLicensableFeatures', c_nvmlGridLicensableFeature_v3_t * NVML_GRID_LICENSE_FEATURE_MAX_COUNT),
  1511. ]
  1512. class c_nvmlGridLicensableFeature_v2_t(_PrintableStructure):
  1513. _fields_ = [
  1514. ('featureCode', _nvmlGridLicenseFeatureCode_t),
  1515. ('featureState', c_uint),
  1516. ('licenseInfo', c_char * NVML_GRID_LICENSE_BUFFER_SIZE),
  1517. ('productName', c_char * NVML_GRID_LICENSE_BUFFER_SIZE),
  1518. ]
  1519. class c_nvmlGridLicensableFeatures_v2_t(_PrintableStructure):
  1520. _fields_ = [
  1521. ('isGridLicenseSupported', c_int),
  1522. ('licensableFeaturesCount', c_uint),
  1523. ('gridLicensableFeatures', c_nvmlGridLicensableFeature_v2_t * NVML_GRID_LICENSE_FEATURE_MAX_COUNT),
  1524. ]
  1525. class c_nvmlGridLicensableFeature_t(_PrintableStructure):
  1526. _fields_ = [
  1527. ('featureCode', _nvmlGridLicenseFeatureCode_t),
  1528. ('featureState', c_uint),
  1529. ('licenseInfo', c_char * NVML_GRID_LICENSE_BUFFER_SIZE),
  1530. ]
  1531. class c_nvmlGridLicensableFeatures_t(_PrintableStructure):
  1532. _fields_ = [
  1533. ('isGridLicenseSupported', c_int),
  1534. ('licensableFeaturesCount', c_uint),
  1535. ('gridLicensableFeatures', c_nvmlGridLicensableFeature_t * NVML_GRID_LICENSE_FEATURE_MAX_COUNT),
  1536. ]
  1537. class c_nvmlMarginTemperature_v1_t(_PrintableStructure):
  1538. _fields_ = [
  1539. ('version', c_uint),
  1540. ('marginTemperature', c_int),
  1541. ]
  1542. nvmlMarginTemperature_v1 = 0x1000008
  1543. NVML_DEVICE_UUID_ASCII_LEN = 41
  1544. NVML_DEVICE_UUID_BINARY_LEN = 16
  1545. NVML_UUID_TYPE_NONE = 0
  1546. NVML_UUID_TYPE_ASCII = 1
  1547. NVML_UUID_TYPE_BINARY = 2
  1548. class c_nvmlUUIDValue_t(Union):
  1549. _fields_ = [
  1550. ('str', c_char * NVML_DEVICE_UUID_ASCII_LEN),
  1551. ('bytes', c_ubyte * NVML_DEVICE_UUID_BINARY_LEN),
  1552. ]
  1553. nvmlUUID_v1 = 0x1000034
  1554. class c_nvmlUUID_t(_PrintableStructure):
  1555. _fields_ = [
  1556. ('version', c_uint),
  1557. ('type', c_uint),
  1558. ('value', c_nvmlUUIDValue_t),
  1559. ]
  1560. def __init__(self):
  1561. super(c_nvmlUUID_t, self).__init__(version=nvmlUUID_v1)
  1562. nvmlPdi_v1 = 0x1000010
  1563. class c_nvmlPdi_t(_PrintableStructure):
  1564. _fields_ = [
  1565. ('version', c_uint),
  1566. ('value', c_ulonglong),
  1567. ]
  1568. def __init__(self):
  1569. super(c_nvmlPdi_t, self).__init__(version=nvmlPdi_v1)
  1570. nvmlRepairStatus_v1 = 0x100000C
  1571. class c_nvmlRepairStatus_t(_PrintableStructure):
  1572. _fields_ = [
  1573. ("version", c_uint),
  1574. ("bChannelRepairPending", c_uint),
  1575. ("bTpcRepairPending", c_uint),
  1576. ]
  1577. def __init__(self):
  1578. super(c_nvmlRepairStatus_t, self).__init__(version=nvmlRepairStatus_v1)
  1579. nvmlNvLinkInfo_v1 =0x1000008
  1580. class c_nvmlNvLinkInfo_v1_t(_PrintableStructure):
  1581. _fields_ = [
  1582. ("version", c_uint),
  1583. ("isNvleEnabled", c_uint),
  1584. ]
  1585. def __init__(self):
  1586. super(c_nvmlNvLinkInfo_v1_t, self).__init__(version=nvmlNvLinkInfo_v1)
  1587. NVML_NVLINK_FIRMWARE_UCODE_TYPE_MSE = 0x1
  1588. NVML_NVLINK_FIRMWARE_UCODE_TYPE_NETIR = 0x2
  1589. NVML_NVLINK_FIRMWARE_UCODE_TYPE_NETIR_UPHY = 0x3
  1590. NVML_NVLINK_FIRMWARE_UCODE_TYPE_NETIR_CLN = 0x4
  1591. NVML_NVLINK_FIRMWARE_UCODE_TYPE_NETIR_DLN = 0x5
  1592. NVML_NVLINK_FIRMWARE_VERSION_LENGTH = 100
  1593. class c_nvmlNvlinkFirmwareVersion_t(_PrintableStructure):
  1594. _fields_ = [
  1595. ("ucodeType", c_uint8),
  1596. ("major", c_uint),
  1597. ("minor", c_uint),
  1598. ("subMinor", c_uint)
  1599. ]
  1600. class c_nvmlNvlinkFirmwareInfo_t(_PrintableStructure):
  1601. _fields_ = [
  1602. ("firmwareVersion", c_nvmlNvlinkFirmwareVersion_t * NVML_NVLINK_FIRMWARE_VERSION_LENGTH),
  1603. ("numValidEntries", c_uint)
  1604. ]
  1605. nvmlNvLinkInfo_v2 = 0x200064c
  1606. class c_nvmlNvLinkInfo_v2_t(_PrintableStructure):
  1607. _fields_ = [
  1608. ("version", c_uint),
  1609. ("isNvleEnabled", c_uint),
  1610. ("firmwareInfo", c_nvmlNvlinkFirmwareInfo_t)
  1611. ]
  1612. def __init__(self):
  1613. super(c_nvmlNvLinkInfo_v2_t, self).__init__(version=nvmlNvLinkInfo_v2)
  1614. NVML_PRM_DATA_MAX_SIZE = 496
  1615. class c_nvmlPRMTLV_v1_t(_PrintableStructure):
  1616. _fields_ = [
  1617. ('dataSize', c_uint32),
  1618. ('status', c_uint32),
  1619. ('data', c_ubyte * NVML_PRM_DATA_MAX_SIZE),
  1620. ]
  1621. def __init__(self, size=0):
  1622. super(c_nvmlPRMTLV_v1_t, self).__init__(dataSize=size, status=0)
  1623. def nvmlDeviceReadWritePRM_v1(handle, c_info):
  1624. fn = _nvmlGetFunctionPointer("nvmlDeviceReadWritePRM_v1")
  1625. ret = fn(handle, byref(c_info))
  1626. _nvmlCheckReturn(ret)
  1627. # Addressing modes
  1628. NVML_DEVICE_ADDRESSING_MODE_NONE = 0
  1629. NVML_DEVICE_ADDRESSING_MODE_HMM = 1
  1630. NVML_DEVICE_ADDRESSING_MODE_ATS = 2
  1631. nvmlDeviceAddressingMode_v1 = 0x1000008
  1632. class c_nvmlDeviceAddressingMode_t(_PrintableStructure):
  1633. _fields_ = [
  1634. ('version', c_uint),
  1635. ('value', c_uint),
  1636. ]
  1637. def __init__(self):
  1638. super(c_nvmlDeviceAddressingMode_t, self).__init__(version=nvmlDeviceAddressingMode_v1)
  1639. ## Event structures
  1640. class struct_c_nvmlEventSet_t(Structure):
  1641. pass # opaque handle
  1642. c_nvmlEventSet_t = POINTER(struct_c_nvmlEventSet_t)
  1643. nvmlEventTypeSingleBitEccError = 0x0000000000000001
  1644. nvmlEventTypeDoubleBitEccError = 0x0000000000000002
  1645. nvmlEventTypePState = 0x0000000000000004
  1646. nvmlEventTypeXidCriticalError = 0x0000000000000008
  1647. nvmlEventTypeClock = 0x0000000000000010
  1648. nvmlEventTypePowerSourceChange = 0x0000000000000080
  1649. nvmlEventMigConfigChange = 0x0000000000000100
  1650. nvmlEventTypeSingleBitEccErrorStorm = 0x0000000000000200
  1651. nvmlEventTypeDramRetirementEvent = 0x0000000000000400
  1652. nvmlEventTypeDramRetirementFailure = 0x0000000000000800
  1653. nvmlEventTypeNonFatalPoisonError = 0x0000000000001000
  1654. nvmlEventTypeFatalPoisonError = 0x0000000000002000
  1655. nvmlEventTypeGpuUnavailableError = 0x0000000000004000
  1656. nvmlEventTypeGpuRecoveryAction = 0x0000000000008000
  1657. nvmlEventTypeNone = 0x0000000000000000
  1658. nvmlEventTypeAll = (
  1659. nvmlEventTypeNone
  1660. | nvmlEventTypeSingleBitEccError
  1661. | nvmlEventTypeDoubleBitEccError
  1662. | nvmlEventTypePState
  1663. | nvmlEventTypeClock
  1664. | nvmlEventTypePowerSourceChange
  1665. | nvmlEventTypeXidCriticalError
  1666. | nvmlEventMigConfigChange
  1667. | nvmlEventTypeSingleBitEccErrorStorm
  1668. | nvmlEventTypeDramRetirementEvent
  1669. | nvmlEventTypeDramRetirementFailure
  1670. | nvmlEventTypeNonFatalPoisonError
  1671. | nvmlEventTypeFatalPoisonError
  1672. | nvmlEventTypeGpuUnavailableError
  1673. | nvmlEventTypeGpuRecoveryAction
  1674. )
  1675. ## Clock Event Reasons defines
  1676. nvmlClocksEventReasonGpuIdle = 0x0000000000000001
  1677. nvmlClocksEventReasonApplicationsClocksSetting = 0x0000000000000002
  1678. nvmlClocksEventReasonUserDefinedClocks = nvmlClocksEventReasonApplicationsClocksSetting # deprecated, use nvmlClocksEventReasonApplicationsClocksSetting
  1679. nvmlClocksEventReasonSwPowerCap = 0x0000000000000004
  1680. nvmlClocksEventReasonHwSlowdown = 0x0000000000000008
  1681. nvmlClocksEventReasonSyncBoost = 0x0000000000000010
  1682. nvmlClocksEventReasonSwThermalSlowdown = 0x0000000000000020
  1683. nvmlClocksEventReasonHwThermalSlowdown = 0x0000000000000040
  1684. nvmlClocksEventReasonHwPowerBrakeSlowdown = 0x0000000000000080
  1685. nvmlClocksEventReasonDisplayClockSetting = 0x0000000000000100
  1686. nvmlClocksEventReasonNone = 0x0000000000000000
  1687. nvmlClocksEventReasonAll = (
  1688. nvmlClocksEventReasonNone |
  1689. nvmlClocksEventReasonGpuIdle |
  1690. nvmlClocksEventReasonApplicationsClocksSetting |
  1691. nvmlClocksEventReasonSwPowerCap |
  1692. nvmlClocksEventReasonHwSlowdown |
  1693. nvmlClocksEventReasonSyncBoost |
  1694. nvmlClocksEventReasonSwThermalSlowdown |
  1695. nvmlClocksEventReasonHwThermalSlowdown |
  1696. nvmlClocksEventReasonHwPowerBrakeSlowdown |
  1697. nvmlClocksEventReasonDisplayClockSetting
  1698. )
  1699. ## Following have been deprecated
  1700. nvmlClocksThrottleReasonGpuIdle = 0x0000000000000001
  1701. nvmlClocksThrottleReasonApplicationsClocksSetting = 0x0000000000000002
  1702. nvmlClocksThrottleReasonUserDefinedClocks = nvmlClocksThrottleReasonApplicationsClocksSetting # deprecated, use nvmlClocksThrottleReasonApplicationsClocksSetting
  1703. nvmlClocksThrottleReasonSwPowerCap = 0x0000000000000004
  1704. nvmlClocksThrottleReasonHwSlowdown = 0x0000000000000008
  1705. nvmlClocksThrottleReasonSyncBoost = 0x0000000000000010
  1706. nvmlClocksThrottleReasonSwThermalSlowdown = 0x0000000000000020
  1707. nvmlClocksThrottleReasonHwThermalSlowdown = 0x0000000000000040
  1708. nvmlClocksThrottleReasonHwPowerBrakeSlowdown = 0x0000000000000080
  1709. nvmlClocksThrottleReasonDisplayClockSetting = 0x0000000000000100
  1710. nvmlClocksThrottleReasonNone = 0x0000000000000000
  1711. nvmlClocksThrottleReasonAll = (
  1712. nvmlClocksThrottleReasonNone |
  1713. nvmlClocksThrottleReasonGpuIdle |
  1714. nvmlClocksThrottleReasonApplicationsClocksSetting |
  1715. nvmlClocksThrottleReasonSwPowerCap |
  1716. nvmlClocksThrottleReasonHwSlowdown |
  1717. nvmlClocksThrottleReasonSyncBoost |
  1718. nvmlClocksThrottleReasonSwThermalSlowdown |
  1719. nvmlClocksThrottleReasonHwThermalSlowdown |
  1720. nvmlClocksThrottleReasonHwPowerBrakeSlowdown |
  1721. nvmlClocksThrottleReasonDisplayClockSetting
  1722. )
  1723. class c_nvmlEventData_t(_PrintableStructure):
  1724. _fields_ = [
  1725. ('device', c_nvmlDevice_t),
  1726. ('eventType', c_ulonglong),
  1727. ('eventData', c_ulonglong),
  1728. ('gpuInstanceId', c_uint),
  1729. ('computeInstanceId', c_uint)
  1730. ]
  1731. _fmt_ = {'eventType': "0x%08X"}
  1732. class struct_c_nvmlSystemEventSet_t(Structure):
  1733. pass # opaque handle
  1734. c_nvmlSystemEventSet_t = POINTER(struct_c_nvmlSystemEventSet_t)
  1735. nvmlSystemEventTypeGpuDriverUnbind = 0x0000000000000001
  1736. nvmlSystemEventTypeGpuDriverBind = 0x0000000000000002
  1737. nvmlSystemEventTypeCount = 2
  1738. nvmlSystemEventSetCreateRequest_v1 = 0x1000010
  1739. class c_nvmlSystemEventSetCreateRequest_v1_t(_PrintableStructure):
  1740. _fields_ = [
  1741. ('version', c_uint),
  1742. ('set', c_nvmlSystemEventSet_t)
  1743. ]
  1744. def __init__(self):
  1745. super(c_nvmlSystemEventSetCreateRequest_v1_t, self).__init__(version=nvmlSystemEventSetCreateRequest_v1)
  1746. nvmlSystemEventSetFreeRequest_v1 = 0x1000010
  1747. class c_nvmlSystemEventSetFreeRequest_v1_t(_PrintableStructure):
  1748. _fields_ = [
  1749. ('version', c_uint),
  1750. ('set', c_nvmlSystemEventSet_t)
  1751. ]
  1752. def __init__(self):
  1753. super(c_nvmlSystemEventSetFreeRequest_v1_t, self).__init__(version=nvmlSystemEventSetFreeRequest_v1)
  1754. nvmlSystemRegisterEventRequest_v1 = 0x1000018
  1755. class c_nvmlSystemRegisterEventRequest_v1_t(_PrintableStructure):
  1756. _fields_ = [
  1757. ('version', c_uint),
  1758. ('eventTypes', c_ulonglong),
  1759. ('set', c_nvmlSystemEventSet_t)
  1760. ]
  1761. def __init__(self):
  1762. super(c_nvmlSystemRegisterEventRequest_v1_t, self).__init__(version=nvmlSystemRegisterEventRequest_v1)
  1763. class c_nvmlSystemEventData_v1_t(_PrintableStructure):
  1764. _fields_ = [
  1765. ('eventType', c_ulonglong),
  1766. ('gpuId', c_uint)
  1767. ]
  1768. _fmt_ = {'eventType': "0x%08X"}
  1769. nvmlSystemEventSetWaitRequest_v1 = 0x1000020
  1770. class c_nvmlSystemEventSetWaitRequest_v1_t(_PrintableStructure):
  1771. _fields_ = [
  1772. ('version', c_uint), # input/output
  1773. ('timeoutms', c_uint), # input
  1774. ('set', c_nvmlSystemEventSet_t), # input
  1775. ('data', POINTER(c_nvmlSystemEventData_v1_t)), # input/output. Buffer owned by caller
  1776. ('dataSize', c_uint), # input
  1777. ('numEvent', c_uint) # output. Number of event recorded
  1778. ]
  1779. def __init__(self):
  1780. super(c_nvmlSystemEventSetWaitRequest_v1_t, self).__init__(version=nvmlSystemEventSetWaitRequest_v1)
  1781. # C APIs for system events
  1782. def c_nvmlSystemEventSetCreate(req):
  1783. """
  1784. C API binding for c_nvmlSystemEventSetFree
  1785. :param req: reference of c_nvmlSystemEventSetCreateRequest_v1_t
  1786. """
  1787. fn = _nvmlGetFunctionPointer("nvmlSystemEventSetCreate")
  1788. ret = fn(req)
  1789. _nvmlCheckReturn(ret)
  1790. def c_nvmlSystemEventSetFree(req):
  1791. """
  1792. C API binding for c_nvmlSystemEventSetFree
  1793. :param req: reference of c_nvmlSystemEventSetFreeRequest_v1_t
  1794. """
  1795. fn = _nvmlGetFunctionPointer("nvmlSystemEventSetFree")
  1796. ret = fn(req)
  1797. _nvmlCheckReturn(ret)
  1798. def c_nvmlSystemRegisterEvents(req):
  1799. """
  1800. C API binding for nvmlSystemRegisterEvents
  1801. :param req: reference of c_nvmlSystemRegisterEventRequest_v1_t
  1802. """
  1803. fn = _nvmlGetFunctionPointer("nvmlSystemRegisterEvents")
  1804. ret = fn(req)
  1805. _nvmlCheckReturn(ret)
  1806. def c_nvmlSystemEventSetWait(req):
  1807. """
  1808. C API binding for nvmlSystemEventSetWait
  1809. :param req: reference of c_nvmlSystemEventSetWaitRequest_v1_t
  1810. """
  1811. fn = _nvmlGetFunctionPointer("nvmlSystemEventSetWait")
  1812. ret = fn(req)
  1813. # Accept TIMEOUT error
  1814. if ret == NVML_ERROR_TIMEOUT:
  1815. return ret
  1816. _nvmlCheckReturn(ret)
  1817. # Pythonic APIs for system events
  1818. # No Pythonic API compability support
  1819. # When user upgrades to a new NVML Python binding,
  1820. # user should upgrade their code against API change.
  1821. def nvmlSystemEventSetCreate(version):
  1822. """
  1823. Create an NVML system event set.
  1824. :param version: The version of the request.
  1825. :return: A ctypes pointer to the created c_nvmlSystemEventSet_t structure.
  1826. """
  1827. if version != nvmlSystemEventSetCreateRequest_v1:
  1828. raise NVMLError(NVML_ERROR_ARGUMENT_VERSION_MISMATCH)
  1829. # Prepare the request structure
  1830. req = c_nvmlSystemEventSetCreateRequest_v1_t()
  1831. req.version = version
  1832. req.set = None # Initialize as NULL
  1833. c_nvmlSystemEventSetCreate(byref(req))
  1834. # Return the created set handle
  1835. if not req.set:
  1836. raise NVMLError(NVML_ERROR_MEMORY)
  1837. return req.set
  1838. def nvmlSystemEventSetFree(version, setHandle):
  1839. """
  1840. Free an NVML system event set.
  1841. :param version: The version of the request.
  1842. :param setHandle: A ctypes pointer to a c_nvmlSystemEventSet_t structure.
  1843. """
  1844. if version != nvmlSystemEventSetFreeRequest_v1:
  1845. raise NVMLError(NVML_ERROR_ARGUMENT_VERSION_MISMATCH)
  1846. req = c_nvmlSystemEventSetFreeRequest_v1_t()
  1847. req.version = version
  1848. req.set = setHandle
  1849. c_nvmlSystemEventSetFree(byref(req))
  1850. def nvmlSystemRegisterEvents(version, eventTypes, setHandle):
  1851. """
  1852. Register events for an NVML system event set.
  1853. :param version: The version of the request.
  1854. :param eventTypes: A bitmask of event types to register.
  1855. :param setHandle: A ctypes pointer to a c_nvmlSystemEventSet_t structure.
  1856. """
  1857. if version != nvmlSystemRegisterEventRequest_v1:
  1858. raise NVMLError(NVML_ERROR_ARGUMENT_VERSION_MISMATCH)
  1859. req = c_nvmlSystemRegisterEventRequest_v1_t()
  1860. req.version = version
  1861. req.eventTypes = eventTypes
  1862. req.set = setHandle
  1863. c_nvmlSystemRegisterEvents(byref(req))
  1864. def nvmlSystemEventSetWait(version, setHandle, timeoutMs, eventData, eventDataSize):
  1865. """
  1866. Wait for events in an NVML system event set.
  1867. :param version: The version of the request.
  1868. :param setHandle: A ctypes pointer to a c_nvmlSystemEventSet_t structure.
  1869. :param timeoutMs: Timeout in milliseconds.
  1870. :param eventData: A ctypes array of c_nvmlSystemEventData_v1_t for event data.
  1871. :param eventDataSize: Number of c_nvmlSystemEventData_v1_t in evenData array..
  1872. :return: A list of dictionaries containing event data.
  1873. """
  1874. if version != nvmlSystemEventSetWaitRequest_v1:
  1875. raise NVMLError(NVML_ERROR_ARGUMENT_VERSION_MISMATCH)
  1876. req = c_nvmlSystemEventSetWaitRequest_v1_t()
  1877. req.version = version
  1878. req.timeoutms = timeoutMs
  1879. req.set = setHandle
  1880. req.data = eventData
  1881. req.dataSize = eventDataSize
  1882. ret = c_nvmlSystemEventSetWait(byref(req))
  1883. if ret == NVML_ERROR_TIMEOUT:
  1884. return [] # Timeout, no events occurred.
  1885. # Extract event data from the buffer
  1886. events = []
  1887. for i in range(req.numEvent):
  1888. events.append({
  1889. 'eventType': eventData[i].eventType,
  1890. 'gpuId': eventData[i].gpuId
  1891. })
  1892. return events
  1893. class c_nvmlAccountingStats_t(_PrintableStructure):
  1894. _fields_ = [
  1895. ('gpuUtilization', c_uint),
  1896. ('memoryUtilization', c_uint),
  1897. ('maxMemoryUsage', c_ulonglong),
  1898. ('time', c_ulonglong),
  1899. ('startTime', c_ulonglong),
  1900. ('isRunning', c_uint),
  1901. ('reserved', c_uint * 5)
  1902. ]
  1903. class c_nvmlVgpuVersion_t(Structure):
  1904. _fields_ = [("minVersion", c_uint),
  1905. ("maxVersion", c_uint)
  1906. ]
  1907. class c_nvmlVgpuMetadata_t(_PrintableStructure):
  1908. _fields_ = [("version", c_uint),
  1909. ("revision", c_uint),
  1910. ("guestInfoState", _nvmlVgpuGuestInfoState_t),
  1911. ("guestDriverVersion", c_char * NVML_SYSTEM_DRIVER_VERSION_BUFFER_SIZE),
  1912. ("hostDriverVersion", c_char * NVML_SYSTEM_DRIVER_VERSION_BUFFER_SIZE),
  1913. ("reserved", c_uint * 6),
  1914. ("vgpuVirtualizationCaps", c_uint),
  1915. ("guestVgpuVersion", c_uint),
  1916. ("opaqueDataSize", c_uint),
  1917. ("opaqueData", c_char * NVML_VGPU_METADATA_OPAQUE_DATA_SIZE)
  1918. ]
  1919. class c_nvmlVgpuPgpuMetadata_t(_PrintableStructure):
  1920. _fields_ = [("version", c_uint),
  1921. ("revision", c_uint),
  1922. ("hostDriverVersion", c_char * NVML_SYSTEM_DRIVER_VERSION_BUFFER_SIZE),
  1923. ("pgpuVirtualizationCaps", c_uint),
  1924. ("reserved", c_uint * 5),
  1925. ("hostSupportedVgpuRange", c_nvmlVgpuVersion_t),
  1926. ("opaqueDataSize", c_uint),
  1927. ("opaqueData", c_char * NVML_VGPU_PGPU_METADATA_OPAQUE_DATA_SIZE)
  1928. ]
  1929. class c_nvmlVgpuPgpuCompatibility_t(Structure):
  1930. _fields_ = [("vgpuVmCompatibility", _nvmlVgpuVmCompatibility_t),
  1931. ("compatibilityLimitCode", _nvmlVgpuPgpuCompatibilityLimitCode_t)
  1932. ]
  1933. ## vGPU scheduler policy defines
  1934. NVML_VGPU_SCHEDULER_POLICY_UNKNOWN = 0
  1935. NVML_VGPU_SCHEDULER_POLICY_BEST_EFFORT = 1
  1936. NVML_VGPU_SCHEDULER_POLICY_EQUAL_SHARE = 2
  1937. NVML_VGPU_SCHEDULER_POLICY_FIXED_SHARE = 3
  1938. ## Supported vGPU scheduler policy count
  1939. NVML_SUPPORTED_VGPU_SCHEDULER_POLICY_COUNT = 3
  1940. NVML_SCHEDULER_SW_MAX_LOG_ENTRIES = 200
  1941. NVML_VGPU_SCHEDULER_ARR_DEFAULT = 0
  1942. NVML_VGPU_SCHEDULER_ARR_DISABLE = 1
  1943. NVML_VGPU_SCHEDULER_ARR_ENABLE = 2
  1944. NVML_VGPU_SCHEDULER_ENGINE_TYPE_GRAPHICS = 1
  1945. class c_nvmlVgpuSchedDataWithARR_t(_PrintableStructure):
  1946. _fields_ = [
  1947. ('avgFactor', c_uint),
  1948. ('timeslice', c_uint),
  1949. ]
  1950. class c_nvmlVgpuSchedData_t(_PrintableStructure):
  1951. _fields_ = [
  1952. ('timeslice', c_uint),
  1953. ]
  1954. class c_nvmlVgpuSchedulerParams_t(Union):
  1955. _fields_ = [
  1956. ('vgpuSchedDataWithARR', c_nvmlVgpuSchedDataWithARR_t),
  1957. ('vgpuSchedData', c_nvmlVgpuSchedData_t),
  1958. ]
  1959. class c_nvmlVgpuSchedulerLogEntry_t(_PrintableStructure):
  1960. _fields_ = [
  1961. ('timestamp', c_ulonglong),
  1962. ('timeRunTotal', c_ulonglong),
  1963. ('timeRun', c_ulonglong),
  1964. ('swRunlistId', c_uint),
  1965. ('targetTimeSlice', c_ulonglong),
  1966. ('cumulativePreemptionTime', c_ulonglong),
  1967. ]
  1968. class c_nvmlVgpuSchedulerLog_t(_PrintableStructure):
  1969. _fields_ = [
  1970. ('engineId', c_uint),
  1971. ('schedulerPolicy', c_uint),
  1972. ('arrMode', c_uint),
  1973. ('schedulerParams', c_nvmlVgpuSchedulerParams_t),
  1974. ('entriesCount', c_uint),
  1975. ('logEntries', c_nvmlVgpuSchedulerLogEntry_t * NVML_SCHEDULER_SW_MAX_LOG_ENTRIES),
  1976. ]
  1977. class c_nvmlVgpuSchedulerGetState_t(_PrintableStructure):
  1978. _fields_ = [
  1979. ('schedulerPolicy', c_uint),
  1980. ('arrMode', c_uint),
  1981. ('schedulerParams', c_nvmlVgpuSchedulerParams_t),
  1982. ]
  1983. class c_nvmlVgpuSchedSetDataWithARR_t(_PrintableStructure):
  1984. _fields_ = [
  1985. ('avgFactor', c_uint),
  1986. ('frequency', c_uint),
  1987. ]
  1988. class c_nvmlVgpuSchedSetData_t(_PrintableStructure):
  1989. _fields_ = [
  1990. ('timeslice', c_uint),
  1991. ]
  1992. class c_nvmlVgpuSchedulerSetParams_t(Union):
  1993. _fields_ = [
  1994. ('vgpuSchedDataWithARR', c_nvmlVgpuSchedSetDataWithARR_t),
  1995. ('vgpuSchedData', c_nvmlVgpuSchedSetData_t),
  1996. ]
  1997. class c_nvmlVgpuSchedulerSetState_t(_PrintableStructure):
  1998. _fields_ = [
  1999. ('schedulerPolicy', c_uint),
  2000. ('enableARRMode', c_uint),
  2001. ('schedulerParams', c_nvmlVgpuSchedulerSetParams_t),
  2002. ]
  2003. class c_nvmlVgpuSchedulerCapabilities_t(_PrintableStructure):
  2004. _fields_ = [
  2005. ('supportedSchedulers', c_uint * NVML_SUPPORTED_VGPU_SCHEDULER_POLICY_COUNT),
  2006. ('maxTimeslice', c_uint),
  2007. ('minTimeslice', c_uint),
  2008. ('isArrModeSupported', c_uint),
  2009. ('maxFrequencyForARR', c_uint),
  2010. ('minFrequencyForARR', c_uint),
  2011. ('maxAvgFactorForARR', c_uint),
  2012. ('minAvgFactorForARR', c_uint),
  2013. ]
  2014. class c_nvmlVgpuTypeIdInfo_v1_t(_PrintableStructure):
  2015. _fields_ = [
  2016. ('version', c_uint),
  2017. ('vgpuCount', c_uint),
  2018. ('vgpuTypeIds', POINTER(c_uint)),
  2019. ]
  2020. nvmlVgpuTypeIdInfo_v1 = 0x1000010
  2021. class c_nvmlVgpuTypeMaxInstance_v1_t(_PrintableStructure):
  2022. _fields_ = [
  2023. ('version', c_uint),
  2024. ('vgpuTypeId', c_uint),
  2025. ('maxInstancePerGI', c_uint),
  2026. ]
  2027. nvmlVgpuTypeMaxInstance_v1 = 0x100000C
  2028. class c_nvmlActiveVgpuInstanceInfo_v1_t(_PrintableStructure):
  2029. _fields_ = [
  2030. ('version', c_uint),
  2031. ('vgpuCount', c_uint),
  2032. ('vgpuInstances', POINTER(c_uint)),
  2033. ]
  2034. nvmlActiveVgpuInstanceInfo_v1 = 0x1000010
  2035. class c_nvmlVgpuSchedulerState_v1_t(_PrintableStructure):
  2036. _fields_ = [
  2037. ('version', c_uint),
  2038. ('engineId', c_uint),
  2039. ('schedulerPolicy', c_uint),
  2040. ('enableARRMode', c_uint),
  2041. ('schedulerParams', c_nvmlVgpuSchedulerSetParams_t),
  2042. ]
  2043. nvmlVgpuSchedulerState_v1 = 0x1000018
  2044. class c_nvmlVgpuSchedulerStateInfo_v1_t(_PrintableStructure):
  2045. _fields_ = [
  2046. ('version', c_uint), # input
  2047. ('engineId', c_uint), # input. One of NVML_ENGINE_TYPE*
  2048. ('schedulerPolicy', c_uint), # output
  2049. ('arrMode', c_uint), # output
  2050. ('schedulerParams', c_nvmlVgpuSchedulerParams_t), # output
  2051. ]
  2052. nvmlVgpuSchedulerStateInfo_v1 = 0x1000018
  2053. class c_nvmlVgpuSchedulerLogInfo_v1_t(_PrintableStructure):
  2054. _fields_ = [
  2055. ('version', c_uint), # input
  2056. ('engineId', c_uint), # input. One of NVML_ENGINE_TYPE*
  2057. ('schedulerPolicy', c_uint), # output
  2058. ('arrMode', c_uint), # output
  2059. ('schedulerParams', c_nvmlVgpuSchedulerParams_t), # output
  2060. ('entriesCount', c_uint), # output
  2061. ('logEntries', c_nvmlVgpuSchedulerLogEntry_t * NVML_SCHEDULER_SW_MAX_LOG_ENTRIES), # output
  2062. ]
  2063. nvmlVgpuSchedulerLogInfo_v1 = 0x10025A0
  2064. class c_nvmlVgpuCreatablePlacementInfo_v1_t(_PrintableStructure):
  2065. _fields_ = [
  2066. ('version', c_uint),
  2067. ('vgpuTypeId', c_uint),
  2068. ('count', c_uint),
  2069. ('placementIds', POINTER(c_uint)),
  2070. ('placementSize', c_uint),
  2071. ]
  2072. nvmlVgpuCreatablePlacementInfo_v1 = 0x1000020
  2073. class c_nvmlFBCStats_t(Structure):
  2074. _fields_ = [("sessionsCount", c_uint),
  2075. ("averageFPS", c_uint),
  2076. ("averageLatency", c_uint)
  2077. ]
  2078. class c_nvmlFBCSession_t(_PrintableStructure):
  2079. _fields_ = [
  2080. ('sessionId', c_uint),
  2081. ('pid', c_uint),
  2082. ('vgpuInstance', _nvmlVgpuInstance_t),
  2083. ('displayOrdinal', c_uint),
  2084. ('sessionType', c_uint),
  2085. ('sessionFlags', c_uint),
  2086. ('hMaxResolution', c_uint),
  2087. ('vMaxResolution', c_uint),
  2088. ('hResolution', c_uint),
  2089. ('vResolution', c_uint),
  2090. ('averageFPS', c_uint),
  2091. ('averageLatency', c_uint),
  2092. ]
  2093. NVML_DEVICE_MIG_DISABLE = 0x0
  2094. NVML_DEVICE_MIG_ENABLE = 0x1
  2095. NVML_GPU_INSTANCE_PROFILE_1_SLICE = 0x0
  2096. NVML_GPU_INSTANCE_PROFILE_2_SLICE = 0x1
  2097. NVML_GPU_INSTANCE_PROFILE_3_SLICE = 0x2
  2098. NVML_GPU_INSTANCE_PROFILE_4_SLICE = 0x3
  2099. NVML_GPU_INSTANCE_PROFILE_7_SLICE = 0x4
  2100. NVML_GPU_INSTANCE_PROFILE_8_SLICE = 0x5
  2101. NVML_GPU_INSTANCE_PROFILE_6_SLICE = 0x6
  2102. NVML_GPU_INSTANCE_PROFILE_1_SLICE_REV1 = 0x7
  2103. NVML_GPU_INSTANCE_PROFILE_2_SLICE_REV1 = 0x8
  2104. NVML_GPU_INSTANCE_PROFILE_1_SLICE_REV2 = 0x9
  2105. NVML_GPU_INSTANCE_PROFILE_1_SLICE_GFX = 0xA
  2106. NVML_GPU_INSTANCE_PROFILE_2_SLICE_GFX = 0xB
  2107. NVML_GPU_INSTANCE_PROFILE_4_SLICE_GFX = 0xC
  2108. NVML_GPU_INSTANCE_PROFILE_1_SLICE_NO_ME = 0xD
  2109. NVML_GPU_INSTANCE_PROFILE_2_SLICE_NO_ME = 0xE
  2110. NVML_GPU_INSTANCE_PROFILE_1_SLICE_ALL_ME = 0xF
  2111. NVML_GPU_INSTANCE_PROFILE_2_SLICE_ALL_ME = 0x10
  2112. NVML_GPU_INSTANCE_PROFILE_COUNT = 0x11
  2113. class c_nvmlGpuInstancePlacement_t(Structure):
  2114. _fields_ = [("start", c_uint),
  2115. ("size", c_uint)
  2116. ]
  2117. class c_nvmlGpuInstanceProfileInfo_t(Structure):
  2118. _fields_ = [("id", c_uint),
  2119. ("isP2pSupported", c_uint),
  2120. ("sliceCount", c_uint),
  2121. ("instanceCount", c_uint),
  2122. ("multiprocessorCount", c_uint),
  2123. ("copyEngineCount", c_uint),
  2124. ("decoderCount", c_uint),
  2125. ("encoderCount", c_uint),
  2126. ("jpegCount", c_uint),
  2127. ("ofaCount", c_uint),
  2128. ("memorySizeMB", c_ulonglong),
  2129. ]
  2130. nvmlGpuInstanceProfileInfo_v2 = 0x02000098
  2131. class c_nvmlGpuInstanceProfileInfo_v2_t(_PrintableStructure):
  2132. _fields_ = [("version", c_uint),
  2133. ("id", c_uint),
  2134. ("isP2pSupported", c_uint),
  2135. ("sliceCount", c_uint),
  2136. ("instanceCount", c_uint),
  2137. ("multiprocessorCount", c_uint),
  2138. ("copyEngineCount", c_uint),
  2139. ("decoderCount", c_uint),
  2140. ("encoderCount", c_uint),
  2141. ("jpegCount", c_uint),
  2142. ("ofaCount", c_uint),
  2143. ("memorySizeMB", c_ulonglong),
  2144. ("name", c_char * NVML_DEVICE_NAME_V2_BUFFER_SIZE)
  2145. ]
  2146. def __init__(self):
  2147. super(c_nvmlGpuInstanceProfileInfo_v2_t, self).__init__(version=nvmlGpuInstanceProfileInfo_v2)
  2148. class c_nvmlGpuInstanceInfo_t(Structure):
  2149. _fields_ = [("device", c_nvmlDevice_t),
  2150. ("id", c_uint),
  2151. ("profileId", c_uint),
  2152. ("placement", c_nvmlGpuInstancePlacement_t)
  2153. ]
  2154. class struct_c_nvmlGpuInstance_t(Structure):
  2155. pass # opaque handle
  2156. c_nvmlGpuInstance_t = POINTER(struct_c_nvmlGpuInstance_t)
  2157. NVML_COMPUTE_INSTANCE_PROFILE_1_SLICE = 0x0
  2158. NVML_COMPUTE_INSTANCE_PROFILE_2_SLICE = 0x1
  2159. NVML_COMPUTE_INSTANCE_PROFILE_3_SLICE = 0x2
  2160. NVML_COMPUTE_INSTANCE_PROFILE_4_SLICE = 0x3
  2161. NVML_COMPUTE_INSTANCE_PROFILE_7_SLICE = 0x4
  2162. NVML_COMPUTE_INSTANCE_PROFILE_8_SLICE = 0x5
  2163. NVML_COMPUTE_INSTANCE_PROFILE_6_SLICE = 0x6
  2164. NVML_COMPUTE_INSTANCE_PROFILE_1_SLICE_REV1 = 0x7
  2165. NVML_COMPUTE_INSTANCE_PROFILE_COUNT = 0x8
  2166. NVML_COMPUTE_INSTANCE_ENGINE_PROFILE_SHARED = 0x0
  2167. NVML_COMPUTE_INSTANCE_ENGINE_PROFILE_COUNT = 0x1
  2168. class c_nvmlComputeInstancePlacement_t(Structure):
  2169. _fields_ = [("start", c_uint),
  2170. ("size", c_uint)
  2171. ]
  2172. class c_nvmlComputeInstanceProfileInfo_t(Structure):
  2173. _fields_ = [("id", c_uint),
  2174. ("sliceCount", c_uint),
  2175. ("instanceCount", c_uint),
  2176. ("multiprocessorCount", c_uint),
  2177. ("sharedCopyEngineCount", c_uint),
  2178. ("sharedDecoderCount", c_uint),
  2179. ("sharedEncoderCount", c_uint),
  2180. ("sharedJpegCount", c_uint),
  2181. ("sharedOfaCount", c_uint)
  2182. ]
  2183. nvmlComputeInstanceProfileInfo_v2 = 0x02000088
  2184. class c_nvmlComputeInstanceProfileInfo_v2_t(_PrintableStructure):
  2185. _fields_ = [("version", c_uint),
  2186. ("id", c_uint),
  2187. ("sliceCount", c_uint),
  2188. ("instanceCount", c_uint),
  2189. ("multiprocessorCount", c_uint),
  2190. ("sharedCopyEngineCount", c_uint),
  2191. ("sharedDecoderCount", c_uint),
  2192. ("sharedEncoderCount", c_uint),
  2193. ("sharedJpegCount", c_uint),
  2194. ("sharedOfaCount", c_uint),
  2195. ("name", c_char * NVML_DEVICE_NAME_V2_BUFFER_SIZE)
  2196. ]
  2197. def __init__(self):
  2198. super(c_nvmlComputeInstanceProfileInfo_v2_t, self).__init__(version=nvmlComputeInstanceProfileInfo_v2)
  2199. class c_nvmlComputeInstanceInfo_t(Structure):
  2200. _fields_ = [("device", c_nvmlDevice_t),
  2201. ("gpuInstance", c_nvmlGpuInstance_t),
  2202. ("id", c_uint),
  2203. ("profileId", c_uint),
  2204. ("placement", c_nvmlComputeInstancePlacement_t)
  2205. ]
  2206. NVML_MAX_GPU_UTILIZATIONS = 8
  2207. NVML_GPU_UTILIZATION_DOMAIN_GPU = 0
  2208. NVML_GPU_UTILIZATION_DOMAIN_FB = 1
  2209. NVML_GPU_UTILIZATION_DOMAIN_VID = 2
  2210. NVML_GPU_UTILIZATION_DOMAIN_BUS = 3
  2211. class c_nvmlGpuDynamicPstatesUtilization_t(Structure):
  2212. _fields_ = [("bIsPresent", c_uint, 1),
  2213. ("percentage", c_uint),
  2214. ("incThreshold", c_uint),
  2215. ("decThreshold", c_uint)]
  2216. class c_nvmlGpuDynamicPstatesInfo_t(Structure):
  2217. _fields_ = [("flags", c_uint),
  2218. ("utilization", c_nvmlGpuDynamicPstatesUtilization_t * NVML_MAX_GPU_UTILIZATIONS)]
  2219. NVML_MAX_THERMAL_SENSORS_PER_GPU = 3
  2220. NVML_THERMAL_TARGET_NONE = 0
  2221. NVML_THERMAL_TARGET_GPU = 1
  2222. NVML_THERMAL_TARGET_MEMORY = 2
  2223. NVML_THERMAL_TARGET_POWER_SUPPLY = 4
  2224. NVML_THERMAL_TARGET_BOARD = 8
  2225. NVML_THERMAL_TARGET_VCD_BOARD = 9
  2226. NVML_THERMAL_TARGET_VCD_INLET = 10
  2227. NVML_THERMAL_TARGET_VCD_OUTLET = 11
  2228. NVML_THERMAL_TARGET_ALL = 15
  2229. NVML_THERMAL_TARGET_UNKNOWN = -1
  2230. NVML_THERMAL_CONTROLLER_NONE = 0
  2231. NVML_THERMAL_CONTROLLER_GPU_INTERNAL = 1
  2232. NVML_THERMAL_CONTROLLER_ADM1032 = 2
  2233. NVML_THERMAL_CONTROLLER_ADT7461 = 3
  2234. NVML_THERMAL_CONTROLLER_MAX6649 = 4
  2235. NVML_THERMAL_CONTROLLER_MAX1617 = 5
  2236. NVML_THERMAL_CONTROLLER_LM99 = 6
  2237. NVML_THERMAL_CONTROLLER_LM89 = 7
  2238. NVML_THERMAL_CONTROLLER_LM64 = 8
  2239. NVML_THERMAL_CONTROLLER_G781 = 9
  2240. NVML_THERMAL_CONTROLLER_ADT7473 = 10
  2241. NVML_THERMAL_CONTROLLER_SBMAX6649 = 11
  2242. NVML_THERMAL_CONTROLLER_VBIOSEVT = 12
  2243. NVML_THERMAL_CONTROLLER_OS = 13
  2244. NVML_THERMAL_CONTROLLER_NVSYSCON_CANOAS = 14
  2245. NVML_THERMAL_CONTROLLER_NVSYSCON_E551 = 15
  2246. NVML_THERMAL_CONTROLLER_MAX6649R = 16
  2247. NVML_THERMAL_CONTROLLER_ADT7473S = 17
  2248. NVML_THERMAL_CONTROLLER_UNKNOWN = -1
  2249. class c_nvmlGpuThermalSensor_t(Structure):
  2250. _fields_ = [("controller", c_int),
  2251. ("defaultMinTemp", c_int),
  2252. ("defaultMaxTemp", c_int),
  2253. ("currentTemp", c_int),
  2254. ("target", c_int)]
  2255. class c_nvmlGpuThermalSettings_t(Structure):
  2256. _fields_ = [("count", c_uint),
  2257. ("sensor", c_nvmlGpuThermalSensor_t * NVML_MAX_THERMAL_SENSORS_PER_GPU)]
  2258. _nvmlCoolerControl_t = c_uint
  2259. NVML_THERMAL_COOLER_SIGNAL_NONE = 0
  2260. NVML_THERMAL_COOLER_SIGNAL_TOGGLE = 1
  2261. NVML_THERMAL_COOLER_SIGNAL_VARIABLE = 2
  2262. NVML_THERMAL_COOLER_SIGNAL_COUNT = 3
  2263. _nvmlCoolerTarget_t = c_uint
  2264. NVML_THERMAL_COOLER_TARGET_NONE = (1 << 0)
  2265. NVML_THERMAL_COOLER_TARGET_GPU = (1 << 1)
  2266. NVML_THERMAL_COOLER_TARGET_MEMORY = (1 << 2)
  2267. NVML_THERMAL_COOLER_TARGET_POWER_SUPPLY = (1 << 3)
  2268. NVML_THERMAL_COOLER_TARGET_GPU_RELATED = (NVML_THERMAL_COOLER_TARGET_GPU | NVML_THERMAL_COOLER_TARGET_MEMORY | NVML_THERMAL_COOLER_TARGET_POWER_SUPPLY)
  2269. class c_nvmlCoolerInfo_t(_PrintableStructure):
  2270. _fields_ = [("version", c_uint),
  2271. ("index", c_uint),
  2272. ("coolerControlType", _nvmlCoolerControl_t),
  2273. ("coolerTarget", _nvmlCoolerTarget_t)
  2274. ]
  2275. nvmlCoolerInfo_v1 = 0x1000010
  2276. def nvmlDeviceGetCoolerInfo(handle):
  2277. c_coolerInfo = c_nvmlCoolerInfo_t()
  2278. c_coolerInfo.version = nvmlCoolerInfo_v1
  2279. c_coolerInfo.index = 0
  2280. fn = _nvmlGetFunctionPointer("nvmlDeviceGetCoolerInfo")
  2281. ret = fn(handle, byref(c_coolerInfo))
  2282. _nvmlCheckReturn(ret)
  2283. return [c_coolerInfo.coolerControlType, c_coolerInfo.coolerTarget]
  2284. class struct_c_nvmlComputeInstance_t(Structure):
  2285. pass # opaque handle
  2286. c_nvmlComputeInstance_t = POINTER(struct_c_nvmlComputeInstance_t)
  2287. class c_nvmlDeviceAttributes(Structure):
  2288. _fields_ = [("multiprocessorCount", c_uint),
  2289. ("sharedCopyEngineCount", c_uint),
  2290. ("sharedDecoderCount", c_uint),
  2291. ("sharedEncoderCount", c_uint),
  2292. ("sharedJpegCount", c_uint),
  2293. ("sharedOfaCount", c_uint),
  2294. ("gpuInstanceSliceCount", c_uint),
  2295. ("computeInstanceSliceCount", c_uint),
  2296. ("memorySizeMB", c_ulonglong),
  2297. ]
  2298. class c_nvmlRowRemapperHistogramValues(Structure):
  2299. _fields_ = [("max", c_uint),
  2300. ("high", c_uint),
  2301. ("partial", c_uint),
  2302. ("low", c_uint),
  2303. ("none", c_uint)
  2304. ]
  2305. NVML_GPU_CERT_CHAIN_SIZE = 0x1000
  2306. NVML_GPU_ATTESTATION_CERT_CHAIN_SIZE = 0x1400
  2307. NVML_CC_GPU_CEC_NONCE_SIZE = 0x20
  2308. NVML_CC_GPU_ATTESTATION_REPORT_SIZE = 0x2000
  2309. NVML_CC_GPU_CEC_ATTESTATION_REPORT_SIZE = 0x1000
  2310. NVML_CC_CEC_ATTESTATION_REPORT_NOT_PRESENT = 0
  2311. NVML_CC_CEC_ATTESTATION_REPORT_PRESENT = 1
  2312. class c_nvmlConfComputeSystemState_t(Structure):
  2313. _fields_ = [('environment', c_uint),
  2314. ('ccFeature', c_uint),
  2315. ('devToolsMode', c_uint),
  2316. ]
  2317. nvmlSystemConfComputeSettings_v1 = 0x1000014
  2318. class c_nvmlSystemConfComputeSettings_v1_t(Structure):
  2319. _fields_ = [('version', c_uint),
  2320. ('environment', c_uint),
  2321. ('ccFeature', c_uint),
  2322. ('devToolsMode', c_uint),
  2323. ('multiGpuMode', c_uint),
  2324. ]
  2325. def __init__(self):
  2326. super(c_nvmlSystemConfComputeSettings_v1_t, self).__init__(version=nvmlSystemConfComputeSettings_v1)
  2327. class c_nvmlConfComputeSystemCaps_t(Structure):
  2328. _fields_ = [('cpuCaps', c_uint),
  2329. ('gpusCaps', c_uint),
  2330. ]
  2331. class c_nvmlConfComputeMemSizeInfo_t(Structure):
  2332. _fields_ = [('protectedMemSizeKib', c_ulonglong),
  2333. ('unprotectedMemSizeKib', c_ulonglong),
  2334. ]
  2335. class c_nvmlConfComputeGpuCertificate_t(Structure):
  2336. _fields_ = [('certChainSize', c_uint),
  2337. ('attestationCertChainSize', c_uint),
  2338. ('certChain', c_uint8 * NVML_GPU_CERT_CHAIN_SIZE),
  2339. ('attestationCertChain', c_uint8 * NVML_GPU_ATTESTATION_CERT_CHAIN_SIZE),
  2340. ]
  2341. class c_nvmlConfComputeGpuAttestationReport_t(Structure):
  2342. _fields_ = [('isCecAttestationReportPresent', c_uint), # output
  2343. ('attestationReportSize', c_uint), # output
  2344. ('cecAttestationReportSize', c_uint), # output
  2345. ('nonce', c_uint8 * NVML_CC_GPU_CEC_NONCE_SIZE), # input: spdm supports 32 bytes on nonce
  2346. ('attestationReport', c_uint8 * NVML_CC_GPU_ATTESTATION_REPORT_SIZE), # output
  2347. ('cecAttestationReport', c_uint8 * NVML_CC_GPU_CEC_ATTESTATION_REPORT_SIZE), # output
  2348. ]
  2349. class c_nvmlConfComputeSetKeyRotationThresholdInfo_t(Structure):
  2350. _fields_ = [('version', c_uint),
  2351. ('maxAttackerAdvantage', c_ulong),
  2352. ]
  2353. ConfComputeSetKeyRotationThresholdInfo_v1 = 0x1000010
  2354. class c_nvmlConfComputeGetKeyRotationThresholdInfo_t(Structure):
  2355. _fields_ = [('version', c_uint),
  2356. ('attackerAdvantage', c_ulong),
  2357. ]
  2358. ConfComputeGetKeyRotationThresholdInfo_v1 = 0x1000010
  2359. ## string/bytes conversion for ease of use
  2360. def convertStrBytes(func):
  2361. '''
  2362. In python 3, strings are unicode instead of bytes, and need to be converted for ctypes
  2363. Args from caller: (1, 'string', <__main__.c_nvmlDevice_t at 0xFFFFFFFF>)
  2364. Args passed to function: (1, b'string', <__main__.c_nvmlDevice_t at 0xFFFFFFFF)>
  2365. ----
  2366. Returned from function: b'returned string'
  2367. Returned to caller: 'returned string'
  2368. '''
  2369. @wraps(func)
  2370. def wrapper(*args, **kwargs):
  2371. # encoding a str returns bytes in python 2 and 3
  2372. args = [arg.encode() if isinstance(arg, str) else arg for arg in args]
  2373. res = func(*args, **kwargs)
  2374. # In python 2, str and bytes are the same
  2375. # In python 3, str is unicode and should be decoded.
  2376. # Ctypes handles most conversions, this only effects c_char and char arrays.
  2377. if isinstance(res, bytes):
  2378. if isinstance(res, str):
  2379. return res
  2380. return res.decode()
  2381. return res
  2382. if sys.version_info >= (3,):
  2383. return wrapper
  2384. return func
  2385. def throwOnVersionMismatch(func):
  2386. @wraps(func)
  2387. def wrapper(*args, **kwargs):
  2388. try:
  2389. return func(*args, **kwargs)
  2390. except NVMLError_FunctionNotFound:
  2391. raise NVMLLibraryMismatchError("Unversioned function called and the "
  2392. "pyNVML version does not match the NVML lib version. "
  2393. "Either use matching pyNVML and NVML lib versions or "
  2394. "use a versioned function such as " + func.__name__ + "_v2")
  2395. return wrapper
  2396. ## C function wrappers ##
  2397. def nvmlInitWithFlags(flags):
  2398. _LoadNvmlLibrary()
  2399. #
  2400. # Initialize the library
  2401. #
  2402. fn = _nvmlGetFunctionPointer("nvmlInitWithFlags")
  2403. ret = fn(flags)
  2404. _nvmlCheckReturn(ret)
  2405. # Atomically update refcount
  2406. global _nvmlLib_refcount
  2407. libLoadLock.acquire()
  2408. _nvmlLib_refcount += 1
  2409. libLoadLock.release()
  2410. return None
  2411. def nvmlInit():
  2412. nvmlInitWithFlags(0)
  2413. return None
  2414. def _LoadNvmlLibrary():
  2415. '''
  2416. Load the library if it isn't loaded already
  2417. '''
  2418. global nvmlLib
  2419. if (nvmlLib == None):
  2420. # lock to ensure only one caller loads the library
  2421. libLoadLock.acquire()
  2422. try:
  2423. # ensure the library still isn't loaded
  2424. if (nvmlLib == None):
  2425. try:
  2426. if (sys.platform[:3] == "win"):
  2427. # cdecl calling convention
  2428. try:
  2429. # Check for nvml.dll in System32 first for DCH drivers
  2430. nvmlLib = CDLL(os.path.join(os.getenv("WINDIR", "C:/Windows"), "System32/nvml.dll"))
  2431. except OSError as ose:
  2432. # If nvml.dll is not found in System32, it should be in ProgramFiles
  2433. # load nvml.dll from %ProgramFiles%/NVIDIA Corporation/NVSMI/nvml.dll
  2434. nvmlLib = CDLL(os.path.join(os.getenv("ProgramFiles", "C:/Program Files"), "NVIDIA Corporation/NVSMI/nvml.dll"))
  2435. else:
  2436. # assume linux
  2437. nvmlLib = CDLL("libnvidia-ml.so.1")
  2438. except OSError as ose:
  2439. _nvmlCheckReturn(NVML_ERROR_LIBRARY_NOT_FOUND)
  2440. if (nvmlLib == None):
  2441. _nvmlCheckReturn(NVML_ERROR_LIBRARY_NOT_FOUND)
  2442. finally:
  2443. # lock is always freed
  2444. libLoadLock.release()
  2445. def nvmlShutdown():
  2446. #
  2447. # Leave the library loaded, but shutdown the interface
  2448. #
  2449. fn = _nvmlGetFunctionPointer("nvmlShutdown")
  2450. ret = fn()
  2451. _nvmlCheckReturn(ret)
  2452. # Atomically update refcount
  2453. global _nvmlLib_refcount
  2454. libLoadLock.acquire()
  2455. if (0 < _nvmlLib_refcount):
  2456. _nvmlLib_refcount -= 1
  2457. libLoadLock.release()
  2458. return None
  2459. # Added in 2.285
  2460. @convertStrBytes
  2461. def nvmlErrorString(result):
  2462. fn = _nvmlGetFunctionPointer("nvmlErrorString")
  2463. fn.restype = c_char_p # otherwise return is an int
  2464. ret = fn(result)
  2465. return ret
  2466. # Added in 2.285
  2467. @convertStrBytes
  2468. def nvmlSystemGetNVMLVersion():
  2469. c_version = create_string_buffer(NVML_SYSTEM_NVML_VERSION_BUFFER_SIZE)
  2470. fn = _nvmlGetFunctionPointer("nvmlSystemGetNVMLVersion")
  2471. ret = fn(c_version, c_uint(NVML_SYSTEM_NVML_VERSION_BUFFER_SIZE))
  2472. _nvmlCheckReturn(ret)
  2473. return c_version.value
  2474. def nvmlSystemGetCudaDriverVersion():
  2475. c_cuda_version = c_int()
  2476. fn = _nvmlGetFunctionPointer("nvmlSystemGetCudaDriverVersion")
  2477. ret = fn(byref(c_cuda_version))
  2478. _nvmlCheckReturn(ret)
  2479. return c_cuda_version.value
  2480. def nvmlSystemGetCudaDriverVersion_v2():
  2481. c_cuda_version = c_int()
  2482. fn = _nvmlGetFunctionPointer("nvmlSystemGetCudaDriverVersion_v2")
  2483. ret = fn(byref(c_cuda_version))
  2484. _nvmlCheckReturn(ret)
  2485. return c_cuda_version.value
  2486. # Added in 2.285
  2487. @convertStrBytes
  2488. def nvmlSystemGetProcessName(pid):
  2489. c_name = create_string_buffer(1024)
  2490. fn = _nvmlGetFunctionPointer("nvmlSystemGetProcessName")
  2491. ret = fn(c_uint(pid), c_name, c_uint(1024))
  2492. _nvmlCheckReturn(ret)
  2493. return c_name.value
  2494. @convertStrBytes
  2495. def nvmlSystemGetDriverVersion():
  2496. c_version = create_string_buffer(NVML_SYSTEM_DRIVER_VERSION_BUFFER_SIZE)
  2497. fn = _nvmlGetFunctionPointer("nvmlSystemGetDriverVersion")
  2498. ret = fn(c_version, c_uint(NVML_SYSTEM_DRIVER_VERSION_BUFFER_SIZE))
  2499. _nvmlCheckReturn(ret)
  2500. return c_version.value
  2501. # Added in 2.285
  2502. def nvmlSystemGetHicVersion():
  2503. c_count = c_uint(0)
  2504. hics = None
  2505. fn = _nvmlGetFunctionPointer("nvmlSystemGetHicVersion")
  2506. # get the count
  2507. ret = fn(byref(c_count), None)
  2508. # this should only fail with insufficient size
  2509. if ((ret != NVML_SUCCESS) and
  2510. (ret != NVML_ERROR_INSUFFICIENT_SIZE)):
  2511. raise NVMLError(ret)
  2512. # If there are no hics
  2513. if (c_count.value == 0):
  2514. return []
  2515. hic_array = c_nvmlHwbcEntry_t * c_count.value
  2516. hics = hic_array()
  2517. ret = fn(byref(c_count), hics)
  2518. _nvmlCheckReturn(ret)
  2519. return hics
  2520. def nvmlSystemGetDriverBranch():
  2521. c_branchInfo = c_nvmlSystemDriverBranchInfo_v1_t(0)
  2522. c_branchInfo.version = SystemDriverBranchInfo_v1
  2523. fn = _nvmlGetFunctionPointer("nvmlSystemGetDriverBranch")
  2524. ret = fn(byref(c_branchInfo), c_uint(NVML_SYSTEM_DRIVER_VERSION_BUFFER_SIZE))
  2525. _nvmlCheckReturn(ret)
  2526. return c_branchInfo
  2527. ## Unit get functions
  2528. def nvmlUnitGetCount():
  2529. c_count = c_uint()
  2530. fn = _nvmlGetFunctionPointer("nvmlUnitGetCount")
  2531. ret = fn(byref(c_count))
  2532. _nvmlCheckReturn(ret)
  2533. return c_count.value
  2534. def nvmlUnitGetHandleByIndex(index):
  2535. c_index = c_uint(index)
  2536. unit = c_nvmlUnit_t()
  2537. fn = _nvmlGetFunctionPointer("nvmlUnitGetHandleByIndex")
  2538. ret = fn(c_index, byref(unit))
  2539. _nvmlCheckReturn(ret)
  2540. return unit
  2541. def nvmlUnitGetUnitInfo(unit):
  2542. c_info = c_nvmlUnitInfo_t()
  2543. fn = _nvmlGetFunctionPointer("nvmlUnitGetUnitInfo")
  2544. ret = fn(unit, byref(c_info))
  2545. _nvmlCheckReturn(ret)
  2546. return c_info
  2547. def nvmlUnitGetLedState(unit):
  2548. c_state = c_nvmlLedState_t()
  2549. fn = _nvmlGetFunctionPointer("nvmlUnitGetLedState")
  2550. ret = fn(unit, byref(c_state))
  2551. _nvmlCheckReturn(ret)
  2552. return c_state
  2553. def nvmlUnitGetPsuInfo(unit):
  2554. c_info = c_nvmlPSUInfo_t()
  2555. fn = _nvmlGetFunctionPointer("nvmlUnitGetPsuInfo")
  2556. ret = fn(unit, byref(c_info))
  2557. _nvmlCheckReturn(ret)
  2558. return c_info
  2559. def nvmlUnitGetTemperature(unit, type):
  2560. c_temp = c_uint()
  2561. fn = _nvmlGetFunctionPointer("nvmlUnitGetTemperature")
  2562. ret = fn(unit, c_uint(type), byref(c_temp))
  2563. _nvmlCheckReturn(ret)
  2564. return c_temp.value
  2565. def nvmlUnitGetFanSpeedInfo(unit):
  2566. c_speeds = c_nvmlUnitFanSpeeds_t()
  2567. fn = _nvmlGetFunctionPointer("nvmlUnitGetFanSpeedInfo")
  2568. ret = fn(unit, byref(c_speeds))
  2569. _nvmlCheckReturn(ret)
  2570. return c_speeds
  2571. # added to API
  2572. def nvmlUnitGetDeviceCount(unit):
  2573. c_count = c_uint(0)
  2574. # query the unit to determine device count
  2575. fn = _nvmlGetFunctionPointer("nvmlUnitGetDevices")
  2576. ret = fn(unit, byref(c_count), None)
  2577. if (ret == NVML_ERROR_INSUFFICIENT_SIZE):
  2578. ret = NVML_SUCCESS
  2579. _nvmlCheckReturn(ret)
  2580. return c_count.value
  2581. def nvmlUnitGetDevices(unit):
  2582. c_count = c_uint(nvmlUnitGetDeviceCount(unit))
  2583. device_array = c_nvmlDevice_t * c_count.value
  2584. c_devices = device_array()
  2585. fn = _nvmlGetFunctionPointer("nvmlUnitGetDevices")
  2586. ret = fn(unit, byref(c_count), c_devices)
  2587. _nvmlCheckReturn(ret)
  2588. return c_devices
  2589. ## Device get functions
  2590. def nvmlDeviceGetCount():
  2591. c_count = c_uint()
  2592. fn = _nvmlGetFunctionPointer("nvmlDeviceGetCount_v2")
  2593. ret = fn(byref(c_count))
  2594. _nvmlCheckReturn(ret)
  2595. return c_count.value
  2596. def nvmlDeviceGetHandleByIndex(index):
  2597. c_index = c_uint(index)
  2598. device = c_nvmlDevice_t()
  2599. fn = _nvmlGetFunctionPointer("nvmlDeviceGetHandleByIndex_v2")
  2600. ret = fn(c_index, byref(device))
  2601. _nvmlCheckReturn(ret)
  2602. return device
  2603. # Deprecated
  2604. @convertStrBytes
  2605. def nvmlDeviceGetHandleBySerial(serial):
  2606. c_serial = c_char_p(serial)
  2607. device = c_nvmlDevice_t()
  2608. fn = _nvmlGetFunctionPointer("nvmlDeviceGetHandleBySerial")
  2609. ret = fn(c_serial, byref(device))
  2610. _nvmlCheckReturn(ret)
  2611. return device
  2612. @convertStrBytes
  2613. def nvmlDeviceGetHandleByUUID(uuid):
  2614. c_uuid = c_char_p(uuid)
  2615. device = c_nvmlDevice_t()
  2616. fn = _nvmlGetFunctionPointer("nvmlDeviceGetHandleByUUID")
  2617. ret = fn(c_uuid, byref(device))
  2618. _nvmlCheckReturn(ret)
  2619. return device
  2620. @convertStrBytes
  2621. def nvmlDeviceGetHandleByUUIDV(uuid, type):
  2622. c_uuid = c_nvmlUUID_t()
  2623. c_uuid.type = type
  2624. if type == NVML_UUID_TYPE_ASCII:
  2625. c_uuid.value.str = uuid
  2626. elif type == NVML_UUID_TYPE_BINARY:
  2627. memmove(c_uuid.value.bytes, uuid, NVML_DEVICE_UUID_BINARY_LEN)
  2628. device = c_nvmlDevice_t()
  2629. fn = _nvmlGetFunctionPointer("nvmlDeviceGetHandleByUUIDV")
  2630. ret = fn(byref(c_uuid), byref(device))
  2631. _nvmlCheckReturn(ret)
  2632. return device
  2633. @convertStrBytes
  2634. def nvmlDeviceGetHandleByPciBusId(pciBusId):
  2635. c_busId = c_char_p(pciBusId)
  2636. device = c_nvmlDevice_t()
  2637. fn = _nvmlGetFunctionPointer("nvmlDeviceGetHandleByPciBusId_v2")
  2638. ret = fn(c_busId, byref(device))
  2639. _nvmlCheckReturn(ret)
  2640. return device
  2641. @convertStrBytes
  2642. def nvmlDeviceGetName(handle):
  2643. c_name = create_string_buffer(NVML_DEVICE_NAME_V2_BUFFER_SIZE)
  2644. fn = _nvmlGetFunctionPointer("nvmlDeviceGetName")
  2645. ret = fn(handle, c_name, c_uint(NVML_DEVICE_NAME_V2_BUFFER_SIZE))
  2646. _nvmlCheckReturn(ret)
  2647. return c_name.value
  2648. class c_nvmlDevicePerfModes_v1_t(_PrintableStructure):
  2649. _fields_ = [
  2650. ('version', c_uint),
  2651. ('str', c_char * NVML_PERF_MODES_BUFFER_SIZE),
  2652. ]
  2653. nvmlDevicePerfModes_v1 = 0x1000804
  2654. @convertStrBytes
  2655. def nvmlDeviceGetPerformanceModes(handle):
  2656. perfModes = c_nvmlDevicePerfModes_v1_t()
  2657. perfModes.version = nvmlDevicePerfModes_v1
  2658. fn = _nvmlGetFunctionPointer("nvmlDeviceGetPerformanceModes")
  2659. ret = fn(handle, byref(perfModes))
  2660. _nvmlCheckReturn(ret)
  2661. return perfModes.str
  2662. class c_nvmlDeviceCurrentClockFreqs_v1_t(_PrintableStructure):
  2663. _fields_ = [
  2664. ('version', c_uint),
  2665. ('str', c_char * NVML_PERF_MODES_BUFFER_SIZE),
  2666. ]
  2667. nvmlDeviceCurrentClockFreqs_v1 = 0x1000804
  2668. @convertStrBytes
  2669. def nvmlDeviceGetCurrentClockFreqs(handle):
  2670. currentClockFreqs = c_nvmlDeviceCurrentClockFreqs_v1_t()
  2671. currentClockFreqs.version = nvmlDeviceCurrentClockFreqs_v1
  2672. fn = _nvmlGetFunctionPointer("nvmlDeviceGetCurrentClockFreqs")
  2673. ret = fn(handle, byref(currentClockFreqs))
  2674. _nvmlCheckReturn(ret)
  2675. return currentClockFreqs.str
  2676. def nvmlDeviceGetBoardId(handle):
  2677. c_id = c_uint()
  2678. fn = _nvmlGetFunctionPointer("nvmlDeviceGetBoardId")
  2679. ret = fn(handle, byref(c_id))
  2680. _nvmlCheckReturn(ret)
  2681. return c_id.value
  2682. def nvmlDeviceGetMultiGpuBoard(handle):
  2683. c_multiGpu = c_uint()
  2684. fn = _nvmlGetFunctionPointer("nvmlDeviceGetMultiGpuBoard")
  2685. ret = fn(handle, byref(c_multiGpu))
  2686. _nvmlCheckReturn(ret)
  2687. return c_multiGpu.value
  2688. def nvmlDeviceGetBrand(handle):
  2689. c_type = _nvmlBrandType_t()
  2690. fn = _nvmlGetFunctionPointer("nvmlDeviceGetBrand")
  2691. ret = fn(handle, byref(c_type))
  2692. _nvmlCheckReturn(ret)
  2693. return c_type.value
  2694. def nvmlDeviceGetC2cModeInfoV1(handle):
  2695. c_info = c_nvmlC2cModeInfo_v1_t()
  2696. fn = _nvmlGetFunctionPointer("nvmlDeviceGetC2cModeInfoV")
  2697. ret = fn(handle, byref(c_info))
  2698. _nvmlCheckReturn(ret)
  2699. return c_info
  2700. def nvmlDeviceGetC2cModeInfoV(handle):
  2701. return nvmlDeviceGetC2cModeInfoV1(handle)
  2702. @convertStrBytes
  2703. def nvmlDeviceGetBoardPartNumber(handle):
  2704. c_part_number = create_string_buffer(NVML_DEVICE_PART_NUMBER_BUFFER_SIZE)
  2705. fn = _nvmlGetFunctionPointer("nvmlDeviceGetBoardPartNumber")
  2706. ret = fn(handle, c_part_number, c_uint(NVML_DEVICE_PART_NUMBER_BUFFER_SIZE))
  2707. _nvmlCheckReturn(ret)
  2708. return c_part_number.value
  2709. @convertStrBytes
  2710. def nvmlDeviceGetSerial(handle):
  2711. c_serial = create_string_buffer(NVML_DEVICE_SERIAL_BUFFER_SIZE)
  2712. fn = _nvmlGetFunctionPointer("nvmlDeviceGetSerial")
  2713. ret = fn(handle, c_serial, c_uint(NVML_DEVICE_SERIAL_BUFFER_SIZE))
  2714. _nvmlCheckReturn(ret)
  2715. return c_serial.value
  2716. def nvmlDeviceGetModuleId(handle, moduleId=c_uint()):
  2717. isReference = type(moduleId) is not c_uint
  2718. moduleIdRef = moduleId if isReference else byref(moduleId)
  2719. fn = _nvmlGetFunctionPointer("nvmlDeviceGetModuleId")
  2720. ret = fn(handle, moduleIdRef)
  2721. if isReference:
  2722. return ret
  2723. else:
  2724. _nvmlCheckReturn(ret)
  2725. return moduleId.value
  2726. def nvmlDeviceGetMemoryAffinity(handle, nodeSetSize, scope):
  2727. affinity_array = c_ulonglong * nodeSetSize
  2728. c_affinity = affinity_array()
  2729. fn = _nvmlGetFunctionPointer("nvmlDeviceGetMemoryAffinity")
  2730. ret = fn(handle, nodeSetSize, byref(c_affinity), _nvmlAffinityScope_t(scope))
  2731. _nvmlCheckReturn(ret)
  2732. return c_affinity
  2733. def nvmlDeviceGetCpuAffinityWithinScope(handle, cpuSetSize, scope):
  2734. affinity_array = c_ulonglong * cpuSetSize
  2735. c_affinity = affinity_array()
  2736. fn = _nvmlGetFunctionPointer("nvmlDeviceGetCpuAffinityWithinScope")
  2737. ret = fn(handle, cpuSetSize, byref(c_affinity), _nvmlAffinityScope_t(scope))
  2738. _nvmlCheckReturn(ret)
  2739. return c_affinity
  2740. def nvmlDeviceGetCpuAffinity(handle, cpuSetSize):
  2741. affinity_array = c_ulonglong * cpuSetSize
  2742. c_affinity = affinity_array()
  2743. fn = _nvmlGetFunctionPointer("nvmlDeviceGetCpuAffinity")
  2744. ret = fn(handle, cpuSetSize, byref(c_affinity))
  2745. _nvmlCheckReturn(ret)
  2746. return c_affinity
  2747. def nvmlDeviceSetCpuAffinity(handle):
  2748. fn = _nvmlGetFunctionPointer("nvmlDeviceSetCpuAffinity")
  2749. ret = fn(handle)
  2750. _nvmlCheckReturn(ret)
  2751. return None
  2752. def nvmlDeviceClearCpuAffinity(handle):
  2753. fn = _nvmlGetFunctionPointer("nvmlDeviceClearCpuAffinity")
  2754. ret = fn(handle)
  2755. _nvmlCheckReturn(ret)
  2756. return None
  2757. def nvmlDeviceGetNumaNodeId(handle):
  2758. fn = _nvmlGetFunctionPointer("nvmlDeviceGetNumaNodeId")
  2759. node = c_int()
  2760. ret = fn(handle, byref(node))
  2761. _nvmlCheckReturn(ret)
  2762. return node.value
  2763. def nvmlDeviceGetAddressingMode(device):
  2764. c_mode = c_nvmlDeviceAddressingMode_t()
  2765. fn = _nvmlGetFunctionPointer("nvmlDeviceGetAddressingMode")
  2766. ret = fn(device, byref(c_mode))
  2767. _nvmlCheckReturn(ret)
  2768. return c_mode.value
  2769. def nvmlDeviceGetMinorNumber(handle):
  2770. c_minor_number = c_uint()
  2771. fn = _nvmlGetFunctionPointer("nvmlDeviceGetMinorNumber")
  2772. ret = fn(handle, byref(c_minor_number))
  2773. _nvmlCheckReturn(ret)
  2774. return c_minor_number.value
  2775. @convertStrBytes
  2776. def nvmlDeviceGetUUID(handle):
  2777. c_uuid = create_string_buffer(NVML_DEVICE_UUID_V2_BUFFER_SIZE)
  2778. fn = _nvmlGetFunctionPointer("nvmlDeviceGetUUID")
  2779. ret = fn(handle, c_uuid, c_uint(NVML_DEVICE_UUID_V2_BUFFER_SIZE))
  2780. _nvmlCheckReturn(ret)
  2781. return c_uuid.value
  2782. @convertStrBytes
  2783. def nvmlDeviceGetInforomVersion(handle, infoRomObject):
  2784. c_version = create_string_buffer(NVML_DEVICE_INFOROM_VERSION_BUFFER_SIZE)
  2785. fn = _nvmlGetFunctionPointer("nvmlDeviceGetInforomVersion")
  2786. ret = fn(handle, _nvmlInforomObject_t(infoRomObject),
  2787. c_version, c_uint(NVML_DEVICE_INFOROM_VERSION_BUFFER_SIZE))
  2788. _nvmlCheckReturn(ret)
  2789. return c_version.value
  2790. # Added in 4.304
  2791. @convertStrBytes
  2792. def nvmlDeviceGetInforomImageVersion(handle):
  2793. c_version = create_string_buffer(NVML_DEVICE_INFOROM_VERSION_BUFFER_SIZE)
  2794. fn = _nvmlGetFunctionPointer("nvmlDeviceGetInforomImageVersion")
  2795. ret = fn(handle, c_version, c_uint(NVML_DEVICE_INFOROM_VERSION_BUFFER_SIZE))
  2796. _nvmlCheckReturn(ret)
  2797. return c_version.value
  2798. # Added in 4.304
  2799. def nvmlDeviceGetInforomConfigurationChecksum(handle):
  2800. c_checksum = c_uint()
  2801. fn = _nvmlGetFunctionPointer("nvmlDeviceGetInforomConfigurationChecksum")
  2802. ret = fn(handle, byref(c_checksum))
  2803. _nvmlCheckReturn(ret)
  2804. return c_checksum.value
  2805. # Added in 4.304
  2806. def nvmlDeviceValidateInforom(handle):
  2807. fn = _nvmlGetFunctionPointer("nvmlDeviceValidateInforom")
  2808. ret = fn(handle)
  2809. _nvmlCheckReturn(ret)
  2810. return None
  2811. def nvmlDeviceGetLastBBXFlushTime(handle):
  2812. c_timestamp = c_ulonglong()
  2813. c_durationUs = c_ulong()
  2814. fn = _nvmlGetFunctionPointer("nvmlDeviceGetLastBBXFlushTime")
  2815. ret = fn(handle, byref(c_timestamp), byref(c_durationUs))
  2816. _nvmlCheckReturn(ret)
  2817. return [c_timestamp.value, c_durationUs.value]
  2818. def nvmlDeviceGetDisplayMode(handle):
  2819. c_mode = _nvmlEnableState_t()
  2820. fn = _nvmlGetFunctionPointer("nvmlDeviceGetDisplayMode")
  2821. ret = fn(handle, byref(c_mode))
  2822. _nvmlCheckReturn(ret)
  2823. return c_mode.value
  2824. def nvmlDeviceGetDisplayActive(handle):
  2825. c_mode = _nvmlEnableState_t()
  2826. fn = _nvmlGetFunctionPointer("nvmlDeviceGetDisplayActive")
  2827. ret = fn(handle, byref(c_mode))
  2828. _nvmlCheckReturn(ret)
  2829. return c_mode.value
  2830. def nvmlDeviceGetPersistenceMode(handle):
  2831. c_state = _nvmlEnableState_t()
  2832. fn = _nvmlGetFunctionPointer("nvmlDeviceGetPersistenceMode")
  2833. ret = fn(handle, byref(c_state))
  2834. _nvmlCheckReturn(ret)
  2835. return c_state.value
  2836. def nvmlDeviceGetPciInfoExt(handle, c_info):
  2837. fn = _nvmlGetFunctionPointer("nvmlDeviceGetPciInfoExt")
  2838. ret = fn(handle, c_info)
  2839. _nvmlCheckReturn(ret)
  2840. return None
  2841. def nvmlDeviceGetPciInfo_v3(handle):
  2842. c_info = nvmlPciInfo_t()
  2843. fn = _nvmlGetFunctionPointer("nvmlDeviceGetPciInfo_v3")
  2844. ret = fn(handle, byref(c_info))
  2845. _nvmlCheckReturn(ret)
  2846. return c_info
  2847. def nvmlDeviceGetPciInfo(handle):
  2848. return nvmlDeviceGetPciInfo_v3(handle)
  2849. def nvmlDeviceGetClockInfo(handle, type):
  2850. c_clock = c_uint()
  2851. fn = _nvmlGetFunctionPointer("nvmlDeviceGetClockInfo")
  2852. ret = fn(handle, _nvmlClockType_t(type), byref(c_clock))
  2853. _nvmlCheckReturn(ret)
  2854. return c_clock.value
  2855. # Added in 2.285
  2856. def nvmlDeviceGetMaxClockInfo(handle, type):
  2857. c_clock = c_uint()
  2858. fn = _nvmlGetFunctionPointer("nvmlDeviceGetMaxClockInfo")
  2859. ret = fn(handle, _nvmlClockType_t(type), byref(c_clock))
  2860. _nvmlCheckReturn(ret)
  2861. return c_clock.value
  2862. # Added in 4.304
  2863. # Deprecated
  2864. def nvmlDeviceGetApplicationsClock(handle, type):
  2865. c_clock = c_uint()
  2866. fn = _nvmlGetFunctionPointer("nvmlDeviceGetApplicationsClock")
  2867. ret = fn(handle, _nvmlClockType_t(type), byref(c_clock))
  2868. _nvmlCheckReturn(ret)
  2869. return c_clock.value
  2870. def nvmlDeviceGetMaxCustomerBoostClock(handle, type):
  2871. c_clock = c_uint()
  2872. fn = _nvmlGetFunctionPointer("nvmlDeviceGetMaxCustomerBoostClock")
  2873. ret = fn(handle, _nvmlClockType_t(type), byref(c_clock))
  2874. _nvmlCheckReturn(ret)
  2875. return c_clock.value
  2876. def nvmlDeviceGetClock(handle, type, id):
  2877. c_clock = c_uint()
  2878. fn = _nvmlGetFunctionPointer("nvmlDeviceGetClock")
  2879. ret = fn(handle, _nvmlClockType_t(type), _nvmlClockId_t(id), byref(c_clock))
  2880. _nvmlCheckReturn(ret)
  2881. return c_clock.value
  2882. # Added in 5.319
  2883. # Deprecated
  2884. def nvmlDeviceGetDefaultApplicationsClock(handle, type):
  2885. c_clock = c_uint()
  2886. fn = _nvmlGetFunctionPointer("nvmlDeviceGetDefaultApplicationsClock")
  2887. ret = fn(handle, _nvmlClockType_t(type), byref(c_clock))
  2888. _nvmlCheckReturn(ret)
  2889. return c_clock.value
  2890. # Added in 4.304
  2891. def nvmlDeviceGetSupportedMemoryClocks(handle):
  2892. # first call to get the size
  2893. c_count = c_uint(0)
  2894. fn = _nvmlGetFunctionPointer("nvmlDeviceGetSupportedMemoryClocks")
  2895. ret = fn(handle, byref(c_count), None)
  2896. if (ret == NVML_SUCCESS):
  2897. # special case, no clocks
  2898. return []
  2899. elif (ret == NVML_ERROR_INSUFFICIENT_SIZE):
  2900. # typical case
  2901. clocks_array = c_uint * c_count.value
  2902. c_clocks = clocks_array()
  2903. # make the call again
  2904. ret = fn(handle, byref(c_count), c_clocks)
  2905. _nvmlCheckReturn(ret)
  2906. procs = []
  2907. for i in range(c_count.value):
  2908. procs.append(c_clocks[i])
  2909. return procs
  2910. else:
  2911. # error case
  2912. raise NVMLError(ret)
  2913. # Added in 4.304
  2914. def nvmlDeviceGetSupportedGraphicsClocks(handle, memoryClockMHz):
  2915. # first call to get the size
  2916. c_count = c_uint(0)
  2917. fn = _nvmlGetFunctionPointer("nvmlDeviceGetSupportedGraphicsClocks")
  2918. ret = fn(handle, c_uint(memoryClockMHz), byref(c_count), None)
  2919. if (ret == NVML_SUCCESS):
  2920. # special case, no clocks
  2921. return []
  2922. elif (ret == NVML_ERROR_INSUFFICIENT_SIZE):
  2923. # typical case
  2924. clocks_array = c_uint * c_count.value
  2925. c_clocks = clocks_array()
  2926. # make the call again
  2927. ret = fn(handle, c_uint(memoryClockMHz), byref(c_count), c_clocks)
  2928. _nvmlCheckReturn(ret)
  2929. procs = []
  2930. for i in range(c_count.value):
  2931. procs.append(c_clocks[i])
  2932. return procs
  2933. else:
  2934. # error case
  2935. raise NVMLError(ret)
  2936. def nvmlDeviceGetFanSpeed(handle):
  2937. c_speed = c_uint()
  2938. fn = _nvmlGetFunctionPointer("nvmlDeviceGetFanSpeed")
  2939. ret = fn(handle, byref(c_speed))
  2940. _nvmlCheckReturn(ret)
  2941. return c_speed.value
  2942. def nvmlDeviceGetFanSpeed_v2(handle, fan):
  2943. c_speed = c_uint()
  2944. fn = _nvmlGetFunctionPointer("nvmlDeviceGetFanSpeed_v2")
  2945. ret = fn(handle, fan, byref(c_speed))
  2946. _nvmlCheckReturn(ret)
  2947. return c_speed.value
  2948. class c_nvmlFanSpeedInfo_t(_PrintableStructure):
  2949. _fields_ = [
  2950. ('version', c_uint),
  2951. ('fan', c_uint),
  2952. ('speed', c_uint),
  2953. ]
  2954. nvmlFanSpeedInfo_v1 = 0x100000C
  2955. def nvmlDeviceGetFanSpeedRPM(handle):
  2956. c_fanSpeed = c_nvmlFanSpeedInfo_t()
  2957. c_fanSpeed.fan = 0
  2958. c_fanSpeed.version = nvmlFanSpeedInfo_v1
  2959. fn = _nvmlGetFunctionPointer("nvmlDeviceGetFanSpeedRPM")
  2960. ret = fn(handle, byref(c_fanSpeed))
  2961. _nvmlCheckReturn(ret)
  2962. return c_fanSpeed.speed
  2963. def nvmlDeviceGetTargetFanSpeed(handle, fan):
  2964. c_speed = c_uint()
  2965. fn = _nvmlGetFunctionPointer("nvmlDeviceGetTargetFanSpeed")
  2966. ret = fn(handle, fan, byref(c_speed))
  2967. _nvmlCheckReturn(ret)
  2968. return c_speed.value
  2969. def nvmlDeviceGetNumFans(device):
  2970. c_numFans = c_uint()
  2971. fn = _nvmlGetFunctionPointer("nvmlDeviceGetNumFans")
  2972. ret = fn(device, byref(c_numFans))
  2973. _nvmlCheckReturn(ret)
  2974. return c_numFans.value
  2975. def nvmlDeviceSetDefaultFanSpeed_v2(handle, index):
  2976. fn = _nvmlGetFunctionPointer("nvmlDeviceSetDefaultFanSpeed_v2");
  2977. ret = fn(handle, index)
  2978. _nvmlCheckReturn(ret)
  2979. return NVML_SUCCESS
  2980. def nvmlDeviceGetMinMaxFanSpeed(handle, minSpeed=c_uint(), maxSpeed=c_uint()):
  2981. isReference = (type(minSpeed) is not c_uint) or (type(maxSpeed) is not c_uint)
  2982. minSpeedRef = minSpeed if isReference else byref(minSpeed)
  2983. maxSpeedRef = maxSpeed if isReference else byref(maxSpeed)
  2984. fn = _nvmlGetFunctionPointer("nvmlDeviceGetMinMaxFanSpeed")
  2985. ret = fn(handle, minSpeedRef, maxSpeedRef)
  2986. _nvmlCheckReturn(ret)
  2987. return NVML_SUCCESS if isReference else [minSpeed.value, maxSpeed.value]
  2988. def nvmlDeviceGetFanControlPolicy_v2(handle, fan, fanControlPolicy=c_uint()):
  2989. isReference = type(fanControlPolicy) is not c_uint
  2990. fanControlPolicyRef = fanControlPolicy if isReference else byref(fanControlPolicy)
  2991. fn = _nvmlGetFunctionPointer("nvmlDeviceGetFanControlPolicy_v2")
  2992. ret = fn(handle, fan, fanControlPolicyRef)
  2993. _nvmlCheckReturn(ret)
  2994. return NVML_SUCCESS if isReference else fanControlPolicy.value
  2995. def nvmlDeviceSetFanControlPolicy(handle, fan, fanControlPolicy):
  2996. fn = _nvmlGetFunctionPointer("nvmlDeviceSetFanControlPolicy")
  2997. ret = fn(handle, fan, _nvmlFanControlPolicy_t(fanControlPolicy))
  2998. _nvmlCheckReturn(ret)
  2999. return NVML_SUCCESS
  3000. class c_nvmlTemperature_v1_t(_PrintableStructure):
  3001. _fields_ = [
  3002. ('version', c_uint),
  3003. ('sensorType', _nvmlTemperatureSensors_t),
  3004. ('temperature', c_int),
  3005. ]
  3006. nvmlTemperature_v1 = 0x100000C
  3007. def nvmlDeviceGetTemperatureV1(handle, sensor):
  3008. c_temp = c_nvmlTemperature_v1_t()
  3009. c_temp.version = nvmlTemperature_v1
  3010. c_temp.sensorType = _nvmlTemperatureSensors_t(sensor)
  3011. fn = _nvmlGetFunctionPointer("nvmlDeviceGetTemperatureV")
  3012. ret = fn(handle, byref(c_temp))
  3013. _nvmlCheckReturn(ret)
  3014. return c_temp.temperature
  3015. def nvmlDeviceGetTemperatureV(handle, sensor, version=nvmlTemperature_v1):
  3016. if version == nvmlTemperature_v1:
  3017. return nvmlDeviceGetTemperatureV1(handle, sensor)
  3018. else:
  3019. raise NVMLError(NVML_ERROR_ARGUMENT_VERSION_MISMATCH)
  3020. # DEPRECATED use nvmlDeviceGetTemperatureV instead
  3021. def nvmlDeviceGetTemperature(handle, sensor):
  3022. c_temp = c_uint()
  3023. fn = _nvmlGetFunctionPointer("nvmlDeviceGetTemperature")
  3024. ret = fn(handle, _nvmlTemperatureSensors_t(sensor), byref(c_temp))
  3025. _nvmlCheckReturn(ret)
  3026. return c_temp.value
  3027. def nvmlDeviceGetTemperatureThreshold(handle, threshold):
  3028. c_temp = c_uint()
  3029. fn = _nvmlGetFunctionPointer("nvmlDeviceGetTemperatureThreshold")
  3030. ret = fn(handle, _nvmlTemperatureThresholds_t(threshold), byref(c_temp))
  3031. _nvmlCheckReturn(ret)
  3032. return c_temp.value
  3033. def nvmlDeviceSetTemperatureThreshold(handle, threshold, temp):
  3034. c_temp = c_uint()
  3035. c_temp.value = temp
  3036. fn = _nvmlGetFunctionPointer("nvmlDeviceSetTemperatureThreshold")
  3037. ret = fn(handle, _nvmlTemperatureThresholds_t(threshold), byref(c_temp))
  3038. _nvmlCheckReturn(ret)
  3039. return None
  3040. def nvmlDeviceGetMarginTemperature(handle):
  3041. c_marginTempInfo = c_nvmlMarginTemperature_v1_t()
  3042. c_marginTempInfo.version = nvmlMarginTemperature_v1
  3043. fn = _nvmlGetFunctionPointer("nvmlDeviceGetMarginTemperature")
  3044. ret = fn(handle, byref(c_marginTempInfo))
  3045. _nvmlCheckReturn(ret)
  3046. return c_marginTempInfo.marginTemperature
  3047. # DEPRECATED use nvmlDeviceGetPerformanceState
  3048. def nvmlDeviceGetPowerState(handle):
  3049. c_pstate = _nvmlPstates_t()
  3050. fn = _nvmlGetFunctionPointer("nvmlDeviceGetPowerState")
  3051. ret = fn(handle, byref(c_pstate))
  3052. _nvmlCheckReturn(ret)
  3053. return c_pstate.value
  3054. def nvmlDeviceGetPerformanceState(handle):
  3055. c_pstate = _nvmlPstates_t()
  3056. fn = _nvmlGetFunctionPointer("nvmlDeviceGetPerformanceState")
  3057. ret = fn(handle, byref(c_pstate))
  3058. _nvmlCheckReturn(ret)
  3059. return c_pstate.value
  3060. # Deprecated
  3061. def nvmlDeviceGetPowerManagementMode(handle):
  3062. c_pcapMode = _nvmlEnableState_t()
  3063. fn = _nvmlGetFunctionPointer("nvmlDeviceGetPowerManagementMode")
  3064. ret = fn(handle, byref(c_pcapMode))
  3065. _nvmlCheckReturn(ret)
  3066. return c_pcapMode.value
  3067. def nvmlDeviceGetPowerManagementLimit(handle):
  3068. c_limit = c_uint()
  3069. fn = _nvmlGetFunctionPointer("nvmlDeviceGetPowerManagementLimit")
  3070. ret = fn(handle, byref(c_limit))
  3071. _nvmlCheckReturn(ret)
  3072. return c_limit.value
  3073. # Added in 4.304
  3074. def nvmlDeviceGetPowerManagementLimitConstraints(handle):
  3075. c_minLimit = c_uint()
  3076. c_maxLimit = c_uint()
  3077. fn = _nvmlGetFunctionPointer("nvmlDeviceGetPowerManagementLimitConstraints")
  3078. ret = fn(handle, byref(c_minLimit), byref(c_maxLimit))
  3079. _nvmlCheckReturn(ret)
  3080. return [c_minLimit.value, c_maxLimit.value]
  3081. # Added in 4.304
  3082. def nvmlDeviceGetPowerManagementDefaultLimit(handle):
  3083. c_limit = c_uint()
  3084. fn = _nvmlGetFunctionPointer("nvmlDeviceGetPowerManagementDefaultLimit")
  3085. ret = fn(handle, byref(c_limit))
  3086. _nvmlCheckReturn(ret)
  3087. return c_limit.value
  3088. # Added in 331
  3089. def nvmlDeviceGetEnforcedPowerLimit(handle):
  3090. c_limit = c_uint()
  3091. fn = _nvmlGetFunctionPointer("nvmlDeviceGetEnforcedPowerLimit")
  3092. ret = fn(handle, byref(c_limit))
  3093. _nvmlCheckReturn(ret)
  3094. return c_limit.value
  3095. def nvmlDeviceGetPowerUsage(handle):
  3096. c_watts = c_uint()
  3097. fn = _nvmlGetFunctionPointer("nvmlDeviceGetPowerUsage")
  3098. ret = fn(handle, byref(c_watts))
  3099. _nvmlCheckReturn(ret)
  3100. return c_watts.value
  3101. def nvmlDeviceGetTotalEnergyConsumption(handle):
  3102. c_millijoules = c_uint64()
  3103. fn = _nvmlGetFunctionPointer("nvmlDeviceGetTotalEnergyConsumption")
  3104. ret = fn(handle, byref(c_millijoules))
  3105. _nvmlCheckReturn(ret)
  3106. return c_millijoules.value
  3107. # Added in 4.304
  3108. def nvmlDeviceGetGpuOperationMode(handle):
  3109. c_currState = _nvmlGpuOperationMode_t()
  3110. c_pendingState = _nvmlGpuOperationMode_t()
  3111. fn = _nvmlGetFunctionPointer("nvmlDeviceGetGpuOperationMode")
  3112. ret = fn(handle, byref(c_currState), byref(c_pendingState))
  3113. _nvmlCheckReturn(ret)
  3114. return [c_currState.value, c_pendingState.value]
  3115. # Added in 4.304
  3116. def nvmlDeviceGetCurrentGpuOperationMode(handle):
  3117. return nvmlDeviceGetGpuOperationMode(handle)[0]
  3118. # Added in 4.304
  3119. def nvmlDeviceGetPendingGpuOperationMode(handle):
  3120. return nvmlDeviceGetGpuOperationMode(handle)[1]
  3121. def nvmlDeviceGetMemoryInfo(handle, version=None):
  3122. if not version:
  3123. c_memory = c_nvmlMemory_t()
  3124. fn = _nvmlGetFunctionPointer("nvmlDeviceGetMemoryInfo")
  3125. else:
  3126. c_memory = c_nvmlMemory_v2_t()
  3127. c_memory.version = version
  3128. fn = _nvmlGetFunctionPointer("nvmlDeviceGetMemoryInfo_v2")
  3129. ret = fn(handle, byref(c_memory))
  3130. _nvmlCheckReturn(ret)
  3131. return c_memory
  3132. def nvmlDeviceGetBAR1MemoryInfo(handle):
  3133. c_bar1_memory = c_nvmlBAR1Memory_t()
  3134. fn = _nvmlGetFunctionPointer("nvmlDeviceGetBAR1MemoryInfo")
  3135. ret = fn(handle, byref(c_bar1_memory))
  3136. _nvmlCheckReturn(ret)
  3137. return c_bar1_memory
  3138. def nvmlDeviceGetComputeMode(handle):
  3139. c_mode = _nvmlComputeMode_t()
  3140. fn = _nvmlGetFunctionPointer("nvmlDeviceGetComputeMode")
  3141. ret = fn(handle, byref(c_mode))
  3142. _nvmlCheckReturn(ret)
  3143. return c_mode.value
  3144. def nvmlDeviceGetCudaComputeCapability(handle):
  3145. c_major = c_int()
  3146. c_minor = c_int()
  3147. fn = _nvmlGetFunctionPointer("nvmlDeviceGetCudaComputeCapability")
  3148. ret = fn(handle, byref(c_major), byref(c_minor))
  3149. _nvmlCheckReturn(ret)
  3150. return (c_major.value, c_minor.value)
  3151. def nvmlDeviceGetEccMode(handle):
  3152. c_currState = _nvmlEnableState_t()
  3153. c_pendingState = _nvmlEnableState_t()
  3154. fn = _nvmlGetFunctionPointer("nvmlDeviceGetEccMode")
  3155. ret = fn(handle, byref(c_currState), byref(c_pendingState))
  3156. _nvmlCheckReturn(ret)
  3157. return [c_currState.value, c_pendingState.value]
  3158. # added to API
  3159. def nvmlDeviceGetCurrentEccMode(handle):
  3160. return nvmlDeviceGetEccMode(handle)[0]
  3161. # added to API
  3162. def nvmlDeviceGetPendingEccMode(handle):
  3163. return nvmlDeviceGetEccMode(handle)[1]
  3164. def nvmlDeviceGetDefaultEccMode(handle):
  3165. c_defaultState = _nvmlEnableState_t()
  3166. fn = _nvmlGetFunctionPointer("nvmlDeviceGetDefaultEccMode")
  3167. ret = fn(handle, byref(c_defaultState))
  3168. _nvmlCheckReturn(ret)
  3169. return [c_defaultState.value]
  3170. def nvmlDeviceGetTotalEccErrors(handle, errorType, counterType):
  3171. c_count = c_ulonglong()
  3172. fn = _nvmlGetFunctionPointer("nvmlDeviceGetTotalEccErrors")
  3173. ret = fn(handle, _nvmlMemoryErrorType_t(errorType),
  3174. _nvmlEccCounterType_t(counterType), byref(c_count))
  3175. _nvmlCheckReturn(ret)
  3176. return c_count.value
  3177. # This is deprecated, instead use nvmlDeviceGetMemoryErrorCounter
  3178. def nvmlDeviceGetDetailedEccErrors(handle, errorType, counterType):
  3179. c_counts = c_nvmlEccErrorCounts_t()
  3180. fn = _nvmlGetFunctionPointer("nvmlDeviceGetDetailedEccErrors")
  3181. ret = fn(handle, _nvmlMemoryErrorType_t(errorType),
  3182. _nvmlEccCounterType_t(counterType), byref(c_counts))
  3183. _nvmlCheckReturn(ret)
  3184. return c_counts
  3185. # Added in 4.304
  3186. def nvmlDeviceGetMemoryErrorCounter(handle, errorType, counterType, locationType):
  3187. c_count = c_ulonglong()
  3188. fn = _nvmlGetFunctionPointer("nvmlDeviceGetMemoryErrorCounter")
  3189. ret = fn(handle,
  3190. _nvmlMemoryErrorType_t(errorType),
  3191. _nvmlEccCounterType_t(counterType),
  3192. _nvmlMemoryLocation_t(locationType),
  3193. byref(c_count))
  3194. _nvmlCheckReturn(ret)
  3195. return c_count.value
  3196. def nvmlDeviceGetUtilizationRates(handle):
  3197. c_util = c_nvmlUtilization_t()
  3198. fn = _nvmlGetFunctionPointer("nvmlDeviceGetUtilizationRates")
  3199. ret = fn(handle, byref(c_util))
  3200. _nvmlCheckReturn(ret)
  3201. return c_util
  3202. def nvmlDeviceGetEncoderUtilization(handle):
  3203. c_util = c_uint()
  3204. c_samplingPeriod = c_uint()
  3205. fn = _nvmlGetFunctionPointer("nvmlDeviceGetEncoderUtilization")
  3206. ret = fn(handle, byref(c_util), byref(c_samplingPeriod))
  3207. _nvmlCheckReturn(ret)
  3208. return [c_util.value, c_samplingPeriod.value]
  3209. def nvmlDeviceGetDecoderUtilization(handle):
  3210. c_util = c_uint()
  3211. c_samplingPeriod = c_uint()
  3212. fn = _nvmlGetFunctionPointer("nvmlDeviceGetDecoderUtilization")
  3213. ret = fn(handle, byref(c_util), byref(c_samplingPeriod))
  3214. _nvmlCheckReturn(ret)
  3215. return [c_util.value, c_samplingPeriod.value]
  3216. def nvmlDeviceGetJpgUtilization(handle):
  3217. c_util = c_uint()
  3218. c_samplingPeriod = c_uint()
  3219. fn = _nvmlGetFunctionPointer("nvmlDeviceGetJpgUtilization")
  3220. ret = fn(handle, byref(c_util), byref(c_samplingPeriod))
  3221. _nvmlCheckReturn(ret)
  3222. return [c_util.value, c_samplingPeriod.value]
  3223. def nvmlDeviceGetOfaUtilization(handle):
  3224. c_util = c_uint()
  3225. c_samplingPeriod = c_uint()
  3226. fn = _nvmlGetFunctionPointer("nvmlDeviceGetOfaUtilization")
  3227. ret = fn(handle, byref(c_util), byref(c_samplingPeriod))
  3228. _nvmlCheckReturn(ret)
  3229. return [c_util.value, c_samplingPeriod.value]
  3230. def nvmlDeviceGetPcieReplayCounter(handle):
  3231. c_replay = c_uint()
  3232. fn = _nvmlGetFunctionPointer("nvmlDeviceGetPcieReplayCounter")
  3233. ret = fn(handle, byref(c_replay))
  3234. _nvmlCheckReturn(ret)
  3235. return c_replay.value
  3236. def nvmlDeviceGetDriverModel(handle):
  3237. c_currModel = _nvmlDriverModel_t()
  3238. c_pendingModel = _nvmlDriverModel_t()
  3239. fn = _nvmlGetFunctionPointer("nvmlDeviceGetDriverModel")
  3240. ret = fn(handle, byref(c_currModel), byref(c_pendingModel))
  3241. _nvmlCheckReturn(ret)
  3242. return [c_currModel.value, c_pendingModel.value]
  3243. # added to API
  3244. def nvmlDeviceGetCurrentDriverModel(handle):
  3245. return nvmlDeviceGetDriverModel(handle)[0]
  3246. # added to API
  3247. def nvmlDeviceGetPendingDriverModel(handle):
  3248. return nvmlDeviceGetDriverModel(handle)[1]
  3249. # Added in 2.285
  3250. @convertStrBytes
  3251. def nvmlDeviceGetVbiosVersion(handle):
  3252. c_version = create_string_buffer(NVML_DEVICE_VBIOS_VERSION_BUFFER_SIZE)
  3253. fn = _nvmlGetFunctionPointer("nvmlDeviceGetVbiosVersion")
  3254. ret = fn(handle, c_version, c_uint(NVML_DEVICE_VBIOS_VERSION_BUFFER_SIZE))
  3255. _nvmlCheckReturn(ret)
  3256. return c_version.value
  3257. # Added in 2.285
  3258. def nvmlDeviceGetComputeRunningProcesses_v2(handle):
  3259. # first call to get the size
  3260. c_count = c_uint(0)
  3261. fn = _nvmlGetFunctionPointer("nvmlDeviceGetComputeRunningProcesses_v2")
  3262. ret = fn(handle, byref(c_count), None)
  3263. if (ret == NVML_SUCCESS):
  3264. # special case, no running processes
  3265. return []
  3266. elif (ret == NVML_ERROR_INSUFFICIENT_SIZE):
  3267. # typical case
  3268. # oversize the array incase more processes are created
  3269. c_count.value = c_count.value * 2 + 5
  3270. proc_array = c_nvmlProcessInfo_v2_t * c_count.value
  3271. c_procs = proc_array()
  3272. # make the call again
  3273. ret = fn(handle, byref(c_count), c_procs)
  3274. _nvmlCheckReturn(ret)
  3275. procs = []
  3276. for i in range(c_count.value):
  3277. # use an alternative struct for this object
  3278. obj = nvmlStructToFriendlyObject(c_procs[i])
  3279. if (obj.usedGpuMemory == NVML_VALUE_NOT_AVAILABLE_ulonglong.value):
  3280. # special case for WDDM on Windows, see comment above
  3281. obj.usedGpuMemory = None
  3282. procs.append(obj)
  3283. return procs
  3284. else:
  3285. # error case
  3286. raise NVMLError(ret)
  3287. # Added in 2.285
  3288. def nvmlDeviceGetComputeRunningProcesses_v3(handle):
  3289. # first call to get the size
  3290. c_count = c_uint(0)
  3291. fn = _nvmlGetFunctionPointer("nvmlDeviceGetComputeRunningProcesses_v3")
  3292. ret = fn(handle, byref(c_count), None)
  3293. if (ret == NVML_SUCCESS):
  3294. # special case, no running processes
  3295. return []
  3296. elif (ret == NVML_ERROR_INSUFFICIENT_SIZE):
  3297. # typical case
  3298. # oversize the array incase more processes are created
  3299. c_count.value = c_count.value * 2 + 5
  3300. proc_array = c_nvmlProcessInfo_v3_t * c_count.value
  3301. c_procs = proc_array()
  3302. # make the call again
  3303. ret = fn(handle, byref(c_count), c_procs)
  3304. _nvmlCheckReturn(ret)
  3305. procs = []
  3306. for i in range(c_count.value):
  3307. # use an alternative struct for this object
  3308. obj = nvmlStructToFriendlyObject(c_procs[i])
  3309. if (obj.usedGpuMemory == NVML_VALUE_NOT_AVAILABLE_ulonglong.value):
  3310. # special case for WDDM on Windows, see comment above
  3311. obj.usedGpuMemory = None
  3312. procs.append(obj)
  3313. return procs
  3314. else:
  3315. # error case
  3316. raise NVMLError(ret)
  3317. @throwOnVersionMismatch
  3318. def nvmlDeviceGetComputeRunningProcesses(handle):
  3319. return nvmlDeviceGetComputeRunningProcesses_v3(handle)
  3320. def nvmlDeviceGetGraphicsRunningProcesses_v2(handle):
  3321. # first call to get the size
  3322. c_count = c_uint(0)
  3323. fn = _nvmlGetFunctionPointer("nvmlDeviceGetGraphicsRunningProcesses_v2")
  3324. ret = fn(handle, byref(c_count), None)
  3325. if (ret == NVML_SUCCESS):
  3326. # special case, no running processes
  3327. return []
  3328. elif (ret == NVML_ERROR_INSUFFICIENT_SIZE):
  3329. # typical case
  3330. # oversize the array incase more processes are created
  3331. c_count.value = c_count.value * 2 + 5
  3332. proc_array = c_nvmlProcessInfo_v2_t * c_count.value
  3333. c_procs = proc_array()
  3334. # make the call again
  3335. ret = fn(handle, byref(c_count), c_procs)
  3336. _nvmlCheckReturn(ret)
  3337. procs = []
  3338. for i in range(c_count.value):
  3339. # use an alternative struct for this object
  3340. obj = nvmlStructToFriendlyObject(c_procs[i])
  3341. if (obj.usedGpuMemory == NVML_VALUE_NOT_AVAILABLE_ulonglong.value):
  3342. # special case for WDDM on Windows, see comment above
  3343. obj.usedGpuMemory = None
  3344. procs.append(obj)
  3345. return procs
  3346. else:
  3347. # error case
  3348. raise NVMLError(ret)
  3349. def nvmlDeviceGetGraphicsRunningProcesses_v3(handle):
  3350. # first call to get the size
  3351. c_count = c_uint(0)
  3352. fn = _nvmlGetFunctionPointer("nvmlDeviceGetGraphicsRunningProcesses_v3")
  3353. ret = fn(handle, byref(c_count), None)
  3354. if (ret == NVML_SUCCESS):
  3355. # special case, no running processes
  3356. return []
  3357. elif (ret == NVML_ERROR_INSUFFICIENT_SIZE):
  3358. # typical case
  3359. # oversize the array incase more processes are created
  3360. c_count.value = c_count.value * 2 + 5
  3361. proc_array = c_nvmlProcessInfo_v3_t * c_count.value
  3362. c_procs = proc_array()
  3363. # make the call again
  3364. ret = fn(handle, byref(c_count), c_procs)
  3365. _nvmlCheckReturn(ret)
  3366. procs = []
  3367. for i in range(c_count.value):
  3368. # use an alternative struct for this object
  3369. obj = nvmlStructToFriendlyObject(c_procs[i])
  3370. if (obj.usedGpuMemory == NVML_VALUE_NOT_AVAILABLE_ulonglong.value):
  3371. # special case for WDDM on Windows, see comment above
  3372. obj.usedGpuMemory = None
  3373. procs.append(obj)
  3374. return procs
  3375. else:
  3376. # error case
  3377. raise NVMLError(ret)
  3378. @throwOnVersionMismatch
  3379. def nvmlDeviceGetGraphicsRunningProcesses(handle):
  3380. return nvmlDeviceGetGraphicsRunningProcesses_v3(handle)
  3381. @throwOnVersionMismatch
  3382. def nvmlDeviceGetMPSComputeRunningProcesses(handle):
  3383. return nvmlDeviceGetMPSComputeRunningProcesses_v3(handle)
  3384. def nvmlDeviceGetMPSComputeRunningProcesses_v2(handle):
  3385. # first call to get the size
  3386. c_count = c_uint(0)
  3387. fn = _nvmlGetFunctionPointer("nvmlDeviceGetMPSComputeRunningProcesses_v2")
  3388. ret = fn(handle, byref(c_count), None)
  3389. if (ret == NVML_SUCCESS):
  3390. # special case, no running processes
  3391. return []
  3392. elif (ret == NVML_ERROR_INSUFFICIENT_SIZE):
  3393. # typical case
  3394. # oversize the array incase more processes are created
  3395. c_count.value = c_count.value * 2 + 5
  3396. proc_array = c_nvmlProcessInfo_v2_t * c_count.value
  3397. c_procs = proc_array()
  3398. # make the call again
  3399. ret = fn(handle, byref(c_count), c_procs)
  3400. _nvmlCheckReturn(ret)
  3401. procs = []
  3402. for i in range(c_count.value):
  3403. # use an alternative struct for this object
  3404. obj = nvmlStructToFriendlyObject(c_procs[i])
  3405. if (obj.usedGpuMemory == NVML_VALUE_NOT_AVAILABLE_ulonglong.value):
  3406. # special case for WDDM on Windows, see comment above
  3407. obj.usedGpuMemory = None
  3408. procs.append(obj)
  3409. return procs
  3410. else:
  3411. # error case
  3412. raise NVMLError(ret)
  3413. def nvmlDeviceGetMPSComputeRunningProcesses_v3(handle):
  3414. # first call to get the size
  3415. c_count = c_uint(0)
  3416. fn = _nvmlGetFunctionPointer("nvmlDeviceGetMPSComputeRunningProcesses_v3")
  3417. ret = fn(handle, byref(c_count), None)
  3418. if (ret == NVML_SUCCESS):
  3419. # special case, no running processes
  3420. return []
  3421. elif (ret == NVML_ERROR_INSUFFICIENT_SIZE):
  3422. # typical case
  3423. # oversize the array incase more processes are created
  3424. c_count.value = c_count.value * 2 + 5
  3425. proc_array = c_nvmlProcessInfo_v3_t * c_count.value
  3426. c_procs = proc_array()
  3427. # make the call again
  3428. ret = fn(handle, byref(c_count), c_procs)
  3429. _nvmlCheckReturn(ret)
  3430. procs = []
  3431. for i in range(c_count.value):
  3432. # use an alternative struct for this object
  3433. obj = nvmlStructToFriendlyObject(c_procs[i])
  3434. if (obj.usedGpuMemory == NVML_VALUE_NOT_AVAILABLE_ulonglong.value):
  3435. # special case for WDDM on Windows, see comment above
  3436. obj.usedGpuMemory = None
  3437. procs.append(obj)
  3438. return procs
  3439. else:
  3440. # error case
  3441. raise NVMLError(ret)
  3442. def nvmlDeviceGetRunningProcessDetailList(handle, version, mode):
  3443. c_processDetailList = c_nvmlProcessDetailList_t()
  3444. c_processDetailList.version = version
  3445. c_processDetailList.mode = mode
  3446. fn = _nvmlGetFunctionPointer("nvmlDeviceGetRunningProcessDetailList")
  3447. # first call to get the size
  3448. ret = fn(handle, byref(c_processDetailList))
  3449. if (ret == NVML_SUCCESS):
  3450. # special case, no running processes
  3451. return []
  3452. elif (ret == NVML_ERROR_INSUFFICIENT_SIZE):
  3453. c_procs = c_nvmlProcessDetail_v1_t * c_processDetailList.numProcArrayEntries
  3454. c_processDetailList.procArray = cast((c_procs)(), POINTER(c_nvmlProcessDetail_v1_t))
  3455. # make the call again
  3456. ret = fn(handle, byref(c_processDetailList))
  3457. _nvmlCheckReturn(ret)
  3458. procs = []
  3459. for i in range(c_processDetailList.numProcArrayEntries):
  3460. # use an alternative struct for this object
  3461. obj = c_processDetailList.procArray[i]
  3462. if (obj.usedGpuMemory == NVML_VALUE_NOT_AVAILABLE_ulonglong.value):
  3463. obj.usedGpuMemory = None
  3464. if (obj.usedGpuCcProtectedMemory == NVML_VALUE_NOT_AVAILABLE_ulonglong.value):
  3465. obj.usedGpuCcProtectedMemory = None
  3466. procs.append(obj)
  3467. return procs
  3468. else:
  3469. # error case
  3470. raise NVMLError(ret)
  3471. def nvmlDeviceGetAutoBoostedClocksEnabled(handle):
  3472. c_isEnabled = _nvmlEnableState_t()
  3473. c_defaultIsEnabled = _nvmlEnableState_t()
  3474. fn = _nvmlGetFunctionPointer("nvmlDeviceGetAutoBoostedClocksEnabled")
  3475. ret = fn(handle, byref(c_isEnabled), byref(c_defaultIsEnabled))
  3476. _nvmlCheckReturn(ret)
  3477. return [c_isEnabled.value, c_defaultIsEnabled.value]
  3478. #Throws NVML_ERROR_NOT_SUPPORTED if hardware doesn't support setting auto boosted clocks
  3479. ## Set functions
  3480. def nvmlUnitSetLedState(unit, color):
  3481. fn = _nvmlGetFunctionPointer("nvmlUnitSetLedState")
  3482. ret = fn(unit, _nvmlLedColor_t(color))
  3483. _nvmlCheckReturn(ret)
  3484. return None
  3485. def nvmlDeviceSetPersistenceMode(handle, mode):
  3486. fn = _nvmlGetFunctionPointer("nvmlDeviceSetPersistenceMode")
  3487. ret = fn(handle, _nvmlEnableState_t(mode))
  3488. _nvmlCheckReturn(ret)
  3489. return None
  3490. def nvmlDeviceSetComputeMode(handle, mode):
  3491. fn = _nvmlGetFunctionPointer("nvmlDeviceSetComputeMode")
  3492. ret = fn(handle, _nvmlComputeMode_t(mode))
  3493. _nvmlCheckReturn(ret)
  3494. return None
  3495. def nvmlDeviceSetEccMode(handle, mode):
  3496. fn = _nvmlGetFunctionPointer("nvmlDeviceSetEccMode")
  3497. ret = fn(handle, _nvmlEnableState_t(mode))
  3498. _nvmlCheckReturn(ret)
  3499. return None
  3500. def nvmlDeviceClearEccErrorCounts(handle, counterType):
  3501. fn = _nvmlGetFunctionPointer("nvmlDeviceClearEccErrorCounts")
  3502. ret = fn(handle, _nvmlEccCounterType_t(counterType))
  3503. _nvmlCheckReturn(ret)
  3504. return None
  3505. def nvmlDeviceSetDriverModel(handle, model):
  3506. fn = _nvmlGetFunctionPointer("nvmlDeviceSetDriverModel")
  3507. ret = fn(handle, _nvmlDriverModel_t(model))
  3508. _nvmlCheckReturn(ret)
  3509. return None
  3510. def nvmlDeviceSetAutoBoostedClocksEnabled(handle, enabled):
  3511. fn = _nvmlGetFunctionPointer("nvmlDeviceSetAutoBoostedClocksEnabled")
  3512. ret = fn(handle, _nvmlEnableState_t(enabled))
  3513. _nvmlCheckReturn(ret)
  3514. return None
  3515. #Throws NVML_ERROR_NOT_SUPPORTED if hardware doesn't support setting auto boosted clocks
  3516. def nvmlDeviceSetDefaultAutoBoostedClocksEnabled(handle, enabled, flags):
  3517. fn = _nvmlGetFunctionPointer("nvmlDeviceSetDefaultAutoBoostedClocksEnabled")
  3518. ret = fn(handle, _nvmlEnableState_t(enabled), c_uint(flags))
  3519. _nvmlCheckReturn(ret)
  3520. return None
  3521. #Throws NVML_ERROR_NOT_SUPPORTED if hardware doesn't support setting auto boosted clocks
  3522. def nvmlDeviceSetGpuLockedClocks(handle, minGpuClockMHz, maxGpuClockMHz):
  3523. fn = _nvmlGetFunctionPointer("nvmlDeviceSetGpuLockedClocks")
  3524. ret = fn(handle, c_uint(minGpuClockMHz), c_uint(maxGpuClockMHz))
  3525. _nvmlCheckReturn(ret)
  3526. return None
  3527. def nvmlDeviceResetGpuLockedClocks(handle):
  3528. fn = _nvmlGetFunctionPointer("nvmlDeviceResetGpuLockedClocks")
  3529. ret = fn(handle)
  3530. _nvmlCheckReturn(ret)
  3531. return None
  3532. def nvmlDeviceSetMemoryLockedClocks(handle, minMemClockMHz, maxMemClockMHz):
  3533. fn = _nvmlGetFunctionPointer("nvmlDeviceSetMemoryLockedClocks")
  3534. ret = fn(handle, c_uint(minMemClockMHz), c_uint(maxMemClockMHz))
  3535. _nvmlCheckReturn(ret)
  3536. return None
  3537. def nvmlDeviceResetMemoryLockedClocks(handle):
  3538. fn = _nvmlGetFunctionPointer("nvmlDeviceResetMemoryLockedClocks")
  3539. ret = fn(handle)
  3540. _nvmlCheckReturn(ret)
  3541. return None
  3542. def nvmlDeviceGetClkMonStatus(handle, c_clkMonInfo=nvmlClkMonStatus_t()):
  3543. isReference = type(c_clkMonInfo) is not nvmlClkMonStatus_t
  3544. c_clkMonInfoRef = c_clkMonInfo if isReference else byref(c_clkMonInfo)
  3545. fn = _nvmlGetFunctionPointer("nvmlDeviceGetClkMonStatus")
  3546. ret = fn(handle, c_clkMonInfoRef)
  3547. _nvmlCheckReturn(ret)
  3548. return NVML_SUCCESS if isReference else c_clkMonInfo
  3549. # Added in 4.304
  3550. # Deprecated
  3551. def nvmlDeviceSetApplicationsClocks(handle, maxMemClockMHz, maxGraphicsClockMHz):
  3552. fn = _nvmlGetFunctionPointer("nvmlDeviceSetApplicationsClocks")
  3553. ret = fn(handle, c_uint(maxMemClockMHz), c_uint(maxGraphicsClockMHz))
  3554. _nvmlCheckReturn(ret)
  3555. return None
  3556. # Added in 4.304
  3557. # Deprecated
  3558. def nvmlDeviceResetApplicationsClocks(handle):
  3559. fn = _nvmlGetFunctionPointer("nvmlDeviceResetApplicationsClocks")
  3560. ret = fn(handle)
  3561. _nvmlCheckReturn(ret)
  3562. return None
  3563. # Added in 4.304
  3564. def nvmlDeviceSetPowerManagementLimit(handle, limit):
  3565. fn = _nvmlGetFunctionPointer("nvmlDeviceSetPowerManagementLimit")
  3566. ret = fn(handle, c_uint(limit))
  3567. _nvmlCheckReturn(ret)
  3568. return None
  3569. # Added in 4.304
  3570. def nvmlDeviceSetGpuOperationMode(handle, mode):
  3571. fn = _nvmlGetFunctionPointer("nvmlDeviceSetGpuOperationMode")
  3572. ret = fn(handle, _nvmlGpuOperationMode_t(mode))
  3573. _nvmlCheckReturn(ret)
  3574. return None
  3575. # Added in 2.285
  3576. def nvmlEventSetCreate():
  3577. fn = _nvmlGetFunctionPointer("nvmlEventSetCreate")
  3578. eventSet = c_nvmlEventSet_t()
  3579. ret = fn(byref(eventSet))
  3580. _nvmlCheckReturn(ret)
  3581. return eventSet
  3582. # Added in 2.285
  3583. def nvmlDeviceRegisterEvents(handle, eventTypes, eventSet):
  3584. fn = _nvmlGetFunctionPointer("nvmlDeviceRegisterEvents")
  3585. ret = fn(handle, c_ulonglong(eventTypes), eventSet)
  3586. _nvmlCheckReturn(ret)
  3587. return None
  3588. # Added in 2.285
  3589. def nvmlDeviceGetSupportedEventTypes(handle):
  3590. c_eventTypes = c_ulonglong()
  3591. fn = _nvmlGetFunctionPointer("nvmlDeviceGetSupportedEventTypes")
  3592. ret = fn(handle, byref(c_eventTypes))
  3593. _nvmlCheckReturn(ret)
  3594. return c_eventTypes.value
  3595. # raises NVML_ERROR_TIMEOUT exception on timeout
  3596. def nvmlEventSetWait_v2(eventSet, timeoutms):
  3597. fn = _nvmlGetFunctionPointer("nvmlEventSetWait_v2")
  3598. data = c_nvmlEventData_t()
  3599. ret = fn(eventSet, byref(data), c_uint(timeoutms))
  3600. _nvmlCheckReturn(ret)
  3601. return data
  3602. def nvmlEventSetWait(eventSet, timeoutms):
  3603. return nvmlEventSetWait_v2(eventSet, timeoutms)
  3604. # Added in 2.285
  3605. def nvmlEventSetFree(eventSet):
  3606. fn = _nvmlGetFunctionPointer("nvmlEventSetFree")
  3607. ret = fn(eventSet)
  3608. _nvmlCheckReturn(ret)
  3609. return None
  3610. # Added in 3.295
  3611. def nvmlDeviceOnSameBoard(handle1, handle2):
  3612. fn = _nvmlGetFunctionPointer("nvmlDeviceOnSameBoard")
  3613. onSameBoard = c_int()
  3614. ret = fn(handle1, handle2, byref(onSameBoard))
  3615. _nvmlCheckReturn(ret)
  3616. return (onSameBoard.value != 0)
  3617. # Added in 3.295
  3618. def nvmlDeviceGetCurrPcieLinkGeneration(handle):
  3619. fn = _nvmlGetFunctionPointer("nvmlDeviceGetCurrPcieLinkGeneration")
  3620. gen = c_uint()
  3621. ret = fn(handle, byref(gen))
  3622. _nvmlCheckReturn(ret)
  3623. return gen.value
  3624. # Added in 3.295
  3625. def nvmlDeviceGetMaxPcieLinkGeneration(handle):
  3626. fn = _nvmlGetFunctionPointer("nvmlDeviceGetMaxPcieLinkGeneration")
  3627. gen = c_uint()
  3628. ret = fn(handle, byref(gen))
  3629. _nvmlCheckReturn(ret)
  3630. return gen.value
  3631. # Added in 3.295
  3632. def nvmlDeviceGetCurrPcieLinkWidth(handle):
  3633. fn = _nvmlGetFunctionPointer("nvmlDeviceGetCurrPcieLinkWidth")
  3634. width = c_uint()
  3635. ret = fn(handle, byref(width))
  3636. _nvmlCheckReturn(ret)
  3637. return width.value
  3638. # Added in 3.295
  3639. def nvmlDeviceGetMaxPcieLinkWidth(handle):
  3640. fn = _nvmlGetFunctionPointer("nvmlDeviceGetMaxPcieLinkWidth")
  3641. width = c_uint()
  3642. ret = fn(handle, byref(width))
  3643. _nvmlCheckReturn(ret)
  3644. return width.value
  3645. def nvmlDeviceGetGpuMaxPcieLinkGeneration(handle):
  3646. fn = _nvmlGetFunctionPointer("nvmlDeviceGetGpuMaxPcieLinkGeneration")
  3647. gen = c_uint()
  3648. ret = fn(handle, byref(gen))
  3649. _nvmlCheckReturn(ret)
  3650. return gen.value
  3651. # Added in 4.304
  3652. # Deprecated
  3653. def nvmlDeviceGetSupportedClocksThrottleReasons(handle):
  3654. c_reasons= c_ulonglong()
  3655. fn = _nvmlGetFunctionPointer("nvmlDeviceGetSupportedClocksThrottleReasons")
  3656. ret = fn(handle, byref(c_reasons))
  3657. _nvmlCheckReturn(ret)
  3658. return c_reasons.value
  3659. def nvmlDeviceGetSupportedClocksEventReasons(handle):
  3660. c_reasons= c_ulonglong()
  3661. fn = _nvmlGetFunctionPointer("nvmlDeviceGetSupportedClocksEventReasons")
  3662. ret = fn(handle, byref(c_reasons))
  3663. _nvmlCheckReturn(ret)
  3664. return c_reasons.value
  3665. # Added in 4.304
  3666. # Deprecated
  3667. def nvmlDeviceGetCurrentClocksThrottleReasons(handle):
  3668. c_reasons= c_ulonglong()
  3669. fn = _nvmlGetFunctionPointer("nvmlDeviceGetCurrentClocksThrottleReasons")
  3670. ret = fn(handle, byref(c_reasons))
  3671. _nvmlCheckReturn(ret)
  3672. return c_reasons.value
  3673. def nvmlDeviceGetCurrentClocksEventReasons(handle):
  3674. c_reasons= c_ulonglong()
  3675. fn = _nvmlGetFunctionPointer("nvmlDeviceGetCurrentClocksEventReasons")
  3676. ret = fn(handle, byref(c_reasons))
  3677. _nvmlCheckReturn(ret)
  3678. return c_reasons.value
  3679. # Added in 5.319
  3680. def nvmlDeviceGetIndex(handle):
  3681. fn = _nvmlGetFunctionPointer("nvmlDeviceGetIndex")
  3682. c_index = c_uint()
  3683. ret = fn(handle, byref(c_index))
  3684. _nvmlCheckReturn(ret)
  3685. return c_index.value
  3686. # Added in 5.319
  3687. def nvmlDeviceGetAccountingMode(handle):
  3688. c_mode = _nvmlEnableState_t()
  3689. fn = _nvmlGetFunctionPointer("nvmlDeviceGetAccountingMode")
  3690. ret = fn(handle, byref(c_mode))
  3691. _nvmlCheckReturn(ret)
  3692. return c_mode.value
  3693. def nvmlDeviceSetAccountingMode(handle, mode):
  3694. fn = _nvmlGetFunctionPointer("nvmlDeviceSetAccountingMode")
  3695. ret = fn(handle, _nvmlEnableState_t(mode))
  3696. _nvmlCheckReturn(ret)
  3697. return None
  3698. def nvmlDeviceClearAccountingPids(handle):
  3699. fn = _nvmlGetFunctionPointer("nvmlDeviceClearAccountingPids")
  3700. ret = fn(handle)
  3701. _nvmlCheckReturn(ret)
  3702. return None
  3703. def nvmlDeviceGetAccountingStats(handle, pid):
  3704. stats = c_nvmlAccountingStats_t()
  3705. fn = _nvmlGetFunctionPointer("nvmlDeviceGetAccountingStats")
  3706. ret = fn(handle, c_uint(pid), byref(stats))
  3707. _nvmlCheckReturn(ret)
  3708. if (stats.maxMemoryUsage == NVML_VALUE_NOT_AVAILABLE_ulonglong.value):
  3709. # special case for WDDM on Windows, see comment above
  3710. stats.maxMemoryUsage = None
  3711. return stats
  3712. def nvmlDeviceGetAccountingPids(handle):
  3713. count = c_uint(nvmlDeviceGetAccountingBufferSize(handle))
  3714. pids = (c_uint * count.value)()
  3715. fn = _nvmlGetFunctionPointer("nvmlDeviceGetAccountingPids")
  3716. ret = fn(handle, byref(count), pids)
  3717. _nvmlCheckReturn(ret)
  3718. return list(map(int, pids[0:count.value]))
  3719. def nvmlDeviceGetAccountingBufferSize(handle):
  3720. bufferSize = c_uint()
  3721. fn = _nvmlGetFunctionPointer("nvmlDeviceGetAccountingBufferSize")
  3722. ret = fn(handle, byref(bufferSize))
  3723. _nvmlCheckReturn(ret)
  3724. return int(bufferSize.value)
  3725. def nvmlDeviceGetRetiredPages(device, sourceFilter):
  3726. c_source = _nvmlPageRetirementCause_t(sourceFilter)
  3727. c_count = c_uint(0)
  3728. fn = _nvmlGetFunctionPointer("nvmlDeviceGetRetiredPages")
  3729. # First call will get the size
  3730. ret = fn(device, c_source, byref(c_count), None)
  3731. # this should only fail with insufficient size
  3732. if ((ret != NVML_SUCCESS) and
  3733. (ret != NVML_ERROR_INSUFFICIENT_SIZE)):
  3734. raise NVMLError(ret)
  3735. # call again with a buffer
  3736. # oversize the array for the rare cases where additional pages
  3737. # are retired between NVML calls
  3738. c_count.value = c_count.value * 2 + 5
  3739. page_array = c_ulonglong * c_count.value
  3740. c_pages = page_array()
  3741. ret = fn(device, c_source, byref(c_count), c_pages)
  3742. _nvmlCheckReturn(ret)
  3743. return list(map(int, c_pages[0:c_count.value]))
  3744. def nvmlDeviceGetRetiredPages_v2(device, sourceFilter):
  3745. c_source = _nvmlPageRetirementCause_t(sourceFilter)
  3746. c_count = c_uint(0)
  3747. fn = _nvmlGetFunctionPointer("nvmlDeviceGetRetiredPages_v2")
  3748. # First call will get the size
  3749. ret = fn(device, c_source, byref(c_count), None)
  3750. # this should only fail with insufficient size
  3751. if ((ret != NVML_SUCCESS) and
  3752. (ret != NVML_ERROR_INSUFFICIENT_SIZE)):
  3753. raise NVMLError(ret)
  3754. # call again with a buffer
  3755. # oversize the array for the rare cases where additional pages
  3756. # are retired between NVML calls
  3757. c_count.value = c_count.value * 2 + 5
  3758. page_array = c_ulonglong * c_count.value
  3759. c_pages = page_array()
  3760. times_array = c_ulonglong * c_count.value
  3761. c_times = times_array()
  3762. ret = fn(device, c_source, byref(c_count), c_pages, c_times)
  3763. _nvmlCheckReturn(ret)
  3764. return [ { 'address': int(c_pages[i]), 'timestamp': int(c_times[i]) } for i in range(c_count.value) ];
  3765. def nvmlDeviceGetRetiredPagesPendingStatus(device):
  3766. c_pending = _nvmlEnableState_t()
  3767. fn = _nvmlGetFunctionPointer("nvmlDeviceGetRetiredPagesPendingStatus")
  3768. ret = fn(device, byref(c_pending))
  3769. _nvmlCheckReturn(ret)
  3770. return int(c_pending.value)
  3771. def nvmlDeviceGetAPIRestriction(device, apiType):
  3772. c_permission = _nvmlEnableState_t()
  3773. fn = _nvmlGetFunctionPointer("nvmlDeviceGetAPIRestriction")
  3774. ret = fn(device, _nvmlRestrictedAPI_t(apiType), byref(c_permission))
  3775. _nvmlCheckReturn(ret)
  3776. return int(c_permission.value)
  3777. def nvmlDeviceSetAPIRestriction(handle, apiType, isRestricted):
  3778. fn = _nvmlGetFunctionPointer("nvmlDeviceSetAPIRestriction")
  3779. ret = fn(handle, _nvmlRestrictedAPI_t(apiType), _nvmlEnableState_t(isRestricted))
  3780. _nvmlCheckReturn(ret)
  3781. return None
  3782. def nvmlDeviceGetBridgeChipInfo(handle):
  3783. bridgeHierarchy = c_nvmlBridgeChipHierarchy_t()
  3784. fn = _nvmlGetFunctionPointer("nvmlDeviceGetBridgeChipInfo")
  3785. ret = fn(handle, byref(bridgeHierarchy))
  3786. _nvmlCheckReturn(ret)
  3787. return bridgeHierarchy
  3788. def nvmlDeviceGetSamples(device, sampling_type, timeStamp):
  3789. c_sampling_type = _nvmlSamplingType_t(sampling_type)
  3790. c_time_stamp = c_ulonglong(timeStamp)
  3791. c_sample_count = c_uint(0)
  3792. c_sample_value_type = _nvmlValueType_t()
  3793. fn = _nvmlGetFunctionPointer("nvmlDeviceGetSamples")
  3794. ## First Call gets the size
  3795. ret = fn(device, c_sampling_type, c_time_stamp, byref(c_sample_value_type), byref(c_sample_count), None)
  3796. # Stop if this fails
  3797. if (ret != NVML_SUCCESS):
  3798. raise NVMLError(ret)
  3799. sampleArray = c_sample_count.value * c_nvmlSample_t
  3800. c_samples = sampleArray()
  3801. ret = fn(device, c_sampling_type, c_time_stamp, byref(c_sample_value_type), byref(c_sample_count), c_samples)
  3802. _nvmlCheckReturn(ret)
  3803. return (c_sample_value_type.value, c_samples[0:c_sample_count.value])
  3804. # Deprecated
  3805. def nvmlDeviceGetViolationStatus(device, perfPolicyType):
  3806. c_perfPolicy_type = _nvmlPerfPolicyType_t(perfPolicyType)
  3807. c_violTime = c_nvmlViolationTime_t()
  3808. fn = _nvmlGetFunctionPointer("nvmlDeviceGetViolationStatus")
  3809. ## Invoke the method to get violation time
  3810. ret = fn(device, c_perfPolicy_type, byref(c_violTime))
  3811. _nvmlCheckReturn(ret)
  3812. return c_violTime
  3813. def nvmlDeviceGetPcieThroughput(device, counter):
  3814. c_util = c_uint()
  3815. fn = _nvmlGetFunctionPointer("nvmlDeviceGetPcieThroughput")
  3816. ret = fn(device, _nvmlPcieUtilCounter_t(counter), byref(c_util))
  3817. _nvmlCheckReturn(ret)
  3818. return c_util.value
  3819. def nvmlSystemGetTopologyGpuSet(cpuNumber):
  3820. c_count = c_uint(0)
  3821. fn = _nvmlGetFunctionPointer("nvmlSystemGetTopologyGpuSet")
  3822. # First call will get the size
  3823. ret = fn(cpuNumber, byref(c_count), None)
  3824. if ret != NVML_SUCCESS:
  3825. raise NVMLError(ret)
  3826. # call again with a buffer
  3827. device_array = c_nvmlDevice_t * c_count.value
  3828. c_devices = device_array()
  3829. ret = fn(cpuNumber, byref(c_count), c_devices)
  3830. _nvmlCheckReturn(ret)
  3831. return list(c_devices[0:c_count.value])
  3832. def nvmlDeviceGetTopologyNearestGpus(device, level):
  3833. c_count = c_uint(0)
  3834. fn = _nvmlGetFunctionPointer("nvmlDeviceGetTopologyNearestGpus")
  3835. # First call will get the size
  3836. ret = fn(device, level, byref(c_count), None)
  3837. if ret != NVML_SUCCESS:
  3838. raise NVMLError(ret)
  3839. # call again with a buffer
  3840. device_array = c_nvmlDevice_t * c_count.value
  3841. c_devices = device_array()
  3842. ret = fn(device, level, byref(c_count), c_devices)
  3843. _nvmlCheckReturn(ret)
  3844. return list(c_devices[0:c_count.value])
  3845. def nvmlDeviceGetTopologyCommonAncestor(device1, device2):
  3846. c_level = _nvmlGpuTopologyLevel_t()
  3847. fn = _nvmlGetFunctionPointer("nvmlDeviceGetTopologyCommonAncestor")
  3848. ret = fn(device1, device2, byref(c_level))
  3849. _nvmlCheckReturn(ret)
  3850. return c_level.value
  3851. # Deprecated
  3852. def nvmlDeviceGetNvLinkUtilizationCounter(device, link, counter):
  3853. c_rxcounter = c_ulonglong()
  3854. c_txcounter = c_ulonglong()
  3855. fn = _nvmlGetFunctionPointer("nvmlDeviceGetNvLinkUtilizationCounter")
  3856. ret = fn(device, link, counter, byref(c_rxcounter), byref(c_txcounter))
  3857. _nvmlCheckReturn(ret)
  3858. return (c_rxcounter.value, c_txcounter.value)
  3859. # Deprecated
  3860. def nvmlDeviceFreezeNvLinkUtilizationCounter(device, link, counter, freeze):
  3861. fn = _nvmlGetFunctionPointer("nvmlDeviceFreezeNvLinkUtilizationCounter")
  3862. ret = fn(device, link, counter, freeze)
  3863. _nvmlCheckReturn(ret)
  3864. return None
  3865. # Deprecated
  3866. def nvmlDeviceResetNvLinkUtilizationCounter(device, link, counter):
  3867. fn = _nvmlGetFunctionPointer("nvmlDeviceResetNvLinkUtilizationCounter")
  3868. ret = fn(device, link, counter)
  3869. _nvmlCheckReturn(ret)
  3870. return None
  3871. # Deprecated
  3872. def nvmlDeviceSetNvLinkUtilizationControl(device, link, counter, control, reset):
  3873. fn = _nvmlGetFunctionPointer("nvmlDeviceSetNvLinkUtilizationControl")
  3874. ret = fn(device, link, counter, byref(control), reset)
  3875. _nvmlCheckReturn(ret)
  3876. return None
  3877. # Deprecated
  3878. def nvmlDeviceGetNvLinkUtilizationControl(device, link, counter):
  3879. c_control = nvmlNvLinkUtilizationControl_t()
  3880. fn = _nvmlGetFunctionPointer("nvmlDeviceGetNvLinkUtilizationControl")
  3881. ret = fn(device, link, counter, byref(c_control))
  3882. _nvmlCheckReturn(ret)
  3883. return c_control
  3884. def nvmlDeviceGetNvLinkCapability(device, link, capability):
  3885. c_capResult = c_uint()
  3886. fn = _nvmlGetFunctionPointer("nvmlDeviceGetNvLinkCapability")
  3887. ret = fn(device, link, capability, byref(c_capResult))
  3888. _nvmlCheckReturn(ret)
  3889. return c_capResult.value
  3890. def nvmlDeviceGetNvLinkErrorCounter(device, link, counter):
  3891. c_result = c_ulonglong()
  3892. fn = _nvmlGetFunctionPointer("nvmlDeviceGetNvLinkErrorCounter")
  3893. ret = fn(device, link, counter, byref(c_result))
  3894. _nvmlCheckReturn(ret)
  3895. return c_result.value
  3896. def nvmlDeviceResetNvLinkErrorCounters(device, link):
  3897. fn = _nvmlGetFunctionPointer("nvmlDeviceResetNvLinkErrorCounters")
  3898. ret = fn(device, link)
  3899. _nvmlCheckReturn(ret)
  3900. return None
  3901. def nvmlDeviceGetNvLinkRemotePciInfo(device, link):
  3902. c_pci = nvmlPciInfo_t()
  3903. fn = _nvmlGetFunctionPointer("nvmlDeviceGetNvLinkRemotePciInfo_v2")
  3904. ret = fn(device, link, byref(c_pci))
  3905. _nvmlCheckReturn(ret)
  3906. return c_pci
  3907. def nvmlDeviceGetNvLinkRemoteDeviceType(handle, link):
  3908. c_type = _nvmlNvLinkDeviceType_t()
  3909. fn = _nvmlGetFunctionPointer("nvmlDeviceGetNvLinkRemoteDeviceType")
  3910. ret = fn(handle, link, byref(c_type))
  3911. _nvmlCheckReturn(ret)
  3912. return c_type.value
  3913. def nvmlDeviceGetNvLinkState(device, link):
  3914. c_isActive = c_uint()
  3915. fn = _nvmlGetFunctionPointer("nvmlDeviceGetNvLinkState")
  3916. ret = fn(device, link, byref(c_isActive))
  3917. _nvmlCheckReturn(ret)
  3918. return c_isActive.value
  3919. def nvmlDeviceGetNvLinkVersion(device, link):
  3920. c_version = c_uint()
  3921. fn = _nvmlGetFunctionPointer("nvmlDeviceGetNvLinkVersion")
  3922. ret = fn(device, link, byref(c_version))
  3923. _nvmlCheckReturn(ret)
  3924. return c_version.value
  3925. def nvmlDeviceModifyDrainState(pciInfo, newState):
  3926. fn = _nvmlGetFunctionPointer("nvmlDeviceModifyDrainState")
  3927. ret = fn(pointer(pciInfo), newState)
  3928. _nvmlCheckReturn(ret)
  3929. return None
  3930. def nvmlDeviceQueryDrainState(pciInfo):
  3931. c_newState = c_uint()
  3932. fn = _nvmlGetFunctionPointer("nvmlDeviceQueryDrainState")
  3933. ret = fn(pointer(pciInfo), byref(c_newState))
  3934. _nvmlCheckReturn(ret)
  3935. return c_newState.value
  3936. def nvmlDeviceRemoveGpu(pciInfo):
  3937. fn = _nvmlGetFunctionPointer("nvmlDeviceRemoveGpu")
  3938. ret = fn(pointer(pciInfo))
  3939. _nvmlCheckReturn(ret)
  3940. return None
  3941. def nvmlDeviceDiscoverGpus(pciInfo):
  3942. fn = _nvmlGetFunctionPointer("nvmlDeviceDiscoverGpus")
  3943. ret = fn(pointer(pciInfo))
  3944. _nvmlCheckReturn(ret)
  3945. return None
  3946. def nvmlDeviceGetFieldValues(handle, fieldIds):
  3947. values_arr = c_nvmlFieldValue_t * len(fieldIds)
  3948. values = values_arr()
  3949. fn = _nvmlGetFunctionPointer("nvmlDeviceGetFieldValues")
  3950. for i, fieldId in enumerate(fieldIds):
  3951. try:
  3952. (values[i].fieldId, values[i].scopeId) = fieldId
  3953. except TypeError:
  3954. values[i].fieldId = fieldId
  3955. ret = fn(handle, c_int32(len(fieldIds)), byref(values))
  3956. _nvmlCheckReturn(ret)
  3957. return values
  3958. def nvmlDeviceClearFieldValues(handle, fieldIds):
  3959. values_arr = c_nvmlFieldValue_t * len(fieldIds)
  3960. values = values_arr()
  3961. fn = _nvmlGetFunctionPointer("nvmlDeviceClearFieldValues")
  3962. for i, fieldId in enumerate(fieldIds):
  3963. try:
  3964. (values[i].fieldId, values[i].scopeId) = fieldId
  3965. except TypeError:
  3966. values[i].fieldId = fieldId
  3967. ret = fn(handle, c_int32(len(fieldIds)), byref(values))
  3968. _nvmlCheckReturn(ret)
  3969. return values
  3970. def nvmlDeviceGetVirtualizationMode(handle):
  3971. c_virtualization_mode = c_ulonglong()
  3972. fn = _nvmlGetFunctionPointer("nvmlDeviceGetVirtualizationMode")
  3973. ret = fn(handle, byref(c_virtualization_mode))
  3974. _nvmlCheckReturn(ret)
  3975. return c_virtualization_mode.value
  3976. def nvmlDeviceSetVirtualizationMode(handle, virtualization_mode):
  3977. fn = _nvmlGetFunctionPointer("nvmlDeviceSetVirtualizationMode")
  3978. return fn(handle, virtualization_mode)
  3979. def nvmlDeviceGetVgpuHeterogeneousMode(handle):
  3980. c_vgpuHeterogeneousMode = c_nvmlVgpuHeterogeneousMode_v1_t(0)
  3981. c_vgpuHeterogeneousMode.version = VgpuHeterogeneousMode_v1
  3982. fn = _nvmlGetFunctionPointer("nvmlDeviceGetVgpuHeterogeneousMode")
  3983. ret = fn(handle, byref(c_vgpuHeterogeneousMode))
  3984. _nvmlCheckReturn(ret)
  3985. return c_vgpuHeterogeneousMode.mode
  3986. def nvmlDeviceSetVgpuHeterogeneousMode(handle, heterogeneous_mode):
  3987. c_vgpuHeterogeneousMode = c_nvmlVgpuHeterogeneousMode_v1_t(0)
  3988. c_vgpuHeterogeneousMode.version = VgpuHeterogeneousMode_v1
  3989. c_vgpuHeterogeneousMode.mode = heterogeneous_mode
  3990. fn = _nvmlGetFunctionPointer("nvmlDeviceSetVgpuHeterogeneousMode")
  3991. ret = fn(handle, byref(c_vgpuHeterogeneousMode))
  3992. _nvmlCheckReturn(ret)
  3993. return NVML_SUCCESS
  3994. def nvmlVgpuInstanceGetPlacementId(vgpuInstance):
  3995. c_placement = c_nvmlVgpuPlacementId_v1_t(0)
  3996. c_placement.version = VgpuPlacementId_v1
  3997. fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetPlacementId")
  3998. ret = fn(vgpuInstance, byref(c_placement))
  3999. _nvmlCheckReturn(ret)
  4000. return c_placement.placementId
  4001. def nvmlDeviceGetVgpuTypeSupportedPlacements(handle, vgpuTypeId, mode=0, version=1):
  4002. c_max_instances = c_uint(0)
  4003. fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetMaxInstances")
  4004. ret = fn(handle, vgpuTypeId, byref(c_max_instances))
  4005. _nvmlCheckReturn(ret)
  4006. if version == 2:
  4007. c_vgpu_placements = c_nvmlVgpuPlacementList_v2_t()
  4008. c_vgpu_placements.version = VgpuPlacementList_v2
  4009. c_vgpu_placements.count = c_max_instances.value
  4010. c_vgpu_placements.mode = mode
  4011. elif version == 1:
  4012. c_vgpu_placements = c_nvmlVgpuPlacementList_v1_t()
  4013. c_vgpu_placements.version = VgpuPlacementList_v1
  4014. else:
  4015. raise NVMLError(NVML_ERROR_ARGUMENT_VERSION_MISMATCH)
  4016. c_placements = c_uint * c_max_instances.value
  4017. c_vgpu_placements.placementIds = c_placements()
  4018. fn = _nvmlGetFunctionPointer("nvmlDeviceGetVgpuTypeSupportedPlacements")
  4019. ret = fn(handle, vgpuTypeId, byref(c_vgpu_placements))
  4020. _nvmlCheckReturn(ret)
  4021. return c_vgpu_placements
  4022. def nvmlDeviceGetVgpuTypeCreatablePlacements(handle, vgpuTypeId, version=1):
  4023. c_max_instances = c_uint(0)
  4024. fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetMaxInstances")
  4025. ret = fn(handle, vgpuTypeId, byref(c_max_instances))
  4026. _nvmlCheckReturn(ret)
  4027. if version == 2:
  4028. c_vgpu_placements = c_nvmlVgpuPlacementList_v2_t()
  4029. c_vgpu_placements.version = VgpuPlacementList_v2
  4030. c_vgpu_placements.count = c_max_instances.value
  4031. elif version == 1:
  4032. c_vgpu_placements = c_nvmlVgpuPlacementList_v1_t()
  4033. c_vgpu_placements.version = VgpuPlacementList_v1
  4034. c_placements = c_uint * c_max_instances.value
  4035. c_vgpu_placements.placementIds = c_placements()
  4036. fn = _nvmlGetFunctionPointer("nvmlDeviceGetVgpuTypeCreatablePlacements")
  4037. ret = fn(handle, vgpuTypeId, byref(c_vgpu_placements))
  4038. _nvmlCheckReturn(ret)
  4039. return c_vgpu_placements
  4040. def nvmlGetVgpuDriverCapabilities(capability):
  4041. c_capResult = c_uint()
  4042. fn = _nvmlGetFunctionPointer("nvmlGetVgpuDriverCapabilities")
  4043. ret = fn(_nvmlVgpuDriverCapability_t(capability), byref(c_capResult))
  4044. _nvmlCheckReturn(ret)
  4045. return c_capResult.value
  4046. def nvmlDeviceGetVgpuCapabilities(handle, capability):
  4047. c_capResult = c_uint()
  4048. fn = _nvmlGetFunctionPointer("nvmlDeviceGetVgpuCapabilities")
  4049. ret = fn(handle, _nvmlDeviceVgpuCapability_t(capability), byref(c_capResult))
  4050. _nvmlCheckReturn(ret)
  4051. return c_capResult.value
  4052. def nvmlDeviceSetVgpuCapabilities(handle, capability, state):
  4053. fn = _nvmlGetFunctionPointer("nvmlDeviceSetVgpuCapabilities")
  4054. ret = fn(handle, _nvmlDeviceVgpuCapability_t(capability), state)
  4055. _nvmlCheckReturn(ret)
  4056. return NVML_SUCCESS
  4057. def nvmlDeviceGetSupportedVgpus(handle):
  4058. # first call to get the size
  4059. c_vgpu_count = c_uint(0)
  4060. fn = _nvmlGetFunctionPointer("nvmlDeviceGetSupportedVgpus")
  4061. ret = fn(handle, byref(c_vgpu_count), None)
  4062. if (ret == NVML_SUCCESS):
  4063. # special case, no supported vGPUs
  4064. return []
  4065. elif (ret == NVML_ERROR_INSUFFICIENT_SIZE):
  4066. # typical case
  4067. vgpu_type_ids_array = _nvmlVgpuTypeId_t * c_vgpu_count.value
  4068. c_vgpu_type_ids = vgpu_type_ids_array()
  4069. # make the call again
  4070. ret = fn(handle, byref(c_vgpu_count), c_vgpu_type_ids)
  4071. _nvmlCheckReturn(ret)
  4072. vgpus = []
  4073. for i in range(c_vgpu_count.value):
  4074. vgpus.append(c_vgpu_type_ids[i])
  4075. return vgpus
  4076. else:
  4077. # error case
  4078. raise NVMLError(ret)
  4079. def nvmlDeviceGetCreatableVgpus(handle):
  4080. # first call to get the size
  4081. c_vgpu_count = c_uint(0)
  4082. fn = _nvmlGetFunctionPointer("nvmlDeviceGetCreatableVgpus")
  4083. ret = fn(handle, byref(c_vgpu_count), None)
  4084. if (ret == NVML_SUCCESS):
  4085. # special case, no supported vGPUs
  4086. return []
  4087. elif (ret == NVML_ERROR_INSUFFICIENT_SIZE):
  4088. # typical case
  4089. vgpu_type_ids_array = _nvmlVgpuTypeId_t * c_vgpu_count.value
  4090. c_vgpu_type_ids = vgpu_type_ids_array()
  4091. # make the call again
  4092. ret = fn(handle, byref(c_vgpu_count), c_vgpu_type_ids)
  4093. _nvmlCheckReturn(ret)
  4094. vgpus = []
  4095. for i in range(c_vgpu_count.value):
  4096. vgpus.append(c_vgpu_type_ids[i])
  4097. return vgpus
  4098. else:
  4099. # error case
  4100. raise NVMLError(ret)
  4101. def nvmlVgpuTypeGetGpuInstanceProfileId(vgpuTypeId):
  4102. c_profile_id = c_uint(0)
  4103. fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetGpuInstanceProfileId")
  4104. ret = fn(vgpuTypeId, byref(c_profile_id))
  4105. _nvmlCheckReturn(ret)
  4106. return (c_profile_id.value)
  4107. @convertStrBytes
  4108. def nvmlVgpuTypeGetClass(vgpuTypeId):
  4109. c_class = create_string_buffer(NVML_DEVICE_NAME_BUFFER_SIZE)
  4110. c_buffer_size = c_uint(NVML_DEVICE_NAME_BUFFER_SIZE)
  4111. fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetClass")
  4112. ret = fn(vgpuTypeId, c_class, byref(c_buffer_size))
  4113. _nvmlCheckReturn(ret)
  4114. return c_class.value
  4115. @convertStrBytes
  4116. def nvmlVgpuTypeGetName(vgpuTypeId):
  4117. c_name = create_string_buffer(NVML_DEVICE_NAME_BUFFER_SIZE)
  4118. c_buffer_size = c_uint(NVML_DEVICE_NAME_BUFFER_SIZE)
  4119. fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetName")
  4120. ret = fn(vgpuTypeId, c_name, byref(c_buffer_size))
  4121. _nvmlCheckReturn(ret)
  4122. return c_name.value
  4123. def nvmlVgpuTypeGetDeviceID(vgpuTypeId):
  4124. c_device_id = c_ulonglong(0)
  4125. c_subsystem_id = c_ulonglong(0)
  4126. fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetDeviceID")
  4127. ret = fn(vgpuTypeId, byref(c_device_id), byref(c_subsystem_id))
  4128. _nvmlCheckReturn(ret)
  4129. return (c_device_id.value, c_subsystem_id.value)
  4130. def nvmlVgpuTypeGetFramebufferSize(vgpuTypeId):
  4131. c_fb_size = c_ulonglong(0)
  4132. fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetFramebufferSize")
  4133. ret = fn(vgpuTypeId, byref(c_fb_size))
  4134. _nvmlCheckReturn(ret)
  4135. return c_fb_size.value
  4136. def nvmlVgpuTypeGetNumDisplayHeads(vgpuTypeId):
  4137. c_num_heads = c_uint(0)
  4138. fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetNumDisplayHeads")
  4139. ret = fn(vgpuTypeId, byref(c_num_heads))
  4140. _nvmlCheckReturn(ret)
  4141. return c_num_heads.value
  4142. def nvmlVgpuTypeGetResolution(vgpuTypeId):
  4143. c_xdim = c_uint(0)
  4144. c_ydim = c_uint(0)
  4145. fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetResolution")
  4146. ret = fn(vgpuTypeId, 0, byref(c_xdim), byref(c_ydim))
  4147. _nvmlCheckReturn(ret)
  4148. return (c_xdim.value, c_ydim.value)
  4149. @convertStrBytes
  4150. def nvmlVgpuTypeGetLicense(vgpuTypeId):
  4151. c_license = create_string_buffer(NVML_GRID_LICENSE_BUFFER_SIZE)
  4152. c_buffer_size = c_uint(NVML_GRID_LICENSE_BUFFER_SIZE)
  4153. fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetLicense")
  4154. ret = fn(vgpuTypeId, c_license, c_buffer_size)
  4155. _nvmlCheckReturn(ret)
  4156. return c_license.value
  4157. def nvmlVgpuTypeGetFrameRateLimit(vgpuTypeId):
  4158. c_frl_config = c_uint(0)
  4159. fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetFrameRateLimit")
  4160. ret = fn(vgpuTypeId, byref(c_frl_config))
  4161. _nvmlCheckReturn(ret)
  4162. return c_frl_config.value
  4163. def nvmlVgpuTypeGetGspHeapSize(vgpuTypeId):
  4164. c_gsp_heap = c_uint(0)
  4165. fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetGspHeapSize")
  4166. ret = fn(vgpuTypeId, byref(c_gsp_heap))
  4167. _nvmlCheckReturn(ret)
  4168. return c_gsp_heap.value
  4169. def nvmlVgpuTypeGetFbReservation(vgpuTypeId):
  4170. c_fb_reservation = c_uint(0)
  4171. fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetFbReservation")
  4172. ret = fn(vgpuTypeId, byref(c_fb_reservation))
  4173. _nvmlCheckReturn(ret)
  4174. return c_fb_reservation.value
  4175. def nvmlVgpuInstanceGetRuntimeStateSize(vgpuInstance):
  4176. c_runtime_state = nvmlVgpuRuntimeState_v1_t()
  4177. c_runtime_state.version = VgpuRuntimeState_v1
  4178. fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetRuntimeStateSize")
  4179. ret = fn(vgpuInstance, byref(c_runtime_state))
  4180. _nvmlCheckReturn(ret)
  4181. return c_runtime_state
  4182. def nvmlVgpuTypeGetMaxInstances(handle, vgpuTypeId):
  4183. c_max_instances = c_uint(0)
  4184. fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetMaxInstances")
  4185. ret = fn(handle, vgpuTypeId, byref(c_max_instances))
  4186. _nvmlCheckReturn(ret)
  4187. return c_max_instances.value
  4188. def nvmlVgpuTypeGetMaxInstancesPerVm(vgpuTypeId):
  4189. c_max_instances_per_vm = c_uint(0)
  4190. fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetMaxInstancesPerVm")
  4191. ret = fn(vgpuTypeId, byref(c_max_instances_per_vm))
  4192. _nvmlCheckReturn(ret)
  4193. return c_max_instances_per_vm.value
  4194. def nvmlVgpuTypeGetBAR1Info(vgpuTypeId):
  4195. c_bar1Info = c_nvmlVgpuTypeBar1Info_v1_t(0)
  4196. c_bar1Info.version = VgpuTypeBar1Info_v1
  4197. fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetBAR1Info")
  4198. ret = fn(vgpuTypeId, byref(c_bar1Info))
  4199. _nvmlCheckReturn(ret)
  4200. return c_bar1Info
  4201. def nvmlDeviceGetActiveVgpus(handle):
  4202. # first call to get the size
  4203. c_vgpu_count = c_uint(0)
  4204. fn = _nvmlGetFunctionPointer("nvmlDeviceGetActiveVgpus")
  4205. ret = fn(handle, byref(c_vgpu_count), None)
  4206. if (ret == NVML_SUCCESS):
  4207. # special case, no active vGPUs
  4208. return []
  4209. elif (ret == NVML_ERROR_INSUFFICIENT_SIZE):
  4210. # typical case
  4211. vgpu_instance_array = _nvmlVgpuInstance_t * c_vgpu_count.value
  4212. c_vgpu_instances = vgpu_instance_array()
  4213. # make the call again
  4214. ret = fn(handle, byref(c_vgpu_count), c_vgpu_instances)
  4215. _nvmlCheckReturn(ret)
  4216. vgpus = []
  4217. for i in range(c_vgpu_count.value):
  4218. vgpus.append(c_vgpu_instances[i])
  4219. return vgpus
  4220. else:
  4221. # error case
  4222. raise NVMLError(ret)
  4223. @convertStrBytes
  4224. def nvmlVgpuInstanceGetVmID(vgpuInstance):
  4225. c_vm_id = create_string_buffer(NVML_DEVICE_UUID_BUFFER_SIZE)
  4226. c_buffer_size = c_uint(NVML_GRID_LICENSE_BUFFER_SIZE)
  4227. c_vm_id_type = c_uint(0)
  4228. fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetVmID")
  4229. ret = fn(vgpuInstance, byref(c_vm_id), c_buffer_size, byref(c_vm_id_type))
  4230. _nvmlCheckReturn(ret)
  4231. return (c_vm_id.value, c_vm_id_type.value)
  4232. @convertStrBytes
  4233. def nvmlVgpuInstanceGetUUID(vgpuInstance):
  4234. c_uuid = create_string_buffer(NVML_DEVICE_UUID_BUFFER_SIZE)
  4235. c_buffer_size = c_uint(NVML_DEVICE_UUID_BUFFER_SIZE)
  4236. fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetUUID")
  4237. ret = fn(vgpuInstance, byref(c_uuid), c_buffer_size)
  4238. _nvmlCheckReturn(ret)
  4239. return c_uuid.value
  4240. @convertStrBytes
  4241. def nvmlVgpuInstanceGetMdevUUID(vgpuInstance):
  4242. c_uuid = create_string_buffer(NVML_DEVICE_UUID_BUFFER_SIZE)
  4243. c_buffer_size = c_uint(NVML_DEVICE_UUID_BUFFER_SIZE)
  4244. fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetMdevUUID")
  4245. ret = fn(vgpuInstance, byref(c_uuid), c_buffer_size)
  4246. _nvmlCheckReturn(ret)
  4247. return c_uuid.value
  4248. @convertStrBytes
  4249. def nvmlVgpuInstanceGetVmDriverVersion(vgpuInstance):
  4250. c_driver_version = create_string_buffer(NVML_SYSTEM_DRIVER_VERSION_BUFFER_SIZE)
  4251. c_buffer_size = c_uint(NVML_SYSTEM_DRIVER_VERSION_BUFFER_SIZE)
  4252. fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetVmDriverVersion")
  4253. ret = fn(vgpuInstance, byref(c_driver_version), c_buffer_size)
  4254. _nvmlCheckReturn(ret)
  4255. return c_driver_version.value
  4256. # Deprecated
  4257. def nvmlVgpuInstanceGetLicenseStatus(vgpuInstance):
  4258. c_license_status = c_uint(0)
  4259. fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetLicenseStatus")
  4260. ret = fn(vgpuInstance, byref(c_license_status))
  4261. _nvmlCheckReturn(ret)
  4262. return c_license_status.value
  4263. def nvmlVgpuInstanceGetLicenseInfo_v2(vgpuInstance):
  4264. fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetLicenseInfo_v2")
  4265. c_license_info = c_nvmlVgpuLicenseInfo_t()
  4266. ret = fn(vgpuInstance, byref(c_license_info))
  4267. _nvmlCheckReturn(ret)
  4268. return c_license_info
  4269. def nvmlVgpuInstanceGetLicenseInfo(vgpuInstance):
  4270. return nvmlVgpuInstanceGetLicenseInfo_v2(vgpuInstance)
  4271. def nvmlVgpuInstanceGetFrameRateLimit(vgpuInstance):
  4272. c_frl = c_uint(0)
  4273. fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetFrameRateLimit")
  4274. ret = fn(vgpuInstance, byref(c_frl))
  4275. _nvmlCheckReturn(ret)
  4276. return c_frl.value
  4277. def nvmlVgpuInstanceGetEccMode(vgpuInstance):
  4278. c_mode = _nvmlEnableState_t()
  4279. fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetEccMode")
  4280. ret = fn(vgpuInstance, byref(c_mode))
  4281. _nvmlCheckReturn(ret)
  4282. return c_mode.value
  4283. def nvmlVgpuInstanceGetType(vgpuInstance):
  4284. c_vgpu_type = c_uint(0)
  4285. fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetType")
  4286. ret = fn(vgpuInstance, byref(c_vgpu_type))
  4287. _nvmlCheckReturn(ret)
  4288. return c_vgpu_type.value
  4289. def nvmlVgpuInstanceGetEncoderCapacity(vgpuInstance):
  4290. c_encoder_capacity = c_ulonglong(0)
  4291. fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetEncoderCapacity")
  4292. ret = fn(vgpuInstance, byref(c_encoder_capacity))
  4293. _nvmlCheckReturn(ret)
  4294. return c_encoder_capacity.value
  4295. def nvmlVgpuInstanceSetEncoderCapacity(vgpuInstance, encoder_capacity):
  4296. fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceSetEncoderCapacity")
  4297. return fn(vgpuInstance, encoder_capacity)
  4298. def nvmlVgpuInstanceGetFbUsage(vgpuInstance):
  4299. c_fb_usage = c_uint(0)
  4300. fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetFbUsage")
  4301. ret = fn(vgpuInstance, byref(c_fb_usage))
  4302. _nvmlCheckReturn(ret)
  4303. return c_fb_usage.value
  4304. def nvmlVgpuTypeGetCapabilities(vgpuTypeId, capability):
  4305. c_cap_result = c_uint(0)
  4306. fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetCapabilities")
  4307. ret = fn(vgpuTypeId, _nvmlVgpuCapability_t(capability), byref(c_cap_result))
  4308. _nvmlCheckReturn(ret)
  4309. return (c_cap_result.value)
  4310. def nvmlVgpuInstanceGetGpuInstanceId(vgpuInstance):
  4311. c_id = c_uint(0)
  4312. fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetGpuInstanceId")
  4313. ret = fn(vgpuInstance, byref(c_id))
  4314. _nvmlCheckReturn(ret)
  4315. return (c_id.value)
  4316. @convertStrBytes
  4317. def nvmlVgpuInstanceGetGpuPciId(vgpuInstance):
  4318. c_vgpuPciId = create_string_buffer(NVML_DEVICE_PCI_BUS_ID_BUFFER_SIZE)
  4319. fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetGpuPciId")
  4320. ret = fn(vgpuInstance, c_vgpuPciId, byref(c_uint(NVML_DEVICE_PCI_BUS_ID_BUFFER_SIZE)))
  4321. _nvmlCheckReturn(ret)
  4322. return c_vgpuPciId.value
  4323. def nvmlDeviceGetVgpuUtilization(handle, timeStamp):
  4324. # first call to get the size
  4325. c_vgpu_count = c_uint(0)
  4326. c_time_stamp = c_ulonglong(timeStamp)
  4327. c_sample_value_type = _nvmlValueType_t()
  4328. fn = _nvmlGetFunctionPointer("nvmlDeviceGetVgpuUtilization")
  4329. ret = fn(handle, c_time_stamp, byref(c_sample_value_type), byref(c_vgpu_count), None)
  4330. if (ret == NVML_SUCCESS):
  4331. # special case, no active vGPUs
  4332. return []
  4333. elif (ret == NVML_ERROR_INSUFFICIENT_SIZE):
  4334. # typical case
  4335. sampleArray = c_vgpu_count.value * c_nvmlVgpuInstanceUtilizationSample_t
  4336. c_samples = sampleArray()
  4337. # make the call again
  4338. ret = fn(handle, c_time_stamp, byref(c_sample_value_type), byref(c_vgpu_count), c_samples)
  4339. _nvmlCheckReturn(ret)
  4340. return c_samples[0:c_vgpu_count.value]
  4341. else:
  4342. # error case
  4343. raise NVMLError(ret)
  4344. def nvmlDeviceGetVgpuInstancesUtilizationInfo(handle, timeStamp):
  4345. # first call to get the size
  4346. c_time_stamp = c_ulonglong(timeStamp)
  4347. c_vgpuUtilInfo = c_nvmlVgpuInstancesUtilizationInfo_v1_t(0)
  4348. c_vgpuUtilInfo.version = VgpuInstancesUtilizationInfo_v1
  4349. c_vgpuUtilInfo.sampleValType = _nvmlValueType_t()
  4350. c_vgpuUtilInfo.vgpuInstanceCount = c_uint(0)
  4351. c_vgpuUtilInfo.lastSeenTimeStamp = c_time_stamp
  4352. fn = _nvmlGetFunctionPointer("nvmlDeviceGetVgpuInstancesUtilizationInfo")
  4353. ret = fn(handle, byref(c_vgpuUtilInfo))
  4354. if (ret == NVML_SUCCESS):
  4355. # special case, no active vGPUs
  4356. return []
  4357. elif (ret == NVML_ERROR_INSUFFICIENT_SIZE):
  4358. # typical case
  4359. sampleArray = c_vgpuUtilInfo.vgpuInstanceCount * c_nvmlVgpuInstanceUtilizationInfo_v1_t
  4360. c_samples = sampleArray()
  4361. c_vgpuUtilInfo.vgpuUtilArray = c_samples
  4362. # make the call again
  4363. ret = fn(handle, byref(c_vgpuUtilInfo))
  4364. _nvmlCheckReturn(ret)
  4365. return c_samples[0:c_vgpuUtilInfo.vgpuInstanceCount]
  4366. else:
  4367. # error case
  4368. raise NVMLError(ret)
  4369. def nvmlDeviceGetP2PStatus(device1, device2, p2pIndex):
  4370. c_p2pstatus = _nvmlGpuP2PStatus_t()
  4371. fn = _nvmlGetFunctionPointer("nvmlDeviceGetP2PStatus")
  4372. ret = fn(device1, device2,p2pIndex, byref(c_p2pstatus))
  4373. _nvmlCheckReturn(ret)
  4374. return c_p2pstatus.value
  4375. def nvmlDeviceGetGridLicensableFeatures_v4(handle):
  4376. c_get_grid_licensable_features = c_nvmlGridLicensableFeatures_v4_t()
  4377. fn = _nvmlGetFunctionPointer("nvmlDeviceGetGridLicensableFeatures_v4")
  4378. ret = fn(handle, byref(c_get_grid_licensable_features))
  4379. _nvmlCheckReturn(ret)
  4380. return (c_get_grid_licensable_features)
  4381. def nvmlDeviceGetGridLicensableFeatures(handle):
  4382. return nvmlDeviceGetGridLicensableFeatures_v4(handle)
  4383. def nvmlDeviceGetGspFirmwareVersion(handle, version=None):
  4384. isUserDefined = version is not None
  4385. if not isUserDefined:
  4386. version = (c_char * NVML_GSP_FIRMWARE_VERSION_BUF_SIZE)()
  4387. fn = _nvmlGetFunctionPointer("nvmlDeviceGetGspFirmwareVersion")
  4388. ret = fn(handle, version)
  4389. _nvmlCheckReturn(ret)
  4390. return NVML_SUCCESS if isUserDefined else version.value
  4391. def nvmlDeviceGetGspFirmwareMode(handle, isEnabled=c_uint(), defaultMode=c_uint()):
  4392. isReference = type(isEnabled) is not c_uint
  4393. isEnabledRef = isEnabled if isReference else byref(isEnabled)
  4394. defaultModeRef = defaultMode if isReference else byref(defaultMode)
  4395. fn = _nvmlGetFunctionPointer("nvmlDeviceGetGspFirmwareMode")
  4396. ret = fn(handle, isEnabledRef, defaultModeRef)
  4397. _nvmlCheckReturn(ret)
  4398. return NVML_SUCCESS if isReference else [isEnabled.value, defaultMode.value]
  4399. def nvmlDeviceGetEncoderCapacity(handle, encoderQueryType):
  4400. c_encoder_capacity = c_ulonglong(0)
  4401. c_encoderQuery_type = _nvmlEncoderQueryType_t(encoderQueryType)
  4402. fn = _nvmlGetFunctionPointer("nvmlDeviceGetEncoderCapacity")
  4403. ret = fn(handle, c_encoderQuery_type, byref(c_encoder_capacity))
  4404. _nvmlCheckReturn(ret)
  4405. return c_encoder_capacity.value
  4406. def nvmlDeviceGetVgpuProcessUtilization(handle, timeStamp):
  4407. # first call to get the size
  4408. c_vgpu_count = c_uint(0)
  4409. c_time_stamp = c_ulonglong(timeStamp)
  4410. fn = _nvmlGetFunctionPointer("nvmlDeviceGetVgpuProcessUtilization")
  4411. ret = fn(handle, c_time_stamp, byref(c_vgpu_count), None)
  4412. if (ret == NVML_SUCCESS):
  4413. # special case, no active vGPUs
  4414. return []
  4415. elif (ret == NVML_ERROR_INSUFFICIENT_SIZE):
  4416. # typical case
  4417. sampleArray = c_vgpu_count.value * c_nvmlVgpuProcessUtilizationSample_t
  4418. c_samples = sampleArray()
  4419. # make the call again
  4420. ret = fn(handle, c_time_stamp, byref(c_vgpu_count), c_samples)
  4421. _nvmlCheckReturn(ret)
  4422. return c_samples[0:c_vgpu_count.value]
  4423. else:
  4424. # error case
  4425. raise NVMLError(ret)
  4426. def nvmlDeviceGetVgpuProcessesUtilizationInfo(handle, timeStamp):
  4427. # first call to get the size
  4428. c_time_stamp = c_ulonglong(timeStamp)
  4429. c_vgpuProcUtilInfo = c_nvmlVgpuProcessesUtilizationInfo_v1_t(0)
  4430. c_vgpuProcUtilInfo.version = VgpuProcessesUtilizationInfo_v1
  4431. c_vgpuProcUtilInfo.vgpuProcessCount = c_uint(0)
  4432. c_vgpuProcUtilInfo.lastSeenTimeStamp = c_time_stamp
  4433. fn = _nvmlGetFunctionPointer("nvmlDeviceGetVgpuProcessesUtilizationInfo")
  4434. ret = fn(handle, byref(c_vgpuProcUtilInfo))
  4435. if (ret == NVML_SUCCESS):
  4436. # special case, no active vGPUs
  4437. return []
  4438. elif (ret == NVML_ERROR_INSUFFICIENT_SIZE):
  4439. # typical case
  4440. sampleArray = c_vgpuProcUtilInfo.vgpuProcessCount * c_nvmlVgpuProcessUtilizationInfo_v1_t
  4441. c_samples = sampleArray()
  4442. c_vgpuProcUtilInfo.vgpuProcUtilArray = c_samples
  4443. # make the call again
  4444. ret = fn(handle, byref(c_vgpuProcUtilInfo))
  4445. _nvmlCheckReturn(ret)
  4446. return c_samples[0:c_vgpuProcUtilInfo.vgpuProcessCount]
  4447. else:
  4448. # error case
  4449. raise NVMLError(ret)
  4450. def nvmlDeviceGetEncoderStats(handle):
  4451. c_encoderCount = c_ulonglong(0)
  4452. c_encodeFps = c_ulonglong(0)
  4453. c_encoderLatency = c_ulonglong(0)
  4454. fn = _nvmlGetFunctionPointer("nvmlDeviceGetEncoderStats")
  4455. ret = fn(handle, byref(c_encoderCount), byref(c_encodeFps), byref(c_encoderLatency))
  4456. _nvmlCheckReturn(ret)
  4457. return (c_encoderCount.value, c_encodeFps.value, c_encoderLatency.value)
  4458. def nvmlDeviceGetEncoderSessions(handle):
  4459. # first call to get the size
  4460. c_session_count = c_uint(0)
  4461. fn = _nvmlGetFunctionPointer("nvmlDeviceGetEncoderSessions")
  4462. ret = fn(handle, byref(c_session_count), None)
  4463. if (ret == NVML_SUCCESS):
  4464. if (c_session_count.value != 0):
  4465. # typical case
  4466. session_array = c_nvmlEncoderSession_t * c_session_count.value
  4467. c_sessions = session_array()
  4468. # make the call again
  4469. ret = fn(handle, byref(c_session_count), c_sessions)
  4470. _nvmlCheckReturn(ret)
  4471. sessions = []
  4472. for i in range(c_session_count.value):
  4473. sessions.append(c_sessions[i])
  4474. return sessions
  4475. else:
  4476. return [] # no active sessions
  4477. else:
  4478. # error case
  4479. raise NVMLError(ret)
  4480. def nvmlDeviceGetFBCStats(handle):
  4481. c_fbcStats = c_nvmlFBCStats_t()
  4482. fn = _nvmlGetFunctionPointer("nvmlDeviceGetFBCStats")
  4483. ret = fn(handle, byref(c_fbcStats))
  4484. _nvmlCheckReturn(ret)
  4485. return c_fbcStats
  4486. def nvmlDeviceGetFBCSessions(handle):
  4487. # first call to get the size
  4488. c_session_count = c_uint(0)
  4489. fn = _nvmlGetFunctionPointer("nvmlDeviceGetFBCSessions")
  4490. ret = fn(handle, byref(c_session_count), None)
  4491. if (ret == NVML_SUCCESS):
  4492. if (c_session_count.value != 0):
  4493. # typical case
  4494. session_array = c_nvmlFBCSession_t * c_session_count.value
  4495. c_sessions = session_array()
  4496. # make the call again
  4497. ret = fn(handle, byref(c_session_count), c_sessions)
  4498. _nvmlCheckReturn(ret)
  4499. sessions = []
  4500. for i in range(c_session_count.value):
  4501. sessions.append(c_sessions[i])
  4502. return sessions
  4503. else:
  4504. return [] # no active sessions
  4505. else:
  4506. # error case
  4507. raise NVMLError(ret)
  4508. def nvmlVgpuInstanceGetEncoderStats(vgpuInstance):
  4509. c_encoderCount = c_ulonglong(0)
  4510. c_encodeFps = c_ulonglong(0)
  4511. c_encoderLatency = c_ulonglong(0)
  4512. fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetEncoderStats")
  4513. ret = fn(vgpuInstance, byref(c_encoderCount), byref(c_encodeFps), byref(c_encoderLatency))
  4514. _nvmlCheckReturn(ret)
  4515. return (c_encoderCount.value, c_encodeFps.value, c_encoderLatency.value)
  4516. def nvmlVgpuInstanceGetEncoderSessions(vgpuInstance):
  4517. # first call to get the size
  4518. c_session_count = c_uint(0)
  4519. fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetEncoderSessions")
  4520. ret = fn(vgpuInstance, byref(c_session_count), None)
  4521. if (ret == NVML_SUCCESS):
  4522. if (c_session_count.value != 0):
  4523. # typical case
  4524. session_array = c_nvmlEncoderSession_t * c_session_count.value
  4525. c_sessions = session_array()
  4526. # make the call again
  4527. ret = fn(vgpuInstance, byref(c_session_count), c_sessions)
  4528. _nvmlCheckReturn(ret)
  4529. sessions = []
  4530. for i in range(c_session_count.value):
  4531. sessions.append(c_sessions[i])
  4532. return sessions
  4533. else:
  4534. return [] # no active sessions
  4535. else:
  4536. # error case
  4537. raise NVMLError(ret)
  4538. def nvmlVgpuInstanceGetFBCStats(vgpuInstance):
  4539. c_fbcStats = c_nvmlFBCStats_t()
  4540. fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetFBCStats")
  4541. ret = fn(vgpuInstance, byref(c_fbcStats))
  4542. _nvmlCheckReturn(ret)
  4543. return c_fbcStats
  4544. def nvmlVgpuInstanceGetFBCSessions(vgpuInstance):
  4545. # first call to get the size
  4546. c_session_count = c_uint(0)
  4547. fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetFBCSessions")
  4548. ret = fn(vgpuInstance, byref(c_session_count), None)
  4549. if (ret == NVML_SUCCESS):
  4550. if (c_session_count.value != 0):
  4551. # typical case
  4552. session_array = c_nvmlFBCSession_t * c_session_count.value
  4553. c_sessions = session_array()
  4554. # make the call again
  4555. ret = fn(vgpuInstance, byref(c_session_count), c_sessions)
  4556. _nvmlCheckReturn(ret)
  4557. sessions = []
  4558. for i in range(c_session_count.value):
  4559. sessions.append(c_sessions[i])
  4560. return sessions
  4561. else:
  4562. return [] # no active sessions
  4563. else:
  4564. # error case
  4565. raise NVMLError(ret)
  4566. def nvmlDeviceGetProcessUtilization(handle, timeStamp):
  4567. # first call to get the size
  4568. c_count = c_uint(0)
  4569. c_time_stamp = c_ulonglong(timeStamp)
  4570. fn = _nvmlGetFunctionPointer("nvmlDeviceGetProcessUtilization")
  4571. ret = fn(handle, None, byref(c_count), c_time_stamp)
  4572. if (ret == NVML_ERROR_INSUFFICIENT_SIZE):
  4573. # typical case
  4574. sampleArray = c_count.value * c_nvmlProcessUtilizationSample_t
  4575. c_samples = sampleArray()
  4576. # make the call again
  4577. ret = fn(handle, c_samples, byref(c_count), c_time_stamp)
  4578. _nvmlCheckReturn(ret)
  4579. return c_samples[0:c_count.value]
  4580. else:
  4581. # error case
  4582. raise NVMLError(ret)
  4583. def nvmlDeviceGetProcessesUtilizationInfo(handle, timeStamp):
  4584. # first call to get the size
  4585. c_time_stamp = c_ulonglong(timeStamp)
  4586. c_processesUtilInfo = c_nvmlProcessesUtilizationInfo_v1_t(0)
  4587. c_processesUtilInfo.version = ProcessesUtilizationInfo_v1
  4588. c_processesUtilInfo.processSamplesCount = c_uint(0)
  4589. c_processesUtilInfo.lastSeenTimeStamp = c_time_stamp
  4590. fn = _nvmlGetFunctionPointer("nvmlDeviceGetProcessesUtilizationInfo")
  4591. ret = fn(handle, byref(c_processesUtilInfo))
  4592. if (ret == NVML_ERROR_INSUFFICIENT_SIZE):
  4593. # typical case
  4594. sampleArray = c_processesUtilInfo.processSamplesCount * c_nvmlProcessUtilizationInfo_v1_t
  4595. c_samples = sampleArray()
  4596. c_processesUtilInfo.procUtilArray = c_samples
  4597. # make the call again
  4598. ret = fn(handle, byref(c_processesUtilInfo))
  4599. _nvmlCheckReturn(ret)
  4600. return c_samples[0:c_processesUtilInfo.processSamplesCount]
  4601. else:
  4602. # error case
  4603. raise NVMLError(ret)
  4604. def nvmlVgpuInstanceGetMetadata(vgpuInstance):
  4605. fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetMetadata")
  4606. c_vgpuMetadata = c_nvmlVgpuMetadata_t()
  4607. c_bufferSize = c_uint(0)
  4608. # Make the first NVML API call to get the c_bufferSize value.
  4609. # We have already allocated required buffer above.
  4610. ret = fn(vgpuInstance, byref(c_vgpuMetadata), byref(c_bufferSize))
  4611. if (ret == NVML_ERROR_INSUFFICIENT_SIZE):
  4612. ret = fn(vgpuInstance, byref(c_vgpuMetadata), byref(c_bufferSize))
  4613. _nvmlCheckReturn(ret)
  4614. else:
  4615. raise NVMLError(ret)
  4616. return c_vgpuMetadata
  4617. def nvmlDeviceGetVgpuMetadata(handle):
  4618. fn = _nvmlGetFunctionPointer("nvmlDeviceGetVgpuMetadata")
  4619. c_vgpuPgpuMetadata = c_nvmlVgpuPgpuMetadata_t()
  4620. c_bufferSize = c_uint(0)
  4621. # Make the first NVML API call to get the c_bufferSize value.
  4622. # We have already allocated required buffer above.
  4623. ret = fn(handle, byref(c_vgpuPgpuMetadata), byref(c_bufferSize))
  4624. if (ret == NVML_ERROR_INSUFFICIENT_SIZE):
  4625. ret = fn(handle, byref(c_vgpuPgpuMetadata), byref(c_bufferSize))
  4626. _nvmlCheckReturn(ret)
  4627. else:
  4628. raise NVMLError(ret)
  4629. return c_vgpuPgpuMetadata
  4630. def nvmlGetVgpuCompatibility(vgpuMetadata, pgpuMetadata):
  4631. fn = _nvmlGetFunctionPointer("nvmlGetVgpuCompatibility")
  4632. c_vgpuPgpuCompatibility = c_nvmlVgpuPgpuCompatibility_t()
  4633. ret = fn(byref(vgpuMetadata), byref(pgpuMetadata), byref(c_vgpuPgpuCompatibility))
  4634. _nvmlCheckReturn(ret)
  4635. return c_vgpuPgpuCompatibility
  4636. @convertStrBytes
  4637. def nvmlDeviceGetPgpuMetadataString(handle):
  4638. fn = _nvmlGetFunctionPointer("nvmlDeviceGetPgpuMetadataString")
  4639. c_pgpuMetadata = create_string_buffer(NVML_VGPU_PGPU_METADATA_OPAQUE_DATA_SIZE)
  4640. c_bufferSize = c_uint(0)
  4641. # Make the first NVML API call to get the c_bufferSize value.
  4642. # We have already allocated required buffer above.
  4643. ret = fn(handle, byref(c_pgpuMetadata), byref(c_bufferSize))
  4644. if (ret == NVML_ERROR_INSUFFICIENT_SIZE):
  4645. ret = fn(handle, byref(c_pgpuMetadata), byref(c_bufferSize))
  4646. _nvmlCheckReturn(ret)
  4647. else:
  4648. raise NVMLError(ret)
  4649. return (c_pgpuMetadata.value, c_bufferSize.value)
  4650. def nvmlDeviceGetVgpuSchedulerLog(handle):
  4651. c_vgpu_sched_log = c_nvmlVgpuSchedulerLog_t()
  4652. fn = _nvmlGetFunctionPointer("nvmlDeviceGetVgpuSchedulerLog")
  4653. ret = fn(handle, byref(c_vgpu_sched_log))
  4654. _nvmlCheckReturn(ret)
  4655. return c_vgpu_sched_log
  4656. def nvmlDeviceGetVgpuSchedulerState(handle):
  4657. c_vgpu_sched_state = c_nvmlVgpuSchedulerGetState_t()
  4658. fn = _nvmlGetFunctionPointer("nvmlDeviceGetVgpuSchedulerState")
  4659. ret = fn(handle, byref(c_vgpu_sched_state))
  4660. _nvmlCheckReturn(ret)
  4661. return c_vgpu_sched_state
  4662. def nvmlDeviceGetVgpuSchedulerCapabilities(handle):
  4663. c_vgpu_sched_caps = c_nvmlVgpuSchedulerCapabilities_t()
  4664. fn = _nvmlGetFunctionPointer("nvmlDeviceGetVgpuSchedulerCapabilities")
  4665. ret = fn(handle, byref(c_vgpu_sched_caps))
  4666. _nvmlCheckReturn(ret)
  4667. return c_vgpu_sched_caps
  4668. def nvmlDeviceSetVgpuSchedulerState(handle, sched_state):
  4669. fn = _nvmlGetFunctionPointer("nvmlDeviceSetVgpuSchedulerState")
  4670. ret = fn(handle, byref(sched_state))
  4671. _nvmlCheckReturn(ret)
  4672. return NVML_SUCCESS
  4673. def nvmlSetVgpuVersion(vgpuVersion):
  4674. fn = _nvmlGetFunctionPointer("nvmlSetVgpuVersion")
  4675. ret = fn(byref(vgpuVersion))
  4676. _nvmlCheckReturn(ret)
  4677. return NVML_SUCCESS
  4678. def nvmlGetVgpuVersion(supported=None, current=None):
  4679. isUserDefined = (supported is not None) or (current is not None)
  4680. if not isUserDefined:
  4681. supported = c_nvmlVgpuVersion_t()
  4682. current = c_nvmlVgpuVersion_t()
  4683. fn = _nvmlGetFunctionPointer("nvmlGetVgpuVersion")
  4684. ret = fn(byref(supported), byref(current))
  4685. _nvmlCheckReturn(ret)
  4686. return NVML_SUCCESS if isUserDefined else [(supported.minVersion,
  4687. supported.maxVersion),
  4688. (current.minVersion,
  4689. current.maxVersion)]
  4690. def nvmlVgpuInstanceGetAccountingMode(vgpuInstance):
  4691. c_mode = _nvmlEnableState_t()
  4692. fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetAccountingMode")
  4693. ret = fn(vgpuInstance, byref(c_mode))
  4694. _nvmlCheckReturn(ret)
  4695. return c_mode.value
  4696. def nvmlVgpuInstanceGetAccountingPids(vgpuInstance):
  4697. c_pidCount = c_uint()
  4698. fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetAccountingPids")
  4699. ret = fn(vgpuInstance, byref(c_pidCount), None)
  4700. if (ret == NVML_ERROR_INSUFFICIENT_SIZE):
  4701. sampleArray = c_pidCount.value * c_uint
  4702. c_pidArray = sampleArray()
  4703. ret = fn(vgpuInstance, byref(c_pidCount), byref(c_pidArray))
  4704. _nvmlCheckReturn(ret)
  4705. else:
  4706. raise NVMLError(ret)
  4707. return (c_pidCount, c_pidArray)
  4708. def nvmlVgpuInstanceGetAccountingStats(vgpuInstance, pid):
  4709. c_accountingStats = c_nvmlAccountingStats_t()
  4710. fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetAccountingStats")
  4711. ret = fn(vgpuInstance, pid, byref(c_accountingStats))
  4712. _nvmlCheckReturn(ret)
  4713. return c_accountingStats
  4714. def nvmlVgpuInstanceClearAccountingPids(vgpuInstance):
  4715. fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceClearAccountingPids")
  4716. ret = fn(vgpuInstance)
  4717. _nvmlCheckReturn(ret)
  4718. return NVML_SUCCESS
  4719. def nvmlGpuInstanceGetCreatableVgpus(gpuInstance, c_vgpus):
  4720. c_vgpus.vgpuCount = 0;
  4721. fn = _nvmlGetFunctionPointer("nvmlGpuInstanceGetCreatableVgpus")
  4722. ret = fn(gpuInstance, byref(c_vgpus))
  4723. if (ret == NVML_SUCCESS):
  4724. # special case, no supported vGPUs
  4725. return c_vgpus
  4726. elif (ret == NVML_ERROR_INSUFFICIENT_SIZE):
  4727. vgpu_type_ids_array = _nvmlVgpuTypeId_t * c_vgpus.vgpuCount
  4728. c_vgpus.vgpuTypeIds = vgpu_type_ids_array()
  4729. ret = fn(gpuInstance, byref(c_vgpus))
  4730. _nvmlCheckReturn(ret)
  4731. return c_vgpus
  4732. else:
  4733. raise NVMLError(ret)
  4734. def nvmlVgpuTypeGetMaxInstancesPerGpuInstance(vgpuTypeId):
  4735. c_max_instances = c_nvmlVgpuTypeMaxInstance_v1_t()
  4736. c_max_instances.version = nvmlVgpuTypeMaxInstance_v1
  4737. c_max_instances.vgpuTypeId = vgpuTypeId
  4738. fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetMaxInstancesPerGpuInstance")
  4739. ret = fn(byref(c_max_instances))
  4740. _nvmlCheckReturn(ret)
  4741. return c_max_instances.maxInstancePerGI
  4742. def nvmlGpuInstanceGetActiveVgpus(gpuInstance, c_vgpu_instance_info):
  4743. c_vgpu_instance_info.vgpuCount = c_uint(0)
  4744. fn = _nvmlGetFunctionPointer("nvmlGpuInstanceGetActiveVgpus")
  4745. ret = fn(gpuInstance, byref(c_vgpu_instance_info))
  4746. if (ret == NVML_SUCCESS):
  4747. # special case, no active vGPUs
  4748. return c_vgpu_instance_info
  4749. elif (ret == NVML_ERROR_INSUFFICIENT_SIZE):
  4750. # typical case
  4751. vgpu_instance_array = _nvmlVgpuInstance_t * c_vgpu_instance_info.vgpuCount
  4752. c_vgpu_instance_info.vgpuInstances = vgpu_instance_array()
  4753. # make the call again
  4754. ret = fn(gpuInstance, byref(c_vgpu_instance_info))
  4755. _nvmlCheckReturn(ret)
  4756. return c_vgpu_instance_info
  4757. else:
  4758. raise NVMLError(ret)
  4759. def nvmlGpuInstanceSetVgpuSchedulerState(gpuInstance, sched_state):
  4760. fn = _nvmlGetFunctionPointer("nvmlGpuInstanceSetVgpuSchedulerState")
  4761. ret = fn(gpuInstance, byref(sched_state))
  4762. _nvmlCheckReturn(ret)
  4763. return ret
  4764. def nvmlGpuInstanceGetVgpuSchedulerState(gpuInstance, c_vgpu_sched_state_info):
  4765. fn = _nvmlGetFunctionPointer("nvmlGpuInstanceGetVgpuSchedulerState")
  4766. ret = fn(gpuInstance, byref(c_vgpu_sched_state_info))
  4767. _nvmlCheckReturn(ret)
  4768. return c_vgpu_sched_state_info
  4769. def nvmlGpuInstanceGetVgpuSchedulerLog(gpuInstance, c_vgpu_sched_log_info):
  4770. fn = _nvmlGetFunctionPointer("nvmlGpuInstanceGetVgpuSchedulerLog")
  4771. ret = fn(gpuInstance, byref(c_vgpu_sched_log_info))
  4772. _nvmlCheckReturn(ret)
  4773. return c_vgpu_sched_log_info
  4774. def nvmlGpuInstanceGetVgpuTypeCreatablePlacements(gpuInstance, c_vgpu_placements):
  4775. c_max_instances = c_nvmlVgpuTypeMaxInstance_v1_t()
  4776. c_max_instances.version = nvmlVgpuTypeMaxInstance_v1
  4777. c_max_instances.vgpuTypeId = c_vgpu_placements.vgpuTypeId
  4778. fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetMaxInstancesPerGpuInstance")
  4779. ret = fn(byref(c_max_instances))
  4780. _nvmlCheckReturn(ret)
  4781. c_vgpu_placements.count = c_max_instances.maxInstancePerGI
  4782. c_placements = c_uint * c_max_instances.maxInstancePerGI
  4783. c_vgpu_placements.placementIds = c_placements()
  4784. fn = _nvmlGetFunctionPointer("nvmlGpuInstanceGetVgpuTypeCreatablePlacements")
  4785. ret = fn(gpuInstance, byref(c_vgpu_placements))
  4786. _nvmlCheckReturn(ret)
  4787. return c_vgpu_placements
  4788. def nvmlGpuInstanceGetVgpuHeterogeneousMode(gpuInstance):
  4789. c_vgpuHeterogeneousMode = c_nvmlVgpuHeterogeneousMode_v1_t(0)
  4790. c_vgpuHeterogeneousMode.version = VgpuHeterogeneousMode_v1
  4791. fn = _nvmlGetFunctionPointer("nvmlGpuInstanceGetVgpuHeterogeneousMode")
  4792. ret = fn(gpuInstance, byref(c_vgpuHeterogeneousMode))
  4793. _nvmlCheckReturn(ret)
  4794. return c_vgpuHeterogeneousMode.mode
  4795. def nvmlGpuInstanceSetVgpuHeterogeneousMode(gpuInstance, heterogeneous_mode):
  4796. c_vgpuHeterogeneousMode = c_nvmlVgpuHeterogeneousMode_v1_t(0)
  4797. c_vgpuHeterogeneousMode.version = VgpuHeterogeneousMode_v1
  4798. c_vgpuHeterogeneousMode.mode = heterogeneous_mode
  4799. fn = _nvmlGetFunctionPointer("nvmlGpuInstanceSetVgpuHeterogeneousMode")
  4800. ret = fn(gpuInstance, byref(c_vgpuHeterogeneousMode))
  4801. _nvmlCheckReturn(ret)
  4802. return NVML_SUCCESS
  4803. def nvmlGetExcludedDeviceCount():
  4804. c_count = c_uint()
  4805. fn = _nvmlGetFunctionPointer("nvmlGetExcludedDeviceCount")
  4806. ret = fn(byref(c_count))
  4807. _nvmlCheckReturn(ret)
  4808. return c_count.value
  4809. def nvmlGetExcludedDeviceInfoByIndex(index):
  4810. c_index = c_uint(index)
  4811. info = c_nvmlExcludedDeviceInfo_t()
  4812. fn = _nvmlGetFunctionPointer("nvmlGetExcludedDeviceInfoByIndex")
  4813. ret = fn(c_index, byref(info))
  4814. _nvmlCheckReturn(ret)
  4815. return info
  4816. def nvmlDeviceGetHostVgpuMode(handle):
  4817. c_host_vgpu_mode = _nvmlHostVgpuMode_t()
  4818. fn = _nvmlGetFunctionPointer("nvmlDeviceGetHostVgpuMode")
  4819. ret = fn(handle, byref(c_host_vgpu_mode))
  4820. _nvmlCheckReturn(ret)
  4821. return c_host_vgpu_mode.value
  4822. def nvmlDeviceSetMigMode(device, mode):
  4823. c_activationStatus = c_uint()
  4824. fn = _nvmlGetFunctionPointer("nvmlDeviceSetMigMode")
  4825. ret = fn(device, mode, byref(c_activationStatus))
  4826. _nvmlCheckReturn(ret)
  4827. return c_activationStatus.value
  4828. def nvmlDeviceGetMigMode(device):
  4829. c_currentMode = c_uint()
  4830. c_pendingMode = c_uint()
  4831. fn = _nvmlGetFunctionPointer("nvmlDeviceGetMigMode")
  4832. ret = fn(device, byref(c_currentMode), byref(c_pendingMode))
  4833. _nvmlCheckReturn(ret)
  4834. return [c_currentMode.value, c_pendingMode.value]
  4835. def nvmlDeviceGetGpuInstanceProfileInfo(device, profile, version=2):
  4836. if version == 2:
  4837. c_info = c_nvmlGpuInstanceProfileInfo_v2_t()
  4838. fn = _nvmlGetFunctionPointer("nvmlDeviceGetGpuInstanceProfileInfoV")
  4839. elif version == 1:
  4840. c_info = c_nvmlGpuInstanceProfileInfo_t()
  4841. fn = _nvmlGetFunctionPointer("nvmlDeviceGetGpuInstanceProfileInfo")
  4842. else:
  4843. raise NVMLError(NVML_ERROR_FUNCTION_NOT_FOUND)
  4844. ret = fn(device, profile, byref(c_info))
  4845. _nvmlCheckReturn(ret)
  4846. return c_info
  4847. def nvmlDeviceGetGpuInstanceProfileInfoById(device, profileId):
  4848. c_info = c_nvmlGpuInstanceProfileInfo_v2_t()
  4849. fn = _nvmlGetFunctionPointer("nvmlDeviceGetGpuInstanceProfileInfoByIdV")
  4850. ret = fn(device, profileId, byref(c_info))
  4851. _nvmlCheckReturn(ret)
  4852. return c_info
  4853. # Define function alias for the API exposed by NVML
  4854. nvmlDeviceGetGpuInstanceProfileInfoV = nvmlDeviceGetGpuInstanceProfileInfo
  4855. nvmlDeviceGetGpuInstanceProfileInfoByIdV = nvmlDeviceGetGpuInstanceProfileInfoById
  4856. def nvmlDeviceGetGpuInstanceRemainingCapacity(device, profileId):
  4857. c_count = c_uint()
  4858. fn = _nvmlGetFunctionPointer("nvmlDeviceGetGpuInstanceRemainingCapacity")
  4859. ret = fn(device, profileId, byref(c_count))
  4860. _nvmlCheckReturn(ret)
  4861. return c_count.value
  4862. def nvmlDeviceGetGpuInstancePossiblePlacements(device, profileId, placementsRef, countRef):
  4863. fn = _nvmlGetFunctionPointer("nvmlDeviceGetGpuInstancePossiblePlacements_v2")
  4864. ret = fn(device, profileId, placementsRef, countRef)
  4865. _nvmlCheckReturn(ret)
  4866. return NVML_SUCCESS
  4867. def nvmlDeviceCreateGpuInstance(device, profileId):
  4868. c_instance = c_nvmlGpuInstance_t()
  4869. fn = _nvmlGetFunctionPointer("nvmlDeviceCreateGpuInstance")
  4870. ret = fn(device, profileId, byref(c_instance))
  4871. _nvmlCheckReturn(ret)
  4872. return c_instance
  4873. def nvmlDeviceCreateGpuInstanceWithPlacement(device, profileId, placement):
  4874. c_instance = c_nvmlGpuInstance_t()
  4875. fn = _nvmlGetFunctionPointer("nvmlDeviceCreateGpuInstanceWithPlacement")
  4876. ret = fn(device, profileId, placement, byref(c_instance))
  4877. _nvmlCheckReturn(ret)
  4878. return c_instance
  4879. def nvmlGpuInstanceDestroy(gpuInstance):
  4880. fn = _nvmlGetFunctionPointer("nvmlGpuInstanceDestroy")
  4881. ret = fn(gpuInstance)
  4882. _nvmlCheckReturn(ret)
  4883. return NVML_SUCCESS
  4884. def nvmlDeviceGetGpuInstances(device, profileId, gpuInstancesRef, countRef):
  4885. fn = _nvmlGetFunctionPointer("nvmlDeviceGetGpuInstances")
  4886. ret = fn(device, profileId, gpuInstancesRef, countRef)
  4887. _nvmlCheckReturn(ret)
  4888. return NVML_SUCCESS
  4889. def nvmlDeviceGetGpuInstanceById(device, gpuInstanceId):
  4890. c_instance = c_nvmlGpuInstance_t()
  4891. fn = _nvmlGetFunctionPointer("nvmlDeviceGetGpuInstanceById")
  4892. ret = fn(device, gpuInstanceId, byref(c_instance))
  4893. _nvmlCheckReturn(ret)
  4894. return c_instance
  4895. def nvmlGpuInstanceGetInfo(gpuInstance):
  4896. c_info = c_nvmlGpuInstanceInfo_t()
  4897. fn = _nvmlGetFunctionPointer("nvmlGpuInstanceGetInfo")
  4898. ret = fn(gpuInstance, byref(c_info))
  4899. _nvmlCheckReturn(ret)
  4900. return c_info
  4901. def nvmlGpuInstanceGetComputeInstanceProfileInfo(device, profile, engProfile, version=2):
  4902. if version == 2:
  4903. c_info = c_nvmlComputeInstanceProfileInfo_v2_t()
  4904. fn = _nvmlGetFunctionPointer("nvmlGpuInstanceGetComputeInstanceProfileInfoV")
  4905. elif version == 1:
  4906. c_info = c_nvmlComputeInstanceProfileInfo_t()
  4907. fn = _nvmlGetFunctionPointer("nvmlGpuInstanceGetComputeInstanceProfileInfo")
  4908. else:
  4909. raise NVMLError(NVML_ERROR_FUNCTION_NOT_FOUND)
  4910. ret = fn(device, profile, engProfile, byref(c_info))
  4911. _nvmlCheckReturn(ret)
  4912. return c_info
  4913. # Define function alias for the API exposed by NVML
  4914. nvmlGpuInstanceGetComputeInstanceProfileInfoV = nvmlGpuInstanceGetComputeInstanceProfileInfo
  4915. def nvmlGpuInstanceGetComputeInstanceRemainingCapacity(gpuInstance, profileId):
  4916. c_count = c_uint()
  4917. fn = _nvmlGetFunctionPointer("nvmlGpuInstanceGetComputeInstanceRemainingCapacity")
  4918. ret = fn(gpuInstance, profileId, byref(c_count))
  4919. _nvmlCheckReturn(ret)
  4920. return c_count.value
  4921. def nvmlGpuInstanceGetComputeInstancePossiblePlacements(gpuInstance, profileId, placementsRef, countRef):
  4922. fn = _nvmlGetFunctionPointer("nvmlGpuInstanceGetComputeInstancePossiblePlacements")
  4923. ret = fn(gpuInstance, profileId, placementsRef, countRef)
  4924. _nvmlCheckReturn(ret)
  4925. return NVML_SUCCESS
  4926. def nvmlGpuInstanceCreateComputeInstance(gpuInstance, profileId):
  4927. c_instance = c_nvmlComputeInstance_t()
  4928. fn = _nvmlGetFunctionPointer("nvmlGpuInstanceCreateComputeInstance")
  4929. ret = fn(gpuInstance, profileId, byref(c_instance))
  4930. _nvmlCheckReturn(ret)
  4931. return c_instance
  4932. def nvmlGpuInstanceCreateComputeInstanceWithPlacement(gpuInstance, profileId, placement):
  4933. c_instance = c_nvmlComputeInstance_t()
  4934. fn = _nvmlGetFunctionPointer("nvmlGpuInstanceCreateComputeInstanceWithPlacement")
  4935. ret = fn(gpuInstance, profileId, placement, byref(c_instance))
  4936. _nvmlCheckReturn(ret)
  4937. return c_instance
  4938. def nvmlComputeInstanceDestroy(computeInstance):
  4939. fn = _nvmlGetFunctionPointer("nvmlComputeInstanceDestroy")
  4940. ret = fn(computeInstance)
  4941. _nvmlCheckReturn(ret)
  4942. return NVML_SUCCESS
  4943. def nvmlGpuInstanceGetComputeInstances(gpuInstance, profileId, computeInstancesRef, countRef):
  4944. fn = _nvmlGetFunctionPointer("nvmlGpuInstanceGetComputeInstances")
  4945. ret = fn(gpuInstance, profileId, computeInstancesRef, countRef)
  4946. _nvmlCheckReturn(ret)
  4947. return NVML_SUCCESS
  4948. def nvmlGpuInstanceGetComputeInstanceById(gpuInstance, computeInstanceId):
  4949. c_instance = c_nvmlComputeInstance_t()
  4950. fn = _nvmlGetFunctionPointer("nvmlGpuInstanceGetComputeInstanceById")
  4951. ret = fn(gpuInstance, computeInstanceId, byref(c_instance))
  4952. _nvmlCheckReturn(ret)
  4953. return c_instance
  4954. def nvmlComputeInstanceGetInfo_v2(computeInstance):
  4955. c_info = c_nvmlComputeInstanceInfo_t()
  4956. fn = _nvmlGetFunctionPointer("nvmlComputeInstanceGetInfo_v2")
  4957. ret = fn(computeInstance, byref(c_info))
  4958. _nvmlCheckReturn(ret)
  4959. return c_info
  4960. def nvmlComputeInstanceGetInfo(computeInstance):
  4961. return nvmlComputeInstanceGetInfo_v2(computeInstance)
  4962. def nvmlDeviceIsMigDeviceHandle(device):
  4963. c_isMigDevice = c_uint()
  4964. fn = _nvmlGetFunctionPointer("nvmlDeviceIsMigDeviceHandle")
  4965. ret = fn(device, byref(c_isMigDevice))
  4966. _nvmlCheckReturn(ret)
  4967. return c_isMigDevice
  4968. def nvmlDeviceGetGpuInstanceId(device):
  4969. c_gpuInstanceId = c_uint()
  4970. fn = _nvmlGetFunctionPointer("nvmlDeviceGetGpuInstanceId")
  4971. ret = fn(device, byref(c_gpuInstanceId))
  4972. _nvmlCheckReturn(ret)
  4973. return c_gpuInstanceId.value
  4974. def nvmlDeviceGetComputeInstanceId(device):
  4975. c_computeInstanceId = c_uint()
  4976. fn = _nvmlGetFunctionPointer("nvmlDeviceGetComputeInstanceId")
  4977. ret = fn(device, byref(c_computeInstanceId))
  4978. _nvmlCheckReturn(ret)
  4979. return c_computeInstanceId.value
  4980. def nvmlDeviceGetMaxMigDeviceCount(device):
  4981. c_count = c_uint()
  4982. fn = _nvmlGetFunctionPointer("nvmlDeviceGetMaxMigDeviceCount")
  4983. ret = fn(device, byref(c_count))
  4984. _nvmlCheckReturn(ret)
  4985. return c_count.value
  4986. def nvmlDeviceGetMigDeviceHandleByIndex(device, index):
  4987. c_index = c_uint(index)
  4988. migDevice = c_nvmlDevice_t()
  4989. fn = _nvmlGetFunctionPointer("nvmlDeviceGetMigDeviceHandleByIndex")
  4990. ret = fn(device, c_index, byref(migDevice))
  4991. _nvmlCheckReturn(ret)
  4992. return migDevice
  4993. def nvmlDeviceGetDeviceHandleFromMigDeviceHandle(migDevice):
  4994. device = c_nvmlDevice_t()
  4995. fn = _nvmlGetFunctionPointer("nvmlDeviceGetDeviceHandleFromMigDeviceHandle")
  4996. ret = fn(migDevice, byref(device))
  4997. _nvmlCheckReturn(ret)
  4998. return device
  4999. def nvmlDeviceGetAttributes_v2(device):
  5000. c_attrs = c_nvmlDeviceAttributes()
  5001. fn = _nvmlGetFunctionPointer("nvmlDeviceGetAttributes_v2")
  5002. ret = fn(device, byref(c_attrs))
  5003. _nvmlCheckReturn(ret)
  5004. return c_attrs
  5005. def nvmlDeviceGetAttributes(device):
  5006. return nvmlDeviceGetAttributes_v2(device)
  5007. def nvmlDeviceGetRemappedRows(device):
  5008. fn = _nvmlGetFunctionPointer("nvmlDeviceGetRemappedRows")
  5009. c_corr = c_uint()
  5010. c_unc = c_uint()
  5011. c_bpending = c_uint()
  5012. c_bfailure = c_uint()
  5013. ret = fn(device, byref(c_corr), byref(c_unc), byref(c_bpending), byref(c_bfailure))
  5014. _nvmlCheckReturn(ret)
  5015. return (c_corr.value, c_unc.value, c_bpending.value, c_bfailure.value)
  5016. def nvmlDeviceGetRowRemapperHistogram(device):
  5017. c_vals = c_nvmlRowRemapperHistogramValues()
  5018. fn = _nvmlGetFunctionPointer("nvmlDeviceGetRowRemapperHistogram")
  5019. ret = fn(device, byref(c_vals))
  5020. _nvmlCheckReturn(ret)
  5021. return c_vals
  5022. def nvmlDeviceGetArchitecture(device):
  5023. arch = _nvmlDeviceArchitecture_t()
  5024. fn = _nvmlGetFunctionPointer("nvmlDeviceGetArchitecture")
  5025. ret = fn(device, byref(arch))
  5026. _nvmlCheckReturn(ret)
  5027. return arch.value
  5028. def nvmlDeviceGetBusType(device):
  5029. c_busType = _nvmlBusType_t()
  5030. fn = _nvmlGetFunctionPointer("nvmlDeviceGetBusType")
  5031. ret = fn(device, byref(c_busType))
  5032. _nvmlCheckReturn(ret)
  5033. return c_busType.value
  5034. def nvmlDeviceGetIrqNum(device):
  5035. c_irqNum = c_uint()
  5036. fn = _nvmlGetFunctionPointer("nvmlDeviceGetIrqNum")
  5037. ret = fn(device, byref(c_irqNum))
  5038. _nvmlCheckReturn(ret)
  5039. return c_irqNum.value
  5040. def nvmlDeviceGetNumGpuCores(device):
  5041. c_numCores = c_uint()
  5042. fn = _nvmlGetFunctionPointer("nvmlDeviceGetNumGpuCores")
  5043. ret = fn(device, byref(c_numCores))
  5044. _nvmlCheckReturn(ret)
  5045. return c_numCores.value
  5046. def nvmlDeviceGetPowerSource(device):
  5047. c_powerSource = _nvmlPowerSource_t()
  5048. fn = _nvmlGetFunctionPointer("nvmlDeviceGetPowerSource")
  5049. ret = fn(device, byref(c_powerSource))
  5050. _nvmlCheckReturn(ret)
  5051. return c_powerSource.value
  5052. def nvmlDeviceGetMemoryBusWidth(device):
  5053. c_memBusWidth = c_uint()
  5054. fn = _nvmlGetFunctionPointer("nvmlDeviceGetMemoryBusWidth")
  5055. ret = fn(device, byref(c_memBusWidth))
  5056. _nvmlCheckReturn(ret)
  5057. return c_memBusWidth.value
  5058. def nvmlDeviceGetPcieLinkMaxSpeed(device):
  5059. c_speed = _nvmlPcieLinkMaxSpeed_t()
  5060. fn = _nvmlGetFunctionPointer("nvmlDeviceGetPcieLinkMaxSpeed")
  5061. ret = fn(device, byref(c_speed))
  5062. _nvmlCheckReturn(ret)
  5063. return c_speed.value
  5064. def nvmlDeviceGetAdaptiveClockInfoStatus(device):
  5065. c_adaptiveClockInfoStatus = _nvmlAdaptiveClockInfoStatus_t()
  5066. fn = _nvmlGetFunctionPointer("nvmlDeviceGetAdaptiveClockInfoStatus")
  5067. ret = fn(device, byref(c_adaptiveClockInfoStatus))
  5068. _nvmlCheckReturn(ret)
  5069. return c_adaptiveClockInfoStatus.value
  5070. def nvmlDeviceGetPcieSpeed(device):
  5071. c_speed = c_uint()
  5072. fn = _nvmlGetFunctionPointer("nvmlDeviceGetPcieSpeed")
  5073. ret = fn(device, byref(c_speed))
  5074. _nvmlCheckReturn(ret)
  5075. return c_speed.value
  5076. def nvmlDeviceGetDynamicPstatesInfo(device, c_dynamicpstatesinfo=c_nvmlGpuDynamicPstatesInfo_t()):
  5077. isReference = type(c_dynamicpstatesinfo) is not c_nvmlGpuDynamicPstatesInfo_t
  5078. dynamicpstatesinfoRef = c_dynamicpstatesinfo if isReference else byref(c_dynamicpstatesinfo)
  5079. fn = _nvmlGetFunctionPointer("nvmlDeviceGetDynamicPstatesInfo");
  5080. ret = fn(device, dynamicpstatesinfoRef)
  5081. _nvmlCheckReturn(ret)
  5082. return NVML_SUCCESS if isReference else c_dynamicpstatesinfo
  5083. def nvmlDeviceSetFanSpeed_v2(handle, index, speed):
  5084. fn = _nvmlGetFunctionPointer("nvmlDeviceSetFanSpeed_v2");
  5085. ret = fn(handle, index, speed)
  5086. _nvmlCheckReturn(ret)
  5087. return NVML_SUCCESS
  5088. def nvmlDeviceGetThermalSettings(device, sensorindex, c_thermalsettings=c_nvmlGpuThermalSettings_t()):
  5089. isReference = type(c_thermalsettings) is not c_nvmlGpuThermalSettings_t
  5090. thermalsettingsRef = c_thermalsettings if isReference else byref(c_thermalsettings)
  5091. fn = _nvmlGetFunctionPointer("nvmlDeviceGetThermalSettings");
  5092. ret = fn(device, sensorindex, thermalsettingsRef)
  5093. _nvmlCheckReturn(ret)
  5094. return NVML_SUCCESS if isReference else c_thermalsettings.sensor[:]
  5095. def nvmlDeviceGetMinMaxClockOfPState(device, clockType, pstate, minClockMHz=c_uint(), maxClockMHz=c_uint()):
  5096. isReference = (type(minClockMHz) is not c_uint) or (type(maxClockMHz) is not c_uint)
  5097. minClockMHzRef = minClockMHz if isReference else byref(minClockMHz)
  5098. maxClockMHzRef = maxClockMHz if isReference else byref(maxClockMHz)
  5099. fn = _nvmlGetFunctionPointer("nvmlDeviceGetMinMaxClockOfPState");
  5100. ret = fn(device, _nvmlClockType_t(clockType), _nvmlClockType_t(pstate), minClockMHzRef, maxClockMHzRef)
  5101. _nvmlCheckReturn(ret)
  5102. return NVML_SUCCESS if isReference else (minClockMHz.value, maxClockMHz.value)
  5103. _nvmlPowerMizerMode_t = c_uint
  5104. NVML_POWER_MIZER_MODE_ADAPTIVE = 0
  5105. NVML_POWER_MIZER_MODE_PREFER_MAXIMUM_PERFORMANCE = 1
  5106. NVML_POWER_MIZER_MODE_AUTO = 2
  5107. NVML_POWER_MIZER_MODE_PREFER_CONSISTENT_PERFORMANCE = 3
  5108. class c_nvmlDevicePowerMizerModes_v1_t(_PrintableStructure):
  5109. _fields_ = [
  5110. ('currentMode', _nvmlPowerMizerMode_t),
  5111. ('mode', _nvmlPowerMizerMode_t),
  5112. ('supportedPowerMizerModes', _nvmlPowerMizerMode_t),
  5113. ]
  5114. def nvmlDeviceGetPowerMizerMode_v1(device, info):
  5115. fn = _nvmlGetFunctionPointer("nvmlDeviceGetPowerMizerMode_v1");
  5116. ret = fn(device, info)
  5117. return ret
  5118. def nvmlDeviceSetPowerMizerMode_v1(device, info):
  5119. fn = _nvmlGetFunctionPointer("nvmlDeviceSetPowerMizerMode_v1");
  5120. ret = fn(device, info)
  5121. return ret
  5122. class c_nvmlClockOffset_t(_PrintableStructure):
  5123. _fields_ = [
  5124. ('version', c_uint),
  5125. ('type', _nvmlClockType_t),
  5126. ('pstate', _nvmlPstates_t),
  5127. ('clockOffsetMHz', c_int),
  5128. ('minClockOffsetMHz', c_int),
  5129. ('maxClockOffsetMHz', c_int),
  5130. ]
  5131. nvmlClockOffset_v1 = 0x1000018
  5132. def nvmlDeviceGetClockOffsets(device, info):
  5133. fn = _nvmlGetFunctionPointer("nvmlDeviceGetClockOffsets");
  5134. ret = fn(device, info)
  5135. return NVML_SUCCESS
  5136. def nvmlDeviceSetClockOffsets(device, info):
  5137. fn = _nvmlGetFunctionPointer("nvmlDeviceSetClockOffsets");
  5138. ret = fn(device, info)
  5139. return NVML_SUCCESS
  5140. def nvmlDeviceGetSupportedPerformanceStates(device):
  5141. pstates = []
  5142. c_count = c_uint(NVML_MAX_GPU_PERF_PSTATES)
  5143. c_size = sizeof(c_uint)*c_count.value
  5144. # NOTE: use 'c_uint' to represent the size of the nvmlPstate_t enumeration.
  5145. pstates_array = _nvmlPstates_t * c_count.value
  5146. c_pstates = pstates_array()
  5147. fn = _nvmlGetFunctionPointer("nvmlDeviceGetSupportedPerformanceStates")
  5148. ret = fn(device, c_pstates, c_size)
  5149. _nvmlCheckReturn(ret)
  5150. for value in c_pstates:
  5151. if value != NVML_PSTATE_UNKNOWN:
  5152. pstates.append(value)
  5153. return pstates
  5154. def nvmlDeviceGetGpcClkVfOffset(device):
  5155. offset = c_int32()
  5156. fn = _nvmlGetFunctionPointer("nvmlDeviceGetGpcClkVfOffset")
  5157. ret = fn(device, byref(offset))
  5158. _nvmlCheckReturn(ret)
  5159. return offset.value
  5160. # Deprecated
  5161. def nvmlDeviceSetGpcClkVfOffset(device, offset):
  5162. c_offset = c_int32(offset)
  5163. fn = _nvmlGetFunctionPointer("nvmlDeviceSetGpcClkVfOffset")
  5164. ret = fn(device, c_offset)
  5165. _nvmlCheckReturn(ret)
  5166. return NVML_SUCCESS
  5167. def nvmlDeviceGetGpcClkMinMaxVfOffset(device, minOffset=c_int(), maxOffset=c_int()):
  5168. isReference = (type(minOffset) is not c_int) or (type(maxOffset) is not c_int)
  5169. minOffsetRef = minOffset if isReference else byref(minOffset)
  5170. maxOffsetRef = maxOffset if isReference else byref(maxOffset)
  5171. fn = _nvmlGetFunctionPointer("nvmlDeviceGetGpcClkMinMaxVfOffset")
  5172. ret = fn(device, minOffsetRef, maxOffsetRef)
  5173. _nvmlCheckReturn(ret)
  5174. return NVML_SUCCESS if isReference else (minOffset.value, maxOffset.value)
  5175. def nvmlDeviceGetMemClkVfOffset(device):
  5176. offset = c_int32()
  5177. fn = _nvmlGetFunctionPointer("nvmlDeviceGetMemClkVfOffset")
  5178. ret = fn(device, byref(offset))
  5179. _nvmlCheckReturn(ret)
  5180. return offset.value
  5181. # Deprecated
  5182. def nvmlDeviceSetMemClkVfOffset(device, offset):
  5183. c_offset = c_int32(offset)
  5184. fn = _nvmlGetFunctionPointer("nvmlDeviceSetMemClkVfOffset")
  5185. ret = fn(device, c_offset)
  5186. _nvmlCheckReturn(ret)
  5187. return NVML_SUCCESS
  5188. def nvmlDeviceGetMemClkMinMaxVfOffset(device, minOffset=c_int(), maxOffset=c_int()):
  5189. isReference = (type(minOffset) is not c_int) or (type(maxOffset) is not c_int)
  5190. minOffsetRef = minOffset if isReference else byref(minOffset)
  5191. maxOffsetRef = maxOffset if isReference else byref(maxOffset)
  5192. fn = _nvmlGetFunctionPointer("nvmlDeviceGetMemClkMinMaxVfOffset")
  5193. ret = fn(device, minOffsetRef, maxOffsetRef)
  5194. _nvmlCheckReturn(ret)
  5195. return NVML_SUCCESS if isReference else (minOffset.value, maxOffset.value)
  5196. def nvmlSystemSetConfComputeGpusReadyState(state):
  5197. c_state = c_uint(state)
  5198. fn = _nvmlGetFunctionPointer("nvmlSystemSetConfComputeGpusReadyState")
  5199. ret = fn(c_state)
  5200. _nvmlCheckReturn(ret)
  5201. return NVML_SUCCESS
  5202. def nvmlSystemGetConfComputeGpusReadyState():
  5203. c_state = c_uint()
  5204. fn = _nvmlGetFunctionPointer("nvmlSystemGetConfComputeGpusReadyState")
  5205. ret = fn(byref(c_state))
  5206. _nvmlCheckReturn(ret)
  5207. return c_state.value
  5208. def nvmlSystemGetConfComputeCapabilities():
  5209. c_ccSysCaps = c_nvmlConfComputeSystemCaps_t()
  5210. fn = _nvmlGetFunctionPointer("nvmlSystemGetConfComputeCapabilities")
  5211. ret = fn(byref(c_ccSysCaps))
  5212. _nvmlCheckReturn(ret)
  5213. return c_ccSysCaps
  5214. def nvmlSystemGetConfComputeState():
  5215. c_state = c_nvmlConfComputeSystemState_t()
  5216. fn = _nvmlGetFunctionPointer("nvmlSystemGetConfComputeState")
  5217. ret = fn(byref(c_state))
  5218. _nvmlCheckReturn(ret)
  5219. return c_state
  5220. def nvmlSystemGetConfComputeSettings(settings):
  5221. fn = _nvmlGetFunctionPointer("nvmlSystemGetConfComputeSettings")
  5222. return fn(settings)
  5223. def nvmlDeviceSetConfComputeUnprotectedMemSize(device, c_ccMemSize):
  5224. fn = _nvmlGetFunctionPointer("nvmlDeviceSetConfComputeUnprotectedMemSize")
  5225. ret = fn(device, c_ccMemSize)
  5226. _nvmlCheckReturn(ret)
  5227. return NVML_SUCCESS
  5228. def nvmlDeviceGetConfComputeMemSizeInfo(device):
  5229. c_ccMemSize = c_nvmlConfComputeMemSizeInfo_t()
  5230. fn = _nvmlGetFunctionPointer("nvmlDeviceGetConfComputeMemSizeInfo")
  5231. ret = fn(device, byref(c_ccMemSize))
  5232. _nvmlCheckReturn(ret)
  5233. return c_ccMemSize
  5234. def nvmlDeviceGetConfComputeProtectedMemoryUsage(device):
  5235. c_memory = c_nvmlMemory_t()
  5236. fn = _nvmlGetFunctionPointer("nvmlDeviceGetConfComputeProtectedMemoryUsage")
  5237. ret = fn(device, byref(c_memory))
  5238. _nvmlCheckReturn(ret)
  5239. return c_memory
  5240. def nvmlDeviceGetConfComputeGpuCertificate(device):
  5241. c_cert = c_nvmlConfComputeGpuCertificate_t()
  5242. fn = _nvmlGetFunctionPointer("nvmlDeviceGetConfComputeGpuCertificate")
  5243. ret = fn(device, byref(c_cert))
  5244. _nvmlCheckReturn(ret)
  5245. return c_cert
  5246. def nvmlDeviceGetConfComputeGpuAttestationReport(device, c_nonce):
  5247. c_attestReport = c_nvmlConfComputeGpuAttestationReport_t()
  5248. c_nonce_arr = (c_uint8 * len(c_nonce))(*(c_nonce))
  5249. setattr(c_attestReport, 'nonce', c_nonce_arr)
  5250. fn = _nvmlGetFunctionPointer("nvmlDeviceGetConfComputeGpuAttestationReport")
  5251. ret = fn(device, byref(c_attestReport))
  5252. _nvmlCheckReturn(ret)
  5253. return c_attestReport
  5254. def nvmlSystemSetConfComputeKeyRotationThresholdInfo(max_atk_adv):
  5255. c_keyRotationThrInfo = c_nvmlConfComputeSetKeyRotationThresholdInfo_t(0)
  5256. c_keyRotationThrInfo.version = ConfComputeSetKeyRotationThresholdInfo_v1
  5257. c_keyRotationThrInfo.maxAttackerAdvantage = max_atk_adv
  5258. fn = _nvmlGetFunctionPointer("nvmlSystemSetConfComputeKeyRotationThresholdInfo")
  5259. ret = fn(byref(c_keyRotationThrInfo))
  5260. _nvmlCheckReturn(ret)
  5261. return NVML_SUCCESS
  5262. def nvmlSystemGetConfComputeKeyRotationThresholdInfo():
  5263. c_keyRotationThrInfo = c_nvmlConfComputeGetKeyRotationThresholdInfo_t(0)
  5264. c_keyRotationThrInfo.version = ConfComputeGetKeyRotationThresholdInfo_v1
  5265. fn = _nvmlGetFunctionPointer("nvmlSystemGetConfComputeKeyRotationThresholdInfo")
  5266. ret = fn(byref(c_keyRotationThrInfo))
  5267. _nvmlCheckReturn(ret)
  5268. return c_keyRotationThrInfo
  5269. ## GPM ##
  5270. #########
  5271. ## Enums/defines
  5272. #### GPM Metric Identifiers
  5273. NVML_GPM_METRIC_GRAPHICS_UTIL = 1 # Percentage of time any compute/graphics app was active on the GPU. 0.0 - 100.0
  5274. NVML_GPM_METRIC_SM_UTIL = 2 # Percentage of SMs that were busy. 0.0 - 100.0
  5275. NVML_GPM_METRIC_SM_OCCUPANCY = 3 # Percentage of warps that were active vs theoretical maximum. 0.0 - 100.0
  5276. NVML_GPM_METRIC_INTEGER_UTIL = 4 # Percentage of time the GPU's SMs were doing integer operations. 0.0 - 100.0
  5277. NVML_GPM_METRIC_ANY_TENSOR_UTIL = 5 # Percentage of time the GPU's SMs were doing ANY tensor operations. 0.0 - 100.0
  5278. NVML_GPM_METRIC_DFMA_TENSOR_UTIL = 6 # Percentage of time the GPU's SMs were doing DFMA tensor operations. 0.0 - 100.0
  5279. NVML_GPM_METRIC_HMMA_TENSOR_UTIL = 7 # Percentage of time the GPU's SMs were doing HMMA tensor operations. 0.0 - 100.0
  5280. NVML_GPM_METRIC_IMMA_TENSOR_UTIL = 9 # Percentage of time the GPU's SMs were doing IMMA tensor operations. 0.0 - 100.0
  5281. NVML_GPM_METRIC_DRAM_BW_UTIL = 10 # Percentage of DRAM bw used vs theoretical maximum. 0.0 - 100.0
  5282. NVML_GPM_METRIC_FP64_UTIL = 11 # Percentage of time the GPU's SMs were doing non-tensor FP64 math. 0.0 - 100.0
  5283. NVML_GPM_METRIC_FP32_UTIL = 12 # Percentage of time the GPU's SMs were doing non-tensor FP32 math. 0.0 - 100.0
  5284. NVML_GPM_METRIC_FP16_UTIL = 13 # Percentage of time the GPU's SMs were doing non-tensor FP16 math. 0.0 - 100.0
  5285. NVML_GPM_METRIC_PCIE_TX_PER_SEC = 20 # PCIe traffic from this GPU in MiB/sec
  5286. NVML_GPM_METRIC_PCIE_RX_PER_SEC = 21 # PCIe traffic to this GPU in MiB/sec
  5287. NVML_GPM_METRIC_NVDEC_0_UTIL = 30 # Percent utilization of NVDEC 0. 0.0 - 100.0
  5288. NVML_GPM_METRIC_NVDEC_1_UTIL = 31 # Percent utilization of NVDEC 1. 0.0 - 100.0
  5289. NVML_GPM_METRIC_NVDEC_2_UTIL = 32 # Percent utilization of NVDEC 2. 0.0 - 100.0
  5290. NVML_GPM_METRIC_NVDEC_3_UTIL = 33 # Percent utilization of NVDEC 3. 0.0 - 100.0
  5291. NVML_GPM_METRIC_NVDEC_4_UTIL = 34 # Percent utilization of NVDEC 4. 0.0 - 100.0
  5292. NVML_GPM_METRIC_NVDEC_5_UTIL = 35 # Percent utilization of NVDEC 5. 0.0 - 100.0
  5293. NVML_GPM_METRIC_NVDEC_6_UTIL = 36 # Percent utilization of NVDEC 6. 0.0 - 100.0
  5294. NVML_GPM_METRIC_NVDEC_7_UTIL = 37 # Percent utilization of NVDEC 7. 0.0 - 100.0
  5295. NVML_GPM_METRIC_NVJPG_0_UTIL = 40 # Percent utilization of NVJPG 0. 0.0 - 100.0
  5296. NVML_GPM_METRIC_NVJPG_1_UTIL = 41 # Percent utilization of NVJPG 1. 0.0 - 100.0
  5297. NVML_GPM_METRIC_NVJPG_2_UTIL = 42 # Percent utilization of NVJPG 2. 0.0 - 100.0
  5298. NVML_GPM_METRIC_NVJPG_3_UTIL = 43 # Percent utilization of NVJPG 3. 0.0 - 100.0
  5299. NVML_GPM_METRIC_NVJPG_4_UTIL = 44 # Percent utilization of NVJPG 4. 0.0 - 100.0
  5300. NVML_GPM_METRIC_NVJPG_5_UTIL = 45 # Percent utilization of NVJPG 5. 0.0 - 100.0
  5301. NVML_GPM_METRIC_NVJPG_6_UTIL = 46 # Percent utilization of NVJPG 6. 0.0 - 100.0
  5302. NVML_GPM_METRIC_NVJPG_7_UTIL = 47 # Percent utilization of NVJPG 7. 0.0 - 100.0
  5303. NVML_GPM_METRIC_NVOFA_0_UTIL = 50 # Percent utilization of NVOFA 0. 0.0 - 100.0
  5304. NVML_GPM_METRIC_NVOFA_1_UTIL = 51 # Percent utilization of NVOFA 1. 0.0 - 100.0
  5305. NVML_GPM_METRIC_NVLINK_TOTAL_RX_PER_SEC = 60 # NvLink read bandwidth for all links in MiB/sec
  5306. NVML_GPM_METRIC_NVLINK_TOTAL_TX_PER_SEC = 61 # NvLink write bandwidth for all links in MiB/sec
  5307. NVML_GPM_METRIC_NVLINK_L0_RX_PER_SEC = 62 # NvLink read bandwidth for link 0 in MiB/sec
  5308. NVML_GPM_METRIC_NVLINK_L0_TX_PER_SEC = 63 # NvLink write bandwidth for link 0 in MiB/sec
  5309. NVML_GPM_METRIC_NVLINK_L1_RX_PER_SEC = 64 # NvLink read bandwidth for link 1 in MiB/sec
  5310. NVML_GPM_METRIC_NVLINK_L1_TX_PER_SEC = 65 # NvLink write bandwidth for link 1 in MiB/sec
  5311. NVML_GPM_METRIC_NVLINK_L2_RX_PER_SEC = 66 # NvLink read bandwidth for link 2 in MiB/sec
  5312. NVML_GPM_METRIC_NVLINK_L2_TX_PER_SEC = 67 # NvLink write bandwidth for link 2 in MiB/sec
  5313. NVML_GPM_METRIC_NVLINK_L3_RX_PER_SEC = 68 # NvLink read bandwidth for link 3 in MiB/sec
  5314. NVML_GPM_METRIC_NVLINK_L3_TX_PER_SEC = 69 # NvLink write bandwidth for link 3 in MiB/sec
  5315. NVML_GPM_METRIC_NVLINK_L4_RX_PER_SEC = 70 # NvLink read bandwidth for link 4 in MiB/sec
  5316. NVML_GPM_METRIC_NVLINK_L4_TX_PER_SEC = 71 # NvLink write bandwidth for link 4 in MiB/sec
  5317. NVML_GPM_METRIC_NVLINK_L5_RX_PER_SEC = 72 # NvLink read bandwidth for link 5 in MiB/sec
  5318. NVML_GPM_METRIC_NVLINK_L5_TX_PER_SEC = 73 # NvLink write bandwidth for link 5 in MiB/sec
  5319. NVML_GPM_METRIC_NVLINK_L6_RX_PER_SEC = 74 # NvLink read bandwidth for link 6 in MiB/sec
  5320. NVML_GPM_METRIC_NVLINK_L6_TX_PER_SEC = 75 # NvLink write bandwidth for link 6 in MiB/sec
  5321. NVML_GPM_METRIC_NVLINK_L7_RX_PER_SEC = 76 # NvLink read bandwidth for link 7 in MiB/sec
  5322. NVML_GPM_METRIC_NVLINK_L7_TX_PER_SEC = 77 # NvLink write bandwidth for link 7 in MiB/sec
  5323. NVML_GPM_METRIC_NVLINK_L8_RX_PER_SEC = 78 # NvLink read bandwidth for link 8 in MiB/sec
  5324. NVML_GPM_METRIC_NVLINK_L8_TX_PER_SEC = 79 # NvLink write bandwidth for link 8 in MiB/sec
  5325. NVML_GPM_METRIC_NVLINK_L9_RX_PER_SEC = 80 # NvLink read bandwidth for link 9 in MiB/sec
  5326. NVML_GPM_METRIC_NVLINK_L9_TX_PER_SEC = 81 # NvLink write bandwidth for link 9 in MiB/sec
  5327. NVML_GPM_METRIC_NVLINK_L10_RX_PER_SEC = 82 # NvLink read bandwidth for link 10 in MiB/sec
  5328. NVML_GPM_METRIC_NVLINK_L10_TX_PER_SEC = 83 # NvLink write bandwidth for link 10 in MiB/sec
  5329. NVML_GPM_METRIC_NVLINK_L11_RX_PER_SEC = 84 # NvLink read bandwidth for link 11 in MiB/sec
  5330. NVML_GPM_METRIC_NVLINK_L11_TX_PER_SEC = 85 # NvLink write bandwidth for link 11 in MiB/sec
  5331. NVML_GPM_METRIC_NVLINK_L12_RX_PER_SEC = 86 # NvLink read bandwidth for link 12 in MiB/sec
  5332. NVML_GPM_METRIC_NVLINK_L12_TX_PER_SEC = 87 # NvLink write bandwidth for link 12 in MiB/sec
  5333. NVML_GPM_METRIC_NVLINK_L13_RX_PER_SEC = 88 # NvLink read bandwidth for link 13 in MiB/sec
  5334. NVML_GPM_METRIC_NVLINK_L13_TX_PER_SEC = 89 # NvLink write bandwidth for link 13 in MiB/sec
  5335. NVML_GPM_METRIC_NVLINK_L14_RX_PER_SEC = 90 # NvLink read bandwidth for link 14 in MiB/sec
  5336. NVML_GPM_METRIC_NVLINK_L14_TX_PER_SEC = 91 # NvLink write bandwidth for link 14 in MiB/sec
  5337. NVML_GPM_METRIC_NVLINK_L15_RX_PER_SEC = 92 # NvLink read bandwidth for link 15 in MiB/sec
  5338. NVML_GPM_METRIC_NVLINK_L15_TX_PER_SEC = 93 # NvLink write bandwidth for link 15 in MiB/sec
  5339. NVML_GPM_METRIC_NVLINK_L16_RX_PER_SEC = 94 # NvLink read bandwidth for link 16 in MiB/sec
  5340. NVML_GPM_METRIC_NVLINK_L16_TX_PER_SEC = 95 # NvLink write bandwidth for link 16 in MiB/sec
  5341. NVML_GPM_METRIC_NVLINK_L17_RX_PER_SEC = 96 # NvLink read bandwidth for link 17 in MiB/sec
  5342. NVML_GPM_METRIC_NVLINK_L17_TX_PER_SEC = 97 # NvLink write bandwidth for link 17 in MiB/sec
  5343. NVML_GPM_METRIC_C2C_TOTAL_TX_PER_SEC = 100
  5344. NVML_GPM_METRIC_C2C_TOTAL_RX_PER_SEC = 101
  5345. NVML_GPM_METRIC_C2C_DATA_TX_PER_SEC = 102
  5346. NVML_GPM_METRIC_C2C_DATA_RX_PER_SEC = 103
  5347. NVML_GPM_METRIC_C2C_LINK0_TOTAL_TX_PER_SEC = 104
  5348. NVML_GPM_METRIC_C2C_LINK0_TOTAL_RX_PER_SEC = 105
  5349. NVML_GPM_METRIC_C2C_LINK0_DATA_TX_PER_SEC = 106
  5350. NVML_GPM_METRIC_C2C_LINK0_DATA_RX_PER_SEC = 107
  5351. NVML_GPM_METRIC_C2C_LINK1_TOTAL_TX_PER_SEC = 108
  5352. NVML_GPM_METRIC_C2C_LINK1_TOTAL_RX_PER_SEC = 109
  5353. NVML_GPM_METRIC_C2C_LINK1_DATA_TX_PER_SEC = 110
  5354. NVML_GPM_METRIC_C2C_LINK1_DATA_RX_PER_SEC = 111
  5355. NVML_GPM_METRIC_C2C_LINK2_TOTAL_TX_PER_SEC = 112
  5356. NVML_GPM_METRIC_C2C_LINK2_TOTAL_RX_PER_SEC = 113
  5357. NVML_GPM_METRIC_C2C_LINK2_DATA_TX_PER_SEC = 114
  5358. NVML_GPM_METRIC_C2C_LINK2_DATA_RX_PER_SEC = 115
  5359. NVML_GPM_METRIC_C2C_LINK3_TOTAL_TX_PER_SEC = 116
  5360. NVML_GPM_METRIC_C2C_LINK3_TOTAL_RX_PER_SEC = 117
  5361. NVML_GPM_METRIC_C2C_LINK3_DATA_TX_PER_SEC = 118
  5362. NVML_GPM_METRIC_C2C_LINK3_DATA_RX_PER_SEC = 119
  5363. NVML_GPM_METRIC_C2C_LINK4_TOTAL_TX_PER_SEC = 120
  5364. NVML_GPM_METRIC_C2C_LINK4_TOTAL_RX_PER_SEC = 121
  5365. NVML_GPM_METRIC_C2C_LINK4_DATA_TX_PER_SEC = 122
  5366. NVML_GPM_METRIC_C2C_LINK4_DATA_RX_PER_SEC = 123
  5367. NVML_GPM_METRIC_C2C_LINK5_TOTAL_TX_PER_SEC = 124
  5368. NVML_GPM_METRIC_C2C_LINK5_TOTAL_RX_PER_SEC = 125
  5369. NVML_GPM_METRIC_C2C_LINK5_DATA_TX_PER_SEC = 126
  5370. NVML_GPM_METRIC_C2C_LINK5_DATA_RX_PER_SEC = 127
  5371. NVML_GPM_METRIC_C2C_LINK6_TOTAL_TX_PER_SEC = 128
  5372. NVML_GPM_METRIC_C2C_LINK6_TOTAL_RX_PER_SEC = 129
  5373. NVML_GPM_METRIC_C2C_LINK6_DATA_TX_PER_SEC = 130
  5374. NVML_GPM_METRIC_C2C_LINK6_DATA_RX_PER_SEC = 131
  5375. NVML_GPM_METRIC_C2C_LINK7_TOTAL_TX_PER_SEC = 132
  5376. NVML_GPM_METRIC_C2C_LINK7_TOTAL_RX_PER_SEC = 133
  5377. NVML_GPM_METRIC_C2C_LINK7_DATA_TX_PER_SEC = 134
  5378. NVML_GPM_METRIC_C2C_LINK7_DATA_RX_PER_SEC = 135
  5379. NVML_GPM_METRIC_C2C_LINK8_TOTAL_TX_PER_SEC = 136
  5380. NVML_GPM_METRIC_C2C_LINK8_TOTAL_RX_PER_SEC = 137
  5381. NVML_GPM_METRIC_C2C_LINK8_DATA_TX_PER_SEC = 138
  5382. NVML_GPM_METRIC_C2C_LINK8_DATA_RX_PER_SEC = 139
  5383. NVML_GPM_METRIC_C2C_LINK9_TOTAL_TX_PER_SEC = 140
  5384. NVML_GPM_METRIC_C2C_LINK9_TOTAL_RX_PER_SEC = 141
  5385. NVML_GPM_METRIC_C2C_LINK9_DATA_TX_PER_SEC = 142
  5386. NVML_GPM_METRIC_C2C_LINK9_DATA_RX_PER_SEC = 143
  5387. NVML_GPM_METRIC_C2C_LINK10_TOTAL_TX_PER_SEC = 144
  5388. NVML_GPM_METRIC_C2C_LINK10_TOTAL_RX_PER_SEC = 145
  5389. NVML_GPM_METRIC_C2C_LINK10_DATA_TX_PER_SEC = 146
  5390. NVML_GPM_METRIC_C2C_LINK10_DATA_RX_PER_SEC = 147
  5391. NVML_GPM_METRIC_C2C_LINK11_TOTAL_TX_PER_SEC = 148
  5392. NVML_GPM_METRIC_C2C_LINK11_TOTAL_RX_PER_SEC = 149
  5393. NVML_GPM_METRIC_C2C_LINK11_DATA_TX_PER_SEC = 150
  5394. NVML_GPM_METRIC_C2C_LINK11_DATA_RX_PER_SEC = 151
  5395. NVML_GPM_METRIC_C2C_LINK12_TOTAL_TX_PER_SEC = 152
  5396. NVML_GPM_METRIC_C2C_LINK12_TOTAL_RX_PER_SEC = 153
  5397. NVML_GPM_METRIC_C2C_LINK12_DATA_TX_PER_SEC = 154
  5398. NVML_GPM_METRIC_C2C_LINK12_DATA_RX_PER_SEC = 155
  5399. NVML_GPM_METRIC_C2C_LINK13_TOTAL_TX_PER_SEC = 156
  5400. NVML_GPM_METRIC_C2C_LINK13_TOTAL_RX_PER_SEC = 157
  5401. NVML_GPM_METRIC_C2C_LINK13_DATA_TX_PER_SEC = 158
  5402. NVML_GPM_METRIC_C2C_LINK13_DATA_RX_PER_SEC = 159
  5403. NVML_GPM_METRIC_HOSTMEM_CACHE_HIT = 160
  5404. NVML_GPM_METRIC_HOSTMEM_CACHE_MISS = 161
  5405. NVML_GPM_METRIC_PEERMEM_CACHE_HIT = 162
  5406. NVML_GPM_METRIC_PEERMEM_CACHE_MISS = 163
  5407. NVML_GPM_METRIC_DRAM_CACHE_HIT = 164
  5408. NVML_GPM_METRIC_DRAM_CACHE_MISS = 165
  5409. NVML_GPM_METRIC_NVENC_0_UTIL = 166,
  5410. NVML_GPM_METRIC_NVENC_1_UTIL = 167,
  5411. NVML_GPM_METRIC_NVENC_2_UTIL = 168,
  5412. NVML_GPM_METRIC_NVENC_3_UTIL = 169,
  5413. NVML_GPM_METRIC_GR0_CTXSW_CYCLES_ELAPSED = 170,
  5414. NVML_GPM_METRIC_GR0_CTXSW_CYCLES_ACTIVE = 171,
  5415. NVML_GPM_METRIC_GR0_CTXSW_REQUESTS = 172,
  5416. NVML_GPM_METRIC_GR0_CTXSW_CYCLES_PER_REQ = 173,
  5417. NVML_GPM_METRIC_GR0_CTXSW_ACTIVE_PCT = 174,
  5418. NVML_GPM_METRIC_GR1_CTXSW_CYCLES_ELAPSED = 175,
  5419. NVML_GPM_METRIC_GR1_CTXSW_CYCLES_ACTIVE = 176,
  5420. NVML_GPM_METRIC_GR1_CTXSW_REQUESTS = 177,
  5421. NVML_GPM_METRIC_GR1_CTXSW_CYCLES_PER_REQ = 178,
  5422. NVML_GPM_METRIC_GR1_CTXSW_ACTIVE_PCT = 179,
  5423. NVML_GPM_METRIC_GR2_CTXSW_CYCLES_ELAPSED = 180,
  5424. NVML_GPM_METRIC_GR2_CTXSW_CYCLES_ACTIVE = 181,
  5425. NVML_GPM_METRIC_GR2_CTXSW_REQUESTS = 182,
  5426. NVML_GPM_METRIC_GR2_CTXSW_CYCLES_PER_REQ = 183,
  5427. NVML_GPM_METRIC_GR2_CTXSW_ACTIVE_PCT = 184,
  5428. NVML_GPM_METRIC_GR3_CTXSW_CYCLES_ELAPSED = 185,
  5429. NVML_GPM_METRIC_GR3_CTXSW_CYCLES_ACTIVE = 186,
  5430. NVML_GPM_METRIC_GR3_CTXSW_REQUESTS = 187,
  5431. NVML_GPM_METRIC_GR3_CTXSW_CYCLES_PER_REQ = 188,
  5432. NVML_GPM_METRIC_GR3_CTXSW_ACTIVE_PCT = 189,
  5433. NVML_GPM_METRIC_GR4_CTXSW_CYCLES_ELAPSED = 190,
  5434. NVML_GPM_METRIC_GR4_CTXSW_CYCLES_ACTIVE = 191,
  5435. NVML_GPM_METRIC_GR4_CTXSW_REQUESTS = 192,
  5436. NVML_GPM_METRIC_GR4_CTXSW_CYCLES_PER_REQ = 193,
  5437. NVML_GPM_METRIC_GR4_CTXSW_ACTIVE_PCT = 194,
  5438. NVML_GPM_METRIC_GR5_CTXSW_CYCLES_ELAPSED = 195,
  5439. NVML_GPM_METRIC_GR5_CTXSW_CYCLES_ACTIVE = 196,
  5440. NVML_GPM_METRIC_GR5_CTXSW_REQUESTS = 197,
  5441. NVML_GPM_METRIC_GR5_CTXSW_CYCLES_PER_REQ = 198,
  5442. NVML_GPM_METRIC_GR5_CTXSW_ACTIVE_PCT = 199,
  5443. NVML_GPM_METRIC_GR6_CTXSW_CYCLES_ELAPSED = 200,
  5444. NVML_GPM_METRIC_GR6_CTXSW_CYCLES_ACTIVE = 201,
  5445. NVML_GPM_METRIC_GR6_CTXSW_REQUESTS = 202,
  5446. NVML_GPM_METRIC_GR6_CTXSW_CYCLES_PER_REQ = 203,
  5447. NVML_GPM_METRIC_GR6_CTXSW_ACTIVE_PCT = 204,
  5448. NVML_GPM_METRIC_GR7_CTXSW_CYCLES_ELAPSED = 205,
  5449. NVML_GPM_METRIC_GR7_CTXSW_CYCLES_ACTIVE = 206,
  5450. NVML_GPM_METRIC_GR7_CTXSW_REQUESTS = 207,
  5451. NVML_GPM_METRIC_GR7_CTXSW_CYCLES_PER_REQ = 208,
  5452. NVML_GPM_METRIC_GR7_CTXSW_ACTIVE_PCT = 209,
  5453. NVML_GPM_METRIC_MAX = 210
  5454. ## Structs
  5455. class c_nvmlUnitInfo_t(_PrintableStructure):
  5456. _fields_ = [
  5457. ('name', c_char * 96),
  5458. ('id', c_char * 96),
  5459. ('serial', c_char * 96),
  5460. ('firmwareVersion', c_char * 96),
  5461. ]
  5462. class struct_c_nvmlGpmSample_t(Structure):
  5463. pass # opaque handle
  5464. c_nvmlGpmSample_t = POINTER(struct_c_nvmlGpmSample_t)
  5465. class c_metricInfo_t(Structure):
  5466. _fields_ = [
  5467. ("shortName", c_char_p),
  5468. ("longName", c_char_p),
  5469. ("unit", c_char_p),
  5470. ]
  5471. class c_nvmlGpmMetric_t(_PrintableStructure):
  5472. _fields_ = [
  5473. ('metricId', c_uint),
  5474. ('nvmlReturn', _nvmlReturn_t),
  5475. ('value', c_double),
  5476. ('metricInfo', c_metricInfo_t)
  5477. ]
  5478. class c_nvmlGpmMetricsGet_t(_PrintableStructure):
  5479. _fields_ = [
  5480. ('version', c_uint),
  5481. ('numMetrics', c_uint),
  5482. ('sample1', c_nvmlGpmSample_t),
  5483. ('sample2', c_nvmlGpmSample_t),
  5484. ('metrics', c_nvmlGpmMetric_t * NVML_GPM_METRIC_MAX)
  5485. ]
  5486. NVML_GPM_METRICS_GET_VERSION = 1
  5487. class c_nvmlGpmSupport_t(_PrintableStructure):
  5488. _fields_ = [
  5489. ('version', c_uint),
  5490. ('isSupportedDevice', c_uint),
  5491. ]
  5492. NVML_GPM_SUPPORT_VERSION = 1
  5493. ## Functions
  5494. def nvmlGpmMetricsGet(metricsGet):
  5495. fn = _nvmlGetFunctionPointer("nvmlGpmMetricsGet")
  5496. ret = fn(byref(metricsGet))
  5497. _nvmlCheckReturn(ret)
  5498. return metricsGet
  5499. def nvmlGpmSampleFree(gpmSample):
  5500. fn = _nvmlGetFunctionPointer("nvmlGpmSampleFree")
  5501. ret = fn(gpmSample)
  5502. _nvmlCheckReturn(ret)
  5503. return
  5504. def nvmlGpmSampleAlloc():
  5505. gpmSample = c_nvmlGpmSample_t()
  5506. fn = _nvmlGetFunctionPointer("nvmlGpmSampleAlloc")
  5507. ret = fn(byref(gpmSample))
  5508. _nvmlCheckReturn(ret)
  5509. return gpmSample
  5510. def nvmlGpmSampleGet(device, gpmSample):
  5511. fn = _nvmlGetFunctionPointer("nvmlGpmSampleGet")
  5512. ret = fn(device, gpmSample)
  5513. _nvmlCheckReturn(ret)
  5514. return gpmSample
  5515. def nvmlGpmMigSampleGet(device, gpuInstanceId, gpmSample):
  5516. fn = _nvmlGetFunctionPointer("nvmlGpmMigSampleGet")
  5517. ret = fn(device, gpuInstanceId, gpmSample)
  5518. _nvmlCheckReturn(ret)
  5519. return gpmSample
  5520. def nvmlGpmQueryDeviceSupport(device):
  5521. gpmSupport = c_nvmlGpmSupport_t()
  5522. gpmSupport.version = NVML_GPM_SUPPORT_VERSION
  5523. fn = _nvmlGetFunctionPointer("nvmlGpmQueryDeviceSupport")
  5524. ret = fn(device, byref(gpmSupport))
  5525. _nvmlCheckReturn(ret)
  5526. return gpmSupport
  5527. def nvmlGpmSetStreamingEnabled(device, state):
  5528. c_state = c_uint(state)
  5529. fn = _nvmlGetFunctionPointer("nvmlGpmSetStreamingEnabled")
  5530. ret = fn(device, c_state)
  5531. _nvmlCheckReturn(ret)
  5532. return NVML_SUCCESS
  5533. def nvmlGpmQueryIfStreamingEnabled(device):
  5534. c_state = c_uint()
  5535. fn = _nvmlGetFunctionPointer("nvmlGpmQueryIfStreamingEnabled")
  5536. ret = fn(device, byref(c_state))
  5537. _nvmlCheckReturn(ret)
  5538. return c_state.value
  5539. # Low Power Structure and Function
  5540. NVML_NVLINK_POWER_STATE_HIGH_SPEED = 0x0
  5541. NVML_NVLINK_POWER_STATE_LOW = 0x1
  5542. NVML_NVLINK_LOW_POWER_THRESHOLD_MIN = 0x1
  5543. NVML_NVLINK_LOW_POWER_THRESHOLD_MAX = 0x1FFF
  5544. NVML_NVLINK_LOW_POWER_THRESHOLD_RESET = 0xFFFFFFFF
  5545. NVML_NVLINK_LOW_POWER_THRESHOLD_DEFAULT = NVML_NVLINK_LOW_POWER_THRESHOLD_RESET
  5546. class c_nvmlNvLinkPowerThres_t(Structure):
  5547. _fields_ = [
  5548. ("lowPwrThreshold", c_uint),
  5549. ]
  5550. def nvmlDeviceSetNvLinkDeviceLowPowerThreshold(device, l1threshold):
  5551. c_info = c_nvmlNvLinkPowerThres_t()
  5552. c_info.lowPwrThreshold = l1threshold
  5553. fn = _nvmlGetFunctionPointer("nvmlDeviceSetNvLinkDeviceLowPowerThreshold")
  5554. ret = fn(device, byref(c_info))
  5555. _nvmlCheckReturn(ret)
  5556. return NVML_SUCCESS
  5557. NVML_GPU_FABRIC_UUID_LEN = 16
  5558. _nvmlGpuFabricState_t = c_uint
  5559. NVML_GPU_FABRIC_STATE_NOT_SUPPORTED = 0
  5560. NVML_GPU_FABRIC_STATE_NOT_STARTED = 1
  5561. NVML_GPU_FABRIC_STATE_IN_PROGRESS = 2
  5562. NVML_GPU_FABRIC_STATE_COMPLETED = 3
  5563. class c_nvmlGpuFabricInfo_t(_PrintableStructure):
  5564. _fields_ = [
  5565. ("clusterUuid", c_uint8 * NVML_DEVICE_UUID_BUFFER_SIZE),
  5566. ("status", _nvmlReturn_t),
  5567. ("cliqueId", c_uint32),
  5568. ("state", _nvmlGpuFabricState_t)
  5569. ]
  5570. NVML_GPU_FABRIC_HEALTH_MASK_DEGRADED_BW_NOT_SUPPORTED = 0
  5571. NVML_GPU_FABRIC_HEALTH_MASK_DEGRADED_BW_TRUE = 1
  5572. NVML_GPU_FABRIC_HEALTH_MASK_DEGRADED_BW_FALSE = 2
  5573. NVML_GPU_FABRIC_HEALTH_MASK_SHIFT_DEGRADED_BW = 0
  5574. NVML_GPU_FABRIC_HEALTH_MASK_WIDTH_DEGRADED_BW = 0x11
  5575. NVML_GPU_FABRIC_HEALTH_MASK_ROUTE_RECOVERY_NOT_SUPPORTED = 0
  5576. NVML_GPU_FABRIC_HEALTH_MASK_ROUTE_RECOVERY_TRUE = 1
  5577. NVML_GPU_FABRIC_HEALTH_MASK_ROUTE_RECOVERY_FALSE = 2
  5578. NVML_GPU_FABRIC_HEALTH_MASK_SHIFT_ROUTE_RECOVERY = 2
  5579. NVML_GPU_FABRIC_HEALTH_MASK_WIDTH_ROUTE_RECOVERY = 0x11
  5580. NVML_GPU_FABRIC_HEALTH_MASK_ROUTE_UNHEALTHY_NOT_SUPPORTED = 0
  5581. NVML_GPU_FABRIC_HEALTH_MASK_ROUTE_UNHEALTHY_TRUE = 1
  5582. NVML_GPU_FABRIC_HEALTH_MASK_ROUTE_UNHEALTHY_FALSE = 2
  5583. NVML_GPU_FABRIC_HEALTH_MASK_SHIFT_ROUTE_UNHEALTHY = 4
  5584. NVML_GPU_FABRIC_HEALTH_MASK_WIDTH_ROUTE_UNHEALTHY = 0x11
  5585. NVML_GPU_FABRIC_HEALTH_MASK_ACCESS_TIMEOUT_RECOVERY_NOT_SUPPORTED = 0
  5586. NVML_GPU_FABRIC_HEALTH_MASK_ACCESS_TIMEOUT_RECOVERY_TRUE = 1
  5587. NVML_GPU_FABRIC_HEALTH_MASK_ACCESS_TIMEOUT_RECOVERY_FALSE = 2
  5588. NVML_GPU_FABRIC_HEALTH_MASK_SHIFT_ACCESS_TIMEOUT_RECOVERY = 6
  5589. NVML_GPU_FABRIC_HEALTH_MASK_WIDTH_ACCESS_TIMEOUT_RECOVERY = 0x11
  5590. NVML_GPU_FABRIC_HEALTH_MASK_INCORRECT_CONFIGURATION_NOT_SUPPORTED = 0
  5591. NVML_GPU_FABRIC_HEALTH_MASK_INCORRECT_CONFIGURATION_NONE = 1
  5592. NVML_GPU_FABRIC_HEALTH_MASK_INCORRECT_CONFIGURATION_INCORRECT_SYSGUID = 2
  5593. NVML_GPU_FABRIC_HEALTH_MASK_INCORRECT_CONFIGURATION_INCORRECT_CHASSIS_SN = 3
  5594. NVML_GPU_FABRIC_HEALTH_MASK_INCORRECT_CONFIGURATION_NO_PARTITION = 4
  5595. NVML_GPU_FABRIC_HEALTH_MASK_INCORRECT_CONFIGURATION_INSUFFICIENT_NVLINKS = 5
  5596. NVML_GPU_FABRIC_HEALTH_MASK_SHIFT_INCORRECT_CONFIGURATION = 8
  5597. NVML_GPU_FABRIC_HEALTH_MASK_WIDTH_INCORRECT_CONFIGURATION = 0xf
  5598. NVML_GPU_FABRIC_HEALTH_SUMMARY_NOT_SUPPORTED = 0
  5599. NVML_GPU_FABRIC_HEALTH_SUMMARY_HEALTHY = 1
  5600. NVML_GPU_FABRIC_HEALTH_SUMMARY_UNHEALTHY = 2
  5601. NVML_GPU_FABRIC_HEALTH_SUMMARY_LIMITED_CAPACITY = 3
  5602. nvmlGpuFabricInfo_v2 = 0x02000024
  5603. class c_nvmlGpuFabricInfo_v2_t(_PrintableStructure):
  5604. _fields_ = [
  5605. ("version", c_uint),
  5606. ("clusterUuid", c_uint8 * NVML_GPU_FABRIC_UUID_LEN),
  5607. ("status", _nvmlReturn_t),
  5608. ("cliqueId", c_uint32),
  5609. ("state", _nvmlGpuFabricState_t),
  5610. ("healthMask", c_uint32)
  5611. ]
  5612. def __init__(self):
  5613. super(c_nvmlGpuFabricInfo_v2_t, self).__init__(version=nvmlGpuFabricInfo_v2)
  5614. c_nvmlGpuFabricInfoV_t = c_nvmlGpuFabricInfo_v2_t
  5615. class c_nvmlGpuFabricInfo_v3_t(_PrintableStructure):
  5616. _fields_ = [
  5617. ("version", c_uint),
  5618. ("clusterUuid", c_uint8 * NVML_GPU_FABRIC_UUID_LEN),
  5619. ("status", _nvmlReturn_t),
  5620. ("cliqueId", c_uint32),
  5621. ("state", _nvmlGpuFabricState_t),
  5622. ("healthMask", c_uint32),
  5623. ("healthSummary", c_uint8)
  5624. ]
  5625. def __init__(self):
  5626. super(c_nvmlGpuFabricInfo_v3_t, self).__init__(version=nvmlGpuFabricInfo_v3)
  5627. nvmlGpuFabricInfo_v3 = 0x3000028
  5628. # Deprecated
  5629. def nvmlDeviceGetGpuFabricInfo(device, gpuFabricInfo):
  5630. fn = _nvmlGetFunctionPointer("nvmlDeviceGetGpuFabricInfo");
  5631. ret = fn(device, gpuFabricInfo)
  5632. _nvmlCheckReturn(ret)
  5633. return NVML_SUCCESS
  5634. def nvmlDeviceGetGpuFabricInfoV(device, gpuFabricInfo):
  5635. fn = _nvmlGetFunctionPointer("nvmlDeviceGetGpuFabricInfoV");
  5636. ret = fn(device, gpuFabricInfo)
  5637. _nvmlCheckReturn(ret)
  5638. return NVML_SUCCESS
  5639. ######################
  5640. ## Enums/defines
  5641. #### NVML GPU NVLINK BW MODE
  5642. NVML_GPU_NVLINK_BW_MODE_FULL = 0x0
  5643. NVML_GPU_NVLINK_BW_MODE_OFF = 0x1
  5644. NVML_GPU_NVLINK_BW_MODE_MIN = 0x2
  5645. NVML_GPU_NVLINK_BW_MODE_HALF = 0x3
  5646. NVML_GPU_NVLINK_BW_MODE_3QUARTER = 0x4
  5647. NVML_GPU_NVLINK_BW_MODE_COUNT = 0x5
  5648. def nvmlSystemSetNvlinkBwMode(mode):
  5649. fn = _nvmlGetFunctionPointer("nvmlSystemSetNvlinkBwMode")
  5650. ret = fn(mode)
  5651. _nvmlCheckReturn(ret)
  5652. return NVML_SUCCESS
  5653. def nvmlSystemGetNvlinkBwMode():
  5654. mode = c_uint()
  5655. fn = _nvmlGetFunctionPointer("nvmlSystemGetNvlinkBwMode")
  5656. ret = fn(byref(mode))
  5657. _nvmlCheckReturn(ret)
  5658. return mode.value
  5659. _nvmlPowerScopeType_t = c_uint
  5660. NVML_POWER_SCOPE_GPU = 0
  5661. NVML_POWER_SCOPE_MODULE = 1
  5662. NVML_POWER_SCOPE_MEMORY = 2
  5663. class c_nvmlPowerValue_v2_t(_PrintableStructure):
  5664. _fields_ = [
  5665. ('version', c_uint),
  5666. ('powerScope', _nvmlPowerScopeType_t),
  5667. ('powerValueMw', c_uint),
  5668. ]
  5669. _fmt_ = {'<default>': "%d B"}
  5670. nvmlPowerValue_v2 = 0x0200000C
  5671. def nvmlDeviceSetPowerManagementLimit_v2(device, powerScope, powerLimit, version=nvmlPowerValue_v2):
  5672. c_powerScope = _nvmlPowerScopeType_t(powerScope)
  5673. c_powerValue = c_nvmlPowerValue_v2_t()
  5674. c_powerValue.version = c_uint(version)
  5675. c_powerValue.powerScope = c_powerScope
  5676. c_powerValue.powerValueMw = c_uint(powerLimit)
  5677. fn = _nvmlGetFunctionPointer("nvmlDeviceSetPowerManagementLimit_v2")
  5678. ret = fn(device, byref(c_powerValue))
  5679. return NVML_SUCCESS
  5680. class c_nvmlEccSramErrorStatus_v1_t(_PrintableStructure):
  5681. _fields_ = [
  5682. ('version', c_uint),
  5683. ('aggregateUncParity', c_ulonglong),
  5684. ('aggregateUncSecDed', c_ulonglong),
  5685. ('aggregateCor', c_ulonglong),
  5686. ('volatileUncParity', c_ulonglong),
  5687. ('volatileUncSecDed', c_ulonglong),
  5688. ('volatileCor', c_ulonglong),
  5689. ('aggregateUncBucketL2', c_ulonglong),
  5690. ('aggregateUncBucketSm', c_ulonglong),
  5691. ('aggregateUncBucketPcie', c_ulonglong),
  5692. ('aggregateUncBucketMcu', c_ulonglong),
  5693. ('aggregateUncBucketOther', c_ulonglong),
  5694. ('bThresholdExceeded', c_uint)
  5695. ]
  5696. def __init__(self):
  5697. super(c_nvmlEccSramErrorStatus_v1_t, self).__init__(version=nvmlEccSramErrorStatus_v1)
  5698. nvmlEccSramErrorStatus_v1 = 0x1000068
  5699. def nvmlDeviceGetSramEccErrorStatus(device, status):
  5700. fn = _nvmlGetFunctionPointer("nvmlDeviceGetSramEccErrorStatus")
  5701. ret = fn(device, status)
  5702. _nvmlCheckReturn(ret)
  5703. return NVML_SUCCESS
  5704. NVML_DEV_CAP_EGM = (1 << 0)
  5705. nvmlDeviceCapabilities_v1 = 0x1000008
  5706. class c_nvmlDeviceCapabilities_v1_t(_PrintableStructure):
  5707. _fields_ = [
  5708. ('version', c_uint),
  5709. ('capMask', c_uint),
  5710. ]
  5711. def __init__(self):
  5712. super(c_nvmlDeviceCapabilities_v1_t, self).__init__(version=nvmlDeviceCapabilities_v1)
  5713. def nvmlDeviceGetCapabilities(device, caps):
  5714. fn = _nvmlGetFunctionPointer("nvmlDeviceGetCapabilities")
  5715. return fn(device, caps)
  5716. class c_nvmlPlatformInfo_v1_t(_PrintableStructure):
  5717. _fields_ = [
  5718. ('version', c_uint),
  5719. ('ibGuid', c_char * 16),
  5720. ('rackGuid', c_char * 16),
  5721. ('chassisPhysicalSlotNumber', c_char),
  5722. ('computeSlotIndex', c_char),
  5723. ('nodeIndex', c_char),
  5724. ('peerType', c_char),
  5725. ('moduleId', c_char)
  5726. ]
  5727. def __init__(self):
  5728. super(c_nvmlPlatformInfo_v1_t, self).__init__(version=nvmlPlatformInfo_v1)
  5729. class c_nvmlPlatformInfo_v2_t(_PrintableStructure):
  5730. _fields_ = [
  5731. ('version', c_uint),
  5732. ('ibGuid', c_char * 16),
  5733. ('chassisSerialNumber', c_char * 16),
  5734. ('slotNumber', c_char),
  5735. ('trayIndex', c_char),
  5736. ('hostId', c_char),
  5737. ('peerType', c_char),
  5738. ('moduleId', c_char)
  5739. ]
  5740. def __init__(self):
  5741. super(c_nvmlPlatformInfo_v2_t, self).__init__(version=nvmlPlatformInfo_v2)
  5742. nvmlPlatformInfo_v1 = 0x100002c
  5743. nvmlPlatformInfo_v2 = 0x200002c
  5744. def nvmlDeviceGetPlatformInfo(device, platformInfo):
  5745. fn = _nvmlGetFunctionPointer("nvmlDeviceGetPlatformInfo")
  5746. ret = fn(device, platformInfo)
  5747. _nvmlCheckReturn(ret)
  5748. return NVML_SUCCESS
  5749. class c_nvmlMask255_t(_PrintableStructure):
  5750. _fields_ = [
  5751. ('mask', c_uint * 8),
  5752. ]
  5753. NVML_WORKLOAD_POWER_MAX_PROFILES = 255
  5754. NVML_POWER_PROFILE_MAX_P = 0
  5755. NVML_POWER_PROFILE_MAX_Q = 1
  5756. NVML_POWER_PROFILE_COMPUTE = 2
  5757. NVML_POWER_PROFILE_MEMORY_BOUND = 3
  5758. NVML_POWER_PROFILE_NETWORK = 4
  5759. NVML_POWER_PROFILE_BALANCED = 5
  5760. NVML_POWER_PROFILE_LLM_INFERENCE = 6
  5761. NVML_POWER_PROFILE_LLM_TRAINING = 7
  5762. NVML_POWER_PROFILE_RBM = 8
  5763. NVML_POWER_PROFILE_DCPCIE = 9
  5764. NVML_POWER_PROFILE_HMMA_SPARSE = 10
  5765. NVML_POWER_PROFILE_HMMA_DENSE = 11
  5766. NVML_POWER_PROFILE_SYNC_BALANCED = 12
  5767. NVML_POWER_PROFILE_HPC = 13
  5768. NVML_POWER_PROFILE_MIG = 14
  5769. NVML_POWER_PROFILE_MAX = 15
  5770. nvmlWorkloadPowerProfileInfo_v1 = 0x100002c
  5771. class c_nvmlWorkloadPowerProfileInfo_v1_t(_PrintableStructure):
  5772. _fields_ = [
  5773. ('version', c_uint),
  5774. ('profileId', c_uint),
  5775. ('priority', c_uint),
  5776. ('conflictingmask', c_nvmlMask255_t)
  5777. ]
  5778. def __init__(self):
  5779. super(c_nvmlWorkloadPowerProfileInfo_v1_t, self).__init__(version=nvmlWorkloadPowerProfileInfo_v1)
  5780. nvmlWorkloadPowerProfileProfilesInfo_v1 = 0x1002bf8
  5781. class c_nvmlWorkloadPowerProfileProfilesInfo_v1_t(_PrintableStructure):
  5782. _fields_ = [
  5783. ('version', c_uint),
  5784. ('perfProfilesMask', c_nvmlMask255_t),
  5785. ('perfProfile', c_nvmlWorkloadPowerProfileInfo_v1_t * NVML_WORKLOAD_POWER_MAX_PROFILES)
  5786. ]
  5787. def __init__(self):
  5788. super(c_nvmlWorkloadPowerProfileProfilesInfo_v1_t, self).__init__(version=nvmlWorkloadPowerProfileProfilesInfo_v1)
  5789. nvmlWorkloadPowerProfileCurrentProfiles_v1 = 0x1000064
  5790. class c_nvmlWorkloadPowerProfileCurrentProfiles_v1_t(_PrintableStructure):
  5791. _fields_ = [
  5792. ('version', c_uint),
  5793. ('perfProfilesMask', c_nvmlMask255_t),
  5794. ('requestedProfilesMask', c_nvmlMask255_t),
  5795. ('enforcedProfilesMask', c_nvmlMask255_t)
  5796. ]
  5797. def __init__(self):
  5798. super(c_nvmlWorkloadPowerProfileCurrentProfiles_v1_t, self).__init__(version=nvmlWorkloadPowerProfileCurrentProfiles_v1)
  5799. nvmlWorkloadPowerProfileRequestedProfiles_v1 = 0x1000024
  5800. class c_nvmlWorkloadPowerProfileRequestedProfiles_v1_t(_PrintableStructure):
  5801. _fields_ = [
  5802. ('version', c_uint),
  5803. ('requestedProfilesMask', c_nvmlMask255_t),
  5804. ]
  5805. def __init__(self):
  5806. super(c_nvmlWorkloadPowerProfileRequestedProfiles_v1_t, self).__init__(version=nvmlWorkloadPowerProfileRequestedProfiles_v1)
  5807. def nvmlDeviceWorkloadPowerProfileGetProfilesInfo(device, profilesInfo):
  5808. fn = _nvmlGetFunctionPointer("nvmlDeviceWorkloadPowerProfileGetProfilesInfo")
  5809. ret = fn(device, profilesInfo)
  5810. _nvmlCheckReturn(ret)
  5811. return NVML_SUCCESS
  5812. def nvmlDeviceWorkloadPowerProfileGetCurrentProfiles(device, currentProfiles):
  5813. fn = _nvmlGetFunctionPointer("nvmlDeviceWorkloadPowerProfileGetCurrentProfiles")
  5814. ret = fn(device, currentProfiles)
  5815. _nvmlCheckReturn(ret)
  5816. return NVML_SUCCESS
  5817. def nvmlDeviceWorkloadPowerProfileSetRequestedProfiles(device, requestedProfiles):
  5818. fn = _nvmlGetFunctionPointer("nvmlDeviceWorkloadPowerProfileSetRequestedProfiles")
  5819. ret = fn(device, requestedProfiles)
  5820. _nvmlCheckReturn(ret)
  5821. return NVML_SUCCESS
  5822. def nvmlDeviceWorkloadPowerProfileClearRequestedProfiles(device, requestedProfiles):
  5823. fn = _nvmlGetFunctionPointer("nvmlDeviceWorkloadPowerProfileClearRequestedProfiles")
  5824. ret = fn(device, requestedProfiles)
  5825. _nvmlCheckReturn(ret)
  5826. return NVML_SUCCESS
  5827. def nvmlDeviceGetNvlinkSupportedBwModes(device, supportedBwModes):
  5828. fn = _nvmlGetFunctionPointer("nvmlDeviceGetNvlinkSupportedBwModes")
  5829. ret = fn(device, supportedBwModes)
  5830. _nvmlCheckReturn(ret)
  5831. return NVML_SUCCESS
  5832. def nvmlDeviceGetNvlinkBwMode(device, getBwMode):
  5833. fn = _nvmlGetFunctionPointer("nvmlDeviceGetNvlinkBwMode")
  5834. ret = fn(device, getBwMode)
  5835. _nvmlCheckReturn(ret)
  5836. return NVML_SUCCESS
  5837. def nvmlDeviceSetNvlinkBwMode(device, setBwMode):
  5838. fn = _nvmlGetFunctionPointer("nvmlDeviceSetNvlinkBwMode")
  5839. ret = fn(device, setBwMode)
  5840. _nvmlCheckReturn(ret)
  5841. return NVML_SUCCESS
  5842. nvmlDramEncryptionInfo_v1 = 0x01000008
  5843. class c_nvmlDramEncryptionInfo_t(_PrintableStructure):
  5844. _fields_ = [
  5845. ('version', c_uint),
  5846. ('encryptionState', _nvmlEnableState_t),
  5847. ]
  5848. def __init__(self):
  5849. super(c_nvmlDramEncryptionInfo_t, self).__init__(version=nvmlDramEncryptionInfo_v1)
  5850. def nvmlDeviceGetDramEncryptionMode(handle):
  5851. c_currState = c_nvmlDramEncryptionInfo_t()
  5852. c_pendingState = c_nvmlDramEncryptionInfo_t()
  5853. fn = _nvmlGetFunctionPointer("nvmlDeviceGetDramEncryptionMode")
  5854. ret = fn(handle, byref(c_currState), byref(c_pendingState))
  5855. _nvmlCheckReturn(ret)
  5856. return [c_currState.encryptionState, c_pendingState.encryptionState]
  5857. # added to API
  5858. def nvmlDeviceGetCurrentDramEncryptionMode(handle):
  5859. return nvmlDeviceGetDramEncryptionMode(handle)[0]
  5860. # added to API
  5861. def nvmlDeviceGetPendingDramEncryptionMode(handle):
  5862. return nvmlDeviceGetDramEncryptionMode(handle)[1]
  5863. def nvmlDeviceSetDramEncryptionMode(handle, mode):
  5864. fn = _nvmlGetFunctionPointer("nvmlDeviceSetDramEncryptionMode")
  5865. c_dramEncryptionMode = c_nvmlDramEncryptionInfo_t()
  5866. c_dramEncryptionMode.encryptionState = mode;
  5867. ret = fn(handle, byref(c_dramEncryptionMode))
  5868. _nvmlCheckReturn(ret)
  5869. return None
  5870. # Power Smoothing defines
  5871. NVML_POWER_SMOOTHING_MAX_NUM_PROFILES = 5
  5872. NVML_POWER_SMOOTHING_ADMIN_OVERRIDE_NOT_SET = 0xFFFFFFFF
  5873. NVML_POWER_SMOOTHING_PROFILE_PARAM_PERCENT_TMP_FLOOR = 0
  5874. NVML_POWER_SMOOTHING_PROFILE_PARAM_RAMP_UP_RATE = 1
  5875. NVML_POWER_SMOOTHING_PROFILE_PARAM_RAMP_DOWN_RATE = 2
  5876. NVML_POWER_SMOOTHING_PROFILE_PARAM_RAMP_DOWN_HYSTERESIS = 3
  5877. nvmlPowerSmoothingState_v1=0x1000008
  5878. class c_nvmlPowerSmoothingState_v1_t(_PrintableStructure):
  5879. _fields_ = [
  5880. ('version', c_uint),
  5881. ('state', c_uint),
  5882. ]
  5883. def __init__(self):
  5884. super(c_nvmlPowerSmoothingState_v1_t, self).__init__(version=nvmlPowerSmoothingState_v1)
  5885. nvmlPowerSmoothingProfile_v1=0x1000018
  5886. class c_nvmlPowerSmoothingProfile_v1_t(_PrintableStructure):
  5887. _fields_ = [
  5888. ('version', c_uint),
  5889. ('profileId', c_uint),
  5890. ('paramId', c_uint),
  5891. ('value', c_double),
  5892. ]
  5893. def __init__(self):
  5894. super(c_nvmlPowerSmoothingProfile_v1_t, self).__init__(version=nvmlPowerSmoothingProfile_v1)
  5895. def nvmlDevicePowerSmoothingActivatePresetProfile(device, profile):
  5896. fn = _nvmlGetFunctionPointer("nvmlDevicePowerSmoothingActivatePresetProfile")
  5897. ret = fn(device, profile)
  5898. _nvmlCheckReturn(ret)
  5899. def nvmlDevicePowerSmoothingUpdatePresetProfileParam(device, profile):
  5900. fn = _nvmlGetFunctionPointer("nvmlDevicePowerSmoothingUpdatePresetProfileParam")
  5901. ret = fn(device, profile)
  5902. _nvmlCheckReturn(ret)
  5903. def nvmlDevicePowerSmoothingSetState(device, state):
  5904. fn = _nvmlGetFunctionPointer("nvmlDevicePowerSmoothingSetState")
  5905. ret = fn(device, state)
  5906. _nvmlCheckReturn(ret)
  5907. class c_nvmlEccSramUniqueUncorrectedErrorEntry_v1_t(_PrintableStructure):
  5908. _fields_ = [
  5909. ('unit', c_uint),
  5910. ('location', c_uint),
  5911. ('sublocation', c_uint),
  5912. ('extlocation', c_uint),
  5913. ('address', c_uint),
  5914. ('isParity', c_uint),
  5915. ('count', c_uint)
  5916. ]
  5917. class c_nvmlEccSramUniqueUncorrectedErrorCounts_v1_t(_PrintableStructure):
  5918. _fields_ = [
  5919. ('version', c_uint),
  5920. ('entryCount', c_uint),
  5921. ('entries', POINTER(c_nvmlEccSramUniqueUncorrectedErrorEntry_v1_t))
  5922. ]
  5923. def __init__(self):
  5924. super(c_nvmlEccSramUniqueUncorrectedErrorCounts_v1_t, self).__init__(version=nvmlEccSramUniqueUncorrectedErrorCounts_v1)
  5925. nvmlEccSramUniqueUncorrectedErrorCounts_v1 = 0x1000010
  5926. def nvmlDeviceGetSramUniqueUncorrectedEccErrorCounts(device, counts):
  5927. fn = _nvmlGetFunctionPointer("nvmlDeviceGetSramUniqueUncorrectedEccErrorCounts")
  5928. ret = fn(device, counts)
  5929. _nvmlCheckReturn(ret)
  5930. return NVML_SUCCESS
  5931. def nvmlDeviceGetPdi(device):
  5932. c_pdi = c_nvmlPdi_t()
  5933. fn = _nvmlGetFunctionPointer("nvmlDeviceGetPdi")
  5934. ret = fn(device, byref(c_pdi))
  5935. _nvmlCheckReturn(ret)
  5936. return c_pdi.value
  5937. def nvmlDeviceGetNvLinkInfo(device, info):
  5938. fn = _nvmlGetFunctionPointer("nvmlDeviceGetNvLinkInfo");
  5939. ret = fn(device, info)
  5940. _nvmlCheckReturn(ret)
  5941. return NVML_SUCCESS
  5942. def nvmlDeviceGetRepairStatus(device):
  5943. c_status = c_nvmlRepairStatus_t()
  5944. fn = _nvmlGetFunctionPointer("nvmlDeviceGetRepairStatus")
  5945. ret = fn(device, byref(c_status))
  5946. _nvmlCheckReturn(ret)
  5947. return [c_status.bChannelRepairPending, c_status.bTpcRepairPending]