AMDGPUUsage.rst 443 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504
  1. =============================
  2. User Guide for AMDGPU Backend
  3. =============================
  4. .. contents::
  5. :local:
  6. Introduction
  7. ============
  8. The AMDGPU backend provides ISA code generation for AMD GPUs, starting with the
  9. R600 family up until the current GCN families. It lives in the
  10. ``lib/Target/AMDGPU`` directory.
  11. LLVM
  12. ====
  13. .. _amdgpu-target-triples:
  14. Target Triples
  15. --------------
  16. Use the ``clang -target <Architecture>-<Vendor>-<OS>-<Environment>`` option to
  17. specify the target triple:
  18. .. table:: AMDGPU Architectures
  19. :name: amdgpu-architecture-table
  20. ============ ==============================================================
  21. Architecture Description
  22. ============ ==============================================================
  23. ``r600`` AMD GPUs HD2XXX-HD6XXX for graphics and compute shaders.
  24. ``amdgcn`` AMD GPUs GCN GFX6 onwards for graphics and compute shaders.
  25. ============ ==============================================================
  26. .. table:: AMDGPU Vendors
  27. :name: amdgpu-vendor-table
  28. ============ ==============================================================
  29. Vendor Description
  30. ============ ==============================================================
  31. ``amd`` Can be used for all AMD GPU usage.
  32. ``mesa3d`` Can be used if the OS is ``mesa3d``.
  33. ============ ==============================================================
  34. .. table:: AMDGPU Operating Systems
  35. :name: amdgpu-os-table
  36. ============== ============================================================
  37. OS Description
  38. ============== ============================================================
  39. *<empty>* Defaults to the *unknown* OS.
  40. ``amdhsa`` Compute kernels executed on HSA [HSA]_ compatible runtimes
  41. such as AMD's ROCm [AMD-ROCm]_.
  42. ``amdpal`` Graphic shaders and compute kernels executed on AMD PAL
  43. runtime.
  44. ``mesa3d`` Graphic shaders and compute kernels executed on Mesa 3D
  45. runtime.
  46. ============== ============================================================
  47. .. table:: AMDGPU Environments
  48. :name: amdgpu-environment-table
  49. ============ ==============================================================
  50. Environment Description
  51. ============ ==============================================================
  52. *<empty>* Default.
  53. ============ ==============================================================
  54. .. _amdgpu-processors:
  55. Processors
  56. ----------
  57. Use the ``clang -mcpu <Processor>`` option to specify the AMD GPU processor. The
  58. names from both the *Processor* and *Alternative Processor* can be used.
  59. .. table:: AMDGPU Processors
  60. :name: amdgpu-processor-table
  61. =========== =============== ============ ===== ================= ======= ======================
  62. Processor Alternative Target dGPU/ Target ROCm Example
  63. Processor Triple APU Features Support Products
  64. Architecture Supported
  65. [Default]
  66. =========== =============== ============ ===== ================= ======= ======================
  67. **Radeon HD 2000/3000 Series (R600)** [AMD-RADEON-HD-2000-3000]_
  68. -----------------------------------------------------------------------------------------------
  69. ``r600`` ``r600`` dGPU
  70. ``r630`` ``r600`` dGPU
  71. ``rs880`` ``r600`` dGPU
  72. ``rv670`` ``r600`` dGPU
  73. **Radeon HD 4000 Series (R700)** [AMD-RADEON-HD-4000]_
  74. -----------------------------------------------------------------------------------------------
  75. ``rv710`` ``r600`` dGPU
  76. ``rv730`` ``r600`` dGPU
  77. ``rv770`` ``r600`` dGPU
  78. **Radeon HD 5000 Series (Evergreen)** [AMD-RADEON-HD-5000]_
  79. -----------------------------------------------------------------------------------------------
  80. ``cedar`` ``r600`` dGPU
  81. ``cypress`` ``r600`` dGPU
  82. ``juniper`` ``r600`` dGPU
  83. ``redwood`` ``r600`` dGPU
  84. ``sumo`` ``r600`` dGPU
  85. **Radeon HD 6000 Series (Northern Islands)** [AMD-RADEON-HD-6000]_
  86. -----------------------------------------------------------------------------------------------
  87. ``barts`` ``r600`` dGPU
  88. ``caicos`` ``r600`` dGPU
  89. ``cayman`` ``r600`` dGPU
  90. ``turks`` ``r600`` dGPU
  91. **GCN GFX6 (Southern Islands (SI))** [AMD-GCN-GFX6]_
  92. -----------------------------------------------------------------------------------------------
  93. ``gfx600`` - ``tahiti`` ``amdgcn`` dGPU
  94. ``gfx601`` - ``hainan`` ``amdgcn`` dGPU
  95. - ``oland``
  96. - ``pitcairn``
  97. - ``verde``
  98. **GCN GFX7 (Sea Islands (CI))** [AMD-GCN-GFX7]_
  99. -----------------------------------------------------------------------------------------------
  100. ``gfx700`` - ``kaveri`` ``amdgcn`` APU - A6-7000
  101. - A6 Pro-7050B
  102. - A8-7100
  103. - A8 Pro-7150B
  104. - A10-7300
  105. - A10 Pro-7350B
  106. - FX-7500
  107. - A8-7200P
  108. - A10-7400P
  109. - FX-7600P
  110. ``gfx701`` - ``hawaii`` ``amdgcn`` dGPU ROCm - FirePro W8100
  111. - FirePro W9100
  112. - FirePro S9150
  113. - FirePro S9170
  114. ``gfx702`` ``amdgcn`` dGPU ROCm - Radeon R9 290
  115. - Radeon R9 290x
  116. - Radeon R390
  117. - Radeon R390x
  118. ``gfx703`` - ``kabini`` ``amdgcn`` APU - E1-2100
  119. - ``mullins`` - E1-2200
  120. - E1-2500
  121. - E2-3000
  122. - E2-3800
  123. - A4-5000
  124. - A4-5100
  125. - A6-5200
  126. - A4 Pro-3340B
  127. ``gfx704`` - ``bonaire`` ``amdgcn`` dGPU - Radeon HD 7790
  128. - Radeon HD 8770
  129. - R7 260
  130. - R7 260X
  131. **GCN GFX8 (Volcanic Islands (VI))** [AMD-GCN-GFX8]_
  132. -----------------------------------------------------------------------------------------------
  133. ``gfx801`` - ``carrizo`` ``amdgcn`` APU - xnack - A6-8500P
  134. [on] - Pro A6-8500B
  135. - A8-8600P
  136. - Pro A8-8600B
  137. - FX-8800P
  138. - Pro A12-8800B
  139. \ ``amdgcn`` APU - xnack ROCm - A10-8700P
  140. [on] - Pro A10-8700B
  141. - A10-8780P
  142. \ ``amdgcn`` APU - xnack - A10-9600P
  143. [on] - A10-9630P
  144. - A12-9700P
  145. - A12-9730P
  146. - FX-9800P
  147. - FX-9830P
  148. \ ``amdgcn`` APU - xnack - E2-9010
  149. [on] - A6-9210
  150. - A9-9410
  151. ``gfx802`` - ``iceland`` ``amdgcn`` dGPU - xnack ROCm - FirePro S7150
  152. - ``tonga`` [off] - FirePro S7100
  153. - FirePro W7100
  154. - Radeon R285
  155. - Radeon R9 380
  156. - Radeon R9 385
  157. - Mobile FirePro
  158. M7170
  159. ``gfx803`` - ``fiji`` ``amdgcn`` dGPU - xnack ROCm - Radeon R9 Nano
  160. [off] - Radeon R9 Fury
  161. - Radeon R9 FuryX
  162. - Radeon Pro Duo
  163. - FirePro S9300x2
  164. - Radeon Instinct MI8
  165. \ - ``polaris10`` ``amdgcn`` dGPU - xnack ROCm - Radeon RX 470
  166. [off] - Radeon RX 480
  167. - Radeon Instinct MI6
  168. \ - ``polaris11`` ``amdgcn`` dGPU - xnack ROCm - Radeon RX 460
  169. [off]
  170. ``gfx810`` - ``stoney`` ``amdgcn`` APU - xnack
  171. [on]
  172. **GCN GFX9** [AMD-GCN-GFX9]_
  173. -----------------------------------------------------------------------------------------------
  174. ``gfx900`` ``amdgcn`` dGPU - xnack ROCm - Radeon Vega
  175. [off] Frontier Edition
  176. - Radeon RX Vega 56
  177. - Radeon RX Vega 64
  178. - Radeon RX Vega 64
  179. Liquid
  180. - Radeon Instinct MI25
  181. ``gfx902`` ``amdgcn`` APU - xnack - Ryzen 3 2200G
  182. [on] - Ryzen 5 2400G
  183. ``gfx904`` ``amdgcn`` dGPU - xnack *TBA*
  184. [off]
  185. .. TODO
  186. Add product
  187. names.
  188. ``gfx906`` ``amdgcn`` dGPU - xnack - Radeon Instinct MI50
  189. [off] - Radeon Instinct MI60
  190. ``gfx908`` ``amdgcn`` dGPU - xnack *TBA*
  191. [off]
  192. sram-ecc
  193. [on]
  194. ``gfx909`` ``amdgcn`` APU - xnack *TBA* (Raven Ridge 2)
  195. [on]
  196. .. TODO
  197. Add product
  198. names.
  199. **GCN GFX10** [AMD-GCN-GFX10]_
  200. -----------------------------------------------------------------------------------------------
  201. ``gfx1010`` ``amdgcn`` dGPU - xnack *TBA*
  202. [off]
  203. - wavefrontsize64
  204. [off]
  205. - cumode
  206. [off]
  207. .. TODO
  208. Add product
  209. names.
  210. ``gfx1011`` ``amdgcn`` dGPU - xnack *TBA*
  211. [off]
  212. - wavefrontsize64
  213. [off]
  214. - cumode
  215. [off]
  216. .. TODO
  217. Add product
  218. names.
  219. ``gfx1012`` ``amdgcn`` dGPU - xnack *TBA*
  220. [off]
  221. - wavefrontsize64
  222. [off]
  223. - cumode
  224. [off]
  225. .. TODO
  226. Add product
  227. names.
  228. =========== =============== ============ ===== ================= ======= ======================
  229. .. _amdgpu-target-features:
  230. Target Features
  231. ---------------
  232. Target features control how code is generated to support certain
  233. processor specific features. Not all target features are supported by
  234. all processors. The runtime must ensure that the features supported by
  235. the device used to execute the code match the features enabled when
  236. generating the code. A mismatch of features may result in incorrect
  237. execution, or a reduction in performance.
  238. The target features supported by each processor, and the default value
  239. used if not specified explicitly, is listed in
  240. :ref:`amdgpu-processor-table`.
  241. Use the ``clang -m[no-]<TargetFeature>`` option to specify the AMD GPU
  242. target features.
  243. For example:
  244. ``-mxnack``
  245. Enable the ``xnack`` feature.
  246. ``-mno-xnack``
  247. Disable the ``xnack`` feature.
  248. .. table:: AMDGPU Target Features
  249. :name: amdgpu-target-feature-table
  250. ====================== ==================================================
  251. Target Feature Description
  252. ====================== ==================================================
  253. -m[no-]xnack Enable/disable generating code that has
  254. memory clauses that are compatible with
  255. having XNACK replay enabled.
  256. This is used for demand paging and page
  257. migration. If XNACK replay is enabled in
  258. the device, then if a page fault occurs
  259. the code may execute incorrectly if the
  260. ``xnack`` feature is not enabled. Executing
  261. code that has the feature enabled on a
  262. device that does not have XNACK replay
  263. enabled will execute correctly, but may
  264. be less performant than code with the
  265. feature disabled.
  266. -m[no-]sram-ecc Enable/disable generating code that assumes SRAM
  267. ECC is enabled/disabled.
  268. -m[no-]wavefrontsize64 Control the default wavefront size used when
  269. generating code for kernels. When disabled
  270. native wavefront size 32 is used, when enabled
  271. wavefront size 64 is used.
  272. -m[no-]cumode Control the default wavefront execution mode used
  273. when generating code for kernels. When disabled
  274. native WGP wavefront execution mode is used,
  275. when enabled CU wavefront execution mode is used
  276. (see :ref:`amdgpu-amdhsa-memory-model`).
  277. ====================== ==================================================
  278. .. _amdgpu-address-spaces:
  279. Address Spaces
  280. --------------
  281. The AMDGPU backend uses the following address space mappings.
  282. The memory space names used in the table, aside from the region memory space, is
  283. from the OpenCL standard.
  284. LLVM Address Space number is used throughout LLVM (for example, in LLVM IR).
  285. .. table:: Address Space Mapping
  286. :name: amdgpu-address-space-mapping-table
  287. ================== =================================
  288. LLVM Address Space Memory Space
  289. ================== =================================
  290. 0 Generic (Flat)
  291. 1 Global
  292. 2 Region (GDS)
  293. 3 Local (group/LDS)
  294. 4 Constant
  295. 5 Private (Scratch)
  296. 6 Constant 32-bit
  297. 7 Buffer Fat Pointer (experimental)
  298. ================== =================================
  299. The buffer fat pointer is an experimental address space that is currently
  300. unsupported in the backend. It exposes a non-integral pointer that is in future
  301. intended to support the modelling of 128-bit buffer descriptors + a 32-bit
  302. offset into the buffer descriptor (in total encapsulating a 160-bit 'pointer'),
  303. allowing us to use normal LLVM load/store/atomic operations to model the buffer
  304. descriptors used heavily in graphics workloads targeting the backend.
  305. .. _amdgpu-memory-scopes:
  306. Memory Scopes
  307. -------------
  308. This section provides LLVM memory synchronization scopes supported by the AMDGPU
  309. backend memory model when the target triple OS is ``amdhsa`` (see
  310. :ref:`amdgpu-amdhsa-memory-model` and :ref:`amdgpu-target-triples`).
  311. The memory model supported is based on the HSA memory model [HSA]_ which is
  312. based in turn on HRF-indirect with scope inclusion [HRF]_. The happens-before
  313. relation is transitive over the synchonizes-with relation independent of scope,
  314. and synchonizes-with allows the memory scope instances to be inclusive (see
  315. table :ref:`amdgpu-amdhsa-llvm-sync-scopes-table`).
  316. This is different to the OpenCL [OpenCL]_ memory model which does not have scope
  317. inclusion and requires the memory scopes to exactly match. However, this
  318. is conservatively correct for OpenCL.
  319. .. table:: AMDHSA LLVM Sync Scopes
  320. :name: amdgpu-amdhsa-llvm-sync-scopes-table
  321. ======================= ===================================================
  322. LLVM Sync Scope Description
  323. ======================= ===================================================
  324. *none* The default: ``system``.
  325. Synchronizes with, and participates in modification
  326. and seq_cst total orderings with, other operations
  327. (except image operations) for all address spaces
  328. (except private, or generic that accesses private)
  329. provided the other operation's sync scope is:
  330. - ``system``.
  331. - ``agent`` and executed by a thread on the same
  332. agent.
  333. - ``workgroup`` and executed by a thread in the
  334. same workgroup.
  335. - ``wavefront`` and executed by a thread in the
  336. same wavefront.
  337. ``agent`` Synchronizes with, and participates in modification
  338. and seq_cst total orderings with, other operations
  339. (except image operations) for all address spaces
  340. (except private, or generic that accesses private)
  341. provided the other operation's sync scope is:
  342. - ``system`` or ``agent`` and executed by a thread
  343. on the same agent.
  344. - ``workgroup`` and executed by a thread in the
  345. same workgroup.
  346. - ``wavefront`` and executed by a thread in the
  347. same wavefront.
  348. ``workgroup`` Synchronizes with, and participates in modification
  349. and seq_cst total orderings with, other operations
  350. (except image operations) for all address spaces
  351. (except private, or generic that accesses private)
  352. provided the other operation's sync scope is:
  353. - ``system``, ``agent`` or ``workgroup`` and
  354. executed by a thread in the same workgroup.
  355. - ``wavefront`` and executed by a thread in the
  356. same wavefront.
  357. ``wavefront`` Synchronizes with, and participates in modification
  358. and seq_cst total orderings with, other operations
  359. (except image operations) for all address spaces
  360. (except private, or generic that accesses private)
  361. provided the other operation's sync scope is:
  362. - ``system``, ``agent``, ``workgroup`` or
  363. ``wavefront`` and executed by a thread in the
  364. same wavefront.
  365. ``singlethread`` Only synchronizes with, and participates in
  366. modification and seq_cst total orderings with,
  367. other operations (except image operations) running
  368. in the same thread for all address spaces (for
  369. example, in signal handlers).
  370. ``one-as`` Same as ``system`` but only synchronizes with other
  371. operations within the same address space.
  372. ``agent-one-as`` Same as ``agent`` but only synchronizes with other
  373. operations within the same address space.
  374. ``workgroup-one-as`` Same as ``workgroup`` but only synchronizes with
  375. other operations within the same address space.
  376. ``wavefront-one-as`` Same as ``wavefront`` but only synchronizes with
  377. other operations within the same address space.
  378. ``singlethread-one-as`` Same as ``singlethread`` but only synchronizes with
  379. other operations within the same address space.
  380. ======================= ===================================================
  381. AMDGPU Intrinsics
  382. -----------------
  383. The AMDGPU backend implements the following LLVM IR intrinsics.
  384. *This section is WIP.*
  385. .. TODO
  386. List AMDGPU intrinsics
  387. AMDGPU Attributes
  388. -----------------
  389. The AMDGPU backend supports the following LLVM IR attributes.
  390. .. table:: AMDGPU LLVM IR Attributes
  391. :name: amdgpu-llvm-ir-attributes-table
  392. ======================================= ==========================================================
  393. LLVM Attribute Description
  394. ======================================= ==========================================================
  395. "amdgpu-flat-work-group-size"="min,max" Specify the minimum and maximum flat work group sizes that
  396. will be specified when the kernel is dispatched. Generated
  397. by the ``amdgpu_flat_work_group_size`` CLANG attribute [CLANG-ATTR]_.
  398. "amdgpu-implicitarg-num-bytes"="n" Number of kernel argument bytes to add to the kernel
  399. argument block size for the implicit arguments. This
  400. varies by OS and language (for OpenCL see
  401. :ref:`opencl-kernel-implicit-arguments-appended-for-amdhsa-os-table`).
  402. "amdgpu-num-sgpr"="n" Specifies the number of SGPRs to use. Generated by
  403. the ``amdgpu_num_sgpr`` CLANG attribute [CLANG-ATTR]_.
  404. "amdgpu-num-vgpr"="n" Specifies the number of VGPRs to use. Generated by the
  405. ``amdgpu_num_vgpr`` CLANG attribute [CLANG-ATTR]_.
  406. "amdgpu-waves-per-eu"="m,n" Specify the minimum and maximum number of waves per
  407. execution unit. Generated by the ``amdgpu_waves_per_eu``
  408. CLANG attribute [CLANG-ATTR]_.
  409. "amdgpu-ieee" true/false. Specify whether the function expects the IEEE field of the
  410. mode register to be set on entry. Overrides the default for
  411. the calling convention.
  412. "amdgpu-dx10-clamp" true/false. Specify whether the function expects the DX10_CLAMP field of
  413. the mode register to be set on entry. Overrides the default
  414. for the calling convention.
  415. ======================================= ==========================================================
  416. Code Object
  417. ===========
  418. The AMDGPU backend generates a standard ELF [ELF]_ relocatable code object that
  419. can be linked by ``lld`` to produce a standard ELF shared code object which can
  420. be loaded and executed on an AMDGPU target.
  421. Header
  422. ------
  423. The AMDGPU backend uses the following ELF header:
  424. .. table:: AMDGPU ELF Header
  425. :name: amdgpu-elf-header-table
  426. ========================== ===============================
  427. Field Value
  428. ========================== ===============================
  429. ``e_ident[EI_CLASS]`` ``ELFCLASS64``
  430. ``e_ident[EI_DATA]`` ``ELFDATA2LSB``
  431. ``e_ident[EI_OSABI]`` - ``ELFOSABI_NONE``
  432. - ``ELFOSABI_AMDGPU_HSA``
  433. - ``ELFOSABI_AMDGPU_PAL``
  434. - ``ELFOSABI_AMDGPU_MESA3D``
  435. ``e_ident[EI_ABIVERSION]`` - ``ELFABIVERSION_AMDGPU_HSA``
  436. - ``ELFABIVERSION_AMDGPU_PAL``
  437. - ``ELFABIVERSION_AMDGPU_MESA3D``
  438. ``e_type`` - ``ET_REL``
  439. - ``ET_DYN``
  440. ``e_machine`` ``EM_AMDGPU``
  441. ``e_entry`` 0
  442. ``e_flags`` See :ref:`amdgpu-elf-header-e_flags-table`
  443. ========================== ===============================
  444. ..
  445. .. table:: AMDGPU ELF Header Enumeration Values
  446. :name: amdgpu-elf-header-enumeration-values-table
  447. =============================== =====
  448. Name Value
  449. =============================== =====
  450. ``EM_AMDGPU`` 224
  451. ``ELFOSABI_NONE`` 0
  452. ``ELFOSABI_AMDGPU_HSA`` 64
  453. ``ELFOSABI_AMDGPU_PAL`` 65
  454. ``ELFOSABI_AMDGPU_MESA3D`` 66
  455. ``ELFABIVERSION_AMDGPU_HSA`` 1
  456. ``ELFABIVERSION_AMDGPU_PAL`` 0
  457. ``ELFABIVERSION_AMDGPU_MESA3D`` 0
  458. =============================== =====
  459. ``e_ident[EI_CLASS]``
  460. The ELF class is:
  461. * ``ELFCLASS32`` for ``r600`` architecture.
  462. * ``ELFCLASS64`` for ``amdgcn`` architecture which only supports 64
  463. bit applications.
  464. ``e_ident[EI_DATA]``
  465. All AMDGPU targets use ``ELFDATA2LSB`` for little-endian byte ordering.
  466. ``e_ident[EI_OSABI]``
  467. One of the following AMD GPU architecture specific OS ABIs
  468. (see :ref:`amdgpu-os-table`):
  469. * ``ELFOSABI_NONE`` for *unknown* OS.
  470. * ``ELFOSABI_AMDGPU_HSA`` for ``amdhsa`` OS.
  471. * ``ELFOSABI_AMDGPU_PAL`` for ``amdpal`` OS.
  472. * ``ELFOSABI_AMDGPU_MESA3D`` for ``mesa3D`` OS.
  473. ``e_ident[EI_ABIVERSION]``
  474. The ABI version of the AMD GPU architecture specific OS ABI to which the code
  475. object conforms:
  476. * ``ELFABIVERSION_AMDGPU_HSA`` is used to specify the version of AMD HSA
  477. runtime ABI.
  478. * ``ELFABIVERSION_AMDGPU_PAL`` is used to specify the version of AMD PAL
  479. runtime ABI.
  480. * ``ELFABIVERSION_AMDGPU_MESA3D`` is used to specify the version of AMD MESA
  481. 3D runtime ABI.
  482. ``e_type``
  483. Can be one of the following values:
  484. ``ET_REL``
  485. The type produced by the AMD GPU backend compiler as it is relocatable code
  486. object.
  487. ``ET_DYN``
  488. The type produced by the linker as it is a shared code object.
  489. The AMD HSA runtime loader requires a ``ET_DYN`` code object.
  490. ``e_machine``
  491. The value ``EM_AMDGPU`` is used for the machine for all processors supported
  492. by the ``r600`` and ``amdgcn`` architectures (see
  493. :ref:`amdgpu-processor-table`). The specific processor is specified in the
  494. ``EF_AMDGPU_MACH`` bit field of the ``e_flags`` (see
  495. :ref:`amdgpu-elf-header-e_flags-table`).
  496. ``e_entry``
  497. The entry point is 0 as the entry points for individual kernels must be
  498. selected in order to invoke them through AQL packets.
  499. ``e_flags``
  500. The AMDGPU backend uses the following ELF header flags:
  501. .. table:: AMDGPU ELF Header ``e_flags``
  502. :name: amdgpu-elf-header-e_flags-table
  503. ================================= ========== =============================
  504. Name Value Description
  505. ================================= ========== =============================
  506. **AMDGPU Processor Flag** See :ref:`amdgpu-processor-table`.
  507. -------------------------------------------- -----------------------------
  508. ``EF_AMDGPU_MACH`` 0x000000ff AMDGPU processor selection
  509. mask for
  510. ``EF_AMDGPU_MACH_xxx`` values
  511. defined in
  512. :ref:`amdgpu-ef-amdgpu-mach-table`.
  513. ``EF_AMDGPU_XNACK`` 0x00000100 Indicates if the ``xnack``
  514. target feature is
  515. enabled for all code
  516. contained in the code object.
  517. If the processor
  518. does not support the
  519. ``xnack`` target
  520. feature then must
  521. be 0.
  522. See
  523. :ref:`amdgpu-target-features`.
  524. ``EF_AMDGPU_SRAM_ECC`` 0x00000200 Indicates if the ``sram-ecc``
  525. target feature is
  526. enabled for all code
  527. contained in the code object.
  528. If the processor
  529. does not support the
  530. ``sram-ecc`` target
  531. feature then must
  532. be 0.
  533. See
  534. :ref:`amdgpu-target-features`.
  535. ================================= ========== =============================
  536. .. table:: AMDGPU ``EF_AMDGPU_MACH`` Values
  537. :name: amdgpu-ef-amdgpu-mach-table
  538. ================================= ========== =============================
  539. Name Value Description (see
  540. :ref:`amdgpu-processor-table`)
  541. ================================= ========== =============================
  542. ``EF_AMDGPU_MACH_NONE`` 0x000 *not specified*
  543. ``EF_AMDGPU_MACH_R600_R600`` 0x001 ``r600``
  544. ``EF_AMDGPU_MACH_R600_R630`` 0x002 ``r630``
  545. ``EF_AMDGPU_MACH_R600_RS880`` 0x003 ``rs880``
  546. ``EF_AMDGPU_MACH_R600_RV670`` 0x004 ``rv670``
  547. ``EF_AMDGPU_MACH_R600_RV710`` 0x005 ``rv710``
  548. ``EF_AMDGPU_MACH_R600_RV730`` 0x006 ``rv730``
  549. ``EF_AMDGPU_MACH_R600_RV770`` 0x007 ``rv770``
  550. ``EF_AMDGPU_MACH_R600_CEDAR`` 0x008 ``cedar``
  551. ``EF_AMDGPU_MACH_R600_CYPRESS`` 0x009 ``cypress``
  552. ``EF_AMDGPU_MACH_R600_JUNIPER`` 0x00a ``juniper``
  553. ``EF_AMDGPU_MACH_R600_REDWOOD`` 0x00b ``redwood``
  554. ``EF_AMDGPU_MACH_R600_SUMO`` 0x00c ``sumo``
  555. ``EF_AMDGPU_MACH_R600_BARTS`` 0x00d ``barts``
  556. ``EF_AMDGPU_MACH_R600_CAICOS`` 0x00e ``caicos``
  557. ``EF_AMDGPU_MACH_R600_CAYMAN`` 0x00f ``cayman``
  558. ``EF_AMDGPU_MACH_R600_TURKS`` 0x010 ``turks``
  559. *reserved* 0x011 - Reserved for ``r600``
  560. 0x01f architecture processors.
  561. ``EF_AMDGPU_MACH_AMDGCN_GFX600`` 0x020 ``gfx600``
  562. ``EF_AMDGPU_MACH_AMDGCN_GFX601`` 0x021 ``gfx601``
  563. ``EF_AMDGPU_MACH_AMDGCN_GFX700`` 0x022 ``gfx700``
  564. ``EF_AMDGPU_MACH_AMDGCN_GFX701`` 0x023 ``gfx701``
  565. ``EF_AMDGPU_MACH_AMDGCN_GFX702`` 0x024 ``gfx702``
  566. ``EF_AMDGPU_MACH_AMDGCN_GFX703`` 0x025 ``gfx703``
  567. ``EF_AMDGPU_MACH_AMDGCN_GFX704`` 0x026 ``gfx704``
  568. *reserved* 0x027 Reserved.
  569. ``EF_AMDGPU_MACH_AMDGCN_GFX801`` 0x028 ``gfx801``
  570. ``EF_AMDGPU_MACH_AMDGCN_GFX802`` 0x029 ``gfx802``
  571. ``EF_AMDGPU_MACH_AMDGCN_GFX803`` 0x02a ``gfx803``
  572. ``EF_AMDGPU_MACH_AMDGCN_GFX810`` 0x02b ``gfx810``
  573. ``EF_AMDGPU_MACH_AMDGCN_GFX900`` 0x02c ``gfx900``
  574. ``EF_AMDGPU_MACH_AMDGCN_GFX902`` 0x02d ``gfx902``
  575. ``EF_AMDGPU_MACH_AMDGCN_GFX904`` 0x02e ``gfx904``
  576. ``EF_AMDGPU_MACH_AMDGCN_GFX906`` 0x02f ``gfx906``
  577. ``EF_AMDGPU_MACH_AMDGCN_GFX908`` 0x030 ``gfx908``
  578. ``EF_AMDGPU_MACH_AMDGCN_GFX909`` 0x031 ``gfx909``
  579. *reserved* 0x032 Reserved.
  580. ``EF_AMDGPU_MACH_AMDGCN_GFX1010`` 0x033 ``gfx1010``
  581. ``EF_AMDGPU_MACH_AMDGCN_GFX1011`` 0x034 ``gfx1011``
  582. ``EF_AMDGPU_MACH_AMDGCN_GFX1012`` 0x035 ``gfx1012``
  583. ================================= ========== =============================
  584. Sections
  585. --------
  586. An AMDGPU target ELF code object has the standard ELF sections which include:
  587. .. table:: AMDGPU ELF Sections
  588. :name: amdgpu-elf-sections-table
  589. ================== ================ =================================
  590. Name Type Attributes
  591. ================== ================ =================================
  592. ``.bss`` ``SHT_NOBITS`` ``SHF_ALLOC`` + ``SHF_WRITE``
  593. ``.data`` ``SHT_PROGBITS`` ``SHF_ALLOC`` + ``SHF_WRITE``
  594. ``.debug_``\ *\** ``SHT_PROGBITS`` *none*
  595. ``.dynamic`` ``SHT_DYNAMIC`` ``SHF_ALLOC``
  596. ``.dynstr`` ``SHT_PROGBITS`` ``SHF_ALLOC``
  597. ``.dynsym`` ``SHT_PROGBITS`` ``SHF_ALLOC``
  598. ``.got`` ``SHT_PROGBITS`` ``SHF_ALLOC`` + ``SHF_WRITE``
  599. ``.hash`` ``SHT_HASH`` ``SHF_ALLOC``
  600. ``.note`` ``SHT_NOTE`` *none*
  601. ``.rela``\ *name* ``SHT_RELA`` *none*
  602. ``.rela.dyn`` ``SHT_RELA`` *none*
  603. ``.rodata`` ``SHT_PROGBITS`` ``SHF_ALLOC``
  604. ``.shstrtab`` ``SHT_STRTAB`` *none*
  605. ``.strtab`` ``SHT_STRTAB`` *none*
  606. ``.symtab`` ``SHT_SYMTAB`` *none*
  607. ``.text`` ``SHT_PROGBITS`` ``SHF_ALLOC`` + ``SHF_EXECINSTR``
  608. ================== ================ =================================
  609. These sections have their standard meanings (see [ELF]_) and are only generated
  610. if needed.
  611. ``.debug``\ *\**
  612. The standard DWARF sections. See :ref:`amdgpu-dwarf` for information on the
  613. DWARF produced by the AMDGPU backend.
  614. ``.dynamic``, ``.dynstr``, ``.dynsym``, ``.hash``
  615. The standard sections used by a dynamic loader.
  616. ``.note``
  617. See :ref:`amdgpu-note-records` for the note records supported by the AMDGPU
  618. backend.
  619. ``.rela``\ *name*, ``.rela.dyn``
  620. For relocatable code objects, *name* is the name of the section that the
  621. relocation records apply. For example, ``.rela.text`` is the section name for
  622. relocation records associated with the ``.text`` section.
  623. For linked shared code objects, ``.rela.dyn`` contains all the relocation
  624. records from each of the relocatable code object's ``.rela``\ *name* sections.
  625. See :ref:`amdgpu-relocation-records` for the relocation records supported by
  626. the AMDGPU backend.
  627. ``.text``
  628. The executable machine code for the kernels and functions they call. Generated
  629. as position independent code. See :ref:`amdgpu-code-conventions` for
  630. information on conventions used in the isa generation.
  631. .. _amdgpu-note-records:
  632. Note Records
  633. ------------
  634. The AMDGPU backend code object contains ELF note records in the ``.note``
  635. section. The set of generated notes and their semantics depend on the code
  636. object version; see :ref:`amdgpu-note-records-v2` and
  637. :ref:`amdgpu-note-records-v3`.
  638. As required by ``ELFCLASS32`` and ``ELFCLASS64``, minimal zero byte padding
  639. must be generated after the ``name`` field to ensure the ``desc`` field is 4
  640. byte aligned. In addition, minimal zero byte padding must be generated to
  641. ensure the ``desc`` field size is a multiple of 4 bytes. The ``sh_addralign``
  642. field of the ``.note`` section must be at least 4 to indicate at least 8 byte
  643. alignment.
  644. .. _amdgpu-note-records-v2:
  645. Code Object V2 Note Records (-mattr=-code-object-v3)
  646. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  647. .. warning:: Code Object V2 is not the default code object version emitted by
  648. this version of LLVM. For a description of the notes generated with the
  649. default configuration (Code Object V3) see :ref:`amdgpu-note-records-v3`.
  650. The AMDGPU backend code object uses the following ELF note record in the
  651. ``.note`` section when compiling for Code Object V2 (-mattr=-code-object-v3).
  652. Additional note records may be present, but any which are not documented here
  653. are deprecated and should not be used.
  654. .. table:: AMDGPU Code Object V2 ELF Note Records
  655. :name: amdgpu-elf-note-records-table-v2
  656. ===== ============================== ======================================
  657. Name Type Description
  658. ===== ============================== ======================================
  659. "AMD" ``NT_AMD_AMDGPU_HSA_METADATA`` <metadata null terminated string>
  660. ===== ============================== ======================================
  661. ..
  662. .. table:: AMDGPU Code Object V2 ELF Note Record Enumeration Values
  663. :name: amdgpu-elf-note-record-enumeration-values-table-v2
  664. ============================== =====
  665. Name Value
  666. ============================== =====
  667. *reserved* 0-9
  668. ``NT_AMD_AMDGPU_HSA_METADATA`` 10
  669. *reserved* 11
  670. ============================== =====
  671. ``NT_AMD_AMDGPU_HSA_METADATA``
  672. Specifies extensible metadata associated with the code objects executed on HSA
  673. [HSA]_ compatible runtimes such as AMD's ROCm [AMD-ROCm]_. It is required when
  674. the target triple OS is ``amdhsa`` (see :ref:`amdgpu-target-triples`). See
  675. :ref:`amdgpu-amdhsa-code-object-metadata-v2` for the syntax of the code
  676. object metadata string.
  677. .. _amdgpu-note-records-v3:
  678. Code Object V3 Note Records (-mattr=+code-object-v3)
  679. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  680. The AMDGPU backend code object uses the following ELF note record in the
  681. ``.note`` section when compiling for Code Object V3 (-mattr=+code-object-v3).
  682. Additional note records may be present, but any which are not documented here
  683. are deprecated and should not be used.
  684. .. table:: AMDGPU Code Object V3 ELF Note Records
  685. :name: amdgpu-elf-note-records-table-v3
  686. ======== ============================== ======================================
  687. Name Type Description
  688. ======== ============================== ======================================
  689. "AMDGPU" ``NT_AMDGPU_METADATA`` Metadata in Message Pack [MsgPack]_
  690. binary format.
  691. ======== ============================== ======================================
  692. ..
  693. .. table:: AMDGPU Code Object V3 ELF Note Record Enumeration Values
  694. :name: amdgpu-elf-note-record-enumeration-values-table-v3
  695. ============================== =====
  696. Name Value
  697. ============================== =====
  698. *reserved* 0-31
  699. ``NT_AMDGPU_METADATA`` 32
  700. ============================== =====
  701. ``NT_AMDGPU_METADATA``
  702. Specifies extensible metadata associated with an AMDGPU code
  703. object. It is encoded as a map in the Message Pack [MsgPack]_ binary
  704. data format. See :ref:`amdgpu-amdhsa-code-object-metadata-v3` for the
  705. map keys defined for the ``amdhsa`` OS.
  706. .. _amdgpu-symbols:
  707. Symbols
  708. -------
  709. Symbols include the following:
  710. .. table:: AMDGPU ELF Symbols
  711. :name: amdgpu-elf-symbols-table
  712. ===================== ================== ================ ==================
  713. Name Type Section Description
  714. ===================== ================== ================ ==================
  715. *link-name* ``STT_OBJECT`` - ``.data`` Global variable
  716. - ``.rodata``
  717. - ``.bss``
  718. *link-name*\ ``.kd`` ``STT_OBJECT`` - ``.rodata`` Kernel descriptor
  719. *link-name* ``STT_FUNC`` - ``.text`` Kernel entry point
  720. *link-name* ``STT_OBJECT`` - SHN_AMDGPU_LDS Global variable in LDS
  721. ===================== ================== ================ ==================
  722. Global variable
  723. Global variables both used and defined by the compilation unit.
  724. If the symbol is defined in the compilation unit then it is allocated in the
  725. appropriate section according to if it has initialized data or is readonly.
  726. If the symbol is external then its section is ``STN_UNDEF`` and the loader
  727. will resolve relocations using the definition provided by another code object
  728. or explicitly defined by the runtime.
  729. If the symbol resides in local/group memory (LDS) then its section is the
  730. special processor-specific section name ``SHN_AMDGPU_LDS``, and the
  731. ``st_value`` field describes alignment requirements as it does for common
  732. symbols.
  733. .. TODO
  734. Add description of linked shared object symbols. Seems undefined symbols
  735. are marked as STT_NOTYPE.
  736. Kernel descriptor
  737. Every HSA kernel has an associated kernel descriptor. It is the address of the
  738. kernel descriptor that is used in the AQL dispatch packet used to invoke the
  739. kernel, not the kernel entry point. The layout of the HSA kernel descriptor is
  740. defined in :ref:`amdgpu-amdhsa-kernel-descriptor`.
  741. Kernel entry point
  742. Every HSA kernel also has a symbol for its machine code entry point.
  743. .. _amdgpu-relocation-records:
  744. Relocation Records
  745. ------------------
  746. AMDGPU backend generates ``Elf64_Rela`` relocation records. Supported
  747. relocatable fields are:
  748. ``word32``
  749. This specifies a 32-bit field occupying 4 bytes with arbitrary byte
  750. alignment. These values use the same byte order as other word values in the
  751. AMD GPU architecture.
  752. ``word64``
  753. This specifies a 64-bit field occupying 8 bytes with arbitrary byte
  754. alignment. These values use the same byte order as other word values in the
  755. AMD GPU architecture.
  756. Following notations are used for specifying relocation calculations:
  757. **A**
  758. Represents the addend used to compute the value of the relocatable field.
  759. **G**
  760. Represents the offset into the global offset table at which the relocation
  761. entry's symbol will reside during execution.
  762. **GOT**
  763. Represents the address of the global offset table.
  764. **P**
  765. Represents the place (section offset for ``et_rel`` or address for ``et_dyn``)
  766. of the storage unit being relocated (computed using ``r_offset``).
  767. **S**
  768. Represents the value of the symbol whose index resides in the relocation
  769. entry. Relocations not using this must specify a symbol index of ``STN_UNDEF``.
  770. **B**
  771. Represents the base address of a loaded executable or shared object which is
  772. the difference between the ELF address and the actual load address. Relocations
  773. using this are only valid in executable or shared objects.
  774. The following relocation types are supported:
  775. .. table:: AMDGPU ELF Relocation Records
  776. :name: amdgpu-elf-relocation-records-table
  777. ========================== ======= ===== ========== ==============================
  778. Relocation Type Kind Value Field Calculation
  779. ========================== ======= ===== ========== ==============================
  780. ``R_AMDGPU_NONE`` 0 *none* *none*
  781. ``R_AMDGPU_ABS32_LO`` Static, 1 ``word32`` (S + A) & 0xFFFFFFFF
  782. Dynamic
  783. ``R_AMDGPU_ABS32_HI`` Static, 2 ``word32`` (S + A) >> 32
  784. Dynamic
  785. ``R_AMDGPU_ABS64`` Static, 3 ``word64`` S + A
  786. Dynamic
  787. ``R_AMDGPU_REL32`` Static 4 ``word32`` S + A - P
  788. ``R_AMDGPU_REL64`` Static 5 ``word64`` S + A - P
  789. ``R_AMDGPU_ABS32`` Static, 6 ``word32`` S + A
  790. Dynamic
  791. ``R_AMDGPU_GOTPCREL`` Static 7 ``word32`` G + GOT + A - P
  792. ``R_AMDGPU_GOTPCREL32_LO`` Static 8 ``word32`` (G + GOT + A - P) & 0xFFFFFFFF
  793. ``R_AMDGPU_GOTPCREL32_HI`` Static 9 ``word32`` (G + GOT + A - P) >> 32
  794. ``R_AMDGPU_REL32_LO`` Static 10 ``word32`` (S + A - P) & 0xFFFFFFFF
  795. ``R_AMDGPU_REL32_HI`` Static 11 ``word32`` (S + A - P) >> 32
  796. *reserved* 12
  797. ``R_AMDGPU_RELATIVE64`` Dynamic 13 ``word64`` B + A
  798. ========================== ======= ===== ========== ==============================
  799. ``R_AMDGPU_ABS32_LO`` and ``R_AMDGPU_ABS32_HI`` are only supported by
  800. the ``mesa3d`` OS, which does not support ``R_AMDGPU_ABS64``.
  801. There is no current OS loader support for 32 bit programs and so
  802. ``R_AMDGPU_ABS32`` is not used.
  803. .. _amdgpu-dwarf:
  804. DWARF
  805. -----
  806. Standard DWARF [DWARF]_ Version 5 sections can be generated. These contain
  807. information that maps the code object executable code and data to the source
  808. language constructs. It can be used by tools such as debuggers and profilers.
  809. Address Space Mapping
  810. ~~~~~~~~~~~~~~~~~~~~~
  811. The following address space mapping is used:
  812. .. table:: AMDGPU DWARF Address Space Mapping
  813. :name: amdgpu-dwarf-address-space-mapping-table
  814. =================== =================
  815. DWARF Address Space Memory Space
  816. =================== =================
  817. 1 Private (Scratch)
  818. 2 Local (group/LDS)
  819. *omitted* Global
  820. *omitted* Constant
  821. *omitted* Generic (Flat)
  822. *not supported* Region (GDS)
  823. =================== =================
  824. See :ref:`amdgpu-address-spaces` for information on the memory space terminology
  825. used in the table.
  826. An ``address_class`` attribute is generated on pointer type DIEs to specify the
  827. DWARF address space of the value of the pointer when it is in the *private* or
  828. *local* address space. Otherwise the attribute is omitted.
  829. An ``XDEREF`` operation is generated in location list expressions for variables
  830. that are allocated in the *private* and *local* address space. Otherwise no
  831. ``XDREF`` is omitted.
  832. Register Mapping
  833. ~~~~~~~~~~~~~~~~
  834. *This section is WIP.*
  835. .. TODO
  836. Define DWARF register enumeration.
  837. If want to present a wavefront state then should expose vector registers as
  838. 64 wide (rather than per work-item view that LLVM uses). Either as separate
  839. registers, or a 64x4 byte single register. In either case use a new LANE op
  840. (akin to XDREF) to select the current lane usage in a location
  841. expression. This would also allow scalar register spilling to vector register
  842. lanes to be expressed (currently no debug information is being generated for
  843. spilling). If choose a wide single register approach then use LANE in
  844. conjunction with PIECE operation to select the dword part of the register for
  845. the current lane. If the separate register approach then use LANE to select
  846. the register.
  847. Source Text
  848. ~~~~~~~~~~~
  849. Source text for online-compiled programs (e.g. those compiled by the OpenCL
  850. runtime) may be embedded into the DWARF v5 line table using the ``clang
  851. -gembed-source`` option, described in table :ref:`amdgpu-debug-options`.
  852. For example:
  853. ``-gembed-source``
  854. Enable the embedded source DWARF v5 extension.
  855. ``-gno-embed-source``
  856. Disable the embedded source DWARF v5 extension.
  857. .. table:: AMDGPU Debug Options
  858. :name: amdgpu-debug-options
  859. ==================== ==================================================
  860. Debug Flag Description
  861. ==================== ==================================================
  862. -g[no-]embed-source Enable/disable embedding source text in DWARF
  863. debug sections. Useful for environments where
  864. source cannot be written to disk, such as
  865. when performing online compilation.
  866. ==================== ==================================================
  867. This option enables one extended content types in the DWARF v5 Line Number
  868. Program Header, which is used to encode embedded source.
  869. .. table:: AMDGPU DWARF Line Number Program Header Extended Content Types
  870. :name: amdgpu-dwarf-extended-content-types
  871. ============================ ======================
  872. Content Type Form
  873. ============================ ======================
  874. ``DW_LNCT_LLVM_source`` ``DW_FORM_line_strp``
  875. ============================ ======================
  876. The source field will contain the UTF-8 encoded, null-terminated source text
  877. with ``'\n'`` line endings. When the source field is present, consumers can use
  878. the embedded source instead of attempting to discover the source on disk. When
  879. the source field is absent, consumers can access the file to get the source
  880. text.
  881. The above content type appears in the ``file_name_entry_format`` field of the
  882. line table prologue, and its corresponding value appear in the ``file_names``
  883. field. The current encoding of the content type is documented in table
  884. :ref:`amdgpu-dwarf-extended-content-types-encoding`
  885. .. table:: AMDGPU DWARF Line Number Program Header Extended Content Types Encoding
  886. :name: amdgpu-dwarf-extended-content-types-encoding
  887. ============================ ====================
  888. Content Type Value
  889. ============================ ====================
  890. ``DW_LNCT_LLVM_source`` 0x2001
  891. ============================ ====================
  892. .. _amdgpu-code-conventions:
  893. Code Conventions
  894. ================
  895. This section provides code conventions used for each supported target triple OS
  896. (see :ref:`amdgpu-target-triples`).
  897. AMDHSA
  898. ------
  899. This section provides code conventions used when the target triple OS is
  900. ``amdhsa`` (see :ref:`amdgpu-target-triples`).
  901. .. _amdgpu-amdhsa-code-object-target-identification:
  902. Code Object Target Identification
  903. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  904. The AMDHSA OS uses the following syntax to specify the code object
  905. target as a single string:
  906. ``<Architecture>-<Vendor>-<OS>-<Environment>-<Processor><Target Features>``
  907. Where:
  908. - ``<Architecture>``, ``<Vendor>``, ``<OS>`` and ``<Environment>``
  909. are the same as the *Target Triple* (see
  910. :ref:`amdgpu-target-triples`).
  911. - ``<Processor>`` is the same as the *Processor* (see
  912. :ref:`amdgpu-processors`).
  913. - ``<Target Features>`` is a list of the enabled *Target Features*
  914. (see :ref:`amdgpu-target-features`), each prefixed by a plus, that
  915. apply to *Processor*. The list must be in the same order as listed
  916. in the table :ref:`amdgpu-target-feature-table`. Note that *Target
  917. Features* must be included in the list if they are enabled even if
  918. that is the default for *Processor*.
  919. For example:
  920. ``"amdgcn-amd-amdhsa--gfx902+xnack"``
  921. .. _amdgpu-amdhsa-code-object-metadata:
  922. Code Object Metadata
  923. ~~~~~~~~~~~~~~~~~~~~
  924. The code object metadata specifies extensible metadata associated with the code
  925. objects executed on HSA [HSA]_ compatible runtimes such as AMD's ROCm
  926. [AMD-ROCm]_. The encoding and semantics of this metadata depends on the code
  927. object version; see :ref:`amdgpu-amdhsa-code-object-metadata-v2` and
  928. :ref:`amdgpu-amdhsa-code-object-metadata-v3`.
  929. Code object metadata is specified in a note record (see
  930. :ref:`amdgpu-note-records`) and is required when the target triple OS is
  931. ``amdhsa`` (see :ref:`amdgpu-target-triples`). It must contain the minimum
  932. information necessary to support the ROCM kernel queries. For example, the
  933. segment sizes needed in a dispatch packet. In addition, a high level language
  934. runtime may require other information to be included. For example, the AMD
  935. OpenCL runtime records kernel argument information.
  936. .. _amdgpu-amdhsa-code-object-metadata-v2:
  937. Code Object V2 Metadata (-mattr=-code-object-v3)
  938. ++++++++++++++++++++++++++++++++++++++++++++++++
  939. .. warning:: Code Object V2 is not the default code object version emitted by
  940. this version of LLVM. For a description of the metadata generated with the
  941. default configuration (Code Object V3) see
  942. :ref:`amdgpu-amdhsa-code-object-metadata-v3`.
  943. Code object V2 metadata is specified by the ``NT_AMD_AMDGPU_METADATA`` note
  944. record (see :ref:`amdgpu-note-records-v2`).
  945. The metadata is specified as a YAML formatted string (see [YAML]_ and
  946. :doc:`YamlIO`).
  947. .. TODO
  948. Is the string null terminated? It probably should not if YAML allows it to
  949. contain null characters, otherwise it should be.
  950. The metadata is represented as a single YAML document comprised of the mapping
  951. defined in table :ref:`amdgpu-amdhsa-code-object-metadata-map-table-v2` and
  952. referenced tables.
  953. For boolean values, the string values of ``false`` and ``true`` are used for
  954. false and true respectively.
  955. Additional information can be added to the mappings. To avoid conflicts, any
  956. non-AMD key names should be prefixed by "*vendor-name*.".
  957. .. table:: AMDHSA Code Object V2 Metadata Map
  958. :name: amdgpu-amdhsa-code-object-metadata-map-table-v2
  959. ========== ============== ========= =======================================
  960. String Key Value Type Required? Description
  961. ========== ============== ========= =======================================
  962. "Version" sequence of Required - The first integer is the major
  963. 2 integers version. Currently 1.
  964. - The second integer is the minor
  965. version. Currently 0.
  966. "Printf" sequence of Each string is encoded information
  967. strings about a printf function call. The
  968. encoded information is organized as
  969. fields separated by colon (':'):
  970. ``ID:N:S[0]:S[1]:...:S[N-1]:FormatString``
  971. where:
  972. ``ID``
  973. A 32 bit integer as a unique id for
  974. each printf function call
  975. ``N``
  976. A 32 bit integer equal to the number
  977. of arguments of printf function call
  978. minus 1
  979. ``S[i]`` (where i = 0, 1, ... , N-1)
  980. 32 bit integers for the size in bytes
  981. of the i-th FormatString argument of
  982. the printf function call
  983. FormatString
  984. The format string passed to the
  985. printf function call.
  986. "Kernels" sequence of Required Sequence of the mappings for each
  987. mapping kernel in the code object. See
  988. :ref:`amdgpu-amdhsa-code-object-kernel-metadata-map-table-v2`
  989. for the definition of the mapping.
  990. ========== ============== ========= =======================================
  991. ..
  992. .. table:: AMDHSA Code Object V2 Kernel Metadata Map
  993. :name: amdgpu-amdhsa-code-object-kernel-metadata-map-table-v2
  994. ================= ============== ========= ================================
  995. String Key Value Type Required? Description
  996. ================= ============== ========= ================================
  997. "Name" string Required Source name of the kernel.
  998. "SymbolName" string Required Name of the kernel
  999. descriptor ELF symbol.
  1000. "Language" string Source language of the kernel.
  1001. Values include:
  1002. - "OpenCL C"
  1003. - "OpenCL C++"
  1004. - "HCC"
  1005. - "OpenMP"
  1006. "LanguageVersion" sequence of - The first integer is the major
  1007. 2 integers version.
  1008. - The second integer is the
  1009. minor version.
  1010. "Attrs" mapping Mapping of kernel attributes.
  1011. See
  1012. :ref:`amdgpu-amdhsa-code-object-kernel-attribute-metadata-map-table-v2`
  1013. for the mapping definition.
  1014. "Args" sequence of Sequence of mappings of the
  1015. mapping kernel arguments. See
  1016. :ref:`amdgpu-amdhsa-code-object-kernel-argument-metadata-map-table-v2`
  1017. for the definition of the mapping.
  1018. "CodeProps" mapping Mapping of properties related to
  1019. the kernel code. See
  1020. :ref:`amdgpu-amdhsa-code-object-kernel-code-properties-metadata-map-table-v2`
  1021. for the mapping definition.
  1022. ================= ============== ========= ================================
  1023. ..
  1024. .. table:: AMDHSA Code Object V2 Kernel Attribute Metadata Map
  1025. :name: amdgpu-amdhsa-code-object-kernel-attribute-metadata-map-table-v2
  1026. =================== ============== ========= ==============================
  1027. String Key Value Type Required? Description
  1028. =================== ============== ========= ==============================
  1029. "ReqdWorkGroupSize" sequence of If not 0, 0, 0 then all values
  1030. 3 integers must be >=1 and the dispatch
  1031. work-group size X, Y, Z must
  1032. correspond to the specified
  1033. values. Defaults to 0, 0, 0.
  1034. Corresponds to the OpenCL
  1035. ``reqd_work_group_size``
  1036. attribute.
  1037. "WorkGroupSizeHint" sequence of The dispatch work-group size
  1038. 3 integers X, Y, Z is likely to be the
  1039. specified values.
  1040. Corresponds to the OpenCL
  1041. ``work_group_size_hint``
  1042. attribute.
  1043. "VecTypeHint" string The name of a scalar or vector
  1044. type.
  1045. Corresponds to the OpenCL
  1046. ``vec_type_hint`` attribute.
  1047. "RuntimeHandle" string The external symbol name
  1048. associated with a kernel.
  1049. OpenCL runtime allocates a
  1050. global buffer for the symbol
  1051. and saves the kernel's address
  1052. to it, which is used for
  1053. device side enqueueing. Only
  1054. available for device side
  1055. enqueued kernels.
  1056. =================== ============== ========= ==============================
  1057. ..
  1058. .. table:: AMDHSA Code Object V2 Kernel Argument Metadata Map
  1059. :name: amdgpu-amdhsa-code-object-kernel-argument-metadata-map-table-v2
  1060. ================= ============== ========= ================================
  1061. String Key Value Type Required? Description
  1062. ================= ============== ========= ================================
  1063. "Name" string Kernel argument name.
  1064. "TypeName" string Kernel argument type name.
  1065. "Size" integer Required Kernel argument size in bytes.
  1066. "Align" integer Required Kernel argument alignment in
  1067. bytes. Must be a power of two.
  1068. "ValueKind" string Required Kernel argument kind that
  1069. specifies how to set up the
  1070. corresponding argument.
  1071. Values include:
  1072. "ByValue"
  1073. The argument is copied
  1074. directly into the kernarg.
  1075. "GlobalBuffer"
  1076. A global address space pointer
  1077. to the buffer data is passed
  1078. in the kernarg.
  1079. "DynamicSharedPointer"
  1080. A group address space pointer
  1081. to dynamically allocated LDS
  1082. is passed in the kernarg.
  1083. "Sampler"
  1084. A global address space
  1085. pointer to a S# is passed in
  1086. the kernarg.
  1087. "Image"
  1088. A global address space
  1089. pointer to a T# is passed in
  1090. the kernarg.
  1091. "Pipe"
  1092. A global address space pointer
  1093. to an OpenCL pipe is passed in
  1094. the kernarg.
  1095. "Queue"
  1096. A global address space pointer
  1097. to an OpenCL device enqueue
  1098. queue is passed in the
  1099. kernarg.
  1100. "HiddenGlobalOffsetX"
  1101. The OpenCL grid dispatch
  1102. global offset for the X
  1103. dimension is passed in the
  1104. kernarg.
  1105. "HiddenGlobalOffsetY"
  1106. The OpenCL grid dispatch
  1107. global offset for the Y
  1108. dimension is passed in the
  1109. kernarg.
  1110. "HiddenGlobalOffsetZ"
  1111. The OpenCL grid dispatch
  1112. global offset for the Z
  1113. dimension is passed in the
  1114. kernarg.
  1115. "HiddenNone"
  1116. An argument that is not used
  1117. by the kernel. Space needs to
  1118. be left for it, but it does
  1119. not need to be set up.
  1120. "HiddenPrintfBuffer"
  1121. A global address space pointer
  1122. to the runtime printf buffer
  1123. is passed in kernarg.
  1124. "HiddenDefaultQueue"
  1125. A global address space pointer
  1126. to the OpenCL device enqueue
  1127. queue that should be used by
  1128. the kernel by default is
  1129. passed in the kernarg.
  1130. "HiddenCompletionAction"
  1131. A global address space pointer
  1132. to help link enqueued kernels into
  1133. the ancestor tree for determining
  1134. when the parent kernel has finished.
  1135. "HiddenMultiGridSyncArg"
  1136. A global address space pointer for
  1137. multi-grid synchronization is
  1138. passed in the kernarg.
  1139. "ValueType" string Required Kernel argument value type. Only
  1140. present if "ValueKind" is
  1141. "ByValue". For vector data
  1142. types, the value is for the
  1143. element type. Values include:
  1144. - "Struct"
  1145. - "I8"
  1146. - "U8"
  1147. - "I16"
  1148. - "U16"
  1149. - "F16"
  1150. - "I32"
  1151. - "U32"
  1152. - "F32"
  1153. - "I64"
  1154. - "U64"
  1155. - "F64"
  1156. .. TODO
  1157. How can it be determined if a
  1158. vector type, and what size
  1159. vector?
  1160. "PointeeAlign" integer Alignment in bytes of pointee
  1161. type for pointer type kernel
  1162. argument. Must be a power
  1163. of 2. Only present if
  1164. "ValueKind" is
  1165. "DynamicSharedPointer".
  1166. "AddrSpaceQual" string Kernel argument address space
  1167. qualifier. Only present if
  1168. "ValueKind" is "GlobalBuffer" or
  1169. "DynamicSharedPointer". Values
  1170. are:
  1171. - "Private"
  1172. - "Global"
  1173. - "Constant"
  1174. - "Local"
  1175. - "Generic"
  1176. - "Region"
  1177. .. TODO
  1178. Is GlobalBuffer only Global
  1179. or Constant? Is
  1180. DynamicSharedPointer always
  1181. Local? Can HCC allow Generic?
  1182. How can Private or Region
  1183. ever happen?
  1184. "AccQual" string Kernel argument access
  1185. qualifier. Only present if
  1186. "ValueKind" is "Image" or
  1187. "Pipe". Values
  1188. are:
  1189. - "ReadOnly"
  1190. - "WriteOnly"
  1191. - "ReadWrite"
  1192. .. TODO
  1193. Does this apply to
  1194. GlobalBuffer?
  1195. "ActualAccQual" string The actual memory accesses
  1196. performed by the kernel on the
  1197. kernel argument. Only present if
  1198. "ValueKind" is "GlobalBuffer",
  1199. "Image", or "Pipe". This may be
  1200. more restrictive than indicated
  1201. by "AccQual" to reflect what the
  1202. kernel actual does. If not
  1203. present then the runtime must
  1204. assume what is implied by
  1205. "AccQual" and "IsConst". Values
  1206. are:
  1207. - "ReadOnly"
  1208. - "WriteOnly"
  1209. - "ReadWrite"
  1210. "IsConst" boolean Indicates if the kernel argument
  1211. is const qualified. Only present
  1212. if "ValueKind" is
  1213. "GlobalBuffer".
  1214. "IsRestrict" boolean Indicates if the kernel argument
  1215. is restrict qualified. Only
  1216. present if "ValueKind" is
  1217. "GlobalBuffer".
  1218. "IsVolatile" boolean Indicates if the kernel argument
  1219. is volatile qualified. Only
  1220. present if "ValueKind" is
  1221. "GlobalBuffer".
  1222. "IsPipe" boolean Indicates if the kernel argument
  1223. is pipe qualified. Only present
  1224. if "ValueKind" is "Pipe".
  1225. .. TODO
  1226. Can GlobalBuffer be pipe
  1227. qualified?
  1228. ================= ============== ========= ================================
  1229. ..
  1230. .. table:: AMDHSA Code Object V2 Kernel Code Properties Metadata Map
  1231. :name: amdgpu-amdhsa-code-object-kernel-code-properties-metadata-map-table-v2
  1232. ============================ ============== ========= =====================
  1233. String Key Value Type Required? Description
  1234. ============================ ============== ========= =====================
  1235. "KernargSegmentSize" integer Required The size in bytes of
  1236. the kernarg segment
  1237. that holds the values
  1238. of the arguments to
  1239. the kernel.
  1240. "GroupSegmentFixedSize" integer Required The amount of group
  1241. segment memory
  1242. required by a
  1243. work-group in
  1244. bytes. This does not
  1245. include any
  1246. dynamically allocated
  1247. group segment memory
  1248. that may be added
  1249. when the kernel is
  1250. dispatched.
  1251. "PrivateSegmentFixedSize" integer Required The amount of fixed
  1252. private address space
  1253. memory required for a
  1254. work-item in
  1255. bytes. If the kernel
  1256. uses a dynamic call
  1257. stack then additional
  1258. space must be added
  1259. to this value for the
  1260. call stack.
  1261. "KernargSegmentAlign" integer Required The maximum byte
  1262. alignment of
  1263. arguments in the
  1264. kernarg segment. Must
  1265. be a power of 2.
  1266. "WavefrontSize" integer Required Wavefront size. Must
  1267. be a power of 2.
  1268. "NumSGPRs" integer Required Number of scalar
  1269. registers used by a
  1270. wavefront for
  1271. GFX6-GFX10. This
  1272. includes the special
  1273. SGPRs for VCC, Flat
  1274. Scratch (GFX7-GFX10)
  1275. and XNACK (for
  1276. GFX8-GFX10). It does
  1277. not include the 16
  1278. SGPR added if a trap
  1279. handler is
  1280. enabled. It is not
  1281. rounded up to the
  1282. allocation
  1283. granularity.
  1284. "NumVGPRs" integer Required Number of vector
  1285. registers used by
  1286. each work-item for
  1287. GFX6-GFX10
  1288. "MaxFlatWorkGroupSize" integer Required Maximum flat
  1289. work-group size
  1290. supported by the
  1291. kernel in work-items.
  1292. Must be >=1 and
  1293. consistent with
  1294. ReqdWorkGroupSize if
  1295. not 0, 0, 0.
  1296. "NumSpilledSGPRs" integer Number of stores from
  1297. a scalar register to
  1298. a register allocator
  1299. created spill
  1300. location.
  1301. "NumSpilledVGPRs" integer Number of stores from
  1302. a vector register to
  1303. a register allocator
  1304. created spill
  1305. location.
  1306. ============================ ============== ========= =====================
  1307. .. _amdgpu-amdhsa-code-object-metadata-v3:
  1308. Code Object V3 Metadata (-mattr=+code-object-v3)
  1309. ++++++++++++++++++++++++++++++++++++++++++++++++
  1310. Code object V3 metadata is specified by the ``NT_AMDGPU_METADATA`` note record
  1311. (see :ref:`amdgpu-note-records-v3`).
  1312. The metadata is represented as Message Pack formatted binary data (see
  1313. [MsgPack]_). The top level is a Message Pack map that includes the
  1314. keys defined in table
  1315. :ref:`amdgpu-amdhsa-code-object-metadata-map-table-v3` and referenced
  1316. tables.
  1317. Additional information can be added to the maps. To avoid conflicts,
  1318. any key names should be prefixed by "*vendor-name*." where
  1319. ``vendor-name`` can be the the name of the vendor and specific vendor
  1320. tool that generates the information. The prefix is abbreviated to
  1321. simply "." when it appears within a map that has been added by the
  1322. same *vendor-name*.
  1323. .. table:: AMDHSA Code Object V3 Metadata Map
  1324. :name: amdgpu-amdhsa-code-object-metadata-map-table-v3
  1325. ================= ============== ========= =======================================
  1326. String Key Value Type Required? Description
  1327. ================= ============== ========= =======================================
  1328. "amdhsa.version" sequence of Required - The first integer is the major
  1329. 2 integers version. Currently 1.
  1330. - The second integer is the minor
  1331. version. Currently 0.
  1332. "amdhsa.printf" sequence of Each string is encoded information
  1333. strings about a printf function call. The
  1334. encoded information is organized as
  1335. fields separated by colon (':'):
  1336. ``ID:N:S[0]:S[1]:...:S[N-1]:FormatString``
  1337. where:
  1338. ``ID``
  1339. A 32 bit integer as a unique id for
  1340. each printf function call
  1341. ``N``
  1342. A 32 bit integer equal to the number
  1343. of arguments of printf function call
  1344. minus 1
  1345. ``S[i]`` (where i = 0, 1, ... , N-1)
  1346. 32 bit integers for the size in bytes
  1347. of the i-th FormatString argument of
  1348. the printf function call
  1349. FormatString
  1350. The format string passed to the
  1351. printf function call.
  1352. "amdhsa.kernels" sequence of Required Sequence of the maps for each
  1353. map kernel in the code object. See
  1354. :ref:`amdgpu-amdhsa-code-object-kernel-metadata-map-table-v3`
  1355. for the definition of the keys included
  1356. in that map.
  1357. ================= ============== ========= =======================================
  1358. ..
  1359. .. table:: AMDHSA Code Object V3 Kernel Metadata Map
  1360. :name: amdgpu-amdhsa-code-object-kernel-metadata-map-table-v3
  1361. =================================== ============== ========= ================================
  1362. String Key Value Type Required? Description
  1363. =================================== ============== ========= ================================
  1364. ".name" string Required Source name of the kernel.
  1365. ".symbol" string Required Name of the kernel
  1366. descriptor ELF symbol.
  1367. ".language" string Source language of the kernel.
  1368. Values include:
  1369. - "OpenCL C"
  1370. - "OpenCL C++"
  1371. - "HCC"
  1372. - "HIP"
  1373. - "OpenMP"
  1374. - "Assembler"
  1375. ".language_version" sequence of - The first integer is the major
  1376. 2 integers version.
  1377. - The second integer is the
  1378. minor version.
  1379. ".args" sequence of Sequence of maps of the
  1380. map kernel arguments. See
  1381. :ref:`amdgpu-amdhsa-code-object-kernel-argument-metadata-map-table-v3`
  1382. for the definition of the keys
  1383. included in that map.
  1384. ".reqd_workgroup_size" sequence of If not 0, 0, 0 then all values
  1385. 3 integers must be >=1 and the dispatch
  1386. work-group size X, Y, Z must
  1387. correspond to the specified
  1388. values. Defaults to 0, 0, 0.
  1389. Corresponds to the OpenCL
  1390. ``reqd_work_group_size``
  1391. attribute.
  1392. ".workgroup_size_hint" sequence of The dispatch work-group size
  1393. 3 integers X, Y, Z is likely to be the
  1394. specified values.
  1395. Corresponds to the OpenCL
  1396. ``work_group_size_hint``
  1397. attribute.
  1398. ".vec_type_hint" string The name of a scalar or vector
  1399. type.
  1400. Corresponds to the OpenCL
  1401. ``vec_type_hint`` attribute.
  1402. ".device_enqueue_symbol" string The external symbol name
  1403. associated with a kernel.
  1404. OpenCL runtime allocates a
  1405. global buffer for the symbol
  1406. and saves the kernel's address
  1407. to it, which is used for
  1408. device side enqueueing. Only
  1409. available for device side
  1410. enqueued kernels.
  1411. ".kernarg_segment_size" integer Required The size in bytes of
  1412. the kernarg segment
  1413. that holds the values
  1414. of the arguments to
  1415. the kernel.
  1416. ".group_segment_fixed_size" integer Required The amount of group
  1417. segment memory
  1418. required by a
  1419. work-group in
  1420. bytes. This does not
  1421. include any
  1422. dynamically allocated
  1423. group segment memory
  1424. that may be added
  1425. when the kernel is
  1426. dispatched.
  1427. ".private_segment_fixed_size" integer Required The amount of fixed
  1428. private address space
  1429. memory required for a
  1430. work-item in
  1431. bytes. If the kernel
  1432. uses a dynamic call
  1433. stack then additional
  1434. space must be added
  1435. to this value for the
  1436. call stack.
  1437. ".kernarg_segment_align" integer Required The maximum byte
  1438. alignment of
  1439. arguments in the
  1440. kernarg segment. Must
  1441. be a power of 2.
  1442. ".wavefront_size" integer Required Wavefront size. Must
  1443. be a power of 2.
  1444. ".sgpr_count" integer Required Number of scalar
  1445. registers required by a
  1446. wavefront for
  1447. GFX6-GFX9. A register
  1448. is required if it is
  1449. used explicitly, or
  1450. if a higher numbered
  1451. register is used
  1452. explicitly. This
  1453. includes the special
  1454. SGPRs for VCC, Flat
  1455. Scratch (GFX7-GFX9)
  1456. and XNACK (for
  1457. GFX8-GFX9). It does
  1458. not include the 16
  1459. SGPR added if a trap
  1460. handler is
  1461. enabled. It is not
  1462. rounded up to the
  1463. allocation
  1464. granularity.
  1465. ".vgpr_count" integer Required Number of vector
  1466. registers required by
  1467. each work-item for
  1468. GFX6-GFX9. A register
  1469. is required if it is
  1470. used explicitly, or
  1471. if a higher numbered
  1472. register is used
  1473. explicitly.
  1474. ".max_flat_workgroup_size" integer Required Maximum flat
  1475. work-group size
  1476. supported by the
  1477. kernel in work-items.
  1478. Must be >=1 and
  1479. consistent with
  1480. ReqdWorkGroupSize if
  1481. not 0, 0, 0.
  1482. ".sgpr_spill_count" integer Number of stores from
  1483. a scalar register to
  1484. a register allocator
  1485. created spill
  1486. location.
  1487. ".vgpr_spill_count" integer Number of stores from
  1488. a vector register to
  1489. a register allocator
  1490. created spill
  1491. location.
  1492. =================================== ============== ========= ================================
  1493. ..
  1494. .. table:: AMDHSA Code Object V3 Kernel Argument Metadata Map
  1495. :name: amdgpu-amdhsa-code-object-kernel-argument-metadata-map-table-v3
  1496. ====================== ============== ========= ================================
  1497. String Key Value Type Required? Description
  1498. ====================== ============== ========= ================================
  1499. ".name" string Kernel argument name.
  1500. ".type_name" string Kernel argument type name.
  1501. ".size" integer Required Kernel argument size in bytes.
  1502. ".offset" integer Required Kernel argument offset in
  1503. bytes. The offset must be a
  1504. multiple of the alignment
  1505. required by the argument.
  1506. ".value_kind" string Required Kernel argument kind that
  1507. specifies how to set up the
  1508. corresponding argument.
  1509. Values include:
  1510. "by_value"
  1511. The argument is copied
  1512. directly into the kernarg.
  1513. "global_buffer"
  1514. A global address space pointer
  1515. to the buffer data is passed
  1516. in the kernarg.
  1517. "dynamic_shared_pointer"
  1518. A group address space pointer
  1519. to dynamically allocated LDS
  1520. is passed in the kernarg.
  1521. "sampler"
  1522. A global address space
  1523. pointer to a S# is passed in
  1524. the kernarg.
  1525. "image"
  1526. A global address space
  1527. pointer to a T# is passed in
  1528. the kernarg.
  1529. "pipe"
  1530. A global address space pointer
  1531. to an OpenCL pipe is passed in
  1532. the kernarg.
  1533. "queue"
  1534. A global address space pointer
  1535. to an OpenCL device enqueue
  1536. queue is passed in the
  1537. kernarg.
  1538. "hidden_global_offset_x"
  1539. The OpenCL grid dispatch
  1540. global offset for the X
  1541. dimension is passed in the
  1542. kernarg.
  1543. "hidden_global_offset_y"
  1544. The OpenCL grid dispatch
  1545. global offset for the Y
  1546. dimension is passed in the
  1547. kernarg.
  1548. "hidden_global_offset_z"
  1549. The OpenCL grid dispatch
  1550. global offset for the Z
  1551. dimension is passed in the
  1552. kernarg.
  1553. "hidden_none"
  1554. An argument that is not used
  1555. by the kernel. Space needs to
  1556. be left for it, but it does
  1557. not need to be set up.
  1558. "hidden_printf_buffer"
  1559. A global address space pointer
  1560. to the runtime printf buffer
  1561. is passed in kernarg.
  1562. "hidden_default_queue"
  1563. A global address space pointer
  1564. to the OpenCL device enqueue
  1565. queue that should be used by
  1566. the kernel by default is
  1567. passed in the kernarg.
  1568. "hidden_completion_action"
  1569. A global address space pointer
  1570. to help link enqueued kernels into
  1571. the ancestor tree for determining
  1572. when the parent kernel has finished.
  1573. "hidden_multigrid_sync_arg"
  1574. A global address space pointer for
  1575. multi-grid synchronization is
  1576. passed in the kernarg.
  1577. ".value_type" string Required Kernel argument value type. Only
  1578. present if ".value_kind" is
  1579. "by_value". For vector data
  1580. types, the value is for the
  1581. element type. Values include:
  1582. - "struct"
  1583. - "i8"
  1584. - "u8"
  1585. - "i16"
  1586. - "u16"
  1587. - "f16"
  1588. - "i32"
  1589. - "u32"
  1590. - "f32"
  1591. - "i64"
  1592. - "u64"
  1593. - "f64"
  1594. .. TODO
  1595. How can it be determined if a
  1596. vector type, and what size
  1597. vector?
  1598. ".pointee_align" integer Alignment in bytes of pointee
  1599. type for pointer type kernel
  1600. argument. Must be a power
  1601. of 2. Only present if
  1602. ".value_kind" is
  1603. "dynamic_shared_pointer".
  1604. ".address_space" string Kernel argument address space
  1605. qualifier. Only present if
  1606. ".value_kind" is "global_buffer" or
  1607. "dynamic_shared_pointer". Values
  1608. are:
  1609. - "private"
  1610. - "global"
  1611. - "constant"
  1612. - "local"
  1613. - "generic"
  1614. - "region"
  1615. .. TODO
  1616. Is "global_buffer" only "global"
  1617. or "constant"? Is
  1618. "dynamic_shared_pointer" always
  1619. "local"? Can HCC allow "generic"?
  1620. How can "private" or "region"
  1621. ever happen?
  1622. ".access" string Kernel argument access
  1623. qualifier. Only present if
  1624. ".value_kind" is "image" or
  1625. "pipe". Values
  1626. are:
  1627. - "read_only"
  1628. - "write_only"
  1629. - "read_write"
  1630. .. TODO
  1631. Does this apply to
  1632. "global_buffer"?
  1633. ".actual_access" string The actual memory accesses
  1634. performed by the kernel on the
  1635. kernel argument. Only present if
  1636. ".value_kind" is "global_buffer",
  1637. "image", or "pipe". This may be
  1638. more restrictive than indicated
  1639. by ".access" to reflect what the
  1640. kernel actual does. If not
  1641. present then the runtime must
  1642. assume what is implied by
  1643. ".access" and ".is_const" . Values
  1644. are:
  1645. - "read_only"
  1646. - "write_only"
  1647. - "read_write"
  1648. ".is_const" boolean Indicates if the kernel argument
  1649. is const qualified. Only present
  1650. if ".value_kind" is
  1651. "global_buffer".
  1652. ".is_restrict" boolean Indicates if the kernel argument
  1653. is restrict qualified. Only
  1654. present if ".value_kind" is
  1655. "global_buffer".
  1656. ".is_volatile" boolean Indicates if the kernel argument
  1657. is volatile qualified. Only
  1658. present if ".value_kind" is
  1659. "global_buffer".
  1660. ".is_pipe" boolean Indicates if the kernel argument
  1661. is pipe qualified. Only present
  1662. if ".value_kind" is "pipe".
  1663. .. TODO
  1664. Can "global_buffer" be pipe
  1665. qualified?
  1666. ====================== ============== ========= ================================
  1667. ..
  1668. Kernel Dispatch
  1669. ~~~~~~~~~~~~~~~
  1670. The HSA architected queuing language (AQL) defines a user space memory interface
  1671. that can be used to control the dispatch of kernels, in an agent independent
  1672. way. An agent can have zero or more AQL queues created for it using the ROCm
  1673. runtime, in which AQL packets (all of which are 64 bytes) can be placed. See the
  1674. *HSA Platform System Architecture Specification* [HSA]_ for the AQL queue
  1675. mechanics and packet layouts.
  1676. The packet processor of a kernel agent is responsible for detecting and
  1677. dispatching HSA kernels from the AQL queues associated with it. For AMD GPUs the
  1678. packet processor is implemented by the hardware command processor (CP),
  1679. asynchronous dispatch controller (ADC) and shader processor input controller
  1680. (SPI).
  1681. The ROCm runtime can be used to allocate an AQL queue object. It uses the kernel
  1682. mode driver to initialize and register the AQL queue with CP.
  1683. To dispatch a kernel the following actions are performed. This can occur in the
  1684. CPU host program, or from an HSA kernel executing on a GPU.
  1685. 1. A pointer to an AQL queue for the kernel agent on which the kernel is to be
  1686. executed is obtained.
  1687. 2. A pointer to the kernel descriptor (see
  1688. :ref:`amdgpu-amdhsa-kernel-descriptor`) of the kernel to execute is
  1689. obtained. It must be for a kernel that is contained in a code object that that
  1690. was loaded by the ROCm runtime on the kernel agent with which the AQL queue is
  1691. associated.
  1692. 3. Space is allocated for the kernel arguments using the ROCm runtime allocator
  1693. for a memory region with the kernarg property for the kernel agent that will
  1694. execute the kernel. It must be at least 16 byte aligned.
  1695. 4. Kernel argument values are assigned to the kernel argument memory
  1696. allocation. The layout is defined in the *HSA Programmer's Language Reference*
  1697. [HSA]_. For AMDGPU the kernel execution directly accesses the kernel argument
  1698. memory in the same way constant memory is accessed. (Note that the HSA
  1699. specification allows an implementation to copy the kernel argument contents to
  1700. another location that is accessed by the kernel.)
  1701. 5. An AQL kernel dispatch packet is created on the AQL queue. The ROCm runtime
  1702. api uses 64 bit atomic operations to reserve space in the AQL queue for the
  1703. packet. The packet must be set up, and the final write must use an atomic
  1704. store release to set the packet kind to ensure the packet contents are
  1705. visible to the kernel agent. AQL defines a doorbell signal mechanism to
  1706. notify the kernel agent that the AQL queue has been updated. These rules, and
  1707. the layout of the AQL queue and kernel dispatch packet is defined in the *HSA
  1708. System Architecture Specification* [HSA]_.
  1709. 6. A kernel dispatch packet includes information about the actual dispatch,
  1710. such as grid and work-group size, together with information from the code
  1711. object about the kernel, such as segment sizes. The ROCm runtime queries on
  1712. the kernel symbol can be used to obtain the code object values which are
  1713. recorded in the :ref:`amdgpu-amdhsa-code-object-metadata`.
  1714. 7. CP executes micro-code and is responsible for detecting and setting up the
  1715. GPU to execute the wavefronts of a kernel dispatch.
  1716. 8. CP ensures that when the a wavefront starts executing the kernel machine
  1717. code, the scalar general purpose registers (SGPR) and vector general purpose
  1718. registers (VGPR) are set up as required by the machine code. The required
  1719. setup is defined in the :ref:`amdgpu-amdhsa-kernel-descriptor`. The initial
  1720. register state is defined in
  1721. :ref:`amdgpu-amdhsa-initial-kernel-execution-state`.
  1722. 9. The prolog of the kernel machine code (see
  1723. :ref:`amdgpu-amdhsa-kernel-prolog`) sets up the machine state as necessary
  1724. before continuing executing the machine code that corresponds to the kernel.
  1725. 10. When the kernel dispatch has completed execution, CP signals the completion
  1726. signal specified in the kernel dispatch packet if not 0.
  1727. .. _amdgpu-amdhsa-memory-spaces:
  1728. Memory Spaces
  1729. ~~~~~~~~~~~~~
  1730. The memory space properties are:
  1731. .. table:: AMDHSA Memory Spaces
  1732. :name: amdgpu-amdhsa-memory-spaces-table
  1733. ================= =========== ======== ======= ==================
  1734. Memory Space Name HSA Segment Hardware Address NULL Value
  1735. Name Name Size
  1736. ================= =========== ======== ======= ==================
  1737. Private private scratch 32 0x00000000
  1738. Local group LDS 32 0xFFFFFFFF
  1739. Global global global 64 0x0000000000000000
  1740. Constant constant *same as 64 0x0000000000000000
  1741. global*
  1742. Generic flat flat 64 0x0000000000000000
  1743. Region N/A GDS 32 *not implemented
  1744. for AMDHSA*
  1745. ================= =========== ======== ======= ==================
  1746. The global and constant memory spaces both use global virtual addresses, which
  1747. are the same virtual address space used by the CPU. However, some virtual
  1748. addresses may only be accessible to the CPU, some only accessible by the GPU,
  1749. and some by both.
  1750. Using the constant memory space indicates that the data will not change during
  1751. the execution of the kernel. This allows scalar read instructions to be
  1752. used. The vector and scalar L1 caches are invalidated of volatile data before
  1753. each kernel dispatch execution to allow constant memory to change values between
  1754. kernel dispatches.
  1755. The local memory space uses the hardware Local Data Store (LDS) which is
  1756. automatically allocated when the hardware creates work-groups of wavefronts, and
  1757. freed when all the wavefronts of a work-group have terminated. The data store
  1758. (DS) instructions can be used to access it.
  1759. The private memory space uses the hardware scratch memory support. If the kernel
  1760. uses scratch, then the hardware allocates memory that is accessed using
  1761. wavefront lane dword (4 byte) interleaving. The mapping used from private
  1762. address to physical address is:
  1763. ``wavefront-scratch-base +
  1764. (private-address * wavefront-size * 4) +
  1765. (wavefront-lane-id * 4)``
  1766. There are different ways that the wavefront scratch base address is determined
  1767. by a wavefront (see :ref:`amdgpu-amdhsa-initial-kernel-execution-state`). This
  1768. memory can be accessed in an interleaved manner using buffer instruction with
  1769. the scratch buffer descriptor and per wavefront scratch offset, by the scratch
  1770. instructions, or by flat instructions. If each lane of a wavefront accesses the
  1771. same private address, the interleaving results in adjacent dwords being accessed
  1772. and hence requires fewer cache lines to be fetched. Multi-dword access is not
  1773. supported except by flat and scratch instructions in GFX9-GFX10.
  1774. The generic address space uses the hardware flat address support available in
  1775. GFX7-GFX10. This uses two fixed ranges of virtual addresses (the private and
  1776. local appertures), that are outside the range of addressible global memory, to
  1777. map from a flat address to a private or local address.
  1778. FLAT instructions can take a flat address and access global, private (scratch)
  1779. and group (LDS) memory depending in if the address is within one of the
  1780. apperture ranges. Flat access to scratch requires hardware aperture setup and
  1781. setup in the kernel prologue (see :ref:`amdgpu-amdhsa-flat-scratch`). Flat
  1782. access to LDS requires hardware aperture setup and M0 (GFX7-GFX8) register setup
  1783. (see :ref:`amdgpu-amdhsa-m0`).
  1784. To convert between a segment address and a flat address the base address of the
  1785. appertures address can be used. For GFX7-GFX8 these are available in the
  1786. :ref:`amdgpu-amdhsa-hsa-aql-queue` the address of which can be obtained with
  1787. Queue Ptr SGPR (see :ref:`amdgpu-amdhsa-initial-kernel-execution-state`). For
  1788. GFX9-GFX10 the appature base addresses are directly available as inline constant
  1789. registers ``SRC_SHARED_BASE/LIMIT`` and ``SRC_PRIVATE_BASE/LIMIT``. In 64 bit
  1790. address mode the apperture sizes are 2^32 bytes and the base is aligned to 2^32
  1791. which makes it easier to convert from flat to segment or segment to flat.
  1792. Image and Samplers
  1793. ~~~~~~~~~~~~~~~~~~
  1794. Image and sample handles created by the ROCm runtime are 64 bit addresses of a
  1795. hardware 32 byte V# and 48 byte S# object respectively. In order to support the
  1796. HSA ``query_sampler`` operations two extra dwords are used to store the HSA BRIG
  1797. enumeration values for the queries that are not trivially deducible from the S#
  1798. representation.
  1799. HSA Signals
  1800. ~~~~~~~~~~~
  1801. HSA signal handles created by the ROCm runtime are 64 bit addresses of a
  1802. structure allocated in memory accessible from both the CPU and GPU. The
  1803. structure is defined by the ROCm runtime and subject to change between releases
  1804. (see [AMD-ROCm-github]_).
  1805. .. _amdgpu-amdhsa-hsa-aql-queue:
  1806. HSA AQL Queue
  1807. ~~~~~~~~~~~~~
  1808. The HSA AQL queue structure is defined by the ROCm runtime and subject to change
  1809. between releases (see [AMD-ROCm-github]_). For some processors it contains
  1810. fields needed to implement certain language features such as the flat address
  1811. aperture bases. It also contains fields used by CP such as managing the
  1812. allocation of scratch memory.
  1813. .. _amdgpu-amdhsa-kernel-descriptor:
  1814. Kernel Descriptor
  1815. ~~~~~~~~~~~~~~~~~
  1816. A kernel descriptor consists of the information needed by CP to initiate the
  1817. execution of a kernel, including the entry point address of the machine code
  1818. that implements the kernel.
  1819. Kernel Descriptor for GFX6-GFX10
  1820. ++++++++++++++++++++++++++++++++
  1821. CP microcode requires the Kernel descriptor to be allocated on 64 byte
  1822. alignment.
  1823. .. table:: Kernel Descriptor for GFX6-GFX10
  1824. :name: amdgpu-amdhsa-kernel-descriptor-gfx6-gfx10-table
  1825. ======= ======= =============================== ============================
  1826. Bits Size Field Name Description
  1827. ======= ======= =============================== ============================
  1828. 31:0 4 bytes GROUP_SEGMENT_FIXED_SIZE The amount of fixed local
  1829. address space memory
  1830. required for a work-group
  1831. in bytes. This does not
  1832. include any dynamically
  1833. allocated local address
  1834. space memory that may be
  1835. added when the kernel is
  1836. dispatched.
  1837. 63:32 4 bytes PRIVATE_SEGMENT_FIXED_SIZE The amount of fixed
  1838. private address space
  1839. memory required for a
  1840. work-item in bytes. If
  1841. is_dynamic_callstack is 1
  1842. then additional space must
  1843. be added to this value for
  1844. the call stack.
  1845. 127:64 8 bytes Reserved, must be 0.
  1846. 191:128 8 bytes KERNEL_CODE_ENTRY_BYTE_OFFSET Byte offset (possibly
  1847. negative) from base
  1848. address of kernel
  1849. descriptor to kernel's
  1850. entry point instruction
  1851. which must be 256 byte
  1852. aligned.
  1853. 351:272 20 Reserved, must be 0.
  1854. bytes
  1855. 383:352 4 bytes COMPUTE_PGM_RSRC3 GFX6-9
  1856. Reserved, must be 0.
  1857. GFX10
  1858. Compute Shader (CS)
  1859. program settings used by
  1860. CP to set up
  1861. ``COMPUTE_PGM_RSRC3``
  1862. configuration
  1863. register. See
  1864. :ref:`amdgpu-amdhsa-compute_pgm_rsrc3-gfx10-table`.
  1865. 415:384 4 bytes COMPUTE_PGM_RSRC1 Compute Shader (CS)
  1866. program settings used by
  1867. CP to set up
  1868. ``COMPUTE_PGM_RSRC1``
  1869. configuration
  1870. register. See
  1871. :ref:`amdgpu-amdhsa-compute_pgm_rsrc1-gfx6-gfx10-table`.
  1872. 447:416 4 bytes COMPUTE_PGM_RSRC2 Compute Shader (CS)
  1873. program settings used by
  1874. CP to set up
  1875. ``COMPUTE_PGM_RSRC2``
  1876. configuration
  1877. register. See
  1878. :ref:`amdgpu-amdhsa-compute_pgm_rsrc2-gfx6-gfx10-table`.
  1879. 448 1 bit ENABLE_SGPR_PRIVATE_SEGMENT Enable the setup of the
  1880. _BUFFER SGPR user data registers
  1881. (see
  1882. :ref:`amdgpu-amdhsa-initial-kernel-execution-state`).
  1883. The total number of SGPR
  1884. user data registers
  1885. requested must not exceed
  1886. 16 and match value in
  1887. ``compute_pgm_rsrc2.user_sgpr.user_sgpr_count``.
  1888. Any requests beyond 16
  1889. will be ignored.
  1890. 449 1 bit ENABLE_SGPR_DISPATCH_PTR *see above*
  1891. 450 1 bit ENABLE_SGPR_QUEUE_PTR *see above*
  1892. 451 1 bit ENABLE_SGPR_KERNARG_SEGMENT_PTR *see above*
  1893. 452 1 bit ENABLE_SGPR_DISPATCH_ID *see above*
  1894. 453 1 bit ENABLE_SGPR_FLAT_SCRATCH_INIT *see above*
  1895. 454 1 bit ENABLE_SGPR_PRIVATE_SEGMENT *see above*
  1896. _SIZE
  1897. 457:455 3 bits Reserved, must be 0.
  1898. 458 1 bit ENABLE_WAVEFRONT_SIZE32 GFX6-9
  1899. Reserved, must be 0.
  1900. GFX10
  1901. - If 0 execute in
  1902. wavefront size 64 mode.
  1903. - If 1 execute in
  1904. native wavefront size
  1905. 32 mode.
  1906. 463:459 5 bits Reserved, must be 0.
  1907. 511:464 6 bytes Reserved, must be 0.
  1908. 512 **Total size 64 bytes.**
  1909. ======= ====================================================================
  1910. ..
  1911. .. table:: compute_pgm_rsrc1 for GFX6-GFX10
  1912. :name: amdgpu-amdhsa-compute_pgm_rsrc1-gfx6-gfx10-table
  1913. ======= ======= =============================== ===========================================================================
  1914. Bits Size Field Name Description
  1915. ======= ======= =============================== ===========================================================================
  1916. 5:0 6 bits GRANULATED_WORKITEM_VGPR_COUNT Number of vector register
  1917. blocks used by each work-item;
  1918. granularity is device
  1919. specific:
  1920. GFX6-GFX9
  1921. - vgprs_used 0..256
  1922. - max(0, ceil(vgprs_used / 4) - 1)
  1923. GFX10 (wavefront size 64)
  1924. - max_vgpr 1..256
  1925. - max(0, ceil(vgprs_used / 4) - 1)
  1926. GFX10 (wavefront size 32)
  1927. - max_vgpr 1..256
  1928. - max(0, ceil(vgprs_used / 8) - 1)
  1929. Where vgprs_used is defined
  1930. as the highest VGPR number
  1931. explicitly referenced plus
  1932. one.
  1933. Used by CP to set up
  1934. ``COMPUTE_PGM_RSRC1.VGPRS``.
  1935. The
  1936. :ref:`amdgpu-assembler`
  1937. calculates this
  1938. automatically for the
  1939. selected processor from
  1940. values provided to the
  1941. `.amdhsa_kernel` directive
  1942. by the
  1943. `.amdhsa_next_free_vgpr`
  1944. nested directive (see
  1945. :ref:`amdhsa-kernel-directives-table`).
  1946. 9:6 4 bits GRANULATED_WAVEFRONT_SGPR_COUNT Number of scalar register
  1947. blocks used by a wavefront;
  1948. granularity is device
  1949. specific:
  1950. GFX6-GFX8
  1951. - sgprs_used 0..112
  1952. - max(0, ceil(sgprs_used / 8) - 1)
  1953. GFX9
  1954. - sgprs_used 0..112
  1955. - 2 * max(0, ceil(sgprs_used / 16) - 1)
  1956. GFX10
  1957. Reserved, must be 0.
  1958. (128 SGPRs always
  1959. allocated.)
  1960. Where sgprs_used is
  1961. defined as the highest
  1962. SGPR number explicitly
  1963. referenced plus one, plus
  1964. a target-specific number
  1965. of additional special
  1966. SGPRs for VCC,
  1967. FLAT_SCRATCH (GFX7+) and
  1968. XNACK_MASK (GFX8+), and
  1969. any additional
  1970. target-specific
  1971. limitations. It does not
  1972. include the 16 SGPRs added
  1973. if a trap handler is
  1974. enabled.
  1975. The target-specific
  1976. limitations and special
  1977. SGPR layout are defined in
  1978. the hardware
  1979. documentation, which can
  1980. be found in the
  1981. :ref:`amdgpu-processors`
  1982. table.
  1983. Used by CP to set up
  1984. ``COMPUTE_PGM_RSRC1.SGPRS``.
  1985. The
  1986. :ref:`amdgpu-assembler`
  1987. calculates this
  1988. automatically for the
  1989. selected processor from
  1990. values provided to the
  1991. `.amdhsa_kernel` directive
  1992. by the
  1993. `.amdhsa_next_free_sgpr`
  1994. and `.amdhsa_reserve_*`
  1995. nested directives (see
  1996. :ref:`amdhsa-kernel-directives-table`).
  1997. 11:10 2 bits PRIORITY Must be 0.
  1998. Start executing wavefront
  1999. at the specified priority.
  2000. CP is responsible for
  2001. filling in
  2002. ``COMPUTE_PGM_RSRC1.PRIORITY``.
  2003. 13:12 2 bits FLOAT_ROUND_MODE_32 Wavefront starts execution
  2004. with specified rounding
  2005. mode for single (32
  2006. bit) floating point
  2007. precision floating point
  2008. operations.
  2009. Floating point rounding
  2010. mode values are defined in
  2011. :ref:`amdgpu-amdhsa-floating-point-rounding-mode-enumeration-values-table`.
  2012. Used by CP to set up
  2013. ``COMPUTE_PGM_RSRC1.FLOAT_MODE``.
  2014. 15:14 2 bits FLOAT_ROUND_MODE_16_64 Wavefront starts execution
  2015. with specified rounding
  2016. denorm mode for half/double (16
  2017. and 64 bit) floating point
  2018. precision floating point
  2019. operations.
  2020. Floating point rounding
  2021. mode values are defined in
  2022. :ref:`amdgpu-amdhsa-floating-point-rounding-mode-enumeration-values-table`.
  2023. Used by CP to set up
  2024. ``COMPUTE_PGM_RSRC1.FLOAT_MODE``.
  2025. 17:16 2 bits FLOAT_DENORM_MODE_32 Wavefront starts execution
  2026. with specified denorm mode
  2027. for single (32
  2028. bit) floating point
  2029. precision floating point
  2030. operations.
  2031. Floating point denorm mode
  2032. values are defined in
  2033. :ref:`amdgpu-amdhsa-floating-point-denorm-mode-enumeration-values-table`.
  2034. Used by CP to set up
  2035. ``COMPUTE_PGM_RSRC1.FLOAT_MODE``.
  2036. 19:18 2 bits FLOAT_DENORM_MODE_16_64 Wavefront starts execution
  2037. with specified denorm mode
  2038. for half/double (16
  2039. and 64 bit) floating point
  2040. precision floating point
  2041. operations.
  2042. Floating point denorm mode
  2043. values are defined in
  2044. :ref:`amdgpu-amdhsa-floating-point-denorm-mode-enumeration-values-table`.
  2045. Used by CP to set up
  2046. ``COMPUTE_PGM_RSRC1.FLOAT_MODE``.
  2047. 20 1 bit PRIV Must be 0.
  2048. Start executing wavefront
  2049. in privilege trap handler
  2050. mode.
  2051. CP is responsible for
  2052. filling in
  2053. ``COMPUTE_PGM_RSRC1.PRIV``.
  2054. 21 1 bit ENABLE_DX10_CLAMP Wavefront starts execution
  2055. with DX10 clamp mode
  2056. enabled. Used by the vector
  2057. ALU to force DX10 style
  2058. treatment of NaN's (when
  2059. set, clamp NaN to zero,
  2060. otherwise pass NaN
  2061. through).
  2062. Used by CP to set up
  2063. ``COMPUTE_PGM_RSRC1.DX10_CLAMP``.
  2064. 22 1 bit DEBUG_MODE Must be 0.
  2065. Start executing wavefront
  2066. in single step mode.
  2067. CP is responsible for
  2068. filling in
  2069. ``COMPUTE_PGM_RSRC1.DEBUG_MODE``.
  2070. 23 1 bit ENABLE_IEEE_MODE Wavefront starts execution
  2071. with IEEE mode
  2072. enabled. Floating point
  2073. opcodes that support
  2074. exception flag gathering
  2075. will quiet and propagate
  2076. signaling-NaN inputs per
  2077. IEEE 754-2008. Min_dx10 and
  2078. max_dx10 become IEEE
  2079. 754-2008 compliant due to
  2080. signaling-NaN propagation
  2081. and quieting.
  2082. Used by CP to set up
  2083. ``COMPUTE_PGM_RSRC1.IEEE_MODE``.
  2084. 24 1 bit BULKY Must be 0.
  2085. Only one work-group allowed
  2086. to execute on a compute
  2087. unit.
  2088. CP is responsible for
  2089. filling in
  2090. ``COMPUTE_PGM_RSRC1.BULKY``.
  2091. 25 1 bit CDBG_USER Must be 0.
  2092. Flag that can be used to
  2093. control debugging code.
  2094. CP is responsible for
  2095. filling in
  2096. ``COMPUTE_PGM_RSRC1.CDBG_USER``.
  2097. 26 1 bit FP16_OVFL GFX6-GFX8
  2098. Reserved, must be 0.
  2099. GFX9-GFX10
  2100. Wavefront starts execution
  2101. with specified fp16 overflow
  2102. mode.
  2103. - If 0, fp16 overflow generates
  2104. +/-INF values.
  2105. - If 1, fp16 overflow that is the
  2106. result of an +/-INF input value
  2107. or divide by 0 produces a +/-INF,
  2108. otherwise clamps computed
  2109. overflow to +/-MAX_FP16 as
  2110. appropriate.
  2111. Used by CP to set up
  2112. ``COMPUTE_PGM_RSRC1.FP16_OVFL``.
  2113. 28:27 2 bits Reserved, must be 0.
  2114. 29 1 bit WGP_MODE GFX6-GFX9
  2115. Reserved, must be 0.
  2116. GFX10
  2117. - If 0 execute work-groups in
  2118. CU wavefront execution mode.
  2119. - If 1 execute work-groups on
  2120. in WGP wavefront execution mode.
  2121. See :ref:`amdgpu-amdhsa-memory-model`.
  2122. Used by CP to set up
  2123. ``COMPUTE_PGM_RSRC1.WGP_MODE``.
  2124. 30 1 bit MEM_ORDERED GFX6-9
  2125. Reserved, must be 0.
  2126. GFX10
  2127. Controls the behavior of the
  2128. waitcnt's vmcnt and vscnt
  2129. counters.
  2130. - If 0 vmcnt reports completion
  2131. of load and atomic with return
  2132. out of order with sample
  2133. instructions, and the vscnt
  2134. reports the completion of
  2135. store and atomic without
  2136. return in order.
  2137. - If 1 vmcnt reports completion
  2138. of load, atomic with return
  2139. and sample instructions in
  2140. order, and the vscnt reports
  2141. the completion of store and
  2142. atomic without return in order.
  2143. Used by CP to set up
  2144. ``COMPUTE_PGM_RSRC1.MEM_ORDERED``.
  2145. 31 1 bit FWD_PROGRESS GFX6-9
  2146. Reserved, must be 0.
  2147. GFX10
  2148. - If 0 execute SIMD wavefronts
  2149. using oldest first policy.
  2150. - If 1 execute SIMD wavefronts to
  2151. ensure wavefronts will make some
  2152. forward progress.
  2153. Used by CP to set up
  2154. ``COMPUTE_PGM_RSRC1.FWD_PROGRESS``.
  2155. 32 **Total size 4 bytes**
  2156. ======= ===================================================================================================================
  2157. ..
  2158. .. table:: compute_pgm_rsrc2 for GFX6-GFX10
  2159. :name: amdgpu-amdhsa-compute_pgm_rsrc2-gfx6-gfx10-table
  2160. ======= ======= =============================== ===========================================================================
  2161. Bits Size Field Name Description
  2162. ======= ======= =============================== ===========================================================================
  2163. 0 1 bit ENABLE_SGPR_PRIVATE_SEGMENT Enable the setup of the
  2164. _WAVEFRONT_OFFSET SGPR wavefront scratch offset
  2165. system register (see
  2166. :ref:`amdgpu-amdhsa-initial-kernel-execution-state`).
  2167. Used by CP to set up
  2168. ``COMPUTE_PGM_RSRC2.SCRATCH_EN``.
  2169. 5:1 5 bits USER_SGPR_COUNT The total number of SGPR
  2170. user data registers
  2171. requested. This number must
  2172. match the number of user
  2173. data registers enabled.
  2174. Used by CP to set up
  2175. ``COMPUTE_PGM_RSRC2.USER_SGPR``.
  2176. 6 1 bit ENABLE_TRAP_HANDLER Must be 0.
  2177. This bit represents
  2178. ``COMPUTE_PGM_RSRC2.TRAP_PRESENT``,
  2179. which is set by the CP if
  2180. the runtime has installed a
  2181. trap handler.
  2182. 7 1 bit ENABLE_SGPR_WORKGROUP_ID_X Enable the setup of the
  2183. system SGPR register for
  2184. the work-group id in the X
  2185. dimension (see
  2186. :ref:`amdgpu-amdhsa-initial-kernel-execution-state`).
  2187. Used by CP to set up
  2188. ``COMPUTE_PGM_RSRC2.TGID_X_EN``.
  2189. 8 1 bit ENABLE_SGPR_WORKGROUP_ID_Y Enable the setup of the
  2190. system SGPR register for
  2191. the work-group id in the Y
  2192. dimension (see
  2193. :ref:`amdgpu-amdhsa-initial-kernel-execution-state`).
  2194. Used by CP to set up
  2195. ``COMPUTE_PGM_RSRC2.TGID_Y_EN``.
  2196. 9 1 bit ENABLE_SGPR_WORKGROUP_ID_Z Enable the setup of the
  2197. system SGPR register for
  2198. the work-group id in the Z
  2199. dimension (see
  2200. :ref:`amdgpu-amdhsa-initial-kernel-execution-state`).
  2201. Used by CP to set up
  2202. ``COMPUTE_PGM_RSRC2.TGID_Z_EN``.
  2203. 10 1 bit ENABLE_SGPR_WORKGROUP_INFO Enable the setup of the
  2204. system SGPR register for
  2205. work-group information (see
  2206. :ref:`amdgpu-amdhsa-initial-kernel-execution-state`).
  2207. Used by CP to set up
  2208. ``COMPUTE_PGM_RSRC2.TGID_SIZE_EN``.
  2209. 12:11 2 bits ENABLE_VGPR_WORKITEM_ID Enable the setup of the
  2210. VGPR system registers used
  2211. for the work-item ID.
  2212. :ref:`amdgpu-amdhsa-system-vgpr-work-item-id-enumeration-values-table`
  2213. defines the values.
  2214. Used by CP to set up
  2215. ``COMPUTE_PGM_RSRC2.TIDIG_CMP_CNT``.
  2216. 13 1 bit ENABLE_EXCEPTION_ADDRESS_WATCH Must be 0.
  2217. Wavefront starts execution
  2218. with address watch
  2219. exceptions enabled which
  2220. are generated when L1 has
  2221. witnessed a thread access
  2222. an *address of
  2223. interest*.
  2224. CP is responsible for
  2225. filling in the address
  2226. watch bit in
  2227. ``COMPUTE_PGM_RSRC2.EXCP_EN_MSB``
  2228. according to what the
  2229. runtime requests.
  2230. 14 1 bit ENABLE_EXCEPTION_MEMORY Must be 0.
  2231. Wavefront starts execution
  2232. with memory violation
  2233. exceptions exceptions
  2234. enabled which are generated
  2235. when a memory violation has
  2236. occurred for this wavefront from
  2237. L1 or LDS
  2238. (write-to-read-only-memory,
  2239. mis-aligned atomic, LDS
  2240. address out of range,
  2241. illegal address, etc.).
  2242. CP sets the memory
  2243. violation bit in
  2244. ``COMPUTE_PGM_RSRC2.EXCP_EN_MSB``
  2245. according to what the
  2246. runtime requests.
  2247. 23:15 9 bits GRANULATED_LDS_SIZE Must be 0.
  2248. CP uses the rounded value
  2249. from the dispatch packet,
  2250. not this value, as the
  2251. dispatch may contain
  2252. dynamically allocated group
  2253. segment memory. CP writes
  2254. directly to
  2255. ``COMPUTE_PGM_RSRC2.LDS_SIZE``.
  2256. Amount of group segment
  2257. (LDS) to allocate for each
  2258. work-group. Granularity is
  2259. device specific:
  2260. GFX6:
  2261. roundup(lds-size / (64 * 4))
  2262. GFX7-GFX10:
  2263. roundup(lds-size / (128 * 4))
  2264. 24 1 bit ENABLE_EXCEPTION_IEEE_754_FP Wavefront starts execution
  2265. _INVALID_OPERATION with specified exceptions
  2266. enabled.
  2267. Used by CP to set up
  2268. ``COMPUTE_PGM_RSRC2.EXCP_EN``
  2269. (set from bits 0..6).
  2270. IEEE 754 FP Invalid
  2271. Operation
  2272. 25 1 bit ENABLE_EXCEPTION_FP_DENORMAL FP Denormal one or more
  2273. _SOURCE input operands is a
  2274. denormal number
  2275. 26 1 bit ENABLE_EXCEPTION_IEEE_754_FP IEEE 754 FP Division by
  2276. _DIVISION_BY_ZERO Zero
  2277. 27 1 bit ENABLE_EXCEPTION_IEEE_754_FP IEEE 754 FP FP Overflow
  2278. _OVERFLOW
  2279. 28 1 bit ENABLE_EXCEPTION_IEEE_754_FP IEEE 754 FP Underflow
  2280. _UNDERFLOW
  2281. 29 1 bit ENABLE_EXCEPTION_IEEE_754_FP IEEE 754 FP Inexact
  2282. _INEXACT
  2283. 30 1 bit ENABLE_EXCEPTION_INT_DIVIDE_BY Integer Division by Zero
  2284. _ZERO (rcp_iflag_f32 instruction
  2285. only)
  2286. 31 1 bit Reserved, must be 0.
  2287. 32 **Total size 4 bytes.**
  2288. ======= ===================================================================================================================
  2289. ..
  2290. .. table:: compute_pgm_rsrc3 for GFX10
  2291. :name: amdgpu-amdhsa-compute_pgm_rsrc3-gfx10-table
  2292. ======= ======= =============================== ===========================================================================
  2293. Bits Size Field Name Description
  2294. ======= ======= =============================== ===========================================================================
  2295. 3:0 4 bits SHARED_VGPR_COUNT Number of shared VGPRs for wavefront size 64. Granularity 8. Value 0-120.
  2296. compute_pgm_rsrc1.vgprs + shared_vgpr_cnt cannot exceed 64.
  2297. 31:4 28 Reserved, must be 0.
  2298. bits
  2299. 32 **Total size 4 bytes.**
  2300. ======= ===================================================================================================================
  2301. ..
  2302. .. table:: Floating Point Rounding Mode Enumeration Values
  2303. :name: amdgpu-amdhsa-floating-point-rounding-mode-enumeration-values-table
  2304. ====================================== ===== ==============================
  2305. Enumeration Name Value Description
  2306. ====================================== ===== ==============================
  2307. FLOAT_ROUND_MODE_NEAR_EVEN 0 Round Ties To Even
  2308. FLOAT_ROUND_MODE_PLUS_INFINITY 1 Round Toward +infinity
  2309. FLOAT_ROUND_MODE_MINUS_INFINITY 2 Round Toward -infinity
  2310. FLOAT_ROUND_MODE_ZERO 3 Round Toward 0
  2311. ====================================== ===== ==============================
  2312. ..
  2313. .. table:: Floating Point Denorm Mode Enumeration Values
  2314. :name: amdgpu-amdhsa-floating-point-denorm-mode-enumeration-values-table
  2315. ====================================== ===== ==============================
  2316. Enumeration Name Value Description
  2317. ====================================== ===== ==============================
  2318. FLOAT_DENORM_MODE_FLUSH_SRC_DST 0 Flush Source and Destination
  2319. Denorms
  2320. FLOAT_DENORM_MODE_FLUSH_DST 1 Flush Output Denorms
  2321. FLOAT_DENORM_MODE_FLUSH_SRC 2 Flush Source Denorms
  2322. FLOAT_DENORM_MODE_FLUSH_NONE 3 No Flush
  2323. ====================================== ===== ==============================
  2324. ..
  2325. .. table:: System VGPR Work-Item ID Enumeration Values
  2326. :name: amdgpu-amdhsa-system-vgpr-work-item-id-enumeration-values-table
  2327. ======================================== ===== ============================
  2328. Enumeration Name Value Description
  2329. ======================================== ===== ============================
  2330. SYSTEM_VGPR_WORKITEM_ID_X 0 Set work-item X dimension
  2331. ID.
  2332. SYSTEM_VGPR_WORKITEM_ID_X_Y 1 Set work-item X and Y
  2333. dimensions ID.
  2334. SYSTEM_VGPR_WORKITEM_ID_X_Y_Z 2 Set work-item X, Y and Z
  2335. dimensions ID.
  2336. SYSTEM_VGPR_WORKITEM_ID_UNDEFINED 3 Undefined.
  2337. ======================================== ===== ============================
  2338. .. _amdgpu-amdhsa-initial-kernel-execution-state:
  2339. Initial Kernel Execution State
  2340. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2341. This section defines the register state that will be set up by the packet
  2342. processor prior to the start of execution of every wavefront. This is limited by
  2343. the constraints of the hardware controllers of CP/ADC/SPI.
  2344. The order of the SGPR registers is defined, but the compiler can specify which
  2345. ones are actually setup in the kernel descriptor using the ``enable_sgpr_*`` bit
  2346. fields (see :ref:`amdgpu-amdhsa-kernel-descriptor`). The register numbers used
  2347. for enabled registers are dense starting at SGPR0: the first enabled register is
  2348. SGPR0, the next enabled register is SGPR1 etc.; disabled registers do not have
  2349. an SGPR number.
  2350. The initial SGPRs comprise up to 16 User SRGPs that are set by CP and apply to
  2351. all wavefronts of the grid. It is possible to specify more than 16 User SGPRs using
  2352. the ``enable_sgpr_*`` bit fields, in which case only the first 16 are actually
  2353. initialized. These are then immediately followed by the System SGPRs that are
  2354. set up by ADC/SPI and can have different values for each wavefront of the grid
  2355. dispatch.
  2356. SGPR register initial state is defined in
  2357. :ref:`amdgpu-amdhsa-sgpr-register-set-up-order-table`.
  2358. .. table:: SGPR Register Set Up Order
  2359. :name: amdgpu-amdhsa-sgpr-register-set-up-order-table
  2360. ========== ========================== ====== ==============================
  2361. SGPR Order Name Number Description
  2362. (kernel descriptor enable of
  2363. field) SGPRs
  2364. ========== ========================== ====== ==============================
  2365. First Private Segment Buffer 4 V# that can be used, together
  2366. (enable_sgpr_private with Scratch Wavefront Offset
  2367. _segment_buffer) as an offset, to access the
  2368. private memory space using a
  2369. segment address.
  2370. CP uses the value provided by
  2371. the runtime.
  2372. then Dispatch Ptr 2 64 bit address of AQL dispatch
  2373. (enable_sgpr_dispatch_ptr) packet for kernel dispatch
  2374. actually executing.
  2375. then Queue Ptr 2 64 bit address of amd_queue_t
  2376. (enable_sgpr_queue_ptr) object for AQL queue on which
  2377. the dispatch packet was
  2378. queued.
  2379. then Kernarg Segment Ptr 2 64 bit address of Kernarg
  2380. (enable_sgpr_kernarg segment. This is directly
  2381. _segment_ptr) copied from the
  2382. kernarg_address in the kernel
  2383. dispatch packet.
  2384. Having CP load it once avoids
  2385. loading it at the beginning of
  2386. every wavefront.
  2387. then Dispatch Id 2 64 bit Dispatch ID of the
  2388. (enable_sgpr_dispatch_id) dispatch packet being
  2389. executed.
  2390. then Flat Scratch Init 2 This is 2 SGPRs:
  2391. (enable_sgpr_flat_scratch
  2392. _init) GFX6
  2393. Not supported.
  2394. GFX7-GFX8
  2395. The first SGPR is a 32 bit
  2396. byte offset from
  2397. ``SH_HIDDEN_PRIVATE_BASE_VIMID``
  2398. to per SPI base of memory
  2399. for scratch for the queue
  2400. executing the kernel
  2401. dispatch. CP obtains this
  2402. from the runtime. (The
  2403. Scratch Segment Buffer base
  2404. address is
  2405. ``SH_HIDDEN_PRIVATE_BASE_VIMID``
  2406. plus this offset.) The value
  2407. of Scratch Wavefront Offset must
  2408. be added to this offset by
  2409. the kernel machine code,
  2410. right shifted by 8, and
  2411. moved to the FLAT_SCRATCH_HI
  2412. SGPR register.
  2413. FLAT_SCRATCH_HI corresponds
  2414. to SGPRn-4 on GFX7, and
  2415. SGPRn-6 on GFX8 (where SGPRn
  2416. is the highest numbered SGPR
  2417. allocated to the wavefront).
  2418. FLAT_SCRATCH_HI is
  2419. multiplied by 256 (as it is
  2420. in units of 256 bytes) and
  2421. added to
  2422. ``SH_HIDDEN_PRIVATE_BASE_VIMID``
  2423. to calculate the per wavefront
  2424. FLAT SCRATCH BASE in flat
  2425. memory instructions that
  2426. access the scratch
  2427. apperture.
  2428. The second SGPR is 32 bit
  2429. byte size of a single
  2430. work-item's scratch memory
  2431. usage. CP obtains this from
  2432. the runtime, and it is
  2433. always a multiple of DWORD.
  2434. CP checks that the value in
  2435. the kernel dispatch packet
  2436. Private Segment Byte Size is
  2437. not larger, and requests the
  2438. runtime to increase the
  2439. queue's scratch size if
  2440. necessary. The kernel code
  2441. must move it to
  2442. FLAT_SCRATCH_LO which is
  2443. SGPRn-3 on GFX7 and SGPRn-5
  2444. on GFX8. FLAT_SCRATCH_LO is
  2445. used as the FLAT SCRATCH
  2446. SIZE in flat memory
  2447. instructions. Having CP load
  2448. it once avoids loading it at
  2449. the beginning of every
  2450. wavefront.
  2451. GFX9-GFX10
  2452. This is the
  2453. 64 bit base address of the
  2454. per SPI scratch backing
  2455. memory managed by SPI for
  2456. the queue executing the
  2457. kernel dispatch. CP obtains
  2458. this from the runtime (and
  2459. divides it if there are
  2460. multiple Shader Arrays each
  2461. with its own SPI). The value
  2462. of Scratch Wavefront Offset must
  2463. be added by the kernel
  2464. machine code and the result
  2465. moved to the FLAT_SCRATCH
  2466. SGPR which is SGPRn-6 and
  2467. SGPRn-5. It is used as the
  2468. FLAT SCRATCH BASE in flat
  2469. memory instructions.
  2470. then Private Segment Size 1 The 32 bit byte size of a
  2471. (enable_sgpr_private single
  2472. work-item's
  2473. scratch_segment_size) memory
  2474. allocation. This is the
  2475. value from the kernel
  2476. dispatch packet Private
  2477. Segment Byte Size rounded up
  2478. by CP to a multiple of
  2479. DWORD.
  2480. Having CP load it once avoids
  2481. loading it at the beginning of
  2482. every wavefront.
  2483. This is not used for
  2484. GFX7-GFX8 since it is the same
  2485. value as the second SGPR of
  2486. Flat Scratch Init. However, it
  2487. may be needed for GFX9-GFX10 which
  2488. changes the meaning of the
  2489. Flat Scratch Init value.
  2490. then Grid Work-Group Count X 1 32 bit count of the number of
  2491. (enable_sgpr_grid work-groups in the X dimension
  2492. _workgroup_count_X) for the grid being
  2493. executed. Computed from the
  2494. fields in the kernel dispatch
  2495. packet as ((grid_size.x +
  2496. workgroup_size.x - 1) /
  2497. workgroup_size.x).
  2498. then Grid Work-Group Count Y 1 32 bit count of the number of
  2499. (enable_sgpr_grid work-groups in the Y dimension
  2500. _workgroup_count_Y && for the grid being
  2501. less than 16 previous executed. Computed from the
  2502. SGPRs) fields in the kernel dispatch
  2503. packet as ((grid_size.y +
  2504. workgroup_size.y - 1) /
  2505. workgroupSize.y).
  2506. Only initialized if <16
  2507. previous SGPRs initialized.
  2508. then Grid Work-Group Count Z 1 32 bit count of the number of
  2509. (enable_sgpr_grid work-groups in the Z dimension
  2510. _workgroup_count_Z && for the grid being
  2511. less than 16 previous executed. Computed from the
  2512. SGPRs) fields in the kernel dispatch
  2513. packet as ((grid_size.z +
  2514. workgroup_size.z - 1) /
  2515. workgroupSize.z).
  2516. Only initialized if <16
  2517. previous SGPRs initialized.
  2518. then Work-Group Id X 1 32 bit work-group id in X
  2519. (enable_sgpr_workgroup_id dimension of grid for
  2520. _X) wavefront.
  2521. then Work-Group Id Y 1 32 bit work-group id in Y
  2522. (enable_sgpr_workgroup_id dimension of grid for
  2523. _Y) wavefront.
  2524. then Work-Group Id Z 1 32 bit work-group id in Z
  2525. (enable_sgpr_workgroup_id dimension of grid for
  2526. _Z) wavefront.
  2527. then Work-Group Info 1 {first_wavefront, 14'b0000,
  2528. (enable_sgpr_workgroup ordered_append_term[10:0],
  2529. _info) threadgroup_size_in_wavefronts[5:0]}
  2530. then Scratch Wavefront Offset 1 32 bit byte offset from base
  2531. (enable_sgpr_private of scratch base of queue
  2532. _segment_wavefront_offset) executing the kernel
  2533. dispatch. Must be used as an
  2534. offset with Private
  2535. segment address when using
  2536. Scratch Segment Buffer. It
  2537. must be used to set up FLAT
  2538. SCRATCH for flat addressing
  2539. (see
  2540. :ref:`amdgpu-amdhsa-flat-scratch`).
  2541. ========== ========================== ====== ==============================
  2542. The order of the VGPR registers is defined, but the compiler can specify which
  2543. ones are actually setup in the kernel descriptor using the ``enable_vgpr*`` bit
  2544. fields (see :ref:`amdgpu-amdhsa-kernel-descriptor`). The register numbers used
  2545. for enabled registers are dense starting at VGPR0: the first enabled register is
  2546. VGPR0, the next enabled register is VGPR1 etc.; disabled registers do not have a
  2547. VGPR number.
  2548. VGPR register initial state is defined in
  2549. :ref:`amdgpu-amdhsa-vgpr-register-set-up-order-table`.
  2550. .. table:: VGPR Register Set Up Order
  2551. :name: amdgpu-amdhsa-vgpr-register-set-up-order-table
  2552. ========== ========================== ====== ==============================
  2553. VGPR Order Name Number Description
  2554. (kernel descriptor enable of
  2555. field) VGPRs
  2556. ========== ========================== ====== ==============================
  2557. First Work-Item Id X 1 32 bit work item id in X
  2558. (Always initialized) dimension of work-group for
  2559. wavefront lane.
  2560. then Work-Item Id Y 1 32 bit work item id in Y
  2561. (enable_vgpr_workitem_id dimension of work-group for
  2562. > 0) wavefront lane.
  2563. then Work-Item Id Z 1 32 bit work item id in Z
  2564. (enable_vgpr_workitem_id dimension of work-group for
  2565. > 1) wavefront lane.
  2566. ========== ========================== ====== ==============================
  2567. The setting of registers is done by GPU CP/ADC/SPI hardware as follows:
  2568. 1. SGPRs before the Work-Group Ids are set by CP using the 16 User Data
  2569. registers.
  2570. 2. Work-group Id registers X, Y, Z are set by ADC which supports any
  2571. combination including none.
  2572. 3. Scratch Wavefront Offset is set by SPI in a per wavefront basis which is why
  2573. its value cannot included with the flat scratch init value which is per queue.
  2574. 4. The VGPRs are set by SPI which only supports specifying either (X), (X, Y)
  2575. or (X, Y, Z).
  2576. Flat Scratch register pair are adjacent SGRRs so they can be moved as a 64 bit
  2577. value to the hardware required SGPRn-3 and SGPRn-4 respectively.
  2578. The global segment can be accessed either using buffer instructions (GFX6 which
  2579. has V# 64 bit address support), flat instructions (GFX7-GFX10), or global
  2580. instructions (GFX9-GFX10).
  2581. If buffer operations are used then the compiler can generate a V# with the
  2582. following properties:
  2583. * base address of 0
  2584. * no swizzle
  2585. * ATC: 1 if IOMMU present (such as APU)
  2586. * ptr64: 1
  2587. * MTYPE set to support memory coherence that matches the runtime (such as CC for
  2588. APU and NC for dGPU).
  2589. .. _amdgpu-amdhsa-kernel-prolog:
  2590. Kernel Prolog
  2591. ~~~~~~~~~~~~~
  2592. .. _amdgpu-amdhsa-m0:
  2593. M0
  2594. ++
  2595. GFX6-GFX8
  2596. The M0 register must be initialized with a value at least the total LDS size
  2597. if the kernel may access LDS via DS or flat operations. Total LDS size is
  2598. available in dispatch packet. For M0, it is also possible to use maximum
  2599. possible value of LDS for given target (0x7FFF for GFX6 and 0xFFFF for
  2600. GFX7-GFX8).
  2601. GFX9-GFX10
  2602. The M0 register is not used for range checking LDS accesses and so does not
  2603. need to be initialized in the prolog.
  2604. .. _amdgpu-amdhsa-flat-scratch:
  2605. Flat Scratch
  2606. ++++++++++++
  2607. If the kernel may use flat operations to access scratch memory, the prolog code
  2608. must set up FLAT_SCRATCH register pair (FLAT_SCRATCH_LO/FLAT_SCRATCH_HI which
  2609. are in SGPRn-4/SGPRn-3). Initialization uses Flat Scratch Init and Scratch Wavefront
  2610. Offset SGPR registers (see :ref:`amdgpu-amdhsa-initial-kernel-execution-state`):
  2611. GFX6
  2612. Flat scratch is not supported.
  2613. GFX7-GFX8
  2614. 1. The low word of Flat Scratch Init is 32 bit byte offset from
  2615. ``SH_HIDDEN_PRIVATE_BASE_VIMID`` to the base of scratch backing memory
  2616. being managed by SPI for the queue executing the kernel dispatch. This is
  2617. the same value used in the Scratch Segment Buffer V# base address. The
  2618. prolog must add the value of Scratch Wavefront Offset to get the wavefront's byte
  2619. scratch backing memory offset from ``SH_HIDDEN_PRIVATE_BASE_VIMID``. Since
  2620. FLAT_SCRATCH_LO is in units of 256 bytes, the offset must be right shifted
  2621. by 8 before moving into FLAT_SCRATCH_LO.
  2622. 2. The second word of Flat Scratch Init is 32 bit byte size of a single
  2623. work-items scratch memory usage. This is directly loaded from the kernel
  2624. dispatch packet Private Segment Byte Size and rounded up to a multiple of
  2625. DWORD. Having CP load it once avoids loading it at the beginning of every
  2626. wavefront. The prolog must move it to FLAT_SCRATCH_LO for use as FLAT SCRATCH
  2627. SIZE.
  2628. GFX9-GFX10
  2629. The Flat Scratch Init is the 64 bit address of the base of scratch backing
  2630. memory being managed by SPI for the queue executing the kernel dispatch. The
  2631. prolog must add the value of Scratch Wavefront Offset and moved to the FLAT_SCRATCH
  2632. pair for use as the flat scratch base in flat memory instructions.
  2633. .. _amdgpu-amdhsa-memory-model:
  2634. Memory Model
  2635. ~~~~~~~~~~~~
  2636. This section describes the mapping of LLVM memory model onto AMDGPU machine code
  2637. (see :ref:`memmodel`). *The implementation is WIP.*
  2638. .. TODO
  2639. Update when implementation complete.
  2640. The AMDGPU backend supports the memory synchronization scopes specified in
  2641. :ref:`amdgpu-memory-scopes`.
  2642. The code sequences used to implement the memory model are defined in table
  2643. :ref:`amdgpu-amdhsa-memory-model-code-sequences-gfx6-gfx10-table`.
  2644. The sequences specify the order of instructions that a single thread must
  2645. execute. The ``s_waitcnt`` and ``buffer_wbinvl1_vol`` are defined with respect
  2646. to other memory instructions executed by the same thread. This allows them to be
  2647. moved earlier or later which can allow them to be combined with other instances
  2648. of the same instruction, or hoisted/sunk out of loops to improve
  2649. performance. Only the instructions related to the memory model are given;
  2650. additional ``s_waitcnt`` instructions are required to ensure registers are
  2651. defined before being used. These may be able to be combined with the memory
  2652. model ``s_waitcnt`` instructions as described above.
  2653. The AMDGPU backend supports the following memory models:
  2654. HSA Memory Model [HSA]_
  2655. The HSA memory model uses a single happens-before relation for all address
  2656. spaces (see :ref:`amdgpu-address-spaces`).
  2657. OpenCL Memory Model [OpenCL]_
  2658. The OpenCL memory model which has separate happens-before relations for the
  2659. global and local address spaces. Only a fence specifying both global and
  2660. local address space, and seq_cst instructions join the relationships. Since
  2661. the LLVM ``memfence`` instruction does not allow an address space to be
  2662. specified the OpenCL fence has to convervatively assume both local and
  2663. global address space was specified. However, optimizations can often be
  2664. done to eliminate the additional ``s_waitcnt`` instructions when there are
  2665. no intervening memory instructions which access the corresponding address
  2666. space. The code sequences in the table indicate what can be omitted for the
  2667. OpenCL memory. The target triple environment is used to determine if the
  2668. source language is OpenCL (see :ref:`amdgpu-opencl`).
  2669. ``ds/flat_load/store/atomic`` instructions to local memory are termed LDS
  2670. operations.
  2671. ``buffer/global/flat_load/store/atomic`` instructions to global memory are
  2672. termed vector memory operations.
  2673. For GFX6-GFX9:
  2674. * Each agent has multiple shader arrays (SA).
  2675. * Each SA has multiple compute units (CU).
  2676. * Each CU has multiple SIMDs that execute wavefronts.
  2677. * The wavefronts for a single work-group are executed in the same CU but may be
  2678. executed by different SIMDs.
  2679. * Each CU has a single LDS memory shared by the wavefronts of the work-groups
  2680. executing on it.
  2681. * All LDS operations of a CU are performed as wavefront wide operations in a
  2682. global order and involve no caching. Completion is reported to a wavefront in
  2683. execution order.
  2684. * The LDS memory has multiple request queues shared by the SIMDs of a
  2685. CU. Therefore, the LDS operations performed by different wavefronts of a work-group
  2686. can be reordered relative to each other, which can result in reordering the
  2687. visibility of vector memory operations with respect to LDS operations of other
  2688. wavefronts in the same work-group. A ``s_waitcnt lgkmcnt(0)`` is required to
  2689. ensure synchronization between LDS operations and vector memory operations
  2690. between wavefronts of a work-group, but not between operations performed by the
  2691. same wavefront.
  2692. * The vector memory operations are performed as wavefront wide operations and
  2693. completion is reported to a wavefront in execution order. The exception is
  2694. that for GFX7-GFX9 ``flat_load/store/atomic`` instructions can report out of
  2695. vector memory order if they access LDS memory, and out of LDS operation order
  2696. if they access global memory.
  2697. * The vector memory operations access a single vector L1 cache shared by all
  2698. SIMDs a CU. Therefore, no special action is required for coherence between the
  2699. lanes of a single wavefront, or for coherence between wavefronts in the same
  2700. work-group. A ``buffer_wbinvl1_vol`` is required for coherence between wavefronts
  2701. executing in different work-groups as they may be executing on different CUs.
  2702. * The scalar memory operations access a scalar L1 cache shared by all wavefronts
  2703. on a group of CUs. The scalar and vector L1 caches are not coherent. However,
  2704. scalar operations are used in a restricted way so do not impact the memory
  2705. model. See :ref:`amdgpu-amdhsa-memory-spaces`.
  2706. * The vector and scalar memory operations use an L2 cache shared by all CUs on
  2707. the same agent.
  2708. * The L2 cache has independent channels to service disjoint ranges of virtual
  2709. addresses.
  2710. * Each CU has a separate request queue per channel. Therefore, the vector and
  2711. scalar memory operations performed by wavefronts executing in different work-groups
  2712. (which may be executing on different CUs) of an agent can be reordered
  2713. relative to each other. A ``s_waitcnt vmcnt(0)`` is required to ensure
  2714. synchronization between vector memory operations of different CUs. It ensures a
  2715. previous vector memory operation has completed before executing a subsequent
  2716. vector memory or LDS operation and so can be used to meet the requirements of
  2717. acquire and release.
  2718. * The L2 cache can be kept coherent with other agents on some targets, or ranges
  2719. of virtual addresses can be set up to bypass it to ensure system coherence.
  2720. For GFX10:
  2721. * Each agent has multiple shader arrays (SA).
  2722. * Each SA has multiple work-group processors (WGP).
  2723. * Each WGP has multiple compute units (CU).
  2724. * Each CU has multiple SIMDs that execute wavefronts.
  2725. * The wavefronts for a single work-group are executed in the same
  2726. WGP. In CU wavefront execution mode the wavefronts may be executed by
  2727. different SIMDs in the same CU. In WGP wavefront execution mode the
  2728. wavefronts may be executed by different SIMDs in different CUs in the same
  2729. WGP.
  2730. * Each WGP has a single LDS memory shared by the wavefronts of the work-groups
  2731. executing on it.
  2732. * All LDS operations of a WGP are performed as wavefront wide operations in a
  2733. global order and involve no caching. Completion is reported to a wavefront in
  2734. execution order.
  2735. * The LDS memory has multiple request queues shared by the SIMDs of a
  2736. WGP. Therefore, the LDS operations performed by different wavefronts of a work-group
  2737. can be reordered relative to each other, which can result in reordering the
  2738. visibility of vector memory operations with respect to LDS operations of other
  2739. wavefronts in the same work-group. A ``s_waitcnt lgkmcnt(0)`` is required to
  2740. ensure synchronization between LDS operations and vector memory operations
  2741. between wavefronts of a work-group, but not between operations performed by the
  2742. same wavefront.
  2743. * The vector memory operations are performed as wavefront wide operations.
  2744. Completion of load/store/sample operations are reported to a wavefront in
  2745. execution order of other load/store/sample operations performed by that
  2746. wavefront.
  2747. * The vector memory operations access a vector L0 cache. There is a single L0
  2748. cache per CU. Each SIMD of a CU accesses the same L0 cache.
  2749. Therefore, no special action is required for coherence between the lanes of a
  2750. single wavefront. However, a ``BUFFER_GL0_INV`` is required for coherence
  2751. between wavefronts executing in the same work-group as they may be executing on
  2752. SIMDs of different CUs that access different L0s. A ``BUFFER_GL0_INV`` is also
  2753. required for coherence between wavefronts executing in different work-groups as
  2754. they may be executing on different WGPs.
  2755. * The scalar memory operations access a scalar L0 cache shared by all wavefronts
  2756. on a WGP. The scalar and vector L0 caches are not coherent. However, scalar
  2757. operations are used in a restricted way so do not impact the memory model. See
  2758. :ref:`amdgpu-amdhsa-memory-spaces`.
  2759. * The vector and scalar memory L0 caches use an L1 cache shared by all WGPs on
  2760. the same SA. Therefore, no special action is required for coherence between
  2761. the wavefronts of a single work-group. However, a ``BUFFER_GL1_INV`` is
  2762. required for coherence between wavefronts executing in different work-groups as
  2763. they may be executing on different SAs that access different L1s.
  2764. * The L1 caches have independent quadrants to service disjoint ranges of virtual
  2765. addresses.
  2766. * Each L0 cache has a separate request queue per L1 quadrant. Therefore, the
  2767. vector and scalar memory operations performed by different wavefronts, whether
  2768. executing in the same or different work-groups (which may be executing on
  2769. different CUs accessing different L0s), can be reordered relative to each
  2770. other. A ``s_waitcnt vmcnt(0) & vscnt(0)`` is required to ensure synchronization
  2771. between vector memory operations of different wavefronts. It ensures a previous
  2772. vector memory operation has completed before executing a subsequent vector
  2773. memory or LDS operation and so can be used to meet the requirements of acquire,
  2774. release and sequential consistency.
  2775. * The L1 caches use an L2 cache shared by all SAs on the same agent.
  2776. * The L2 cache has independent channels to service disjoint ranges of virtual
  2777. addresses.
  2778. * Each L1 quadrant of a single SA accesses a different L2 channel. Each L1
  2779. quadrant has a separate request queue per L2 channel. Therefore, the vector
  2780. and scalar memory operations performed by wavefronts executing in different
  2781. work-groups (which may be executing on different SAs) of an agent can be
  2782. reordered relative to each other. A ``s_waitcnt vmcnt(0) & vscnt(0)`` is
  2783. required to ensure synchronization between vector memory operations of
  2784. different SAs. It ensures a previous vector memory operation has completed
  2785. before executing a subsequent vector memory and so can be used to meet the
  2786. requirements of acquire, release and sequential consistency.
  2787. * The L2 cache can be kept coherent with other agents on some targets, or ranges
  2788. of virtual addresses can be set up to bypass it to ensure system coherence.
  2789. Private address space uses ``buffer_load/store`` using the scratch V# (GFX6-GFX8),
  2790. or ``scratch_load/store`` (GFX9-GFX10). Since only a single thread is accessing the
  2791. memory, atomic memory orderings are not meaningful and all accesses are treated
  2792. as non-atomic.
  2793. Constant address space uses ``buffer/global_load`` instructions (or equivalent
  2794. scalar memory instructions). Since the constant address space contents do not
  2795. change during the execution of a kernel dispatch it is not legal to perform
  2796. stores, and atomic memory orderings are not meaningful and all access are
  2797. treated as non-atomic.
  2798. A memory synchronization scope wider than work-group is not meaningful for the
  2799. group (LDS) address space and is treated as work-group.
  2800. The memory model does not support the region address space which is treated as
  2801. non-atomic.
  2802. Acquire memory ordering is not meaningful on store atomic instructions and is
  2803. treated as non-atomic.
  2804. Release memory ordering is not meaningful on load atomic instructions and is
  2805. treated a non-atomic.
  2806. Acquire-release memory ordering is not meaningful on load or store atomic
  2807. instructions and is treated as acquire and release respectively.
  2808. AMDGPU backend only uses scalar memory operations to access memory that is
  2809. proven to not change during the execution of the kernel dispatch. This includes
  2810. constant address space and global address space for program scope const
  2811. variables. Therefore the kernel machine code does not have to maintain the
  2812. scalar L1 cache to ensure it is coherent with the vector L1 cache. The scalar
  2813. and vector L1 caches are invalidated between kernel dispatches by CP since
  2814. constant address space data may change between kernel dispatch executions. See
  2815. :ref:`amdgpu-amdhsa-memory-spaces`.
  2816. The one execption is if scalar writes are used to spill SGPR registers. In this
  2817. case the AMDGPU backend ensures the memory location used to spill is never
  2818. accessed by vector memory operations at the same time. If scalar writes are used
  2819. then a ``s_dcache_wb`` is inserted before the ``s_endpgm`` and before a function
  2820. return since the locations may be used for vector memory instructions by a
  2821. future wavefront that uses the same scratch area, or a function call that creates a
  2822. frame at the same address, respectively. There is no need for a ``s_dcache_inv``
  2823. as all scalar writes are write-before-read in the same thread.
  2824. For GFX6-GFX9, scratch backing memory (which is used for the private address space)
  2825. is accessed with MTYPE NC_NV (non-coherenent non-volatile). Since the private
  2826. address space is only accessed by a single thread, and is always
  2827. write-before-read, there is never a need to invalidate these entries from the L1
  2828. cache. Hence all cache invalidates are done as ``*_vol`` to only invalidate the
  2829. volatile cache lines.
  2830. For GFX10, scratch backing memory (which is used for the private address space)
  2831. is accessed with MTYPE NC (non-coherenent). Since the private address space is
  2832. only accessed by a single thread, and is always write-before-read, there is
  2833. never a need to invalidate these entries from the L0 or L1 caches.
  2834. For GFX10, wavefronts are executed in native mode with in-order reporting of loads
  2835. and sample instructions. In this mode vmcnt reports completion of load, atomic
  2836. with return and sample instructions in order, and the vscnt reports the
  2837. completion of store and atomic without return in order. See ``MEM_ORDERED`` field
  2838. in :ref:`amdgpu-amdhsa-compute_pgm_rsrc1-gfx6-gfx10-table`.
  2839. In GFX10, wavefronts can be executed in WGP or CU wavefront execution mode:
  2840. * In WGP wavefront execution mode the wavefronts of a work-group are executed
  2841. on the SIMDs of both CUs of the WGP. Therefore, explicit management of the per
  2842. CU L0 caches is required for work-group synchronization. Also accesses to L1 at
  2843. work-group scope need to be expicitly ordered as the accesses from different
  2844. CUs are not ordered.
  2845. * In CU wavefront execution mode the wavefronts of a work-group are executed on
  2846. the SIMDs of a single CU of the WGP. Therefore, all global memory access by
  2847. the work-group access the same L0 which in turn ensures L1 accesses are
  2848. ordered and so do not require explicit management of the caches for
  2849. work-group synchronization.
  2850. See ``WGP_MODE`` field in :ref:`amdgpu-amdhsa-compute_pgm_rsrc1-gfx6-gfx10-table`
  2851. and :ref:`amdgpu-target-features`.
  2852. On dGPU the kernarg backing memory is accessed as UC (uncached) to avoid needing
  2853. to invalidate the L2 cache. For GFX6-GFX9, this also causes it to be treated as
  2854. non-volatile and so is not invalidated by ``*_vol``. On APU it is accessed as CC
  2855. (cache coherent) and so the L2 cache will be coherent with the CPU and other
  2856. agents.
  2857. .. table:: AMDHSA Memory Model Code Sequences GFX6-GFX10
  2858. :name: amdgpu-amdhsa-memory-model-code-sequences-gfx6-gfx10-table
  2859. ============ ============ ============== ========== =============================== ==================================
  2860. LLVM Instr LLVM Memory LLVM Memory AMDGPU AMDGPU Machine Code AMDGPU Machine Code
  2861. Ordering Sync Scope Address GFX6-9 GFX10
  2862. Space
  2863. ============ ============ ============== ========== =============================== ==================================
  2864. **Non-Atomic**
  2865. ----------------------------------------------------------------------------------------------------------------------
  2866. load *none* *none* - global - !volatile & !nontemporal - !volatile & !nontemporal
  2867. - generic
  2868. - private 1. buffer/global/flat_load 1. buffer/global/flat_load
  2869. - constant
  2870. - volatile & !nontemporal - volatile & !nontemporal
  2871. 1. buffer/global/flat_load 1. buffer/global/flat_load
  2872. glc=1 glc=1 dlc=1
  2873. - nontemporal - nontemporal
  2874. 1. buffer/global/flat_load 1. buffer/global/flat_load
  2875. glc=1 slc=1 slc=1
  2876. load *none* *none* - local 1. ds_load 1. ds_load
  2877. store *none* *none* - global - !nontemporal - !nontemporal
  2878. - generic
  2879. - private 1. buffer/global/flat_store 1. buffer/global/flat_store
  2880. - constant
  2881. - nontemporal - nontemporal
  2882. 1. buffer/global/flat_stote 1. buffer/global/flat_store
  2883. glc=1 slc=1 slc=1
  2884. store *none* *none* - local 1. ds_store 1. ds_store
  2885. **Unordered Atomic**
  2886. ----------------------------------------------------------------------------------------------------------------------
  2887. load atomic unordered *any* *any* *Same as non-atomic*. *Same as non-atomic*.
  2888. store atomic unordered *any* *any* *Same as non-atomic*. *Same as non-atomic*.
  2889. atomicrmw unordered *any* *any* *Same as monotonic *Same as monotonic
  2890. atomic*. atomic*.
  2891. **Monotonic Atomic**
  2892. ----------------------------------------------------------------------------------------------------------------------
  2893. load atomic monotonic - singlethread - global 1. buffer/global/flat_load 1. buffer/global/flat_load
  2894. - wavefront - generic
  2895. load atomic monotonic - workgroup - global 1. buffer/global/flat_load 1. buffer/global/flat_load
  2896. - generic glc=1
  2897. - If CU wavefront execution mode, omit glc=1.
  2898. load atomic monotonic - singlethread - local 1. ds_load 1. ds_load
  2899. - wavefront
  2900. - workgroup
  2901. load atomic monotonic - agent - global 1. buffer/global/flat_load 1. buffer/global/flat_load
  2902. - system - generic glc=1 glc=1 dlc=1
  2903. store atomic monotonic - singlethread - global 1. buffer/global/flat_store 1. buffer/global/flat_store
  2904. - wavefront - generic
  2905. - workgroup
  2906. - agent
  2907. - system
  2908. store atomic monotonic - singlethread - local 1. ds_store 1. ds_store
  2909. - wavefront
  2910. - workgroup
  2911. atomicrmw monotonic - singlethread - global 1. buffer/global/flat_atomic 1. buffer/global/flat_atomic
  2912. - wavefront - generic
  2913. - workgroup
  2914. - agent
  2915. - system
  2916. atomicrmw monotonic - singlethread - local 1. ds_atomic 1. ds_atomic
  2917. - wavefront
  2918. - workgroup
  2919. **Acquire Atomic**
  2920. ----------------------------------------------------------------------------------------------------------------------
  2921. load atomic acquire - singlethread - global 1. buffer/global/ds/flat_load 1. buffer/global/ds/flat_load
  2922. - wavefront - local
  2923. - generic
  2924. load atomic acquire - workgroup - global 1. buffer/global/flat_load 1. buffer/global_load glc=1
  2925. - If CU wavefront execution mode, omit glc=1.
  2926. 2. s_waitcnt vmcnt(0)
  2927. - If CU wavefront execution mode, omit.
  2928. - Must happen before
  2929. the following buffer_gl0_inv
  2930. and before any following
  2931. global/generic
  2932. load/load
  2933. atomic/stote/store
  2934. atomic/atomicrmw.
  2935. 3. buffer_gl0_inv
  2936. - If CU wavefront execution mode, omit.
  2937. - Ensures that
  2938. following
  2939. loads will not see
  2940. stale data.
  2941. load atomic acquire - workgroup - local 1. ds_load 1. ds_load
  2942. 2. s_waitcnt lgkmcnt(0) 2. s_waitcnt lgkmcnt(0)
  2943. - If OpenCL, omit. - If OpenCL, omit.
  2944. - Must happen before - Must happen before
  2945. any following the following buffer_gl0_inv
  2946. global/generic and before any following
  2947. load/load global/generic load/load
  2948. atomic/store/store atomic/store/store
  2949. atomic/atomicrmw. atomic/atomicrmw.
  2950. - Ensures any - Ensures any
  2951. following global following global
  2952. data read is no data read is no
  2953. older than the load older than the load
  2954. atomic value being atomic value being
  2955. acquired. acquired.
  2956. 3. buffer_gl0_inv
  2957. - If CU wavefront execution mode, omit.
  2958. - If OpenCL, omit.
  2959. - Ensures that
  2960. following
  2961. loads will not see
  2962. stale data.
  2963. load atomic acquire - workgroup - generic 1. flat_load 1. flat_load glc=1
  2964. - If CU wavefront execution mode, omit glc=1.
  2965. 2. s_waitcnt lgkmcnt(0) 2. s_waitcnt lgkmcnt(0) &
  2966. vmcnt(0)
  2967. - If CU wavefront execution mode, omit vmcnt.
  2968. - If OpenCL, omit. - If OpenCL, omit
  2969. lgkmcnt(0).
  2970. - Must happen before - Must happen before
  2971. any following the following
  2972. global/generic buffer_gl0_inv and any
  2973. load/load following global/generic
  2974. atomic/store/store load/load
  2975. atomic/atomicrmw. atomic/store/store
  2976. atomic/atomicrmw.
  2977. - Ensures any - Ensures any
  2978. following global following global
  2979. data read is no data read is no
  2980. older than the load older than the load
  2981. atomic value being atomic value being
  2982. acquired. acquired.
  2983. 3. buffer_gl0_inv
  2984. - If CU wavefront execution mode, omit.
  2985. - Ensures that
  2986. following
  2987. loads will not see
  2988. stale data.
  2989. load atomic acquire - agent - global 1. buffer/global/flat_load 1. buffer/global_load
  2990. - system glc=1 glc=1 dlc=1
  2991. 2. s_waitcnt vmcnt(0) 2. s_waitcnt vmcnt(0)
  2992. - Must happen before - Must happen before
  2993. following following
  2994. buffer_wbinvl1_vol. buffer_gl*_inv.
  2995. - Ensures the load - Ensures the load
  2996. has completed has completed
  2997. before invalidating before invalidating
  2998. the cache. the caches.
  2999. 3. buffer_wbinvl1_vol 3. buffer_gl0_inv;
  3000. buffer_gl1_inv
  3001. - Must happen before - Must happen before
  3002. any following any following
  3003. global/generic global/generic
  3004. load/load load/load
  3005. atomic/atomicrmw. atomic/atomicrmw.
  3006. - Ensures that - Ensures that
  3007. following following
  3008. loads will not see loads will not see
  3009. stale global data. stale global data.
  3010. load atomic acquire - agent - generic 1. flat_load glc=1 1. flat_load glc=1 dlc=1
  3011. - system 2. s_waitcnt vmcnt(0) & 2. s_waitcnt vmcnt(0) &
  3012. lgkmcnt(0) lgkmcnt(0)
  3013. - If OpenCL omit - If OpenCL omit
  3014. lgkmcnt(0). lgkmcnt(0).
  3015. - Must happen before - Must happen before
  3016. following following
  3017. buffer_wbinvl1_vol. buffer_gl*_invl.
  3018. - Ensures the flat_load - Ensures the flat_load
  3019. has completed has completed
  3020. before invalidating before invalidating
  3021. the cache. the caches.
  3022. 3. buffer_wbinvl1_vol 3. buffer_gl0_inv;
  3023. buffer_gl1_inv
  3024. - Must happen before - Must happen before
  3025. any following any following
  3026. global/generic global/generic
  3027. load/load load/load
  3028. atomic/atomicrmw. atomic/atomicrmw.
  3029. - Ensures that - Ensures that
  3030. following loads following loads
  3031. will not see stale will not see stale
  3032. global data. global data.
  3033. atomicrmw acquire - singlethread - global 1. buffer/global/ds/flat_atomic 1. buffer/global/ds/flat_atomic
  3034. - wavefront - local
  3035. - generic
  3036. atomicrmw acquire - workgroup - global 1. buffer/global/flat_atomic 1. buffer/global_atomic
  3037. 2. s_waitcnt vm/vscnt(0)
  3038. - If CU wavefront execution mode, omit.
  3039. - Use vmcnt if atomic with
  3040. return and vscnt if atomic
  3041. with no-return.
  3042. - Must happen before
  3043. the following buffer_gl0_inv
  3044. and before any following
  3045. global/generic
  3046. load/load
  3047. atomic/stote/store
  3048. atomic/atomicrmw.
  3049. 3. buffer_gl0_inv
  3050. - If CU wavefront execution mode, omit.
  3051. - Ensures that
  3052. following
  3053. loads will not see
  3054. stale data.
  3055. atomicrmw acquire - workgroup - local 1. ds_atomic 1. ds_atomic
  3056. 2. waitcnt lgkmcnt(0) 2. waitcnt lgkmcnt(0)
  3057. - If OpenCL, omit. - If OpenCL, omit.
  3058. - Must happen before - Must happen before
  3059. any following the following
  3060. global/generic buffer_gl0_inv.
  3061. load/load
  3062. atomic/store/store
  3063. atomic/atomicrmw.
  3064. - Ensures any - Ensures any
  3065. following global following global
  3066. data read is no data read is no
  3067. older than the older than the
  3068. atomicrmw value atomicrmw value
  3069. being acquired. being acquired.
  3070. 3. buffer_gl0_inv
  3071. - If OpenCL omit.
  3072. - Ensures that
  3073. following
  3074. loads will not see
  3075. stale data.
  3076. atomicrmw acquire - workgroup - generic 1. flat_atomic 1. flat_atomic
  3077. 2. waitcnt lgkmcnt(0) 2. waitcnt lgkmcnt(0) &
  3078. vm/vscnt(0)
  3079. - If CU wavefront execution mode, omit vm/vscnt.
  3080. - If OpenCL, omit. - If OpenCL, omit
  3081. waitcnt lgkmcnt(0)..
  3082. - Use vmcnt if atomic with
  3083. return and vscnt if atomic
  3084. with no-return.
  3085. waitcnt lgkmcnt(0).
  3086. - Must happen before - Must happen before
  3087. any following the following
  3088. global/generic buffer_gl0_inv.
  3089. load/load
  3090. atomic/store/store
  3091. atomic/atomicrmw.
  3092. - Ensures any - Ensures any
  3093. following global following global
  3094. data read is no data read is no
  3095. older than the older than the
  3096. atomicrmw value atomicrmw value
  3097. being acquired. being acquired.
  3098. 3. buffer_gl0_inv
  3099. - If CU wavefront execution mode, omit.
  3100. - Ensures that
  3101. following
  3102. loads will not see
  3103. stale data.
  3104. atomicrmw acquire - agent - global 1. buffer/global/flat_atomic 1. buffer/global_atomic
  3105. - system 2. s_waitcnt vmcnt(0) 2. s_waitcnt vm/vscnt(0)
  3106. - Use vmcnt if atomic with
  3107. return and vscnt if atomic
  3108. with no-return.
  3109. waitcnt lgkmcnt(0).
  3110. - Must happen before - Must happen before
  3111. following following
  3112. buffer_wbinvl1_vol. buffer_gl*_inv.
  3113. - Ensures the - Ensures the
  3114. atomicrmw has atomicrmw has
  3115. completed before completed before
  3116. invalidating the invalidating the
  3117. cache. caches.
  3118. 3. buffer_wbinvl1_vol 3. buffer_gl0_inv;
  3119. buffer_gl1_inv
  3120. - Must happen before - Must happen before
  3121. any following any following
  3122. global/generic global/generic
  3123. load/load load/load
  3124. atomic/atomicrmw. atomic/atomicrmw.
  3125. - Ensures that - Ensures that
  3126. following loads following loads
  3127. will not see stale will not see stale
  3128. global data. global data.
  3129. atomicrmw acquire - agent - generic 1. flat_atomic 1. flat_atomic
  3130. - system 2. s_waitcnt vmcnt(0) & 2. s_waitcnt vm/vscnt(0) &
  3131. lgkmcnt(0) lgkmcnt(0)
  3132. - If OpenCL, omit - If OpenCL, omit
  3133. lgkmcnt(0). lgkmcnt(0).
  3134. - Use vmcnt if atomic with
  3135. return and vscnt if atomic
  3136. with no-return.
  3137. - Must happen before - Must happen before
  3138. following following
  3139. buffer_wbinvl1_vol. buffer_gl*_inv.
  3140. - Ensures the - Ensures the
  3141. atomicrmw has atomicrmw has
  3142. completed before completed before
  3143. invalidating the invalidating the
  3144. cache. caches.
  3145. 3. buffer_wbinvl1_vol 3. buffer_gl0_inv;
  3146. buffer_gl1_inv
  3147. - Must happen before - Must happen before
  3148. any following any following
  3149. global/generic global/generic
  3150. load/load load/load
  3151. atomic/atomicrmw. atomic/atomicrmw.
  3152. - Ensures that - Ensures that
  3153. following loads following loads
  3154. will not see stale will not see stale
  3155. global data. global data.
  3156. fence acquire - singlethread *none* *none* *none*
  3157. - wavefront
  3158. fence acquire - workgroup *none* 1. s_waitcnt lgkmcnt(0) 1. s_waitcnt lgkmcnt(0) &
  3159. vmcnt(0) & vscnt(0)
  3160. - If CU wavefront execution mode, omit vmcnt and
  3161. vscnt.
  3162. - If OpenCL and - If OpenCL and
  3163. address space is address space is
  3164. not generic, omit. not generic, omit
  3165. lgkmcnt(0).
  3166. - If OpenCL and
  3167. address space is
  3168. local, omit
  3169. vmcnt(0) and vscnt(0).
  3170. - However, since LLVM - However, since LLVM
  3171. currently has no currently has no
  3172. address space on address space on
  3173. the fence need to the fence need to
  3174. conservatively conservatively
  3175. always generate. If always generate. If
  3176. fence had an fence had an
  3177. address space then address space then
  3178. set to address set to address
  3179. space of OpenCL space of OpenCL
  3180. fence flag, or to fence flag, or to
  3181. generic if both generic if both
  3182. local and global local and global
  3183. flags are flags are
  3184. specified. specified.
  3185. - Must happen after
  3186. any preceding
  3187. local/generic load
  3188. atomic/atomicrmw
  3189. with an equal or
  3190. wider sync scope
  3191. and memory ordering
  3192. stronger than
  3193. unordered (this is
  3194. termed the
  3195. fence-paired-atomic).
  3196. - Must happen before
  3197. any following
  3198. global/generic
  3199. load/load
  3200. atomic/store/store
  3201. atomic/atomicrmw.
  3202. - Ensures any
  3203. following global
  3204. data read is no
  3205. older than the
  3206. value read by the
  3207. fence-paired-atomic.
  3208. - Could be split into
  3209. separate s_waitcnt
  3210. vmcnt(0), s_waitcnt
  3211. vscnt(0) and s_waitcnt
  3212. lgkmcnt(0) to allow
  3213. them to be
  3214. independently moved
  3215. according to the
  3216. following rules.
  3217. - s_waitcnt vmcnt(0)
  3218. must happen after
  3219. any preceding
  3220. global/generic load
  3221. atomic/
  3222. atomicrmw-with-return-value
  3223. with an equal or
  3224. wider sync scope
  3225. and memory ordering
  3226. stronger than
  3227. unordered (this is
  3228. termed the
  3229. fence-paired-atomic).
  3230. - s_waitcnt vscnt(0)
  3231. must happen after
  3232. any preceding
  3233. global/generic
  3234. atomicrmw-no-return-value
  3235. with an equal or
  3236. wider sync scope
  3237. and memory ordering
  3238. stronger than
  3239. unordered (this is
  3240. termed the
  3241. fence-paired-atomic).
  3242. - s_waitcnt lgkmcnt(0)
  3243. must happen after
  3244. any preceding
  3245. local/generic load
  3246. atomic/atomicrmw
  3247. with an equal or
  3248. wider sync scope
  3249. and memory ordering
  3250. stronger than
  3251. unordered (this is
  3252. termed the
  3253. fence-paired-atomic).
  3254. - Must happen before
  3255. the following
  3256. buffer_gl0_inv.
  3257. - Ensures that the
  3258. fence-paired atomic
  3259. has completed
  3260. before invalidating
  3261. the
  3262. cache. Therefore
  3263. any following
  3264. locations read must
  3265. be no older than
  3266. the value read by
  3267. the
  3268. fence-paired-atomic.
  3269. 3. buffer_gl0_inv
  3270. - If CU wavefront execution mode, omit.
  3271. - Ensures that
  3272. following
  3273. loads will not see
  3274. stale data.
  3275. fence acquire - agent *none* 1. s_waitcnt lgkmcnt(0) & 1. s_waitcnt lgkmcnt(0) &
  3276. - system vmcnt(0) vmcnt(0) & vscnt(0)
  3277. - If OpenCL and - If OpenCL and
  3278. address space is address space is
  3279. not generic, omit not generic, omit
  3280. lgkmcnt(0). lgkmcnt(0).
  3281. - If OpenCL and
  3282. address space is
  3283. local, omit
  3284. vmcnt(0) and vscnt(0).
  3285. - However, since LLVM - However, since LLVM
  3286. currently has no currently has no
  3287. address space on address space on
  3288. the fence need to the fence need to
  3289. conservatively conservatively
  3290. always generate always generate
  3291. (see comment for (see comment for
  3292. previous fence). previous fence).
  3293. - Could be split into
  3294. separate s_waitcnt
  3295. vmcnt(0) and
  3296. s_waitcnt
  3297. lgkmcnt(0) to allow
  3298. them to be
  3299. independently moved
  3300. according to the
  3301. following rules.
  3302. - s_waitcnt vmcnt(0)
  3303. must happen after
  3304. any preceding
  3305. global/generic load
  3306. atomic/atomicrmw
  3307. with an equal or
  3308. wider sync scope
  3309. and memory ordering
  3310. stronger than
  3311. unordered (this is
  3312. termed the
  3313. fence-paired-atomic).
  3314. - s_waitcnt lgkmcnt(0)
  3315. must happen after
  3316. any preceding
  3317. local/generic load
  3318. atomic/atomicrmw
  3319. with an equal or
  3320. wider sync scope
  3321. and memory ordering
  3322. stronger than
  3323. unordered (this is
  3324. termed the
  3325. fence-paired-atomic).
  3326. - Must happen before
  3327. the following
  3328. buffer_wbinvl1_vol.
  3329. - Ensures that the
  3330. fence-paired atomic
  3331. has completed
  3332. before invalidating
  3333. the
  3334. cache. Therefore
  3335. any following
  3336. locations read must
  3337. be no older than
  3338. the value read by
  3339. the
  3340. fence-paired-atomic.
  3341. - Could be split into
  3342. separate s_waitcnt
  3343. vmcnt(0), s_waitcnt
  3344. vscnt(0) and s_waitcnt
  3345. lgkmcnt(0) to allow
  3346. them to be
  3347. independently moved
  3348. according to the
  3349. following rules.
  3350. - s_waitcnt vmcnt(0)
  3351. must happen after
  3352. any preceding
  3353. global/generic load
  3354. atomic/
  3355. atomicrmw-with-return-value
  3356. with an equal or
  3357. wider sync scope
  3358. and memory ordering
  3359. stronger than
  3360. unordered (this is
  3361. termed the
  3362. fence-paired-atomic).
  3363. - s_waitcnt vscnt(0)
  3364. must happen after
  3365. any preceding
  3366. global/generic
  3367. atomicrmw-no-return-value
  3368. with an equal or
  3369. wider sync scope
  3370. and memory ordering
  3371. stronger than
  3372. unordered (this is
  3373. termed the
  3374. fence-paired-atomic).
  3375. - s_waitcnt lgkmcnt(0)
  3376. must happen after
  3377. any preceding
  3378. local/generic load
  3379. atomic/atomicrmw
  3380. with an equal or
  3381. wider sync scope
  3382. and memory ordering
  3383. stronger than
  3384. unordered (this is
  3385. termed the
  3386. fence-paired-atomic).
  3387. - Must happen before
  3388. the following
  3389. buffer_gl*_inv.
  3390. - Ensures that the
  3391. fence-paired atomic
  3392. has completed
  3393. before invalidating
  3394. the
  3395. caches. Therefore
  3396. any following
  3397. locations read must
  3398. be no older than
  3399. the value read by
  3400. the
  3401. fence-paired-atomic.
  3402. 2. buffer_wbinvl1_vol 2. buffer_gl0_inv;
  3403. buffer_gl1_inv
  3404. - Must happen before any - Must happen before any
  3405. following global/generic following global/generic
  3406. load/load load/load
  3407. atomic/store/store atomic/store/store
  3408. atomic/atomicrmw. atomic/atomicrmw.
  3409. - Ensures that - Ensures that
  3410. following loads following loads
  3411. will not see stale will not see stale
  3412. global data. global data.
  3413. **Release Atomic**
  3414. ----------------------------------------------------------------------------------------------------------------------
  3415. store atomic release - singlethread - global 1. buffer/global/ds/flat_store 1. buffer/global/ds/flat_store
  3416. - wavefront - local
  3417. - generic
  3418. store atomic release - workgroup - global 1. s_waitcnt lgkmcnt(0) 1. s_waitcnt lgkmcnt(0) &
  3419. vmcnt(0) & vscnt(0)
  3420. - If CU wavefront execution mode, omit vmcnt and
  3421. vscnt.
  3422. - If OpenCL, omit. - If OpenCL, omit
  3423. lgkmcnt(0).
  3424. - Must happen after
  3425. any preceding
  3426. local/generic
  3427. load/store/load
  3428. atomic/store
  3429. atomic/atomicrmw.
  3430. - Could be split into
  3431. separate s_waitcnt
  3432. vmcnt(0), s_waitcnt
  3433. vscnt(0) and s_waitcnt
  3434. lgkmcnt(0) to allow
  3435. them to be
  3436. independently moved
  3437. according to the
  3438. following rules.
  3439. - s_waitcnt vmcnt(0)
  3440. must happen after
  3441. any preceding
  3442. global/generic load/load
  3443. atomic/
  3444. atomicrmw-with-return-value.
  3445. - s_waitcnt vscnt(0)
  3446. must happen after
  3447. any preceding
  3448. global/generic
  3449. store/store
  3450. atomic/
  3451. atomicrmw-no-return-value.
  3452. - s_waitcnt lgkmcnt(0)
  3453. must happen after
  3454. any preceding
  3455. local/generic
  3456. load/store/load
  3457. atomic/store
  3458. atomic/atomicrmw.
  3459. - Must happen before - Must happen before
  3460. the following the following
  3461. store. store.
  3462. - Ensures that all - Ensures that all
  3463. memory operations memory operations
  3464. to local have have
  3465. completed before completed before
  3466. performing the performing the
  3467. store that is being store that is being
  3468. released. released.
  3469. 2. buffer/global/flat_store 2. buffer/global_store
  3470. store atomic release - workgroup - local 1. waitcnt vmcnt(0) & vscnt(0)
  3471. - If CU wavefront execution mode, omit.
  3472. - If OpenCL, omit.
  3473. - Could be split into
  3474. separate s_waitcnt
  3475. vmcnt(0) and s_waitcnt
  3476. vscnt(0) to allow
  3477. them to be
  3478. independently moved
  3479. according to the
  3480. following rules.
  3481. - s_waitcnt vmcnt(0)
  3482. must happen after
  3483. any preceding
  3484. global/generic load/load
  3485. atomic/
  3486. atomicrmw-with-return-value.
  3487. - s_waitcnt vscnt(0)
  3488. must happen after
  3489. any preceding
  3490. global/generic
  3491. store/store atomic/
  3492. atomicrmw-no-return-value.
  3493. - Must happen before
  3494. the following
  3495. store.
  3496. - Ensures that all
  3497. global memory
  3498. operations have
  3499. completed before
  3500. performing the
  3501. store that is being
  3502. released.
  3503. 1. ds_store 2. ds_store
  3504. store atomic release - workgroup - generic 1. s_waitcnt lgkmcnt(0) 1. s_waitcnt lgkmcnt(0) &
  3505. vmcnt(0) & vscnt(0)
  3506. - If CU wavefront execution mode, omit vmcnt and
  3507. vscnt.
  3508. - If OpenCL, omit. - If OpenCL, omit
  3509. lgkmcnt(0).
  3510. - Must happen after
  3511. any preceding
  3512. local/generic
  3513. load/store/load
  3514. atomic/store
  3515. atomic/atomicrmw.
  3516. - Could be split into
  3517. separate s_waitcnt
  3518. vmcnt(0), s_waitcnt
  3519. vscnt(0) and s_waitcnt
  3520. lgkmcnt(0) to allow
  3521. them to be
  3522. independently moved
  3523. according to the
  3524. following rules.
  3525. - s_waitcnt vmcnt(0)
  3526. must happen after
  3527. any preceding
  3528. global/generic load/load
  3529. atomic/
  3530. atomicrmw-with-return-value.
  3531. - s_waitcnt vscnt(0)
  3532. must happen after
  3533. any preceding
  3534. global/generic
  3535. store/store
  3536. atomic/
  3537. atomicrmw-no-return-value.
  3538. - s_waitcnt lgkmcnt(0)
  3539. must happen after
  3540. any preceding
  3541. local/generic load/store/load
  3542. atomic/store atomic/atomicrmw.
  3543. - Must happen before - Must happen before
  3544. the following the following
  3545. store. store.
  3546. - Ensures that all - Ensures that all
  3547. memory operations memory operations
  3548. to local have have
  3549. completed before completed before
  3550. performing the performing the
  3551. store that is being store that is being
  3552. released. released.
  3553. 2. flat_store 2. flat_store
  3554. store atomic release - agent - global 1. s_waitcnt lgkmcnt(0) & 1. s_waitcnt lgkmcnt(0) &
  3555. - system - generic vmcnt(0) vmcnt(0) & vscnt(0)
  3556. - If OpenCL, omit - If OpenCL, omit
  3557. lgkmcnt(0). lgkmcnt(0).
  3558. - Could be split into - Could be split into
  3559. separate s_waitcnt separate s_waitcnt
  3560. vmcnt(0) and vmcnt(0), s_waitcnt vscnt(0)
  3561. s_waitcnt and s_waitcnt
  3562. lgkmcnt(0) to allow lgkmcnt(0) to allow
  3563. them to be them to be
  3564. independently moved independently moved
  3565. according to the according to the
  3566. following rules. following rules.
  3567. - s_waitcnt vmcnt(0) - s_waitcnt vmcnt(0)
  3568. must happen after must happen after
  3569. any preceding any preceding
  3570. global/generic global/generic
  3571. load/store/load load/load
  3572. atomic/store atomic/
  3573. atomic/atomicrmw. atomicrmw-with-return-value.
  3574. - s_waitcnt vscnt(0)
  3575. must happen after
  3576. any preceding
  3577. global/generic
  3578. store/store atomic/
  3579. atomicrmw-no-return-value.
  3580. - s_waitcnt lgkmcnt(0) - s_waitcnt lgkmcnt(0)
  3581. must happen after must happen after
  3582. any preceding any preceding
  3583. local/generic local/generic
  3584. load/store/load load/store/load
  3585. atomic/store atomic/store
  3586. atomic/atomicrmw. atomic/atomicrmw.
  3587. - Must happen before - Must happen before
  3588. the following the following
  3589. store. store.
  3590. - Ensures that all - Ensures that all
  3591. memory operations memory operations
  3592. to memory have to memory have
  3593. completed before completed before
  3594. performing the performing the
  3595. store that is being store that is being
  3596. released. released.
  3597. 2. buffer/global/ds/flat_store 2. buffer/global/ds/flat_store
  3598. atomicrmw release - singlethread - global 1. buffer/global/ds/flat_atomic 1. buffer/global/ds/flat_atomic
  3599. - wavefront - local
  3600. - generic
  3601. atomicrmw release - workgroup - global 1. s_waitcnt lgkmcnt(0) 1. s_waitcnt lgkmcnt(0) &
  3602. vmcnt(0) & vscnt(0)
  3603. - If CU wavefront execution mode, omit vmcnt and
  3604. vscnt.
  3605. - If OpenCL, omit.
  3606. - Must happen after
  3607. any preceding
  3608. local/generic
  3609. load/store/load
  3610. atomic/store
  3611. atomic/atomicrmw.
  3612. - Could be split into
  3613. separate s_waitcnt
  3614. vmcnt(0), s_waitcnt
  3615. vscnt(0) and s_waitcnt
  3616. lgkmcnt(0) to allow
  3617. them to be
  3618. independently moved
  3619. according to the
  3620. following rules.
  3621. - s_waitcnt vmcnt(0)
  3622. must happen after
  3623. any preceding
  3624. global/generic load/load
  3625. atomic/
  3626. atomicrmw-with-return-value.
  3627. - s_waitcnt vscnt(0)
  3628. must happen after
  3629. any preceding
  3630. global/generic
  3631. store/store
  3632. atomic/
  3633. atomicrmw-no-return-value.
  3634. - s_waitcnt lgkmcnt(0)
  3635. must happen after
  3636. any preceding
  3637. local/generic
  3638. load/store/load
  3639. atomic/store
  3640. atomic/atomicrmw.
  3641. - Must happen before - Must happen before
  3642. the following the following
  3643. atomicrmw. atomicrmw.
  3644. - Ensures that all - Ensures that all
  3645. memory operations memory operations
  3646. to local have have
  3647. completed before completed before
  3648. performing the performing the
  3649. atomicrmw that is atomicrmw that is
  3650. being released. being released.
  3651. 2. buffer/global/flat_atomic 2. buffer/global_atomic
  3652. atomicrmw release - workgroup - local 1. waitcnt vmcnt(0) & vscnt(0)
  3653. - If CU wavefront execution mode, omit.
  3654. - If OpenCL, omit.
  3655. - Could be split into
  3656. separate s_waitcnt
  3657. vmcnt(0) and s_waitcnt
  3658. vscnt(0) to allow
  3659. them to be
  3660. independently moved
  3661. according to the
  3662. following rules.
  3663. - s_waitcnt vmcnt(0)
  3664. must happen after
  3665. any preceding
  3666. global/generic load/load
  3667. atomic/
  3668. atomicrmw-with-return-value.
  3669. - s_waitcnt vscnt(0)
  3670. must happen after
  3671. any preceding
  3672. global/generic
  3673. store/store atomic/
  3674. atomicrmw-no-return-value.
  3675. - Must happen before
  3676. the following
  3677. store.
  3678. - Ensures that all
  3679. global memory
  3680. operations have
  3681. completed before
  3682. performing the
  3683. store that is being
  3684. released.
  3685. 1. ds_atomic 2. ds_atomic
  3686. atomicrmw release - workgroup - generic 1. s_waitcnt lgkmcnt(0) 1. s_waitcnt lgkmcnt(0) &
  3687. vmcnt(0) & vscnt(0)
  3688. - If CU wavefront execution mode, omit vmcnt and
  3689. vscnt.
  3690. - If OpenCL, omit. - If OpenCL, omit
  3691. waitcnt lgkmcnt(0).
  3692. - Must happen after
  3693. any preceding
  3694. local/generic
  3695. load/store/load
  3696. atomic/store
  3697. atomic/atomicrmw.
  3698. - Could be split into
  3699. separate s_waitcnt
  3700. vmcnt(0), s_waitcnt
  3701. vscnt(0) and s_waitcnt
  3702. lgkmcnt(0) to allow
  3703. them to be
  3704. independently moved
  3705. according to the
  3706. following rules.
  3707. - s_waitcnt vmcnt(0)
  3708. must happen after
  3709. any preceding
  3710. global/generic load/load
  3711. atomic/
  3712. atomicrmw-with-return-value.
  3713. - s_waitcnt vscnt(0)
  3714. must happen after
  3715. any preceding
  3716. global/generic
  3717. store/store
  3718. atomic/
  3719. atomicrmw-no-return-value.
  3720. - s_waitcnt lgkmcnt(0)
  3721. must happen after
  3722. any preceding
  3723. local/generic load/store/load
  3724. atomic/store atomic/atomicrmw.
  3725. - Must happen before - Must happen before
  3726. the following the following
  3727. atomicrmw. atomicrmw.
  3728. - Ensures that all - Ensures that all
  3729. memory operations memory operations
  3730. to local have have
  3731. completed before completed before
  3732. performing the performing the
  3733. atomicrmw that is atomicrmw that is
  3734. being released. being released.
  3735. 2. flat_atomic 2. flat_atomic
  3736. atomicrmw release - agent - global 1. s_waitcnt lgkmcnt(0) & 1. s_waitcnt lkkmcnt(0) &
  3737. - system - generic vmcnt(0) vmcnt(0) & vscnt(0)
  3738. - If OpenCL, omit - If OpenCL, omit
  3739. lgkmcnt(0). lgkmcnt(0).
  3740. - Could be split into - Could be split into
  3741. separate s_waitcnt separate s_waitcnt
  3742. vmcnt(0) and vmcnt(0), s_waitcnt
  3743. s_waitcnt vscnt(0) and s_waitcnt
  3744. lgkmcnt(0) to allow lgkmcnt(0) to allow
  3745. them to be them to be
  3746. independently moved independently moved
  3747. according to the according to the
  3748. following rules. following rules.
  3749. - s_waitcnt vmcnt(0) - s_waitcnt vmcnt(0)
  3750. must happen after must happen after
  3751. any preceding any preceding
  3752. global/generic global/generic
  3753. load/store/load load/load atomic/
  3754. atomic/store atomicrmw-with-return-value.
  3755. atomic/atomicrmw.
  3756. - s_waitcnt vscnt(0)
  3757. must happen after
  3758. any preceding
  3759. global/generic
  3760. store/store atomic/
  3761. atomicrmw-no-return-value.
  3762. - s_waitcnt lgkmcnt(0) - s_waitcnt lgkmcnt(0)
  3763. must happen after must happen after
  3764. any preceding any preceding
  3765. local/generic local/generic
  3766. load/store/load load/store/load
  3767. atomic/store atomic/store
  3768. atomic/atomicrmw. atomic/atomicrmw.
  3769. - Must happen before - Must happen before
  3770. the following the following
  3771. atomicrmw. atomicrmw.
  3772. - Ensures that all - Ensures that all
  3773. memory operations memory operations
  3774. to global and local to global and local
  3775. have completed have completed
  3776. before performing before performing
  3777. the atomicrmw that the atomicrmw that
  3778. is being released. is being released.
  3779. 2. buffer/global/ds/flat_atomic 2. buffer/global/ds/flat_atomic
  3780. fence release - singlethread *none* *none* *none*
  3781. - wavefront
  3782. fence release - workgroup *none* 1. s_waitcnt lgkmcnt(0) 1. s_waitcnt lgkmcnt(0) &
  3783. vmcnt(0) & vscnt(0)
  3784. - If CU wavefront execution mode, omit vmcnt and
  3785. vscnt.
  3786. - If OpenCL and - If OpenCL and
  3787. address space is address space is
  3788. not generic, omit. not generic, omit
  3789. lgkmcnt(0).
  3790. - If OpenCL and
  3791. address space is
  3792. local, omit
  3793. vmcnt(0) and vscnt(0).
  3794. - However, since LLVM - However, since LLVM
  3795. currently has no currently has no
  3796. address space on address space on
  3797. the fence need to the fence need to
  3798. conservatively conservatively
  3799. always generate. If always generate. If
  3800. fence had an fence had an
  3801. address space then address space then
  3802. set to address set to address
  3803. space of OpenCL space of OpenCL
  3804. fence flag, or to fence flag, or to
  3805. generic if both generic if both
  3806. local and global local and global
  3807. flags are flags are
  3808. specified. specified.
  3809. - Must happen after
  3810. any preceding
  3811. local/generic
  3812. load/load
  3813. atomic/store/store
  3814. atomic/atomicrmw.
  3815. - Could be split into
  3816. separate s_waitcnt
  3817. vmcnt(0), s_waitcnt
  3818. vscnt(0) and s_waitcnt
  3819. lgkmcnt(0) to allow
  3820. them to be
  3821. independently moved
  3822. according to the
  3823. following rules.
  3824. - s_waitcnt vmcnt(0)
  3825. must happen after
  3826. any preceding
  3827. global/generic
  3828. load/load
  3829. atomic/
  3830. atomicrmw-with-return-value.
  3831. - s_waitcnt vscnt(0)
  3832. must happen after
  3833. any preceding
  3834. global/generic
  3835. store/store atomic/
  3836. atomicrmw-no-return-value.
  3837. - s_waitcnt lgkmcnt(0)
  3838. must happen after
  3839. any preceding
  3840. local/generic
  3841. load/store/load
  3842. atomic/store atomic/
  3843. atomicrmw.
  3844. - Must happen before - Must happen before
  3845. any following store any following store
  3846. atomic/atomicrmw atomic/atomicrmw
  3847. with an equal or with an equal or
  3848. wider sync scope wider sync scope
  3849. and memory ordering and memory ordering
  3850. stronger than stronger than
  3851. unordered (this is unordered (this is
  3852. termed the termed the
  3853. fence-paired-atomic). fence-paired-atomic).
  3854. - Ensures that all - Ensures that all
  3855. memory operations memory operations
  3856. to local have have
  3857. completed before completed before
  3858. performing the performing the
  3859. following following
  3860. fence-paired-atomic. fence-paired-atomic.
  3861. fence release - agent *none* 1. s_waitcnt lgkmcnt(0) & 1. s_waitcnt lgkmcnt(0) &
  3862. - system vmcnt(0) vmcnt(0) & vscnt(0)
  3863. - If OpenCL and - If OpenCL and
  3864. address space is address space is
  3865. not generic, omit not generic, omit
  3866. lgkmcnt(0). lgkmcnt(0).
  3867. - If OpenCL and - If OpenCL and
  3868. address space is address space is
  3869. local, omit local, omit
  3870. vmcnt(0). vmcnt(0) and vscnt(0).
  3871. - However, since LLVM - However, since LLVM
  3872. currently has no currently has no
  3873. address space on address space on
  3874. the fence need to the fence need to
  3875. conservatively conservatively
  3876. always generate. If always generate. If
  3877. fence had an fence had an
  3878. address space then address space then
  3879. set to address set to address
  3880. space of OpenCL space of OpenCL
  3881. fence flag, or to fence flag, or to
  3882. generic if both generic if both
  3883. local and global local and global
  3884. flags are flags are
  3885. specified. specified.
  3886. - Could be split into - Could be split into
  3887. separate s_waitcnt separate s_waitcnt
  3888. vmcnt(0) and vmcnt(0), s_waitcnt
  3889. s_waitcnt vscnt(0) and s_waitcnt
  3890. lgkmcnt(0) to allow lgkmcnt(0) to allow
  3891. them to be them to be
  3892. independently moved independently moved
  3893. according to the according to the
  3894. following rules. following rules.
  3895. - s_waitcnt vmcnt(0) - s_waitcnt vmcnt(0)
  3896. must happen after must happen after
  3897. any preceding any preceding
  3898. global/generic global/generic
  3899. load/store/load load/load atomic/
  3900. atomic/store atomicrmw-with-return-value.
  3901. atomic/atomicrmw.
  3902. - s_waitcnt vscnt(0)
  3903. must happen after
  3904. any preceding
  3905. global/generic
  3906. store/store atomic/
  3907. atomicrmw-no-return-value.
  3908. - s_waitcnt lgkmcnt(0) - s_waitcnt lgkmcnt(0)
  3909. must happen after must happen after
  3910. any preceding any preceding
  3911. local/generic local/generic
  3912. load/store/load load/store/load
  3913. atomic/store atomic/store
  3914. atomic/atomicrmw. atomic/atomicrmw.
  3915. - Must happen before - Must happen before
  3916. any following store any following store
  3917. atomic/atomicrmw atomic/atomicrmw
  3918. with an equal or with an equal or
  3919. wider sync scope wider sync scope
  3920. and memory ordering and memory ordering
  3921. stronger than stronger than
  3922. unordered (this is unordered (this is
  3923. termed the termed the
  3924. fence-paired-atomic). fence-paired-atomic).
  3925. - Ensures that all - Ensures that all
  3926. memory operations memory operations
  3927. have have
  3928. completed before completed before
  3929. performing the performing the
  3930. following following
  3931. fence-paired-atomic. fence-paired-atomic.
  3932. **Acquire-Release Atomic**
  3933. ----------------------------------------------------------------------------------------------------------------------
  3934. atomicrmw acq_rel - singlethread - global 1. buffer/global/ds/flat_atomic 1. buffer/global/ds/flat_atomic
  3935. - wavefront - local
  3936. - generic
  3937. atomicrmw acq_rel - workgroup - global 1. s_waitcnt lgkmcnt(0) 1. s_waitcnt lgkmcnt(0) &
  3938. vmcnt(0) & vscnt(0)
  3939. - If CU wavefront execution mode, omit vmcnt and
  3940. vscnt.
  3941. - If OpenCL, omit. - If OpenCL, omit
  3942. s_waitcnt lgkmcnt(0).
  3943. - Must happen after - Must happen after
  3944. any preceding any preceding
  3945. local/generic local/generic
  3946. load/store/load load/store/load
  3947. atomic/store atomic/store
  3948. atomic/atomicrmw. atomic/atomicrmw.
  3949. - Could be split into
  3950. separate s_waitcnt
  3951. vmcnt(0), s_waitcnt
  3952. vscnt(0) and s_waitcnt
  3953. lgkmcnt(0) to allow
  3954. them to be
  3955. independently moved
  3956. according to the
  3957. following rules.
  3958. - s_waitcnt vmcnt(0)
  3959. must happen after
  3960. any preceding
  3961. global/generic load/load
  3962. atomic/
  3963. atomicrmw-with-return-value.
  3964. - s_waitcnt vscnt(0)
  3965. must happen after
  3966. any preceding
  3967. global/generic
  3968. store/store
  3969. atomic/
  3970. atomicrmw-no-return-value.
  3971. - s_waitcnt lgkmcnt(0)
  3972. must happen after
  3973. any preceding
  3974. local/generic load/store/load
  3975. atomic/store atomic/atomicrmw.
  3976. - Must happen before - Must happen before
  3977. the following the following
  3978. atomicrmw. atomicrmw.
  3979. - Ensures that all - Ensures that all
  3980. memory operations memory operations
  3981. to local have have
  3982. completed before completed before
  3983. performing the performing the
  3984. atomicrmw that is atomicrmw that is
  3985. being released. being released.
  3986. 2. buffer/global/flat_atomic 2. buffer/global_atomic
  3987. 3. s_waitcnt vm/vscnt(0)
  3988. - If CU wavefront execution mode, omit vm/vscnt.
  3989. - Use vmcnt if atomic with
  3990. return and vscnt if atomic
  3991. with no-return.
  3992. waitcnt lgkmcnt(0).
  3993. - Must happen before
  3994. the following
  3995. buffer_gl0_inv.
  3996. - Ensures any
  3997. following global
  3998. data read is no
  3999. older than the
  4000. atomicrmw value
  4001. being acquired.
  4002. 4. buffer_gl0_inv
  4003. - If CU wavefront execution mode, omit.
  4004. - Ensures that
  4005. following
  4006. loads will not see
  4007. stale data.
  4008. atomicrmw acq_rel - workgroup - local 1. waitcnt vmcnt(0) & vscnt(0)
  4009. - If CU wavefront execution mode, omit.
  4010. - If OpenCL, omit.
  4011. - Could be split into
  4012. separate s_waitcnt
  4013. vmcnt(0) and s_waitcnt
  4014. vscnt(0) to allow
  4015. them to be
  4016. independently moved
  4017. according to the
  4018. following rules.
  4019. - s_waitcnt vmcnt(0)
  4020. must happen after
  4021. any preceding
  4022. global/generic load/load
  4023. atomic/
  4024. atomicrmw-with-return-value.
  4025. - s_waitcnt vscnt(0)
  4026. must happen after
  4027. any preceding
  4028. global/generic
  4029. store/store atomic/
  4030. atomicrmw-no-return-value.
  4031. - Must happen before
  4032. the following
  4033. store.
  4034. - Ensures that all
  4035. global memory
  4036. operations have
  4037. completed before
  4038. performing the
  4039. store that is being
  4040. released.
  4041. 1. ds_atomic 2. ds_atomic
  4042. 2. s_waitcnt lgkmcnt(0) 3. s_waitcnt lgkmcnt(0)
  4043. - If OpenCL, omit. - If OpenCL, omit.
  4044. - Must happen before - Must happen before
  4045. any following the following
  4046. global/generic buffer_gl0_inv.
  4047. load/load
  4048. atomic/store/store
  4049. atomic/atomicrmw.
  4050. - Ensures any - Ensures any
  4051. following global following global
  4052. data read is no data read is no
  4053. older than the load older than the load
  4054. atomic value being atomic value being
  4055. acquired. acquired.
  4056. 4. buffer_gl0_inv
  4057. - If CU wavefront execution mode, omit.
  4058. - If OpenCL omit.
  4059. - Ensures that
  4060. following
  4061. loads will not see
  4062. stale data.
  4063. atomicrmw acq_rel - workgroup - generic 1. s_waitcnt lgkmcnt(0) 1. s_waitcnt lgkmcnt(0) &
  4064. vmcnt(0) & vscnt(0)
  4065. - If CU wavefront execution mode, omit vmcnt and
  4066. vscnt.
  4067. - If OpenCL, omit. - If OpenCL, omit
  4068. waitcnt lgkmcnt(0).
  4069. - Must happen after
  4070. any preceding
  4071. local/generic
  4072. load/store/load
  4073. atomic/store
  4074. atomic/atomicrmw.
  4075. - Could be split into
  4076. separate s_waitcnt
  4077. vmcnt(0), s_waitcnt
  4078. vscnt(0) and s_waitcnt
  4079. lgkmcnt(0) to allow
  4080. them to be
  4081. independently moved
  4082. according to the
  4083. following rules.
  4084. - s_waitcnt vmcnt(0)
  4085. must happen after
  4086. any preceding
  4087. global/generic load/load
  4088. atomic/
  4089. atomicrmw-with-return-value.
  4090. - s_waitcnt vscnt(0)
  4091. must happen after
  4092. any preceding
  4093. global/generic
  4094. store/store
  4095. atomic/
  4096. atomicrmw-no-return-value.
  4097. - s_waitcnt lgkmcnt(0)
  4098. must happen after
  4099. any preceding
  4100. local/generic load/store/load
  4101. atomic/store atomic/atomicrmw.
  4102. - Must happen before - Must happen before
  4103. the following the following
  4104. atomicrmw. atomicrmw.
  4105. - Ensures that all - Ensures that all
  4106. memory operations memory operations
  4107. to local have have
  4108. completed before completed before
  4109. performing the performing the
  4110. atomicrmw that is atomicrmw that is
  4111. being released. being released.
  4112. 2. flat_atomic 2. flat_atomic
  4113. 3. s_waitcnt lgkmcnt(0) 3. s_waitcnt lgkmcnt(0) &
  4114. vm/vscnt(0)
  4115. - If CU wavefront execution mode, omit vm/vscnt.
  4116. - If OpenCL, omit. - If OpenCL, omit
  4117. waitcnt lgkmcnt(0).
  4118. - Must happen before - Must happen before
  4119. any following the following
  4120. global/generic buffer_gl0_inv.
  4121. load/load
  4122. atomic/store/store
  4123. atomic/atomicrmw.
  4124. - Ensures any - Ensures any
  4125. following global following global
  4126. data read is no data read is no
  4127. older than the load older than the load
  4128. atomic value being atomic value being
  4129. acquired. acquired.
  4130. 3. buffer_gl0_inv
  4131. - If CU wavefront execution mode, omit.
  4132. - Ensures that
  4133. following
  4134. loads will not see
  4135. stale data.
  4136. atomicrmw acq_rel - agent - global 1. s_waitcnt lgkmcnt(0) & 1. s_waitcnt lgkmcnt(0) &
  4137. - system vmcnt(0) vmcnt(0) & vscnt(0)
  4138. - If OpenCL, omit - If OpenCL, omit
  4139. lgkmcnt(0). lgkmcnt(0).
  4140. - Could be split into - Could be split into
  4141. separate s_waitcnt separate s_waitcnt
  4142. vmcnt(0) and vmcnt(0), s_waitcnt
  4143. s_waitcnt vscnt(0) and s_waitcnt
  4144. lgkmcnt(0) to allow lgkmcnt(0) to allow
  4145. them to be them to be
  4146. independently moved independently moved
  4147. according to the according to the
  4148. following rules. following rules.
  4149. - s_waitcnt vmcnt(0) - s_waitcnt vmcnt(0)
  4150. must happen after must happen after
  4151. any preceding any preceding
  4152. global/generic global/generic
  4153. load/store/load load/load atomic/
  4154. atomic/store atomicrmw-with-return-value.
  4155. atomic/atomicrmw.
  4156. - s_waitcnt vscnt(0)
  4157. must happen after
  4158. any preceding
  4159. global/generic
  4160. store/store atomic/
  4161. atomicrmw-no-return-value.
  4162. - s_waitcnt lgkmcnt(0) - s_waitcnt lgkmcnt(0)
  4163. must happen after must happen after
  4164. any preceding any preceding
  4165. local/generic local/generic
  4166. load/store/load load/store/load
  4167. atomic/store atomic/store
  4168. atomic/atomicrmw. atomic/atomicrmw.
  4169. - Must happen before - Must happen before
  4170. the following the following
  4171. atomicrmw. atomicrmw.
  4172. - Ensures that all - Ensures that all
  4173. memory operations memory operations
  4174. to global have to global have
  4175. completed before completed before
  4176. performing the performing the
  4177. atomicrmw that is atomicrmw that is
  4178. being released. being released.
  4179. 2. buffer/global/flat_atomic 2. buffer/global_atomic
  4180. 3. s_waitcnt vmcnt(0) 3. s_waitcnt vm/vscnt(0)
  4181. - Use vmcnt if atomic with
  4182. return and vscnt if atomic
  4183. with no-return.
  4184. waitcnt lgkmcnt(0).
  4185. - Must happen before - Must happen before
  4186. following following
  4187. buffer_wbinvl1_vol. buffer_gl*_inv.
  4188. - Ensures the - Ensures the
  4189. atomicrmw has atomicrmw has
  4190. completed before completed before
  4191. invalidating the invalidating the
  4192. cache. caches.
  4193. 4. buffer_wbinvl1_vol 4. buffer_gl0_inv;
  4194. buffer_gl1_inv
  4195. - Must happen before - Must happen before
  4196. any following any following
  4197. global/generic global/generic
  4198. load/load load/load
  4199. atomic/atomicrmw. atomic/atomicrmw.
  4200. - Ensures that - Ensures that
  4201. following loads following loads
  4202. will not see stale will not see stale
  4203. global data. global data.
  4204. atomicrmw acq_rel - agent - generic 1. s_waitcnt lgkmcnt(0) & 1. s_waitcnt lgkmcnt(0) &
  4205. - system vmcnt(0) vmcnt(0) & vscnt(0)
  4206. - If OpenCL, omit - If OpenCL, omit
  4207. lgkmcnt(0). lgkmcnt(0).
  4208. - Could be split into - Could be split into
  4209. separate s_waitcnt separate s_waitcnt
  4210. vmcnt(0) and vmcnt(0), s_waitcnt
  4211. s_waitcnt vscnt(0) and s_waitcnt
  4212. lgkmcnt(0) to allow lgkmcnt(0) to allow
  4213. them to be them to be
  4214. independently moved independently moved
  4215. according to the according to the
  4216. following rules. following rules.
  4217. - s_waitcnt vmcnt(0) - s_waitcnt vmcnt(0)
  4218. must happen after must happen after
  4219. any preceding any preceding
  4220. global/generic global/generic
  4221. load/store/load load/load atomic
  4222. atomic/store atomicrmw-with-return-value.
  4223. atomic/atomicrmw.
  4224. - s_waitcnt vscnt(0)
  4225. must happen after
  4226. any preceding
  4227. global/generic
  4228. store/store atomic/
  4229. atomicrmw-no-return-value.
  4230. - s_waitcnt lgkmcnt(0) - s_waitcnt lgkmcnt(0)
  4231. must happen after must happen after
  4232. any preceding any preceding
  4233. local/generic local/generic
  4234. load/store/load load/store/load
  4235. atomic/store atomic/store
  4236. atomic/atomicrmw. atomic/atomicrmw.
  4237. - Must happen before - Must happen before
  4238. the following the following
  4239. atomicrmw. atomicrmw.
  4240. - Ensures that all - Ensures that all
  4241. memory operations memory operations
  4242. to global have have
  4243. completed before completed before
  4244. performing the performing the
  4245. atomicrmw that is atomicrmw that is
  4246. being released. being released.
  4247. 2. flat_atomic 2. flat_atomic
  4248. 3. s_waitcnt vmcnt(0) & 3. s_waitcnt vm/vscnt(0) &
  4249. lgkmcnt(0) lgkmcnt(0)
  4250. - If OpenCL, omit - If OpenCL, omit
  4251. lgkmcnt(0). lgkmcnt(0).
  4252. - Use vmcnt if atomic with
  4253. return and vscnt if atomic
  4254. with no-return.
  4255. - Must happen before - Must happen before
  4256. following following
  4257. buffer_wbinvl1_vol. buffer_gl*_inv.
  4258. - Ensures the - Ensures the
  4259. atomicrmw has atomicrmw has
  4260. completed before completed before
  4261. invalidating the invalidating the
  4262. cache. caches.
  4263. 4. buffer_wbinvl1_vol 4. buffer_gl0_inv;
  4264. buffer_gl1_inv
  4265. - Must happen before - Must happen before
  4266. any following any following
  4267. global/generic global/generic
  4268. load/load load/load
  4269. atomic/atomicrmw. atomic/atomicrmw.
  4270. - Ensures that - Ensures that
  4271. following loads following loads
  4272. will not see stale will not see stale
  4273. global data. global data.
  4274. fence acq_rel - singlethread *none* *none* *none*
  4275. - wavefront
  4276. fence acq_rel - workgroup *none* 1. s_waitcnt lgkmcnt(0) 1. s_waitcnt lgkmcnt(0) &
  4277. vmcnt(0) & vscnt(0)
  4278. - If CU wavefront execution mode, omit vmcnt and
  4279. vscnt.
  4280. - If OpenCL and - If OpenCL and
  4281. address space is address space is
  4282. not generic, omit. not generic, omit
  4283. lgkmcnt(0).
  4284. - If OpenCL and
  4285. address space is
  4286. local, omit
  4287. vmcnt(0) and vscnt(0).
  4288. - However, - However,
  4289. since LLVM since LLVM
  4290. currently has no currently has no
  4291. address space on address space on
  4292. the fence need to the fence need to
  4293. conservatively conservatively
  4294. always generate always generate
  4295. (see comment for (see comment for
  4296. previous fence). previous fence).
  4297. - Must happen after
  4298. any preceding
  4299. local/generic
  4300. load/load
  4301. atomic/store/store
  4302. atomic/atomicrmw.
  4303. - Could be split into
  4304. separate s_waitcnt
  4305. vmcnt(0), s_waitcnt
  4306. vscnt(0) and s_waitcnt
  4307. lgkmcnt(0) to allow
  4308. them to be
  4309. independently moved
  4310. according to the
  4311. following rules.
  4312. - s_waitcnt vmcnt(0)
  4313. must happen after
  4314. any preceding
  4315. global/generic
  4316. load/load
  4317. atomic/
  4318. atomicrmw-with-return-value.
  4319. - s_waitcnt vscnt(0)
  4320. must happen after
  4321. any preceding
  4322. global/generic
  4323. store/store atomic/
  4324. atomicrmw-no-return-value.
  4325. - s_waitcnt lgkmcnt(0)
  4326. must happen after
  4327. any preceding
  4328. local/generic
  4329. load/store/load
  4330. atomic/store atomic/
  4331. atomicrmw.
  4332. - Must happen before - Must happen before
  4333. any following any following
  4334. global/generic global/generic
  4335. load/load load/load
  4336. atomic/store/store atomic/store/store
  4337. atomic/atomicrmw. atomic/atomicrmw.
  4338. - Ensures that all - Ensures that all
  4339. memory operations memory operations
  4340. to local have have
  4341. completed before completed before
  4342. performing any performing any
  4343. following global following global
  4344. memory operations. memory operations.
  4345. - Ensures that the - Ensures that the
  4346. preceding preceding
  4347. local/generic load local/generic load
  4348. atomic/atomicrmw atomic/atomicrmw
  4349. with an equal or with an equal or
  4350. wider sync scope wider sync scope
  4351. and memory ordering and memory ordering
  4352. stronger than stronger than
  4353. unordered (this is unordered (this is
  4354. termed the termed the
  4355. acquire-fence-paired-atomic acquire-fence-paired-atomic
  4356. ) has completed ) has completed
  4357. before following before following
  4358. global memory global memory
  4359. operations. This operations. This
  4360. satisfies the satisfies the
  4361. requirements of requirements of
  4362. acquire. acquire.
  4363. - Ensures that all - Ensures that all
  4364. previous memory previous memory
  4365. operations have operations have
  4366. completed before a completed before a
  4367. following following
  4368. local/generic store local/generic store
  4369. atomic/atomicrmw atomic/atomicrmw
  4370. with an equal or with an equal or
  4371. wider sync scope wider sync scope
  4372. and memory ordering and memory ordering
  4373. stronger than stronger than
  4374. unordered (this is unordered (this is
  4375. termed the termed the
  4376. release-fence-paired-atomic release-fence-paired-atomic
  4377. ). This satisfies the ). This satisfies the
  4378. requirements of requirements of
  4379. release. release.
  4380. - Must happen before
  4381. the following
  4382. buffer_gl0_inv.
  4383. - Ensures that the
  4384. acquire-fence-paired
  4385. atomic has completed
  4386. before invalidating
  4387. the
  4388. cache. Therefore
  4389. any following
  4390. locations read must
  4391. be no older than
  4392. the value read by
  4393. the
  4394. acquire-fence-paired-atomic.
  4395. 3. buffer_gl0_inv
  4396. - If CU wavefront execution mode, omit.
  4397. - Ensures that
  4398. following
  4399. loads will not see
  4400. stale data.
  4401. fence acq_rel - agent *none* 1. s_waitcnt lgkmcnt(0) & 1. s_waitcnt lgkmcnt(0) &
  4402. - system vmcnt(0) vmcnt(0) & vscnt(0)
  4403. - If OpenCL and - If OpenCL and
  4404. address space is address space is
  4405. not generic, omit not generic, omit
  4406. lgkmcnt(0). lgkmcnt(0).
  4407. - If OpenCL and
  4408. address space is
  4409. local, omit
  4410. vmcnt(0) and vscnt(0).
  4411. - However, since LLVM - However, since LLVM
  4412. currently has no currently has no
  4413. address space on address space on
  4414. the fence need to the fence need to
  4415. conservatively conservatively
  4416. always generate always generate
  4417. (see comment for (see comment for
  4418. previous fence). previous fence).
  4419. - Could be split into - Could be split into
  4420. separate s_waitcnt separate s_waitcnt
  4421. vmcnt(0) and vmcnt(0), s_waitcnt
  4422. s_waitcnt vscnt(0) and s_waitcnt
  4423. lgkmcnt(0) to allow lgkmcnt(0) to allow
  4424. them to be them to be
  4425. independently moved independently moved
  4426. according to the according to the
  4427. following rules. following rules.
  4428. - s_waitcnt vmcnt(0) - s_waitcnt vmcnt(0)
  4429. must happen after must happen after
  4430. any preceding any preceding
  4431. global/generic global/generic
  4432. load/store/load load/load
  4433. atomic/store atomic/
  4434. atomic/atomicrmw. atomicrmw-with-return-value.
  4435. - s_waitcnt vscnt(0)
  4436. must happen after
  4437. any preceding
  4438. global/generic
  4439. store/store atomic/
  4440. atomicrmw-no-return-value.
  4441. - s_waitcnt lgkmcnt(0) - s_waitcnt lgkmcnt(0)
  4442. must happen after must happen after
  4443. any preceding any preceding
  4444. local/generic local/generic
  4445. load/store/load load/store/load
  4446. atomic/store atomic/store
  4447. atomic/atomicrmw. atomic/atomicrmw.
  4448. - Must happen before - Must happen before
  4449. the following the following
  4450. buffer_wbinvl1_vol. buffer_gl*_inv.
  4451. - Ensures that the - Ensures that the
  4452. preceding preceding
  4453. global/local/generic global/local/generic
  4454. load load
  4455. atomic/atomicrmw atomic/atomicrmw
  4456. with an equal or with an equal or
  4457. wider sync scope wider sync scope
  4458. and memory ordering and memory ordering
  4459. stronger than stronger than
  4460. unordered (this is unordered (this is
  4461. termed the termed the
  4462. acquire-fence-paired-atomic acquire-fence-paired-atomic
  4463. ) has completed ) has completed
  4464. before invalidating before invalidating
  4465. the cache. This the caches. This
  4466. satisfies the satisfies the
  4467. requirements of requirements of
  4468. acquire. acquire.
  4469. - Ensures that all - Ensures that all
  4470. previous memory previous memory
  4471. operations have operations have
  4472. completed before a completed before a
  4473. following following
  4474. global/local/generic global/local/generic
  4475. store store
  4476. atomic/atomicrmw atomic/atomicrmw
  4477. with an equal or with an equal or
  4478. wider sync scope wider sync scope
  4479. and memory ordering and memory ordering
  4480. stronger than stronger than
  4481. unordered (this is unordered (this is
  4482. termed the termed the
  4483. release-fence-paired-atomic release-fence-paired-atomic
  4484. ). This satisfies the ). This satisfies the
  4485. requirements of requirements of
  4486. release. release.
  4487. 2. buffer_wbinvl1_vol 2. buffer_gl0_inv;
  4488. buffer_gl1_inv
  4489. - Must happen before - Must happen before
  4490. any following any following
  4491. global/generic global/generic
  4492. load/load load/load
  4493. atomic/store/store atomic/store/store
  4494. atomic/atomicrmw. atomic/atomicrmw.
  4495. - Ensures that - Ensures that
  4496. following loads following loads
  4497. will not see stale will not see stale
  4498. global data. This global data. This
  4499. satisfies the satisfies the
  4500. requirements of requirements of
  4501. acquire. acquire.
  4502. **Sequential Consistent Atomic**
  4503. ----------------------------------------------------------------------------------------------------------------------
  4504. load atomic seq_cst - singlethread - global *Same as corresponding *Same as corresponding
  4505. - wavefront - local load atomic acquire, load atomic acquire,
  4506. - generic except must generated except must generated
  4507. all instructions even all instructions even
  4508. for OpenCL.* for OpenCL.*
  4509. load atomic seq_cst - workgroup - global 1. s_waitcnt lgkmcnt(0) 1. s_waitcnt lgkmcnt(0) &
  4510. - generic vmcnt(0) & vscnt(0)
  4511. - If CU wavefront execution mode, omit vmcnt and
  4512. vscnt.
  4513. - Could be split into
  4514. separate s_waitcnt
  4515. vmcnt(0), s_waitcnt
  4516. vscnt(0) and s_waitcnt
  4517. lgkmcnt(0) to allow
  4518. them to be
  4519. independently moved
  4520. according to the
  4521. following rules.
  4522. - Must - waitcnt lgkmcnt(0) must
  4523. happen after happen after
  4524. preceding preceding
  4525. global/generic load local load
  4526. atomic/store atomic/store
  4527. atomic/atomicrmw atomic/atomicrmw
  4528. with memory with memory
  4529. ordering of seq_cst ordering of seq_cst
  4530. and with equal or and with equal or
  4531. wider sync scope. wider sync scope.
  4532. (Note that seq_cst (Note that seq_cst
  4533. fences have their fences have their
  4534. own s_waitcnt own s_waitcnt
  4535. lgkmcnt(0) and so do lgkmcnt(0) and so do
  4536. not need to be not need to be
  4537. considered.) considered.)
  4538. - waitcnt vmcnt(0)
  4539. Must happen after
  4540. preceding
  4541. global/generic load
  4542. atomic/
  4543. atomicrmw-with-return-value
  4544. with memory
  4545. ordering of seq_cst
  4546. and with equal or
  4547. wider sync scope.
  4548. (Note that seq_cst
  4549. fences have their
  4550. own s_waitcnt
  4551. vmcnt(0) and so do
  4552. not need to be
  4553. considered.)
  4554. - waitcnt vscnt(0)
  4555. Must happen after
  4556. preceding
  4557. global/generic store
  4558. atomic/
  4559. atomicrmw-no-return-value
  4560. with memory
  4561. ordering of seq_cst
  4562. and with equal or
  4563. wider sync scope.
  4564. (Note that seq_cst
  4565. fences have their
  4566. own s_waitcnt
  4567. vscnt(0) and so do
  4568. not need to be
  4569. considered.)
  4570. - Ensures any - Ensures any
  4571. preceding preceding
  4572. sequential sequential
  4573. consistent local consistent global/local
  4574. memory instructions memory instructions
  4575. have completed have completed
  4576. before executing before executing
  4577. this sequentially this sequentially
  4578. consistent consistent
  4579. instruction. This instruction. This
  4580. prevents reordering prevents reordering
  4581. a seq_cst store a seq_cst store
  4582. followed by a followed by a
  4583. seq_cst load. (Note seq_cst load. (Note
  4584. that seq_cst is that seq_cst is
  4585. stronger than stronger than
  4586. acquire/release as acquire/release as
  4587. the reordering of the reordering of
  4588. load acquire load acquire
  4589. followed by a store followed by a store
  4590. release is release is
  4591. prevented by the prevented by the
  4592. waitcnt of waitcnt of
  4593. the release, but the release, but
  4594. there is nothing there is nothing
  4595. preventing a store preventing a store
  4596. release followed by release followed by
  4597. load acquire from load acquire from
  4598. competing out of competing out of
  4599. order.) order.)
  4600. 2. *Following 2. *Following
  4601. instructions same as instructions same as
  4602. corresponding load corresponding load
  4603. atomic acquire, atomic acquire,
  4604. except must generated except must generated
  4605. all instructions even all instructions even
  4606. for OpenCL.* for OpenCL.*
  4607. load atomic seq_cst - workgroup - local *Same as corresponding
  4608. load atomic acquire,
  4609. except must generated
  4610. all instructions even
  4611. for OpenCL.*
  4612. 1. s_waitcnt vmcnt(0) & vscnt(0)
  4613. - If CU wavefront execution mode, omit.
  4614. - Could be split into
  4615. separate s_waitcnt
  4616. vmcnt(0) and s_waitcnt
  4617. vscnt(0) to allow
  4618. them to be
  4619. independently moved
  4620. according to the
  4621. following rules.
  4622. - waitcnt vmcnt(0)
  4623. Must happen after
  4624. preceding
  4625. global/generic load
  4626. atomic/
  4627. atomicrmw-with-return-value
  4628. with memory
  4629. ordering of seq_cst
  4630. and with equal or
  4631. wider sync scope.
  4632. (Note that seq_cst
  4633. fences have their
  4634. own s_waitcnt
  4635. vmcnt(0) and so do
  4636. not need to be
  4637. considered.)
  4638. - waitcnt vscnt(0)
  4639. Must happen after
  4640. preceding
  4641. global/generic store
  4642. atomic/
  4643. atomicrmw-no-return-value
  4644. with memory
  4645. ordering of seq_cst
  4646. and with equal or
  4647. wider sync scope.
  4648. (Note that seq_cst
  4649. fences have their
  4650. own s_waitcnt
  4651. vscnt(0) and so do
  4652. not need to be
  4653. considered.)
  4654. - Ensures any
  4655. preceding
  4656. sequential
  4657. consistent global
  4658. memory instructions
  4659. have completed
  4660. before executing
  4661. this sequentially
  4662. consistent
  4663. instruction. This
  4664. prevents reordering
  4665. a seq_cst store
  4666. followed by a
  4667. seq_cst load. (Note
  4668. that seq_cst is
  4669. stronger than
  4670. acquire/release as
  4671. the reordering of
  4672. load acquire
  4673. followed by a store
  4674. release is
  4675. prevented by the
  4676. waitcnt of
  4677. the release, but
  4678. there is nothing
  4679. preventing a store
  4680. release followed by
  4681. load acquire from
  4682. competing out of
  4683. order.)
  4684. 2. *Following
  4685. instructions same as
  4686. corresponding load
  4687. atomic acquire,
  4688. except must generated
  4689. all instructions even
  4690. for OpenCL.*
  4691. load atomic seq_cst - agent - global 1. s_waitcnt lgkmcnt(0) & 1. s_waitcnt lgkmcnt(0) &
  4692. - system - generic vmcnt(0) vmcnt(0) & vscnt(0)
  4693. - Could be split into - Could be split into
  4694. separate s_waitcnt separate s_waitcnt
  4695. vmcnt(0) vmcnt(0), s_waitcnt
  4696. and s_waitcnt vscnt(0) and s_waitcnt
  4697. lgkmcnt(0) to allow lgkmcnt(0) to allow
  4698. them to be them to be
  4699. independently moved independently moved
  4700. according to the according to the
  4701. following rules. following rules.
  4702. - waitcnt lgkmcnt(0) - waitcnt lgkmcnt(0)
  4703. must happen after must happen after
  4704. preceding preceding
  4705. global/generic load local load
  4706. atomic/store atomic/store
  4707. atomic/atomicrmw atomic/atomicrmw
  4708. with memory with memory
  4709. ordering of seq_cst ordering of seq_cst
  4710. and with equal or and with equal or
  4711. wider sync scope. wider sync scope.
  4712. (Note that seq_cst (Note that seq_cst
  4713. fences have their fences have their
  4714. own s_waitcnt own s_waitcnt
  4715. lgkmcnt(0) and so do lgkmcnt(0) and so do
  4716. not need to be not need to be
  4717. considered.) considered.)
  4718. - waitcnt vmcnt(0) - waitcnt vmcnt(0)
  4719. must happen after must happen after
  4720. preceding preceding
  4721. global/generic load global/generic load
  4722. atomic/store atomic/
  4723. atomic/atomicrmw atomicrmw-with-return-value
  4724. with memory with memory
  4725. ordering of seq_cst ordering of seq_cst
  4726. and with equal or and with equal or
  4727. wider sync scope. wider sync scope.
  4728. (Note that seq_cst (Note that seq_cst
  4729. fences have their fences have their
  4730. own s_waitcnt own s_waitcnt
  4731. vmcnt(0) and so do vmcnt(0) and so do
  4732. not need to be not need to be
  4733. considered.) considered.)
  4734. - waitcnt vscnt(0)
  4735. Must happen after
  4736. preceding
  4737. global/generic store
  4738. atomic/
  4739. atomicrmw-no-return-value
  4740. with memory
  4741. ordering of seq_cst
  4742. and with equal or
  4743. wider sync scope.
  4744. (Note that seq_cst
  4745. fences have their
  4746. own s_waitcnt
  4747. vscnt(0) and so do
  4748. not need to be
  4749. considered.)
  4750. - Ensures any - Ensures any
  4751. preceding preceding
  4752. sequential sequential
  4753. consistent global consistent global
  4754. memory instructions memory instructions
  4755. have completed have completed
  4756. before executing before executing
  4757. this sequentially this sequentially
  4758. consistent consistent
  4759. instruction. This instruction. This
  4760. prevents reordering prevents reordering
  4761. a seq_cst store a seq_cst store
  4762. followed by a followed by a
  4763. seq_cst load. (Note seq_cst load. (Note
  4764. that seq_cst is that seq_cst is
  4765. stronger than stronger than
  4766. acquire/release as acquire/release as
  4767. the reordering of the reordering of
  4768. load acquire load acquire
  4769. followed by a store followed by a store
  4770. release is release is
  4771. prevented by the prevented by the
  4772. waitcnt of waitcnt of
  4773. the release, but the release, but
  4774. there is nothing there is nothing
  4775. preventing a store preventing a store
  4776. release followed by release followed by
  4777. load acquire from load acquire from
  4778. competing out of competing out of
  4779. order.) order.)
  4780. 2. *Following 2. *Following
  4781. instructions same as instructions same as
  4782. corresponding load corresponding load
  4783. atomic acquire, atomic acquire,
  4784. except must generated except must generated
  4785. all instructions even all instructions even
  4786. for OpenCL.* for OpenCL.*
  4787. store atomic seq_cst - singlethread - global *Same as corresponding *Same as corresponding
  4788. - wavefront - local store atomic release, store atomic release,
  4789. - workgroup - generic except must generated except must generated
  4790. all instructions even all instructions even
  4791. for OpenCL.* for OpenCL.*
  4792. store atomic seq_cst - agent - global *Same as corresponding *Same as corresponding
  4793. - system - generic store atomic release, store atomic release,
  4794. except must generated except must generated
  4795. all instructions even all instructions even
  4796. for OpenCL.* for OpenCL.*
  4797. atomicrmw seq_cst - singlethread - global *Same as corresponding *Same as corresponding
  4798. - wavefront - local atomicrmw acq_rel, atomicrmw acq_rel,
  4799. - workgroup - generic except must generated except must generated
  4800. all instructions even all instructions even
  4801. for OpenCL.* for OpenCL.*
  4802. atomicrmw seq_cst - agent - global *Same as corresponding *Same as corresponding
  4803. - system - generic atomicrmw acq_rel, atomicrmw acq_rel,
  4804. except must generated except must generated
  4805. all instructions even all instructions even
  4806. for OpenCL.* for OpenCL.*
  4807. fence seq_cst - singlethread *none* *Same as corresponding *Same as corresponding
  4808. - wavefront fence acq_rel, fence acq_rel,
  4809. - workgroup except must generated except must generated
  4810. - agent all instructions even all instructions even
  4811. - system for OpenCL.* for OpenCL.*
  4812. ============ ============ ============== ========== =============================== ==================================
  4813. The memory order also adds the single thread optimization constrains defined in
  4814. table
  4815. :ref:`amdgpu-amdhsa-memory-model-single-thread-optimization-constraints-gfx6-gfx10-table`.
  4816. .. table:: AMDHSA Memory Model Single Thread Optimization Constraints GFX6-GFX10
  4817. :name: amdgpu-amdhsa-memory-model-single-thread-optimization-constraints-gfx6-gfx10-table
  4818. ============ ==============================================================
  4819. LLVM Memory Optimization Constraints
  4820. Ordering
  4821. ============ ==============================================================
  4822. unordered *none*
  4823. monotonic *none*
  4824. acquire - If a load atomic/atomicrmw then no following load/load
  4825. atomic/store/ store atomic/atomicrmw/fence instruction can
  4826. be moved before the acquire.
  4827. - If a fence then same as load atomic, plus no preceding
  4828. associated fence-paired-atomic can be moved after the fence.
  4829. release - If a store atomic/atomicrmw then no preceding load/load
  4830. atomic/store/ store atomic/atomicrmw/fence instruction can
  4831. be moved after the release.
  4832. - If a fence then same as store atomic, plus no following
  4833. associated fence-paired-atomic can be moved before the
  4834. fence.
  4835. acq_rel Same constraints as both acquire and release.
  4836. seq_cst - If a load atomic then same constraints as acquire, plus no
  4837. preceding sequentially consistent load atomic/store
  4838. atomic/atomicrmw/fence instruction can be moved after the
  4839. seq_cst.
  4840. - If a store atomic then the same constraints as release, plus
  4841. no following sequentially consistent load atomic/store
  4842. atomic/atomicrmw/fence instruction can be moved before the
  4843. seq_cst.
  4844. - If an atomicrmw/fence then same constraints as acq_rel.
  4845. ============ ==============================================================
  4846. Trap Handler ABI
  4847. ~~~~~~~~~~~~~~~~
  4848. For code objects generated by AMDGPU backend for HSA [HSA]_ compatible runtimes
  4849. (such as ROCm [AMD-ROCm]_), the runtime installs a trap handler that supports
  4850. the ``s_trap`` instruction with the following usage:
  4851. .. table:: AMDGPU Trap Handler for AMDHSA OS
  4852. :name: amdgpu-trap-handler-for-amdhsa-os-table
  4853. =================== =============== =============== =======================
  4854. Usage Code Sequence Trap Handler Description
  4855. Inputs
  4856. =================== =============== =============== =======================
  4857. reserved ``s_trap 0x00`` Reserved by hardware.
  4858. ``debugtrap(arg)`` ``s_trap 0x01`` ``SGPR0-1``: Reserved for HSA
  4859. ``queue_ptr`` ``debugtrap``
  4860. ``VGPR0``: intrinsic (not
  4861. ``arg`` implemented).
  4862. ``llvm.trap`` ``s_trap 0x02`` ``SGPR0-1``: Causes dispatch to be
  4863. ``queue_ptr`` terminated and its
  4864. associated queue put
  4865. into the error state.
  4866. ``llvm.debugtrap`` ``s_trap 0x03`` - If debugger not
  4867. installed then
  4868. behaves as a
  4869. no-operation. The
  4870. trap handler is
  4871. entered and
  4872. immediately returns
  4873. to continue
  4874. execution of the
  4875. wavefront.
  4876. - If the debugger is
  4877. installed, causes
  4878. the debug trap to be
  4879. reported by the
  4880. debugger and the
  4881. wavefront is put in
  4882. the halt state until
  4883. resumed by the
  4884. debugger.
  4885. reserved ``s_trap 0x04`` Reserved.
  4886. reserved ``s_trap 0x05`` Reserved.
  4887. reserved ``s_trap 0x06`` Reserved.
  4888. debugger breakpoint ``s_trap 0x07`` Reserved for debugger
  4889. breakpoints.
  4890. reserved ``s_trap 0x08`` Reserved.
  4891. reserved ``s_trap 0xfe`` Reserved.
  4892. reserved ``s_trap 0xff`` Reserved.
  4893. =================== =============== =============== =======================
  4894. AMDPAL
  4895. ------
  4896. This section provides code conventions used when the target triple OS is
  4897. ``amdpal`` (see :ref:`amdgpu-target-triples`) for passing runtime parameters
  4898. from the application/runtime to each invocation of a hardware shader. These
  4899. parameters include both generic, application-controlled parameters called
  4900. *user data* as well as system-generated parameters that are a product of the
  4901. draw or dispatch execution.
  4902. User Data
  4903. ~~~~~~~~~
  4904. Each hardware stage has a set of 32-bit *user data registers* which can be
  4905. written from a command buffer and then loaded into SGPRs when waves are launched
  4906. via a subsequent dispatch or draw operation. This is the way most arguments are
  4907. passed from the application/runtime to a hardware shader.
  4908. Compute User Data
  4909. ~~~~~~~~~~~~~~~~~
  4910. Compute shader user data mappings are simpler than graphics shaders, and have a
  4911. fixed mapping.
  4912. Note that there are always 10 available *user data entries* in registers -
  4913. entries beyond that limit must be fetched from memory (via the spill table
  4914. pointer) by the shader.
  4915. .. table:: PAL Compute Shader User Data Registers
  4916. :name: pal-compute-user-data-registers
  4917. ============= ================================
  4918. User Register Description
  4919. ============= ================================
  4920. 0 Global Internal Table (32-bit pointer)
  4921. 1 Per-Shader Internal Table (32-bit pointer)
  4922. 2 - 11 Application-Controlled User Data (10 32-bit values)
  4923. 12 Spill Table (32-bit pointer)
  4924. 13 - 14 Thread Group Count (64-bit pointer)
  4925. 15 GDS Range
  4926. ============= ================================
  4927. Graphics User Data
  4928. ~~~~~~~~~~~~~~~~~~
  4929. Graphics pipelines support a much more flexible user data mapping:
  4930. .. table:: PAL Graphics Shader User Data Registers
  4931. :name: pal-graphics-user-data-registers
  4932. ============= ================================
  4933. User Register Description
  4934. ============= ================================
  4935. 0 Global Internal Table (32-bit pointer)
  4936. + Per-Shader Internal Table (32-bit pointer)
  4937. + 1-15 Application Controlled User Data
  4938. (1-15 Contiguous 32-bit Values in Registers)
  4939. + Spill Table (32-bit pointer)
  4940. + Draw Index (First Stage Only)
  4941. + Vertex Offset (First Stage Only)
  4942. + Instance Offset (First Stage Only)
  4943. ============= ================================
  4944. The placement of the global internal table remains fixed in the first *user
  4945. data SGPR register*. Otherwise all parameters are optional, and can be mapped
  4946. to any desired *user data SGPR register*, with the following regstrictions:
  4947. * Draw Index, Vertex Offset, and Instance Offset can only be used by the first
  4948. activehardware stage in a graphics pipeline (i.e. where the API vertex
  4949. shader runs).
  4950. * Application-controlled user data must be mapped into a contiguous range of
  4951. user data registers.
  4952. * The application-controlled user data range supports compaction remapping, so
  4953. only *entries* that are actually consumed by the shader must be assigned to
  4954. corresponding *registers*. Note that in order to support an efficient runtime
  4955. implementation, the remapping must pack *registers* in the same order as
  4956. *entries*, with unused *entries* removed.
  4957. .. _pal_global_internal_table:
  4958. Global Internal Table
  4959. ~~~~~~~~~~~~~~~~~~~~~
  4960. The global internal table is a table of *shader resource descriptors* (SRDs) that
  4961. define how certain engine-wide, runtime-managed resources should be accessed
  4962. from a shader. The majority of these resources have HW-defined formats, and it
  4963. is up to the compiler to write/read data as required by the target hardware.
  4964. The following table illustrates the required format:
  4965. .. table:: PAL Global Internal Table
  4966. :name: pal-git-table
  4967. ============= ================================
  4968. Offset Description
  4969. ============= ================================
  4970. 0-3 Graphics Scratch SRD
  4971. 4-7 Compute Scratch SRD
  4972. 8-11 ES/GS Ring Output SRD
  4973. 12-15 ES/GS Ring Input SRD
  4974. 16-19 GS/VS Ring Output #0
  4975. 20-23 GS/VS Ring Output #1
  4976. 24-27 GS/VS Ring Output #2
  4977. 28-31 GS/VS Ring Output #3
  4978. 32-35 GS/VS Ring Input SRD
  4979. 36-39 Tessellation Factor Buffer SRD
  4980. 40-43 Off-Chip LDS Buffer SRD
  4981. 44-47 Off-Chip Param Cache Buffer SRD
  4982. 48-51 Sample Position Buffer SRD
  4983. 52 vaRange::ShadowDescriptorTable High Bits
  4984. ============= ================================
  4985. The pointer to the global internal table passed to the shader as user data
  4986. is a 32-bit pointer. The top 32 bits should be assumed to be the same as
  4987. the top 32 bits of the pipeline, so the shader may use the program
  4988. counter's top 32 bits.
  4989. Unspecified OS
  4990. --------------
  4991. This section provides code conventions used when the target triple OS is
  4992. empty (see :ref:`amdgpu-target-triples`).
  4993. Trap Handler ABI
  4994. ~~~~~~~~~~~~~~~~
  4995. For code objects generated by AMDGPU backend for non-amdhsa OS, the runtime does
  4996. not install a trap handler. The ``llvm.trap`` and ``llvm.debugtrap``
  4997. instructions are handled as follows:
  4998. .. table:: AMDGPU Trap Handler for Non-AMDHSA OS
  4999. :name: amdgpu-trap-handler-for-non-amdhsa-os-table
  5000. =============== =============== ===========================================
  5001. Usage Code Sequence Description
  5002. =============== =============== ===========================================
  5003. llvm.trap s_endpgm Causes wavefront to be terminated.
  5004. llvm.debugtrap *none* Compiler warning given that there is no
  5005. trap handler installed.
  5006. =============== =============== ===========================================
  5007. Source Languages
  5008. ================
  5009. .. _amdgpu-opencl:
  5010. OpenCL
  5011. ------
  5012. When the language is OpenCL the following differences occur:
  5013. 1. The OpenCL memory model is used (see :ref:`amdgpu-amdhsa-memory-model`).
  5014. 2. The AMDGPU backend appends additional arguments to the kernel's explicit
  5015. arguments for the AMDHSA OS (see
  5016. :ref:`opencl-kernel-implicit-arguments-appended-for-amdhsa-os-table`).
  5017. 3. Additional metadata is generated
  5018. (see :ref:`amdgpu-amdhsa-code-object-metadata`).
  5019. .. table:: OpenCL kernel implicit arguments appended for AMDHSA OS
  5020. :name: opencl-kernel-implicit-arguments-appended-for-amdhsa-os-table
  5021. ======== ==== ========= ===========================================
  5022. Position Byte Byte Description
  5023. Size Alignment
  5024. ======== ==== ========= ===========================================
  5025. 1 8 8 OpenCL Global Offset X
  5026. 2 8 8 OpenCL Global Offset Y
  5027. 3 8 8 OpenCL Global Offset Z
  5028. 4 8 8 OpenCL address of printf buffer
  5029. 5 8 8 OpenCL address of virtual queue used by
  5030. enqueue_kernel.
  5031. 6 8 8 OpenCL address of AqlWrap struct used by
  5032. enqueue_kernel.
  5033. 7 8 8 Pointer argument used for Multi-gird
  5034. synchronization.
  5035. ======== ==== ========= ===========================================
  5036. .. _amdgpu-hcc:
  5037. HCC
  5038. ---
  5039. When the language is HCC the following differences occur:
  5040. 1. The HSA memory model is used (see :ref:`amdgpu-amdhsa-memory-model`).
  5041. .. _amdgpu-assembler:
  5042. Assembler
  5043. ---------
  5044. AMDGPU backend has LLVM-MC based assembler which is currently in development.
  5045. It supports AMDGCN GFX6-GFX10.
  5046. This section describes general syntax for instructions and operands.
  5047. Instructions
  5048. ~~~~~~~~~~~~
  5049. .. toctree::
  5050. :hidden:
  5051. AMDGPU/AMDGPUAsmGFX7
  5052. AMDGPU/AMDGPUAsmGFX8
  5053. AMDGPU/AMDGPUAsmGFX9
  5054. AMDGPU/AMDGPUAsmGFX10
  5055. AMDGPUModifierSyntax
  5056. AMDGPUOperandSyntax
  5057. AMDGPUInstructionSyntax
  5058. AMDGPUInstructionNotation
  5059. An instruction has the following :doc:`syntax<AMDGPUInstructionSyntax>`:
  5060. ``<``\ *opcode*\ ``> <``\ *operand0*\ ``>, <``\ *operand1*\ ``>,... <``\ *modifier0*\ ``> <``\ *modifier1*\ ``>...``
  5061. :doc:`Operands<AMDGPUOperandSyntax>` are normally comma-separated while
  5062. :doc:`modifiers<AMDGPUModifierSyntax>` are space-separated.
  5063. The order of *operands* and *modifiers* is fixed.
  5064. Most *modifiers* are optional and may be omitted.
  5065. See detailed instruction syntax description for :doc:`GFX7<AMDGPU/AMDGPUAsmGFX7>`,
  5066. :doc:`GFX8<AMDGPU/AMDGPUAsmGFX8>`, :doc:`GFX9<AMDGPU/AMDGPUAsmGFX9>`
  5067. and :doc:`GFX10<AMDGPU/AMDGPUAsmGFX10>`.
  5068. Note that features under development are not included in this description.
  5069. For more information about instructions, their semantics and supported combinations of
  5070. operands, refer to one of instruction set architecture manuals
  5071. [AMD-GCN-GFX6]_, [AMD-GCN-GFX7]_, [AMD-GCN-GFX8]_, [AMD-GCN-GFX9]_ and
  5072. [AMD-GCN-GFX10]_.
  5073. Operands
  5074. ~~~~~~~~
  5075. Detailed description of operands may be found :doc:`here<AMDGPUOperandSyntax>`.
  5076. Modifiers
  5077. ~~~~~~~~~
  5078. Detailed description of modifiers may be found :doc:`here<AMDGPUModifierSyntax>`.
  5079. Instruction Examples
  5080. ~~~~~~~~~~~~~~~~~~~~
  5081. DS
  5082. ++
  5083. .. code-block:: nasm
  5084. ds_add_u32 v2, v4 offset:16
  5085. ds_write_src2_b64 v2 offset0:4 offset1:8
  5086. ds_cmpst_f32 v2, v4, v6
  5087. ds_min_rtn_f64 v[8:9], v2, v[4:5]
  5088. For full list of supported instructions, refer to "LDS/GDS instructions" in ISA Manual.
  5089. FLAT
  5090. ++++
  5091. .. code-block:: nasm
  5092. flat_load_dword v1, v[3:4]
  5093. flat_store_dwordx3 v[3:4], v[5:7]
  5094. flat_atomic_swap v1, v[3:4], v5 glc
  5095. flat_atomic_cmpswap v1, v[3:4], v[5:6] glc slc
  5096. flat_atomic_fmax_x2 v[1:2], v[3:4], v[5:6] glc
  5097. For full list of supported instructions, refer to "FLAT instructions" in ISA Manual.
  5098. MUBUF
  5099. +++++
  5100. .. code-block:: nasm
  5101. buffer_load_dword v1, off, s[4:7], s1
  5102. buffer_store_dwordx4 v[1:4], v2, ttmp[4:7], s1 offen offset:4 glc tfe
  5103. buffer_store_format_xy v[1:2], off, s[4:7], s1
  5104. buffer_wbinvl1
  5105. buffer_atomic_inc v1, v2, s[8:11], s4 idxen offset:4 slc
  5106. For full list of supported instructions, refer to "MUBUF Instructions" in ISA Manual.
  5107. SMRD/SMEM
  5108. +++++++++
  5109. .. code-block:: nasm
  5110. s_load_dword s1, s[2:3], 0xfc
  5111. s_load_dwordx8 s[8:15], s[2:3], s4
  5112. s_load_dwordx16 s[88:103], s[2:3], s4
  5113. s_dcache_inv_vol
  5114. s_memtime s[4:5]
  5115. For full list of supported instructions, refer to "Scalar Memory Operations" in ISA Manual.
  5116. SOP1
  5117. ++++
  5118. .. code-block:: nasm
  5119. s_mov_b32 s1, s2
  5120. s_mov_b64 s[0:1], 0x80000000
  5121. s_cmov_b32 s1, 200
  5122. s_wqm_b64 s[2:3], s[4:5]
  5123. s_bcnt0_i32_b64 s1, s[2:3]
  5124. s_swappc_b64 s[2:3], s[4:5]
  5125. s_cbranch_join s[4:5]
  5126. For full list of supported instructions, refer to "SOP1 Instructions" in ISA Manual.
  5127. SOP2
  5128. ++++
  5129. .. code-block:: nasm
  5130. s_add_u32 s1, s2, s3
  5131. s_and_b64 s[2:3], s[4:5], s[6:7]
  5132. s_cselect_b32 s1, s2, s3
  5133. s_andn2_b32 s2, s4, s6
  5134. s_lshr_b64 s[2:3], s[4:5], s6
  5135. s_ashr_i32 s2, s4, s6
  5136. s_bfm_b64 s[2:3], s4, s6
  5137. s_bfe_i64 s[2:3], s[4:5], s6
  5138. s_cbranch_g_fork s[4:5], s[6:7]
  5139. For full list of supported instructions, refer to "SOP2 Instructions" in ISA Manual.
  5140. SOPC
  5141. ++++
  5142. .. code-block:: nasm
  5143. s_cmp_eq_i32 s1, s2
  5144. s_bitcmp1_b32 s1, s2
  5145. s_bitcmp0_b64 s[2:3], s4
  5146. s_setvskip s3, s5
  5147. For full list of supported instructions, refer to "SOPC Instructions" in ISA Manual.
  5148. SOPP
  5149. ++++
  5150. .. code-block:: nasm
  5151. s_barrier
  5152. s_nop 2
  5153. s_endpgm
  5154. s_waitcnt 0 ; Wait for all counters to be 0
  5155. s_waitcnt vmcnt(0) & expcnt(0) & lgkmcnt(0) ; Equivalent to above
  5156. s_waitcnt vmcnt(1) ; Wait for vmcnt counter to be 1.
  5157. s_sethalt 9
  5158. s_sleep 10
  5159. s_sendmsg 0x1
  5160. s_sendmsg sendmsg(MSG_INTERRUPT)
  5161. s_trap 1
  5162. For full list of supported instructions, refer to "SOPP Instructions" in ISA Manual.
  5163. Unless otherwise mentioned, little verification is performed on the operands
  5164. of SOPP Instructions, so it is up to the programmer to be familiar with the
  5165. range or acceptable values.
  5166. VALU
  5167. ++++
  5168. For vector ALU instruction opcodes (VOP1, VOP2, VOP3, VOPC, VOP_DPP, VOP_SDWA),
  5169. the assembler will automatically use optimal encoding based on its operands.
  5170. To force specific encoding, one can add a suffix to the opcode of the instruction:
  5171. * _e32 for 32-bit VOP1/VOP2/VOPC
  5172. * _e64 for 64-bit VOP3
  5173. * _dpp for VOP_DPP
  5174. * _sdwa for VOP_SDWA
  5175. VOP1/VOP2/VOP3/VOPC examples:
  5176. .. code-block:: nasm
  5177. v_mov_b32 v1, v2
  5178. v_mov_b32_e32 v1, v2
  5179. v_nop
  5180. v_cvt_f64_i32_e32 v[1:2], v2
  5181. v_floor_f32_e32 v1, v2
  5182. v_bfrev_b32_e32 v1, v2
  5183. v_add_f32_e32 v1, v2, v3
  5184. v_mul_i32_i24_e64 v1, v2, 3
  5185. v_mul_i32_i24_e32 v1, -3, v3
  5186. v_mul_i32_i24_e32 v1, -100, v3
  5187. v_addc_u32 v1, s[0:1], v2, v3, s[2:3]
  5188. v_max_f16_e32 v1, v2, v3
  5189. VOP_DPP examples:
  5190. .. code-block:: nasm
  5191. v_mov_b32 v0, v0 quad_perm:[0,2,1,1]
  5192. v_sin_f32 v0, v0 row_shl:1 row_mask:0xa bank_mask:0x1 bound_ctrl:0
  5193. v_mov_b32 v0, v0 wave_shl:1
  5194. v_mov_b32 v0, v0 row_mirror
  5195. v_mov_b32 v0, v0 row_bcast:31
  5196. v_mov_b32 v0, v0 quad_perm:[1,3,0,1] row_mask:0xa bank_mask:0x1 bound_ctrl:0
  5197. v_add_f32 v0, v0, |v0| row_shl:1 row_mask:0xa bank_mask:0x1 bound_ctrl:0
  5198. v_max_f16 v1, v2, v3 row_shl:1 row_mask:0xa bank_mask:0x1 bound_ctrl:0
  5199. VOP_SDWA examples:
  5200. .. code-block:: nasm
  5201. v_mov_b32 v1, v2 dst_sel:BYTE_0 dst_unused:UNUSED_PRESERVE src0_sel:DWORD
  5202. v_min_u32 v200, v200, v1 dst_sel:WORD_1 dst_unused:UNUSED_PAD src0_sel:BYTE_1 src1_sel:DWORD
  5203. v_sin_f32 v0, v0 dst_unused:UNUSED_PAD src0_sel:WORD_1
  5204. v_fract_f32 v0, |v0| dst_sel:DWORD dst_unused:UNUSED_PAD src0_sel:WORD_1
  5205. v_cmpx_le_u32 vcc, v1, v2 src0_sel:BYTE_2 src1_sel:WORD_0
  5206. For full list of supported instructions, refer to "Vector ALU instructions".
  5207. .. TODO
  5208. Remove once we switch to code object v3 by default.
  5209. .. _amdgpu-amdhsa-assembler-predefined-symbols-v2:
  5210. Code Object V2 Predefined Symbols (-mattr=-code-object-v3)
  5211. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5212. .. warning:: Code Object V2 is not the default code object version emitted by
  5213. this version of LLVM. For a description of the predefined symbols available
  5214. with the default configuration (Code Object V3) see
  5215. :ref:`amdgpu-amdhsa-assembler-predefined-symbols-v3`.
  5216. The AMDGPU assembler defines and updates some symbols automatically. These
  5217. symbols do not affect code generation.
  5218. .option.machine_version_major
  5219. +++++++++++++++++++++++++++++
  5220. Set to the GFX major generation number of the target being assembled for. For
  5221. example, when assembling for a "GFX9" target this will be set to the integer
  5222. value "9". The possible GFX major generation numbers are presented in
  5223. :ref:`amdgpu-processors`.
  5224. .option.machine_version_minor
  5225. +++++++++++++++++++++++++++++
  5226. Set to the GFX minor generation number of the target being assembled for. For
  5227. example, when assembling for a "GFX810" target this will be set to the integer
  5228. value "1". The possible GFX minor generation numbers are presented in
  5229. :ref:`amdgpu-processors`.
  5230. .option.machine_version_stepping
  5231. ++++++++++++++++++++++++++++++++
  5232. Set to the GFX stepping generation number of the target being assembled for.
  5233. For example, when assembling for a "GFX704" target this will be set to the
  5234. integer value "4". The possible GFX stepping generation numbers are presented
  5235. in :ref:`amdgpu-processors`.
  5236. .kernel.vgpr_count
  5237. ++++++++++++++++++
  5238. Set to zero each time a
  5239. :ref:`amdgpu-amdhsa-assembler-directive-amdgpu_hsa_kernel` directive is
  5240. encountered. At each instruction, if the current value of this symbol is less
  5241. than or equal to the maximum VPGR number explicitly referenced within that
  5242. instruction then the symbol value is updated to equal that VGPR number plus
  5243. one.
  5244. .kernel.sgpr_count
  5245. ++++++++++++++++++
  5246. Set to zero each time a
  5247. :ref:`amdgpu-amdhsa-assembler-directive-amdgpu_hsa_kernel` directive is
  5248. encountered. At each instruction, if the current value of this symbol is less
  5249. than or equal to the maximum VPGR number explicitly referenced within that
  5250. instruction then the symbol value is updated to equal that SGPR number plus
  5251. one.
  5252. .. _amdgpu-amdhsa-assembler-directives-v2:
  5253. Code Object V2 Directives (-mattr=-code-object-v3)
  5254. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5255. .. warning:: Code Object V2 is not the default code object version emitted by
  5256. this version of LLVM. For a description of the directives supported with
  5257. the default configuration (Code Object V3) see
  5258. :ref:`amdgpu-amdhsa-assembler-directives-v3`.
  5259. AMDGPU ABI defines auxiliary data in output code object. In assembly source,
  5260. one can specify them with assembler directives.
  5261. .hsa_code_object_version major, minor
  5262. +++++++++++++++++++++++++++++++++++++
  5263. *major* and *minor* are integers that specify the version of the HSA code
  5264. object that will be generated by the assembler.
  5265. .hsa_code_object_isa [major, minor, stepping, vendor, arch]
  5266. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  5267. *major*, *minor*, and *stepping* are all integers that describe the instruction
  5268. set architecture (ISA) version of the assembly program.
  5269. *vendor* and *arch* are quoted strings. *vendor* should always be equal to
  5270. "AMD" and *arch* should always be equal to "AMDGPU".
  5271. By default, the assembler will derive the ISA version, *vendor*, and *arch*
  5272. from the value of the -mcpu option that is passed to the assembler.
  5273. .. _amdgpu-amdhsa-assembler-directive-amdgpu_hsa_kernel:
  5274. .amdgpu_hsa_kernel (name)
  5275. +++++++++++++++++++++++++
  5276. This directives specifies that the symbol with given name is a kernel entry point
  5277. (label) and the object should contain corresponding symbol of type STT_AMDGPU_HSA_KERNEL.
  5278. .amd_kernel_code_t
  5279. ++++++++++++++++++
  5280. This directive marks the beginning of a list of key / value pairs that are used
  5281. to specify the amd_kernel_code_t object that will be emitted by the assembler.
  5282. The list must be terminated by the *.end_amd_kernel_code_t* directive. For
  5283. any amd_kernel_code_t values that are unspecified a default value will be
  5284. used. The default value for all keys is 0, with the following exceptions:
  5285. - *amd_code_version_major* defaults to 1.
  5286. - *amd_kernel_code_version_minor* defaults to 2.
  5287. - *amd_machine_kind* defaults to 1.
  5288. - *amd_machine_version_major*, *machine_version_minor*, and
  5289. *amd_machine_version_stepping* are derived from the value of the -mcpu option
  5290. that is passed to the assembler.
  5291. - *kernel_code_entry_byte_offset* defaults to 256.
  5292. - *wavefront_size* defaults 6 for all targets before GFX10. For GFX10 onwards
  5293. defaults to 6 if target feature ``wavefrontsize64`` is enabled, otherwise 5.
  5294. Note that wavefront size is specified as a power of two, so a value of **n**
  5295. means a size of 2^ **n**.
  5296. - *call_convention* defaults to -1.
  5297. - *kernarg_segment_alignment*, *group_segment_alignment*, and
  5298. *private_segment_alignment* default to 4. Note that alignments are specified
  5299. as a power of 2, so a value of **n** means an alignment of 2^ **n**.
  5300. - *enable_wgp_mode* defaults to 1 if target feature ``cumode`` is disabled for
  5301. GFX10 onwards.
  5302. - *enable_mem_ordered* defaults to 1 for GFX10 onwards.
  5303. The *.amd_kernel_code_t* directive must be placed immediately after the
  5304. function label and before any instructions.
  5305. For a full list of amd_kernel_code_t keys, refer to AMDGPU ABI document,
  5306. comments in lib/Target/AMDGPU/AmdKernelCodeT.h and test/CodeGen/AMDGPU/hsa.s.
  5307. .. _amdgpu-amdhsa-assembler-example-v2:
  5308. Code Object V2 Example Source Code (-mattr=-code-object-v3)
  5309. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5310. .. warning:: Code Object V2 is not the default code object version emitted by
  5311. this version of LLVM. For a description of the directives supported with
  5312. the default configuration (Code Object V3) see
  5313. :ref:`amdgpu-amdhsa-assembler-example-v3`.
  5314. Here is an example of a minimal assembly source file, defining one HSA kernel:
  5315. .. code-block:: none
  5316. .hsa_code_object_version 1,0
  5317. .hsa_code_object_isa
  5318. .hsatext
  5319. .globl hello_world
  5320. .p2align 8
  5321. .amdgpu_hsa_kernel hello_world
  5322. hello_world:
  5323. .amd_kernel_code_t
  5324. enable_sgpr_kernarg_segment_ptr = 1
  5325. is_ptr64 = 1
  5326. compute_pgm_rsrc1_vgprs = 0
  5327. compute_pgm_rsrc1_sgprs = 0
  5328. compute_pgm_rsrc2_user_sgpr = 2
  5329. compute_pgm_rsrc1_wgp_mode = 0
  5330. compute_pgm_rsrc1_mem_ordered = 0
  5331. compute_pgm_rsrc1_fwd_progress = 1
  5332. .end_amd_kernel_code_t
  5333. s_load_dwordx2 s[0:1], s[0:1] 0x0
  5334. v_mov_b32 v0, 3.14159
  5335. s_waitcnt lgkmcnt(0)
  5336. v_mov_b32 v1, s0
  5337. v_mov_b32 v2, s1
  5338. flat_store_dword v[1:2], v0
  5339. s_endpgm
  5340. .Lfunc_end0:
  5341. .size hello_world, .Lfunc_end0-hello_world
  5342. .. _amdgpu-amdhsa-assembler-predefined-symbols-v3:
  5343. Code Object V3 Predefined Symbols (-mattr=+code-object-v3)
  5344. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5345. The AMDGPU assembler defines and updates some symbols automatically. These
  5346. symbols do not affect code generation.
  5347. .amdgcn.gfx_generation_number
  5348. +++++++++++++++++++++++++++++
  5349. Set to the GFX major generation number of the target being assembled for. For
  5350. example, when assembling for a "GFX9" target this will be set to the integer
  5351. value "9". The possible GFX major generation numbers are presented in
  5352. :ref:`amdgpu-processors`.
  5353. .amdgcn.gfx_generation_minor
  5354. ++++++++++++++++++++++++++++
  5355. Set to the GFX minor generation number of the target being assembled for. For
  5356. example, when assembling for a "GFX810" target this will be set to the integer
  5357. value "1". The possible GFX minor generation numbers are presented in
  5358. :ref:`amdgpu-processors`.
  5359. .amdgcn.gfx_generation_stepping
  5360. +++++++++++++++++++++++++++++++
  5361. Set to the GFX stepping generation number of the target being assembled for.
  5362. For example, when assembling for a "GFX704" target this will be set to the
  5363. integer value "4". The possible GFX stepping generation numbers are presented
  5364. in :ref:`amdgpu-processors`.
  5365. .. _amdgpu-amdhsa-assembler-symbol-next_free_vgpr:
  5366. .amdgcn.next_free_vgpr
  5367. ++++++++++++++++++++++
  5368. Set to zero before assembly begins. At each instruction, if the current value
  5369. of this symbol is less than or equal to the maximum VGPR number explicitly
  5370. referenced within that instruction then the symbol value is updated to equal
  5371. that VGPR number plus one.
  5372. May be used to set the `.amdhsa_next_free_vpgr` directive in
  5373. :ref:`amdhsa-kernel-directives-table`.
  5374. May be set at any time, e.g. manually set to zero at the start of each kernel.
  5375. .. _amdgpu-amdhsa-assembler-symbol-next_free_sgpr:
  5376. .amdgcn.next_free_sgpr
  5377. ++++++++++++++++++++++
  5378. Set to zero before assembly begins. At each instruction, if the current value
  5379. of this symbol is less than or equal the maximum SGPR number explicitly
  5380. referenced within that instruction then the symbol value is updated to equal
  5381. that SGPR number plus one.
  5382. May be used to set the `.amdhsa_next_free_spgr` directive in
  5383. :ref:`amdhsa-kernel-directives-table`.
  5384. May be set at any time, e.g. manually set to zero at the start of each kernel.
  5385. .. _amdgpu-amdhsa-assembler-directives-v3:
  5386. Code Object V3 Directives (-mattr=+code-object-v3)
  5387. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5388. Directives which begin with ``.amdgcn`` are valid for all ``amdgcn``
  5389. architecture processors, and are not OS-specific. Directives which begin with
  5390. ``.amdhsa`` are specific to ``amdgcn`` architecture processors when the
  5391. ``amdhsa`` OS is specified. See :ref:`amdgpu-target-triples` and
  5392. :ref:`amdgpu-processors`.
  5393. .amdgcn_target <target>
  5394. +++++++++++++++++++++++
  5395. Optional directive which declares the target supported by the containing
  5396. assembler source file. Valid values are described in
  5397. :ref:`amdgpu-amdhsa-code-object-target-identification`. Used by the assembler
  5398. to validate command-line options such as ``-triple``, ``-mcpu``, and those
  5399. which specify target features.
  5400. .amdhsa_kernel <name>
  5401. +++++++++++++++++++++
  5402. Creates a correctly aligned AMDHSA kernel descriptor and a symbol,
  5403. ``<name>.kd``, in the current location of the current section. Only valid when
  5404. the OS is ``amdhsa``. ``<name>`` must be a symbol that labels the first
  5405. instruction to execute, and does not need to be previously defined.
  5406. Marks the beginning of a list of directives used to generate the bytes of a
  5407. kernel descriptor, as described in :ref:`amdgpu-amdhsa-kernel-descriptor`.
  5408. Directives which may appear in this list are described in
  5409. :ref:`amdhsa-kernel-directives-table`. Directives may appear in any order, must
  5410. be valid for the target being assembled for, and cannot be repeated. Directives
  5411. support the range of values specified by the field they reference in
  5412. :ref:`amdgpu-amdhsa-kernel-descriptor`. If a directive is not specified, it is
  5413. assumed to have its default value, unless it is marked as "Required", in which
  5414. case it is an error to omit the directive. This list of directives is
  5415. terminated by an ``.end_amdhsa_kernel`` directive.
  5416. .. table:: AMDHSA Kernel Assembler Directives
  5417. :name: amdhsa-kernel-directives-table
  5418. ======================================================== =================== ============ ===================
  5419. Directive Default Supported On Description
  5420. ======================================================== =================== ============ ===================
  5421. ``.amdhsa_group_segment_fixed_size`` 0 GFX6-GFX10 Controls GROUP_SEGMENT_FIXED_SIZE in
  5422. :ref:`amdgpu-amdhsa-kernel-descriptor-gfx6-gfx10-table`.
  5423. ``.amdhsa_private_segment_fixed_size`` 0 GFX6-GFX10 Controls PRIVATE_SEGMENT_FIXED_SIZE in
  5424. :ref:`amdgpu-amdhsa-kernel-descriptor-gfx6-gfx10-table`.
  5425. ``.amdhsa_user_sgpr_private_segment_buffer`` 0 GFX6-GFX10 Controls ENABLE_SGPR_PRIVATE_SEGMENT_BUFFER in
  5426. :ref:`amdgpu-amdhsa-kernel-descriptor-gfx6-gfx10-table`.
  5427. ``.amdhsa_user_sgpr_dispatch_ptr`` 0 GFX6-GFX10 Controls ENABLE_SGPR_DISPATCH_PTR in
  5428. :ref:`amdgpu-amdhsa-kernel-descriptor-gfx6-gfx10-table`.
  5429. ``.amdhsa_user_sgpr_queue_ptr`` 0 GFX6-GFX10 Controls ENABLE_SGPR_QUEUE_PTR in
  5430. :ref:`amdgpu-amdhsa-kernel-descriptor-gfx6-gfx10-table`.
  5431. ``.amdhsa_user_sgpr_kernarg_segment_ptr`` 0 GFX6-GFX10 Controls ENABLE_SGPR_KERNARG_SEGMENT_PTR in
  5432. :ref:`amdgpu-amdhsa-kernel-descriptor-gfx6-gfx10-table`.
  5433. ``.amdhsa_user_sgpr_dispatch_id`` 0 GFX6-GFX10 Controls ENABLE_SGPR_DISPATCH_ID in
  5434. :ref:`amdgpu-amdhsa-kernel-descriptor-gfx6-gfx10-table`.
  5435. ``.amdhsa_user_sgpr_flat_scratch_init`` 0 GFX6-GFX10 Controls ENABLE_SGPR_FLAT_SCRATCH_INIT in
  5436. :ref:`amdgpu-amdhsa-kernel-descriptor-gfx6-gfx10-table`.
  5437. ``.amdhsa_user_sgpr_private_segment_size`` 0 GFX6-GFX10 Controls ENABLE_SGPR_PRIVATE_SEGMENT_SIZE in
  5438. :ref:`amdgpu-amdhsa-kernel-descriptor-gfx6-gfx10-table`.
  5439. ``.amdhsa_wavefront_size32`` Target GFX10 Controls ENABLE_WAVEFRONT_SIZE32 in
  5440. Feature :ref:`amdgpu-amdhsa-kernel-descriptor-gfx6-gfx10-table`.
  5441. Specific
  5442. (-wavefrontsize64)
  5443. ``.amdhsa_system_sgpr_private_segment_wavefront_offset`` 0 GFX6-GFX10 Controls ENABLE_SGPR_PRIVATE_SEGMENT_WAVEFRONT_OFFSET in
  5444. :ref:`amdgpu-amdhsa-compute_pgm_rsrc2-gfx6-gfx10-table`.
  5445. ``.amdhsa_system_sgpr_workgroup_id_x`` 1 GFX6-GFX10 Controls ENABLE_SGPR_WORKGROUP_ID_X in
  5446. :ref:`amdgpu-amdhsa-compute_pgm_rsrc2-gfx6-gfx10-table`.
  5447. ``.amdhsa_system_sgpr_workgroup_id_y`` 0 GFX6-GFX10 Controls ENABLE_SGPR_WORKGROUP_ID_Y in
  5448. :ref:`amdgpu-amdhsa-compute_pgm_rsrc2-gfx6-gfx10-table`.
  5449. ``.amdhsa_system_sgpr_workgroup_id_z`` 0 GFX6-GFX10 Controls ENABLE_SGPR_WORKGROUP_ID_Z in
  5450. :ref:`amdgpu-amdhsa-compute_pgm_rsrc2-gfx6-gfx10-table`.
  5451. ``.amdhsa_system_sgpr_workgroup_info`` 0 GFX6-GFX10 Controls ENABLE_SGPR_WORKGROUP_INFO in
  5452. :ref:`amdgpu-amdhsa-compute_pgm_rsrc2-gfx6-gfx10-table`.
  5453. ``.amdhsa_system_vgpr_workitem_id`` 0 GFX6-GFX10 Controls ENABLE_VGPR_WORKITEM_ID in
  5454. :ref:`amdgpu-amdhsa-compute_pgm_rsrc2-gfx6-gfx10-table`.
  5455. Possible values are defined in
  5456. :ref:`amdgpu-amdhsa-system-vgpr-work-item-id-enumeration-values-table`.
  5457. ``.amdhsa_next_free_vgpr`` Required GFX6-GFX10 Maximum VGPR number explicitly referenced, plus one.
  5458. Used to calculate GRANULATED_WORKITEM_VGPR_COUNT in
  5459. :ref:`amdgpu-amdhsa-compute_pgm_rsrc1-gfx6-gfx10-table`.
  5460. ``.amdhsa_next_free_sgpr`` Required GFX6-GFX10 Maximum SGPR number explicitly referenced, plus one.
  5461. Used to calculate GRANULATED_WAVEFRONT_SGPR_COUNT in
  5462. :ref:`amdgpu-amdhsa-compute_pgm_rsrc1-gfx6-gfx10-table`.
  5463. ``.amdhsa_reserve_vcc`` 1 GFX6-GFX10 Whether the kernel may use the special VCC SGPR.
  5464. Used to calculate GRANULATED_WAVEFRONT_SGPR_COUNT in
  5465. :ref:`amdgpu-amdhsa-compute_pgm_rsrc1-gfx6-gfx10-table`.
  5466. ``.amdhsa_reserve_flat_scratch`` 1 GFX7-GFX10 Whether the kernel may use flat instructions to access
  5467. scratch memory. Used to calculate
  5468. GRANULATED_WAVEFRONT_SGPR_COUNT in
  5469. :ref:`amdgpu-amdhsa-compute_pgm_rsrc1-gfx6-gfx10-table`.
  5470. ``.amdhsa_reserve_xnack_mask`` Target GFX8-GFX10 Whether the kernel may trigger XNACK replay.
  5471. Feature Used to calculate GRANULATED_WAVEFRONT_SGPR_COUNT in
  5472. Specific :ref:`amdgpu-amdhsa-compute_pgm_rsrc1-gfx6-gfx10-table`.
  5473. (+xnack)
  5474. ``.amdhsa_float_round_mode_32`` 0 GFX6-GFX10 Controls FLOAT_ROUND_MODE_32 in
  5475. :ref:`amdgpu-amdhsa-compute_pgm_rsrc1-gfx6-gfx10-table`.
  5476. Possible values are defined in
  5477. :ref:`amdgpu-amdhsa-floating-point-rounding-mode-enumeration-values-table`.
  5478. ``.amdhsa_float_round_mode_16_64`` 0 GFX6-GFX10 Controls FLOAT_ROUND_MODE_16_64 in
  5479. :ref:`amdgpu-amdhsa-compute_pgm_rsrc1-gfx6-gfx10-table`.
  5480. Possible values are defined in
  5481. :ref:`amdgpu-amdhsa-floating-point-rounding-mode-enumeration-values-table`.
  5482. ``.amdhsa_float_denorm_mode_32`` 0 GFX6-GFX10 Controls FLOAT_DENORM_MODE_32 in
  5483. :ref:`amdgpu-amdhsa-compute_pgm_rsrc1-gfx6-gfx10-table`.
  5484. Possible values are defined in
  5485. :ref:`amdgpu-amdhsa-floating-point-denorm-mode-enumeration-values-table`.
  5486. ``.amdhsa_float_denorm_mode_16_64`` 3 GFX6-GFX10 Controls FLOAT_DENORM_MODE_16_64 in
  5487. :ref:`amdgpu-amdhsa-compute_pgm_rsrc1-gfx6-gfx10-table`.
  5488. Possible values are defined in
  5489. :ref:`amdgpu-amdhsa-floating-point-denorm-mode-enumeration-values-table`.
  5490. ``.amdhsa_dx10_clamp`` 1 GFX6-GFX10 Controls ENABLE_DX10_CLAMP in
  5491. :ref:`amdgpu-amdhsa-compute_pgm_rsrc1-gfx6-gfx10-table`.
  5492. ``.amdhsa_ieee_mode`` 1 GFX6-GFX10 Controls ENABLE_IEEE_MODE in
  5493. :ref:`amdgpu-amdhsa-compute_pgm_rsrc1-gfx6-gfx10-table`.
  5494. ``.amdhsa_fp16_overflow`` 0 GFX9-GFX10 Controls FP16_OVFL in
  5495. :ref:`amdgpu-amdhsa-compute_pgm_rsrc1-gfx6-gfx10-table`.
  5496. ``.amdhsa_workgroup_processor_mode`` Target GFX10 Controls ENABLE_WGP_MODE in
  5497. Feature :ref:`amdgpu-amdhsa-kernel-descriptor-gfx6-gfx10-table`.
  5498. Specific
  5499. (-cumode)
  5500. ``.amdhsa_memory_ordered`` 1 GFX10 Controls MEM_ORDERED in
  5501. :ref:`amdgpu-amdhsa-compute_pgm_rsrc1-gfx6-gfx10-table`.
  5502. ``.amdhsa_forward_progress`` 0 GFX10 Controls FWD_PROGRESS in
  5503. :ref:`amdgpu-amdhsa-compute_pgm_rsrc1-gfx6-gfx10-table`.
  5504. ``.amdhsa_exception_fp_ieee_invalid_op`` 0 GFX6-GFX10 Controls ENABLE_EXCEPTION_IEEE_754_FP_INVALID_OPERATION in
  5505. :ref:`amdgpu-amdhsa-compute_pgm_rsrc2-gfx6-gfx10-table`.
  5506. ``.amdhsa_exception_fp_denorm_src`` 0 GFX6-GFX10 Controls ENABLE_EXCEPTION_FP_DENORMAL_SOURCE in
  5507. :ref:`amdgpu-amdhsa-compute_pgm_rsrc2-gfx6-gfx10-table`.
  5508. ``.amdhsa_exception_fp_ieee_div_zero`` 0 GFX6-GFX10 Controls ENABLE_EXCEPTION_IEEE_754_FP_DIVISION_BY_ZERO in
  5509. :ref:`amdgpu-amdhsa-compute_pgm_rsrc2-gfx6-gfx10-table`.
  5510. ``.amdhsa_exception_fp_ieee_overflow`` 0 GFX6-GFX10 Controls ENABLE_EXCEPTION_IEEE_754_FP_OVERFLOW in
  5511. :ref:`amdgpu-amdhsa-compute_pgm_rsrc2-gfx6-gfx10-table`.
  5512. ``.amdhsa_exception_fp_ieee_underflow`` 0 GFX6-GFX10 Controls ENABLE_EXCEPTION_IEEE_754_FP_UNDERFLOW in
  5513. :ref:`amdgpu-amdhsa-compute_pgm_rsrc2-gfx6-gfx10-table`.
  5514. ``.amdhsa_exception_fp_ieee_inexact`` 0 GFX6-GFX10 Controls ENABLE_EXCEPTION_IEEE_754_FP_INEXACT in
  5515. :ref:`amdgpu-amdhsa-compute_pgm_rsrc2-gfx6-gfx10-table`.
  5516. ``.amdhsa_exception_int_div_zero`` 0 GFX6-GFX10 Controls ENABLE_EXCEPTION_INT_DIVIDE_BY_ZERO in
  5517. :ref:`amdgpu-amdhsa-compute_pgm_rsrc2-gfx6-gfx10-table`.
  5518. ======================================================== =================== ============ ===================
  5519. .amdgpu_metadata
  5520. ++++++++++++++++
  5521. Optional directive which declares the contents of the ``NT_AMDGPU_METADATA``
  5522. note record (see :ref:`amdgpu-elf-note-records-table-v3`).
  5523. The contents must be in the [YAML]_ markup format, with the same structure and
  5524. semantics described in :ref:`amdgpu-amdhsa-code-object-metadata-v3`.
  5525. This directive is terminated by an ``.end_amdgpu_metadata`` directive.
  5526. .. _amdgpu-amdhsa-assembler-example-v3:
  5527. Code Object V3 Example Source Code (-mattr=+code-object-v3)
  5528. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5529. Here is an example of a minimal assembly source file, defining one HSA kernel:
  5530. .. code-block:: none
  5531. .amdgcn_target "amdgcn-amd-amdhsa--gfx900+xnack" // optional
  5532. .text
  5533. .globl hello_world
  5534. .p2align 8
  5535. .type hello_world,@function
  5536. hello_world:
  5537. s_load_dwordx2 s[0:1], s[0:1] 0x0
  5538. v_mov_b32 v0, 3.14159
  5539. s_waitcnt lgkmcnt(0)
  5540. v_mov_b32 v1, s0
  5541. v_mov_b32 v2, s1
  5542. flat_store_dword v[1:2], v0
  5543. s_endpgm
  5544. .Lfunc_end0:
  5545. .size hello_world, .Lfunc_end0-hello_world
  5546. .rodata
  5547. .p2align 6
  5548. .amdhsa_kernel hello_world
  5549. .amdhsa_user_sgpr_kernarg_segment_ptr 1
  5550. .amdhsa_next_free_vgpr .amdgcn.next_free_vgpr
  5551. .amdhsa_next_free_sgpr .amdgcn.next_free_sgpr
  5552. .end_amdhsa_kernel
  5553. .amdgpu_metadata
  5554. ---
  5555. amdhsa.version:
  5556. - 1
  5557. - 0
  5558. amdhsa.kernels:
  5559. - .name: hello_world
  5560. .symbol: hello_world.kd
  5561. .kernarg_segment_size: 48
  5562. .group_segment_fixed_size: 0
  5563. .private_segment_fixed_size: 0
  5564. .kernarg_segment_align: 4
  5565. .wavefront_size: 64
  5566. .sgpr_count: 2
  5567. .vgpr_count: 3
  5568. .max_flat_workgroup_size: 256
  5569. ...
  5570. .end_amdgpu_metadata
  5571. If an assembly source file contains multiple kernels and/or functions, the
  5572. :ref:`amdgpu-amdhsa-assembler-symbol-next_free_vgpr` and
  5573. :ref:`amdgpu-amdhsa-assembler-symbol-next_free_sgpr` symbols may be reset using
  5574. the ``.set <symbol>, <expression>`` directive. For example, in the case of two
  5575. kernels, where ``function1`` is only called from ``kernel1`` it is sufficient
  5576. to group the function with the kernel that calls it and reset the symbols
  5577. between the two connected components:
  5578. .. code-block:: none
  5579. .amdgcn_target "amdgcn-amd-amdhsa--gfx900+xnack" // optional
  5580. // gpr tracking symbols are implicitly set to zero
  5581. .text
  5582. .globl kern0
  5583. .p2align 8
  5584. .type kern0,@function
  5585. kern0:
  5586. // ...
  5587. s_endpgm
  5588. .Lkern0_end:
  5589. .size kern0, .Lkern0_end-kern0
  5590. .rodata
  5591. .p2align 6
  5592. .amdhsa_kernel kern0
  5593. // ...
  5594. .amdhsa_next_free_vgpr .amdgcn.next_free_vgpr
  5595. .amdhsa_next_free_sgpr .amdgcn.next_free_sgpr
  5596. .end_amdhsa_kernel
  5597. // reset symbols to begin tracking usage in func1 and kern1
  5598. .set .amdgcn.next_free_vgpr, 0
  5599. .set .amdgcn.next_free_sgpr, 0
  5600. .text
  5601. .hidden func1
  5602. .global func1
  5603. .p2align 2
  5604. .type func1,@function
  5605. func1:
  5606. // ...
  5607. s_setpc_b64 s[30:31]
  5608. .Lfunc1_end:
  5609. .size func1, .Lfunc1_end-func1
  5610. .globl kern1
  5611. .p2align 8
  5612. .type kern1,@function
  5613. kern1:
  5614. // ...
  5615. s_getpc_b64 s[4:5]
  5616. s_add_u32 s4, s4, func1@rel32@lo+4
  5617. s_addc_u32 s5, s5, func1@rel32@lo+4
  5618. s_swappc_b64 s[30:31], s[4:5]
  5619. // ...
  5620. s_endpgm
  5621. .Lkern1_end:
  5622. .size kern1, .Lkern1_end-kern1
  5623. .rodata
  5624. .p2align 6
  5625. .amdhsa_kernel kern1
  5626. // ...
  5627. .amdhsa_next_free_vgpr .amdgcn.next_free_vgpr
  5628. .amdhsa_next_free_sgpr .amdgcn.next_free_sgpr
  5629. .end_amdhsa_kernel
  5630. These symbols cannot identify connected components in order to automatically
  5631. track the usage for each kernel. However, in some cases careful organization of
  5632. the kernels and functions in the source file means there is minimal additional
  5633. effort required to accurately calculate GPR usage.
  5634. Additional Documentation
  5635. ========================
  5636. .. [AMD-RADEON-HD-2000-3000] `AMD R6xx shader ISA <http://developer.amd.com/wordpress/media/2012/10/R600_Instruction_Set_Architecture.pdf>`__
  5637. .. [AMD-RADEON-HD-4000] `AMD R7xx shader ISA <http://developer.amd.com/wordpress/media/2012/10/R700-Family_Instruction_Set_Architecture.pdf>`__
  5638. .. [AMD-RADEON-HD-5000] `AMD Evergreen shader ISA <http://developer.amd.com/wordpress/media/2012/10/AMD_Evergreen-Family_Instruction_Set_Architecture.pdf>`__
  5639. .. [AMD-RADEON-HD-6000] `AMD Cayman/Trinity shader ISA <http://developer.amd.com/wordpress/media/2012/10/AMD_HD_6900_Series_Instruction_Set_Architecture.pdf>`__
  5640. .. [AMD-GCN-GFX6] `AMD Southern Islands Series ISA <http://developer.amd.com/wordpress/media/2012/12/AMD_Southern_Islands_Instruction_Set_Architecture.pdf>`__
  5641. .. [AMD-GCN-GFX7] `AMD Sea Islands Series ISA <http://developer.amd.com/wordpress/media/2013/07/AMD_Sea_Islands_Instruction_Set_Architecture.pdf>`_
  5642. .. [AMD-GCN-GFX8] `AMD GCN3 Instruction Set Architecture <http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2013/12/AMD_GCN3_Instruction_Set_Architecture_rev1.1.pdf>`__
  5643. .. [AMD-GCN-GFX9] `AMD "Vega" Instruction Set Architecture <http://developer.amd.com/wordpress/media/2013/12/Vega_Shader_ISA_28July2017.pdf>`__
  5644. .. [AMD-GCN-GFX10] AMD "Navi" Instruction Set Architecture *TBA*
  5645. .. TODO
  5646. ttye Add link when made public.
  5647. .. [AMD-ROCm] `ROCm: Open Platform for Development, Discovery and Education Around GPU Computing <http://gpuopen.com/compute-product/rocm/>`__
  5648. .. [AMD-ROCm-github] `ROCm github <http://github.com/RadeonOpenCompute>`__
  5649. .. [HSA] `Heterogeneous System Architecture (HSA) Foundation <http://www.hsafoundation.com/>`__
  5650. .. [ELF] `Executable and Linkable Format (ELF) <http://www.sco.com/developers/gabi/>`__
  5651. .. [DWARF] `DWARF Debugging Information Format <http://dwarfstd.org/>`__
  5652. .. [YAML] `YAML Ain't Markup Language (YAML™) Version 1.2 <http://www.yaml.org/spec/1.2/spec.html>`__
  5653. .. [MsgPack] `Message Pack <http://www.msgpack.org/>`__
  5654. .. [OpenCL] `The OpenCL Specification Version 2.0 <http://www.khronos.org/registry/cl/specs/opencl-2.0.pdf>`__
  5655. .. [HRF] `Heterogeneous-race-free Memory Models <http://benedictgaster.org/wp-content/uploads/2014/01/asplos269-FINAL.pdf>`__
  5656. .. [CLANG-ATTR] `Attributes in Clang <http://clang.llvm.org/docs/AttributeReference.html>`__