You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

opdef.cpp.inl 260 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944
  1. // clang-format off
  2. MGB_DYN_TYPE_OBJ_FINAL_IMPL(AdaptivePooling);
  3. namespace {
  4. size_t AdaptivePooling_hash_impl(const OpDef& def_) {
  5. auto&& op_ = def_.cast_final_safe<AdaptivePooling>();
  6. static_cast<void>(op_);
  7. size_t val = mgb::hash(op_.dyn_typeinfo());
  8. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode));
  9. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format));
  10. val = mgb::hash_pair_combine(val, mgb::hash(op_.shape));
  11. return val;
  12. }
  13. bool AdaptivePooling_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  14. auto &&a_ = lhs_.cast_final_safe<AdaptivePooling>(),
  15. &&b_ = rhs_.cast_final_safe<AdaptivePooling>();
  16. static_cast<void>(a_);
  17. static_cast<void>(b_);
  18. if (a_.mode != b_.mode) return false;
  19. if (a_.format != b_.format) return false;
  20. if (a_.shape != b_.shape) return false;
  21. return true;
  22. }
  23. std::vector<std::pair<const char*, std::string>> AdaptivePooling_props_impl(const OpDef& def_) {
  24. auto&& op_ = def_.cast_final_safe<AdaptivePooling>();
  25. static_cast<void>(op_);
  26. std::vector<std::pair<const char*, std::string>> props_;
  27. switch (op_.mode){
  28. case AdaptivePooling::Mode::MAX:
  29. props_.emplace_back("mode", "MAX");
  30. break;
  31. case AdaptivePooling::Mode::AVERAGE:
  32. props_.emplace_back("mode", "AVERAGE");
  33. break;
  34. case AdaptivePooling::Mode::AVERAGE_COUNT_EXCLUDE_PADDING:
  35. props_.emplace_back("mode", "AVERAGE_COUNT_EXCLUDE_PADDING");
  36. break;
  37. default:
  38. props_.emplace_back("mode", "INVALID");
  39. break;
  40. }
  41. switch (op_.format){
  42. case AdaptivePooling::Format::NCHW:
  43. props_.emplace_back("format", "NCHW");
  44. break;
  45. case AdaptivePooling::Format::NHWC:
  46. props_.emplace_back("format", "NHWC");
  47. break;
  48. case AdaptivePooling::Format::NHWCD4:
  49. props_.emplace_back("format", "NHWCD4");
  50. break;
  51. case AdaptivePooling::Format::NCHW4:
  52. props_.emplace_back("format", "NCHW4");
  53. break;
  54. case AdaptivePooling::Format::NCHW8:
  55. props_.emplace_back("format", "NCHW8");
  56. break;
  57. case AdaptivePooling::Format::NCHW32:
  58. props_.emplace_back("format", "NCHW32");
  59. break;
  60. case AdaptivePooling::Format::NCHW88:
  61. props_.emplace_back("format", "NCHW88");
  62. break;
  63. case AdaptivePooling::Format::NCHW44:
  64. props_.emplace_back("format", "NCHW44");
  65. break;
  66. case AdaptivePooling::Format::NCHW44_DOT:
  67. props_.emplace_back("format", "NCHW44_DOT");
  68. break;
  69. case AdaptivePooling::Format::NCHW4_NCHW32:
  70. props_.emplace_back("format", "NCHW4_NCHW32");
  71. break;
  72. case AdaptivePooling::Format::NCHW32_NCHW4:
  73. props_.emplace_back("format", "NCHW32_NCHW4");
  74. break;
  75. case AdaptivePooling::Format::NCHW4_NCHW:
  76. props_.emplace_back("format", "NCHW4_NCHW");
  77. break;
  78. case AdaptivePooling::Format::NHWC_NCHW:
  79. props_.emplace_back("format", "NHWC_NCHW");
  80. break;
  81. case AdaptivePooling::Format::NHWC_NCHW4_IC_SMALL:
  82. props_.emplace_back("format", "NHWC_NCHW4_IC_SMALL");
  83. break;
  84. case AdaptivePooling::Format::NCHW_NCHW4_IC_SMALL:
  85. props_.emplace_back("format", "NCHW_NCHW4_IC_SMALL");
  86. break;
  87. case AdaptivePooling::Format::CHWN4:
  88. props_.emplace_back("format", "CHWN4");
  89. break;
  90. case AdaptivePooling::Format::NCHW64:
  91. props_.emplace_back("format", "NCHW64");
  92. break;
  93. case AdaptivePooling::Format::NCHW4_NHWC:
  94. props_.emplace_back("format", "NCHW4_NHWC");
  95. break;
  96. default:
  97. props_.emplace_back("format", "INVALID");
  98. break;
  99. }
  100. props_.emplace_back("shape", "{std::vector}");
  101. return props_;
  102. }
  103. std::string AdaptivePooling_make_name_impl(const OpDef& def_) {
  104. auto&& op_ = def_.cast_final_safe<AdaptivePooling>();
  105. static_cast<void>(op_);
  106. return "AdaptivePooling";
  107. }
  108. } // anonymous namespace
  109. OP_TRAIT_REG(AdaptivePooling, AdaptivePooling)
  110. .hash(AdaptivePooling_hash_impl)
  111. .is_same_st(AdaptivePooling_is_same_st_impl)
  112. .props(AdaptivePooling_props_impl)
  113. .make_name(AdaptivePooling_make_name_impl);
  114. MGB_DYN_TYPE_OBJ_FINAL_IMPL(AddAxis);
  115. namespace {
  116. size_t AddAxis_hash_impl(const OpDef& def_) {
  117. auto&& op_ = def_.cast_final_safe<AddAxis>();
  118. static_cast<void>(op_);
  119. size_t val = mgb::hash(op_.dyn_typeinfo());
  120. val = mgb::hash_pair_combine(val, mgb::hash(op_.axis));
  121. return val;
  122. }
  123. bool AddAxis_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  124. auto &&a_ = lhs_.cast_final_safe<AddAxis>(),
  125. &&b_ = rhs_.cast_final_safe<AddAxis>();
  126. static_cast<void>(a_);
  127. static_cast<void>(b_);
  128. if (a_.axis != b_.axis) return false;
  129. return true;
  130. }
  131. std::vector<std::pair<const char*, std::string>> AddAxis_props_impl(const OpDef& def_) {
  132. auto&& op_ = def_.cast_final_safe<AddAxis>();
  133. static_cast<void>(op_);
  134. std::vector<std::pair<const char*, std::string>> props_;
  135. props_.emplace_back("axis", "{std::vector}");
  136. return props_;
  137. }
  138. std::string AddAxis_make_name_impl(const OpDef& def_) {
  139. auto&& op_ = def_.cast_final_safe<AddAxis>();
  140. static_cast<void>(op_);
  141. return "AddAxis";
  142. }
  143. } // anonymous namespace
  144. OP_TRAIT_REG(AddAxis, AddAxis)
  145. .hash(AddAxis_hash_impl)
  146. .is_same_st(AddAxis_is_same_st_impl)
  147. .props(AddAxis_props_impl)
  148. .make_name(AddAxis_make_name_impl);
  149. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Argmax);
  150. namespace {
  151. size_t Argmax_hash_impl(const OpDef& def_) {
  152. auto&& op_ = def_.cast_final_safe<Argmax>();
  153. static_cast<void>(op_);
  154. size_t val = mgb::hash(op_.dyn_typeinfo());
  155. val = mgb::hash_pair_combine(val, mgb::hash(op_.axis));
  156. return val;
  157. }
  158. bool Argmax_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  159. auto &&a_ = lhs_.cast_final_safe<Argmax>(),
  160. &&b_ = rhs_.cast_final_safe<Argmax>();
  161. static_cast<void>(a_);
  162. static_cast<void>(b_);
  163. if (a_.axis != b_.axis) return false;
  164. return true;
  165. }
  166. std::vector<std::pair<const char*, std::string>> Argmax_props_impl(const OpDef& def_) {
  167. auto&& op_ = def_.cast_final_safe<Argmax>();
  168. static_cast<void>(op_);
  169. std::vector<std::pair<const char*, std::string>> props_;
  170. props_.emplace_back("axis", std::to_string(op_.axis));
  171. return props_;
  172. }
  173. std::string Argmax_make_name_impl(const OpDef& def_) {
  174. auto&& op_ = def_.cast_final_safe<Argmax>();
  175. static_cast<void>(op_);
  176. return "Argmax";
  177. }
  178. } // anonymous namespace
  179. OP_TRAIT_REG(Argmax, Argmax)
  180. .hash(Argmax_hash_impl)
  181. .is_same_st(Argmax_is_same_st_impl)
  182. .props(Argmax_props_impl)
  183. .make_name(Argmax_make_name_impl);
  184. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Argmin);
  185. namespace {
  186. size_t Argmin_hash_impl(const OpDef& def_) {
  187. auto&& op_ = def_.cast_final_safe<Argmin>();
  188. static_cast<void>(op_);
  189. size_t val = mgb::hash(op_.dyn_typeinfo());
  190. val = mgb::hash_pair_combine(val, mgb::hash(op_.axis));
  191. return val;
  192. }
  193. bool Argmin_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  194. auto &&a_ = lhs_.cast_final_safe<Argmin>(),
  195. &&b_ = rhs_.cast_final_safe<Argmin>();
  196. static_cast<void>(a_);
  197. static_cast<void>(b_);
  198. if (a_.axis != b_.axis) return false;
  199. return true;
  200. }
  201. std::vector<std::pair<const char*, std::string>> Argmin_props_impl(const OpDef& def_) {
  202. auto&& op_ = def_.cast_final_safe<Argmin>();
  203. static_cast<void>(op_);
  204. std::vector<std::pair<const char*, std::string>> props_;
  205. props_.emplace_back("axis", std::to_string(op_.axis));
  206. return props_;
  207. }
  208. std::string Argmin_make_name_impl(const OpDef& def_) {
  209. auto&& op_ = def_.cast_final_safe<Argmin>();
  210. static_cast<void>(op_);
  211. return "Argmin";
  212. }
  213. } // anonymous namespace
  214. OP_TRAIT_REG(Argmin, Argmin)
  215. .hash(Argmin_hash_impl)
  216. .is_same_st(Argmin_is_same_st_impl)
  217. .props(Argmin_props_impl)
  218. .make_name(Argmin_make_name_impl);
  219. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Argsort);
  220. namespace {
  221. size_t Argsort_hash_impl(const OpDef& def_) {
  222. auto&& op_ = def_.cast_final_safe<Argsort>();
  223. static_cast<void>(op_);
  224. size_t val = mgb::hash(op_.dyn_typeinfo());
  225. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.order));
  226. return val;
  227. }
  228. bool Argsort_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  229. auto &&a_ = lhs_.cast_final_safe<Argsort>(),
  230. &&b_ = rhs_.cast_final_safe<Argsort>();
  231. static_cast<void>(a_);
  232. static_cast<void>(b_);
  233. if (a_.order != b_.order) return false;
  234. return true;
  235. }
  236. std::vector<std::pair<const char*, std::string>> Argsort_props_impl(const OpDef& def_) {
  237. auto&& op_ = def_.cast_final_safe<Argsort>();
  238. static_cast<void>(op_);
  239. std::vector<std::pair<const char*, std::string>> props_;
  240. switch (op_.order){
  241. case Argsort::Order::ASCENDING:
  242. props_.emplace_back("order", "ASCENDING");
  243. break;
  244. case Argsort::Order::DESCENDING:
  245. props_.emplace_back("order", "DESCENDING");
  246. break;
  247. default:
  248. props_.emplace_back("order", "INVALID");
  249. break;
  250. }
  251. return props_;
  252. }
  253. std::string Argsort_make_name_impl(const OpDef& def_) {
  254. auto&& op_ = def_.cast_final_safe<Argsort>();
  255. static_cast<void>(op_);
  256. return "Argsort";
  257. }
  258. } // anonymous namespace
  259. OP_TRAIT_REG(Argsort, Argsort)
  260. .hash(Argsort_hash_impl)
  261. .is_same_st(Argsort_is_same_st_impl)
  262. .props(Argsort_props_impl)
  263. .make_name(Argsort_make_name_impl);
  264. MGB_DYN_TYPE_OBJ_FINAL_IMPL(AssertEqual);
  265. namespace {
  266. size_t AssertEqual_hash_impl(const OpDef& def_) {
  267. auto&& op_ = def_.cast_final_safe<AssertEqual>();
  268. static_cast<void>(op_);
  269. size_t val = mgb::hash(op_.dyn_typeinfo());
  270. val = mgb::hash_pair_combine(val, mgb::hash(op_.maxerr));
  271. val = mgb::hash_pair_combine(val, mgb::hash(op_.verbose));
  272. return val;
  273. }
  274. bool AssertEqual_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  275. auto &&a_ = lhs_.cast_final_safe<AssertEqual>(),
  276. &&b_ = rhs_.cast_final_safe<AssertEqual>();
  277. static_cast<void>(a_);
  278. static_cast<void>(b_);
  279. if (a_.maxerr != b_.maxerr) return false;
  280. if (a_.verbose != b_.verbose) return false;
  281. return true;
  282. }
  283. std::vector<std::pair<const char*, std::string>> AssertEqual_props_impl(const OpDef& def_) {
  284. auto&& op_ = def_.cast_final_safe<AssertEqual>();
  285. static_cast<void>(op_);
  286. std::vector<std::pair<const char*, std::string>> props_;
  287. props_.emplace_back("maxerr", std::to_string(op_.maxerr));
  288. props_.emplace_back("verbose", std::to_string(op_.verbose));
  289. return props_;
  290. }
  291. std::string AssertEqual_make_name_impl(const OpDef& def_) {
  292. auto&& op_ = def_.cast_final_safe<AssertEqual>();
  293. static_cast<void>(op_);
  294. return "AssertEqual";
  295. }
  296. } // anonymous namespace
  297. OP_TRAIT_REG(AssertEqual, AssertEqual)
  298. .hash(AssertEqual_hash_impl)
  299. .is_same_st(AssertEqual_is_same_st_impl)
  300. .props(AssertEqual_props_impl)
  301. .make_name(AssertEqual_make_name_impl);
  302. MGB_DYN_TYPE_OBJ_FINAL_IMPL(AtlasRuntime);
  303. namespace {
  304. size_t AtlasRuntime_hash_impl(const OpDef& def_) {
  305. auto&& op_ = def_.cast_final_safe<AtlasRuntime>();
  306. static_cast<void>(op_);
  307. size_t val = mgb::hash(op_.dyn_typeinfo());
  308. val = mgb::hash_pair_combine(val, mgb::hash(op_.buf));
  309. val = mgb::hash_pair_combine(val, mgb::hash(op_.buf_size));
  310. return val;
  311. }
  312. bool AtlasRuntime_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  313. auto &&a_ = lhs_.cast_final_safe<AtlasRuntime>(),
  314. &&b_ = rhs_.cast_final_safe<AtlasRuntime>();
  315. static_cast<void>(a_);
  316. static_cast<void>(b_);
  317. if (a_.buf != b_.buf) return false;
  318. if (a_.buf_size != b_.buf_size) return false;
  319. return true;
  320. }
  321. std::vector<std::pair<const char*, std::string>> AtlasRuntime_props_impl(const OpDef& def_) {
  322. auto&& op_ = def_.cast_final_safe<AtlasRuntime>();
  323. static_cast<void>(op_);
  324. std::vector<std::pair<const char*, std::string>> props_;
  325. props_.emplace_back("buf", op_.buf);
  326. props_.emplace_back("buf_size", std::to_string(op_.buf_size));
  327. return props_;
  328. }
  329. std::string AtlasRuntime_make_name_impl(const OpDef& def_) {
  330. auto&& op_ = def_.cast_final_safe<AtlasRuntime>();
  331. static_cast<void>(op_);
  332. return "AtlasRuntime";
  333. }
  334. } // anonymous namespace
  335. OP_TRAIT_REG(AtlasRuntime, AtlasRuntime)
  336. .hash(AtlasRuntime_hash_impl)
  337. .is_same_st(AtlasRuntime_is_same_st_impl)
  338. .props(AtlasRuntime_props_impl)
  339. .make_name(AtlasRuntime_make_name_impl);
  340. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Barrier);
  341. namespace {
  342. size_t Barrier_hash_impl(const OpDef& def_) {
  343. auto&& op_ = def_.cast_final_safe<Barrier>();
  344. static_cast<void>(op_);
  345. size_t val = mgb::hash(op_.dyn_typeinfo());
  346. val = mgb::hash_pair_combine(val, mgb::hash(op_.comp_node));
  347. val = mgb::hash_pair_combine(val, mgb::hash(op_.nr_outputs));
  348. return val;
  349. }
  350. bool Barrier_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  351. auto &&a_ = lhs_.cast_final_safe<Barrier>(),
  352. &&b_ = rhs_.cast_final_safe<Barrier>();
  353. static_cast<void>(a_);
  354. static_cast<void>(b_);
  355. if (a_.comp_node != b_.comp_node) return false;
  356. if (a_.nr_outputs != b_.nr_outputs) return false;
  357. return true;
  358. }
  359. std::vector<std::pair<const char*, std::string>> Barrier_props_impl(const OpDef& def_) {
  360. auto&& op_ = def_.cast_final_safe<Barrier>();
  361. static_cast<void>(op_);
  362. std::vector<std::pair<const char*, std::string>> props_;
  363. props_.emplace_back("comp_node", op_.comp_node.to_string());
  364. props_.emplace_back("nr_outputs", std::to_string(op_.nr_outputs));
  365. return props_;
  366. }
  367. std::string Barrier_make_name_impl(const OpDef& def_) {
  368. auto&& op_ = def_.cast_final_safe<Barrier>();
  369. static_cast<void>(op_);
  370. return "Barrier";
  371. }
  372. } // anonymous namespace
  373. OP_TRAIT_REG(Barrier, Barrier)
  374. .hash(Barrier_hash_impl)
  375. .is_same_st(Barrier_is_same_st_impl)
  376. .props(Barrier_props_impl)
  377. .make_name(Barrier_make_name_impl);
  378. MGB_DYN_TYPE_OBJ_FINAL_IMPL(BatchConvBias);
  379. namespace {
  380. size_t BatchConvBias_hash_impl(const OpDef& def_) {
  381. auto&& op_ = def_.cast_final_safe<BatchConvBias>();
  382. static_cast<void>(op_);
  383. size_t val = mgb::hash(op_.dyn_typeinfo());
  384. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.nonlineMode));
  385. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode));
  386. val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_h));
  387. val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_w));
  388. val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_h));
  389. val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_w));
  390. val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_h));
  391. val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_w));
  392. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.sparse));
  393. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format));
  394. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.compute_mode));
  395. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.strategy));
  396. val = mgb::hash_pair_combine(val, mgb::hash(op_.workspace_limit));
  397. val = mgb::hash_pair_combine(val, mgb::hash(op_.dtype.handle()));
  398. return val;
  399. }
  400. bool BatchConvBias_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  401. auto &&a_ = lhs_.cast_final_safe<BatchConvBias>(),
  402. &&b_ = rhs_.cast_final_safe<BatchConvBias>();
  403. static_cast<void>(a_);
  404. static_cast<void>(b_);
  405. if (a_.nonlineMode != b_.nonlineMode) return false;
  406. if (a_.mode != b_.mode) return false;
  407. if (a_.pad_h != b_.pad_h) return false;
  408. if (a_.pad_w != b_.pad_w) return false;
  409. if (a_.stride_h != b_.stride_h) return false;
  410. if (a_.stride_w != b_.stride_w) return false;
  411. if (a_.dilate_h != b_.dilate_h) return false;
  412. if (a_.dilate_w != b_.dilate_w) return false;
  413. if (a_.sparse != b_.sparse) return false;
  414. if (a_.format != b_.format) return false;
  415. if (a_.compute_mode != b_.compute_mode) return false;
  416. if (a_.strategy != b_.strategy) return false;
  417. if (a_.workspace_limit != b_.workspace_limit) return false;
  418. if (a_.dtype != b_.dtype) return false;
  419. return true;
  420. }
  421. std::vector<std::pair<const char*, std::string>> BatchConvBias_props_impl(const OpDef& def_) {
  422. auto&& op_ = def_.cast_final_safe<BatchConvBias>();
  423. static_cast<void>(op_);
  424. std::vector<std::pair<const char*, std::string>> props_;
  425. switch (op_.nonlineMode){
  426. case BatchConvBias::NonlineMode::IDENTITY:
  427. props_.emplace_back("nonlineMode", "IDENTITY");
  428. break;
  429. case BatchConvBias::NonlineMode::RELU:
  430. props_.emplace_back("nonlineMode", "RELU");
  431. break;
  432. case BatchConvBias::NonlineMode::SIGMOID:
  433. props_.emplace_back("nonlineMode", "SIGMOID");
  434. break;
  435. case BatchConvBias::NonlineMode::H_SWISH:
  436. props_.emplace_back("nonlineMode", "H_SWISH");
  437. break;
  438. default:
  439. props_.emplace_back("nonlineMode", "INVALID");
  440. break;
  441. }
  442. switch (op_.mode){
  443. case BatchConvBias::Mode::CROSS_CORRELATION:
  444. props_.emplace_back("mode", "CROSS_CORRELATION");
  445. break;
  446. case BatchConvBias::Mode::CONVOLUTION:
  447. props_.emplace_back("mode", "CONVOLUTION");
  448. break;
  449. default:
  450. props_.emplace_back("mode", "INVALID");
  451. break;
  452. }
  453. props_.emplace_back("pad_h", std::to_string(op_.pad_h));
  454. props_.emplace_back("pad_w", std::to_string(op_.pad_w));
  455. props_.emplace_back("stride_h", std::to_string(op_.stride_h));
  456. props_.emplace_back("stride_w", std::to_string(op_.stride_w));
  457. props_.emplace_back("dilate_h", std::to_string(op_.dilate_h));
  458. props_.emplace_back("dilate_w", std::to_string(op_.dilate_w));
  459. switch (op_.sparse){
  460. case BatchConvBias::Sparse::DENSE:
  461. props_.emplace_back("sparse", "DENSE");
  462. break;
  463. case BatchConvBias::Sparse::GROUP:
  464. props_.emplace_back("sparse", "GROUP");
  465. break;
  466. default:
  467. props_.emplace_back("sparse", "INVALID");
  468. break;
  469. }
  470. switch (op_.format){
  471. case BatchConvBias::Format::NCHW:
  472. props_.emplace_back("format", "NCHW");
  473. break;
  474. case BatchConvBias::Format::NHWC:
  475. props_.emplace_back("format", "NHWC");
  476. break;
  477. case BatchConvBias::Format::NHWCD4:
  478. props_.emplace_back("format", "NHWCD4");
  479. break;
  480. case BatchConvBias::Format::NCHW4:
  481. props_.emplace_back("format", "NCHW4");
  482. break;
  483. case BatchConvBias::Format::NCHW8:
  484. props_.emplace_back("format", "NCHW8");
  485. break;
  486. case BatchConvBias::Format::NCHW32:
  487. props_.emplace_back("format", "NCHW32");
  488. break;
  489. case BatchConvBias::Format::NCHW88:
  490. props_.emplace_back("format", "NCHW88");
  491. break;
  492. case BatchConvBias::Format::NCHW44:
  493. props_.emplace_back("format", "NCHW44");
  494. break;
  495. case BatchConvBias::Format::NCHW44_DOT:
  496. props_.emplace_back("format", "NCHW44_DOT");
  497. break;
  498. case BatchConvBias::Format::NCHW4_NCHW32:
  499. props_.emplace_back("format", "NCHW4_NCHW32");
  500. break;
  501. case BatchConvBias::Format::NCHW32_NCHW4:
  502. props_.emplace_back("format", "NCHW32_NCHW4");
  503. break;
  504. case BatchConvBias::Format::NCHW4_NCHW:
  505. props_.emplace_back("format", "NCHW4_NCHW");
  506. break;
  507. case BatchConvBias::Format::NHWC_NCHW:
  508. props_.emplace_back("format", "NHWC_NCHW");
  509. break;
  510. case BatchConvBias::Format::NHWC_NCHW4_IC_SMALL:
  511. props_.emplace_back("format", "NHWC_NCHW4_IC_SMALL");
  512. break;
  513. case BatchConvBias::Format::NCHW_NCHW4_IC_SMALL:
  514. props_.emplace_back("format", "NCHW_NCHW4_IC_SMALL");
  515. break;
  516. case BatchConvBias::Format::CHWN4:
  517. props_.emplace_back("format", "CHWN4");
  518. break;
  519. case BatchConvBias::Format::NCHW64:
  520. props_.emplace_back("format", "NCHW64");
  521. break;
  522. case BatchConvBias::Format::NCHW4_NHWC:
  523. props_.emplace_back("format", "NCHW4_NHWC");
  524. break;
  525. default:
  526. props_.emplace_back("format", "INVALID");
  527. break;
  528. }
  529. switch (op_.compute_mode){
  530. case BatchConvBias::ComputeMode::DEFAULT:
  531. props_.emplace_back("compute_mode", "DEFAULT");
  532. break;
  533. case BatchConvBias::ComputeMode::FLOAT32:
  534. props_.emplace_back("compute_mode", "FLOAT32");
  535. break;
  536. default:
  537. props_.emplace_back("compute_mode", "INVALID");
  538. break;
  539. }
  540. switch (op_.strategy){
  541. case BatchConvBias::Strategy::HEURISTIC:
  542. props_.emplace_back("strategy", "HEURISTIC");
  543. break;
  544. case BatchConvBias::Strategy::PROFILE:
  545. props_.emplace_back("strategy", "PROFILE");
  546. break;
  547. case BatchConvBias::Strategy::REPRODUCIBLE:
  548. props_.emplace_back("strategy", "REPRODUCIBLE");
  549. break;
  550. case BatchConvBias::Strategy::OPTIMIZED:
  551. props_.emplace_back("strategy", "OPTIMIZED");
  552. break;
  553. default:
  554. props_.emplace_back("strategy", "INVALID");
  555. break;
  556. }
  557. props_.emplace_back("workspace_limit", std::to_string(op_.workspace_limit));
  558. props_.emplace_back("dtype", op_.dtype.name());
  559. return props_;
  560. }
  561. std::string BatchConvBias_make_name_impl(const OpDef& def_) {
  562. auto&& op_ = def_.cast_final_safe<BatchConvBias>();
  563. static_cast<void>(op_);
  564. return "BatchConvBias";
  565. }
  566. } // anonymous namespace
  567. OP_TRAIT_REG(BatchConvBias, BatchConvBias)
  568. .hash(BatchConvBias_hash_impl)
  569. .is_same_st(BatchConvBias_is_same_st_impl)
  570. .props(BatchConvBias_props_impl)
  571. .make_name(BatchConvBias_make_name_impl);
  572. MGB_DYN_TYPE_OBJ_FINAL_IMPL(BatchNorm);
  573. namespace {
  574. size_t BatchNorm_hash_impl(const OpDef& def_) {
  575. auto&& op_ = def_.cast_final_safe<BatchNorm>();
  576. static_cast<void>(op_);
  577. size_t val = mgb::hash(op_.dyn_typeinfo());
  578. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.param_dim));
  579. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.fwd_mode));
  580. val = mgb::hash_pair_combine(val, mgb::hash(op_.epsilon));
  581. val = mgb::hash_pair_combine(val, mgb::hash(op_.avg_factor));
  582. val = mgb::hash_pair_combine(val, mgb::hash(op_.scale));
  583. val = mgb::hash_pair_combine(val, mgb::hash(op_.bias));
  584. return val;
  585. }
  586. bool BatchNorm_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  587. auto &&a_ = lhs_.cast_final_safe<BatchNorm>(),
  588. &&b_ = rhs_.cast_final_safe<BatchNorm>();
  589. static_cast<void>(a_);
  590. static_cast<void>(b_);
  591. if (a_.param_dim != b_.param_dim) return false;
  592. if (a_.fwd_mode != b_.fwd_mode) return false;
  593. if (a_.epsilon != b_.epsilon) return false;
  594. if (a_.avg_factor != b_.avg_factor) return false;
  595. if (a_.scale != b_.scale) return false;
  596. if (a_.bias != b_.bias) return false;
  597. return true;
  598. }
  599. std::vector<std::pair<const char*, std::string>> BatchNorm_props_impl(const OpDef& def_) {
  600. auto&& op_ = def_.cast_final_safe<BatchNorm>();
  601. static_cast<void>(op_);
  602. std::vector<std::pair<const char*, std::string>> props_;
  603. switch (op_.param_dim){
  604. case BatchNorm::ParamDim::DIM_11HW:
  605. props_.emplace_back("param_dim", "DIM_11HW");
  606. break;
  607. case BatchNorm::ParamDim::DIM_1CHW:
  608. props_.emplace_back("param_dim", "DIM_1CHW");
  609. break;
  610. case BatchNorm::ParamDim::DIM_1C11:
  611. props_.emplace_back("param_dim", "DIM_1C11");
  612. break;
  613. case BatchNorm::ParamDim::DIM_111C:
  614. props_.emplace_back("param_dim", "DIM_111C");
  615. break;
  616. default:
  617. props_.emplace_back("param_dim", "INVALID");
  618. break;
  619. }
  620. switch (op_.fwd_mode){
  621. case BatchNorm::FwdMode::TRAINING:
  622. props_.emplace_back("fwd_mode", "TRAINING");
  623. break;
  624. case BatchNorm::FwdMode::INFERENCE:
  625. props_.emplace_back("fwd_mode", "INFERENCE");
  626. break;
  627. default:
  628. props_.emplace_back("fwd_mode", "INVALID");
  629. break;
  630. }
  631. props_.emplace_back("epsilon", std::to_string(op_.epsilon));
  632. props_.emplace_back("avg_factor", std::to_string(op_.avg_factor));
  633. props_.emplace_back("scale", std::to_string(op_.scale));
  634. props_.emplace_back("bias", std::to_string(op_.bias));
  635. return props_;
  636. }
  637. std::string BatchNorm_make_name_impl(const OpDef& def_) {
  638. auto&& op_ = def_.cast_final_safe<BatchNorm>();
  639. static_cast<void>(op_);
  640. return "BatchNorm";
  641. }
  642. } // anonymous namespace
  643. OP_TRAIT_REG(BatchNorm, BatchNorm)
  644. .hash(BatchNorm_hash_impl)
  645. .is_same_st(BatchNorm_is_same_st_impl)
  646. .props(BatchNorm_props_impl)
  647. .make_name(BatchNorm_make_name_impl);
  648. MGB_DYN_TYPE_OBJ_FINAL_IMPL(BatchNormBackward);
  649. namespace {
  650. size_t BatchNormBackward_hash_impl(const OpDef& def_) {
  651. auto&& op_ = def_.cast_final_safe<BatchNormBackward>();
  652. static_cast<void>(op_);
  653. size_t val = mgb::hash(op_.dyn_typeinfo());
  654. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.param_dim));
  655. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.fwd_mode));
  656. val = mgb::hash_pair_combine(val, mgb::hash(op_.epsilon));
  657. val = mgb::hash_pair_combine(val, mgb::hash(op_.avg_factor));
  658. val = mgb::hash_pair_combine(val, mgb::hash(op_.scale));
  659. val = mgb::hash_pair_combine(val, mgb::hash(op_.bias));
  660. return val;
  661. }
  662. bool BatchNormBackward_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  663. auto &&a_ = lhs_.cast_final_safe<BatchNormBackward>(),
  664. &&b_ = rhs_.cast_final_safe<BatchNormBackward>();
  665. static_cast<void>(a_);
  666. static_cast<void>(b_);
  667. if (a_.param_dim != b_.param_dim) return false;
  668. if (a_.fwd_mode != b_.fwd_mode) return false;
  669. if (a_.epsilon != b_.epsilon) return false;
  670. if (a_.avg_factor != b_.avg_factor) return false;
  671. if (a_.scale != b_.scale) return false;
  672. if (a_.bias != b_.bias) return false;
  673. return true;
  674. }
  675. std::vector<std::pair<const char*, std::string>> BatchNormBackward_props_impl(const OpDef& def_) {
  676. auto&& op_ = def_.cast_final_safe<BatchNormBackward>();
  677. static_cast<void>(op_);
  678. std::vector<std::pair<const char*, std::string>> props_;
  679. switch (op_.param_dim){
  680. case BatchNormBackward::ParamDim::DIM_11HW:
  681. props_.emplace_back("param_dim", "DIM_11HW");
  682. break;
  683. case BatchNormBackward::ParamDim::DIM_1CHW:
  684. props_.emplace_back("param_dim", "DIM_1CHW");
  685. break;
  686. case BatchNormBackward::ParamDim::DIM_1C11:
  687. props_.emplace_back("param_dim", "DIM_1C11");
  688. break;
  689. case BatchNormBackward::ParamDim::DIM_111C:
  690. props_.emplace_back("param_dim", "DIM_111C");
  691. break;
  692. default:
  693. props_.emplace_back("param_dim", "INVALID");
  694. break;
  695. }
  696. switch (op_.fwd_mode){
  697. case BatchNormBackward::FwdMode::TRAINING:
  698. props_.emplace_back("fwd_mode", "TRAINING");
  699. break;
  700. case BatchNormBackward::FwdMode::INFERENCE:
  701. props_.emplace_back("fwd_mode", "INFERENCE");
  702. break;
  703. default:
  704. props_.emplace_back("fwd_mode", "INVALID");
  705. break;
  706. }
  707. props_.emplace_back("epsilon", std::to_string(op_.epsilon));
  708. props_.emplace_back("avg_factor", std::to_string(op_.avg_factor));
  709. props_.emplace_back("scale", std::to_string(op_.scale));
  710. props_.emplace_back("bias", std::to_string(op_.bias));
  711. return props_;
  712. }
  713. std::string BatchNormBackward_make_name_impl(const OpDef& def_) {
  714. auto&& op_ = def_.cast_final_safe<BatchNormBackward>();
  715. static_cast<void>(op_);
  716. return "BatchNormBackward";
  717. }
  718. } // anonymous namespace
  719. OP_TRAIT_REG(BatchNormBackward, BatchNormBackward)
  720. .hash(BatchNormBackward_hash_impl)
  721. .is_same_st(BatchNormBackward_is_same_st_impl)
  722. .props(BatchNormBackward_props_impl)
  723. .make_name(BatchNormBackward_make_name_impl);
  724. MGB_DYN_TYPE_OBJ_FINAL_IMPL(BatchedIncrMeshIndexing);
  725. namespace {
  726. size_t BatchedIncrMeshIndexing_hash_impl(const OpDef& def_) {
  727. auto&& op_ = def_.cast_final_safe<BatchedIncrMeshIndexing>();
  728. static_cast<void>(op_);
  729. size_t val = mgb::hash(op_.dyn_typeinfo());
  730. val = mgb::hash_pair_combine(val, mgb::hash(op_.items));
  731. return val;
  732. }
  733. bool BatchedIncrMeshIndexing_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  734. auto &&a_ = lhs_.cast_final_safe<BatchedIncrMeshIndexing>(),
  735. &&b_ = rhs_.cast_final_safe<BatchedIncrMeshIndexing>();
  736. static_cast<void>(a_);
  737. static_cast<void>(b_);
  738. if (a_.items != b_.items) return false;
  739. return true;
  740. }
  741. std::vector<std::pair<const char*, std::string>> BatchedIncrMeshIndexing_props_impl(const OpDef& def_) {
  742. auto&& op_ = def_.cast_final_safe<BatchedIncrMeshIndexing>();
  743. static_cast<void>(op_);
  744. std::vector<std::pair<const char*, std::string>> props_;
  745. props_.emplace_back("items", "{std::vector}");
  746. return props_;
  747. }
  748. std::string BatchedIncrMeshIndexing_make_name_impl(const OpDef& def_) {
  749. auto&& op_ = def_.cast_final_safe<BatchedIncrMeshIndexing>();
  750. static_cast<void>(op_);
  751. return "BatchedIncrMeshIndexing";
  752. }
  753. } // anonymous namespace
  754. OP_TRAIT_REG(BatchedIncrMeshIndexing, BatchedIncrMeshIndexing)
  755. .hash(BatchedIncrMeshIndexing_hash_impl)
  756. .is_same_st(BatchedIncrMeshIndexing_is_same_st_impl)
  757. .props(BatchedIncrMeshIndexing_props_impl)
  758. .make_name(BatchedIncrMeshIndexing_make_name_impl);
  759. MGB_DYN_TYPE_OBJ_FINAL_IMPL(BatchedMatrixMul);
  760. namespace {
  761. size_t BatchedMatrixMul_hash_impl(const OpDef& def_) {
  762. auto&& op_ = def_.cast_final_safe<BatchedMatrixMul>();
  763. static_cast<void>(op_);
  764. size_t val = mgb::hash(op_.dyn_typeinfo());
  765. val = mgb::hash_pair_combine(val, mgb::hash(op_.transposeA));
  766. val = mgb::hash_pair_combine(val, mgb::hash(op_.transposeB));
  767. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.compute_mode));
  768. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format));
  769. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.strategy));
  770. val = mgb::hash_pair_combine(val, mgb::hash(op_.workspace_limit));
  771. val = mgb::hash_pair_combine(val, mgb::hash(op_.dimA));
  772. val = mgb::hash_pair_combine(val, mgb::hash(op_.dimB));
  773. return val;
  774. }
  775. bool BatchedMatrixMul_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  776. auto &&a_ = lhs_.cast_final_safe<BatchedMatrixMul>(),
  777. &&b_ = rhs_.cast_final_safe<BatchedMatrixMul>();
  778. static_cast<void>(a_);
  779. static_cast<void>(b_);
  780. if (a_.transposeA != b_.transposeA) return false;
  781. if (a_.transposeB != b_.transposeB) return false;
  782. if (a_.compute_mode != b_.compute_mode) return false;
  783. if (a_.format != b_.format) return false;
  784. if (a_.strategy != b_.strategy) return false;
  785. if (a_.workspace_limit != b_.workspace_limit) return false;
  786. if (a_.dimA != b_.dimA) return false;
  787. if (a_.dimB != b_.dimB) return false;
  788. return true;
  789. }
  790. std::vector<std::pair<const char*, std::string>> BatchedMatrixMul_props_impl(const OpDef& def_) {
  791. auto&& op_ = def_.cast_final_safe<BatchedMatrixMul>();
  792. static_cast<void>(op_);
  793. std::vector<std::pair<const char*, std::string>> props_;
  794. props_.emplace_back("transposeA", std::to_string(op_.transposeA));
  795. props_.emplace_back("transposeB", std::to_string(op_.transposeB));
  796. switch (op_.compute_mode){
  797. case BatchedMatrixMul::ComputeMode::DEFAULT:
  798. props_.emplace_back("compute_mode", "DEFAULT");
  799. break;
  800. case BatchedMatrixMul::ComputeMode::FLOAT32:
  801. props_.emplace_back("compute_mode", "FLOAT32");
  802. break;
  803. default:
  804. props_.emplace_back("compute_mode", "INVALID");
  805. break;
  806. }
  807. switch (op_.format){
  808. case BatchedMatrixMul::Format::DEFAULT:
  809. props_.emplace_back("format", "DEFAULT");
  810. break;
  811. case BatchedMatrixMul::Format::MK4:
  812. props_.emplace_back("format", "MK4");
  813. break;
  814. case BatchedMatrixMul::Format::MK8:
  815. props_.emplace_back("format", "MK8");
  816. break;
  817. case BatchedMatrixMul::Format::MK4_DOT:
  818. props_.emplace_back("format", "MK4_DOT");
  819. break;
  820. case BatchedMatrixMul::Format::N32K4_DOT:
  821. props_.emplace_back("format", "N32K4_DOT");
  822. break;
  823. default:
  824. props_.emplace_back("format", "INVALID");
  825. break;
  826. }
  827. switch (op_.strategy){
  828. case BatchedMatrixMul::Strategy::HEURISTIC:
  829. props_.emplace_back("strategy", "HEURISTIC");
  830. break;
  831. case BatchedMatrixMul::Strategy::PROFILE:
  832. props_.emplace_back("strategy", "PROFILE");
  833. break;
  834. case BatchedMatrixMul::Strategy::REPRODUCIBLE:
  835. props_.emplace_back("strategy", "REPRODUCIBLE");
  836. break;
  837. case BatchedMatrixMul::Strategy::OPTIMIZED:
  838. props_.emplace_back("strategy", "OPTIMIZED");
  839. break;
  840. default:
  841. props_.emplace_back("strategy", "INVALID");
  842. break;
  843. }
  844. props_.emplace_back("workspace_limit", std::to_string(op_.workspace_limit));
  845. props_.emplace_back("dimA", std::to_string(op_.dimA));
  846. props_.emplace_back("dimB", std::to_string(op_.dimB));
  847. return props_;
  848. }
  849. std::string BatchedMatrixMul_make_name_impl(const OpDef& def_) {
  850. auto&& op_ = def_.cast_final_safe<BatchedMatrixMul>();
  851. static_cast<void>(op_);
  852. return "BatchedMatrixMul";
  853. }
  854. } // anonymous namespace
  855. OP_TRAIT_REG(BatchedMatrixMul, BatchedMatrixMul)
  856. .hash(BatchedMatrixMul_hash_impl)
  857. .is_same_st(BatchedMatrixMul_is_same_st_impl)
  858. .props(BatchedMatrixMul_props_impl)
  859. .make_name(BatchedMatrixMul_make_name_impl);
  860. MGB_DYN_TYPE_OBJ_FINAL_IMPL(BatchedMeshIndexing);
  861. namespace {
  862. size_t BatchedMeshIndexing_hash_impl(const OpDef& def_) {
  863. auto&& op_ = def_.cast_final_safe<BatchedMeshIndexing>();
  864. static_cast<void>(op_);
  865. size_t val = mgb::hash(op_.dyn_typeinfo());
  866. val = mgb::hash_pair_combine(val, mgb::hash(op_.items));
  867. return val;
  868. }
  869. bool BatchedMeshIndexing_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  870. auto &&a_ = lhs_.cast_final_safe<BatchedMeshIndexing>(),
  871. &&b_ = rhs_.cast_final_safe<BatchedMeshIndexing>();
  872. static_cast<void>(a_);
  873. static_cast<void>(b_);
  874. if (a_.items != b_.items) return false;
  875. return true;
  876. }
  877. std::vector<std::pair<const char*, std::string>> BatchedMeshIndexing_props_impl(const OpDef& def_) {
  878. auto&& op_ = def_.cast_final_safe<BatchedMeshIndexing>();
  879. static_cast<void>(op_);
  880. std::vector<std::pair<const char*, std::string>> props_;
  881. props_.emplace_back("items", "{std::vector}");
  882. return props_;
  883. }
  884. std::string BatchedMeshIndexing_make_name_impl(const OpDef& def_) {
  885. auto&& op_ = def_.cast_final_safe<BatchedMeshIndexing>();
  886. static_cast<void>(op_);
  887. return "BatchedMeshIndexing";
  888. }
  889. } // anonymous namespace
  890. OP_TRAIT_REG(BatchedMeshIndexing, BatchedMeshIndexing)
  891. .hash(BatchedMeshIndexing_hash_impl)
  892. .is_same_st(BatchedMeshIndexing_is_same_st_impl)
  893. .props(BatchedMeshIndexing_props_impl)
  894. .make_name(BatchedMeshIndexing_make_name_impl);
  895. MGB_DYN_TYPE_OBJ_FINAL_IMPL(BatchedSetMeshIndexing);
  896. namespace {
  897. size_t BatchedSetMeshIndexing_hash_impl(const OpDef& def_) {
  898. auto&& op_ = def_.cast_final_safe<BatchedSetMeshIndexing>();
  899. static_cast<void>(op_);
  900. size_t val = mgb::hash(op_.dyn_typeinfo());
  901. val = mgb::hash_pair_combine(val, mgb::hash(op_.items));
  902. return val;
  903. }
  904. bool BatchedSetMeshIndexing_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  905. auto &&a_ = lhs_.cast_final_safe<BatchedSetMeshIndexing>(),
  906. &&b_ = rhs_.cast_final_safe<BatchedSetMeshIndexing>();
  907. static_cast<void>(a_);
  908. static_cast<void>(b_);
  909. if (a_.items != b_.items) return false;
  910. return true;
  911. }
  912. std::vector<std::pair<const char*, std::string>> BatchedSetMeshIndexing_props_impl(const OpDef& def_) {
  913. auto&& op_ = def_.cast_final_safe<BatchedSetMeshIndexing>();
  914. static_cast<void>(op_);
  915. std::vector<std::pair<const char*, std::string>> props_;
  916. props_.emplace_back("items", "{std::vector}");
  917. return props_;
  918. }
  919. std::string BatchedSetMeshIndexing_make_name_impl(const OpDef& def_) {
  920. auto&& op_ = def_.cast_final_safe<BatchedSetMeshIndexing>();
  921. static_cast<void>(op_);
  922. return "BatchedSetMeshIndexing";
  923. }
  924. } // anonymous namespace
  925. OP_TRAIT_REG(BatchedSetMeshIndexing, BatchedSetMeshIndexing)
  926. .hash(BatchedSetMeshIndexing_hash_impl)
  927. .is_same_st(BatchedSetMeshIndexing_is_same_st_impl)
  928. .props(BatchedSetMeshIndexing_props_impl)
  929. .make_name(BatchedSetMeshIndexing_make_name_impl);
  930. MGB_DYN_TYPE_OBJ_FINAL_IMPL(BetaRNG);
  931. namespace {
  932. size_t BetaRNG_hash_impl(const OpDef& def_) {
  933. auto&& op_ = def_.cast_final_safe<BetaRNG>();
  934. static_cast<void>(op_);
  935. return mgb::hash_pair_combine(
  936. mgb::hash(op_.dyn_typeinfo()),
  937. mgb::hash(op_.handle)
  938. );
  939. }
  940. bool BetaRNG_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  941. auto &&a_ = lhs_.cast_final_safe<BetaRNG>(),
  942. &&b_ = rhs_.cast_final_safe<BetaRNG>();
  943. static_cast<void>(a_);
  944. static_cast<void>(b_);
  945. return a_.handle == b_.handle;}
  946. std::vector<std::pair<const char*, std::string>> BetaRNG_props_impl(const OpDef& def_) {
  947. auto&& op_ = def_.cast_final_safe<BetaRNG>();
  948. static_cast<void>(op_);
  949. std::vector<std::pair<const char*, std::string>> props_;
  950. props_.emplace_back("seed", std::to_string(op_.seed));
  951. props_.emplace_back("handle", std::to_string(op_.handle));
  952. return props_;
  953. }
  954. std::string BetaRNG_make_name_impl(const OpDef& def_) {
  955. auto&& op_ = def_.cast_final_safe<BetaRNG>();
  956. static_cast<void>(op_);
  957. return "BetaRNG";
  958. }
  959. } // anonymous namespace
  960. OP_TRAIT_REG(BetaRNG, BetaRNG)
  961. .hash(BetaRNG_hash_impl)
  962. .is_same_st(BetaRNG_is_same_st_impl)
  963. .props(BetaRNG_props_impl)
  964. .make_name(BetaRNG_make_name_impl);
  965. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Borrow);
  966. namespace {
  967. size_t Borrow_hash_impl(const OpDef& def_) {
  968. auto&& op_ = def_.cast_final_safe<Borrow>();
  969. static_cast<void>(op_);
  970. size_t val = mgb::hash(op_.dyn_typeinfo());
  971. val = mgb::hash_pair_combine(val, mgb::hash(op_.comp_node));
  972. return val;
  973. }
  974. bool Borrow_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  975. auto &&a_ = lhs_.cast_final_safe<Borrow>(),
  976. &&b_ = rhs_.cast_final_safe<Borrow>();
  977. static_cast<void>(a_);
  978. static_cast<void>(b_);
  979. if (a_.comp_node != b_.comp_node) return false;
  980. return true;
  981. }
  982. std::vector<std::pair<const char*, std::string>> Borrow_props_impl(const OpDef& def_) {
  983. auto&& op_ = def_.cast_final_safe<Borrow>();
  984. static_cast<void>(op_);
  985. std::vector<std::pair<const char*, std::string>> props_;
  986. props_.emplace_back("comp_node", op_.comp_node.to_string());
  987. return props_;
  988. }
  989. std::string Borrow_make_name_impl(const OpDef& def_) {
  990. auto&& op_ = def_.cast_final_safe<Borrow>();
  991. static_cast<void>(op_);
  992. return "Borrow";
  993. }
  994. } // anonymous namespace
  995. OP_TRAIT_REG(Borrow, Borrow)
  996. .hash(Borrow_hash_impl)
  997. .is_same_st(Borrow_is_same_st_impl)
  998. .props(Borrow_props_impl)
  999. .make_name(Borrow_make_name_impl);
  1000. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Broadcast);
  1001. namespace {
  1002. size_t Broadcast_hash_impl(const OpDef& def_) {
  1003. auto&& op_ = def_.cast_final_safe<Broadcast>();
  1004. static_cast<void>(op_);
  1005. size_t val = mgb::hash(op_.dyn_typeinfo());
  1006. val = mgb::hash_pair_combine(val, mgb::hash(op_.shape));
  1007. return val;
  1008. }
  1009. bool Broadcast_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  1010. auto &&a_ = lhs_.cast_final_safe<Broadcast>(),
  1011. &&b_ = rhs_.cast_final_safe<Broadcast>();
  1012. static_cast<void>(a_);
  1013. static_cast<void>(b_);
  1014. if (a_.shape != b_.shape) return false;
  1015. return true;
  1016. }
  1017. std::vector<std::pair<const char*, std::string>> Broadcast_props_impl(const OpDef& def_) {
  1018. auto&& op_ = def_.cast_final_safe<Broadcast>();
  1019. static_cast<void>(op_);
  1020. std::vector<std::pair<const char*, std::string>> props_;
  1021. props_.emplace_back("shape", "{std::vector}");
  1022. return props_;
  1023. }
  1024. std::string Broadcast_make_name_impl(const OpDef& def_) {
  1025. auto&& op_ = def_.cast_final_safe<Broadcast>();
  1026. static_cast<void>(op_);
  1027. return "Broadcast";
  1028. }
  1029. } // anonymous namespace
  1030. OP_TRAIT_REG(Broadcast, Broadcast)
  1031. .hash(Broadcast_hash_impl)
  1032. .is_same_st(Broadcast_is_same_st_impl)
  1033. .props(Broadcast_props_impl)
  1034. .make_name(Broadcast_make_name_impl);
  1035. MGB_DYN_TYPE_OBJ_FINAL_IMPL(CambriconRuntime);
  1036. namespace {
  1037. size_t CambriconRuntime_hash_impl(const OpDef& def_) {
  1038. auto&& op_ = def_.cast_final_safe<CambriconRuntime>();
  1039. static_cast<void>(op_);
  1040. size_t val = mgb::hash(op_.dyn_typeinfo());
  1041. val = mgb::hash_pair_combine(val, mgb::hash(op_.buf));
  1042. val = mgb::hash_pair_combine(val, mgb::hash(op_.buf_size));
  1043. val = mgb::hash_pair_combine(val, mgb::hash(op_.symbol));
  1044. val = mgb::hash_pair_combine(val, mgb::hash(op_.tensor_dim_mutable));
  1045. return val;
  1046. }
  1047. bool CambriconRuntime_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  1048. auto &&a_ = lhs_.cast_final_safe<CambriconRuntime>(),
  1049. &&b_ = rhs_.cast_final_safe<CambriconRuntime>();
  1050. static_cast<void>(a_);
  1051. static_cast<void>(b_);
  1052. if (a_.buf != b_.buf) return false;
  1053. if (a_.buf_size != b_.buf_size) return false;
  1054. if (a_.symbol != b_.symbol) return false;
  1055. if (a_.tensor_dim_mutable != b_.tensor_dim_mutable) return false;
  1056. return true;
  1057. }
  1058. std::vector<std::pair<const char*, std::string>> CambriconRuntime_props_impl(const OpDef& def_) {
  1059. auto&& op_ = def_.cast_final_safe<CambriconRuntime>();
  1060. static_cast<void>(op_);
  1061. std::vector<std::pair<const char*, std::string>> props_;
  1062. props_.emplace_back("buf", op_.buf);
  1063. props_.emplace_back("buf_size", std::to_string(op_.buf_size));
  1064. props_.emplace_back("symbol", op_.symbol);
  1065. props_.emplace_back("tensor_dim_mutable", std::to_string(op_.tensor_dim_mutable));
  1066. return props_;
  1067. }
  1068. std::string CambriconRuntime_make_name_impl(const OpDef& def_) {
  1069. auto&& op_ = def_.cast_final_safe<CambriconRuntime>();
  1070. static_cast<void>(op_);
  1071. return "CambriconRuntime";
  1072. }
  1073. } // anonymous namespace
  1074. OP_TRAIT_REG(CambriconRuntime, CambriconRuntime)
  1075. .hash(CambriconRuntime_hash_impl)
  1076. .is_same_st(CambriconRuntime_is_same_st_impl)
  1077. .props(CambriconRuntime_props_impl)
  1078. .make_name(CambriconRuntime_make_name_impl);
  1079. MGB_DYN_TYPE_OBJ_FINAL_IMPL(CheckNonFinite);
  1080. namespace {
  1081. size_t CheckNonFinite_hash_impl(const OpDef& def_) {
  1082. auto&& op_ = def_.cast_final_safe<CheckNonFinite>();
  1083. static_cast<void>(op_);
  1084. size_t val = mgb::hash(op_.dyn_typeinfo());
  1085. val = mgb::hash_pair_combine(val, mgb::hash(op_.scale));
  1086. return val;
  1087. }
  1088. bool CheckNonFinite_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  1089. auto &&a_ = lhs_.cast_final_safe<CheckNonFinite>(),
  1090. &&b_ = rhs_.cast_final_safe<CheckNonFinite>();
  1091. static_cast<void>(a_);
  1092. static_cast<void>(b_);
  1093. if (a_.scale != b_.scale) return false;
  1094. return true;
  1095. }
  1096. std::vector<std::pair<const char*, std::string>> CheckNonFinite_props_impl(const OpDef& def_) {
  1097. auto&& op_ = def_.cast_final_safe<CheckNonFinite>();
  1098. static_cast<void>(op_);
  1099. std::vector<std::pair<const char*, std::string>> props_;
  1100. props_.emplace_back("scale", std::to_string(op_.scale));
  1101. return props_;
  1102. }
  1103. std::string CheckNonFinite_make_name_impl(const OpDef& def_) {
  1104. auto&& op_ = def_.cast_final_safe<CheckNonFinite>();
  1105. static_cast<void>(op_);
  1106. return "CheckNonFinite";
  1107. }
  1108. } // anonymous namespace
  1109. OP_TRAIT_REG(CheckNonFinite, CheckNonFinite)
  1110. .hash(CheckNonFinite_hash_impl)
  1111. .is_same_st(CheckNonFinite_is_same_st_impl)
  1112. .props(CheckNonFinite_props_impl)
  1113. .make_name(CheckNonFinite_make_name_impl);
  1114. MGB_DYN_TYPE_OBJ_FINAL_IMPL(CollectiveComm);
  1115. namespace {
  1116. size_t CollectiveComm_hash_impl(const OpDef& def_) {
  1117. auto&& op_ = def_.cast_final_safe<CollectiveComm>();
  1118. static_cast<void>(op_);
  1119. size_t val = mgb::hash(op_.dyn_typeinfo());
  1120. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode));
  1121. val = mgb::hash_pair_combine(val, mgb::hash(op_.key));
  1122. val = mgb::hash_pair_combine(val, mgb::hash(op_.nr_devices));
  1123. val = mgb::hash_pair_combine(val, mgb::hash(op_.rank));
  1124. val = mgb::hash_pair_combine(val, mgb::hash(op_.is_root));
  1125. val = mgb::hash_pair_combine(val, mgb::hash(op_.local_grad));
  1126. val = mgb::hash_pair_combine(val, mgb::hash(op_.addr));
  1127. val = mgb::hash_pair_combine(val, mgb::hash(op_.port));
  1128. val = mgb::hash_pair_combine(val, mgb::hash(op_.dtype.handle()));
  1129. val = mgb::hash_pair_combine(val, mgb::hash(op_.backend));
  1130. val = mgb::hash_pair_combine(val, mgb::hash(op_.comp_node));
  1131. return val;
  1132. }
  1133. bool CollectiveComm_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  1134. auto &&a_ = lhs_.cast_final_safe<CollectiveComm>(),
  1135. &&b_ = rhs_.cast_final_safe<CollectiveComm>();
  1136. static_cast<void>(a_);
  1137. static_cast<void>(b_);
  1138. if (a_.mode != b_.mode) return false;
  1139. if (a_.key != b_.key) return false;
  1140. if (a_.nr_devices != b_.nr_devices) return false;
  1141. if (a_.rank != b_.rank) return false;
  1142. if (a_.is_root != b_.is_root) return false;
  1143. if (a_.local_grad != b_.local_grad) return false;
  1144. if (a_.addr != b_.addr) return false;
  1145. if (a_.port != b_.port) return false;
  1146. if (a_.dtype != b_.dtype) return false;
  1147. if (a_.backend != b_.backend) return false;
  1148. if (a_.comp_node != b_.comp_node) return false;
  1149. return true;
  1150. }
  1151. std::vector<std::pair<const char*, std::string>> CollectiveComm_props_impl(const OpDef& def_) {
  1152. auto&& op_ = def_.cast_final_safe<CollectiveComm>();
  1153. static_cast<void>(op_);
  1154. std::vector<std::pair<const char*, std::string>> props_;
  1155. switch (op_.mode){
  1156. case CollectiveComm::Mode::REDUCE_SUM:
  1157. props_.emplace_back("mode", "REDUCE_SUM");
  1158. break;
  1159. case CollectiveComm::Mode::BROADCAST:
  1160. props_.emplace_back("mode", "BROADCAST");
  1161. break;
  1162. case CollectiveComm::Mode::ALL_GATHER:
  1163. props_.emplace_back("mode", "ALL_GATHER");
  1164. break;
  1165. case CollectiveComm::Mode::REDUCE_SCATTER_SUM:
  1166. props_.emplace_back("mode", "REDUCE_SCATTER_SUM");
  1167. break;
  1168. case CollectiveComm::Mode::ALL_REDUCE_SUM:
  1169. props_.emplace_back("mode", "ALL_REDUCE_SUM");
  1170. break;
  1171. case CollectiveComm::Mode::ALL_REDUCE_MAX:
  1172. props_.emplace_back("mode", "ALL_REDUCE_MAX");
  1173. break;
  1174. case CollectiveComm::Mode::ALL_REDUCE_MIN:
  1175. props_.emplace_back("mode", "ALL_REDUCE_MIN");
  1176. break;
  1177. case CollectiveComm::Mode::ALL_REDUCE_PROD:
  1178. props_.emplace_back("mode", "ALL_REDUCE_PROD");
  1179. break;
  1180. case CollectiveComm::Mode::GATHER:
  1181. props_.emplace_back("mode", "GATHER");
  1182. break;
  1183. case CollectiveComm::Mode::SCATTER:
  1184. props_.emplace_back("mode", "SCATTER");
  1185. break;
  1186. case CollectiveComm::Mode::ALL_TO_ALL:
  1187. props_.emplace_back("mode", "ALL_TO_ALL");
  1188. break;
  1189. default:
  1190. props_.emplace_back("mode", "INVALID");
  1191. break;
  1192. }
  1193. props_.emplace_back("key", op_.key);
  1194. props_.emplace_back("nr_devices", std::to_string(op_.nr_devices));
  1195. props_.emplace_back("rank", std::to_string(op_.rank));
  1196. props_.emplace_back("is_root", std::to_string(op_.is_root));
  1197. props_.emplace_back("local_grad", std::to_string(op_.local_grad));
  1198. props_.emplace_back("addr", op_.addr);
  1199. props_.emplace_back("port", std::to_string(op_.port));
  1200. props_.emplace_back("dtype", op_.dtype.name());
  1201. props_.emplace_back("backend", op_.backend);
  1202. props_.emplace_back("comp_node", op_.comp_node);
  1203. return props_;
  1204. }
  1205. std::string CollectiveComm_make_name_impl(const OpDef& def_) {
  1206. auto&& op_ = def_.cast_final_safe<CollectiveComm>();
  1207. static_cast<void>(op_);
  1208. return "CollectiveComm";
  1209. }
  1210. } // anonymous namespace
  1211. OP_TRAIT_REG(CollectiveComm, CollectiveComm)
  1212. .hash(CollectiveComm_hash_impl)
  1213. .is_same_st(CollectiveComm_is_same_st_impl)
  1214. .props(CollectiveComm_props_impl)
  1215. .make_name(CollectiveComm_make_name_impl);
  1216. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Concat);
  1217. namespace {
  1218. size_t Concat_hash_impl(const OpDef& def_) {
  1219. auto&& op_ = def_.cast_final_safe<Concat>();
  1220. static_cast<void>(op_);
  1221. size_t val = mgb::hash(op_.dyn_typeinfo());
  1222. val = mgb::hash_pair_combine(val, mgb::hash(op_.axis));
  1223. val = mgb::hash_pair_combine(val, mgb::hash(op_.comp_node));
  1224. return val;
  1225. }
  1226. bool Concat_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  1227. auto &&a_ = lhs_.cast_final_safe<Concat>(),
  1228. &&b_ = rhs_.cast_final_safe<Concat>();
  1229. static_cast<void>(a_);
  1230. static_cast<void>(b_);
  1231. if (a_.axis != b_.axis) return false;
  1232. if (a_.comp_node != b_.comp_node) return false;
  1233. return true;
  1234. }
  1235. std::vector<std::pair<const char*, std::string>> Concat_props_impl(const OpDef& def_) {
  1236. auto&& op_ = def_.cast_final_safe<Concat>();
  1237. static_cast<void>(op_);
  1238. std::vector<std::pair<const char*, std::string>> props_;
  1239. props_.emplace_back("axis", std::to_string(op_.axis));
  1240. props_.emplace_back("comp_node", op_.comp_node.to_string());
  1241. return props_;
  1242. }
  1243. std::string Concat_make_name_impl(const OpDef& def_) {
  1244. auto&& op_ = def_.cast_final_safe<Concat>();
  1245. static_cast<void>(op_);
  1246. return "Concat";
  1247. }
  1248. } // anonymous namespace
  1249. OP_TRAIT_REG(Concat, Concat)
  1250. .hash(Concat_hash_impl)
  1251. .is_same_st(Concat_is_same_st_impl)
  1252. .props(Concat_props_impl)
  1253. .make_name(Concat_make_name_impl);
  1254. MGB_DYN_TYPE_OBJ_FINAL_IMPL(CondTake);
  1255. namespace {
  1256. size_t CondTake_hash_impl(const OpDef& def_) {
  1257. auto&& op_ = def_.cast_final_safe<CondTake>();
  1258. static_cast<void>(op_);
  1259. size_t val = mgb::hash(op_.dyn_typeinfo());
  1260. return val;
  1261. }
  1262. bool CondTake_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  1263. auto &&a_ = lhs_.cast_final_safe<CondTake>(),
  1264. &&b_ = rhs_.cast_final_safe<CondTake>();
  1265. static_cast<void>(a_);
  1266. static_cast<void>(b_);
  1267. return true;
  1268. }
  1269. std::vector<std::pair<const char*, std::string>> CondTake_props_impl(const OpDef& def_) {
  1270. auto&& op_ = def_.cast_final_safe<CondTake>();
  1271. static_cast<void>(op_);
  1272. std::vector<std::pair<const char*, std::string>> props_;
  1273. return props_;
  1274. }
  1275. std::string CondTake_make_name_impl(const OpDef& def_) {
  1276. auto&& op_ = def_.cast_final_safe<CondTake>();
  1277. static_cast<void>(op_);
  1278. return "CondTake";
  1279. }
  1280. } // anonymous namespace
  1281. OP_TRAIT_REG(CondTake, CondTake)
  1282. .hash(CondTake_hash_impl)
  1283. .is_same_st(CondTake_is_same_st_impl)
  1284. .props(CondTake_props_impl)
  1285. .make_name(CondTake_make_name_impl);
  1286. MGB_DYN_TYPE_OBJ_FINAL_IMPL(ConvBias);
  1287. namespace {
  1288. size_t ConvBias_hash_impl(const OpDef& def_) {
  1289. auto&& op_ = def_.cast_final_safe<ConvBias>();
  1290. static_cast<void>(op_);
  1291. size_t val = mgb::hash(op_.dyn_typeinfo());
  1292. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.nonlineMode));
  1293. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode));
  1294. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.sparse));
  1295. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format));
  1296. val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_h));
  1297. val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_w));
  1298. val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_h));
  1299. val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_w));
  1300. val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_h));
  1301. val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_w));
  1302. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.compute_mode));
  1303. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.strategy));
  1304. val = mgb::hash_pair_combine(val, mgb::hash(op_.workspace_limit));
  1305. val = mgb::hash_pair_combine(val, mgb::hash(op_.dtype.handle()));
  1306. return val;
  1307. }
  1308. bool ConvBias_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  1309. auto &&a_ = lhs_.cast_final_safe<ConvBias>(),
  1310. &&b_ = rhs_.cast_final_safe<ConvBias>();
  1311. static_cast<void>(a_);
  1312. static_cast<void>(b_);
  1313. if (a_.nonlineMode != b_.nonlineMode) return false;
  1314. if (a_.mode != b_.mode) return false;
  1315. if (a_.sparse != b_.sparse) return false;
  1316. if (a_.format != b_.format) return false;
  1317. if (a_.pad_h != b_.pad_h) return false;
  1318. if (a_.pad_w != b_.pad_w) return false;
  1319. if (a_.stride_h != b_.stride_h) return false;
  1320. if (a_.stride_w != b_.stride_w) return false;
  1321. if (a_.dilate_h != b_.dilate_h) return false;
  1322. if (a_.dilate_w != b_.dilate_w) return false;
  1323. if (a_.compute_mode != b_.compute_mode) return false;
  1324. if (a_.strategy != b_.strategy) return false;
  1325. if (a_.workspace_limit != b_.workspace_limit) return false;
  1326. if (a_.dtype != b_.dtype) return false;
  1327. return true;
  1328. }
  1329. std::vector<std::pair<const char*, std::string>> ConvBias_props_impl(const OpDef& def_) {
  1330. auto&& op_ = def_.cast_final_safe<ConvBias>();
  1331. static_cast<void>(op_);
  1332. std::vector<std::pair<const char*, std::string>> props_;
  1333. switch (op_.nonlineMode){
  1334. case ConvBias::NonlineMode::IDENTITY:
  1335. props_.emplace_back("nonlineMode", "IDENTITY");
  1336. break;
  1337. case ConvBias::NonlineMode::RELU:
  1338. props_.emplace_back("nonlineMode", "RELU");
  1339. break;
  1340. case ConvBias::NonlineMode::SIGMOID:
  1341. props_.emplace_back("nonlineMode", "SIGMOID");
  1342. break;
  1343. case ConvBias::NonlineMode::H_SWISH:
  1344. props_.emplace_back("nonlineMode", "H_SWISH");
  1345. break;
  1346. default:
  1347. props_.emplace_back("nonlineMode", "INVALID");
  1348. break;
  1349. }
  1350. switch (op_.mode){
  1351. case ConvBias::Mode::CROSS_CORRELATION:
  1352. props_.emplace_back("mode", "CROSS_CORRELATION");
  1353. break;
  1354. case ConvBias::Mode::CONVOLUTION:
  1355. props_.emplace_back("mode", "CONVOLUTION");
  1356. break;
  1357. default:
  1358. props_.emplace_back("mode", "INVALID");
  1359. break;
  1360. }
  1361. switch (op_.sparse){
  1362. case ConvBias::Sparse::DENSE:
  1363. props_.emplace_back("sparse", "DENSE");
  1364. break;
  1365. case ConvBias::Sparse::GROUP:
  1366. props_.emplace_back("sparse", "GROUP");
  1367. break;
  1368. default:
  1369. props_.emplace_back("sparse", "INVALID");
  1370. break;
  1371. }
  1372. switch (op_.format){
  1373. case ConvBias::Format::NCHW:
  1374. props_.emplace_back("format", "NCHW");
  1375. break;
  1376. case ConvBias::Format::NHWC:
  1377. props_.emplace_back("format", "NHWC");
  1378. break;
  1379. case ConvBias::Format::NHWCD4:
  1380. props_.emplace_back("format", "NHWCD4");
  1381. break;
  1382. case ConvBias::Format::NCHW4:
  1383. props_.emplace_back("format", "NCHW4");
  1384. break;
  1385. case ConvBias::Format::NCHW8:
  1386. props_.emplace_back("format", "NCHW8");
  1387. break;
  1388. case ConvBias::Format::NCHW32:
  1389. props_.emplace_back("format", "NCHW32");
  1390. break;
  1391. case ConvBias::Format::NCHW88:
  1392. props_.emplace_back("format", "NCHW88");
  1393. break;
  1394. case ConvBias::Format::NCHW44:
  1395. props_.emplace_back("format", "NCHW44");
  1396. break;
  1397. case ConvBias::Format::NCHW44_DOT:
  1398. props_.emplace_back("format", "NCHW44_DOT");
  1399. break;
  1400. case ConvBias::Format::NCHW4_NCHW32:
  1401. props_.emplace_back("format", "NCHW4_NCHW32");
  1402. break;
  1403. case ConvBias::Format::NCHW32_NCHW4:
  1404. props_.emplace_back("format", "NCHW32_NCHW4");
  1405. break;
  1406. case ConvBias::Format::NCHW4_NCHW:
  1407. props_.emplace_back("format", "NCHW4_NCHW");
  1408. break;
  1409. case ConvBias::Format::NHWC_NCHW:
  1410. props_.emplace_back("format", "NHWC_NCHW");
  1411. break;
  1412. case ConvBias::Format::NHWC_NCHW4_IC_SMALL:
  1413. props_.emplace_back("format", "NHWC_NCHW4_IC_SMALL");
  1414. break;
  1415. case ConvBias::Format::NCHW_NCHW4_IC_SMALL:
  1416. props_.emplace_back("format", "NCHW_NCHW4_IC_SMALL");
  1417. break;
  1418. case ConvBias::Format::CHWN4:
  1419. props_.emplace_back("format", "CHWN4");
  1420. break;
  1421. case ConvBias::Format::NCHW64:
  1422. props_.emplace_back("format", "NCHW64");
  1423. break;
  1424. case ConvBias::Format::NCHW4_NHWC:
  1425. props_.emplace_back("format", "NCHW4_NHWC");
  1426. break;
  1427. default:
  1428. props_.emplace_back("format", "INVALID");
  1429. break;
  1430. }
  1431. props_.emplace_back("pad_h", std::to_string(op_.pad_h));
  1432. props_.emplace_back("pad_w", std::to_string(op_.pad_w));
  1433. props_.emplace_back("stride_h", std::to_string(op_.stride_h));
  1434. props_.emplace_back("stride_w", std::to_string(op_.stride_w));
  1435. props_.emplace_back("dilate_h", std::to_string(op_.dilate_h));
  1436. props_.emplace_back("dilate_w", std::to_string(op_.dilate_w));
  1437. switch (op_.compute_mode){
  1438. case ConvBias::ComputeMode::DEFAULT:
  1439. props_.emplace_back("compute_mode", "DEFAULT");
  1440. break;
  1441. case ConvBias::ComputeMode::FLOAT32:
  1442. props_.emplace_back("compute_mode", "FLOAT32");
  1443. break;
  1444. default:
  1445. props_.emplace_back("compute_mode", "INVALID");
  1446. break;
  1447. }
  1448. switch (op_.strategy){
  1449. case ConvBias::Strategy::HEURISTIC:
  1450. props_.emplace_back("strategy", "HEURISTIC");
  1451. break;
  1452. case ConvBias::Strategy::PROFILE:
  1453. props_.emplace_back("strategy", "PROFILE");
  1454. break;
  1455. case ConvBias::Strategy::REPRODUCIBLE:
  1456. props_.emplace_back("strategy", "REPRODUCIBLE");
  1457. break;
  1458. case ConvBias::Strategy::OPTIMIZED:
  1459. props_.emplace_back("strategy", "OPTIMIZED");
  1460. break;
  1461. default:
  1462. props_.emplace_back("strategy", "INVALID");
  1463. break;
  1464. }
  1465. props_.emplace_back("workspace_limit", std::to_string(op_.workspace_limit));
  1466. props_.emplace_back("dtype", op_.dtype.name());
  1467. return props_;
  1468. }
  1469. std::string ConvBias_make_name_impl(const OpDef& def_) {
  1470. auto&& op_ = def_.cast_final_safe<ConvBias>();
  1471. static_cast<void>(op_);
  1472. return "ConvBias";
  1473. }
  1474. } // anonymous namespace
  1475. OP_TRAIT_REG(ConvBias, ConvBias)
  1476. .hash(ConvBias_hash_impl)
  1477. .is_same_st(ConvBias_is_same_st_impl)
  1478. .props(ConvBias_props_impl)
  1479. .make_name(ConvBias_make_name_impl);
  1480. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Convolution);
  1481. namespace {
  1482. size_t Convolution_hash_impl(const OpDef& def_) {
  1483. auto&& op_ = def_.cast_final_safe<Convolution>();
  1484. static_cast<void>(op_);
  1485. size_t val = mgb::hash(op_.dyn_typeinfo());
  1486. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode));
  1487. val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_h));
  1488. val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_w));
  1489. val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_h));
  1490. val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_w));
  1491. val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_h));
  1492. val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_w));
  1493. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.sparse));
  1494. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format));
  1495. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.compute_mode));
  1496. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.strategy));
  1497. val = mgb::hash_pair_combine(val, mgb::hash(op_.workspace_limit));
  1498. return val;
  1499. }
  1500. bool Convolution_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  1501. auto &&a_ = lhs_.cast_final_safe<Convolution>(),
  1502. &&b_ = rhs_.cast_final_safe<Convolution>();
  1503. static_cast<void>(a_);
  1504. static_cast<void>(b_);
  1505. if (a_.mode != b_.mode) return false;
  1506. if (a_.pad_h != b_.pad_h) return false;
  1507. if (a_.pad_w != b_.pad_w) return false;
  1508. if (a_.stride_h != b_.stride_h) return false;
  1509. if (a_.stride_w != b_.stride_w) return false;
  1510. if (a_.dilate_h != b_.dilate_h) return false;
  1511. if (a_.dilate_w != b_.dilate_w) return false;
  1512. if (a_.sparse != b_.sparse) return false;
  1513. if (a_.format != b_.format) return false;
  1514. if (a_.compute_mode != b_.compute_mode) return false;
  1515. if (a_.strategy != b_.strategy) return false;
  1516. if (a_.workspace_limit != b_.workspace_limit) return false;
  1517. return true;
  1518. }
  1519. std::vector<std::pair<const char*, std::string>> Convolution_props_impl(const OpDef& def_) {
  1520. auto&& op_ = def_.cast_final_safe<Convolution>();
  1521. static_cast<void>(op_);
  1522. std::vector<std::pair<const char*, std::string>> props_;
  1523. switch (op_.mode){
  1524. case Convolution::Mode::CROSS_CORRELATION:
  1525. props_.emplace_back("mode", "CROSS_CORRELATION");
  1526. break;
  1527. case Convolution::Mode::CONVOLUTION:
  1528. props_.emplace_back("mode", "CONVOLUTION");
  1529. break;
  1530. default:
  1531. props_.emplace_back("mode", "INVALID");
  1532. break;
  1533. }
  1534. props_.emplace_back("pad_h", std::to_string(op_.pad_h));
  1535. props_.emplace_back("pad_w", std::to_string(op_.pad_w));
  1536. props_.emplace_back("stride_h", std::to_string(op_.stride_h));
  1537. props_.emplace_back("stride_w", std::to_string(op_.stride_w));
  1538. props_.emplace_back("dilate_h", std::to_string(op_.dilate_h));
  1539. props_.emplace_back("dilate_w", std::to_string(op_.dilate_w));
  1540. switch (op_.sparse){
  1541. case Convolution::Sparse::DENSE:
  1542. props_.emplace_back("sparse", "DENSE");
  1543. break;
  1544. case Convolution::Sparse::GROUP:
  1545. props_.emplace_back("sparse", "GROUP");
  1546. break;
  1547. default:
  1548. props_.emplace_back("sparse", "INVALID");
  1549. break;
  1550. }
  1551. switch (op_.format){
  1552. case Convolution::Format::NCHW:
  1553. props_.emplace_back("format", "NCHW");
  1554. break;
  1555. case Convolution::Format::NHWC:
  1556. props_.emplace_back("format", "NHWC");
  1557. break;
  1558. case Convolution::Format::NHWCD4:
  1559. props_.emplace_back("format", "NHWCD4");
  1560. break;
  1561. case Convolution::Format::NCHW4:
  1562. props_.emplace_back("format", "NCHW4");
  1563. break;
  1564. case Convolution::Format::NCHW8:
  1565. props_.emplace_back("format", "NCHW8");
  1566. break;
  1567. case Convolution::Format::NCHW32:
  1568. props_.emplace_back("format", "NCHW32");
  1569. break;
  1570. case Convolution::Format::NCHW88:
  1571. props_.emplace_back("format", "NCHW88");
  1572. break;
  1573. case Convolution::Format::NCHW44:
  1574. props_.emplace_back("format", "NCHW44");
  1575. break;
  1576. case Convolution::Format::NCHW44_DOT:
  1577. props_.emplace_back("format", "NCHW44_DOT");
  1578. break;
  1579. case Convolution::Format::NCHW4_NCHW32:
  1580. props_.emplace_back("format", "NCHW4_NCHW32");
  1581. break;
  1582. case Convolution::Format::NCHW32_NCHW4:
  1583. props_.emplace_back("format", "NCHW32_NCHW4");
  1584. break;
  1585. case Convolution::Format::NCHW4_NCHW:
  1586. props_.emplace_back("format", "NCHW4_NCHW");
  1587. break;
  1588. case Convolution::Format::NHWC_NCHW:
  1589. props_.emplace_back("format", "NHWC_NCHW");
  1590. break;
  1591. case Convolution::Format::NHWC_NCHW4_IC_SMALL:
  1592. props_.emplace_back("format", "NHWC_NCHW4_IC_SMALL");
  1593. break;
  1594. case Convolution::Format::NCHW_NCHW4_IC_SMALL:
  1595. props_.emplace_back("format", "NCHW_NCHW4_IC_SMALL");
  1596. break;
  1597. case Convolution::Format::CHWN4:
  1598. props_.emplace_back("format", "CHWN4");
  1599. break;
  1600. case Convolution::Format::NCHW64:
  1601. props_.emplace_back("format", "NCHW64");
  1602. break;
  1603. case Convolution::Format::NCHW4_NHWC:
  1604. props_.emplace_back("format", "NCHW4_NHWC");
  1605. break;
  1606. default:
  1607. props_.emplace_back("format", "INVALID");
  1608. break;
  1609. }
  1610. switch (op_.compute_mode){
  1611. case Convolution::ComputeMode::DEFAULT:
  1612. props_.emplace_back("compute_mode", "DEFAULT");
  1613. break;
  1614. case Convolution::ComputeMode::FLOAT32:
  1615. props_.emplace_back("compute_mode", "FLOAT32");
  1616. break;
  1617. default:
  1618. props_.emplace_back("compute_mode", "INVALID");
  1619. break;
  1620. }
  1621. switch (op_.strategy){
  1622. case Convolution::Strategy::HEURISTIC:
  1623. props_.emplace_back("strategy", "HEURISTIC");
  1624. break;
  1625. case Convolution::Strategy::PROFILE:
  1626. props_.emplace_back("strategy", "PROFILE");
  1627. break;
  1628. case Convolution::Strategy::REPRODUCIBLE:
  1629. props_.emplace_back("strategy", "REPRODUCIBLE");
  1630. break;
  1631. case Convolution::Strategy::OPTIMIZED:
  1632. props_.emplace_back("strategy", "OPTIMIZED");
  1633. break;
  1634. default:
  1635. props_.emplace_back("strategy", "INVALID");
  1636. break;
  1637. }
  1638. props_.emplace_back("workspace_limit", std::to_string(op_.workspace_limit));
  1639. return props_;
  1640. }
  1641. std::string Convolution_make_name_impl(const OpDef& def_) {
  1642. auto&& op_ = def_.cast_final_safe<Convolution>();
  1643. static_cast<void>(op_);
  1644. return "Convolution";
  1645. }
  1646. } // anonymous namespace
  1647. OP_TRAIT_REG(Convolution, Convolution)
  1648. .hash(Convolution_hash_impl)
  1649. .is_same_st(Convolution_is_same_st_impl)
  1650. .props(Convolution_props_impl)
  1651. .make_name(Convolution_make_name_impl);
  1652. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Convolution3D);
  1653. namespace {
  1654. size_t Convolution3D_hash_impl(const OpDef& def_) {
  1655. auto&& op_ = def_.cast_final_safe<Convolution3D>();
  1656. static_cast<void>(op_);
  1657. size_t val = mgb::hash(op_.dyn_typeinfo());
  1658. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode));
  1659. val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_d));
  1660. val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_h));
  1661. val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_w));
  1662. val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_d));
  1663. val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_h));
  1664. val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_w));
  1665. val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_d));
  1666. val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_h));
  1667. val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_w));
  1668. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.sparse));
  1669. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.data_type));
  1670. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format));
  1671. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.strategy));
  1672. val = mgb::hash_pair_combine(val, mgb::hash(op_.workspace_limit));
  1673. return val;
  1674. }
  1675. bool Convolution3D_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  1676. auto &&a_ = lhs_.cast_final_safe<Convolution3D>(),
  1677. &&b_ = rhs_.cast_final_safe<Convolution3D>();
  1678. static_cast<void>(a_);
  1679. static_cast<void>(b_);
  1680. if (a_.mode != b_.mode) return false;
  1681. if (a_.pad_d != b_.pad_d) return false;
  1682. if (a_.pad_h != b_.pad_h) return false;
  1683. if (a_.pad_w != b_.pad_w) return false;
  1684. if (a_.stride_d != b_.stride_d) return false;
  1685. if (a_.stride_h != b_.stride_h) return false;
  1686. if (a_.stride_w != b_.stride_w) return false;
  1687. if (a_.dilate_d != b_.dilate_d) return false;
  1688. if (a_.dilate_h != b_.dilate_h) return false;
  1689. if (a_.dilate_w != b_.dilate_w) return false;
  1690. if (a_.sparse != b_.sparse) return false;
  1691. if (a_.data_type != b_.data_type) return false;
  1692. if (a_.format != b_.format) return false;
  1693. if (a_.strategy != b_.strategy) return false;
  1694. if (a_.workspace_limit != b_.workspace_limit) return false;
  1695. return true;
  1696. }
  1697. std::vector<std::pair<const char*, std::string>> Convolution3D_props_impl(const OpDef& def_) {
  1698. auto&& op_ = def_.cast_final_safe<Convolution3D>();
  1699. static_cast<void>(op_);
  1700. std::vector<std::pair<const char*, std::string>> props_;
  1701. switch (op_.mode){
  1702. case Convolution3D::Mode::CROSS_CORRELATION:
  1703. props_.emplace_back("mode", "CROSS_CORRELATION");
  1704. break;
  1705. case Convolution3D::Mode::CONVOLUTION:
  1706. props_.emplace_back("mode", "CONVOLUTION");
  1707. break;
  1708. default:
  1709. props_.emplace_back("mode", "INVALID");
  1710. break;
  1711. }
  1712. props_.emplace_back("pad_d", std::to_string(op_.pad_d));
  1713. props_.emplace_back("pad_h", std::to_string(op_.pad_h));
  1714. props_.emplace_back("pad_w", std::to_string(op_.pad_w));
  1715. props_.emplace_back("stride_d", std::to_string(op_.stride_d));
  1716. props_.emplace_back("stride_h", std::to_string(op_.stride_h));
  1717. props_.emplace_back("stride_w", std::to_string(op_.stride_w));
  1718. props_.emplace_back("dilate_d", std::to_string(op_.dilate_d));
  1719. props_.emplace_back("dilate_h", std::to_string(op_.dilate_h));
  1720. props_.emplace_back("dilate_w", std::to_string(op_.dilate_w));
  1721. switch (op_.sparse){
  1722. case Convolution3D::Sparse::DENSE:
  1723. props_.emplace_back("sparse", "DENSE");
  1724. break;
  1725. case Convolution3D::Sparse::GROUP:
  1726. props_.emplace_back("sparse", "GROUP");
  1727. break;
  1728. default:
  1729. props_.emplace_back("sparse", "INVALID");
  1730. break;
  1731. }
  1732. switch (op_.data_type){
  1733. case Convolution3D::DataType::FLOAT:
  1734. props_.emplace_back("data_type", "FLOAT");
  1735. break;
  1736. case Convolution3D::DataType::FLOAT_IO16xC32:
  1737. props_.emplace_back("data_type", "FLOAT_IO16xC32");
  1738. break;
  1739. default:
  1740. props_.emplace_back("data_type", "INVALID");
  1741. break;
  1742. }
  1743. switch (op_.format){
  1744. case Convolution3D::Format::NCDHW:
  1745. props_.emplace_back("format", "NCDHW");
  1746. break;
  1747. case Convolution3D::Format::NDHWC:
  1748. props_.emplace_back("format", "NDHWC");
  1749. break;
  1750. default:
  1751. props_.emplace_back("format", "INVALID");
  1752. break;
  1753. }
  1754. switch (op_.strategy){
  1755. case Convolution3D::Strategy::HEURISTIC:
  1756. props_.emplace_back("strategy", "HEURISTIC");
  1757. break;
  1758. case Convolution3D::Strategy::PROFILE:
  1759. props_.emplace_back("strategy", "PROFILE");
  1760. break;
  1761. case Convolution3D::Strategy::REPRODUCIBLE:
  1762. props_.emplace_back("strategy", "REPRODUCIBLE");
  1763. break;
  1764. case Convolution3D::Strategy::OPTIMIZED:
  1765. props_.emplace_back("strategy", "OPTIMIZED");
  1766. break;
  1767. default:
  1768. props_.emplace_back("strategy", "INVALID");
  1769. break;
  1770. }
  1771. props_.emplace_back("workspace_limit", std::to_string(op_.workspace_limit));
  1772. return props_;
  1773. }
  1774. std::string Convolution3D_make_name_impl(const OpDef& def_) {
  1775. auto&& op_ = def_.cast_final_safe<Convolution3D>();
  1776. static_cast<void>(op_);
  1777. return "Convolution3D";
  1778. }
  1779. } // anonymous namespace
  1780. OP_TRAIT_REG(Convolution3D, Convolution3D)
  1781. .hash(Convolution3D_hash_impl)
  1782. .is_same_st(Convolution3D_is_same_st_impl)
  1783. .props(Convolution3D_props_impl)
  1784. .make_name(Convolution3D_make_name_impl);
  1785. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Convolution3DBackwardData);
  1786. namespace {
  1787. size_t Convolution3DBackwardData_hash_impl(const OpDef& def_) {
  1788. auto&& op_ = def_.cast_final_safe<Convolution3DBackwardData>();
  1789. static_cast<void>(op_);
  1790. size_t val = mgb::hash(op_.dyn_typeinfo());
  1791. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode));
  1792. val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_d));
  1793. val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_h));
  1794. val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_w));
  1795. val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_d));
  1796. val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_h));
  1797. val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_w));
  1798. val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_d));
  1799. val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_h));
  1800. val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_w));
  1801. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.sparse));
  1802. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.data_type));
  1803. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format));
  1804. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.strategy));
  1805. val = mgb::hash_pair_combine(val, mgb::hash(op_.workspace_limit));
  1806. return val;
  1807. }
  1808. bool Convolution3DBackwardData_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  1809. auto &&a_ = lhs_.cast_final_safe<Convolution3DBackwardData>(),
  1810. &&b_ = rhs_.cast_final_safe<Convolution3DBackwardData>();
  1811. static_cast<void>(a_);
  1812. static_cast<void>(b_);
  1813. if (a_.mode != b_.mode) return false;
  1814. if (a_.pad_d != b_.pad_d) return false;
  1815. if (a_.pad_h != b_.pad_h) return false;
  1816. if (a_.pad_w != b_.pad_w) return false;
  1817. if (a_.stride_d != b_.stride_d) return false;
  1818. if (a_.stride_h != b_.stride_h) return false;
  1819. if (a_.stride_w != b_.stride_w) return false;
  1820. if (a_.dilate_d != b_.dilate_d) return false;
  1821. if (a_.dilate_h != b_.dilate_h) return false;
  1822. if (a_.dilate_w != b_.dilate_w) return false;
  1823. if (a_.sparse != b_.sparse) return false;
  1824. if (a_.data_type != b_.data_type) return false;
  1825. if (a_.format != b_.format) return false;
  1826. if (a_.strategy != b_.strategy) return false;
  1827. if (a_.workspace_limit != b_.workspace_limit) return false;
  1828. return true;
  1829. }
  1830. std::vector<std::pair<const char*, std::string>> Convolution3DBackwardData_props_impl(const OpDef& def_) {
  1831. auto&& op_ = def_.cast_final_safe<Convolution3DBackwardData>();
  1832. static_cast<void>(op_);
  1833. std::vector<std::pair<const char*, std::string>> props_;
  1834. switch (op_.mode){
  1835. case Convolution3DBackwardData::Mode::CROSS_CORRELATION:
  1836. props_.emplace_back("mode", "CROSS_CORRELATION");
  1837. break;
  1838. case Convolution3DBackwardData::Mode::CONVOLUTION:
  1839. props_.emplace_back("mode", "CONVOLUTION");
  1840. break;
  1841. default:
  1842. props_.emplace_back("mode", "INVALID");
  1843. break;
  1844. }
  1845. props_.emplace_back("pad_d", std::to_string(op_.pad_d));
  1846. props_.emplace_back("pad_h", std::to_string(op_.pad_h));
  1847. props_.emplace_back("pad_w", std::to_string(op_.pad_w));
  1848. props_.emplace_back("stride_d", std::to_string(op_.stride_d));
  1849. props_.emplace_back("stride_h", std::to_string(op_.stride_h));
  1850. props_.emplace_back("stride_w", std::to_string(op_.stride_w));
  1851. props_.emplace_back("dilate_d", std::to_string(op_.dilate_d));
  1852. props_.emplace_back("dilate_h", std::to_string(op_.dilate_h));
  1853. props_.emplace_back("dilate_w", std::to_string(op_.dilate_w));
  1854. switch (op_.sparse){
  1855. case Convolution3DBackwardData::Sparse::DENSE:
  1856. props_.emplace_back("sparse", "DENSE");
  1857. break;
  1858. case Convolution3DBackwardData::Sparse::GROUP:
  1859. props_.emplace_back("sparse", "GROUP");
  1860. break;
  1861. default:
  1862. props_.emplace_back("sparse", "INVALID");
  1863. break;
  1864. }
  1865. switch (op_.data_type){
  1866. case Convolution3DBackwardData::DataType::FLOAT:
  1867. props_.emplace_back("data_type", "FLOAT");
  1868. break;
  1869. case Convolution3DBackwardData::DataType::FLOAT_IO16xC32:
  1870. props_.emplace_back("data_type", "FLOAT_IO16xC32");
  1871. break;
  1872. default:
  1873. props_.emplace_back("data_type", "INVALID");
  1874. break;
  1875. }
  1876. switch (op_.format){
  1877. case Convolution3DBackwardData::Format::NCDHW:
  1878. props_.emplace_back("format", "NCDHW");
  1879. break;
  1880. case Convolution3DBackwardData::Format::NDHWC:
  1881. props_.emplace_back("format", "NDHWC");
  1882. break;
  1883. default:
  1884. props_.emplace_back("format", "INVALID");
  1885. break;
  1886. }
  1887. switch (op_.strategy){
  1888. case Convolution3DBackwardData::Strategy::HEURISTIC:
  1889. props_.emplace_back("strategy", "HEURISTIC");
  1890. break;
  1891. case Convolution3DBackwardData::Strategy::PROFILE:
  1892. props_.emplace_back("strategy", "PROFILE");
  1893. break;
  1894. case Convolution3DBackwardData::Strategy::REPRODUCIBLE:
  1895. props_.emplace_back("strategy", "REPRODUCIBLE");
  1896. break;
  1897. case Convolution3DBackwardData::Strategy::OPTIMIZED:
  1898. props_.emplace_back("strategy", "OPTIMIZED");
  1899. break;
  1900. default:
  1901. props_.emplace_back("strategy", "INVALID");
  1902. break;
  1903. }
  1904. props_.emplace_back("workspace_limit", std::to_string(op_.workspace_limit));
  1905. return props_;
  1906. }
  1907. std::string Convolution3DBackwardData_make_name_impl(const OpDef& def_) {
  1908. auto&& op_ = def_.cast_final_safe<Convolution3DBackwardData>();
  1909. static_cast<void>(op_);
  1910. return "Convolution3DBackwardData";
  1911. }
  1912. } // anonymous namespace
  1913. OP_TRAIT_REG(Convolution3DBackwardData, Convolution3DBackwardData)
  1914. .hash(Convolution3DBackwardData_hash_impl)
  1915. .is_same_st(Convolution3DBackwardData_is_same_st_impl)
  1916. .props(Convolution3DBackwardData_props_impl)
  1917. .make_name(Convolution3DBackwardData_make_name_impl);
  1918. MGB_DYN_TYPE_OBJ_FINAL_IMPL(ConvolutionBackwardData);
  1919. namespace {
  1920. size_t ConvolutionBackwardData_hash_impl(const OpDef& def_) {
  1921. auto&& op_ = def_.cast_final_safe<ConvolutionBackwardData>();
  1922. static_cast<void>(op_);
  1923. size_t val = mgb::hash(op_.dyn_typeinfo());
  1924. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode));
  1925. val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_h));
  1926. val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_w));
  1927. val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_h));
  1928. val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_w));
  1929. val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_h));
  1930. val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_w));
  1931. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.sparse));
  1932. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format));
  1933. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.compute_mode));
  1934. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.strategy));
  1935. val = mgb::hash_pair_combine(val, mgb::hash(op_.workspace_limit));
  1936. val = mgb::hash_pair_combine(val, mgb::hash(op_.dtype.handle()));
  1937. return val;
  1938. }
  1939. bool ConvolutionBackwardData_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  1940. auto &&a_ = lhs_.cast_final_safe<ConvolutionBackwardData>(),
  1941. &&b_ = rhs_.cast_final_safe<ConvolutionBackwardData>();
  1942. static_cast<void>(a_);
  1943. static_cast<void>(b_);
  1944. if (a_.mode != b_.mode) return false;
  1945. if (a_.pad_h != b_.pad_h) return false;
  1946. if (a_.pad_w != b_.pad_w) return false;
  1947. if (a_.stride_h != b_.stride_h) return false;
  1948. if (a_.stride_w != b_.stride_w) return false;
  1949. if (a_.dilate_h != b_.dilate_h) return false;
  1950. if (a_.dilate_w != b_.dilate_w) return false;
  1951. if (a_.sparse != b_.sparse) return false;
  1952. if (a_.format != b_.format) return false;
  1953. if (a_.compute_mode != b_.compute_mode) return false;
  1954. if (a_.strategy != b_.strategy) return false;
  1955. if (a_.workspace_limit != b_.workspace_limit) return false;
  1956. if (a_.dtype != b_.dtype) return false;
  1957. return true;
  1958. }
  1959. std::vector<std::pair<const char*, std::string>> ConvolutionBackwardData_props_impl(const OpDef& def_) {
  1960. auto&& op_ = def_.cast_final_safe<ConvolutionBackwardData>();
  1961. static_cast<void>(op_);
  1962. std::vector<std::pair<const char*, std::string>> props_;
  1963. switch (op_.mode){
  1964. case ConvolutionBackwardData::Mode::CROSS_CORRELATION:
  1965. props_.emplace_back("mode", "CROSS_CORRELATION");
  1966. break;
  1967. case ConvolutionBackwardData::Mode::CONVOLUTION:
  1968. props_.emplace_back("mode", "CONVOLUTION");
  1969. break;
  1970. default:
  1971. props_.emplace_back("mode", "INVALID");
  1972. break;
  1973. }
  1974. props_.emplace_back("pad_h", std::to_string(op_.pad_h));
  1975. props_.emplace_back("pad_w", std::to_string(op_.pad_w));
  1976. props_.emplace_back("stride_h", std::to_string(op_.stride_h));
  1977. props_.emplace_back("stride_w", std::to_string(op_.stride_w));
  1978. props_.emplace_back("dilate_h", std::to_string(op_.dilate_h));
  1979. props_.emplace_back("dilate_w", std::to_string(op_.dilate_w));
  1980. switch (op_.sparse){
  1981. case ConvolutionBackwardData::Sparse::DENSE:
  1982. props_.emplace_back("sparse", "DENSE");
  1983. break;
  1984. case ConvolutionBackwardData::Sparse::GROUP:
  1985. props_.emplace_back("sparse", "GROUP");
  1986. break;
  1987. default:
  1988. props_.emplace_back("sparse", "INVALID");
  1989. break;
  1990. }
  1991. switch (op_.format){
  1992. case ConvolutionBackwardData::Format::NCHW:
  1993. props_.emplace_back("format", "NCHW");
  1994. break;
  1995. case ConvolutionBackwardData::Format::NHWC:
  1996. props_.emplace_back("format", "NHWC");
  1997. break;
  1998. case ConvolutionBackwardData::Format::NHWCD4:
  1999. props_.emplace_back("format", "NHWCD4");
  2000. break;
  2001. case ConvolutionBackwardData::Format::NCHW4:
  2002. props_.emplace_back("format", "NCHW4");
  2003. break;
  2004. case ConvolutionBackwardData::Format::NCHW8:
  2005. props_.emplace_back("format", "NCHW8");
  2006. break;
  2007. case ConvolutionBackwardData::Format::NCHW32:
  2008. props_.emplace_back("format", "NCHW32");
  2009. break;
  2010. case ConvolutionBackwardData::Format::NCHW88:
  2011. props_.emplace_back("format", "NCHW88");
  2012. break;
  2013. case ConvolutionBackwardData::Format::NCHW44:
  2014. props_.emplace_back("format", "NCHW44");
  2015. break;
  2016. case ConvolutionBackwardData::Format::NCHW44_DOT:
  2017. props_.emplace_back("format", "NCHW44_DOT");
  2018. break;
  2019. case ConvolutionBackwardData::Format::NCHW4_NCHW32:
  2020. props_.emplace_back("format", "NCHW4_NCHW32");
  2021. break;
  2022. case ConvolutionBackwardData::Format::NCHW32_NCHW4:
  2023. props_.emplace_back("format", "NCHW32_NCHW4");
  2024. break;
  2025. case ConvolutionBackwardData::Format::NCHW4_NCHW:
  2026. props_.emplace_back("format", "NCHW4_NCHW");
  2027. break;
  2028. case ConvolutionBackwardData::Format::NHWC_NCHW:
  2029. props_.emplace_back("format", "NHWC_NCHW");
  2030. break;
  2031. case ConvolutionBackwardData::Format::NHWC_NCHW4_IC_SMALL:
  2032. props_.emplace_back("format", "NHWC_NCHW4_IC_SMALL");
  2033. break;
  2034. case ConvolutionBackwardData::Format::NCHW_NCHW4_IC_SMALL:
  2035. props_.emplace_back("format", "NCHW_NCHW4_IC_SMALL");
  2036. break;
  2037. case ConvolutionBackwardData::Format::CHWN4:
  2038. props_.emplace_back("format", "CHWN4");
  2039. break;
  2040. case ConvolutionBackwardData::Format::NCHW64:
  2041. props_.emplace_back("format", "NCHW64");
  2042. break;
  2043. case ConvolutionBackwardData::Format::NCHW4_NHWC:
  2044. props_.emplace_back("format", "NCHW4_NHWC");
  2045. break;
  2046. default:
  2047. props_.emplace_back("format", "INVALID");
  2048. break;
  2049. }
  2050. switch (op_.compute_mode){
  2051. case ConvolutionBackwardData::ComputeMode::DEFAULT:
  2052. props_.emplace_back("compute_mode", "DEFAULT");
  2053. break;
  2054. case ConvolutionBackwardData::ComputeMode::FLOAT32:
  2055. props_.emplace_back("compute_mode", "FLOAT32");
  2056. break;
  2057. default:
  2058. props_.emplace_back("compute_mode", "INVALID");
  2059. break;
  2060. }
  2061. switch (op_.strategy){
  2062. case ConvolutionBackwardData::Strategy::HEURISTIC:
  2063. props_.emplace_back("strategy", "HEURISTIC");
  2064. break;
  2065. case ConvolutionBackwardData::Strategy::PROFILE:
  2066. props_.emplace_back("strategy", "PROFILE");
  2067. break;
  2068. case ConvolutionBackwardData::Strategy::REPRODUCIBLE:
  2069. props_.emplace_back("strategy", "REPRODUCIBLE");
  2070. break;
  2071. case ConvolutionBackwardData::Strategy::OPTIMIZED:
  2072. props_.emplace_back("strategy", "OPTIMIZED");
  2073. break;
  2074. default:
  2075. props_.emplace_back("strategy", "INVALID");
  2076. break;
  2077. }
  2078. props_.emplace_back("workspace_limit", std::to_string(op_.workspace_limit));
  2079. props_.emplace_back("dtype", op_.dtype.name());
  2080. return props_;
  2081. }
  2082. std::string ConvolutionBackwardData_make_name_impl(const OpDef& def_) {
  2083. auto&& op_ = def_.cast_final_safe<ConvolutionBackwardData>();
  2084. static_cast<void>(op_);
  2085. return "ConvolutionBackwardData";
  2086. }
  2087. } // anonymous namespace
  2088. OP_TRAIT_REG(ConvolutionBackwardData, ConvolutionBackwardData)
  2089. .hash(ConvolutionBackwardData_hash_impl)
  2090. .is_same_st(ConvolutionBackwardData_is_same_st_impl)
  2091. .props(ConvolutionBackwardData_props_impl)
  2092. .make_name(ConvolutionBackwardData_make_name_impl);
  2093. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Copy);
  2094. namespace {
  2095. size_t Copy_hash_impl(const OpDef& def_) {
  2096. auto&& op_ = def_.cast_final_safe<Copy>();
  2097. static_cast<void>(op_);
  2098. size_t val = mgb::hash(op_.dyn_typeinfo());
  2099. val = mgb::hash_pair_combine(val, mgb::hash(op_.comp_node));
  2100. return val;
  2101. }
  2102. bool Copy_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  2103. auto &&a_ = lhs_.cast_final_safe<Copy>(),
  2104. &&b_ = rhs_.cast_final_safe<Copy>();
  2105. static_cast<void>(a_);
  2106. static_cast<void>(b_);
  2107. if (a_.comp_node != b_.comp_node) return false;
  2108. return true;
  2109. }
  2110. std::vector<std::pair<const char*, std::string>> Copy_props_impl(const OpDef& def_) {
  2111. auto&& op_ = def_.cast_final_safe<Copy>();
  2112. static_cast<void>(op_);
  2113. std::vector<std::pair<const char*, std::string>> props_;
  2114. props_.emplace_back("comp_node", op_.comp_node.to_string());
  2115. return props_;
  2116. }
  2117. std::string Copy_make_name_impl(const OpDef& def_) {
  2118. auto&& op_ = def_.cast_final_safe<Copy>();
  2119. static_cast<void>(op_);
  2120. return "Copy";
  2121. }
  2122. } // anonymous namespace
  2123. OP_TRAIT_REG(Copy, Copy)
  2124. .hash(Copy_hash_impl)
  2125. .is_same_st(Copy_is_same_st_impl)
  2126. .props(Copy_props_impl)
  2127. .make_name(Copy_make_name_impl);
  2128. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Correlation);
  2129. namespace {
  2130. size_t Correlation_hash_impl(const OpDef& def_) {
  2131. auto&& op_ = def_.cast_final_safe<Correlation>();
  2132. static_cast<void>(op_);
  2133. size_t val = mgb::hash(op_.dyn_typeinfo());
  2134. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format));
  2135. val = mgb::hash_pair_combine(val, mgb::hash(op_.kernel_size));
  2136. val = mgb::hash_pair_combine(val, mgb::hash(op_.max_displacement));
  2137. val = mgb::hash_pair_combine(val, mgb::hash(op_.stride1));
  2138. val = mgb::hash_pair_combine(val, mgb::hash(op_.stride2));
  2139. val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_size));
  2140. val = mgb::hash_pair_combine(val, mgb::hash(op_.is_multiply));
  2141. return val;
  2142. }
  2143. bool Correlation_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  2144. auto &&a_ = lhs_.cast_final_safe<Correlation>(),
  2145. &&b_ = rhs_.cast_final_safe<Correlation>();
  2146. static_cast<void>(a_);
  2147. static_cast<void>(b_);
  2148. if (a_.format != b_.format) return false;
  2149. if (a_.kernel_size != b_.kernel_size) return false;
  2150. if (a_.max_displacement != b_.max_displacement) return false;
  2151. if (a_.stride1 != b_.stride1) return false;
  2152. if (a_.stride2 != b_.stride2) return false;
  2153. if (a_.pad_size != b_.pad_size) return false;
  2154. if (a_.is_multiply != b_.is_multiply) return false;
  2155. return true;
  2156. }
  2157. std::vector<std::pair<const char*, std::string>> Correlation_props_impl(const OpDef& def_) {
  2158. auto&& op_ = def_.cast_final_safe<Correlation>();
  2159. static_cast<void>(op_);
  2160. std::vector<std::pair<const char*, std::string>> props_;
  2161. switch (op_.format){
  2162. case Correlation::Format::NCHW:
  2163. props_.emplace_back("format", "NCHW");
  2164. break;
  2165. case Correlation::Format::NHWC:
  2166. props_.emplace_back("format", "NHWC");
  2167. break;
  2168. case Correlation::Format::NHWCD4:
  2169. props_.emplace_back("format", "NHWCD4");
  2170. break;
  2171. case Correlation::Format::NCHW4:
  2172. props_.emplace_back("format", "NCHW4");
  2173. break;
  2174. case Correlation::Format::NCHW8:
  2175. props_.emplace_back("format", "NCHW8");
  2176. break;
  2177. case Correlation::Format::NCHW32:
  2178. props_.emplace_back("format", "NCHW32");
  2179. break;
  2180. case Correlation::Format::NCHW88:
  2181. props_.emplace_back("format", "NCHW88");
  2182. break;
  2183. case Correlation::Format::NCHW44:
  2184. props_.emplace_back("format", "NCHW44");
  2185. break;
  2186. case Correlation::Format::NCHW44_DOT:
  2187. props_.emplace_back("format", "NCHW44_DOT");
  2188. break;
  2189. case Correlation::Format::NCHW_WINOGRAD:
  2190. props_.emplace_back("format", "NCHW_WINOGRAD");
  2191. break;
  2192. case Correlation::Format::NCHW88_WINOGRAD:
  2193. props_.emplace_back("format", "NCHW88_WINOGRAD");
  2194. break;
  2195. case Correlation::Format::NCHW44_WINOGRAD:
  2196. props_.emplace_back("format", "NCHW44_WINOGRAD");
  2197. break;
  2198. case Correlation::Format::NCHW4_NCHW32:
  2199. props_.emplace_back("format", "NCHW4_NCHW32");
  2200. break;
  2201. case Correlation::Format::NCHW32_NCHW4:
  2202. props_.emplace_back("format", "NCHW32_NCHW4");
  2203. break;
  2204. case Correlation::Format::NCHW4_NCHW:
  2205. props_.emplace_back("format", "NCHW4_NCHW");
  2206. break;
  2207. case Correlation::Format::NHWC_NCHW:
  2208. props_.emplace_back("format", "NHWC_NCHW");
  2209. break;
  2210. case Correlation::Format::NHWC_NCHW4_IC_SMALL:
  2211. props_.emplace_back("format", "NHWC_NCHW4_IC_SMALL");
  2212. break;
  2213. case Correlation::Format::NCHW_NCHW4_IC_SMALL:
  2214. props_.emplace_back("format", "NCHW_NCHW4_IC_SMALL");
  2215. break;
  2216. case Correlation::Format::CHWN4:
  2217. props_.emplace_back("format", "CHWN4");
  2218. break;
  2219. case Correlation::Format::NCHW4_NHWC:
  2220. props_.emplace_back("format", "NCHW4_NHWC");
  2221. break;
  2222. default:
  2223. props_.emplace_back("format", "INVALID");
  2224. break;
  2225. }
  2226. props_.emplace_back("kernel_size", std::to_string(op_.kernel_size));
  2227. props_.emplace_back("max_displacement", std::to_string(op_.max_displacement));
  2228. props_.emplace_back("stride1", std::to_string(op_.stride1));
  2229. props_.emplace_back("stride2", std::to_string(op_.stride2));
  2230. props_.emplace_back("pad_size", std::to_string(op_.pad_size));
  2231. props_.emplace_back("is_multiply", std::to_string(op_.is_multiply));
  2232. return props_;
  2233. }
  2234. std::string Correlation_make_name_impl(const OpDef& def_) {
  2235. auto&& op_ = def_.cast_final_safe<Correlation>();
  2236. static_cast<void>(op_);
  2237. return "Correlation";
  2238. }
  2239. } // anonymous namespace
  2240. OP_TRAIT_REG(Correlation, Correlation)
  2241. .hash(Correlation_hash_impl)
  2242. .is_same_st(Correlation_is_same_st_impl)
  2243. .props(Correlation_props_impl)
  2244. .make_name(Correlation_make_name_impl);
  2245. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Cumsum);
  2246. namespace {
  2247. size_t Cumsum_hash_impl(const OpDef& def_) {
  2248. auto&& op_ = def_.cast_final_safe<Cumsum>();
  2249. static_cast<void>(op_);
  2250. size_t val = mgb::hash(op_.dyn_typeinfo());
  2251. val = mgb::hash_pair_combine(val, mgb::hash(op_.axis));
  2252. val = mgb::hash_pair_combine(val, mgb::hash(op_.exclusive));
  2253. val = mgb::hash_pair_combine(val, mgb::hash(op_.reverse));
  2254. return val;
  2255. }
  2256. bool Cumsum_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  2257. auto &&a_ = lhs_.cast_final_safe<Cumsum>(),
  2258. &&b_ = rhs_.cast_final_safe<Cumsum>();
  2259. static_cast<void>(a_);
  2260. static_cast<void>(b_);
  2261. if (a_.axis != b_.axis) return false;
  2262. if (a_.exclusive != b_.exclusive) return false;
  2263. if (a_.reverse != b_.reverse) return false;
  2264. return true;
  2265. }
  2266. std::vector<std::pair<const char*, std::string>> Cumsum_props_impl(const OpDef& def_) {
  2267. auto&& op_ = def_.cast_final_safe<Cumsum>();
  2268. static_cast<void>(op_);
  2269. std::vector<std::pair<const char*, std::string>> props_;
  2270. props_.emplace_back("axis", std::to_string(op_.axis));
  2271. props_.emplace_back("exclusive", std::to_string(op_.exclusive));
  2272. props_.emplace_back("reverse", std::to_string(op_.reverse));
  2273. return props_;
  2274. }
  2275. std::string Cumsum_make_name_impl(const OpDef& def_) {
  2276. auto&& op_ = def_.cast_final_safe<Cumsum>();
  2277. static_cast<void>(op_);
  2278. return "Cumsum";
  2279. }
  2280. } // anonymous namespace
  2281. OP_TRAIT_REG(Cumsum, Cumsum)
  2282. .hash(Cumsum_hash_impl)
  2283. .is_same_st(Cumsum_is_same_st_impl)
  2284. .props(Cumsum_props_impl)
  2285. .make_name(Cumsum_make_name_impl);
  2286. MGB_DYN_TYPE_OBJ_FINAL_IMPL(CvtColor);
  2287. namespace {
  2288. size_t CvtColor_hash_impl(const OpDef& def_) {
  2289. auto&& op_ = def_.cast_final_safe<CvtColor>();
  2290. static_cast<void>(op_);
  2291. size_t val = mgb::hash(op_.dyn_typeinfo());
  2292. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode));
  2293. return val;
  2294. }
  2295. bool CvtColor_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  2296. auto &&a_ = lhs_.cast_final_safe<CvtColor>(),
  2297. &&b_ = rhs_.cast_final_safe<CvtColor>();
  2298. static_cast<void>(a_);
  2299. static_cast<void>(b_);
  2300. if (a_.mode != b_.mode) return false;
  2301. return true;
  2302. }
  2303. std::vector<std::pair<const char*, std::string>> CvtColor_props_impl(const OpDef& def_) {
  2304. auto&& op_ = def_.cast_final_safe<CvtColor>();
  2305. static_cast<void>(op_);
  2306. std::vector<std::pair<const char*, std::string>> props_;
  2307. switch (op_.mode){
  2308. case CvtColor::Mode::RGB2GRAY:
  2309. props_.emplace_back("mode", "RGB2GRAY");
  2310. break;
  2311. case CvtColor::Mode::RGB2YUV:
  2312. props_.emplace_back("mode", "RGB2YUV");
  2313. break;
  2314. case CvtColor::Mode::YUV2RGB:
  2315. props_.emplace_back("mode", "YUV2RGB");
  2316. break;
  2317. case CvtColor::Mode::GRAY2RGB:
  2318. props_.emplace_back("mode", "GRAY2RGB");
  2319. break;
  2320. case CvtColor::Mode::RGBA2RGB:
  2321. props_.emplace_back("mode", "RGBA2RGB");
  2322. break;
  2323. case CvtColor::Mode::RGBA2BGR:
  2324. props_.emplace_back("mode", "RGBA2BGR");
  2325. break;
  2326. case CvtColor::Mode::RGBA2GRAY:
  2327. props_.emplace_back("mode", "RGBA2GRAY");
  2328. break;
  2329. case CvtColor::Mode::RGB2BGR:
  2330. props_.emplace_back("mode", "RGB2BGR");
  2331. break;
  2332. case CvtColor::Mode::BGR2GRAY:
  2333. props_.emplace_back("mode", "BGR2GRAY");
  2334. break;
  2335. case CvtColor::Mode::BGR2RGB:
  2336. props_.emplace_back("mode", "BGR2RGB");
  2337. break;
  2338. case CvtColor::Mode::YUV2GRAY_NV21:
  2339. props_.emplace_back("mode", "YUV2GRAY_NV21");
  2340. break;
  2341. case CvtColor::Mode::YUV2RGB_NV21:
  2342. props_.emplace_back("mode", "YUV2RGB_NV21");
  2343. break;
  2344. case CvtColor::Mode::YUV2BGR_NV21:
  2345. props_.emplace_back("mode", "YUV2BGR_NV21");
  2346. break;
  2347. case CvtColor::Mode::YUV2GRAY_NV12:
  2348. props_.emplace_back("mode", "YUV2GRAY_NV12");
  2349. break;
  2350. case CvtColor::Mode::YUV2RGB_NV12:
  2351. props_.emplace_back("mode", "YUV2RGB_NV12");
  2352. break;
  2353. case CvtColor::Mode::YUV2BGR_NV12:
  2354. props_.emplace_back("mode", "YUV2BGR_NV12");
  2355. break;
  2356. case CvtColor::Mode::YUV2GRAY_YV12:
  2357. props_.emplace_back("mode", "YUV2GRAY_YV12");
  2358. break;
  2359. case CvtColor::Mode::YUV2RGB_YV12:
  2360. props_.emplace_back("mode", "YUV2RGB_YV12");
  2361. break;
  2362. case CvtColor::Mode::YUV2BGR_YV12:
  2363. props_.emplace_back("mode", "YUV2BGR_YV12");
  2364. break;
  2365. case CvtColor::Mode::YUV2GRAY_YU12:
  2366. props_.emplace_back("mode", "YUV2GRAY_YU12");
  2367. break;
  2368. case CvtColor::Mode::YUV2RGB_YU12:
  2369. props_.emplace_back("mode", "YUV2RGB_YU12");
  2370. break;
  2371. case CvtColor::Mode::YUV2BGR_YU12:
  2372. props_.emplace_back("mode", "YUV2BGR_YU12");
  2373. break;
  2374. case CvtColor::Mode::YCrCb2RGB:
  2375. props_.emplace_back("mode", "YCrCb2RGB");
  2376. break;
  2377. case CvtColor::Mode::YCrCb2BGR:
  2378. props_.emplace_back("mode", "YCrCb2BGR");
  2379. break;
  2380. case CvtColor::Mode::BT601_YUV2RGB_NV21:
  2381. props_.emplace_back("mode", "BT601_YUV2RGB_NV21");
  2382. break;
  2383. case CvtColor::Mode::BT601_YUV2BGR_NV21:
  2384. props_.emplace_back("mode", "BT601_YUV2BGR_NV21");
  2385. break;
  2386. case CvtColor::Mode::BT601_YUV2RGB_NV12:
  2387. props_.emplace_back("mode", "BT601_YUV2RGB_NV12");
  2388. break;
  2389. case CvtColor::Mode::BT601_YUV2BGR_NV12:
  2390. props_.emplace_back("mode", "BT601_YUV2BGR_NV12");
  2391. break;
  2392. case CvtColor::Mode::BT601_YUV2RGB_YV12:
  2393. props_.emplace_back("mode", "BT601_YUV2RGB_YV12");
  2394. break;
  2395. case CvtColor::Mode::BT601_YUV2BGR_YV12:
  2396. props_.emplace_back("mode", "BT601_YUV2BGR_YV12");
  2397. break;
  2398. case CvtColor::Mode::BT601_YUV2RGB_YU12:
  2399. props_.emplace_back("mode", "BT601_YUV2RGB_YU12");
  2400. break;
  2401. case CvtColor::Mode::BT601_YUV2BGR_YU12:
  2402. props_.emplace_back("mode", "BT601_YUV2BGR_YU12");
  2403. break;
  2404. default:
  2405. props_.emplace_back("mode", "INVALID");
  2406. break;
  2407. }
  2408. return props_;
  2409. }
  2410. std::string CvtColor_make_name_impl(const OpDef& def_) {
  2411. auto&& op_ = def_.cast_final_safe<CvtColor>();
  2412. static_cast<void>(op_);
  2413. return "CvtColor";
  2414. }
  2415. } // anonymous namespace
  2416. OP_TRAIT_REG(CvtColor, CvtColor)
  2417. .hash(CvtColor_hash_impl)
  2418. .is_same_st(CvtColor_is_same_st_impl)
  2419. .props(CvtColor_props_impl)
  2420. .make_name(CvtColor_make_name_impl);
  2421. MGB_DYN_TYPE_OBJ_FINAL_IMPL(DeformableConv);
  2422. namespace {
  2423. size_t DeformableConv_hash_impl(const OpDef& def_) {
  2424. auto&& op_ = def_.cast_final_safe<DeformableConv>();
  2425. static_cast<void>(op_);
  2426. size_t val = mgb::hash(op_.dyn_typeinfo());
  2427. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode));
  2428. val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_h));
  2429. val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_w));
  2430. val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_h));
  2431. val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_w));
  2432. val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_h));
  2433. val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_w));
  2434. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.sparse));
  2435. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format));
  2436. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.compute_mode));
  2437. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.strategy));
  2438. val = mgb::hash_pair_combine(val, mgb::hash(op_.workspace_limit));
  2439. return val;
  2440. }
  2441. bool DeformableConv_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  2442. auto &&a_ = lhs_.cast_final_safe<DeformableConv>(),
  2443. &&b_ = rhs_.cast_final_safe<DeformableConv>();
  2444. static_cast<void>(a_);
  2445. static_cast<void>(b_);
  2446. if (a_.mode != b_.mode) return false;
  2447. if (a_.pad_h != b_.pad_h) return false;
  2448. if (a_.pad_w != b_.pad_w) return false;
  2449. if (a_.stride_h != b_.stride_h) return false;
  2450. if (a_.stride_w != b_.stride_w) return false;
  2451. if (a_.dilate_h != b_.dilate_h) return false;
  2452. if (a_.dilate_w != b_.dilate_w) return false;
  2453. if (a_.sparse != b_.sparse) return false;
  2454. if (a_.format != b_.format) return false;
  2455. if (a_.compute_mode != b_.compute_mode) return false;
  2456. if (a_.strategy != b_.strategy) return false;
  2457. if (a_.workspace_limit != b_.workspace_limit) return false;
  2458. return true;
  2459. }
  2460. std::vector<std::pair<const char*, std::string>> DeformableConv_props_impl(const OpDef& def_) {
  2461. auto&& op_ = def_.cast_final_safe<DeformableConv>();
  2462. static_cast<void>(op_);
  2463. std::vector<std::pair<const char*, std::string>> props_;
  2464. switch (op_.mode){
  2465. case DeformableConv::Mode::CROSS_CORRELATION:
  2466. props_.emplace_back("mode", "CROSS_CORRELATION");
  2467. break;
  2468. case DeformableConv::Mode::CONVOLUTION:
  2469. props_.emplace_back("mode", "CONVOLUTION");
  2470. break;
  2471. default:
  2472. props_.emplace_back("mode", "INVALID");
  2473. break;
  2474. }
  2475. props_.emplace_back("pad_h", std::to_string(op_.pad_h));
  2476. props_.emplace_back("pad_w", std::to_string(op_.pad_w));
  2477. props_.emplace_back("stride_h", std::to_string(op_.stride_h));
  2478. props_.emplace_back("stride_w", std::to_string(op_.stride_w));
  2479. props_.emplace_back("dilate_h", std::to_string(op_.dilate_h));
  2480. props_.emplace_back("dilate_w", std::to_string(op_.dilate_w));
  2481. switch (op_.sparse){
  2482. case DeformableConv::Sparse::DENSE:
  2483. props_.emplace_back("sparse", "DENSE");
  2484. break;
  2485. case DeformableConv::Sparse::GROUP:
  2486. props_.emplace_back("sparse", "GROUP");
  2487. break;
  2488. default:
  2489. props_.emplace_back("sparse", "INVALID");
  2490. break;
  2491. }
  2492. switch (op_.format){
  2493. case DeformableConv::Format::NCHW:
  2494. props_.emplace_back("format", "NCHW");
  2495. break;
  2496. case DeformableConv::Format::NHWC:
  2497. props_.emplace_back("format", "NHWC");
  2498. break;
  2499. case DeformableConv::Format::NHWCD4:
  2500. props_.emplace_back("format", "NHWCD4");
  2501. break;
  2502. case DeformableConv::Format::NCHW4:
  2503. props_.emplace_back("format", "NCHW4");
  2504. break;
  2505. case DeformableConv::Format::NCHW8:
  2506. props_.emplace_back("format", "NCHW8");
  2507. break;
  2508. case DeformableConv::Format::NCHW32:
  2509. props_.emplace_back("format", "NCHW32");
  2510. break;
  2511. case DeformableConv::Format::NCHW88:
  2512. props_.emplace_back("format", "NCHW88");
  2513. break;
  2514. case DeformableConv::Format::NCHW44:
  2515. props_.emplace_back("format", "NCHW44");
  2516. break;
  2517. case DeformableConv::Format::NCHW44_DOT:
  2518. props_.emplace_back("format", "NCHW44_DOT");
  2519. break;
  2520. case DeformableConv::Format::NCHW4_NCHW32:
  2521. props_.emplace_back("format", "NCHW4_NCHW32");
  2522. break;
  2523. case DeformableConv::Format::NCHW32_NCHW4:
  2524. props_.emplace_back("format", "NCHW32_NCHW4");
  2525. break;
  2526. case DeformableConv::Format::NCHW4_NCHW:
  2527. props_.emplace_back("format", "NCHW4_NCHW");
  2528. break;
  2529. case DeformableConv::Format::NHWC_NCHW:
  2530. props_.emplace_back("format", "NHWC_NCHW");
  2531. break;
  2532. case DeformableConv::Format::NHWC_NCHW4_IC_SMALL:
  2533. props_.emplace_back("format", "NHWC_NCHW4_IC_SMALL");
  2534. break;
  2535. case DeformableConv::Format::NCHW_NCHW4_IC_SMALL:
  2536. props_.emplace_back("format", "NCHW_NCHW4_IC_SMALL");
  2537. break;
  2538. case DeformableConv::Format::CHWN4:
  2539. props_.emplace_back("format", "CHWN4");
  2540. break;
  2541. case DeformableConv::Format::NCHW64:
  2542. props_.emplace_back("format", "NCHW64");
  2543. break;
  2544. case DeformableConv::Format::NCHW4_NHWC:
  2545. props_.emplace_back("format", "NCHW4_NHWC");
  2546. break;
  2547. default:
  2548. props_.emplace_back("format", "INVALID");
  2549. break;
  2550. }
  2551. switch (op_.compute_mode){
  2552. case DeformableConv::ComputeMode::DEFAULT:
  2553. props_.emplace_back("compute_mode", "DEFAULT");
  2554. break;
  2555. case DeformableConv::ComputeMode::FLOAT32:
  2556. props_.emplace_back("compute_mode", "FLOAT32");
  2557. break;
  2558. default:
  2559. props_.emplace_back("compute_mode", "INVALID");
  2560. break;
  2561. }
  2562. switch (op_.strategy){
  2563. case DeformableConv::Strategy::HEURISTIC:
  2564. props_.emplace_back("strategy", "HEURISTIC");
  2565. break;
  2566. case DeformableConv::Strategy::PROFILE:
  2567. props_.emplace_back("strategy", "PROFILE");
  2568. break;
  2569. case DeformableConv::Strategy::REPRODUCIBLE:
  2570. props_.emplace_back("strategy", "REPRODUCIBLE");
  2571. break;
  2572. case DeformableConv::Strategy::OPTIMIZED:
  2573. props_.emplace_back("strategy", "OPTIMIZED");
  2574. break;
  2575. default:
  2576. props_.emplace_back("strategy", "INVALID");
  2577. break;
  2578. }
  2579. props_.emplace_back("workspace_limit", std::to_string(op_.workspace_limit));
  2580. return props_;
  2581. }
  2582. std::string DeformableConv_make_name_impl(const OpDef& def_) {
  2583. auto&& op_ = def_.cast_final_safe<DeformableConv>();
  2584. static_cast<void>(op_);
  2585. return "DeformableConv";
  2586. }
  2587. } // anonymous namespace
  2588. OP_TRAIT_REG(DeformableConv, DeformableConv)
  2589. .hash(DeformableConv_hash_impl)
  2590. .is_same_st(DeformableConv_is_same_st_impl)
  2591. .props(DeformableConv_props_impl)
  2592. .make_name(DeformableConv_make_name_impl);
  2593. MGB_DYN_TYPE_OBJ_FINAL_IMPL(DeformablePSROIPooling);
  2594. namespace {
  2595. size_t DeformablePSROIPooling_hash_impl(const OpDef& def_) {
  2596. auto&& op_ = def_.cast_final_safe<DeformablePSROIPooling>();
  2597. static_cast<void>(op_);
  2598. size_t val = mgb::hash(op_.dyn_typeinfo());
  2599. val = mgb::hash_pair_combine(val, mgb::hash(op_.no_trans));
  2600. val = mgb::hash_pair_combine(val, mgb::hash(op_.spatial_scale));
  2601. val = mgb::hash_pair_combine(val, mgb::hash(op_.trans_std));
  2602. val = mgb::hash_pair_combine(val, mgb::hash(op_.pooled_h));
  2603. val = mgb::hash_pair_combine(val, mgb::hash(op_.pooled_w));
  2604. val = mgb::hash_pair_combine(val, mgb::hash(op_.part_size));
  2605. val = mgb::hash_pair_combine(val, mgb::hash(op_.sample_per_part));
  2606. return val;
  2607. }
  2608. bool DeformablePSROIPooling_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  2609. auto &&a_ = lhs_.cast_final_safe<DeformablePSROIPooling>(),
  2610. &&b_ = rhs_.cast_final_safe<DeformablePSROIPooling>();
  2611. static_cast<void>(a_);
  2612. static_cast<void>(b_);
  2613. if (a_.no_trans != b_.no_trans) return false;
  2614. if (a_.spatial_scale != b_.spatial_scale) return false;
  2615. if (a_.trans_std != b_.trans_std) return false;
  2616. if (a_.pooled_h != b_.pooled_h) return false;
  2617. if (a_.pooled_w != b_.pooled_w) return false;
  2618. if (a_.part_size != b_.part_size) return false;
  2619. if (a_.sample_per_part != b_.sample_per_part) return false;
  2620. return true;
  2621. }
  2622. std::vector<std::pair<const char*, std::string>> DeformablePSROIPooling_props_impl(const OpDef& def_) {
  2623. auto&& op_ = def_.cast_final_safe<DeformablePSROIPooling>();
  2624. static_cast<void>(op_);
  2625. std::vector<std::pair<const char*, std::string>> props_;
  2626. props_.emplace_back("no_trans", std::to_string(op_.no_trans));
  2627. props_.emplace_back("spatial_scale", std::to_string(op_.spatial_scale));
  2628. props_.emplace_back("trans_std", std::to_string(op_.trans_std));
  2629. props_.emplace_back("pooled_h", std::to_string(op_.pooled_h));
  2630. props_.emplace_back("pooled_w", std::to_string(op_.pooled_w));
  2631. props_.emplace_back("part_size", std::to_string(op_.part_size));
  2632. props_.emplace_back("sample_per_part", std::to_string(op_.sample_per_part));
  2633. return props_;
  2634. }
  2635. std::string DeformablePSROIPooling_make_name_impl(const OpDef& def_) {
  2636. auto&& op_ = def_.cast_final_safe<DeformablePSROIPooling>();
  2637. static_cast<void>(op_);
  2638. return "DeformablePSROIPooling";
  2639. }
  2640. } // anonymous namespace
  2641. OP_TRAIT_REG(DeformablePSROIPooling, DeformablePSROIPooling)
  2642. .hash(DeformablePSROIPooling_hash_impl)
  2643. .is_same_st(DeformablePSROIPooling_is_same_st_impl)
  2644. .props(DeformablePSROIPooling_props_impl)
  2645. .make_name(DeformablePSROIPooling_make_name_impl);
  2646. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Diag);
  2647. namespace {
  2648. size_t Diag_hash_impl(const OpDef& def_) {
  2649. auto&& op_ = def_.cast_final_safe<Diag>();
  2650. static_cast<void>(op_);
  2651. size_t val = mgb::hash(op_.dyn_typeinfo());
  2652. val = mgb::hash_pair_combine(val, mgb::hash(op_.k));
  2653. return val;
  2654. }
  2655. bool Diag_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  2656. auto &&a_ = lhs_.cast_final_safe<Diag>(),
  2657. &&b_ = rhs_.cast_final_safe<Diag>();
  2658. static_cast<void>(a_);
  2659. static_cast<void>(b_);
  2660. if (a_.k != b_.k) return false;
  2661. return true;
  2662. }
  2663. std::vector<std::pair<const char*, std::string>> Diag_props_impl(const OpDef& def_) {
  2664. auto&& op_ = def_.cast_final_safe<Diag>();
  2665. static_cast<void>(op_);
  2666. std::vector<std::pair<const char*, std::string>> props_;
  2667. props_.emplace_back("k", std::to_string(op_.k));
  2668. return props_;
  2669. }
  2670. std::string Diag_make_name_impl(const OpDef& def_) {
  2671. auto&& op_ = def_.cast_final_safe<Diag>();
  2672. static_cast<void>(op_);
  2673. return "Diag";
  2674. }
  2675. } // anonymous namespace
  2676. OP_TRAIT_REG(Diag, Diag)
  2677. .hash(Diag_hash_impl)
  2678. .is_same_st(Diag_is_same_st_impl)
  2679. .props(Diag_props_impl)
  2680. .make_name(Diag_make_name_impl);
  2681. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Dimshuffle);
  2682. namespace {
  2683. size_t Dimshuffle_hash_impl(const OpDef& def_) {
  2684. auto&& op_ = def_.cast_final_safe<Dimshuffle>();
  2685. static_cast<void>(op_);
  2686. size_t val = mgb::hash(op_.dyn_typeinfo());
  2687. val = mgb::hash_pair_combine(val, mgb::hash(op_.pattern));
  2688. return val;
  2689. }
  2690. bool Dimshuffle_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  2691. auto &&a_ = lhs_.cast_final_safe<Dimshuffle>(),
  2692. &&b_ = rhs_.cast_final_safe<Dimshuffle>();
  2693. static_cast<void>(a_);
  2694. static_cast<void>(b_);
  2695. if (a_.pattern != b_.pattern) return false;
  2696. return true;
  2697. }
  2698. std::vector<std::pair<const char*, std::string>> Dimshuffle_props_impl(const OpDef& def_) {
  2699. auto&& op_ = def_.cast_final_safe<Dimshuffle>();
  2700. static_cast<void>(op_);
  2701. std::vector<std::pair<const char*, std::string>> props_;
  2702. props_.emplace_back("pattern", "{std::vector}");
  2703. return props_;
  2704. }
  2705. std::string Dimshuffle_make_name_impl(const OpDef& def_) {
  2706. auto&& op_ = def_.cast_final_safe<Dimshuffle>();
  2707. static_cast<void>(op_);
  2708. return "Dimshuffle";
  2709. }
  2710. } // anonymous namespace
  2711. OP_TRAIT_REG(Dimshuffle, Dimshuffle)
  2712. .hash(Dimshuffle_hash_impl)
  2713. .is_same_st(Dimshuffle_is_same_st_impl)
  2714. .props(Dimshuffle_props_impl)
  2715. .make_name(Dimshuffle_make_name_impl);
  2716. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Dot);
  2717. namespace {
  2718. size_t Dot_hash_impl(const OpDef& def_) {
  2719. auto&& op_ = def_.cast_final_safe<Dot>();
  2720. static_cast<void>(op_);
  2721. size_t val = mgb::hash(op_.dyn_typeinfo());
  2722. return val;
  2723. }
  2724. bool Dot_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  2725. auto &&a_ = lhs_.cast_final_safe<Dot>(),
  2726. &&b_ = rhs_.cast_final_safe<Dot>();
  2727. static_cast<void>(a_);
  2728. static_cast<void>(b_);
  2729. return true;
  2730. }
  2731. std::vector<std::pair<const char*, std::string>> Dot_props_impl(const OpDef& def_) {
  2732. auto&& op_ = def_.cast_final_safe<Dot>();
  2733. static_cast<void>(op_);
  2734. std::vector<std::pair<const char*, std::string>> props_;
  2735. return props_;
  2736. }
  2737. std::string Dot_make_name_impl(const OpDef& def_) {
  2738. auto&& op_ = def_.cast_final_safe<Dot>();
  2739. static_cast<void>(op_);
  2740. return "Dot";
  2741. }
  2742. } // anonymous namespace
  2743. OP_TRAIT_REG(Dot, Dot)
  2744. .hash(Dot_hash_impl)
  2745. .is_same_st(Dot_is_same_st_impl)
  2746. .props(Dot_props_impl)
  2747. .make_name(Dot_make_name_impl);
  2748. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Dropout);
  2749. namespace {
  2750. size_t Dropout_hash_impl(const OpDef& def_) {
  2751. auto&& op_ = def_.cast_final_safe<Dropout>();
  2752. static_cast<void>(op_);
  2753. return mgb::hash_pair_combine(
  2754. mgb::hash(op_.dyn_typeinfo()),
  2755. mgb::hash_pair_combine(
  2756. mgb::hash(op_.drop_prob),
  2757. mgb::hash(op_.handle))
  2758. );
  2759. }
  2760. bool Dropout_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  2761. auto &&a_ = lhs_.cast_final_safe<Dropout>(),
  2762. &&b_ = rhs_.cast_final_safe<Dropout>();
  2763. static_cast<void>(a_);
  2764. static_cast<void>(b_);
  2765. return a_.handle == b_.handle && a_.drop_prob == b_.drop_prob;}
  2766. std::vector<std::pair<const char*, std::string>> Dropout_props_impl(const OpDef& def_) {
  2767. auto&& op_ = def_.cast_final_safe<Dropout>();
  2768. static_cast<void>(op_);
  2769. std::vector<std::pair<const char*, std::string>> props_;
  2770. props_.emplace_back("drop_prob", std::to_string(op_.drop_prob));
  2771. props_.emplace_back("seed", std::to_string(op_.seed));
  2772. props_.emplace_back("handle", std::to_string(op_.handle));
  2773. return props_;
  2774. }
  2775. std::string Dropout_make_name_impl(const OpDef& def_) {
  2776. auto&& op_ = def_.cast_final_safe<Dropout>();
  2777. static_cast<void>(op_);
  2778. return "Dropout";
  2779. }
  2780. } // anonymous namespace
  2781. OP_TRAIT_REG(Dropout, Dropout)
  2782. .hash(Dropout_hash_impl)
  2783. .is_same_st(Dropout_is_same_st_impl)
  2784. .props(Dropout_props_impl)
  2785. .make_name(Dropout_make_name_impl);
  2786. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Elemwise);
  2787. namespace {
  2788. size_t Elemwise_hash_impl(const OpDef& def_) {
  2789. auto&& op_ = def_.cast_final_safe<Elemwise>();
  2790. static_cast<void>(op_);
  2791. size_t val = mgb::hash(op_.dyn_typeinfo());
  2792. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode));
  2793. return val;
  2794. }
  2795. bool Elemwise_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  2796. auto &&a_ = lhs_.cast_final_safe<Elemwise>(),
  2797. &&b_ = rhs_.cast_final_safe<Elemwise>();
  2798. static_cast<void>(a_);
  2799. static_cast<void>(b_);
  2800. if (a_.mode != b_.mode) return false;
  2801. return true;
  2802. }
  2803. std::vector<std::pair<const char*, std::string>> Elemwise_props_impl(const OpDef& def_) {
  2804. auto&& op_ = def_.cast_final_safe<Elemwise>();
  2805. static_cast<void>(op_);
  2806. std::vector<std::pair<const char*, std::string>> props_;
  2807. switch (op_.mode){
  2808. case Elemwise::Mode::RELU:
  2809. props_.emplace_back("mode", "RELU");
  2810. break;
  2811. case Elemwise::Mode::ABS:
  2812. props_.emplace_back("mode", "ABS");
  2813. break;
  2814. case Elemwise::Mode::ACOS:
  2815. props_.emplace_back("mode", "ACOS");
  2816. break;
  2817. case Elemwise::Mode::ASIN:
  2818. props_.emplace_back("mode", "ASIN");
  2819. break;
  2820. case Elemwise::Mode::CEIL:
  2821. props_.emplace_back("mode", "CEIL");
  2822. break;
  2823. case Elemwise::Mode::COS:
  2824. props_.emplace_back("mode", "COS");
  2825. break;
  2826. case Elemwise::Mode::EXP:
  2827. props_.emplace_back("mode", "EXP");
  2828. break;
  2829. case Elemwise::Mode::EXPM1:
  2830. props_.emplace_back("mode", "EXPM1");
  2831. break;
  2832. case Elemwise::Mode::FLOOR:
  2833. props_.emplace_back("mode", "FLOOR");
  2834. break;
  2835. case Elemwise::Mode::LOG:
  2836. props_.emplace_back("mode", "LOG");
  2837. break;
  2838. case Elemwise::Mode::LOG1P:
  2839. props_.emplace_back("mode", "LOG1P");
  2840. break;
  2841. case Elemwise::Mode::NEGATE:
  2842. props_.emplace_back("mode", "NEGATE");
  2843. break;
  2844. case Elemwise::Mode::SIGMOID:
  2845. props_.emplace_back("mode", "SIGMOID");
  2846. break;
  2847. case Elemwise::Mode::SIN:
  2848. props_.emplace_back("mode", "SIN");
  2849. break;
  2850. case Elemwise::Mode::TANH:
  2851. props_.emplace_back("mode", "TANH");
  2852. break;
  2853. case Elemwise::Mode::ABS_GRAD:
  2854. props_.emplace_back("mode", "ABS_GRAD");
  2855. break;
  2856. case Elemwise::Mode::ADD:
  2857. props_.emplace_back("mode", "ADD");
  2858. break;
  2859. case Elemwise::Mode::FLOOR_DIV:
  2860. props_.emplace_back("mode", "FLOOR_DIV");
  2861. break;
  2862. case Elemwise::Mode::MAX:
  2863. props_.emplace_back("mode", "MAX");
  2864. break;
  2865. case Elemwise::Mode::MIN:
  2866. props_.emplace_back("mode", "MIN");
  2867. break;
  2868. case Elemwise::Mode::MOD:
  2869. props_.emplace_back("mode", "MOD");
  2870. break;
  2871. case Elemwise::Mode::MUL:
  2872. props_.emplace_back("mode", "MUL");
  2873. break;
  2874. case Elemwise::Mode::POW:
  2875. props_.emplace_back("mode", "POW");
  2876. break;
  2877. case Elemwise::Mode::SIGMOID_GRAD:
  2878. props_.emplace_back("mode", "SIGMOID_GRAD");
  2879. break;
  2880. case Elemwise::Mode::SUB:
  2881. props_.emplace_back("mode", "SUB");
  2882. break;
  2883. case Elemwise::Mode::SWITCH_GT0:
  2884. props_.emplace_back("mode", "SWITCH_GT0");
  2885. break;
  2886. case Elemwise::Mode::TANH_GRAD:
  2887. props_.emplace_back("mode", "TANH_GRAD");
  2888. break;
  2889. case Elemwise::Mode::TRUE_DIV:
  2890. props_.emplace_back("mode", "TRUE_DIV");
  2891. break;
  2892. case Elemwise::Mode::LOG_SUM_EXP:
  2893. props_.emplace_back("mode", "LOG_SUM_EXP");
  2894. break;
  2895. case Elemwise::Mode::LT:
  2896. props_.emplace_back("mode", "LT");
  2897. break;
  2898. case Elemwise::Mode::LEQ:
  2899. props_.emplace_back("mode", "LEQ");
  2900. break;
  2901. case Elemwise::Mode::EQ:
  2902. props_.emplace_back("mode", "EQ");
  2903. break;
  2904. case Elemwise::Mode::SHL:
  2905. props_.emplace_back("mode", "SHL");
  2906. break;
  2907. case Elemwise::Mode::SHR:
  2908. props_.emplace_back("mode", "SHR");
  2909. break;
  2910. case Elemwise::Mode::COND_LEQ_MOV:
  2911. props_.emplace_back("mode", "COND_LEQ_MOV");
  2912. break;
  2913. case Elemwise::Mode::FUSE_MUL_ADD3:
  2914. props_.emplace_back("mode", "FUSE_MUL_ADD3");
  2915. break;
  2916. case Elemwise::Mode::FUSE_MUL_ADD4:
  2917. props_.emplace_back("mode", "FUSE_MUL_ADD4");
  2918. break;
  2919. case Elemwise::Mode::FUSE_ADD_RELU:
  2920. props_.emplace_back("mode", "FUSE_ADD_RELU");
  2921. break;
  2922. case Elemwise::Mode::FUSE_ADD_SIGMOID:
  2923. props_.emplace_back("mode", "FUSE_ADD_SIGMOID");
  2924. break;
  2925. case Elemwise::Mode::FUSE_ADD_TANH:
  2926. props_.emplace_back("mode", "FUSE_ADD_TANH");
  2927. break;
  2928. case Elemwise::Mode::FAST_TANH:
  2929. props_.emplace_back("mode", "FAST_TANH");
  2930. break;
  2931. case Elemwise::Mode::FAST_TANH_GRAD:
  2932. props_.emplace_back("mode", "FAST_TANH_GRAD");
  2933. break;
  2934. case Elemwise::Mode::ROUND:
  2935. props_.emplace_back("mode", "ROUND");
  2936. break;
  2937. case Elemwise::Mode::RMULH:
  2938. props_.emplace_back("mode", "RMULH");
  2939. break;
  2940. case Elemwise::Mode::ATAN2:
  2941. props_.emplace_back("mode", "ATAN2");
  2942. break;
  2943. case Elemwise::Mode::ERF:
  2944. props_.emplace_back("mode", "ERF");
  2945. break;
  2946. case Elemwise::Mode::ERFINV:
  2947. props_.emplace_back("mode", "ERFINV");
  2948. break;
  2949. case Elemwise::Mode::ERFC:
  2950. props_.emplace_back("mode", "ERFC");
  2951. break;
  2952. case Elemwise::Mode::ERFCINV:
  2953. props_.emplace_back("mode", "ERFCINV");
  2954. break;
  2955. case Elemwise::Mode::H_SWISH:
  2956. props_.emplace_back("mode", "H_SWISH");
  2957. break;
  2958. case Elemwise::Mode::H_SWISH_GRAD:
  2959. props_.emplace_back("mode", "H_SWISH_GRAD");
  2960. break;
  2961. case Elemwise::Mode::FUSE_ADD_H_SWISH:
  2962. props_.emplace_back("mode", "FUSE_ADD_H_SWISH");
  2963. break;
  2964. case Elemwise::Mode::NOT:
  2965. props_.emplace_back("mode", "NOT");
  2966. break;
  2967. case Elemwise::Mode::AND:
  2968. props_.emplace_back("mode", "AND");
  2969. break;
  2970. case Elemwise::Mode::OR:
  2971. props_.emplace_back("mode", "OR");
  2972. break;
  2973. case Elemwise::Mode::XOR:
  2974. props_.emplace_back("mode", "XOR");
  2975. break;
  2976. case Elemwise::Mode::SILU:
  2977. props_.emplace_back("mode", "SILU");
  2978. break;
  2979. case Elemwise::Mode::SILU_GRAD:
  2980. props_.emplace_back("mode", "SILU_GRAD");
  2981. break;
  2982. case Elemwise::Mode::GELU:
  2983. props_.emplace_back("mode", "GELU");
  2984. break;
  2985. case Elemwise::Mode::GELU_GRAD:
  2986. props_.emplace_back("mode", "GELU_GRAD");
  2987. break;
  2988. case Elemwise::Mode::COND_LT_MOV:
  2989. props_.emplace_back("mode", "COND_LT_MOV");
  2990. break;
  2991. case Elemwise::Mode::NEQ:
  2992. props_.emplace_back("mode", "NEQ");
  2993. break;
  2994. case Elemwise::Mode::ISNAN:
  2995. props_.emplace_back("mode", "ISNAN");
  2996. break;
  2997. case Elemwise::Mode::ISINF:
  2998. props_.emplace_back("mode", "ISINF");
  2999. break;
  3000. default:
  3001. props_.emplace_back("mode", "INVALID");
  3002. break;
  3003. }
  3004. return props_;
  3005. }
  3006. std::string Elemwise_make_name_impl(const OpDef& def_) {
  3007. auto&& op_ = def_.cast_final_safe<Elemwise>();
  3008. static_cast<void>(op_);
  3009. return to_string(op_.mode);
  3010. }
  3011. } // anonymous namespace
  3012. OP_TRAIT_REG(Elemwise, Elemwise)
  3013. .hash(Elemwise_hash_impl)
  3014. .is_same_st(Elemwise_is_same_st_impl)
  3015. .props(Elemwise_props_impl)
  3016. .make_name(Elemwise_make_name_impl);
  3017. MGB_DYN_TYPE_OBJ_FINAL_IMPL(ElemwiseMultiType);
  3018. namespace {
  3019. size_t ElemwiseMultiType_hash_impl(const OpDef& def_) {
  3020. auto&& op_ = def_.cast_final_safe<ElemwiseMultiType>();
  3021. static_cast<void>(op_);
  3022. size_t val = mgb::hash(op_.dyn_typeinfo());
  3023. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode));
  3024. val = mgb::hash_pair_combine(val, mgb::hash(op_.dtype.handle()));
  3025. return val;
  3026. }
  3027. bool ElemwiseMultiType_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3028. auto &&a_ = lhs_.cast_final_safe<ElemwiseMultiType>(),
  3029. &&b_ = rhs_.cast_final_safe<ElemwiseMultiType>();
  3030. static_cast<void>(a_);
  3031. static_cast<void>(b_);
  3032. if (a_.mode != b_.mode) return false;
  3033. if (a_.dtype != b_.dtype) return false;
  3034. return true;
  3035. }
  3036. std::vector<std::pair<const char*, std::string>> ElemwiseMultiType_props_impl(const OpDef& def_) {
  3037. auto&& op_ = def_.cast_final_safe<ElemwiseMultiType>();
  3038. static_cast<void>(op_);
  3039. std::vector<std::pair<const char*, std::string>> props_;
  3040. switch (op_.mode){
  3041. case ElemwiseMultiType::Mode::FUSE_MUL_ADD3_INT16x32x32x32:
  3042. props_.emplace_back("mode", "FUSE_MUL_ADD3_INT16x32x32x32");
  3043. break;
  3044. case ElemwiseMultiType::Mode::FUSE_MUL_ADD3_IXxF32xF32xI8:
  3045. props_.emplace_back("mode", "FUSE_MUL_ADD3_IXxF32xF32xI8");
  3046. break;
  3047. case ElemwiseMultiType::Mode::ROUND_SHR_SATURATE_IXxI8xI8:
  3048. props_.emplace_back("mode", "ROUND_SHR_SATURATE_IXxI8xI8");
  3049. break;
  3050. case ElemwiseMultiType::Mode::FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT16x16x16x8:
  3051. props_.emplace_back("mode", "FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT16x16x16x8");
  3052. break;
  3053. case ElemwiseMultiType::Mode::FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT32x32x32x8:
  3054. props_.emplace_back("mode", "FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT32x32x32x8");
  3055. break;
  3056. case ElemwiseMultiType::Mode::ROUND_SHR_SATURATE_IXxI8xI16:
  3057. props_.emplace_back("mode", "ROUND_SHR_SATURATE_IXxI8xI16");
  3058. break;
  3059. case ElemwiseMultiType::Mode::QADD:
  3060. props_.emplace_back("mode", "QADD");
  3061. break;
  3062. case ElemwiseMultiType::Mode::QFUSE_ADD_RELU:
  3063. props_.emplace_back("mode", "QFUSE_ADD_RELU");
  3064. break;
  3065. case ElemwiseMultiType::Mode::QMUL:
  3066. props_.emplace_back("mode", "QMUL");
  3067. break;
  3068. case ElemwiseMultiType::Mode::QMIN:
  3069. props_.emplace_back("mode", "QMIN");
  3070. break;
  3071. case ElemwiseMultiType::Mode::QMAX:
  3072. props_.emplace_back("mode", "QMAX");
  3073. break;
  3074. case ElemwiseMultiType::Mode::QSUB:
  3075. props_.emplace_back("mode", "QSUB");
  3076. break;
  3077. case ElemwiseMultiType::Mode::QTRUE_DIV:
  3078. props_.emplace_back("mode", "QTRUE_DIV");
  3079. break;
  3080. case ElemwiseMultiType::Mode::QFUSE_ADD_SIGMOID:
  3081. props_.emplace_back("mode", "QFUSE_ADD_SIGMOID");
  3082. break;
  3083. case ElemwiseMultiType::Mode::QFUSE_ADD_TANH:
  3084. props_.emplace_back("mode", "QFUSE_ADD_TANH");
  3085. break;
  3086. case ElemwiseMultiType::Mode::QRELU:
  3087. props_.emplace_back("mode", "QRELU");
  3088. break;
  3089. case ElemwiseMultiType::Mode::QABS:
  3090. props_.emplace_back("mode", "QABS");
  3091. break;
  3092. case ElemwiseMultiType::Mode::QSIGMOID:
  3093. props_.emplace_back("mode", "QSIGMOID");
  3094. break;
  3095. case ElemwiseMultiType::Mode::QEXP:
  3096. props_.emplace_back("mode", "QEXP");
  3097. break;
  3098. case ElemwiseMultiType::Mode::QTANH:
  3099. props_.emplace_back("mode", "QTANH");
  3100. break;
  3101. case ElemwiseMultiType::Mode::QFUSE_MUL_ADD3:
  3102. props_.emplace_back("mode", "QFUSE_MUL_ADD3");
  3103. break;
  3104. case ElemwiseMultiType::Mode::QFAST_TANH:
  3105. props_.emplace_back("mode", "QFAST_TANH");
  3106. break;
  3107. case ElemwiseMultiType::Mode::QNEGATE:
  3108. props_.emplace_back("mode", "QNEGATE");
  3109. break;
  3110. case ElemwiseMultiType::Mode::QACOS:
  3111. props_.emplace_back("mode", "QACOS");
  3112. break;
  3113. case ElemwiseMultiType::Mode::QASIN:
  3114. props_.emplace_back("mode", "QASIN");
  3115. break;
  3116. case ElemwiseMultiType::Mode::QCEIL:
  3117. props_.emplace_back("mode", "QCEIL");
  3118. break;
  3119. case ElemwiseMultiType::Mode::QCOS:
  3120. props_.emplace_back("mode", "QCOS");
  3121. break;
  3122. case ElemwiseMultiType::Mode::QEXPM1:
  3123. props_.emplace_back("mode", "QEXPM1");
  3124. break;
  3125. case ElemwiseMultiType::Mode::QFLOOR:
  3126. props_.emplace_back("mode", "QFLOOR");
  3127. break;
  3128. case ElemwiseMultiType::Mode::QLOG:
  3129. props_.emplace_back("mode", "QLOG");
  3130. break;
  3131. case ElemwiseMultiType::Mode::QLOG1P:
  3132. props_.emplace_back("mode", "QLOG1P");
  3133. break;
  3134. case ElemwiseMultiType::Mode::QSIN:
  3135. props_.emplace_back("mode", "QSIN");
  3136. break;
  3137. case ElemwiseMultiType::Mode::QROUND:
  3138. props_.emplace_back("mode", "QROUND");
  3139. break;
  3140. case ElemwiseMultiType::Mode::QERF:
  3141. props_.emplace_back("mode", "QERF");
  3142. break;
  3143. case ElemwiseMultiType::Mode::QERFINV:
  3144. props_.emplace_back("mode", "QERFINV");
  3145. break;
  3146. case ElemwiseMultiType::Mode::QERFC:
  3147. props_.emplace_back("mode", "QERFC");
  3148. break;
  3149. case ElemwiseMultiType::Mode::QERFCINV:
  3150. props_.emplace_back("mode", "QERFCINV");
  3151. break;
  3152. case ElemwiseMultiType::Mode::QABS_GRAD:
  3153. props_.emplace_back("mode", "QABS_GRAD");
  3154. break;
  3155. case ElemwiseMultiType::Mode::QFLOOR_DIV:
  3156. props_.emplace_back("mode", "QFLOOR_DIV");
  3157. break;
  3158. case ElemwiseMultiType::Mode::QMOD:
  3159. props_.emplace_back("mode", "QMOD");
  3160. break;
  3161. case ElemwiseMultiType::Mode::QSIGMOID_GRAD:
  3162. props_.emplace_back("mode", "QSIGMOID_GRAD");
  3163. break;
  3164. case ElemwiseMultiType::Mode::QSWITCH_GT0:
  3165. props_.emplace_back("mode", "QSWITCH_GT0");
  3166. break;
  3167. case ElemwiseMultiType::Mode::QTANH_GRAD:
  3168. props_.emplace_back("mode", "QTANH_GRAD");
  3169. break;
  3170. case ElemwiseMultiType::Mode::QLT:
  3171. props_.emplace_back("mode", "QLT");
  3172. break;
  3173. case ElemwiseMultiType::Mode::QLEQ:
  3174. props_.emplace_back("mode", "QLEQ");
  3175. break;
  3176. case ElemwiseMultiType::Mode::QEQ:
  3177. props_.emplace_back("mode", "QEQ");
  3178. break;
  3179. case ElemwiseMultiType::Mode::QPOW:
  3180. props_.emplace_back("mode", "QPOW");
  3181. break;
  3182. case ElemwiseMultiType::Mode::QLOG_SUM_EXP:
  3183. props_.emplace_back("mode", "QLOG_SUM_EXP");
  3184. break;
  3185. case ElemwiseMultiType::Mode::QFAST_TANH_GRAD:
  3186. props_.emplace_back("mode", "QFAST_TANH_GRAD");
  3187. break;
  3188. case ElemwiseMultiType::Mode::QATAN2:
  3189. props_.emplace_back("mode", "QATAN2");
  3190. break;
  3191. case ElemwiseMultiType::Mode::QCOND_LEQ_MOV:
  3192. props_.emplace_back("mode", "QCOND_LEQ_MOV");
  3193. break;
  3194. case ElemwiseMultiType::Mode::QH_SWISH:
  3195. props_.emplace_back("mode", "QH_SWISH");
  3196. break;
  3197. case ElemwiseMultiType::Mode::QFUSE_ADD_H_SWISH:
  3198. props_.emplace_back("mode", "QFUSE_ADD_H_SWISH");
  3199. break;
  3200. case ElemwiseMultiType::Mode::QH_SWISH_GRAD:
  3201. props_.emplace_back("mode", "QH_SWISH_GRAD");
  3202. break;
  3203. case ElemwiseMultiType::Mode::FUSE_MUL_ADD3_INT16xF32xF32xF32:
  3204. props_.emplace_back("mode", "FUSE_MUL_ADD3_INT16xF32xF32xF32");
  3205. break;
  3206. case ElemwiseMultiType::Mode::MUL_INT16xF32xF32:
  3207. props_.emplace_back("mode", "MUL_INT16xF32xF32");
  3208. break;
  3209. case ElemwiseMultiType::Mode::FUSE_MUL_ADD3_UINT8xF32xF32xF32:
  3210. props_.emplace_back("mode", "FUSE_MUL_ADD3_UINT8xF32xF32xF32");
  3211. break;
  3212. case ElemwiseMultiType::Mode::QCOND_LT_MOV:
  3213. props_.emplace_back("mode", "QCOND_LT_MOV");
  3214. break;
  3215. case ElemwiseMultiType::Mode::EQ:
  3216. props_.emplace_back("mode", "EQ");
  3217. break;
  3218. case ElemwiseMultiType::Mode::NEQ:
  3219. props_.emplace_back("mode", "NEQ");
  3220. break;
  3221. case ElemwiseMultiType::Mode::LT:
  3222. props_.emplace_back("mode", "LT");
  3223. break;
  3224. case ElemwiseMultiType::Mode::LEQ:
  3225. props_.emplace_back("mode", "LEQ");
  3226. break;
  3227. case ElemwiseMultiType::Mode::ISNAN:
  3228. props_.emplace_back("mode", "ISNAN");
  3229. break;
  3230. case ElemwiseMultiType::Mode::ISINF:
  3231. props_.emplace_back("mode", "ISINF");
  3232. break;
  3233. default:
  3234. props_.emplace_back("mode", "INVALID");
  3235. break;
  3236. }
  3237. props_.emplace_back("dtype", op_.dtype.name());
  3238. return props_;
  3239. }
  3240. std::string ElemwiseMultiType_make_name_impl(const OpDef& def_) {
  3241. auto&& op_ = def_.cast_final_safe<ElemwiseMultiType>();
  3242. static_cast<void>(op_);
  3243. return to_string(op_.mode);
  3244. }
  3245. } // anonymous namespace
  3246. OP_TRAIT_REG(ElemwiseMultiType, ElemwiseMultiType)
  3247. .hash(ElemwiseMultiType_hash_impl)
  3248. .is_same_st(ElemwiseMultiType_is_same_st_impl)
  3249. .props(ElemwiseMultiType_props_impl)
  3250. .make_name(ElemwiseMultiType_make_name_impl);
  3251. MGB_DYN_TYPE_OBJ_FINAL_IMPL(ExternOpr);
  3252. namespace {
  3253. size_t ExternOpr_hash_impl(const OpDef& def_) {
  3254. auto&& op_ = def_.cast_final_safe<ExternOpr>();
  3255. static_cast<void>(op_);
  3256. return mgb::hash_pair_combine(
  3257. mgb::hash(op_.dyn_typeinfo()),
  3258. mgb::hash_pair_combine(
  3259. mgb::hash(op_.name),
  3260. mgb::hash(op_.data))
  3261. );
  3262. }
  3263. bool ExternOpr_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3264. auto &&a_ = lhs_.cast_final_safe<ExternOpr>(),
  3265. &&b_ = rhs_.cast_final_safe<ExternOpr>();
  3266. static_cast<void>(a_);
  3267. static_cast<void>(b_);
  3268. if (a_.output_shapes != b_.output_shapes) return false;
  3269. if (a_.name != b_.name) return false;
  3270. if (a_.data != b_.data) return false;
  3271. if (a_.data_len != b_.data_len) return false;
  3272. if (a_.output_dtypes != b_.output_dtypes) return false;
  3273. return true;
  3274. }
  3275. std::vector<std::pair<const char*, std::string>> ExternOpr_props_impl(const OpDef& def_) {
  3276. auto&& op_ = def_.cast_final_safe<ExternOpr>();
  3277. static_cast<void>(op_);
  3278. std::vector<std::pair<const char*, std::string>> props_;
  3279. props_.emplace_back("output_shapes", "{std::vector}");
  3280. props_.emplace_back("name", op_.name);
  3281. props_.emplace_back("data", op_.data);
  3282. props_.emplace_back("data_len", std::to_string(op_.data_len));
  3283. props_.emplace_back("output_dtypes", "{std::vector}");
  3284. return props_;
  3285. }
  3286. std::string ExternOpr_make_name_impl(const OpDef& def_) {
  3287. auto&& op_ = def_.cast_final_safe<ExternOpr>();
  3288. static_cast<void>(op_);
  3289. return "ExternOpr";
  3290. }
  3291. } // anonymous namespace
  3292. OP_TRAIT_REG(ExternOpr, ExternOpr)
  3293. .hash(ExternOpr_hash_impl)
  3294. .is_same_st(ExternOpr_is_same_st_impl)
  3295. .props(ExternOpr_props_impl)
  3296. .make_name(ExternOpr_make_name_impl);
  3297. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Eye);
  3298. namespace {
  3299. size_t Eye_hash_impl(const OpDef& def_) {
  3300. auto&& op_ = def_.cast_final_safe<Eye>();
  3301. static_cast<void>(op_);
  3302. size_t val = mgb::hash(op_.dyn_typeinfo());
  3303. val = mgb::hash_pair_combine(val, mgb::hash(op_.k));
  3304. val = mgb::hash_pair_combine(val, mgb::hash(op_.dtype.handle()));
  3305. val = mgb::hash_pair_combine(val, mgb::hash(op_.comp_node));
  3306. return val;
  3307. }
  3308. bool Eye_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3309. auto &&a_ = lhs_.cast_final_safe<Eye>(),
  3310. &&b_ = rhs_.cast_final_safe<Eye>();
  3311. static_cast<void>(a_);
  3312. static_cast<void>(b_);
  3313. if (a_.k != b_.k) return false;
  3314. if (a_.dtype != b_.dtype) return false;
  3315. if (a_.comp_node != b_.comp_node) return false;
  3316. return true;
  3317. }
  3318. std::vector<std::pair<const char*, std::string>> Eye_props_impl(const OpDef& def_) {
  3319. auto&& op_ = def_.cast_final_safe<Eye>();
  3320. static_cast<void>(op_);
  3321. std::vector<std::pair<const char*, std::string>> props_;
  3322. props_.emplace_back("k", std::to_string(op_.k));
  3323. props_.emplace_back("dtype", op_.dtype.name());
  3324. props_.emplace_back("comp_node", op_.comp_node.to_string());
  3325. return props_;
  3326. }
  3327. std::string Eye_make_name_impl(const OpDef& def_) {
  3328. auto&& op_ = def_.cast_final_safe<Eye>();
  3329. static_cast<void>(op_);
  3330. return "Eye";
  3331. }
  3332. } // anonymous namespace
  3333. OP_TRAIT_REG(Eye, Eye)
  3334. .hash(Eye_hash_impl)
  3335. .is_same_st(Eye_is_same_st_impl)
  3336. .props(Eye_props_impl)
  3337. .make_name(Eye_make_name_impl);
  3338. MGB_DYN_TYPE_OBJ_FINAL_IMPL(FakeQuant);
  3339. namespace {
  3340. size_t FakeQuant_hash_impl(const OpDef& def_) {
  3341. auto&& op_ = def_.cast_final_safe<FakeQuant>();
  3342. static_cast<void>(op_);
  3343. size_t val = mgb::hash(op_.dyn_typeinfo());
  3344. val = mgb::hash_pair_combine(val, mgb::hash(op_.qmin));
  3345. val = mgb::hash_pair_combine(val, mgb::hash(op_.qmax));
  3346. return val;
  3347. }
  3348. bool FakeQuant_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3349. auto &&a_ = lhs_.cast_final_safe<FakeQuant>(),
  3350. &&b_ = rhs_.cast_final_safe<FakeQuant>();
  3351. static_cast<void>(a_);
  3352. static_cast<void>(b_);
  3353. if (a_.qmin != b_.qmin) return false;
  3354. if (a_.qmax != b_.qmax) return false;
  3355. return true;
  3356. }
  3357. std::vector<std::pair<const char*, std::string>> FakeQuant_props_impl(const OpDef& def_) {
  3358. auto&& op_ = def_.cast_final_safe<FakeQuant>();
  3359. static_cast<void>(op_);
  3360. std::vector<std::pair<const char*, std::string>> props_;
  3361. props_.emplace_back("qmin", std::to_string(op_.qmin));
  3362. props_.emplace_back("qmax", std::to_string(op_.qmax));
  3363. return props_;
  3364. }
  3365. std::string FakeQuant_make_name_impl(const OpDef& def_) {
  3366. auto&& op_ = def_.cast_final_safe<FakeQuant>();
  3367. static_cast<void>(op_);
  3368. return "FakeQuant";
  3369. }
  3370. } // anonymous namespace
  3371. OP_TRAIT_REG(FakeQuant, FakeQuant)
  3372. .hash(FakeQuant_hash_impl)
  3373. .is_same_st(FakeQuant_is_same_st_impl)
  3374. .props(FakeQuant_props_impl)
  3375. .make_name(FakeQuant_make_name_impl);
  3376. MGB_DYN_TYPE_OBJ_FINAL_IMPL(FastpathCopy);
  3377. namespace {
  3378. size_t FastpathCopy_hash_impl(const OpDef& def_) {
  3379. auto&& op_ = def_.cast_final_safe<FastpathCopy>();
  3380. static_cast<void>(op_);
  3381. size_t val = mgb::hash(op_.dyn_typeinfo());
  3382. return val;
  3383. }
  3384. bool FastpathCopy_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3385. auto &&a_ = lhs_.cast_final_safe<FastpathCopy>(),
  3386. &&b_ = rhs_.cast_final_safe<FastpathCopy>();
  3387. static_cast<void>(a_);
  3388. static_cast<void>(b_);
  3389. return true;
  3390. }
  3391. std::vector<std::pair<const char*, std::string>> FastpathCopy_props_impl(const OpDef& def_) {
  3392. auto&& op_ = def_.cast_final_safe<FastpathCopy>();
  3393. static_cast<void>(op_);
  3394. std::vector<std::pair<const char*, std::string>> props_;
  3395. return props_;
  3396. }
  3397. std::string FastpathCopy_make_name_impl(const OpDef& def_) {
  3398. auto&& op_ = def_.cast_final_safe<FastpathCopy>();
  3399. static_cast<void>(op_);
  3400. return "FastpathCopy";
  3401. }
  3402. } // anonymous namespace
  3403. OP_TRAIT_REG(FastpathCopy, FastpathCopy)
  3404. .hash(FastpathCopy_hash_impl)
  3405. .is_same_st(FastpathCopy_is_same_st_impl)
  3406. .props(FastpathCopy_props_impl)
  3407. .make_name(FastpathCopy_make_name_impl);
  3408. MGB_DYN_TYPE_OBJ_FINAL_IMPL(GammaRNG);
  3409. namespace {
  3410. size_t GammaRNG_hash_impl(const OpDef& def_) {
  3411. auto&& op_ = def_.cast_final_safe<GammaRNG>();
  3412. static_cast<void>(op_);
  3413. return mgb::hash_pair_combine(
  3414. mgb::hash(op_.dyn_typeinfo()),
  3415. mgb::hash(op_.handle)
  3416. );
  3417. }
  3418. bool GammaRNG_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3419. auto &&a_ = lhs_.cast_final_safe<GammaRNG>(),
  3420. &&b_ = rhs_.cast_final_safe<GammaRNG>();
  3421. static_cast<void>(a_);
  3422. static_cast<void>(b_);
  3423. return a_.handle == b_.handle;}
  3424. std::vector<std::pair<const char*, std::string>> GammaRNG_props_impl(const OpDef& def_) {
  3425. auto&& op_ = def_.cast_final_safe<GammaRNG>();
  3426. static_cast<void>(op_);
  3427. std::vector<std::pair<const char*, std::string>> props_;
  3428. props_.emplace_back("seed", std::to_string(op_.seed));
  3429. props_.emplace_back("handle", std::to_string(op_.handle));
  3430. return props_;
  3431. }
  3432. std::string GammaRNG_make_name_impl(const OpDef& def_) {
  3433. auto&& op_ = def_.cast_final_safe<GammaRNG>();
  3434. static_cast<void>(op_);
  3435. return "GammaRNG";
  3436. }
  3437. } // anonymous namespace
  3438. OP_TRAIT_REG(GammaRNG, GammaRNG)
  3439. .hash(GammaRNG_hash_impl)
  3440. .is_same_st(GammaRNG_is_same_st_impl)
  3441. .props(GammaRNG_props_impl)
  3442. .make_name(GammaRNG_make_name_impl);
  3443. MGB_DYN_TYPE_OBJ_FINAL_IMPL(GaussianRNG);
  3444. namespace {
  3445. size_t GaussianRNG_hash_impl(const OpDef& def_) {
  3446. auto&& op_ = def_.cast_final_safe<GaussianRNG>();
  3447. static_cast<void>(op_);
  3448. return mgb::hash_pair_combine(
  3449. mgb::hash(op_.dyn_typeinfo()),
  3450. mgb::hash_pair_combine(
  3451. mgb::hash(op_.handle),
  3452. mgb::hash_pair_combine(
  3453. mgb::hash(op_.mean),
  3454. mgb::hash_pair_combine(
  3455. mgb::hash(op_.std),
  3456. mgb::hash(op_.dtype.enumv())
  3457. )
  3458. )
  3459. )
  3460. );
  3461. }
  3462. bool GaussianRNG_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3463. auto &&a_ = lhs_.cast_final_safe<GaussianRNG>(),
  3464. &&b_ = rhs_.cast_final_safe<GaussianRNG>();
  3465. static_cast<void>(a_);
  3466. static_cast<void>(b_);
  3467. return a_.handle == b_.handle && a_.mean == b_.mean && a_.std == b_.std && a_.dtype == b_.dtype;}
  3468. std::vector<std::pair<const char*, std::string>> GaussianRNG_props_impl(const OpDef& def_) {
  3469. auto&& op_ = def_.cast_final_safe<GaussianRNG>();
  3470. static_cast<void>(op_);
  3471. std::vector<std::pair<const char*, std::string>> props_;
  3472. props_.emplace_back("seed", std::to_string(op_.seed));
  3473. props_.emplace_back("mean", std::to_string(op_.mean));
  3474. props_.emplace_back("std", std::to_string(op_.std));
  3475. props_.emplace_back("dtype", op_.dtype.name());
  3476. props_.emplace_back("handle", std::to_string(op_.handle));
  3477. return props_;
  3478. }
  3479. std::string GaussianRNG_make_name_impl(const OpDef& def_) {
  3480. auto&& op_ = def_.cast_final_safe<GaussianRNG>();
  3481. static_cast<void>(op_);
  3482. return "GaussianRNG";
  3483. }
  3484. } // anonymous namespace
  3485. OP_TRAIT_REG(GaussianRNG, GaussianRNG)
  3486. .hash(GaussianRNG_hash_impl)
  3487. .is_same_st(GaussianRNG_is_same_st_impl)
  3488. .props(GaussianRNG_props_impl)
  3489. .make_name(GaussianRNG_make_name_impl);
  3490. MGB_DYN_TYPE_OBJ_FINAL_IMPL(GetVarShape);
  3491. namespace {
  3492. size_t GetVarShape_hash_impl(const OpDef& def_) {
  3493. auto&& op_ = def_.cast_final_safe<GetVarShape>();
  3494. static_cast<void>(op_);
  3495. size_t val = mgb::hash(op_.dyn_typeinfo());
  3496. val = mgb::hash_pair_combine(val, mgb::hash(op_.axis));
  3497. return val;
  3498. }
  3499. bool GetVarShape_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3500. auto &&a_ = lhs_.cast_final_safe<GetVarShape>(),
  3501. &&b_ = rhs_.cast_final_safe<GetVarShape>();
  3502. static_cast<void>(a_);
  3503. static_cast<void>(b_);
  3504. if (a_.axis != b_.axis) return false;
  3505. return true;
  3506. }
  3507. std::vector<std::pair<const char*, std::string>> GetVarShape_props_impl(const OpDef& def_) {
  3508. auto&& op_ = def_.cast_final_safe<GetVarShape>();
  3509. static_cast<void>(op_);
  3510. std::vector<std::pair<const char*, std::string>> props_;
  3511. props_.emplace_back("axis", std::to_string(op_.axis));
  3512. return props_;
  3513. }
  3514. std::string GetVarShape_make_name_impl(const OpDef& def_) {
  3515. auto&& op_ = def_.cast_final_safe<GetVarShape>();
  3516. static_cast<void>(op_);
  3517. return "GetVarShape";
  3518. }
  3519. } // anonymous namespace
  3520. OP_TRAIT_REG(GetVarShape, GetVarShape)
  3521. .hash(GetVarShape_hash_impl)
  3522. .is_same_st(GetVarShape_is_same_st_impl)
  3523. .props(GetVarShape_props_impl)
  3524. .make_name(GetVarShape_make_name_impl);
  3525. MGB_DYN_TYPE_OBJ_FINAL_IMPL(GroupLocal);
  3526. namespace {
  3527. size_t GroupLocal_hash_impl(const OpDef& def_) {
  3528. auto&& op_ = def_.cast_final_safe<GroupLocal>();
  3529. static_cast<void>(op_);
  3530. size_t val = mgb::hash(op_.dyn_typeinfo());
  3531. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode));
  3532. val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_h));
  3533. val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_w));
  3534. val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_h));
  3535. val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_w));
  3536. val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_h));
  3537. val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_w));
  3538. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.sparse));
  3539. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format));
  3540. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.compute_mode));
  3541. return val;
  3542. }
  3543. bool GroupLocal_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3544. auto &&a_ = lhs_.cast_final_safe<GroupLocal>(),
  3545. &&b_ = rhs_.cast_final_safe<GroupLocal>();
  3546. static_cast<void>(a_);
  3547. static_cast<void>(b_);
  3548. if (a_.mode != b_.mode) return false;
  3549. if (a_.pad_h != b_.pad_h) return false;
  3550. if (a_.pad_w != b_.pad_w) return false;
  3551. if (a_.stride_h != b_.stride_h) return false;
  3552. if (a_.stride_w != b_.stride_w) return false;
  3553. if (a_.dilate_h != b_.dilate_h) return false;
  3554. if (a_.dilate_w != b_.dilate_w) return false;
  3555. if (a_.sparse != b_.sparse) return false;
  3556. if (a_.format != b_.format) return false;
  3557. if (a_.compute_mode != b_.compute_mode) return false;
  3558. return true;
  3559. }
  3560. std::vector<std::pair<const char*, std::string>> GroupLocal_props_impl(const OpDef& def_) {
  3561. auto&& op_ = def_.cast_final_safe<GroupLocal>();
  3562. static_cast<void>(op_);
  3563. std::vector<std::pair<const char*, std::string>> props_;
  3564. switch (op_.mode){
  3565. case GroupLocal::Mode::CROSS_CORRELATION:
  3566. props_.emplace_back("mode", "CROSS_CORRELATION");
  3567. break;
  3568. case GroupLocal::Mode::CONVOLUTION:
  3569. props_.emplace_back("mode", "CONVOLUTION");
  3570. break;
  3571. default:
  3572. props_.emplace_back("mode", "INVALID");
  3573. break;
  3574. }
  3575. props_.emplace_back("pad_h", std::to_string(op_.pad_h));
  3576. props_.emplace_back("pad_w", std::to_string(op_.pad_w));
  3577. props_.emplace_back("stride_h", std::to_string(op_.stride_h));
  3578. props_.emplace_back("stride_w", std::to_string(op_.stride_w));
  3579. props_.emplace_back("dilate_h", std::to_string(op_.dilate_h));
  3580. props_.emplace_back("dilate_w", std::to_string(op_.dilate_w));
  3581. switch (op_.sparse){
  3582. case GroupLocal::Sparse::DENSE:
  3583. props_.emplace_back("sparse", "DENSE");
  3584. break;
  3585. case GroupLocal::Sparse::GROUP:
  3586. props_.emplace_back("sparse", "GROUP");
  3587. break;
  3588. default:
  3589. props_.emplace_back("sparse", "INVALID");
  3590. break;
  3591. }
  3592. switch (op_.format){
  3593. case GroupLocal::Format::NCHW:
  3594. props_.emplace_back("format", "NCHW");
  3595. break;
  3596. case GroupLocal::Format::NHWC:
  3597. props_.emplace_back("format", "NHWC");
  3598. break;
  3599. case GroupLocal::Format::NHWCD4:
  3600. props_.emplace_back("format", "NHWCD4");
  3601. break;
  3602. case GroupLocal::Format::NCHW4:
  3603. props_.emplace_back("format", "NCHW4");
  3604. break;
  3605. case GroupLocal::Format::NCHW8:
  3606. props_.emplace_back("format", "NCHW8");
  3607. break;
  3608. case GroupLocal::Format::NCHW32:
  3609. props_.emplace_back("format", "NCHW32");
  3610. break;
  3611. case GroupLocal::Format::NCHW88:
  3612. props_.emplace_back("format", "NCHW88");
  3613. break;
  3614. case GroupLocal::Format::NCHW44:
  3615. props_.emplace_back("format", "NCHW44");
  3616. break;
  3617. case GroupLocal::Format::NCHW44_DOT:
  3618. props_.emplace_back("format", "NCHW44_DOT");
  3619. break;
  3620. case GroupLocal::Format::NCHW4_NCHW32:
  3621. props_.emplace_back("format", "NCHW4_NCHW32");
  3622. break;
  3623. case GroupLocal::Format::NCHW32_NCHW4:
  3624. props_.emplace_back("format", "NCHW32_NCHW4");
  3625. break;
  3626. case GroupLocal::Format::NCHW4_NCHW:
  3627. props_.emplace_back("format", "NCHW4_NCHW");
  3628. break;
  3629. case GroupLocal::Format::NHWC_NCHW:
  3630. props_.emplace_back("format", "NHWC_NCHW");
  3631. break;
  3632. case GroupLocal::Format::NHWC_NCHW4_IC_SMALL:
  3633. props_.emplace_back("format", "NHWC_NCHW4_IC_SMALL");
  3634. break;
  3635. case GroupLocal::Format::NCHW_NCHW4_IC_SMALL:
  3636. props_.emplace_back("format", "NCHW_NCHW4_IC_SMALL");
  3637. break;
  3638. case GroupLocal::Format::CHWN4:
  3639. props_.emplace_back("format", "CHWN4");
  3640. break;
  3641. case GroupLocal::Format::NCHW64:
  3642. props_.emplace_back("format", "NCHW64");
  3643. break;
  3644. case GroupLocal::Format::NCHW4_NHWC:
  3645. props_.emplace_back("format", "NCHW4_NHWC");
  3646. break;
  3647. default:
  3648. props_.emplace_back("format", "INVALID");
  3649. break;
  3650. }
  3651. switch (op_.compute_mode){
  3652. case GroupLocal::ComputeMode::DEFAULT:
  3653. props_.emplace_back("compute_mode", "DEFAULT");
  3654. break;
  3655. case GroupLocal::ComputeMode::FLOAT32:
  3656. props_.emplace_back("compute_mode", "FLOAT32");
  3657. break;
  3658. default:
  3659. props_.emplace_back("compute_mode", "INVALID");
  3660. break;
  3661. }
  3662. return props_;
  3663. }
  3664. std::string GroupLocal_make_name_impl(const OpDef& def_) {
  3665. auto&& op_ = def_.cast_final_safe<GroupLocal>();
  3666. static_cast<void>(op_);
  3667. return "GroupLocal";
  3668. }
  3669. } // anonymous namespace
  3670. OP_TRAIT_REG(GroupLocal, GroupLocal)
  3671. .hash(GroupLocal_hash_impl)
  3672. .is_same_st(GroupLocal_is_same_st_impl)
  3673. .props(GroupLocal_props_impl)
  3674. .make_name(GroupLocal_make_name_impl);
  3675. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Identity);
  3676. namespace {
  3677. size_t Identity_hash_impl(const OpDef& def_) {
  3678. auto&& op_ = def_.cast_final_safe<Identity>();
  3679. static_cast<void>(op_);
  3680. size_t val = mgb::hash(op_.dyn_typeinfo());
  3681. return val;
  3682. }
  3683. bool Identity_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3684. auto &&a_ = lhs_.cast_final_safe<Identity>(),
  3685. &&b_ = rhs_.cast_final_safe<Identity>();
  3686. static_cast<void>(a_);
  3687. static_cast<void>(b_);
  3688. return true;
  3689. }
  3690. std::vector<std::pair<const char*, std::string>> Identity_props_impl(const OpDef& def_) {
  3691. auto&& op_ = def_.cast_final_safe<Identity>();
  3692. static_cast<void>(op_);
  3693. std::vector<std::pair<const char*, std::string>> props_;
  3694. return props_;
  3695. }
  3696. std::string Identity_make_name_impl(const OpDef& def_) {
  3697. auto&& op_ = def_.cast_final_safe<Identity>();
  3698. static_cast<void>(op_);
  3699. return "Identity";
  3700. }
  3701. } // anonymous namespace
  3702. OP_TRAIT_REG(Identity, Identity)
  3703. .hash(Identity_hash_impl)
  3704. .is_same_st(Identity_is_same_st_impl)
  3705. .props(Identity_props_impl)
  3706. .make_name(Identity_make_name_impl);
  3707. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Images2Neibs);
  3708. namespace {
  3709. size_t Images2Neibs_hash_impl(const OpDef& def_) {
  3710. auto&& op_ = def_.cast_final_safe<Images2Neibs>();
  3711. static_cast<void>(op_);
  3712. size_t val = mgb::hash(op_.dyn_typeinfo());
  3713. val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_h));
  3714. val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_w));
  3715. val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_h));
  3716. val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_w));
  3717. val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_h));
  3718. val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_w));
  3719. val = mgb::hash_pair_combine(val, mgb::hash(op_.window_h));
  3720. val = mgb::hash_pair_combine(val, mgb::hash(op_.window_w));
  3721. return val;
  3722. }
  3723. bool Images2Neibs_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3724. auto &&a_ = lhs_.cast_final_safe<Images2Neibs>(),
  3725. &&b_ = rhs_.cast_final_safe<Images2Neibs>();
  3726. static_cast<void>(a_);
  3727. static_cast<void>(b_);
  3728. if (a_.pad_h != b_.pad_h) return false;
  3729. if (a_.pad_w != b_.pad_w) return false;
  3730. if (a_.stride_h != b_.stride_h) return false;
  3731. if (a_.stride_w != b_.stride_w) return false;
  3732. if (a_.dilate_h != b_.dilate_h) return false;
  3733. if (a_.dilate_w != b_.dilate_w) return false;
  3734. if (a_.window_h != b_.window_h) return false;
  3735. if (a_.window_w != b_.window_w) return false;
  3736. return true;
  3737. }
  3738. std::vector<std::pair<const char*, std::string>> Images2Neibs_props_impl(const OpDef& def_) {
  3739. auto&& op_ = def_.cast_final_safe<Images2Neibs>();
  3740. static_cast<void>(op_);
  3741. std::vector<std::pair<const char*, std::string>> props_;
  3742. props_.emplace_back("pad_h", std::to_string(op_.pad_h));
  3743. props_.emplace_back("pad_w", std::to_string(op_.pad_w));
  3744. props_.emplace_back("stride_h", std::to_string(op_.stride_h));
  3745. props_.emplace_back("stride_w", std::to_string(op_.stride_w));
  3746. props_.emplace_back("dilate_h", std::to_string(op_.dilate_h));
  3747. props_.emplace_back("dilate_w", std::to_string(op_.dilate_w));
  3748. props_.emplace_back("window_h", std::to_string(op_.window_h));
  3749. props_.emplace_back("window_w", std::to_string(op_.window_w));
  3750. return props_;
  3751. }
  3752. std::string Images2Neibs_make_name_impl(const OpDef& def_) {
  3753. auto&& op_ = def_.cast_final_safe<Images2Neibs>();
  3754. static_cast<void>(op_);
  3755. return "Images2Neibs";
  3756. }
  3757. } // anonymous namespace
  3758. OP_TRAIT_REG(Images2Neibs, Images2Neibs)
  3759. .hash(Images2Neibs_hash_impl)
  3760. .is_same_st(Images2Neibs_is_same_st_impl)
  3761. .props(Images2Neibs_props_impl)
  3762. .make_name(Images2Neibs_make_name_impl);
  3763. MGB_DYN_TYPE_OBJ_FINAL_IMPL(IncrMeshIndexing);
  3764. namespace {
  3765. size_t IncrMeshIndexing_hash_impl(const OpDef& def_) {
  3766. auto&& op_ = def_.cast_final_safe<IncrMeshIndexing>();
  3767. static_cast<void>(op_);
  3768. size_t val = mgb::hash(op_.dyn_typeinfo());
  3769. val = mgb::hash_pair_combine(val, mgb::hash(op_.items));
  3770. return val;
  3771. }
  3772. bool IncrMeshIndexing_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3773. auto &&a_ = lhs_.cast_final_safe<IncrMeshIndexing>(),
  3774. &&b_ = rhs_.cast_final_safe<IncrMeshIndexing>();
  3775. static_cast<void>(a_);
  3776. static_cast<void>(b_);
  3777. if (a_.items != b_.items) return false;
  3778. return true;
  3779. }
  3780. std::vector<std::pair<const char*, std::string>> IncrMeshIndexing_props_impl(const OpDef& def_) {
  3781. auto&& op_ = def_.cast_final_safe<IncrMeshIndexing>();
  3782. static_cast<void>(op_);
  3783. std::vector<std::pair<const char*, std::string>> props_;
  3784. props_.emplace_back("items", "{std::vector}");
  3785. return props_;
  3786. }
  3787. std::string IncrMeshIndexing_make_name_impl(const OpDef& def_) {
  3788. auto&& op_ = def_.cast_final_safe<IncrMeshIndexing>();
  3789. static_cast<void>(op_);
  3790. return "IncrMeshIndexing";
  3791. }
  3792. } // anonymous namespace
  3793. OP_TRAIT_REG(IncrMeshIndexing, IncrMeshIndexing)
  3794. .hash(IncrMeshIndexing_hash_impl)
  3795. .is_same_st(IncrMeshIndexing_is_same_st_impl)
  3796. .props(IncrMeshIndexing_props_impl)
  3797. .make_name(IncrMeshIndexing_make_name_impl);
  3798. MGB_DYN_TYPE_OBJ_FINAL_IMPL(IncrSubtensor);
  3799. namespace {
  3800. size_t IncrSubtensor_hash_impl(const OpDef& def_) {
  3801. auto&& op_ = def_.cast_final_safe<IncrSubtensor>();
  3802. static_cast<void>(op_);
  3803. size_t val = mgb::hash(op_.dyn_typeinfo());
  3804. val = mgb::hash_pair_combine(val, mgb::hash(op_.items));
  3805. return val;
  3806. }
  3807. bool IncrSubtensor_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3808. auto &&a_ = lhs_.cast_final_safe<IncrSubtensor>(),
  3809. &&b_ = rhs_.cast_final_safe<IncrSubtensor>();
  3810. static_cast<void>(a_);
  3811. static_cast<void>(b_);
  3812. if (a_.items != b_.items) return false;
  3813. return true;
  3814. }
  3815. std::vector<std::pair<const char*, std::string>> IncrSubtensor_props_impl(const OpDef& def_) {
  3816. auto&& op_ = def_.cast_final_safe<IncrSubtensor>();
  3817. static_cast<void>(op_);
  3818. std::vector<std::pair<const char*, std::string>> props_;
  3819. props_.emplace_back("items", "{std::vector}");
  3820. return props_;
  3821. }
  3822. std::string IncrSubtensor_make_name_impl(const OpDef& def_) {
  3823. auto&& op_ = def_.cast_final_safe<IncrSubtensor>();
  3824. static_cast<void>(op_);
  3825. return "IncrSubtensor";
  3826. }
  3827. } // anonymous namespace
  3828. OP_TRAIT_REG(IncrSubtensor, IncrSubtensor)
  3829. .hash(IncrSubtensor_hash_impl)
  3830. .is_same_st(IncrSubtensor_is_same_st_impl)
  3831. .props(IncrSubtensor_props_impl)
  3832. .make_name(IncrSubtensor_make_name_impl);
  3833. MGB_DYN_TYPE_OBJ_FINAL_IMPL(IndexingIncrMultiAxisVec);
  3834. namespace {
  3835. size_t IndexingIncrMultiAxisVec_hash_impl(const OpDef& def_) {
  3836. auto&& op_ = def_.cast_final_safe<IndexingIncrMultiAxisVec>();
  3837. static_cast<void>(op_);
  3838. size_t val = mgb::hash(op_.dyn_typeinfo());
  3839. val = mgb::hash_pair_combine(val, mgb::hash(op_.items));
  3840. return val;
  3841. }
  3842. bool IndexingIncrMultiAxisVec_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3843. auto &&a_ = lhs_.cast_final_safe<IndexingIncrMultiAxisVec>(),
  3844. &&b_ = rhs_.cast_final_safe<IndexingIncrMultiAxisVec>();
  3845. static_cast<void>(a_);
  3846. static_cast<void>(b_);
  3847. if (a_.items != b_.items) return false;
  3848. return true;
  3849. }
  3850. std::vector<std::pair<const char*, std::string>> IndexingIncrMultiAxisVec_props_impl(const OpDef& def_) {
  3851. auto&& op_ = def_.cast_final_safe<IndexingIncrMultiAxisVec>();
  3852. static_cast<void>(op_);
  3853. std::vector<std::pair<const char*, std::string>> props_;
  3854. props_.emplace_back("items", "{std::vector}");
  3855. return props_;
  3856. }
  3857. std::string IndexingIncrMultiAxisVec_make_name_impl(const OpDef& def_) {
  3858. auto&& op_ = def_.cast_final_safe<IndexingIncrMultiAxisVec>();
  3859. static_cast<void>(op_);
  3860. return "IndexingIncrMultiAxisVec";
  3861. }
  3862. } // anonymous namespace
  3863. OP_TRAIT_REG(IndexingIncrMultiAxisVec, IndexingIncrMultiAxisVec)
  3864. .hash(IndexingIncrMultiAxisVec_hash_impl)
  3865. .is_same_st(IndexingIncrMultiAxisVec_is_same_st_impl)
  3866. .props(IndexingIncrMultiAxisVec_props_impl)
  3867. .make_name(IndexingIncrMultiAxisVec_make_name_impl);
  3868. MGB_DYN_TYPE_OBJ_FINAL_IMPL(IndexingMultiAxisVec);
  3869. namespace {
  3870. size_t IndexingMultiAxisVec_hash_impl(const OpDef& def_) {
  3871. auto&& op_ = def_.cast_final_safe<IndexingMultiAxisVec>();
  3872. static_cast<void>(op_);
  3873. size_t val = mgb::hash(op_.dyn_typeinfo());
  3874. val = mgb::hash_pair_combine(val, mgb::hash(op_.items));
  3875. return val;
  3876. }
  3877. bool IndexingMultiAxisVec_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3878. auto &&a_ = lhs_.cast_final_safe<IndexingMultiAxisVec>(),
  3879. &&b_ = rhs_.cast_final_safe<IndexingMultiAxisVec>();
  3880. static_cast<void>(a_);
  3881. static_cast<void>(b_);
  3882. if (a_.items != b_.items) return false;
  3883. return true;
  3884. }
  3885. std::vector<std::pair<const char*, std::string>> IndexingMultiAxisVec_props_impl(const OpDef& def_) {
  3886. auto&& op_ = def_.cast_final_safe<IndexingMultiAxisVec>();
  3887. static_cast<void>(op_);
  3888. std::vector<std::pair<const char*, std::string>> props_;
  3889. props_.emplace_back("items", "{std::vector}");
  3890. return props_;
  3891. }
  3892. std::string IndexingMultiAxisVec_make_name_impl(const OpDef& def_) {
  3893. auto&& op_ = def_.cast_final_safe<IndexingMultiAxisVec>();
  3894. static_cast<void>(op_);
  3895. return "IndexingMultiAxisVec";
  3896. }
  3897. } // anonymous namespace
  3898. OP_TRAIT_REG(IndexingMultiAxisVec, IndexingMultiAxisVec)
  3899. .hash(IndexingMultiAxisVec_hash_impl)
  3900. .is_same_st(IndexingMultiAxisVec_is_same_st_impl)
  3901. .props(IndexingMultiAxisVec_props_impl)
  3902. .make_name(IndexingMultiAxisVec_make_name_impl);
  3903. MGB_DYN_TYPE_OBJ_FINAL_IMPL(IndexingOneHot);
  3904. namespace {
  3905. size_t IndexingOneHot_hash_impl(const OpDef& def_) {
  3906. auto&& op_ = def_.cast_final_safe<IndexingOneHot>();
  3907. static_cast<void>(op_);
  3908. size_t val = mgb::hash(op_.dyn_typeinfo());
  3909. val = mgb::hash_pair_combine(val, mgb::hash(op_.axis));
  3910. val = mgb::hash_pair_combine(val, mgb::hash(op_.ndim));
  3911. return val;
  3912. }
  3913. bool IndexingOneHot_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3914. auto &&a_ = lhs_.cast_final_safe<IndexingOneHot>(),
  3915. &&b_ = rhs_.cast_final_safe<IndexingOneHot>();
  3916. static_cast<void>(a_);
  3917. static_cast<void>(b_);
  3918. if (a_.axis != b_.axis) return false;
  3919. if (a_.ndim != b_.ndim) return false;
  3920. return true;
  3921. }
  3922. std::vector<std::pair<const char*, std::string>> IndexingOneHot_props_impl(const OpDef& def_) {
  3923. auto&& op_ = def_.cast_final_safe<IndexingOneHot>();
  3924. static_cast<void>(op_);
  3925. std::vector<std::pair<const char*, std::string>> props_;
  3926. props_.emplace_back("axis", std::to_string(op_.axis));
  3927. props_.emplace_back("ndim", std::to_string(op_.ndim));
  3928. return props_;
  3929. }
  3930. std::string IndexingOneHot_make_name_impl(const OpDef& def_) {
  3931. auto&& op_ = def_.cast_final_safe<IndexingOneHot>();
  3932. static_cast<void>(op_);
  3933. return "IndexingOneHot";
  3934. }
  3935. } // anonymous namespace
  3936. OP_TRAIT_REG(IndexingOneHot, IndexingOneHot)
  3937. .hash(IndexingOneHot_hash_impl)
  3938. .is_same_st(IndexingOneHot_is_same_st_impl)
  3939. .props(IndexingOneHot_props_impl)
  3940. .make_name(IndexingOneHot_make_name_impl);
  3941. MGB_DYN_TYPE_OBJ_FINAL_IMPL(IndexingSetMultiAxisVec);
  3942. namespace {
  3943. size_t IndexingSetMultiAxisVec_hash_impl(const OpDef& def_) {
  3944. auto&& op_ = def_.cast_final_safe<IndexingSetMultiAxisVec>();
  3945. static_cast<void>(op_);
  3946. size_t val = mgb::hash(op_.dyn_typeinfo());
  3947. val = mgb::hash_pair_combine(val, mgb::hash(op_.items));
  3948. return val;
  3949. }
  3950. bool IndexingSetMultiAxisVec_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3951. auto &&a_ = lhs_.cast_final_safe<IndexingSetMultiAxisVec>(),
  3952. &&b_ = rhs_.cast_final_safe<IndexingSetMultiAxisVec>();
  3953. static_cast<void>(a_);
  3954. static_cast<void>(b_);
  3955. if (a_.items != b_.items) return false;
  3956. return true;
  3957. }
  3958. std::vector<std::pair<const char*, std::string>> IndexingSetMultiAxisVec_props_impl(const OpDef& def_) {
  3959. auto&& op_ = def_.cast_final_safe<IndexingSetMultiAxisVec>();
  3960. static_cast<void>(op_);
  3961. std::vector<std::pair<const char*, std::string>> props_;
  3962. props_.emplace_back("items", "{std::vector}");
  3963. return props_;
  3964. }
  3965. std::string IndexingSetMultiAxisVec_make_name_impl(const OpDef& def_) {
  3966. auto&& op_ = def_.cast_final_safe<IndexingSetMultiAxisVec>();
  3967. static_cast<void>(op_);
  3968. return "IndexingSetMultiAxisVec";
  3969. }
  3970. } // anonymous namespace
  3971. OP_TRAIT_REG(IndexingSetMultiAxisVec, IndexingSetMultiAxisVec)
  3972. .hash(IndexingSetMultiAxisVec_hash_impl)
  3973. .is_same_st(IndexingSetMultiAxisVec_is_same_st_impl)
  3974. .props(IndexingSetMultiAxisVec_props_impl)
  3975. .make_name(IndexingSetMultiAxisVec_make_name_impl);
  3976. MGB_DYN_TYPE_OBJ_FINAL_IMPL(IndexingSetOneHot);
  3977. namespace {
  3978. size_t IndexingSetOneHot_hash_impl(const OpDef& def_) {
  3979. auto&& op_ = def_.cast_final_safe<IndexingSetOneHot>();
  3980. static_cast<void>(op_);
  3981. size_t val = mgb::hash(op_.dyn_typeinfo());
  3982. val = mgb::hash_pair_combine(val, mgb::hash(op_.axis));
  3983. val = mgb::hash_pair_combine(val, mgb::hash(op_.ndim));
  3984. return val;
  3985. }
  3986. bool IndexingSetOneHot_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3987. auto &&a_ = lhs_.cast_final_safe<IndexingSetOneHot>(),
  3988. &&b_ = rhs_.cast_final_safe<IndexingSetOneHot>();
  3989. static_cast<void>(a_);
  3990. static_cast<void>(b_);
  3991. if (a_.axis != b_.axis) return false;
  3992. if (a_.ndim != b_.ndim) return false;
  3993. return true;
  3994. }
  3995. std::vector<std::pair<const char*, std::string>> IndexingSetOneHot_props_impl(const OpDef& def_) {
  3996. auto&& op_ = def_.cast_final_safe<IndexingSetOneHot>();
  3997. static_cast<void>(op_);
  3998. std::vector<std::pair<const char*, std::string>> props_;
  3999. props_.emplace_back("axis", std::to_string(op_.axis));
  4000. props_.emplace_back("ndim", std::to_string(op_.ndim));
  4001. return props_;
  4002. }
  4003. std::string IndexingSetOneHot_make_name_impl(const OpDef& def_) {
  4004. auto&& op_ = def_.cast_final_safe<IndexingSetOneHot>();
  4005. static_cast<void>(op_);
  4006. return "IndexingSetOneHot";
  4007. }
  4008. } // anonymous namespace
  4009. OP_TRAIT_REG(IndexingSetOneHot, IndexingSetOneHot)
  4010. .hash(IndexingSetOneHot_hash_impl)
  4011. .is_same_st(IndexingSetOneHot_is_same_st_impl)
  4012. .props(IndexingSetOneHot_props_impl)
  4013. .make_name(IndexingSetOneHot_make_name_impl);
  4014. MGB_DYN_TYPE_OBJ_FINAL_IMPL(InplaceAdd);
  4015. namespace {
  4016. size_t InplaceAdd_hash_impl(const OpDef& def_) {
  4017. auto&& op_ = def_.cast_final_safe<InplaceAdd>();
  4018. static_cast<void>(op_);
  4019. size_t val = mgb::hash(op_.dyn_typeinfo());
  4020. return val;
  4021. }
  4022. bool InplaceAdd_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4023. auto &&a_ = lhs_.cast_final_safe<InplaceAdd>(),
  4024. &&b_ = rhs_.cast_final_safe<InplaceAdd>();
  4025. static_cast<void>(a_);
  4026. static_cast<void>(b_);
  4027. return true;
  4028. }
  4029. std::vector<std::pair<const char*, std::string>> InplaceAdd_props_impl(const OpDef& def_) {
  4030. auto&& op_ = def_.cast_final_safe<InplaceAdd>();
  4031. static_cast<void>(op_);
  4032. std::vector<std::pair<const char*, std::string>> props_;
  4033. return props_;
  4034. }
  4035. std::string InplaceAdd_make_name_impl(const OpDef& def_) {
  4036. auto&& op_ = def_.cast_final_safe<InplaceAdd>();
  4037. static_cast<void>(op_);
  4038. return "InplaceAdd";
  4039. }
  4040. } // anonymous namespace
  4041. OP_TRAIT_REG(InplaceAdd, InplaceAdd)
  4042. .hash(InplaceAdd_hash_impl)
  4043. .is_same_st(InplaceAdd_is_same_st_impl)
  4044. .props(InplaceAdd_props_impl)
  4045. .make_name(InplaceAdd_make_name_impl);
  4046. MGB_DYN_TYPE_OBJ_FINAL_IMPL(LAMBUpdate);
  4047. namespace {
  4048. size_t LAMBUpdate_hash_impl(const OpDef& def_) {
  4049. auto&& op_ = def_.cast_final_safe<LAMBUpdate>();
  4050. static_cast<void>(op_);
  4051. size_t val = mgb::hash(op_.dyn_typeinfo());
  4052. val = mgb::hash_pair_combine(val, mgb::hash(op_.beta_1));
  4053. val = mgb::hash_pair_combine(val, mgb::hash(op_.beta_2));
  4054. val = mgb::hash_pair_combine(val, mgb::hash(op_.step));
  4055. val = mgb::hash_pair_combine(val, mgb::hash(op_.lr));
  4056. val = mgb::hash_pair_combine(val, mgb::hash(op_.weight_decay));
  4057. val = mgb::hash_pair_combine(val, mgb::hash(op_.eps));
  4058. val = mgb::hash_pair_combine(val, mgb::hash(op_.bias_correction));
  4059. val = mgb::hash_pair_combine(val, mgb::hash(op_.always_adapt));
  4060. return val;
  4061. }
  4062. bool LAMBUpdate_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4063. auto &&a_ = lhs_.cast_final_safe<LAMBUpdate>(),
  4064. &&b_ = rhs_.cast_final_safe<LAMBUpdate>();
  4065. static_cast<void>(a_);
  4066. static_cast<void>(b_);
  4067. if (a_.beta_1 != b_.beta_1) return false;
  4068. if (a_.beta_2 != b_.beta_2) return false;
  4069. if (a_.step != b_.step) return false;
  4070. if (a_.lr != b_.lr) return false;
  4071. if (a_.weight_decay != b_.weight_decay) return false;
  4072. if (a_.eps != b_.eps) return false;
  4073. if (a_.bias_correction != b_.bias_correction) return false;
  4074. if (a_.always_adapt != b_.always_adapt) return false;
  4075. return true;
  4076. }
  4077. std::vector<std::pair<const char*, std::string>> LAMBUpdate_props_impl(const OpDef& def_) {
  4078. auto&& op_ = def_.cast_final_safe<LAMBUpdate>();
  4079. static_cast<void>(op_);
  4080. std::vector<std::pair<const char*, std::string>> props_;
  4081. props_.emplace_back("beta_1", std::to_string(op_.beta_1));
  4082. props_.emplace_back("beta_2", std::to_string(op_.beta_2));
  4083. props_.emplace_back("step", std::to_string(op_.step));
  4084. props_.emplace_back("lr", std::to_string(op_.lr));
  4085. props_.emplace_back("weight_decay", std::to_string(op_.weight_decay));
  4086. props_.emplace_back("eps", std::to_string(op_.eps));
  4087. props_.emplace_back("bias_correction", std::to_string(op_.bias_correction));
  4088. props_.emplace_back("always_adapt", std::to_string(op_.always_adapt));
  4089. return props_;
  4090. }
  4091. std::string LAMBUpdate_make_name_impl(const OpDef& def_) {
  4092. auto&& op_ = def_.cast_final_safe<LAMBUpdate>();
  4093. static_cast<void>(op_);
  4094. return "LAMBUpdate";
  4095. }
  4096. } // anonymous namespace
  4097. OP_TRAIT_REG(LAMBUpdate, LAMBUpdate)
  4098. .hash(LAMBUpdate_hash_impl)
  4099. .is_same_st(LAMBUpdate_is_same_st_impl)
  4100. .props(LAMBUpdate_props_impl)
  4101. .make_name(LAMBUpdate_make_name_impl);
  4102. MGB_DYN_TYPE_OBJ_FINAL_IMPL(LRN);
  4103. namespace {
  4104. size_t LRN_hash_impl(const OpDef& def_) {
  4105. auto&& op_ = def_.cast_final_safe<LRN>();
  4106. static_cast<void>(op_);
  4107. size_t val = mgb::hash(op_.dyn_typeinfo());
  4108. val = mgb::hash_pair_combine(val, mgb::hash(op_.n));
  4109. val = mgb::hash_pair_combine(val, mgb::hash(op_.k));
  4110. val = mgb::hash_pair_combine(val, mgb::hash(op_.alpha));
  4111. val = mgb::hash_pair_combine(val, mgb::hash(op_.beta));
  4112. return val;
  4113. }
  4114. bool LRN_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4115. auto &&a_ = lhs_.cast_final_safe<LRN>(),
  4116. &&b_ = rhs_.cast_final_safe<LRN>();
  4117. static_cast<void>(a_);
  4118. static_cast<void>(b_);
  4119. if (a_.n != b_.n) return false;
  4120. if (a_.k != b_.k) return false;
  4121. if (a_.alpha != b_.alpha) return false;
  4122. if (a_.beta != b_.beta) return false;
  4123. return true;
  4124. }
  4125. std::vector<std::pair<const char*, std::string>> LRN_props_impl(const OpDef& def_) {
  4126. auto&& op_ = def_.cast_final_safe<LRN>();
  4127. static_cast<void>(op_);
  4128. std::vector<std::pair<const char*, std::string>> props_;
  4129. props_.emplace_back("n", std::to_string(op_.n));
  4130. props_.emplace_back("k", std::to_string(op_.k));
  4131. props_.emplace_back("alpha", std::to_string(op_.alpha));
  4132. props_.emplace_back("beta", std::to_string(op_.beta));
  4133. return props_;
  4134. }
  4135. std::string LRN_make_name_impl(const OpDef& def_) {
  4136. auto&& op_ = def_.cast_final_safe<LRN>();
  4137. static_cast<void>(op_);
  4138. return "LRN";
  4139. }
  4140. } // anonymous namespace
  4141. OP_TRAIT_REG(LRN, LRN)
  4142. .hash(LRN_hash_impl)
  4143. .is_same_st(LRN_is_same_st_impl)
  4144. .props(LRN_props_impl)
  4145. .make_name(LRN_make_name_impl);
  4146. MGB_DYN_TYPE_OBJ_FINAL_IMPL(LSQ);
  4147. namespace {
  4148. size_t LSQ_hash_impl(const OpDef& def_) {
  4149. auto&& op_ = def_.cast_final_safe<LSQ>();
  4150. static_cast<void>(op_);
  4151. size_t val = mgb::hash(op_.dyn_typeinfo());
  4152. val = mgb::hash_pair_combine(val, mgb::hash(op_.qmin));
  4153. val = mgb::hash_pair_combine(val, mgb::hash(op_.qmax));
  4154. return val;
  4155. }
  4156. bool LSQ_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4157. auto &&a_ = lhs_.cast_final_safe<LSQ>(),
  4158. &&b_ = rhs_.cast_final_safe<LSQ>();
  4159. static_cast<void>(a_);
  4160. static_cast<void>(b_);
  4161. if (a_.qmin != b_.qmin) return false;
  4162. if (a_.qmax != b_.qmax) return false;
  4163. return true;
  4164. }
  4165. std::vector<std::pair<const char*, std::string>> LSQ_props_impl(const OpDef& def_) {
  4166. auto&& op_ = def_.cast_final_safe<LSQ>();
  4167. static_cast<void>(op_);
  4168. std::vector<std::pair<const char*, std::string>> props_;
  4169. props_.emplace_back("qmin", std::to_string(op_.qmin));
  4170. props_.emplace_back("qmax", std::to_string(op_.qmax));
  4171. return props_;
  4172. }
  4173. std::string LSQ_make_name_impl(const OpDef& def_) {
  4174. auto&& op_ = def_.cast_final_safe<LSQ>();
  4175. static_cast<void>(op_);
  4176. return "LSQ";
  4177. }
  4178. } // anonymous namespace
  4179. OP_TRAIT_REG(LSQ, LSQ)
  4180. .hash(LSQ_hash_impl)
  4181. .is_same_st(LSQ_is_same_st_impl)
  4182. .props(LSQ_props_impl)
  4183. .make_name(LSQ_make_name_impl);
  4184. MGB_DYN_TYPE_OBJ_FINAL_IMPL(LSTM);
  4185. namespace {
  4186. size_t LSTM_hash_impl(const OpDef& def_) {
  4187. auto&& op_ = def_.cast_final_safe<LSTM>();
  4188. static_cast<void>(op_);
  4189. size_t val = mgb::hash(op_.dyn_typeinfo());
  4190. val = mgb::hash_pair_combine(val, mgb::hash(op_.num_layers));
  4191. val = mgb::hash_pair_combine(val, mgb::hash(op_.bidirectional));
  4192. val = mgb::hash_pair_combine(val, mgb::hash(op_.bias));
  4193. val = mgb::hash_pair_combine(val, mgb::hash(op_.hidden_size));
  4194. val = mgb::hash_pair_combine(val, mgb::hash(op_.proj_size));
  4195. val = mgb::hash_pair_combine(val, mgb::hash(op_.dropout));
  4196. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.fwd_mode));
  4197. return val;
  4198. }
  4199. bool LSTM_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4200. auto &&a_ = lhs_.cast_final_safe<LSTM>(),
  4201. &&b_ = rhs_.cast_final_safe<LSTM>();
  4202. static_cast<void>(a_);
  4203. static_cast<void>(b_);
  4204. if (a_.num_layers != b_.num_layers) return false;
  4205. if (a_.bidirectional != b_.bidirectional) return false;
  4206. if (a_.bias != b_.bias) return false;
  4207. if (a_.hidden_size != b_.hidden_size) return false;
  4208. if (a_.proj_size != b_.proj_size) return false;
  4209. if (a_.dropout != b_.dropout) return false;
  4210. if (a_.fwd_mode != b_.fwd_mode) return false;
  4211. return true;
  4212. }
  4213. std::vector<std::pair<const char*, std::string>> LSTM_props_impl(const OpDef& def_) {
  4214. auto&& op_ = def_.cast_final_safe<LSTM>();
  4215. static_cast<void>(op_);
  4216. std::vector<std::pair<const char*, std::string>> props_;
  4217. props_.emplace_back("num_layers", std::to_string(op_.num_layers));
  4218. props_.emplace_back("bidirectional", std::to_string(op_.bidirectional));
  4219. props_.emplace_back("bias", std::to_string(op_.bias));
  4220. props_.emplace_back("hidden_size", std::to_string(op_.hidden_size));
  4221. props_.emplace_back("proj_size", std::to_string(op_.proj_size));
  4222. props_.emplace_back("dropout", std::to_string(op_.dropout));
  4223. switch (op_.fwd_mode){
  4224. case LSTM::FwdMode::TRAINING:
  4225. props_.emplace_back("fwd_mode", "TRAINING");
  4226. break;
  4227. case LSTM::FwdMode::INFERENCE:
  4228. props_.emplace_back("fwd_mode", "INFERENCE");
  4229. break;
  4230. default:
  4231. props_.emplace_back("fwd_mode", "INVALID");
  4232. break;
  4233. }
  4234. return props_;
  4235. }
  4236. std::string LSTM_make_name_impl(const OpDef& def_) {
  4237. auto&& op_ = def_.cast_final_safe<LSTM>();
  4238. static_cast<void>(op_);
  4239. return "LSTM";
  4240. }
  4241. } // anonymous namespace
  4242. OP_TRAIT_REG(LSTM, LSTM)
  4243. .hash(LSTM_hash_impl)
  4244. .is_same_st(LSTM_is_same_st_impl)
  4245. .props(LSTM_props_impl)
  4246. .make_name(LSTM_make_name_impl);
  4247. MGB_DYN_TYPE_OBJ_FINAL_IMPL(LSTMCell);
  4248. namespace {
  4249. size_t LSTMCell_hash_impl(const OpDef& def_) {
  4250. auto&& op_ = def_.cast_final_safe<LSTMCell>();
  4251. static_cast<void>(op_);
  4252. size_t val = mgb::hash(op_.dyn_typeinfo());
  4253. return val;
  4254. }
  4255. bool LSTMCell_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4256. auto &&a_ = lhs_.cast_final_safe<LSTMCell>(),
  4257. &&b_ = rhs_.cast_final_safe<LSTMCell>();
  4258. static_cast<void>(a_);
  4259. static_cast<void>(b_);
  4260. return true;
  4261. }
  4262. std::vector<std::pair<const char*, std::string>> LSTMCell_props_impl(const OpDef& def_) {
  4263. auto&& op_ = def_.cast_final_safe<LSTMCell>();
  4264. static_cast<void>(op_);
  4265. std::vector<std::pair<const char*, std::string>> props_;
  4266. return props_;
  4267. }
  4268. std::string LSTMCell_make_name_impl(const OpDef& def_) {
  4269. auto&& op_ = def_.cast_final_safe<LSTMCell>();
  4270. static_cast<void>(op_);
  4271. return "LSTMCell";
  4272. }
  4273. } // anonymous namespace
  4274. OP_TRAIT_REG(LSTMCell, LSTMCell)
  4275. .hash(LSTMCell_hash_impl)
  4276. .is_same_st(LSTMCell_is_same_st_impl)
  4277. .props(LSTMCell_props_impl)
  4278. .make_name(LSTMCell_make_name_impl);
  4279. MGB_DYN_TYPE_OBJ_FINAL_IMPL(LayerNorm);
  4280. namespace {
  4281. size_t LayerNorm_hash_impl(const OpDef& def_) {
  4282. auto&& op_ = def_.cast_final_safe<LayerNorm>();
  4283. static_cast<void>(op_);
  4284. size_t val = mgb::hash(op_.dyn_typeinfo());
  4285. val = mgb::hash_pair_combine(val, mgb::hash(op_.affine));
  4286. val = mgb::hash_pair_combine(val, mgb::hash(op_.eps));
  4287. val = mgb::hash_pair_combine(val, mgb::hash(op_.normalized_dim));
  4288. val = mgb::hash_pair_combine(val, mgb::hash(op_.normalized_size));
  4289. return val;
  4290. }
  4291. bool LayerNorm_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4292. auto &&a_ = lhs_.cast_final_safe<LayerNorm>(),
  4293. &&b_ = rhs_.cast_final_safe<LayerNorm>();
  4294. static_cast<void>(a_);
  4295. static_cast<void>(b_);
  4296. if (a_.affine != b_.affine) return false;
  4297. if (a_.eps != b_.eps) return false;
  4298. if (a_.normalized_dim != b_.normalized_dim) return false;
  4299. if (a_.normalized_size != b_.normalized_size) return false;
  4300. return true;
  4301. }
  4302. std::vector<std::pair<const char*, std::string>> LayerNorm_props_impl(const OpDef& def_) {
  4303. auto&& op_ = def_.cast_final_safe<LayerNorm>();
  4304. static_cast<void>(op_);
  4305. std::vector<std::pair<const char*, std::string>> props_;
  4306. props_.emplace_back("affine", std::to_string(op_.affine));
  4307. props_.emplace_back("eps", std::to_string(op_.eps));
  4308. props_.emplace_back("normalized_dim", std::to_string(op_.normalized_dim));
  4309. props_.emplace_back("normalized_size", std::to_string(op_.normalized_size));
  4310. return props_;
  4311. }
  4312. std::string LayerNorm_make_name_impl(const OpDef& def_) {
  4313. auto&& op_ = def_.cast_final_safe<LayerNorm>();
  4314. static_cast<void>(op_);
  4315. return "LayerNorm";
  4316. }
  4317. } // anonymous namespace
  4318. OP_TRAIT_REG(LayerNorm, LayerNorm)
  4319. .hash(LayerNorm_hash_impl)
  4320. .is_same_st(LayerNorm_is_same_st_impl)
  4321. .props(LayerNorm_props_impl)
  4322. .make_name(LayerNorm_make_name_impl);
  4323. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Linspace);
  4324. namespace {
  4325. size_t Linspace_hash_impl(const OpDef& def_) {
  4326. auto&& op_ = def_.cast_final_safe<Linspace>();
  4327. static_cast<void>(op_);
  4328. size_t val = mgb::hash(op_.dyn_typeinfo());
  4329. val = mgb::hash_pair_combine(val, mgb::hash(op_.endpoint));
  4330. val = mgb::hash_pair_combine(val, mgb::hash(op_.comp_node));
  4331. return val;
  4332. }
  4333. bool Linspace_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4334. auto &&a_ = lhs_.cast_final_safe<Linspace>(),
  4335. &&b_ = rhs_.cast_final_safe<Linspace>();
  4336. static_cast<void>(a_);
  4337. static_cast<void>(b_);
  4338. if (a_.endpoint != b_.endpoint) return false;
  4339. if (a_.comp_node != b_.comp_node) return false;
  4340. return true;
  4341. }
  4342. std::vector<std::pair<const char*, std::string>> Linspace_props_impl(const OpDef& def_) {
  4343. auto&& op_ = def_.cast_final_safe<Linspace>();
  4344. static_cast<void>(op_);
  4345. std::vector<std::pair<const char*, std::string>> props_;
  4346. props_.emplace_back("endpoint", std::to_string(op_.endpoint));
  4347. props_.emplace_back("comp_node", op_.comp_node.to_string());
  4348. return props_;
  4349. }
  4350. std::string Linspace_make_name_impl(const OpDef& def_) {
  4351. auto&& op_ = def_.cast_final_safe<Linspace>();
  4352. static_cast<void>(op_);
  4353. return "Linspace";
  4354. }
  4355. } // anonymous namespace
  4356. OP_TRAIT_REG(Linspace, Linspace)
  4357. .hash(Linspace_hash_impl)
  4358. .is_same_st(Linspace_is_same_st_impl)
  4359. .props(Linspace_props_impl)
  4360. .make_name(Linspace_make_name_impl);
  4361. MGB_DYN_TYPE_OBJ_FINAL_IMPL(MagicMindRuntime);
  4362. namespace {
  4363. size_t MagicMindRuntime_hash_impl(const OpDef& def_) {
  4364. auto&& op_ = def_.cast_final_safe<MagicMindRuntime>();
  4365. static_cast<void>(op_);
  4366. size_t val = mgb::hash(op_.dyn_typeinfo());
  4367. val = mgb::hash_pair_combine(val, mgb::hash(op_.buf));
  4368. val = mgb::hash_pair_combine(val, mgb::hash(op_.buf_size));
  4369. return val;
  4370. }
  4371. bool MagicMindRuntime_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4372. auto &&a_ = lhs_.cast_final_safe<MagicMindRuntime>(),
  4373. &&b_ = rhs_.cast_final_safe<MagicMindRuntime>();
  4374. static_cast<void>(a_);
  4375. static_cast<void>(b_);
  4376. if (a_.buf != b_.buf) return false;
  4377. if (a_.buf_size != b_.buf_size) return false;
  4378. return true;
  4379. }
  4380. std::vector<std::pair<const char*, std::string>> MagicMindRuntime_props_impl(const OpDef& def_) {
  4381. auto&& op_ = def_.cast_final_safe<MagicMindRuntime>();
  4382. static_cast<void>(op_);
  4383. std::vector<std::pair<const char*, std::string>> props_;
  4384. props_.emplace_back("buf", op_.buf);
  4385. props_.emplace_back("buf_size", std::to_string(op_.buf_size));
  4386. return props_;
  4387. }
  4388. std::string MagicMindRuntime_make_name_impl(const OpDef& def_) {
  4389. auto&& op_ = def_.cast_final_safe<MagicMindRuntime>();
  4390. static_cast<void>(op_);
  4391. return "MagicMindRuntime";
  4392. }
  4393. } // anonymous namespace
  4394. OP_TRAIT_REG(MagicMindRuntime, MagicMindRuntime)
  4395. .hash(MagicMindRuntime_hash_impl)
  4396. .is_same_st(MagicMindRuntime_is_same_st_impl)
  4397. .props(MagicMindRuntime_props_impl)
  4398. .make_name(MagicMindRuntime_make_name_impl);
  4399. MGB_DYN_TYPE_OBJ_FINAL_IMPL(MatrixInverse);
  4400. namespace {
  4401. size_t MatrixInverse_hash_impl(const OpDef& def_) {
  4402. auto&& op_ = def_.cast_final_safe<MatrixInverse>();
  4403. static_cast<void>(op_);
  4404. size_t val = mgb::hash(op_.dyn_typeinfo());
  4405. return val;
  4406. }
  4407. bool MatrixInverse_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4408. auto &&a_ = lhs_.cast_final_safe<MatrixInverse>(),
  4409. &&b_ = rhs_.cast_final_safe<MatrixInverse>();
  4410. static_cast<void>(a_);
  4411. static_cast<void>(b_);
  4412. return true;
  4413. }
  4414. std::vector<std::pair<const char*, std::string>> MatrixInverse_props_impl(const OpDef& def_) {
  4415. auto&& op_ = def_.cast_final_safe<MatrixInverse>();
  4416. static_cast<void>(op_);
  4417. std::vector<std::pair<const char*, std::string>> props_;
  4418. return props_;
  4419. }
  4420. std::string MatrixInverse_make_name_impl(const OpDef& def_) {
  4421. auto&& op_ = def_.cast_final_safe<MatrixInverse>();
  4422. static_cast<void>(op_);
  4423. return "MatrixInverse";
  4424. }
  4425. } // anonymous namespace
  4426. OP_TRAIT_REG(MatrixInverse, MatrixInverse)
  4427. .hash(MatrixInverse_hash_impl)
  4428. .is_same_st(MatrixInverse_is_same_st_impl)
  4429. .props(MatrixInverse_props_impl)
  4430. .make_name(MatrixInverse_make_name_impl);
  4431. MGB_DYN_TYPE_OBJ_FINAL_IMPL(MatrixMul);
  4432. namespace {
  4433. size_t MatrixMul_hash_impl(const OpDef& def_) {
  4434. auto&& op_ = def_.cast_final_safe<MatrixMul>();
  4435. static_cast<void>(op_);
  4436. size_t val = mgb::hash(op_.dyn_typeinfo());
  4437. val = mgb::hash_pair_combine(val, mgb::hash(op_.transposeA));
  4438. val = mgb::hash_pair_combine(val, mgb::hash(op_.transposeB));
  4439. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.compute_mode));
  4440. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format));
  4441. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.strategy));
  4442. val = mgb::hash_pair_combine(val, mgb::hash(op_.workspace_limit));
  4443. val = mgb::hash_pair_combine(val, mgb::hash(op_.dimA));
  4444. val = mgb::hash_pair_combine(val, mgb::hash(op_.dimB));
  4445. return val;
  4446. }
  4447. bool MatrixMul_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4448. auto &&a_ = lhs_.cast_final_safe<MatrixMul>(),
  4449. &&b_ = rhs_.cast_final_safe<MatrixMul>();
  4450. static_cast<void>(a_);
  4451. static_cast<void>(b_);
  4452. if (a_.transposeA != b_.transposeA) return false;
  4453. if (a_.transposeB != b_.transposeB) return false;
  4454. if (a_.compute_mode != b_.compute_mode) return false;
  4455. if (a_.format != b_.format) return false;
  4456. if (a_.strategy != b_.strategy) return false;
  4457. if (a_.workspace_limit != b_.workspace_limit) return false;
  4458. if (a_.dimA != b_.dimA) return false;
  4459. if (a_.dimB != b_.dimB) return false;
  4460. return true;
  4461. }
  4462. std::vector<std::pair<const char*, std::string>> MatrixMul_props_impl(const OpDef& def_) {
  4463. auto&& op_ = def_.cast_final_safe<MatrixMul>();
  4464. static_cast<void>(op_);
  4465. std::vector<std::pair<const char*, std::string>> props_;
  4466. props_.emplace_back("transposeA", std::to_string(op_.transposeA));
  4467. props_.emplace_back("transposeB", std::to_string(op_.transposeB));
  4468. switch (op_.compute_mode){
  4469. case MatrixMul::ComputeMode::DEFAULT:
  4470. props_.emplace_back("compute_mode", "DEFAULT");
  4471. break;
  4472. case MatrixMul::ComputeMode::FLOAT32:
  4473. props_.emplace_back("compute_mode", "FLOAT32");
  4474. break;
  4475. default:
  4476. props_.emplace_back("compute_mode", "INVALID");
  4477. break;
  4478. }
  4479. switch (op_.format){
  4480. case MatrixMul::Format::DEFAULT:
  4481. props_.emplace_back("format", "DEFAULT");
  4482. break;
  4483. case MatrixMul::Format::MK4:
  4484. props_.emplace_back("format", "MK4");
  4485. break;
  4486. case MatrixMul::Format::MK8:
  4487. props_.emplace_back("format", "MK8");
  4488. break;
  4489. case MatrixMul::Format::MK4_DOT:
  4490. props_.emplace_back("format", "MK4_DOT");
  4491. break;
  4492. case MatrixMul::Format::N32K4_DOT:
  4493. props_.emplace_back("format", "N32K4_DOT");
  4494. break;
  4495. default:
  4496. props_.emplace_back("format", "INVALID");
  4497. break;
  4498. }
  4499. switch (op_.strategy){
  4500. case MatrixMul::Strategy::HEURISTIC:
  4501. props_.emplace_back("strategy", "HEURISTIC");
  4502. break;
  4503. case MatrixMul::Strategy::PROFILE:
  4504. props_.emplace_back("strategy", "PROFILE");
  4505. break;
  4506. case MatrixMul::Strategy::REPRODUCIBLE:
  4507. props_.emplace_back("strategy", "REPRODUCIBLE");
  4508. break;
  4509. case MatrixMul::Strategy::OPTIMIZED:
  4510. props_.emplace_back("strategy", "OPTIMIZED");
  4511. break;
  4512. default:
  4513. props_.emplace_back("strategy", "INVALID");
  4514. break;
  4515. }
  4516. props_.emplace_back("workspace_limit", std::to_string(op_.workspace_limit));
  4517. props_.emplace_back("dimA", std::to_string(op_.dimA));
  4518. props_.emplace_back("dimB", std::to_string(op_.dimB));
  4519. return props_;
  4520. }
  4521. std::string MatrixMul_make_name_impl(const OpDef& def_) {
  4522. auto&& op_ = def_.cast_final_safe<MatrixMul>();
  4523. static_cast<void>(op_);
  4524. return "MatrixMul";
  4525. }
  4526. } // anonymous namespace
  4527. OP_TRAIT_REG(MatrixMul, MatrixMul)
  4528. .hash(MatrixMul_hash_impl)
  4529. .is_same_st(MatrixMul_is_same_st_impl)
  4530. .props(MatrixMul_props_impl)
  4531. .make_name(MatrixMul_make_name_impl);
  4532. MGB_DYN_TYPE_OBJ_FINAL_IMPL(MeshIndexing);
  4533. namespace {
  4534. size_t MeshIndexing_hash_impl(const OpDef& def_) {
  4535. auto&& op_ = def_.cast_final_safe<MeshIndexing>();
  4536. static_cast<void>(op_);
  4537. size_t val = mgb::hash(op_.dyn_typeinfo());
  4538. val = mgb::hash_pair_combine(val, mgb::hash(op_.items));
  4539. return val;
  4540. }
  4541. bool MeshIndexing_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4542. auto &&a_ = lhs_.cast_final_safe<MeshIndexing>(),
  4543. &&b_ = rhs_.cast_final_safe<MeshIndexing>();
  4544. static_cast<void>(a_);
  4545. static_cast<void>(b_);
  4546. if (a_.items != b_.items) return false;
  4547. return true;
  4548. }
  4549. std::vector<std::pair<const char*, std::string>> MeshIndexing_props_impl(const OpDef& def_) {
  4550. auto&& op_ = def_.cast_final_safe<MeshIndexing>();
  4551. static_cast<void>(op_);
  4552. std::vector<std::pair<const char*, std::string>> props_;
  4553. props_.emplace_back("items", "{std::vector}");
  4554. return props_;
  4555. }
  4556. std::string MeshIndexing_make_name_impl(const OpDef& def_) {
  4557. auto&& op_ = def_.cast_final_safe<MeshIndexing>();
  4558. static_cast<void>(op_);
  4559. return "MeshIndexing";
  4560. }
  4561. } // anonymous namespace
  4562. OP_TRAIT_REG(MeshIndexing, MeshIndexing)
  4563. .hash(MeshIndexing_hash_impl)
  4564. .is_same_st(MeshIndexing_is_same_st_impl)
  4565. .props(MeshIndexing_props_impl)
  4566. .make_name(MeshIndexing_make_name_impl);
  4567. MGB_DYN_TYPE_OBJ_FINAL_IMPL(NMSKeep);
  4568. namespace {
  4569. size_t NMSKeep_hash_impl(const OpDef& def_) {
  4570. auto&& op_ = def_.cast_final_safe<NMSKeep>();
  4571. static_cast<void>(op_);
  4572. size_t val = mgb::hash(op_.dyn_typeinfo());
  4573. val = mgb::hash_pair_combine(val, mgb::hash(op_.iou_thresh));
  4574. val = mgb::hash_pair_combine(val, mgb::hash(op_.max_output));
  4575. return val;
  4576. }
  4577. bool NMSKeep_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4578. auto &&a_ = lhs_.cast_final_safe<NMSKeep>(),
  4579. &&b_ = rhs_.cast_final_safe<NMSKeep>();
  4580. static_cast<void>(a_);
  4581. static_cast<void>(b_);
  4582. if (a_.iou_thresh != b_.iou_thresh) return false;
  4583. if (a_.max_output != b_.max_output) return false;
  4584. return true;
  4585. }
  4586. std::vector<std::pair<const char*, std::string>> NMSKeep_props_impl(const OpDef& def_) {
  4587. auto&& op_ = def_.cast_final_safe<NMSKeep>();
  4588. static_cast<void>(op_);
  4589. std::vector<std::pair<const char*, std::string>> props_;
  4590. props_.emplace_back("iou_thresh", std::to_string(op_.iou_thresh));
  4591. props_.emplace_back("max_output", std::to_string(op_.max_output));
  4592. return props_;
  4593. }
  4594. std::string NMSKeep_make_name_impl(const OpDef& def_) {
  4595. auto&& op_ = def_.cast_final_safe<NMSKeep>();
  4596. static_cast<void>(op_);
  4597. return "NMSKeep";
  4598. }
  4599. } // anonymous namespace
  4600. OP_TRAIT_REG(NMSKeep, NMSKeep)
  4601. .hash(NMSKeep_hash_impl)
  4602. .is_same_st(NMSKeep_is_same_st_impl)
  4603. .props(NMSKeep_props_impl)
  4604. .make_name(NMSKeep_make_name_impl);
  4605. MGB_DYN_TYPE_OBJ_FINAL_IMPL(NvOf);
  4606. namespace {
  4607. size_t NvOf_hash_impl(const OpDef& def_) {
  4608. auto&& op_ = def_.cast_final_safe<NvOf>();
  4609. static_cast<void>(op_);
  4610. size_t val = mgb::hash(op_.dyn_typeinfo());
  4611. val = mgb::hash_pair_combine(val, mgb::hash(op_.precision));
  4612. return val;
  4613. }
  4614. bool NvOf_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4615. auto &&a_ = lhs_.cast_final_safe<NvOf>(),
  4616. &&b_ = rhs_.cast_final_safe<NvOf>();
  4617. static_cast<void>(a_);
  4618. static_cast<void>(b_);
  4619. if (a_.precision != b_.precision) return false;
  4620. return true;
  4621. }
  4622. std::vector<std::pair<const char*, std::string>> NvOf_props_impl(const OpDef& def_) {
  4623. auto&& op_ = def_.cast_final_safe<NvOf>();
  4624. static_cast<void>(op_);
  4625. std::vector<std::pair<const char*, std::string>> props_;
  4626. props_.emplace_back("precision", std::to_string(op_.precision));
  4627. return props_;
  4628. }
  4629. std::string NvOf_make_name_impl(const OpDef& def_) {
  4630. auto&& op_ = def_.cast_final_safe<NvOf>();
  4631. static_cast<void>(op_);
  4632. return "NvOf";
  4633. }
  4634. } // anonymous namespace
  4635. OP_TRAIT_REG(NvOf, NvOf)
  4636. .hash(NvOf_hash_impl)
  4637. .is_same_st(NvOf_is_same_st_impl)
  4638. .props(NvOf_props_impl)
  4639. .make_name(NvOf_make_name_impl);
  4640. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Padding);
  4641. namespace {
  4642. size_t Padding_hash_impl(const OpDef& def_) {
  4643. auto&& op_ = def_.cast_final_safe<Padding>();
  4644. static_cast<void>(op_);
  4645. size_t val = mgb::hash(op_.dyn_typeinfo());
  4646. val = mgb::hash_pair_combine(val, mgb::hash(op_.front_offset_dim0));
  4647. val = mgb::hash_pair_combine(val, mgb::hash(op_.front_offset_dim1));
  4648. val = mgb::hash_pair_combine(val, mgb::hash(op_.front_offset_dim2));
  4649. val = mgb::hash_pair_combine(val, mgb::hash(op_.front_offset_dim3));
  4650. val = mgb::hash_pair_combine(val, mgb::hash(op_.front_offset_dim4));
  4651. val = mgb::hash_pair_combine(val, mgb::hash(op_.front_offset_dim5));
  4652. val = mgb::hash_pair_combine(val, mgb::hash(op_.front_offset_dim6));
  4653. val = mgb::hash_pair_combine(val, mgb::hash(op_.back_offset_dim0));
  4654. val = mgb::hash_pair_combine(val, mgb::hash(op_.back_offset_dim1));
  4655. val = mgb::hash_pair_combine(val, mgb::hash(op_.back_offset_dim2));
  4656. val = mgb::hash_pair_combine(val, mgb::hash(op_.back_offset_dim3));
  4657. val = mgb::hash_pair_combine(val, mgb::hash(op_.back_offset_dim4));
  4658. val = mgb::hash_pair_combine(val, mgb::hash(op_.back_offset_dim5));
  4659. val = mgb::hash_pair_combine(val, mgb::hash(op_.back_offset_dim6));
  4660. val = mgb::hash_pair_combine(val, mgb::hash(op_.padding_val));
  4661. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.padding_mode));
  4662. return val;
  4663. }
  4664. bool Padding_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4665. auto &&a_ = lhs_.cast_final_safe<Padding>(),
  4666. &&b_ = rhs_.cast_final_safe<Padding>();
  4667. static_cast<void>(a_);
  4668. static_cast<void>(b_);
  4669. if (a_.front_offset_dim0 != b_.front_offset_dim0) return false;
  4670. if (a_.front_offset_dim1 != b_.front_offset_dim1) return false;
  4671. if (a_.front_offset_dim2 != b_.front_offset_dim2) return false;
  4672. if (a_.front_offset_dim3 != b_.front_offset_dim3) return false;
  4673. if (a_.front_offset_dim4 != b_.front_offset_dim4) return false;
  4674. if (a_.front_offset_dim5 != b_.front_offset_dim5) return false;
  4675. if (a_.front_offset_dim6 != b_.front_offset_dim6) return false;
  4676. if (a_.back_offset_dim0 != b_.back_offset_dim0) return false;
  4677. if (a_.back_offset_dim1 != b_.back_offset_dim1) return false;
  4678. if (a_.back_offset_dim2 != b_.back_offset_dim2) return false;
  4679. if (a_.back_offset_dim3 != b_.back_offset_dim3) return false;
  4680. if (a_.back_offset_dim4 != b_.back_offset_dim4) return false;
  4681. if (a_.back_offset_dim5 != b_.back_offset_dim5) return false;
  4682. if (a_.back_offset_dim6 != b_.back_offset_dim6) return false;
  4683. if (a_.padding_val != b_.padding_val) return false;
  4684. if (a_.padding_mode != b_.padding_mode) return false;
  4685. return true;
  4686. }
  4687. std::vector<std::pair<const char*, std::string>> Padding_props_impl(const OpDef& def_) {
  4688. auto&& op_ = def_.cast_final_safe<Padding>();
  4689. static_cast<void>(op_);
  4690. std::vector<std::pair<const char*, std::string>> props_;
  4691. props_.emplace_back("front_offset_dim0", std::to_string(op_.front_offset_dim0));
  4692. props_.emplace_back("front_offset_dim1", std::to_string(op_.front_offset_dim1));
  4693. props_.emplace_back("front_offset_dim2", std::to_string(op_.front_offset_dim2));
  4694. props_.emplace_back("front_offset_dim3", std::to_string(op_.front_offset_dim3));
  4695. props_.emplace_back("front_offset_dim4", std::to_string(op_.front_offset_dim4));
  4696. props_.emplace_back("front_offset_dim5", std::to_string(op_.front_offset_dim5));
  4697. props_.emplace_back("front_offset_dim6", std::to_string(op_.front_offset_dim6));
  4698. props_.emplace_back("back_offset_dim0", std::to_string(op_.back_offset_dim0));
  4699. props_.emplace_back("back_offset_dim1", std::to_string(op_.back_offset_dim1));
  4700. props_.emplace_back("back_offset_dim2", std::to_string(op_.back_offset_dim2));
  4701. props_.emplace_back("back_offset_dim3", std::to_string(op_.back_offset_dim3));
  4702. props_.emplace_back("back_offset_dim4", std::to_string(op_.back_offset_dim4));
  4703. props_.emplace_back("back_offset_dim5", std::to_string(op_.back_offset_dim5));
  4704. props_.emplace_back("back_offset_dim6", std::to_string(op_.back_offset_dim6));
  4705. props_.emplace_back("padding_val", std::to_string(op_.padding_val));
  4706. switch (op_.padding_mode){
  4707. case Padding::PaddingMode::REPLICATE:
  4708. props_.emplace_back("padding_mode", "REPLICATE");
  4709. break;
  4710. case Padding::PaddingMode::REFLECT:
  4711. props_.emplace_back("padding_mode", "REFLECT");
  4712. break;
  4713. case Padding::PaddingMode::CONSTANT:
  4714. props_.emplace_back("padding_mode", "CONSTANT");
  4715. break;
  4716. default:
  4717. props_.emplace_back("padding_mode", "INVALID");
  4718. break;
  4719. }
  4720. return props_;
  4721. }
  4722. std::string Padding_make_name_impl(const OpDef& def_) {
  4723. auto&& op_ = def_.cast_final_safe<Padding>();
  4724. static_cast<void>(op_);
  4725. return "Padding";
  4726. }
  4727. } // anonymous namespace
  4728. OP_TRAIT_REG(Padding, Padding)
  4729. .hash(Padding_hash_impl)
  4730. .is_same_st(Padding_is_same_st_impl)
  4731. .props(Padding_props_impl)
  4732. .make_name(Padding_make_name_impl);
  4733. MGB_DYN_TYPE_OBJ_FINAL_IMPL(ParamPackConcat);
  4734. namespace {
  4735. size_t ParamPackConcat_hash_impl(const OpDef& def_) {
  4736. auto&& op_ = def_.cast_final_safe<ParamPackConcat>();
  4737. static_cast<void>(op_);
  4738. size_t val = mgb::hash(op_.dyn_typeinfo());
  4739. val = mgb::hash_pair_combine(val, mgb::hash(op_.offsets));
  4740. return val;
  4741. }
  4742. bool ParamPackConcat_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4743. auto &&a_ = lhs_.cast_final_safe<ParamPackConcat>(),
  4744. &&b_ = rhs_.cast_final_safe<ParamPackConcat>();
  4745. static_cast<void>(a_);
  4746. static_cast<void>(b_);
  4747. if (a_.offsets != b_.offsets) return false;
  4748. return true;
  4749. }
  4750. std::vector<std::pair<const char*, std::string>> ParamPackConcat_props_impl(const OpDef& def_) {
  4751. auto&& op_ = def_.cast_final_safe<ParamPackConcat>();
  4752. static_cast<void>(op_);
  4753. std::vector<std::pair<const char*, std::string>> props_;
  4754. props_.emplace_back("offsets", "{std::vector}");
  4755. return props_;
  4756. }
  4757. std::string ParamPackConcat_make_name_impl(const OpDef& def_) {
  4758. auto&& op_ = def_.cast_final_safe<ParamPackConcat>();
  4759. static_cast<void>(op_);
  4760. return "ParamPackConcat";
  4761. }
  4762. } // anonymous namespace
  4763. OP_TRAIT_REG(ParamPackConcat, ParamPackConcat)
  4764. .hash(ParamPackConcat_hash_impl)
  4765. .is_same_st(ParamPackConcat_is_same_st_impl)
  4766. .props(ParamPackConcat_props_impl)
  4767. .make_name(ParamPackConcat_make_name_impl);
  4768. MGB_DYN_TYPE_OBJ_FINAL_IMPL(ParamPackSplit);
  4769. namespace {
  4770. size_t ParamPackSplit_hash_impl(const OpDef& def_) {
  4771. auto&& op_ = def_.cast_final_safe<ParamPackSplit>();
  4772. static_cast<void>(op_);
  4773. size_t val = mgb::hash(op_.dyn_typeinfo());
  4774. val = mgb::hash_pair_combine(val, mgb::hash(op_.offsets));
  4775. val = mgb::hash_pair_combine(val, mgb::hash(op_.shapes));
  4776. return val;
  4777. }
  4778. bool ParamPackSplit_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4779. auto &&a_ = lhs_.cast_final_safe<ParamPackSplit>(),
  4780. &&b_ = rhs_.cast_final_safe<ParamPackSplit>();
  4781. static_cast<void>(a_);
  4782. static_cast<void>(b_);
  4783. if (a_.offsets != b_.offsets) return false;
  4784. if (a_.shapes != b_.shapes) return false;
  4785. return true;
  4786. }
  4787. std::vector<std::pair<const char*, std::string>> ParamPackSplit_props_impl(const OpDef& def_) {
  4788. auto&& op_ = def_.cast_final_safe<ParamPackSplit>();
  4789. static_cast<void>(op_);
  4790. std::vector<std::pair<const char*, std::string>> props_;
  4791. props_.emplace_back("offsets", "{std::vector}");
  4792. props_.emplace_back("shapes", "{std::vector}");
  4793. return props_;
  4794. }
  4795. std::string ParamPackSplit_make_name_impl(const OpDef& def_) {
  4796. auto&& op_ = def_.cast_final_safe<ParamPackSplit>();
  4797. static_cast<void>(op_);
  4798. return "ParamPackSplit";
  4799. }
  4800. } // anonymous namespace
  4801. OP_TRAIT_REG(ParamPackSplit, ParamPackSplit)
  4802. .hash(ParamPackSplit_hash_impl)
  4803. .is_same_st(ParamPackSplit_is_same_st_impl)
  4804. .props(ParamPackSplit_props_impl)
  4805. .make_name(ParamPackSplit_make_name_impl);
  4806. MGB_DYN_TYPE_OBJ_FINAL_IMPL(PermutationRNG);
  4807. namespace {
  4808. size_t PermutationRNG_hash_impl(const OpDef& def_) {
  4809. auto&& op_ = def_.cast_final_safe<PermutationRNG>();
  4810. static_cast<void>(op_);
  4811. return mgb::hash_pair_combine(
  4812. mgb::hash(op_.dyn_typeinfo()),
  4813. mgb::hash_pair_combine(
  4814. mgb::hash(op_.handle),
  4815. mgb::hash(op_.dtype.enumv())
  4816. )
  4817. );
  4818. }
  4819. bool PermutationRNG_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4820. auto &&a_ = lhs_.cast_final_safe<PermutationRNG>(),
  4821. &&b_ = rhs_.cast_final_safe<PermutationRNG>();
  4822. static_cast<void>(a_);
  4823. static_cast<void>(b_);
  4824. return a_.handle == b_.handle && a_.dtype == b_.dtype;}
  4825. std::vector<std::pair<const char*, std::string>> PermutationRNG_props_impl(const OpDef& def_) {
  4826. auto&& op_ = def_.cast_final_safe<PermutationRNG>();
  4827. static_cast<void>(op_);
  4828. std::vector<std::pair<const char*, std::string>> props_;
  4829. props_.emplace_back("seed", std::to_string(op_.seed));
  4830. props_.emplace_back("dtype", op_.dtype.name());
  4831. props_.emplace_back("handle", std::to_string(op_.handle));
  4832. return props_;
  4833. }
  4834. std::string PermutationRNG_make_name_impl(const OpDef& def_) {
  4835. auto&& op_ = def_.cast_final_safe<PermutationRNG>();
  4836. static_cast<void>(op_);
  4837. return "PermutationRNG";
  4838. }
  4839. } // anonymous namespace
  4840. OP_TRAIT_REG(PermutationRNG, PermutationRNG)
  4841. .hash(PermutationRNG_hash_impl)
  4842. .is_same_st(PermutationRNG_is_same_st_impl)
  4843. .props(PermutationRNG_props_impl)
  4844. .make_name(PermutationRNG_make_name_impl);
  4845. MGB_DYN_TYPE_OBJ_FINAL_IMPL(PixelShuffle);
  4846. namespace {
  4847. size_t PixelShuffle_hash_impl(const OpDef& def_) {
  4848. auto&& op_ = def_.cast_final_safe<PixelShuffle>();
  4849. static_cast<void>(op_);
  4850. size_t val = mgb::hash(op_.dyn_typeinfo());
  4851. val = mgb::hash_pair_combine(val, mgb::hash(op_.factor));
  4852. return val;
  4853. }
  4854. bool PixelShuffle_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4855. auto &&a_ = lhs_.cast_final_safe<PixelShuffle>(),
  4856. &&b_ = rhs_.cast_final_safe<PixelShuffle>();
  4857. static_cast<void>(a_);
  4858. static_cast<void>(b_);
  4859. if (a_.factor != b_.factor) return false;
  4860. return true;
  4861. }
  4862. std::vector<std::pair<const char*, std::string>> PixelShuffle_props_impl(const OpDef& def_) {
  4863. auto&& op_ = def_.cast_final_safe<PixelShuffle>();
  4864. static_cast<void>(op_);
  4865. std::vector<std::pair<const char*, std::string>> props_;
  4866. props_.emplace_back("factor", std::to_string(op_.factor));
  4867. return props_;
  4868. }
  4869. std::string PixelShuffle_make_name_impl(const OpDef& def_) {
  4870. auto&& op_ = def_.cast_final_safe<PixelShuffle>();
  4871. static_cast<void>(op_);
  4872. return "PixelShuffle";
  4873. }
  4874. } // anonymous namespace
  4875. OP_TRAIT_REG(PixelShuffle, PixelShuffle)
  4876. .hash(PixelShuffle_hash_impl)
  4877. .is_same_st(PixelShuffle_is_same_st_impl)
  4878. .props(PixelShuffle_props_impl)
  4879. .make_name(PixelShuffle_make_name_impl);
  4880. MGB_DYN_TYPE_OBJ_FINAL_IMPL(PixelShuffleBackward);
  4881. namespace {
  4882. size_t PixelShuffleBackward_hash_impl(const OpDef& def_) {
  4883. auto&& op_ = def_.cast_final_safe<PixelShuffleBackward>();
  4884. static_cast<void>(op_);
  4885. size_t val = mgb::hash(op_.dyn_typeinfo());
  4886. val = mgb::hash_pair_combine(val, mgb::hash(op_.factor));
  4887. return val;
  4888. }
  4889. bool PixelShuffleBackward_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4890. auto &&a_ = lhs_.cast_final_safe<PixelShuffleBackward>(),
  4891. &&b_ = rhs_.cast_final_safe<PixelShuffleBackward>();
  4892. static_cast<void>(a_);
  4893. static_cast<void>(b_);
  4894. if (a_.factor != b_.factor) return false;
  4895. return true;
  4896. }
  4897. std::vector<std::pair<const char*, std::string>> PixelShuffleBackward_props_impl(const OpDef& def_) {
  4898. auto&& op_ = def_.cast_final_safe<PixelShuffleBackward>();
  4899. static_cast<void>(op_);
  4900. std::vector<std::pair<const char*, std::string>> props_;
  4901. props_.emplace_back("factor", std::to_string(op_.factor));
  4902. return props_;
  4903. }
  4904. std::string PixelShuffleBackward_make_name_impl(const OpDef& def_) {
  4905. auto&& op_ = def_.cast_final_safe<PixelShuffleBackward>();
  4906. static_cast<void>(op_);
  4907. return "PixelShuffleBackward";
  4908. }
  4909. } // anonymous namespace
  4910. OP_TRAIT_REG(PixelShuffleBackward, PixelShuffleBackward)
  4911. .hash(PixelShuffleBackward_hash_impl)
  4912. .is_same_st(PixelShuffleBackward_is_same_st_impl)
  4913. .props(PixelShuffleBackward_props_impl)
  4914. .make_name(PixelShuffleBackward_make_name_impl);
  4915. MGB_DYN_TYPE_OBJ_FINAL_IMPL(PoissonRNG);
  4916. namespace {
  4917. size_t PoissonRNG_hash_impl(const OpDef& def_) {
  4918. auto&& op_ = def_.cast_final_safe<PoissonRNG>();
  4919. static_cast<void>(op_);
  4920. return mgb::hash_pair_combine(
  4921. mgb::hash(op_.dyn_typeinfo()),
  4922. mgb::hash(op_.handle)
  4923. );
  4924. }
  4925. bool PoissonRNG_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4926. auto &&a_ = lhs_.cast_final_safe<PoissonRNG>(),
  4927. &&b_ = rhs_.cast_final_safe<PoissonRNG>();
  4928. static_cast<void>(a_);
  4929. static_cast<void>(b_);
  4930. return a_.handle == b_.handle;}
  4931. std::vector<std::pair<const char*, std::string>> PoissonRNG_props_impl(const OpDef& def_) {
  4932. auto&& op_ = def_.cast_final_safe<PoissonRNG>();
  4933. static_cast<void>(op_);
  4934. std::vector<std::pair<const char*, std::string>> props_;
  4935. props_.emplace_back("seed", std::to_string(op_.seed));
  4936. props_.emplace_back("handle", std::to_string(op_.handle));
  4937. return props_;
  4938. }
  4939. std::string PoissonRNG_make_name_impl(const OpDef& def_) {
  4940. auto&& op_ = def_.cast_final_safe<PoissonRNG>();
  4941. static_cast<void>(op_);
  4942. return "PoissonRNG";
  4943. }
  4944. } // anonymous namespace
  4945. OP_TRAIT_REG(PoissonRNG, PoissonRNG)
  4946. .hash(PoissonRNG_hash_impl)
  4947. .is_same_st(PoissonRNG_is_same_st_impl)
  4948. .props(PoissonRNG_props_impl)
  4949. .make_name(PoissonRNG_make_name_impl);
  4950. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Pooling);
  4951. namespace {
  4952. size_t Pooling_hash_impl(const OpDef& def_) {
  4953. auto&& op_ = def_.cast_final_safe<Pooling>();
  4954. static_cast<void>(op_);
  4955. size_t val = mgb::hash(op_.dyn_typeinfo());
  4956. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode));
  4957. val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_h));
  4958. val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_w));
  4959. val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_h));
  4960. val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_w));
  4961. val = mgb::hash_pair_combine(val, mgb::hash(op_.window_h));
  4962. val = mgb::hash_pair_combine(val, mgb::hash(op_.window_w));
  4963. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format));
  4964. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.strategy));
  4965. val = mgb::hash_pair_combine(val, mgb::hash(op_.workspace_limit));
  4966. return val;
  4967. }
  4968. bool Pooling_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4969. auto &&a_ = lhs_.cast_final_safe<Pooling>(),
  4970. &&b_ = rhs_.cast_final_safe<Pooling>();
  4971. static_cast<void>(a_);
  4972. static_cast<void>(b_);
  4973. if (a_.mode != b_.mode) return false;
  4974. if (a_.pad_h != b_.pad_h) return false;
  4975. if (a_.pad_w != b_.pad_w) return false;
  4976. if (a_.stride_h != b_.stride_h) return false;
  4977. if (a_.stride_w != b_.stride_w) return false;
  4978. if (a_.window_h != b_.window_h) return false;
  4979. if (a_.window_w != b_.window_w) return false;
  4980. if (a_.format != b_.format) return false;
  4981. if (a_.strategy != b_.strategy) return false;
  4982. if (a_.workspace_limit != b_.workspace_limit) return false;
  4983. return true;
  4984. }
  4985. std::vector<std::pair<const char*, std::string>> Pooling_props_impl(const OpDef& def_) {
  4986. auto&& op_ = def_.cast_final_safe<Pooling>();
  4987. static_cast<void>(op_);
  4988. std::vector<std::pair<const char*, std::string>> props_;
  4989. switch (op_.mode){
  4990. case Pooling::Mode::MAX:
  4991. props_.emplace_back("mode", "MAX");
  4992. break;
  4993. case Pooling::Mode::AVERAGE:
  4994. props_.emplace_back("mode", "AVERAGE");
  4995. break;
  4996. case Pooling::Mode::AVERAGE_COUNT_EXCLUDE_PADDING:
  4997. props_.emplace_back("mode", "AVERAGE_COUNT_EXCLUDE_PADDING");
  4998. break;
  4999. default:
  5000. props_.emplace_back("mode", "INVALID");
  5001. break;
  5002. }
  5003. props_.emplace_back("pad_h", std::to_string(op_.pad_h));
  5004. props_.emplace_back("pad_w", std::to_string(op_.pad_w));
  5005. props_.emplace_back("stride_h", std::to_string(op_.stride_h));
  5006. props_.emplace_back("stride_w", std::to_string(op_.stride_w));
  5007. props_.emplace_back("window_h", std::to_string(op_.window_h));
  5008. props_.emplace_back("window_w", std::to_string(op_.window_w));
  5009. switch (op_.format){
  5010. case Pooling::Format::NCHW:
  5011. props_.emplace_back("format", "NCHW");
  5012. break;
  5013. case Pooling::Format::NHWC:
  5014. props_.emplace_back("format", "NHWC");
  5015. break;
  5016. case Pooling::Format::NHWCD4:
  5017. props_.emplace_back("format", "NHWCD4");
  5018. break;
  5019. case Pooling::Format::NCHW4:
  5020. props_.emplace_back("format", "NCHW4");
  5021. break;
  5022. case Pooling::Format::NCHW8:
  5023. props_.emplace_back("format", "NCHW8");
  5024. break;
  5025. case Pooling::Format::NCHW32:
  5026. props_.emplace_back("format", "NCHW32");
  5027. break;
  5028. case Pooling::Format::NCHW88:
  5029. props_.emplace_back("format", "NCHW88");
  5030. break;
  5031. case Pooling::Format::NCHW44:
  5032. props_.emplace_back("format", "NCHW44");
  5033. break;
  5034. case Pooling::Format::NCHW44_DOT:
  5035. props_.emplace_back("format", "NCHW44_DOT");
  5036. break;
  5037. case Pooling::Format::NCHW4_NCHW32:
  5038. props_.emplace_back("format", "NCHW4_NCHW32");
  5039. break;
  5040. case Pooling::Format::NCHW32_NCHW4:
  5041. props_.emplace_back("format", "NCHW32_NCHW4");
  5042. break;
  5043. case Pooling::Format::NCHW4_NCHW:
  5044. props_.emplace_back("format", "NCHW4_NCHW");
  5045. break;
  5046. case Pooling::Format::NHWC_NCHW:
  5047. props_.emplace_back("format", "NHWC_NCHW");
  5048. break;
  5049. case Pooling::Format::NHWC_NCHW4_IC_SMALL:
  5050. props_.emplace_back("format", "NHWC_NCHW4_IC_SMALL");
  5051. break;
  5052. case Pooling::Format::NCHW_NCHW4_IC_SMALL:
  5053. props_.emplace_back("format", "NCHW_NCHW4_IC_SMALL");
  5054. break;
  5055. case Pooling::Format::CHWN4:
  5056. props_.emplace_back("format", "CHWN4");
  5057. break;
  5058. case Pooling::Format::NCHW64:
  5059. props_.emplace_back("format", "NCHW64");
  5060. break;
  5061. case Pooling::Format::NCHW4_NHWC:
  5062. props_.emplace_back("format", "NCHW4_NHWC");
  5063. break;
  5064. default:
  5065. props_.emplace_back("format", "INVALID");
  5066. break;
  5067. }
  5068. switch (op_.strategy){
  5069. case Pooling::Strategy::HEURISTIC:
  5070. props_.emplace_back("strategy", "HEURISTIC");
  5071. break;
  5072. case Pooling::Strategy::PROFILE:
  5073. props_.emplace_back("strategy", "PROFILE");
  5074. break;
  5075. case Pooling::Strategy::REPRODUCIBLE:
  5076. props_.emplace_back("strategy", "REPRODUCIBLE");
  5077. break;
  5078. case Pooling::Strategy::OPTIMIZED:
  5079. props_.emplace_back("strategy", "OPTIMIZED");
  5080. break;
  5081. default:
  5082. props_.emplace_back("strategy", "INVALID");
  5083. break;
  5084. }
  5085. props_.emplace_back("workspace_limit", std::to_string(op_.workspace_limit));
  5086. return props_;
  5087. }
  5088. std::string Pooling_make_name_impl(const OpDef& def_) {
  5089. auto&& op_ = def_.cast_final_safe<Pooling>();
  5090. static_cast<void>(op_);
  5091. return "Pooling";
  5092. }
  5093. } // anonymous namespace
  5094. OP_TRAIT_REG(Pooling, Pooling)
  5095. .hash(Pooling_hash_impl)
  5096. .is_same_st(Pooling_is_same_st_impl)
  5097. .props(Pooling_props_impl)
  5098. .make_name(Pooling_make_name_impl);
  5099. MGB_DYN_TYPE_OBJ_FINAL_IMPL(RNN);
  5100. namespace {
  5101. size_t RNN_hash_impl(const OpDef& def_) {
  5102. auto&& op_ = def_.cast_final_safe<RNN>();
  5103. static_cast<void>(op_);
  5104. size_t val = mgb::hash(op_.dyn_typeinfo());
  5105. val = mgb::hash_pair_combine(val, mgb::hash(op_.num_layers));
  5106. val = mgb::hash_pair_combine(val, mgb::hash(op_.bidirectional));
  5107. val = mgb::hash_pair_combine(val, mgb::hash(op_.bias));
  5108. val = mgb::hash_pair_combine(val, mgb::hash(op_.hidden_size));
  5109. val = mgb::hash_pair_combine(val, mgb::hash(op_.dropout));
  5110. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.nonlineMode));
  5111. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.fwd_mode));
  5112. return val;
  5113. }
  5114. bool RNN_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  5115. auto &&a_ = lhs_.cast_final_safe<RNN>(),
  5116. &&b_ = rhs_.cast_final_safe<RNN>();
  5117. static_cast<void>(a_);
  5118. static_cast<void>(b_);
  5119. if (a_.num_layers != b_.num_layers) return false;
  5120. if (a_.bidirectional != b_.bidirectional) return false;
  5121. if (a_.bias != b_.bias) return false;
  5122. if (a_.hidden_size != b_.hidden_size) return false;
  5123. if (a_.dropout != b_.dropout) return false;
  5124. if (a_.nonlineMode != b_.nonlineMode) return false;
  5125. if (a_.fwd_mode != b_.fwd_mode) return false;
  5126. return true;
  5127. }
  5128. std::vector<std::pair<const char*, std::string>> RNN_props_impl(const OpDef& def_) {
  5129. auto&& op_ = def_.cast_final_safe<RNN>();
  5130. static_cast<void>(op_);
  5131. std::vector<std::pair<const char*, std::string>> props_;
  5132. props_.emplace_back("num_layers", std::to_string(op_.num_layers));
  5133. props_.emplace_back("bidirectional", std::to_string(op_.bidirectional));
  5134. props_.emplace_back("bias", std::to_string(op_.bias));
  5135. props_.emplace_back("hidden_size", std::to_string(op_.hidden_size));
  5136. props_.emplace_back("dropout", std::to_string(op_.dropout));
  5137. switch (op_.nonlineMode){
  5138. case RNN::NonlineMode::IDENTITY:
  5139. props_.emplace_back("nonlineMode", "IDENTITY");
  5140. break;
  5141. case RNN::NonlineMode::RELU:
  5142. props_.emplace_back("nonlineMode", "RELU");
  5143. break;
  5144. case RNN::NonlineMode::TANH:
  5145. props_.emplace_back("nonlineMode", "TANH");
  5146. break;
  5147. default:
  5148. props_.emplace_back("nonlineMode", "INVALID");
  5149. break;
  5150. }
  5151. switch (op_.fwd_mode){
  5152. case RNN::FwdMode::TRAINING:
  5153. props_.emplace_back("fwd_mode", "TRAINING");
  5154. break;
  5155. case RNN::FwdMode::INFERENCE:
  5156. props_.emplace_back("fwd_mode", "INFERENCE");
  5157. break;
  5158. default:
  5159. props_.emplace_back("fwd_mode", "INVALID");
  5160. break;
  5161. }
  5162. return props_;
  5163. }
  5164. std::string RNN_make_name_impl(const OpDef& def_) {
  5165. auto&& op_ = def_.cast_final_safe<RNN>();
  5166. static_cast<void>(op_);
  5167. return "RNN";
  5168. }
  5169. } // anonymous namespace
  5170. OP_TRAIT_REG(RNN, RNN)
  5171. .hash(RNN_hash_impl)
  5172. .is_same_st(RNN_is_same_st_impl)
  5173. .props(RNN_props_impl)
  5174. .make_name(RNN_make_name_impl);
  5175. MGB_DYN_TYPE_OBJ_FINAL_IMPL(RNNCell);
  5176. namespace {
  5177. size_t RNNCell_hash_impl(const OpDef& def_) {
  5178. auto&& op_ = def_.cast_final_safe<RNNCell>();
  5179. static_cast<void>(op_);
  5180. size_t val = mgb::hash(op_.dyn_typeinfo());
  5181. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.nonlineMode));
  5182. return val;
  5183. }
  5184. bool RNNCell_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  5185. auto &&a_ = lhs_.cast_final_safe<RNNCell>(),
  5186. &&b_ = rhs_.cast_final_safe<RNNCell>();
  5187. static_cast<void>(a_);
  5188. static_cast<void>(b_);
  5189. if (a_.nonlineMode != b_.nonlineMode) return false;
  5190. return true;
  5191. }
  5192. std::vector<std::pair<const char*, std::string>> RNNCell_props_impl(const OpDef& def_) {
  5193. auto&& op_ = def_.cast_final_safe<RNNCell>();
  5194. static_cast<void>(op_);
  5195. std::vector<std::pair<const char*, std::string>> props_;
  5196. switch (op_.nonlineMode){
  5197. case RNNCell::NonlineMode::IDENTITY:
  5198. props_.emplace_back("nonlineMode", "IDENTITY");
  5199. break;
  5200. case RNNCell::NonlineMode::RELU:
  5201. props_.emplace_back("nonlineMode", "RELU");
  5202. break;
  5203. case RNNCell::NonlineMode::TANH:
  5204. props_.emplace_back("nonlineMode", "TANH");
  5205. break;
  5206. default:
  5207. props_.emplace_back("nonlineMode", "INVALID");
  5208. break;
  5209. }
  5210. return props_;
  5211. }
  5212. std::string RNNCell_make_name_impl(const OpDef& def_) {
  5213. auto&& op_ = def_.cast_final_safe<RNNCell>();
  5214. static_cast<void>(op_);
  5215. return "RNNCell";
  5216. }
  5217. } // anonymous namespace
  5218. OP_TRAIT_REG(RNNCell, RNNCell)
  5219. .hash(RNNCell_hash_impl)
  5220. .is_same_st(RNNCell_is_same_st_impl)
  5221. .props(RNNCell_props_impl)
  5222. .make_name(RNNCell_make_name_impl);
  5223. MGB_DYN_TYPE_OBJ_FINAL_IMPL(ROIAlign);
  5224. namespace {
  5225. size_t ROIAlign_hash_impl(const OpDef& def_) {
  5226. auto&& op_ = def_.cast_final_safe<ROIAlign>();
  5227. static_cast<void>(op_);
  5228. size_t val = mgb::hash(op_.dyn_typeinfo());
  5229. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode));
  5230. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format));
  5231. val = mgb::hash_pair_combine(val, mgb::hash(op_.spatial_scale));
  5232. val = mgb::hash_pair_combine(val, mgb::hash(op_.offset));
  5233. val = mgb::hash_pair_combine(val, mgb::hash(op_.pooled_height));
  5234. val = mgb::hash_pair_combine(val, mgb::hash(op_.pooled_width));
  5235. val = mgb::hash_pair_combine(val, mgb::hash(op_.sample_height));
  5236. val = mgb::hash_pair_combine(val, mgb::hash(op_.sample_width));
  5237. return val;
  5238. }
  5239. bool ROIAlign_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  5240. auto &&a_ = lhs_.cast_final_safe<ROIAlign>(),
  5241. &&b_ = rhs_.cast_final_safe<ROIAlign>();
  5242. static_cast<void>(a_);
  5243. static_cast<void>(b_);
  5244. if (a_.mode != b_.mode) return false;
  5245. if (a_.format != b_.format) return false;
  5246. if (a_.spatial_scale != b_.spatial_scale) return false;
  5247. if (a_.offset != b_.offset) return false;
  5248. if (a_.pooled_height != b_.pooled_height) return false;
  5249. if (a_.pooled_width != b_.pooled_width) return false;
  5250. if (a_.sample_height != b_.sample_height) return false;
  5251. if (a_.sample_width != b_.sample_width) return false;
  5252. return true;
  5253. }
  5254. std::vector<std::pair<const char*, std::string>> ROIAlign_props_impl(const OpDef& def_) {
  5255. auto&& op_ = def_.cast_final_safe<ROIAlign>();
  5256. static_cast<void>(op_);
  5257. std::vector<std::pair<const char*, std::string>> props_;
  5258. switch (op_.mode){
  5259. case ROIAlign::Mode::MAX:
  5260. props_.emplace_back("mode", "MAX");
  5261. break;
  5262. case ROIAlign::Mode::AVERAGE:
  5263. props_.emplace_back("mode", "AVERAGE");
  5264. break;
  5265. default:
  5266. props_.emplace_back("mode", "INVALID");
  5267. break;
  5268. }
  5269. switch (op_.format){
  5270. case ROIAlign::Format::NCHW:
  5271. props_.emplace_back("format", "NCHW");
  5272. break;
  5273. case ROIAlign::Format::NHWC:
  5274. props_.emplace_back("format", "NHWC");
  5275. break;
  5276. case ROIAlign::Format::NHWCD4:
  5277. props_.emplace_back("format", "NHWCD4");
  5278. break;
  5279. case ROIAlign::Format::NCHW4:
  5280. props_.emplace_back("format", "NCHW4");
  5281. break;
  5282. case ROIAlign::Format::NCHW8:
  5283. props_.emplace_back("format", "NCHW8");
  5284. break;
  5285. case ROIAlign::Format::NCHW32:
  5286. props_.emplace_back("format", "NCHW32");
  5287. break;
  5288. case ROIAlign::Format::NCHW88:
  5289. props_.emplace_back("format", "NCHW88");
  5290. break;
  5291. case ROIAlign::Format::NCHW44:
  5292. props_.emplace_back("format", "NCHW44");
  5293. break;
  5294. case ROIAlign::Format::NCHW44_DOT:
  5295. props_.emplace_back("format", "NCHW44_DOT");
  5296. break;
  5297. case ROIAlign::Format::NCHW4_NCHW32:
  5298. props_.emplace_back("format", "NCHW4_NCHW32");
  5299. break;
  5300. case ROIAlign::Format::NCHW32_NCHW4:
  5301. props_.emplace_back("format", "NCHW32_NCHW4");
  5302. break;
  5303. case ROIAlign::Format::NCHW4_NCHW:
  5304. props_.emplace_back("format", "NCHW4_NCHW");
  5305. break;
  5306. case ROIAlign::Format::NHWC_NCHW:
  5307. props_.emplace_back("format", "NHWC_NCHW");
  5308. break;
  5309. case ROIAlign::Format::NHWC_NCHW4_IC_SMALL:
  5310. props_.emplace_back("format", "NHWC_NCHW4_IC_SMALL");
  5311. break;
  5312. case ROIAlign::Format::NCHW_NCHW4_IC_SMALL:
  5313. props_.emplace_back("format", "NCHW_NCHW4_IC_SMALL");
  5314. break;
  5315. case ROIAlign::Format::CHWN4:
  5316. props_.emplace_back("format", "CHWN4");
  5317. break;
  5318. case ROIAlign::Format::NCHW64:
  5319. props_.emplace_back("format", "NCHW64");
  5320. break;
  5321. case ROIAlign::Format::NCHW4_NHWC:
  5322. props_.emplace_back("format", "NCHW4_NHWC");
  5323. break;
  5324. default:
  5325. props_.emplace_back("format", "INVALID");
  5326. break;
  5327. }
  5328. props_.emplace_back("spatial_scale", std::to_string(op_.spatial_scale));
  5329. props_.emplace_back("offset", std::to_string(op_.offset));
  5330. props_.emplace_back("pooled_height", std::to_string(op_.pooled_height));
  5331. props_.emplace_back("pooled_width", std::to_string(op_.pooled_width));
  5332. props_.emplace_back("sample_height", std::to_string(op_.sample_height));
  5333. props_.emplace_back("sample_width", std::to_string(op_.sample_width));
  5334. return props_;
  5335. }
  5336. std::string ROIAlign_make_name_impl(const OpDef& def_) {
  5337. auto&& op_ = def_.cast_final_safe<ROIAlign>();
  5338. static_cast<void>(op_);
  5339. return "ROIAlign";
  5340. }
  5341. } // anonymous namespace
  5342. OP_TRAIT_REG(ROIAlign, ROIAlign)
  5343. .hash(ROIAlign_hash_impl)
  5344. .is_same_st(ROIAlign_is_same_st_impl)
  5345. .props(ROIAlign_props_impl)
  5346. .make_name(ROIAlign_make_name_impl);
  5347. MGB_DYN_TYPE_OBJ_FINAL_IMPL(ROIPooling);
  5348. namespace {
  5349. size_t ROIPooling_hash_impl(const OpDef& def_) {
  5350. auto&& op_ = def_.cast_final_safe<ROIPooling>();
  5351. static_cast<void>(op_);
  5352. size_t val = mgb::hash(op_.dyn_typeinfo());
  5353. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode));
  5354. val = mgb::hash_pair_combine(val, mgb::hash(op_.scale));
  5355. return val;
  5356. }
  5357. bool ROIPooling_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  5358. auto &&a_ = lhs_.cast_final_safe<ROIPooling>(),
  5359. &&b_ = rhs_.cast_final_safe<ROIPooling>();
  5360. static_cast<void>(a_);
  5361. static_cast<void>(b_);
  5362. if (a_.mode != b_.mode) return false;
  5363. if (a_.scale != b_.scale) return false;
  5364. return true;
  5365. }
  5366. std::vector<std::pair<const char*, std::string>> ROIPooling_props_impl(const OpDef& def_) {
  5367. auto&& op_ = def_.cast_final_safe<ROIPooling>();
  5368. static_cast<void>(op_);
  5369. std::vector<std::pair<const char*, std::string>> props_;
  5370. switch (op_.mode){
  5371. case ROIPooling::Mode::MAX:
  5372. props_.emplace_back("mode", "MAX");
  5373. break;
  5374. case ROIPooling::Mode::AVERAGE:
  5375. props_.emplace_back("mode", "AVERAGE");
  5376. break;
  5377. default:
  5378. props_.emplace_back("mode", "INVALID");
  5379. break;
  5380. }
  5381. props_.emplace_back("scale", std::to_string(op_.scale));
  5382. return props_;
  5383. }
  5384. std::string ROIPooling_make_name_impl(const OpDef& def_) {
  5385. auto&& op_ = def_.cast_final_safe<ROIPooling>();
  5386. static_cast<void>(op_);
  5387. return "ROIPooling";
  5388. }
  5389. } // anonymous namespace
  5390. OP_TRAIT_REG(ROIPooling, ROIPooling)
  5391. .hash(ROIPooling_hash_impl)
  5392. .is_same_st(ROIPooling_is_same_st_impl)
  5393. .props(ROIPooling_props_impl)
  5394. .make_name(ROIPooling_make_name_impl);
  5395. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Reduce);
  5396. namespace {
  5397. size_t Reduce_hash_impl(const OpDef& def_) {
  5398. auto&& op_ = def_.cast_final_safe<Reduce>();
  5399. static_cast<void>(op_);
  5400. size_t val = mgb::hash(op_.dyn_typeinfo());
  5401. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode));
  5402. val = mgb::hash_pair_combine(val, mgb::hash(op_.axis));
  5403. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.data_type));
  5404. val = mgb::hash_pair_combine(val, mgb::hash(op_.keepdim));
  5405. return val;
  5406. }
  5407. bool Reduce_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  5408. auto &&a_ = lhs_.cast_final_safe<Reduce>(),
  5409. &&b_ = rhs_.cast_final_safe<Reduce>();
  5410. static_cast<void>(a_);
  5411. static_cast<void>(b_);
  5412. if (a_.mode != b_.mode) return false;
  5413. if (a_.axis != b_.axis) return false;
  5414. if (a_.data_type != b_.data_type) return false;
  5415. if (a_.keepdim != b_.keepdim) return false;
  5416. return true;
  5417. }
  5418. std::vector<std::pair<const char*, std::string>> Reduce_props_impl(const OpDef& def_) {
  5419. auto&& op_ = def_.cast_final_safe<Reduce>();
  5420. static_cast<void>(op_);
  5421. std::vector<std::pair<const char*, std::string>> props_;
  5422. switch (op_.mode){
  5423. case Reduce::Mode::SUM:
  5424. props_.emplace_back("mode", "SUM");
  5425. break;
  5426. case Reduce::Mode::SUM_SQR:
  5427. props_.emplace_back("mode", "SUM_SQR");
  5428. break;
  5429. case Reduce::Mode::PRODUCT:
  5430. props_.emplace_back("mode", "PRODUCT");
  5431. break;
  5432. case Reduce::Mode::MIN:
  5433. props_.emplace_back("mode", "MIN");
  5434. break;
  5435. case Reduce::Mode::MAX:
  5436. props_.emplace_back("mode", "MAX");
  5437. break;
  5438. case Reduce::Mode::MEAN:
  5439. props_.emplace_back("mode", "MEAN");
  5440. break;
  5441. default:
  5442. props_.emplace_back("mode", "INVALID");
  5443. break;
  5444. }
  5445. props_.emplace_back("axis", std::to_string(op_.axis));
  5446. switch (op_.data_type){
  5447. case Reduce::DataType::DEFAULT:
  5448. props_.emplace_back("data_type", "DEFAULT");
  5449. break;
  5450. case Reduce::DataType::FLOAT_IO16xC32:
  5451. props_.emplace_back("data_type", "FLOAT_IO16xC32");
  5452. break;
  5453. case Reduce::DataType::FLOAT_O32xC32:
  5454. props_.emplace_back("data_type", "FLOAT_O32xC32");
  5455. break;
  5456. case Reduce::DataType::FLOAT_O16xC32:
  5457. props_.emplace_back("data_type", "FLOAT_O16xC32");
  5458. break;
  5459. case Reduce::DataType::QUINT_I8xO32:
  5460. props_.emplace_back("data_type", "QUINT_I8xO32");
  5461. break;
  5462. case Reduce::DataType::QINT_I8xO32:
  5463. props_.emplace_back("data_type", "QINT_I8xO32");
  5464. break;
  5465. default:
  5466. props_.emplace_back("data_type", "INVALID");
  5467. break;
  5468. }
  5469. props_.emplace_back("keepdim", std::to_string(op_.keepdim));
  5470. return props_;
  5471. }
  5472. std::string Reduce_make_name_impl(const OpDef& def_) {
  5473. auto&& op_ = def_.cast_final_safe<Reduce>();
  5474. static_cast<void>(op_);
  5475. return "Reduce";
  5476. }
  5477. } // anonymous namespace
  5478. OP_TRAIT_REG(Reduce, Reduce)
  5479. .hash(Reduce_hash_impl)
  5480. .is_same_st(Reduce_is_same_st_impl)
  5481. .props(Reduce_props_impl)
  5482. .make_name(Reduce_make_name_impl);
  5483. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Remap);
  5484. namespace {
  5485. size_t Remap_hash_impl(const OpDef& def_) {
  5486. auto&& op_ = def_.cast_final_safe<Remap>();
  5487. static_cast<void>(op_);
  5488. size_t val = mgb::hash(op_.dyn_typeinfo());
  5489. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.imode));
  5490. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.border_type));
  5491. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format));
  5492. val = mgb::hash_pair_combine(val, mgb::hash(op_.scalar));
  5493. return val;
  5494. }
  5495. bool Remap_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  5496. auto &&a_ = lhs_.cast_final_safe<Remap>(),
  5497. &&b_ = rhs_.cast_final_safe<Remap>();
  5498. static_cast<void>(a_);
  5499. static_cast<void>(b_);
  5500. if (a_.imode != b_.imode) return false;
  5501. if (a_.border_type != b_.border_type) return false;
  5502. if (a_.format != b_.format) return false;
  5503. if (a_.scalar != b_.scalar) return false;
  5504. return true;
  5505. }
  5506. std::vector<std::pair<const char*, std::string>> Remap_props_impl(const OpDef& def_) {
  5507. auto&& op_ = def_.cast_final_safe<Remap>();
  5508. static_cast<void>(op_);
  5509. std::vector<std::pair<const char*, std::string>> props_;
  5510. switch (op_.imode){
  5511. case Remap::InterpolationMode::NEAREST:
  5512. props_.emplace_back("imode", "NEAREST");
  5513. break;
  5514. case Remap::InterpolationMode::LINEAR:
  5515. props_.emplace_back("imode", "LINEAR");
  5516. break;
  5517. case Remap::InterpolationMode::AREA:
  5518. props_.emplace_back("imode", "AREA");
  5519. break;
  5520. case Remap::InterpolationMode::CUBIC:
  5521. props_.emplace_back("imode", "CUBIC");
  5522. break;
  5523. case Remap::InterpolationMode::LANCZOS4:
  5524. props_.emplace_back("imode", "LANCZOS4");
  5525. break;
  5526. default:
  5527. props_.emplace_back("imode", "INVALID");
  5528. break;
  5529. }
  5530. switch (op_.border_type){
  5531. case Remap::BorderMode::REPLICATE:
  5532. props_.emplace_back("border_type", "REPLICATE");
  5533. break;
  5534. case Remap::BorderMode::REFLECT:
  5535. props_.emplace_back("border_type", "REFLECT");
  5536. break;
  5537. case Remap::BorderMode::REFLECT_101:
  5538. props_.emplace_back("border_type", "REFLECT_101");
  5539. break;
  5540. case Remap::BorderMode::WRAP:
  5541. props_.emplace_back("border_type", "WRAP");
  5542. break;
  5543. case Remap::BorderMode::CONSTANT:
  5544. props_.emplace_back("border_type", "CONSTANT");
  5545. break;
  5546. case Remap::BorderMode::TRANSPARENT:
  5547. props_.emplace_back("border_type", "TRANSPARENT");
  5548. break;
  5549. case Remap::BorderMode::ISOLATED:
  5550. props_.emplace_back("border_type", "ISOLATED");
  5551. break;
  5552. default:
  5553. props_.emplace_back("border_type", "INVALID");
  5554. break;
  5555. }
  5556. switch (op_.format){
  5557. case Remap::Format::NCHW:
  5558. props_.emplace_back("format", "NCHW");
  5559. break;
  5560. case Remap::Format::NHWC:
  5561. props_.emplace_back("format", "NHWC");
  5562. break;
  5563. case Remap::Format::NHWCD4:
  5564. props_.emplace_back("format", "NHWCD4");
  5565. break;
  5566. case Remap::Format::NCHW4:
  5567. props_.emplace_back("format", "NCHW4");
  5568. break;
  5569. case Remap::Format::NCHW8:
  5570. props_.emplace_back("format", "NCHW8");
  5571. break;
  5572. case Remap::Format::NCHW32:
  5573. props_.emplace_back("format", "NCHW32");
  5574. break;
  5575. case Remap::Format::NCHW88:
  5576. props_.emplace_back("format", "NCHW88");
  5577. break;
  5578. case Remap::Format::NCHW44:
  5579. props_.emplace_back("format", "NCHW44");
  5580. break;
  5581. case Remap::Format::NCHW44_DOT:
  5582. props_.emplace_back("format", "NCHW44_DOT");
  5583. break;
  5584. case Remap::Format::NCHW4_NCHW32:
  5585. props_.emplace_back("format", "NCHW4_NCHW32");
  5586. break;
  5587. case Remap::Format::NCHW32_NCHW4:
  5588. props_.emplace_back("format", "NCHW32_NCHW4");
  5589. break;
  5590. case Remap::Format::NCHW4_NCHW:
  5591. props_.emplace_back("format", "NCHW4_NCHW");
  5592. break;
  5593. case Remap::Format::NHWC_NCHW:
  5594. props_.emplace_back("format", "NHWC_NCHW");
  5595. break;
  5596. case Remap::Format::NHWC_NCHW4_IC_SMALL:
  5597. props_.emplace_back("format", "NHWC_NCHW4_IC_SMALL");
  5598. break;
  5599. case Remap::Format::NCHW_NCHW4_IC_SMALL:
  5600. props_.emplace_back("format", "NCHW_NCHW4_IC_SMALL");
  5601. break;
  5602. case Remap::Format::CHWN4:
  5603. props_.emplace_back("format", "CHWN4");
  5604. break;
  5605. case Remap::Format::NCHW64:
  5606. props_.emplace_back("format", "NCHW64");
  5607. break;
  5608. case Remap::Format::NCHW4_NHWC:
  5609. props_.emplace_back("format", "NCHW4_NHWC");
  5610. break;
  5611. default:
  5612. props_.emplace_back("format", "INVALID");
  5613. break;
  5614. }
  5615. props_.emplace_back("scalar", std::to_string(op_.scalar));
  5616. return props_;
  5617. }
  5618. std::string Remap_make_name_impl(const OpDef& def_) {
  5619. auto&& op_ = def_.cast_final_safe<Remap>();
  5620. static_cast<void>(op_);
  5621. return "Remap";
  5622. }
  5623. } // anonymous namespace
  5624. OP_TRAIT_REG(Remap, Remap)
  5625. .hash(Remap_hash_impl)
  5626. .is_same_st(Remap_is_same_st_impl)
  5627. .props(Remap_props_impl)
  5628. .make_name(Remap_make_name_impl);
  5629. MGB_DYN_TYPE_OBJ_FINAL_IMPL(RemoteRecv);
  5630. namespace {
  5631. size_t RemoteRecv_hash_impl(const OpDef& def_) {
  5632. auto&& op_ = def_.cast_final_safe<RemoteRecv>();
  5633. static_cast<void>(op_);
  5634. size_t val = mgb::hash(op_.dyn_typeinfo());
  5635. val = mgb::hash_pair_combine(val, mgb::hash(op_.key));
  5636. val = mgb::hash_pair_combine(val, mgb::hash(op_.addr));
  5637. val = mgb::hash_pair_combine(val, mgb::hash(op_.port));
  5638. val = mgb::hash_pair_combine(val, mgb::hash(op_.rank_from));
  5639. val = mgb::hash_pair_combine(val, mgb::hash(op_.cn));
  5640. val = mgb::hash_pair_combine(val, mgb::hash(op_.shape));
  5641. val = mgb::hash_pair_combine(val, mgb::hash(op_.dtype.handle()));
  5642. val = mgb::hash_pair_combine(val, mgb::hash(op_.backend));
  5643. return val;
  5644. }
  5645. bool RemoteRecv_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  5646. auto &&a_ = lhs_.cast_final_safe<RemoteRecv>(),
  5647. &&b_ = rhs_.cast_final_safe<RemoteRecv>();
  5648. static_cast<void>(a_);
  5649. static_cast<void>(b_);
  5650. if (a_.key != b_.key) return false;
  5651. if (a_.addr != b_.addr) return false;
  5652. if (a_.port != b_.port) return false;
  5653. if (a_.rank_from != b_.rank_from) return false;
  5654. if (a_.cn != b_.cn) return false;
  5655. if (a_.shape != b_.shape) return false;
  5656. if (a_.dtype != b_.dtype) return false;
  5657. if (a_.backend != b_.backend) return false;
  5658. return true;
  5659. }
  5660. std::vector<std::pair<const char*, std::string>> RemoteRecv_props_impl(const OpDef& def_) {
  5661. auto&& op_ = def_.cast_final_safe<RemoteRecv>();
  5662. static_cast<void>(op_);
  5663. std::vector<std::pair<const char*, std::string>> props_;
  5664. props_.emplace_back("key", op_.key);
  5665. props_.emplace_back("addr", op_.addr);
  5666. props_.emplace_back("port", std::to_string(op_.port));
  5667. props_.emplace_back("rank_from", std::to_string(op_.rank_from));
  5668. props_.emplace_back("cn", op_.cn.to_string());
  5669. props_.emplace_back("shape", "{std::vector}");
  5670. props_.emplace_back("dtype", op_.dtype.name());
  5671. props_.emplace_back("backend", op_.backend);
  5672. return props_;
  5673. }
  5674. std::string RemoteRecv_make_name_impl(const OpDef& def_) {
  5675. auto&& op_ = def_.cast_final_safe<RemoteRecv>();
  5676. static_cast<void>(op_);
  5677. return "RemoteRecv";
  5678. }
  5679. } // anonymous namespace
  5680. OP_TRAIT_REG(RemoteRecv, RemoteRecv)
  5681. .hash(RemoteRecv_hash_impl)
  5682. .is_same_st(RemoteRecv_is_same_st_impl)
  5683. .props(RemoteRecv_props_impl)
  5684. .make_name(RemoteRecv_make_name_impl);
  5685. MGB_DYN_TYPE_OBJ_FINAL_IMPL(RemoteSend);
  5686. namespace {
  5687. size_t RemoteSend_hash_impl(const OpDef& def_) {
  5688. auto&& op_ = def_.cast_final_safe<RemoteSend>();
  5689. static_cast<void>(op_);
  5690. size_t val = mgb::hash(op_.dyn_typeinfo());
  5691. val = mgb::hash_pair_combine(val, mgb::hash(op_.key));
  5692. val = mgb::hash_pair_combine(val, mgb::hash(op_.addr));
  5693. val = mgb::hash_pair_combine(val, mgb::hash(op_.port));
  5694. val = mgb::hash_pair_combine(val, mgb::hash(op_.rank_to));
  5695. val = mgb::hash_pair_combine(val, mgb::hash(op_.backend));
  5696. return val;
  5697. }
  5698. bool RemoteSend_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  5699. auto &&a_ = lhs_.cast_final_safe<RemoteSend>(),
  5700. &&b_ = rhs_.cast_final_safe<RemoteSend>();
  5701. static_cast<void>(a_);
  5702. static_cast<void>(b_);
  5703. if (a_.key != b_.key) return false;
  5704. if (a_.addr != b_.addr) return false;
  5705. if (a_.port != b_.port) return false;
  5706. if (a_.rank_to != b_.rank_to) return false;
  5707. if (a_.backend != b_.backend) return false;
  5708. return true;
  5709. }
  5710. std::vector<std::pair<const char*, std::string>> RemoteSend_props_impl(const OpDef& def_) {
  5711. auto&& op_ = def_.cast_final_safe<RemoteSend>();
  5712. static_cast<void>(op_);
  5713. std::vector<std::pair<const char*, std::string>> props_;
  5714. props_.emplace_back("key", op_.key);
  5715. props_.emplace_back("addr", op_.addr);
  5716. props_.emplace_back("port", std::to_string(op_.port));
  5717. props_.emplace_back("rank_to", std::to_string(op_.rank_to));
  5718. props_.emplace_back("backend", op_.backend);
  5719. return props_;
  5720. }
  5721. std::string RemoteSend_make_name_impl(const OpDef& def_) {
  5722. auto&& op_ = def_.cast_final_safe<RemoteSend>();
  5723. static_cast<void>(op_);
  5724. return "RemoteSend";
  5725. }
  5726. } // anonymous namespace
  5727. OP_TRAIT_REG(RemoteSend, RemoteSend)
  5728. .hash(RemoteSend_hash_impl)
  5729. .is_same_st(RemoteSend_is_same_st_impl)
  5730. .props(RemoteSend_props_impl)
  5731. .make_name(RemoteSend_make_name_impl);
  5732. MGB_DYN_TYPE_OBJ_FINAL_IMPL(RemoveAxis);
  5733. namespace {
  5734. size_t RemoveAxis_hash_impl(const OpDef& def_) {
  5735. auto&& op_ = def_.cast_final_safe<RemoveAxis>();
  5736. static_cast<void>(op_);
  5737. size_t val = mgb::hash(op_.dyn_typeinfo());
  5738. val = mgb::hash_pair_combine(val, mgb::hash(op_.axis));
  5739. return val;
  5740. }
  5741. bool RemoveAxis_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  5742. auto &&a_ = lhs_.cast_final_safe<RemoveAxis>(),
  5743. &&b_ = rhs_.cast_final_safe<RemoveAxis>();
  5744. static_cast<void>(a_);
  5745. static_cast<void>(b_);
  5746. if (a_.axis != b_.axis) return false;
  5747. return true;
  5748. }
  5749. std::vector<std::pair<const char*, std::string>> RemoveAxis_props_impl(const OpDef& def_) {
  5750. auto&& op_ = def_.cast_final_safe<RemoveAxis>();
  5751. static_cast<void>(op_);
  5752. std::vector<std::pair<const char*, std::string>> props_;
  5753. props_.emplace_back("axis", "{std::vector}");
  5754. return props_;
  5755. }
  5756. std::string RemoveAxis_make_name_impl(const OpDef& def_) {
  5757. auto&& op_ = def_.cast_final_safe<RemoveAxis>();
  5758. static_cast<void>(op_);
  5759. return "RemoveAxis";
  5760. }
  5761. } // anonymous namespace
  5762. OP_TRAIT_REG(RemoveAxis, RemoveAxis)
  5763. .hash(RemoveAxis_hash_impl)
  5764. .is_same_st(RemoveAxis_is_same_st_impl)
  5765. .props(RemoveAxis_props_impl)
  5766. .make_name(RemoveAxis_make_name_impl);
  5767. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Reshape);
  5768. namespace {
  5769. size_t Reshape_hash_impl(const OpDef& def_) {
  5770. auto&& op_ = def_.cast_final_safe<Reshape>();
  5771. static_cast<void>(op_);
  5772. size_t val = mgb::hash(op_.dyn_typeinfo());
  5773. val = mgb::hash_pair_combine(val, mgb::hash(op_.axis));
  5774. val = mgb::hash_pair_combine(val, mgb::hash(op_.shape));
  5775. return val;
  5776. }
  5777. bool Reshape_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  5778. auto &&a_ = lhs_.cast_final_safe<Reshape>(),
  5779. &&b_ = rhs_.cast_final_safe<Reshape>();
  5780. static_cast<void>(a_);
  5781. static_cast<void>(b_);
  5782. if (a_.axis != b_.axis) return false;
  5783. if (a_.shape != b_.shape) return false;
  5784. return true;
  5785. }
  5786. std::vector<std::pair<const char*, std::string>> Reshape_props_impl(const OpDef& def_) {
  5787. auto&& op_ = def_.cast_final_safe<Reshape>();
  5788. static_cast<void>(op_);
  5789. std::vector<std::pair<const char*, std::string>> props_;
  5790. props_.emplace_back("axis", std::to_string(op_.axis));
  5791. props_.emplace_back("shape", "{std::vector}");
  5792. return props_;
  5793. }
  5794. std::string Reshape_make_name_impl(const OpDef& def_) {
  5795. auto&& op_ = def_.cast_final_safe<Reshape>();
  5796. static_cast<void>(op_);
  5797. return "Reshape";
  5798. }
  5799. } // anonymous namespace
  5800. OP_TRAIT_REG(Reshape, Reshape)
  5801. .hash(Reshape_hash_impl)
  5802. .is_same_st(Reshape_is_same_st_impl)
  5803. .props(Reshape_props_impl)
  5804. .make_name(Reshape_make_name_impl);
  5805. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Resize);
  5806. namespace {
  5807. size_t Resize_hash_impl(const OpDef& def_) {
  5808. auto&& op_ = def_.cast_final_safe<Resize>();
  5809. static_cast<void>(op_);
  5810. size_t val = mgb::hash(op_.dyn_typeinfo());
  5811. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.imode));
  5812. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format));
  5813. return val;
  5814. }
  5815. bool Resize_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  5816. auto &&a_ = lhs_.cast_final_safe<Resize>(),
  5817. &&b_ = rhs_.cast_final_safe<Resize>();
  5818. static_cast<void>(a_);
  5819. static_cast<void>(b_);
  5820. if (a_.imode != b_.imode) return false;
  5821. if (a_.format != b_.format) return false;
  5822. return true;
  5823. }
  5824. std::vector<std::pair<const char*, std::string>> Resize_props_impl(const OpDef& def_) {
  5825. auto&& op_ = def_.cast_final_safe<Resize>();
  5826. static_cast<void>(op_);
  5827. std::vector<std::pair<const char*, std::string>> props_;
  5828. switch (op_.imode){
  5829. case Resize::InterpolationMode::NEAREST:
  5830. props_.emplace_back("imode", "NEAREST");
  5831. break;
  5832. case Resize::InterpolationMode::LINEAR:
  5833. props_.emplace_back("imode", "LINEAR");
  5834. break;
  5835. case Resize::InterpolationMode::AREA:
  5836. props_.emplace_back("imode", "AREA");
  5837. break;
  5838. case Resize::InterpolationMode::CUBIC:
  5839. props_.emplace_back("imode", "CUBIC");
  5840. break;
  5841. case Resize::InterpolationMode::LANCZOS4:
  5842. props_.emplace_back("imode", "LANCZOS4");
  5843. break;
  5844. default:
  5845. props_.emplace_back("imode", "INVALID");
  5846. break;
  5847. }
  5848. switch (op_.format){
  5849. case Resize::Format::NCHW:
  5850. props_.emplace_back("format", "NCHW");
  5851. break;
  5852. case Resize::Format::NHWC:
  5853. props_.emplace_back("format", "NHWC");
  5854. break;
  5855. case Resize::Format::NHWCD4:
  5856. props_.emplace_back("format", "NHWCD4");
  5857. break;
  5858. case Resize::Format::NCHW4:
  5859. props_.emplace_back("format", "NCHW4");
  5860. break;
  5861. case Resize::Format::NCHW8:
  5862. props_.emplace_back("format", "NCHW8");
  5863. break;
  5864. case Resize::Format::NCHW32:
  5865. props_.emplace_back("format", "NCHW32");
  5866. break;
  5867. case Resize::Format::NCHW88:
  5868. props_.emplace_back("format", "NCHW88");
  5869. break;
  5870. case Resize::Format::NCHW44:
  5871. props_.emplace_back("format", "NCHW44");
  5872. break;
  5873. case Resize::Format::NCHW44_DOT:
  5874. props_.emplace_back("format", "NCHW44_DOT");
  5875. break;
  5876. case Resize::Format::NCHW4_NCHW32:
  5877. props_.emplace_back("format", "NCHW4_NCHW32");
  5878. break;
  5879. case Resize::Format::NCHW32_NCHW4:
  5880. props_.emplace_back("format", "NCHW32_NCHW4");
  5881. break;
  5882. case Resize::Format::NCHW4_NCHW:
  5883. props_.emplace_back("format", "NCHW4_NCHW");
  5884. break;
  5885. case Resize::Format::NHWC_NCHW:
  5886. props_.emplace_back("format", "NHWC_NCHW");
  5887. break;
  5888. case Resize::Format::NHWC_NCHW4_IC_SMALL:
  5889. props_.emplace_back("format", "NHWC_NCHW4_IC_SMALL");
  5890. break;
  5891. case Resize::Format::NCHW_NCHW4_IC_SMALL:
  5892. props_.emplace_back("format", "NCHW_NCHW4_IC_SMALL");
  5893. break;
  5894. case Resize::Format::CHWN4:
  5895. props_.emplace_back("format", "CHWN4");
  5896. break;
  5897. case Resize::Format::NCHW64:
  5898. props_.emplace_back("format", "NCHW64");
  5899. break;
  5900. case Resize::Format::NCHW4_NHWC:
  5901. props_.emplace_back("format", "NCHW4_NHWC");
  5902. break;
  5903. default:
  5904. props_.emplace_back("format", "INVALID");
  5905. break;
  5906. }
  5907. return props_;
  5908. }
  5909. std::string Resize_make_name_impl(const OpDef& def_) {
  5910. auto&& op_ = def_.cast_final_safe<Resize>();
  5911. static_cast<void>(op_);
  5912. return "Resize";
  5913. }
  5914. } // anonymous namespace
  5915. OP_TRAIT_REG(Resize, Resize)
  5916. .hash(Resize_hash_impl)
  5917. .is_same_st(Resize_is_same_st_impl)
  5918. .props(Resize_props_impl)
  5919. .make_name(Resize_make_name_impl);
  5920. MGB_DYN_TYPE_OBJ_FINAL_IMPL(SVD);
  5921. namespace {
  5922. size_t SVD_hash_impl(const OpDef& def_) {
  5923. auto&& op_ = def_.cast_final_safe<SVD>();
  5924. static_cast<void>(op_);
  5925. size_t val = mgb::hash(op_.dyn_typeinfo());
  5926. val = mgb::hash_pair_combine(val, mgb::hash(op_.full_matrices));
  5927. val = mgb::hash_pair_combine(val, mgb::hash(op_.compute_uv));
  5928. return val;
  5929. }
  5930. bool SVD_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  5931. auto &&a_ = lhs_.cast_final_safe<SVD>(),
  5932. &&b_ = rhs_.cast_final_safe<SVD>();
  5933. static_cast<void>(a_);
  5934. static_cast<void>(b_);
  5935. if (a_.full_matrices != b_.full_matrices) return false;
  5936. if (a_.compute_uv != b_.compute_uv) return false;
  5937. return true;
  5938. }
  5939. std::vector<std::pair<const char*, std::string>> SVD_props_impl(const OpDef& def_) {
  5940. auto&& op_ = def_.cast_final_safe<SVD>();
  5941. static_cast<void>(op_);
  5942. std::vector<std::pair<const char*, std::string>> props_;
  5943. props_.emplace_back("full_matrices", std::to_string(op_.full_matrices));
  5944. props_.emplace_back("compute_uv", std::to_string(op_.compute_uv));
  5945. return props_;
  5946. }
  5947. std::string SVD_make_name_impl(const OpDef& def_) {
  5948. auto&& op_ = def_.cast_final_safe<SVD>();
  5949. static_cast<void>(op_);
  5950. return "SVD";
  5951. }
  5952. } // anonymous namespace
  5953. OP_TRAIT_REG(SVD, SVD)
  5954. .hash(SVD_hash_impl)
  5955. .is_same_st(SVD_is_same_st_impl)
  5956. .props(SVD_props_impl)
  5957. .make_name(SVD_make_name_impl);
  5958. MGB_DYN_TYPE_OBJ_FINAL_IMPL(SetMeshIndexing);
  5959. namespace {
  5960. size_t SetMeshIndexing_hash_impl(const OpDef& def_) {
  5961. auto&& op_ = def_.cast_final_safe<SetMeshIndexing>();
  5962. static_cast<void>(op_);
  5963. size_t val = mgb::hash(op_.dyn_typeinfo());
  5964. val = mgb::hash_pair_combine(val, mgb::hash(op_.items));
  5965. return val;
  5966. }
  5967. bool SetMeshIndexing_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  5968. auto &&a_ = lhs_.cast_final_safe<SetMeshIndexing>(),
  5969. &&b_ = rhs_.cast_final_safe<SetMeshIndexing>();
  5970. static_cast<void>(a_);
  5971. static_cast<void>(b_);
  5972. if (a_.items != b_.items) return false;
  5973. return true;
  5974. }
  5975. std::vector<std::pair<const char*, std::string>> SetMeshIndexing_props_impl(const OpDef& def_) {
  5976. auto&& op_ = def_.cast_final_safe<SetMeshIndexing>();
  5977. static_cast<void>(op_);
  5978. std::vector<std::pair<const char*, std::string>> props_;
  5979. props_.emplace_back("items", "{std::vector}");
  5980. return props_;
  5981. }
  5982. std::string SetMeshIndexing_make_name_impl(const OpDef& def_) {
  5983. auto&& op_ = def_.cast_final_safe<SetMeshIndexing>();
  5984. static_cast<void>(op_);
  5985. return "SetMeshIndexing";
  5986. }
  5987. } // anonymous namespace
  5988. OP_TRAIT_REG(SetMeshIndexing, SetMeshIndexing)
  5989. .hash(SetMeshIndexing_hash_impl)
  5990. .is_same_st(SetMeshIndexing_is_same_st_impl)
  5991. .props(SetMeshIndexing_props_impl)
  5992. .make_name(SetMeshIndexing_make_name_impl);
  5993. MGB_DYN_TYPE_OBJ_FINAL_IMPL(SetSubtensor);
  5994. namespace {
  5995. size_t SetSubtensor_hash_impl(const OpDef& def_) {
  5996. auto&& op_ = def_.cast_final_safe<SetSubtensor>();
  5997. static_cast<void>(op_);
  5998. size_t val = mgb::hash(op_.dyn_typeinfo());
  5999. val = mgb::hash_pair_combine(val, mgb::hash(op_.items));
  6000. return val;
  6001. }
  6002. bool SetSubtensor_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  6003. auto &&a_ = lhs_.cast_final_safe<SetSubtensor>(),
  6004. &&b_ = rhs_.cast_final_safe<SetSubtensor>();
  6005. static_cast<void>(a_);
  6006. static_cast<void>(b_);
  6007. if (a_.items != b_.items) return false;
  6008. return true;
  6009. }
  6010. std::vector<std::pair<const char*, std::string>> SetSubtensor_props_impl(const OpDef& def_) {
  6011. auto&& op_ = def_.cast_final_safe<SetSubtensor>();
  6012. static_cast<void>(op_);
  6013. std::vector<std::pair<const char*, std::string>> props_;
  6014. props_.emplace_back("items", "{std::vector}");
  6015. return props_;
  6016. }
  6017. std::string SetSubtensor_make_name_impl(const OpDef& def_) {
  6018. auto&& op_ = def_.cast_final_safe<SetSubtensor>();
  6019. static_cast<void>(op_);
  6020. return "SetSubtensor";
  6021. }
  6022. } // anonymous namespace
  6023. OP_TRAIT_REG(SetSubtensor, SetSubtensor)
  6024. .hash(SetSubtensor_hash_impl)
  6025. .is_same_st(SetSubtensor_is_same_st_impl)
  6026. .props(SetSubtensor_props_impl)
  6027. .make_name(SetSubtensor_make_name_impl);
  6028. MGB_DYN_TYPE_OBJ_FINAL_IMPL(ShuffleRNG);
  6029. namespace {
  6030. size_t ShuffleRNG_hash_impl(const OpDef& def_) {
  6031. auto&& op_ = def_.cast_final_safe<ShuffleRNG>();
  6032. static_cast<void>(op_);
  6033. return mgb::hash_pair_combine(
  6034. mgb::hash(op_.dyn_typeinfo()),
  6035. mgb::hash(op_.handle)
  6036. );
  6037. }
  6038. bool ShuffleRNG_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  6039. auto &&a_ = lhs_.cast_final_safe<ShuffleRNG>(),
  6040. &&b_ = rhs_.cast_final_safe<ShuffleRNG>();
  6041. static_cast<void>(a_);
  6042. static_cast<void>(b_);
  6043. return a_.handle == b_.handle;}
  6044. std::vector<std::pair<const char*, std::string>> ShuffleRNG_props_impl(const OpDef& def_) {
  6045. auto&& op_ = def_.cast_final_safe<ShuffleRNG>();
  6046. static_cast<void>(op_);
  6047. std::vector<std::pair<const char*, std::string>> props_;
  6048. props_.emplace_back("seed", std::to_string(op_.seed));
  6049. props_.emplace_back("handle", std::to_string(op_.handle));
  6050. return props_;
  6051. }
  6052. std::string ShuffleRNG_make_name_impl(const OpDef& def_) {
  6053. auto&& op_ = def_.cast_final_safe<ShuffleRNG>();
  6054. static_cast<void>(op_);
  6055. return "ShuffleRNG";
  6056. }
  6057. } // anonymous namespace
  6058. OP_TRAIT_REG(ShuffleRNG, ShuffleRNG)
  6059. .hash(ShuffleRNG_hash_impl)
  6060. .is_same_st(ShuffleRNG_is_same_st_impl)
  6061. .props(ShuffleRNG_props_impl)
  6062. .make_name(ShuffleRNG_make_name_impl);
  6063. MGB_DYN_TYPE_OBJ_FINAL_IMPL(SlidingWindowTranspose);
  6064. namespace {
  6065. size_t SlidingWindowTranspose_hash_impl(const OpDef& def_) {
  6066. auto&& op_ = def_.cast_final_safe<SlidingWindowTranspose>();
  6067. static_cast<void>(op_);
  6068. size_t val = mgb::hash(op_.dyn_typeinfo());
  6069. val = mgb::hash_pair_combine(val, mgb::hash(op_.out_h));
  6070. val = mgb::hash_pair_combine(val, mgb::hash(op_.out_w));
  6071. val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_h));
  6072. val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_w));
  6073. val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_h));
  6074. val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_w));
  6075. val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_h));
  6076. val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_w));
  6077. val = mgb::hash_pair_combine(val, mgb::hash(op_.window_h));
  6078. val = mgb::hash_pair_combine(val, mgb::hash(op_.window_w));
  6079. return val;
  6080. }
  6081. bool SlidingWindowTranspose_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  6082. auto &&a_ = lhs_.cast_final_safe<SlidingWindowTranspose>(),
  6083. &&b_ = rhs_.cast_final_safe<SlidingWindowTranspose>();
  6084. static_cast<void>(a_);
  6085. static_cast<void>(b_);
  6086. if (a_.out_h != b_.out_h) return false;
  6087. if (a_.out_w != b_.out_w) return false;
  6088. if (a_.pad_h != b_.pad_h) return false;
  6089. if (a_.pad_w != b_.pad_w) return false;
  6090. if (a_.stride_h != b_.stride_h) return false;
  6091. if (a_.stride_w != b_.stride_w) return false;
  6092. if (a_.dilate_h != b_.dilate_h) return false;
  6093. if (a_.dilate_w != b_.dilate_w) return false;
  6094. if (a_.window_h != b_.window_h) return false;
  6095. if (a_.window_w != b_.window_w) return false;
  6096. return true;
  6097. }
  6098. std::vector<std::pair<const char*, std::string>> SlidingWindowTranspose_props_impl(const OpDef& def_) {
  6099. auto&& op_ = def_.cast_final_safe<SlidingWindowTranspose>();
  6100. static_cast<void>(op_);
  6101. std::vector<std::pair<const char*, std::string>> props_;
  6102. props_.emplace_back("out_h", std::to_string(op_.out_h));
  6103. props_.emplace_back("out_w", std::to_string(op_.out_w));
  6104. props_.emplace_back("pad_h", std::to_string(op_.pad_h));
  6105. props_.emplace_back("pad_w", std::to_string(op_.pad_w));
  6106. props_.emplace_back("stride_h", std::to_string(op_.stride_h));
  6107. props_.emplace_back("stride_w", std::to_string(op_.stride_w));
  6108. props_.emplace_back("dilate_h", std::to_string(op_.dilate_h));
  6109. props_.emplace_back("dilate_w", std::to_string(op_.dilate_w));
  6110. props_.emplace_back("window_h", std::to_string(op_.window_h));
  6111. props_.emplace_back("window_w", std::to_string(op_.window_w));
  6112. return props_;
  6113. }
  6114. std::string SlidingWindowTranspose_make_name_impl(const OpDef& def_) {
  6115. auto&& op_ = def_.cast_final_safe<SlidingWindowTranspose>();
  6116. static_cast<void>(op_);
  6117. return "SlidingWindowTranspose";
  6118. }
  6119. } // anonymous namespace
  6120. OP_TRAIT_REG(SlidingWindowTranspose, SlidingWindowTranspose)
  6121. .hash(SlidingWindowTranspose_hash_impl)
  6122. .is_same_st(SlidingWindowTranspose_is_same_st_impl)
  6123. .props(SlidingWindowTranspose_props_impl)
  6124. .make_name(SlidingWindowTranspose_make_name_impl);
  6125. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Softmax);
  6126. namespace {
  6127. size_t Softmax_hash_impl(const OpDef& def_) {
  6128. auto&& op_ = def_.cast_final_safe<Softmax>();
  6129. static_cast<void>(op_);
  6130. size_t val = mgb::hash(op_.dyn_typeinfo());
  6131. val = mgb::hash_pair_combine(val, mgb::hash(op_.axis));
  6132. return val;
  6133. }
  6134. bool Softmax_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  6135. auto &&a_ = lhs_.cast_final_safe<Softmax>(),
  6136. &&b_ = rhs_.cast_final_safe<Softmax>();
  6137. static_cast<void>(a_);
  6138. static_cast<void>(b_);
  6139. if (a_.axis != b_.axis) return false;
  6140. return true;
  6141. }
  6142. std::vector<std::pair<const char*, std::string>> Softmax_props_impl(const OpDef& def_) {
  6143. auto&& op_ = def_.cast_final_safe<Softmax>();
  6144. static_cast<void>(op_);
  6145. std::vector<std::pair<const char*, std::string>> props_;
  6146. props_.emplace_back("axis", std::to_string(op_.axis));
  6147. return props_;
  6148. }
  6149. std::string Softmax_make_name_impl(const OpDef& def_) {
  6150. auto&& op_ = def_.cast_final_safe<Softmax>();
  6151. static_cast<void>(op_);
  6152. return "Softmax";
  6153. }
  6154. } // anonymous namespace
  6155. OP_TRAIT_REG(Softmax, Softmax)
  6156. .hash(Softmax_hash_impl)
  6157. .is_same_st(Softmax_is_same_st_impl)
  6158. .props(Softmax_props_impl)
  6159. .make_name(Softmax_make_name_impl);
  6160. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Split);
  6161. namespace {
  6162. size_t Split_hash_impl(const OpDef& def_) {
  6163. auto&& op_ = def_.cast_final_safe<Split>();
  6164. static_cast<void>(op_);
  6165. size_t val = mgb::hash(op_.dyn_typeinfo());
  6166. val = mgb::hash_pair_combine(val, mgb::hash(op_.axis));
  6167. val = mgb::hash_pair_combine(val, mgb::hash(op_.nsections));
  6168. return val;
  6169. }
  6170. bool Split_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  6171. auto &&a_ = lhs_.cast_final_safe<Split>(),
  6172. &&b_ = rhs_.cast_final_safe<Split>();
  6173. static_cast<void>(a_);
  6174. static_cast<void>(b_);
  6175. if (a_.axis != b_.axis) return false;
  6176. if (a_.nsections != b_.nsections) return false;
  6177. return true;
  6178. }
  6179. std::vector<std::pair<const char*, std::string>> Split_props_impl(const OpDef& def_) {
  6180. auto&& op_ = def_.cast_final_safe<Split>();
  6181. static_cast<void>(op_);
  6182. std::vector<std::pair<const char*, std::string>> props_;
  6183. props_.emplace_back("axis", std::to_string(op_.axis));
  6184. props_.emplace_back("nsections", std::to_string(op_.nsections));
  6185. return props_;
  6186. }
  6187. std::string Split_make_name_impl(const OpDef& def_) {
  6188. auto&& op_ = def_.cast_final_safe<Split>();
  6189. static_cast<void>(op_);
  6190. return "Split";
  6191. }
  6192. } // anonymous namespace
  6193. OP_TRAIT_REG(Split, Split)
  6194. .hash(Split_hash_impl)
  6195. .is_same_st(Split_is_same_st_impl)
  6196. .props(Split_props_impl)
  6197. .make_name(Split_make_name_impl);
  6198. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Subtensor);
  6199. namespace {
  6200. size_t Subtensor_hash_impl(const OpDef& def_) {
  6201. auto&& op_ = def_.cast_final_safe<Subtensor>();
  6202. static_cast<void>(op_);
  6203. size_t val = mgb::hash(op_.dyn_typeinfo());
  6204. val = mgb::hash_pair_combine(val, mgb::hash(op_.items));
  6205. return val;
  6206. }
  6207. bool Subtensor_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  6208. auto &&a_ = lhs_.cast_final_safe<Subtensor>(),
  6209. &&b_ = rhs_.cast_final_safe<Subtensor>();
  6210. static_cast<void>(a_);
  6211. static_cast<void>(b_);
  6212. if (a_.items != b_.items) return false;
  6213. return true;
  6214. }
  6215. std::vector<std::pair<const char*, std::string>> Subtensor_props_impl(const OpDef& def_) {
  6216. auto&& op_ = def_.cast_final_safe<Subtensor>();
  6217. static_cast<void>(op_);
  6218. std::vector<std::pair<const char*, std::string>> props_;
  6219. props_.emplace_back("items", "{std::vector}");
  6220. return props_;
  6221. }
  6222. std::string Subtensor_make_name_impl(const OpDef& def_) {
  6223. auto&& op_ = def_.cast_final_safe<Subtensor>();
  6224. static_cast<void>(op_);
  6225. return "Subtensor";
  6226. }
  6227. } // anonymous namespace
  6228. OP_TRAIT_REG(Subtensor, Subtensor)
  6229. .hash(Subtensor_hash_impl)
  6230. .is_same_st(Subtensor_is_same_st_impl)
  6231. .props(Subtensor_props_impl)
  6232. .make_name(Subtensor_make_name_impl);
  6233. MGB_DYN_TYPE_OBJ_FINAL_IMPL(TQT);
  6234. namespace {
  6235. size_t TQT_hash_impl(const OpDef& def_) {
  6236. auto&& op_ = def_.cast_final_safe<TQT>();
  6237. static_cast<void>(op_);
  6238. size_t val = mgb::hash(op_.dyn_typeinfo());
  6239. val = mgb::hash_pair_combine(val, mgb::hash(op_.qmin));
  6240. val = mgb::hash_pair_combine(val, mgb::hash(op_.qmax));
  6241. return val;
  6242. }
  6243. bool TQT_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  6244. auto &&a_ = lhs_.cast_final_safe<TQT>(),
  6245. &&b_ = rhs_.cast_final_safe<TQT>();
  6246. static_cast<void>(a_);
  6247. static_cast<void>(b_);
  6248. if (a_.qmin != b_.qmin) return false;
  6249. if (a_.qmax != b_.qmax) return false;
  6250. return true;
  6251. }
  6252. std::vector<std::pair<const char*, std::string>> TQT_props_impl(const OpDef& def_) {
  6253. auto&& op_ = def_.cast_final_safe<TQT>();
  6254. static_cast<void>(op_);
  6255. std::vector<std::pair<const char*, std::string>> props_;
  6256. props_.emplace_back("qmin", std::to_string(op_.qmin));
  6257. props_.emplace_back("qmax", std::to_string(op_.qmax));
  6258. return props_;
  6259. }
  6260. std::string TQT_make_name_impl(const OpDef& def_) {
  6261. auto&& op_ = def_.cast_final_safe<TQT>();
  6262. static_cast<void>(op_);
  6263. return "TQT";
  6264. }
  6265. } // anonymous namespace
  6266. OP_TRAIT_REG(TQT, TQT)
  6267. .hash(TQT_hash_impl)
  6268. .is_same_st(TQT_is_same_st_impl)
  6269. .props(TQT_props_impl)
  6270. .make_name(TQT_make_name_impl);
  6271. MGB_DYN_TYPE_OBJ_FINAL_IMPL(TensorRTRuntime);
  6272. namespace {
  6273. size_t TensorRTRuntime_hash_impl(const OpDef& def_) {
  6274. auto&& op_ = def_.cast_final_safe<TensorRTRuntime>();
  6275. static_cast<void>(op_);
  6276. size_t val = mgb::hash(op_.dyn_typeinfo());
  6277. val = mgb::hash_pair_combine(val, mgb::hash(op_.buf));
  6278. val = mgb::hash_pair_combine(val, mgb::hash(op_.buf_size));
  6279. return val;
  6280. }
  6281. bool TensorRTRuntime_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  6282. auto &&a_ = lhs_.cast_final_safe<TensorRTRuntime>(),
  6283. &&b_ = rhs_.cast_final_safe<TensorRTRuntime>();
  6284. static_cast<void>(a_);
  6285. static_cast<void>(b_);
  6286. if (a_.buf != b_.buf) return false;
  6287. if (a_.buf_size != b_.buf_size) return false;
  6288. return true;
  6289. }
  6290. std::vector<std::pair<const char*, std::string>> TensorRTRuntime_props_impl(const OpDef& def_) {
  6291. auto&& op_ = def_.cast_final_safe<TensorRTRuntime>();
  6292. static_cast<void>(op_);
  6293. std::vector<std::pair<const char*, std::string>> props_;
  6294. props_.emplace_back("buf", op_.buf);
  6295. props_.emplace_back("buf_size", std::to_string(op_.buf_size));
  6296. return props_;
  6297. }
  6298. std::string TensorRTRuntime_make_name_impl(const OpDef& def_) {
  6299. auto&& op_ = def_.cast_final_safe<TensorRTRuntime>();
  6300. static_cast<void>(op_);
  6301. return "TensorRTRuntime";
  6302. }
  6303. } // anonymous namespace
  6304. OP_TRAIT_REG(TensorRTRuntime, TensorRTRuntime)
  6305. .hash(TensorRTRuntime_hash_impl)
  6306. .is_same_st(TensorRTRuntime_is_same_st_impl)
  6307. .props(TensorRTRuntime_props_impl)
  6308. .make_name(TensorRTRuntime_make_name_impl);
  6309. MGB_DYN_TYPE_OBJ_FINAL_IMPL(TopK);
  6310. namespace {
  6311. size_t TopK_hash_impl(const OpDef& def_) {
  6312. auto&& op_ = def_.cast_final_safe<TopK>();
  6313. static_cast<void>(op_);
  6314. size_t val = mgb::hash(op_.dyn_typeinfo());
  6315. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode));
  6316. return val;
  6317. }
  6318. bool TopK_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  6319. auto &&a_ = lhs_.cast_final_safe<TopK>(),
  6320. &&b_ = rhs_.cast_final_safe<TopK>();
  6321. static_cast<void>(a_);
  6322. static_cast<void>(b_);
  6323. if (a_.mode != b_.mode) return false;
  6324. return true;
  6325. }
  6326. std::vector<std::pair<const char*, std::string>> TopK_props_impl(const OpDef& def_) {
  6327. auto&& op_ = def_.cast_final_safe<TopK>();
  6328. static_cast<void>(op_);
  6329. std::vector<std::pair<const char*, std::string>> props_;
  6330. switch (op_.mode){
  6331. case TopK::Mode::KTH_ONLY:
  6332. props_.emplace_back("mode", "KTH_ONLY");
  6333. break;
  6334. case TopK::Mode::VALUE_IDX_NOSORT:
  6335. props_.emplace_back("mode", "VALUE_IDX_NOSORT");
  6336. break;
  6337. case TopK::Mode::VALUE_IDX_SORTED:
  6338. props_.emplace_back("mode", "VALUE_IDX_SORTED");
  6339. break;
  6340. default:
  6341. props_.emplace_back("mode", "INVALID");
  6342. break;
  6343. }
  6344. return props_;
  6345. }
  6346. std::string TopK_make_name_impl(const OpDef& def_) {
  6347. auto&& op_ = def_.cast_final_safe<TopK>();
  6348. static_cast<void>(op_);
  6349. return "TopK";
  6350. }
  6351. } // anonymous namespace
  6352. OP_TRAIT_REG(TopK, TopK)
  6353. .hash(TopK_hash_impl)
  6354. .is_same_st(TopK_is_same_st_impl)
  6355. .props(TopK_props_impl)
  6356. .make_name(TopK_make_name_impl);
  6357. MGB_DYN_TYPE_OBJ_FINAL_IMPL(TypeCvt);
  6358. namespace {
  6359. size_t TypeCvt_hash_impl(const OpDef& def_) {
  6360. auto&& op_ = def_.cast_final_safe<TypeCvt>();
  6361. static_cast<void>(op_);
  6362. size_t val = mgb::hash(op_.dyn_typeinfo());
  6363. val = mgb::hash_pair_combine(val, mgb::hash(op_.dtype.handle()));
  6364. return val;
  6365. }
  6366. bool TypeCvt_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  6367. auto &&a_ = lhs_.cast_final_safe<TypeCvt>(),
  6368. &&b_ = rhs_.cast_final_safe<TypeCvt>();
  6369. static_cast<void>(a_);
  6370. static_cast<void>(b_);
  6371. if (a_.dtype != b_.dtype) return false;
  6372. return true;
  6373. }
  6374. std::vector<std::pair<const char*, std::string>> TypeCvt_props_impl(const OpDef& def_) {
  6375. auto&& op_ = def_.cast_final_safe<TypeCvt>();
  6376. static_cast<void>(op_);
  6377. std::vector<std::pair<const char*, std::string>> props_;
  6378. props_.emplace_back("dtype", op_.dtype.name());
  6379. return props_;
  6380. }
  6381. std::string TypeCvt_make_name_impl(const OpDef& def_) {
  6382. auto&& op_ = def_.cast_final_safe<TypeCvt>();
  6383. static_cast<void>(op_);
  6384. return "TypeCvt";
  6385. }
  6386. } // anonymous namespace
  6387. OP_TRAIT_REG(TypeCvt, TypeCvt)
  6388. .hash(TypeCvt_hash_impl)
  6389. .is_same_st(TypeCvt_is_same_st_impl)
  6390. .props(TypeCvt_props_impl)
  6391. .make_name(TypeCvt_make_name_impl);
  6392. MGB_DYN_TYPE_OBJ_FINAL_IMPL(UniformRNG);
  6393. namespace {
  6394. size_t UniformRNG_hash_impl(const OpDef& def_) {
  6395. auto&& op_ = def_.cast_final_safe<UniformRNG>();
  6396. static_cast<void>(op_);
  6397. return mgb::hash_pair_combine(
  6398. mgb::hash(op_.dyn_typeinfo()),
  6399. mgb::hash_pair_combine(
  6400. mgb::hash(op_.handle),
  6401. mgb::hash(op_.dtype.enumv())
  6402. )
  6403. );
  6404. }
  6405. bool UniformRNG_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  6406. auto &&a_ = lhs_.cast_final_safe<UniformRNG>(),
  6407. &&b_ = rhs_.cast_final_safe<UniformRNG>();
  6408. static_cast<void>(a_);
  6409. static_cast<void>(b_);
  6410. return a_.handle == b_.handle && a_.dtype == b_.dtype;}
  6411. std::vector<std::pair<const char*, std::string>> UniformRNG_props_impl(const OpDef& def_) {
  6412. auto&& op_ = def_.cast_final_safe<UniformRNG>();
  6413. static_cast<void>(op_);
  6414. std::vector<std::pair<const char*, std::string>> props_;
  6415. props_.emplace_back("seed", std::to_string(op_.seed));
  6416. props_.emplace_back("dtype", op_.dtype.name());
  6417. props_.emplace_back("handle", std::to_string(op_.handle));
  6418. return props_;
  6419. }
  6420. std::string UniformRNG_make_name_impl(const OpDef& def_) {
  6421. auto&& op_ = def_.cast_final_safe<UniformRNG>();
  6422. static_cast<void>(op_);
  6423. return "UniformRNG";
  6424. }
  6425. } // anonymous namespace
  6426. OP_TRAIT_REG(UniformRNG, UniformRNG)
  6427. .hash(UniformRNG_hash_impl)
  6428. .is_same_st(UniformRNG_is_same_st_impl)
  6429. .props(UniformRNG_props_impl)
  6430. .make_name(UniformRNG_make_name_impl);
  6431. MGB_DYN_TYPE_OBJ_FINAL_IMPL(WarpAffine);
  6432. namespace {
  6433. size_t WarpAffine_hash_impl(const OpDef& def_) {
  6434. auto&& op_ = def_.cast_final_safe<WarpAffine>();
  6435. static_cast<void>(op_);
  6436. size_t val = mgb::hash(op_.dyn_typeinfo());
  6437. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.imode));
  6438. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.border_mode));
  6439. val = mgb::hash_pair_combine(val, mgb::hash(op_.border_val));
  6440. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format));
  6441. return val;
  6442. }
  6443. bool WarpAffine_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  6444. auto &&a_ = lhs_.cast_final_safe<WarpAffine>(),
  6445. &&b_ = rhs_.cast_final_safe<WarpAffine>();
  6446. static_cast<void>(a_);
  6447. static_cast<void>(b_);
  6448. if (a_.imode != b_.imode) return false;
  6449. if (a_.border_mode != b_.border_mode) return false;
  6450. if (a_.border_val != b_.border_val) return false;
  6451. if (a_.format != b_.format) return false;
  6452. return true;
  6453. }
  6454. std::vector<std::pair<const char*, std::string>> WarpAffine_props_impl(const OpDef& def_) {
  6455. auto&& op_ = def_.cast_final_safe<WarpAffine>();
  6456. static_cast<void>(op_);
  6457. std::vector<std::pair<const char*, std::string>> props_;
  6458. switch (op_.imode){
  6459. case WarpAffine::InterpolationMode::NEAREST:
  6460. props_.emplace_back("imode", "NEAREST");
  6461. break;
  6462. case WarpAffine::InterpolationMode::LINEAR:
  6463. props_.emplace_back("imode", "LINEAR");
  6464. break;
  6465. case WarpAffine::InterpolationMode::AREA:
  6466. props_.emplace_back("imode", "AREA");
  6467. break;
  6468. case WarpAffine::InterpolationMode::CUBIC:
  6469. props_.emplace_back("imode", "CUBIC");
  6470. break;
  6471. case WarpAffine::InterpolationMode::LANCZOS4:
  6472. props_.emplace_back("imode", "LANCZOS4");
  6473. break;
  6474. default:
  6475. props_.emplace_back("imode", "INVALID");
  6476. break;
  6477. }
  6478. switch (op_.border_mode){
  6479. case WarpAffine::BorderMode::REPLICATE:
  6480. props_.emplace_back("border_mode", "REPLICATE");
  6481. break;
  6482. case WarpAffine::BorderMode::REFLECT:
  6483. props_.emplace_back("border_mode", "REFLECT");
  6484. break;
  6485. case WarpAffine::BorderMode::REFLECT_101:
  6486. props_.emplace_back("border_mode", "REFLECT_101");
  6487. break;
  6488. case WarpAffine::BorderMode::WRAP:
  6489. props_.emplace_back("border_mode", "WRAP");
  6490. break;
  6491. case WarpAffine::BorderMode::CONSTANT:
  6492. props_.emplace_back("border_mode", "CONSTANT");
  6493. break;
  6494. case WarpAffine::BorderMode::TRANSPARENT:
  6495. props_.emplace_back("border_mode", "TRANSPARENT");
  6496. break;
  6497. case WarpAffine::BorderMode::ISOLATED:
  6498. props_.emplace_back("border_mode", "ISOLATED");
  6499. break;
  6500. default:
  6501. props_.emplace_back("border_mode", "INVALID");
  6502. break;
  6503. }
  6504. props_.emplace_back("border_val", std::to_string(op_.border_val));
  6505. switch (op_.format){
  6506. case WarpAffine::Format::NCHW:
  6507. props_.emplace_back("format", "NCHW");
  6508. break;
  6509. case WarpAffine::Format::NHWC:
  6510. props_.emplace_back("format", "NHWC");
  6511. break;
  6512. case WarpAffine::Format::NHWCD4:
  6513. props_.emplace_back("format", "NHWCD4");
  6514. break;
  6515. case WarpAffine::Format::NCHW4:
  6516. props_.emplace_back("format", "NCHW4");
  6517. break;
  6518. case WarpAffine::Format::NCHW8:
  6519. props_.emplace_back("format", "NCHW8");
  6520. break;
  6521. case WarpAffine::Format::NCHW32:
  6522. props_.emplace_back("format", "NCHW32");
  6523. break;
  6524. case WarpAffine::Format::NCHW88:
  6525. props_.emplace_back("format", "NCHW88");
  6526. break;
  6527. case WarpAffine::Format::NCHW44:
  6528. props_.emplace_back("format", "NCHW44");
  6529. break;
  6530. case WarpAffine::Format::NCHW44_DOT:
  6531. props_.emplace_back("format", "NCHW44_DOT");
  6532. break;
  6533. case WarpAffine::Format::NCHW4_NCHW32:
  6534. props_.emplace_back("format", "NCHW4_NCHW32");
  6535. break;
  6536. case WarpAffine::Format::NCHW32_NCHW4:
  6537. props_.emplace_back("format", "NCHW32_NCHW4");
  6538. break;
  6539. case WarpAffine::Format::NCHW4_NCHW:
  6540. props_.emplace_back("format", "NCHW4_NCHW");
  6541. break;
  6542. case WarpAffine::Format::NHWC_NCHW:
  6543. props_.emplace_back("format", "NHWC_NCHW");
  6544. break;
  6545. case WarpAffine::Format::NHWC_NCHW4_IC_SMALL:
  6546. props_.emplace_back("format", "NHWC_NCHW4_IC_SMALL");
  6547. break;
  6548. case WarpAffine::Format::NCHW_NCHW4_IC_SMALL:
  6549. props_.emplace_back("format", "NCHW_NCHW4_IC_SMALL");
  6550. break;
  6551. case WarpAffine::Format::CHWN4:
  6552. props_.emplace_back("format", "CHWN4");
  6553. break;
  6554. case WarpAffine::Format::NCHW64:
  6555. props_.emplace_back("format", "NCHW64");
  6556. break;
  6557. case WarpAffine::Format::NCHW4_NHWC:
  6558. props_.emplace_back("format", "NCHW4_NHWC");
  6559. break;
  6560. default:
  6561. props_.emplace_back("format", "INVALID");
  6562. break;
  6563. }
  6564. return props_;
  6565. }
  6566. std::string WarpAffine_make_name_impl(const OpDef& def_) {
  6567. auto&& op_ = def_.cast_final_safe<WarpAffine>();
  6568. static_cast<void>(op_);
  6569. return "WarpAffine";
  6570. }
  6571. } // anonymous namespace
  6572. OP_TRAIT_REG(WarpAffine, WarpAffine)
  6573. .hash(WarpAffine_hash_impl)
  6574. .is_same_st(WarpAffine_is_same_st_impl)
  6575. .props(WarpAffine_props_impl)
  6576. .make_name(WarpAffine_make_name_impl);
  6577. MGB_DYN_TYPE_OBJ_FINAL_IMPL(WarpPerspective);
  6578. namespace {
  6579. size_t WarpPerspective_hash_impl(const OpDef& def_) {
  6580. auto&& op_ = def_.cast_final_safe<WarpPerspective>();
  6581. static_cast<void>(op_);
  6582. size_t val = mgb::hash(op_.dyn_typeinfo());
  6583. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.imode));
  6584. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.bmode));
  6585. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format));
  6586. val = mgb::hash_pair_combine(val, mgb::hash(op_.border_val));
  6587. return val;
  6588. }
  6589. bool WarpPerspective_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  6590. auto &&a_ = lhs_.cast_final_safe<WarpPerspective>(),
  6591. &&b_ = rhs_.cast_final_safe<WarpPerspective>();
  6592. static_cast<void>(a_);
  6593. static_cast<void>(b_);
  6594. if (a_.imode != b_.imode) return false;
  6595. if (a_.bmode != b_.bmode) return false;
  6596. if (a_.format != b_.format) return false;
  6597. if (a_.border_val != b_.border_val) return false;
  6598. return true;
  6599. }
  6600. std::vector<std::pair<const char*, std::string>> WarpPerspective_props_impl(const OpDef& def_) {
  6601. auto&& op_ = def_.cast_final_safe<WarpPerspective>();
  6602. static_cast<void>(op_);
  6603. std::vector<std::pair<const char*, std::string>> props_;
  6604. switch (op_.imode){
  6605. case WarpPerspective::InterpolationMode::NEAREST:
  6606. props_.emplace_back("imode", "NEAREST");
  6607. break;
  6608. case WarpPerspective::InterpolationMode::LINEAR:
  6609. props_.emplace_back("imode", "LINEAR");
  6610. break;
  6611. case WarpPerspective::InterpolationMode::AREA:
  6612. props_.emplace_back("imode", "AREA");
  6613. break;
  6614. case WarpPerspective::InterpolationMode::CUBIC:
  6615. props_.emplace_back("imode", "CUBIC");
  6616. break;
  6617. case WarpPerspective::InterpolationMode::LANCZOS4:
  6618. props_.emplace_back("imode", "LANCZOS4");
  6619. break;
  6620. default:
  6621. props_.emplace_back("imode", "INVALID");
  6622. break;
  6623. }
  6624. switch (op_.bmode){
  6625. case WarpPerspective::BorderMode::REPLICATE:
  6626. props_.emplace_back("bmode", "REPLICATE");
  6627. break;
  6628. case WarpPerspective::BorderMode::REFLECT:
  6629. props_.emplace_back("bmode", "REFLECT");
  6630. break;
  6631. case WarpPerspective::BorderMode::REFLECT_101:
  6632. props_.emplace_back("bmode", "REFLECT_101");
  6633. break;
  6634. case WarpPerspective::BorderMode::WRAP:
  6635. props_.emplace_back("bmode", "WRAP");
  6636. break;
  6637. case WarpPerspective::BorderMode::CONSTANT:
  6638. props_.emplace_back("bmode", "CONSTANT");
  6639. break;
  6640. case WarpPerspective::BorderMode::TRANSPARENT:
  6641. props_.emplace_back("bmode", "TRANSPARENT");
  6642. break;
  6643. case WarpPerspective::BorderMode::ISOLATED:
  6644. props_.emplace_back("bmode", "ISOLATED");
  6645. break;
  6646. default:
  6647. props_.emplace_back("bmode", "INVALID");
  6648. break;
  6649. }
  6650. switch (op_.format){
  6651. case WarpPerspective::Format::NCHW:
  6652. props_.emplace_back("format", "NCHW");
  6653. break;
  6654. case WarpPerspective::Format::NHWC:
  6655. props_.emplace_back("format", "NHWC");
  6656. break;
  6657. case WarpPerspective::Format::NHWCD4:
  6658. props_.emplace_back("format", "NHWCD4");
  6659. break;
  6660. case WarpPerspective::Format::NCHW4:
  6661. props_.emplace_back("format", "NCHW4");
  6662. break;
  6663. case WarpPerspective::Format::NCHW8:
  6664. props_.emplace_back("format", "NCHW8");
  6665. break;
  6666. case WarpPerspective::Format::NCHW32:
  6667. props_.emplace_back("format", "NCHW32");
  6668. break;
  6669. case WarpPerspective::Format::NCHW88:
  6670. props_.emplace_back("format", "NCHW88");
  6671. break;
  6672. case WarpPerspective::Format::NCHW44:
  6673. props_.emplace_back("format", "NCHW44");
  6674. break;
  6675. case WarpPerspective::Format::NCHW44_DOT:
  6676. props_.emplace_back("format", "NCHW44_DOT");
  6677. break;
  6678. case WarpPerspective::Format::NCHW4_NCHW32:
  6679. props_.emplace_back("format", "NCHW4_NCHW32");
  6680. break;
  6681. case WarpPerspective::Format::NCHW32_NCHW4:
  6682. props_.emplace_back("format", "NCHW32_NCHW4");
  6683. break;
  6684. case WarpPerspective::Format::NCHW4_NCHW:
  6685. props_.emplace_back("format", "NCHW4_NCHW");
  6686. break;
  6687. case WarpPerspective::Format::NHWC_NCHW:
  6688. props_.emplace_back("format", "NHWC_NCHW");
  6689. break;
  6690. case WarpPerspective::Format::NHWC_NCHW4_IC_SMALL:
  6691. props_.emplace_back("format", "NHWC_NCHW4_IC_SMALL");
  6692. break;
  6693. case WarpPerspective::Format::NCHW_NCHW4_IC_SMALL:
  6694. props_.emplace_back("format", "NCHW_NCHW4_IC_SMALL");
  6695. break;
  6696. case WarpPerspective::Format::CHWN4:
  6697. props_.emplace_back("format", "CHWN4");
  6698. break;
  6699. case WarpPerspective::Format::NCHW64:
  6700. props_.emplace_back("format", "NCHW64");
  6701. break;
  6702. case WarpPerspective::Format::NCHW4_NHWC:
  6703. props_.emplace_back("format", "NCHW4_NHWC");
  6704. break;
  6705. default:
  6706. props_.emplace_back("format", "INVALID");
  6707. break;
  6708. }
  6709. props_.emplace_back("border_val", std::to_string(op_.border_val));
  6710. return props_;
  6711. }
  6712. std::string WarpPerspective_make_name_impl(const OpDef& def_) {
  6713. auto&& op_ = def_.cast_final_safe<WarpPerspective>();
  6714. static_cast<void>(op_);
  6715. return "WarpPerspective";
  6716. }
  6717. } // anonymous namespace
  6718. OP_TRAIT_REG(WarpPerspective, WarpPerspective)
  6719. .hash(WarpPerspective_hash_impl)
  6720. .is_same_st(WarpPerspective_is_same_st_impl)
  6721. .props(WarpPerspective_props_impl)
  6722. .make_name(WarpPerspective_make_name_impl);
  6723. // clang-format on