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 259 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917
  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. default:
  2992. props_.emplace_back("mode", "INVALID");
  2993. break;
  2994. }
  2995. return props_;
  2996. }
  2997. std::string Elemwise_make_name_impl(const OpDef& def_) {
  2998. auto&& op_ = def_.cast_final_safe<Elemwise>();
  2999. static_cast<void>(op_);
  3000. return to_string(op_.mode);
  3001. }
  3002. } // anonymous namespace
  3003. OP_TRAIT_REG(Elemwise, Elemwise)
  3004. .hash(Elemwise_hash_impl)
  3005. .is_same_st(Elemwise_is_same_st_impl)
  3006. .props(Elemwise_props_impl)
  3007. .make_name(Elemwise_make_name_impl);
  3008. MGB_DYN_TYPE_OBJ_FINAL_IMPL(ElemwiseMultiType);
  3009. namespace {
  3010. size_t ElemwiseMultiType_hash_impl(const OpDef& def_) {
  3011. auto&& op_ = def_.cast_final_safe<ElemwiseMultiType>();
  3012. static_cast<void>(op_);
  3013. size_t val = mgb::hash(op_.dyn_typeinfo());
  3014. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode));
  3015. val = mgb::hash_pair_combine(val, mgb::hash(op_.dtype.handle()));
  3016. return val;
  3017. }
  3018. bool ElemwiseMultiType_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3019. auto &&a_ = lhs_.cast_final_safe<ElemwiseMultiType>(),
  3020. &&b_ = rhs_.cast_final_safe<ElemwiseMultiType>();
  3021. static_cast<void>(a_);
  3022. static_cast<void>(b_);
  3023. if (a_.mode != b_.mode) return false;
  3024. if (a_.dtype != b_.dtype) return false;
  3025. return true;
  3026. }
  3027. std::vector<std::pair<const char*, std::string>> ElemwiseMultiType_props_impl(const OpDef& def_) {
  3028. auto&& op_ = def_.cast_final_safe<ElemwiseMultiType>();
  3029. static_cast<void>(op_);
  3030. std::vector<std::pair<const char*, std::string>> props_;
  3031. switch (op_.mode){
  3032. case ElemwiseMultiType::Mode::FUSE_MUL_ADD3_INT16x32x32x32:
  3033. props_.emplace_back("mode", "FUSE_MUL_ADD3_INT16x32x32x32");
  3034. break;
  3035. case ElemwiseMultiType::Mode::FUSE_MUL_ADD3_IXxF32xF32xI8:
  3036. props_.emplace_back("mode", "FUSE_MUL_ADD3_IXxF32xF32xI8");
  3037. break;
  3038. case ElemwiseMultiType::Mode::ROUND_SHR_SATURATE_IXxI8xI8:
  3039. props_.emplace_back("mode", "ROUND_SHR_SATURATE_IXxI8xI8");
  3040. break;
  3041. case ElemwiseMultiType::Mode::FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT16x16x16x8:
  3042. props_.emplace_back("mode", "FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT16x16x16x8");
  3043. break;
  3044. case ElemwiseMultiType::Mode::FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT32x32x32x8:
  3045. props_.emplace_back("mode", "FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT32x32x32x8");
  3046. break;
  3047. case ElemwiseMultiType::Mode::ROUND_SHR_SATURATE_IXxI8xI16:
  3048. props_.emplace_back("mode", "ROUND_SHR_SATURATE_IXxI8xI16");
  3049. break;
  3050. case ElemwiseMultiType::Mode::QADD:
  3051. props_.emplace_back("mode", "QADD");
  3052. break;
  3053. case ElemwiseMultiType::Mode::QFUSE_ADD_RELU:
  3054. props_.emplace_back("mode", "QFUSE_ADD_RELU");
  3055. break;
  3056. case ElemwiseMultiType::Mode::QMUL:
  3057. props_.emplace_back("mode", "QMUL");
  3058. break;
  3059. case ElemwiseMultiType::Mode::QMIN:
  3060. props_.emplace_back("mode", "QMIN");
  3061. break;
  3062. case ElemwiseMultiType::Mode::QMAX:
  3063. props_.emplace_back("mode", "QMAX");
  3064. break;
  3065. case ElemwiseMultiType::Mode::QSUB:
  3066. props_.emplace_back("mode", "QSUB");
  3067. break;
  3068. case ElemwiseMultiType::Mode::QTRUE_DIV:
  3069. props_.emplace_back("mode", "QTRUE_DIV");
  3070. break;
  3071. case ElemwiseMultiType::Mode::QFUSE_ADD_SIGMOID:
  3072. props_.emplace_back("mode", "QFUSE_ADD_SIGMOID");
  3073. break;
  3074. case ElemwiseMultiType::Mode::QFUSE_ADD_TANH:
  3075. props_.emplace_back("mode", "QFUSE_ADD_TANH");
  3076. break;
  3077. case ElemwiseMultiType::Mode::QRELU:
  3078. props_.emplace_back("mode", "QRELU");
  3079. break;
  3080. case ElemwiseMultiType::Mode::QABS:
  3081. props_.emplace_back("mode", "QABS");
  3082. break;
  3083. case ElemwiseMultiType::Mode::QSIGMOID:
  3084. props_.emplace_back("mode", "QSIGMOID");
  3085. break;
  3086. case ElemwiseMultiType::Mode::QEXP:
  3087. props_.emplace_back("mode", "QEXP");
  3088. break;
  3089. case ElemwiseMultiType::Mode::QTANH:
  3090. props_.emplace_back("mode", "QTANH");
  3091. break;
  3092. case ElemwiseMultiType::Mode::QFUSE_MUL_ADD3:
  3093. props_.emplace_back("mode", "QFUSE_MUL_ADD3");
  3094. break;
  3095. case ElemwiseMultiType::Mode::QFAST_TANH:
  3096. props_.emplace_back("mode", "QFAST_TANH");
  3097. break;
  3098. case ElemwiseMultiType::Mode::QNEGATE:
  3099. props_.emplace_back("mode", "QNEGATE");
  3100. break;
  3101. case ElemwiseMultiType::Mode::QACOS:
  3102. props_.emplace_back("mode", "QACOS");
  3103. break;
  3104. case ElemwiseMultiType::Mode::QASIN:
  3105. props_.emplace_back("mode", "QASIN");
  3106. break;
  3107. case ElemwiseMultiType::Mode::QCEIL:
  3108. props_.emplace_back("mode", "QCEIL");
  3109. break;
  3110. case ElemwiseMultiType::Mode::QCOS:
  3111. props_.emplace_back("mode", "QCOS");
  3112. break;
  3113. case ElemwiseMultiType::Mode::QEXPM1:
  3114. props_.emplace_back("mode", "QEXPM1");
  3115. break;
  3116. case ElemwiseMultiType::Mode::QFLOOR:
  3117. props_.emplace_back("mode", "QFLOOR");
  3118. break;
  3119. case ElemwiseMultiType::Mode::QLOG:
  3120. props_.emplace_back("mode", "QLOG");
  3121. break;
  3122. case ElemwiseMultiType::Mode::QLOG1P:
  3123. props_.emplace_back("mode", "QLOG1P");
  3124. break;
  3125. case ElemwiseMultiType::Mode::QSIN:
  3126. props_.emplace_back("mode", "QSIN");
  3127. break;
  3128. case ElemwiseMultiType::Mode::QROUND:
  3129. props_.emplace_back("mode", "QROUND");
  3130. break;
  3131. case ElemwiseMultiType::Mode::QERF:
  3132. props_.emplace_back("mode", "QERF");
  3133. break;
  3134. case ElemwiseMultiType::Mode::QERFINV:
  3135. props_.emplace_back("mode", "QERFINV");
  3136. break;
  3137. case ElemwiseMultiType::Mode::QERFC:
  3138. props_.emplace_back("mode", "QERFC");
  3139. break;
  3140. case ElemwiseMultiType::Mode::QERFCINV:
  3141. props_.emplace_back("mode", "QERFCINV");
  3142. break;
  3143. case ElemwiseMultiType::Mode::QABS_GRAD:
  3144. props_.emplace_back("mode", "QABS_GRAD");
  3145. break;
  3146. case ElemwiseMultiType::Mode::QFLOOR_DIV:
  3147. props_.emplace_back("mode", "QFLOOR_DIV");
  3148. break;
  3149. case ElemwiseMultiType::Mode::QMOD:
  3150. props_.emplace_back("mode", "QMOD");
  3151. break;
  3152. case ElemwiseMultiType::Mode::QSIGMOID_GRAD:
  3153. props_.emplace_back("mode", "QSIGMOID_GRAD");
  3154. break;
  3155. case ElemwiseMultiType::Mode::QSWITCH_GT0:
  3156. props_.emplace_back("mode", "QSWITCH_GT0");
  3157. break;
  3158. case ElemwiseMultiType::Mode::QTANH_GRAD:
  3159. props_.emplace_back("mode", "QTANH_GRAD");
  3160. break;
  3161. case ElemwiseMultiType::Mode::QLT:
  3162. props_.emplace_back("mode", "QLT");
  3163. break;
  3164. case ElemwiseMultiType::Mode::QLEQ:
  3165. props_.emplace_back("mode", "QLEQ");
  3166. break;
  3167. case ElemwiseMultiType::Mode::QEQ:
  3168. props_.emplace_back("mode", "QEQ");
  3169. break;
  3170. case ElemwiseMultiType::Mode::QPOW:
  3171. props_.emplace_back("mode", "QPOW");
  3172. break;
  3173. case ElemwiseMultiType::Mode::QLOG_SUM_EXP:
  3174. props_.emplace_back("mode", "QLOG_SUM_EXP");
  3175. break;
  3176. case ElemwiseMultiType::Mode::QFAST_TANH_GRAD:
  3177. props_.emplace_back("mode", "QFAST_TANH_GRAD");
  3178. break;
  3179. case ElemwiseMultiType::Mode::QATAN2:
  3180. props_.emplace_back("mode", "QATAN2");
  3181. break;
  3182. case ElemwiseMultiType::Mode::QCOND_LEQ_MOV:
  3183. props_.emplace_back("mode", "QCOND_LEQ_MOV");
  3184. break;
  3185. case ElemwiseMultiType::Mode::QH_SWISH:
  3186. props_.emplace_back("mode", "QH_SWISH");
  3187. break;
  3188. case ElemwiseMultiType::Mode::QFUSE_ADD_H_SWISH:
  3189. props_.emplace_back("mode", "QFUSE_ADD_H_SWISH");
  3190. break;
  3191. case ElemwiseMultiType::Mode::QH_SWISH_GRAD:
  3192. props_.emplace_back("mode", "QH_SWISH_GRAD");
  3193. break;
  3194. case ElemwiseMultiType::Mode::FUSE_MUL_ADD3_INT16xF32xF32xF32:
  3195. props_.emplace_back("mode", "FUSE_MUL_ADD3_INT16xF32xF32xF32");
  3196. break;
  3197. case ElemwiseMultiType::Mode::MUL_INT16xF32xF32:
  3198. props_.emplace_back("mode", "MUL_INT16xF32xF32");
  3199. break;
  3200. case ElemwiseMultiType::Mode::FUSE_MUL_ADD3_UINT8xF32xF32xF32:
  3201. props_.emplace_back("mode", "FUSE_MUL_ADD3_UINT8xF32xF32xF32");
  3202. break;
  3203. case ElemwiseMultiType::Mode::QCOND_LT_MOV:
  3204. props_.emplace_back("mode", "QCOND_LT_MOV");
  3205. break;
  3206. default:
  3207. props_.emplace_back("mode", "INVALID");
  3208. break;
  3209. }
  3210. props_.emplace_back("dtype", op_.dtype.name());
  3211. return props_;
  3212. }
  3213. std::string ElemwiseMultiType_make_name_impl(const OpDef& def_) {
  3214. auto&& op_ = def_.cast_final_safe<ElemwiseMultiType>();
  3215. static_cast<void>(op_);
  3216. return to_string(op_.mode);
  3217. }
  3218. } // anonymous namespace
  3219. OP_TRAIT_REG(ElemwiseMultiType, ElemwiseMultiType)
  3220. .hash(ElemwiseMultiType_hash_impl)
  3221. .is_same_st(ElemwiseMultiType_is_same_st_impl)
  3222. .props(ElemwiseMultiType_props_impl)
  3223. .make_name(ElemwiseMultiType_make_name_impl);
  3224. MGB_DYN_TYPE_OBJ_FINAL_IMPL(ExternOpr);
  3225. namespace {
  3226. size_t ExternOpr_hash_impl(const OpDef& def_) {
  3227. auto&& op_ = def_.cast_final_safe<ExternOpr>();
  3228. static_cast<void>(op_);
  3229. return mgb::hash_pair_combine(
  3230. mgb::hash(op_.dyn_typeinfo()),
  3231. mgb::hash_pair_combine(
  3232. mgb::hash(op_.name),
  3233. mgb::hash(op_.data))
  3234. );
  3235. }
  3236. bool ExternOpr_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3237. auto &&a_ = lhs_.cast_final_safe<ExternOpr>(),
  3238. &&b_ = rhs_.cast_final_safe<ExternOpr>();
  3239. static_cast<void>(a_);
  3240. static_cast<void>(b_);
  3241. if (a_.output_shapes != b_.output_shapes) return false;
  3242. if (a_.name != b_.name) return false;
  3243. if (a_.data != b_.data) return false;
  3244. if (a_.data_len != b_.data_len) return false;
  3245. if (a_.output_dtypes != b_.output_dtypes) return false;
  3246. return true;
  3247. }
  3248. std::vector<std::pair<const char*, std::string>> ExternOpr_props_impl(const OpDef& def_) {
  3249. auto&& op_ = def_.cast_final_safe<ExternOpr>();
  3250. static_cast<void>(op_);
  3251. std::vector<std::pair<const char*, std::string>> props_;
  3252. props_.emplace_back("output_shapes", "{std::vector}");
  3253. props_.emplace_back("name", op_.name);
  3254. props_.emplace_back("data", op_.data);
  3255. props_.emplace_back("data_len", std::to_string(op_.data_len));
  3256. props_.emplace_back("output_dtypes", "{std::vector}");
  3257. return props_;
  3258. }
  3259. std::string ExternOpr_make_name_impl(const OpDef& def_) {
  3260. auto&& op_ = def_.cast_final_safe<ExternOpr>();
  3261. static_cast<void>(op_);
  3262. return "ExternOpr";
  3263. }
  3264. } // anonymous namespace
  3265. OP_TRAIT_REG(ExternOpr, ExternOpr)
  3266. .hash(ExternOpr_hash_impl)
  3267. .is_same_st(ExternOpr_is_same_st_impl)
  3268. .props(ExternOpr_props_impl)
  3269. .make_name(ExternOpr_make_name_impl);
  3270. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Eye);
  3271. namespace {
  3272. size_t Eye_hash_impl(const OpDef& def_) {
  3273. auto&& op_ = def_.cast_final_safe<Eye>();
  3274. static_cast<void>(op_);
  3275. size_t val = mgb::hash(op_.dyn_typeinfo());
  3276. val = mgb::hash_pair_combine(val, mgb::hash(op_.k));
  3277. val = mgb::hash_pair_combine(val, mgb::hash(op_.dtype.handle()));
  3278. val = mgb::hash_pair_combine(val, mgb::hash(op_.comp_node));
  3279. return val;
  3280. }
  3281. bool Eye_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3282. auto &&a_ = lhs_.cast_final_safe<Eye>(),
  3283. &&b_ = rhs_.cast_final_safe<Eye>();
  3284. static_cast<void>(a_);
  3285. static_cast<void>(b_);
  3286. if (a_.k != b_.k) return false;
  3287. if (a_.dtype != b_.dtype) return false;
  3288. if (a_.comp_node != b_.comp_node) return false;
  3289. return true;
  3290. }
  3291. std::vector<std::pair<const char*, std::string>> Eye_props_impl(const OpDef& def_) {
  3292. auto&& op_ = def_.cast_final_safe<Eye>();
  3293. static_cast<void>(op_);
  3294. std::vector<std::pair<const char*, std::string>> props_;
  3295. props_.emplace_back("k", std::to_string(op_.k));
  3296. props_.emplace_back("dtype", op_.dtype.name());
  3297. props_.emplace_back("comp_node", op_.comp_node.to_string());
  3298. return props_;
  3299. }
  3300. std::string Eye_make_name_impl(const OpDef& def_) {
  3301. auto&& op_ = def_.cast_final_safe<Eye>();
  3302. static_cast<void>(op_);
  3303. return "Eye";
  3304. }
  3305. } // anonymous namespace
  3306. OP_TRAIT_REG(Eye, Eye)
  3307. .hash(Eye_hash_impl)
  3308. .is_same_st(Eye_is_same_st_impl)
  3309. .props(Eye_props_impl)
  3310. .make_name(Eye_make_name_impl);
  3311. MGB_DYN_TYPE_OBJ_FINAL_IMPL(FakeQuant);
  3312. namespace {
  3313. size_t FakeQuant_hash_impl(const OpDef& def_) {
  3314. auto&& op_ = def_.cast_final_safe<FakeQuant>();
  3315. static_cast<void>(op_);
  3316. size_t val = mgb::hash(op_.dyn_typeinfo());
  3317. val = mgb::hash_pair_combine(val, mgb::hash(op_.qmin));
  3318. val = mgb::hash_pair_combine(val, mgb::hash(op_.qmax));
  3319. return val;
  3320. }
  3321. bool FakeQuant_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3322. auto &&a_ = lhs_.cast_final_safe<FakeQuant>(),
  3323. &&b_ = rhs_.cast_final_safe<FakeQuant>();
  3324. static_cast<void>(a_);
  3325. static_cast<void>(b_);
  3326. if (a_.qmin != b_.qmin) return false;
  3327. if (a_.qmax != b_.qmax) return false;
  3328. return true;
  3329. }
  3330. std::vector<std::pair<const char*, std::string>> FakeQuant_props_impl(const OpDef& def_) {
  3331. auto&& op_ = def_.cast_final_safe<FakeQuant>();
  3332. static_cast<void>(op_);
  3333. std::vector<std::pair<const char*, std::string>> props_;
  3334. props_.emplace_back("qmin", std::to_string(op_.qmin));
  3335. props_.emplace_back("qmax", std::to_string(op_.qmax));
  3336. return props_;
  3337. }
  3338. std::string FakeQuant_make_name_impl(const OpDef& def_) {
  3339. auto&& op_ = def_.cast_final_safe<FakeQuant>();
  3340. static_cast<void>(op_);
  3341. return "FakeQuant";
  3342. }
  3343. } // anonymous namespace
  3344. OP_TRAIT_REG(FakeQuant, FakeQuant)
  3345. .hash(FakeQuant_hash_impl)
  3346. .is_same_st(FakeQuant_is_same_st_impl)
  3347. .props(FakeQuant_props_impl)
  3348. .make_name(FakeQuant_make_name_impl);
  3349. MGB_DYN_TYPE_OBJ_FINAL_IMPL(FastpathCopy);
  3350. namespace {
  3351. size_t FastpathCopy_hash_impl(const OpDef& def_) {
  3352. auto&& op_ = def_.cast_final_safe<FastpathCopy>();
  3353. static_cast<void>(op_);
  3354. size_t val = mgb::hash(op_.dyn_typeinfo());
  3355. return val;
  3356. }
  3357. bool FastpathCopy_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3358. auto &&a_ = lhs_.cast_final_safe<FastpathCopy>(),
  3359. &&b_ = rhs_.cast_final_safe<FastpathCopy>();
  3360. static_cast<void>(a_);
  3361. static_cast<void>(b_);
  3362. return true;
  3363. }
  3364. std::vector<std::pair<const char*, std::string>> FastpathCopy_props_impl(const OpDef& def_) {
  3365. auto&& op_ = def_.cast_final_safe<FastpathCopy>();
  3366. static_cast<void>(op_);
  3367. std::vector<std::pair<const char*, std::string>> props_;
  3368. return props_;
  3369. }
  3370. std::string FastpathCopy_make_name_impl(const OpDef& def_) {
  3371. auto&& op_ = def_.cast_final_safe<FastpathCopy>();
  3372. static_cast<void>(op_);
  3373. return "FastpathCopy";
  3374. }
  3375. } // anonymous namespace
  3376. OP_TRAIT_REG(FastpathCopy, FastpathCopy)
  3377. .hash(FastpathCopy_hash_impl)
  3378. .is_same_st(FastpathCopy_is_same_st_impl)
  3379. .props(FastpathCopy_props_impl)
  3380. .make_name(FastpathCopy_make_name_impl);
  3381. MGB_DYN_TYPE_OBJ_FINAL_IMPL(GammaRNG);
  3382. namespace {
  3383. size_t GammaRNG_hash_impl(const OpDef& def_) {
  3384. auto&& op_ = def_.cast_final_safe<GammaRNG>();
  3385. static_cast<void>(op_);
  3386. return mgb::hash_pair_combine(
  3387. mgb::hash(op_.dyn_typeinfo()),
  3388. mgb::hash(op_.handle)
  3389. );
  3390. }
  3391. bool GammaRNG_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3392. auto &&a_ = lhs_.cast_final_safe<GammaRNG>(),
  3393. &&b_ = rhs_.cast_final_safe<GammaRNG>();
  3394. static_cast<void>(a_);
  3395. static_cast<void>(b_);
  3396. return a_.handle == b_.handle;}
  3397. std::vector<std::pair<const char*, std::string>> GammaRNG_props_impl(const OpDef& def_) {
  3398. auto&& op_ = def_.cast_final_safe<GammaRNG>();
  3399. static_cast<void>(op_);
  3400. std::vector<std::pair<const char*, std::string>> props_;
  3401. props_.emplace_back("seed", std::to_string(op_.seed));
  3402. props_.emplace_back("handle", std::to_string(op_.handle));
  3403. return props_;
  3404. }
  3405. std::string GammaRNG_make_name_impl(const OpDef& def_) {
  3406. auto&& op_ = def_.cast_final_safe<GammaRNG>();
  3407. static_cast<void>(op_);
  3408. return "GammaRNG";
  3409. }
  3410. } // anonymous namespace
  3411. OP_TRAIT_REG(GammaRNG, GammaRNG)
  3412. .hash(GammaRNG_hash_impl)
  3413. .is_same_st(GammaRNG_is_same_st_impl)
  3414. .props(GammaRNG_props_impl)
  3415. .make_name(GammaRNG_make_name_impl);
  3416. MGB_DYN_TYPE_OBJ_FINAL_IMPL(GaussianRNG);
  3417. namespace {
  3418. size_t GaussianRNG_hash_impl(const OpDef& def_) {
  3419. auto&& op_ = def_.cast_final_safe<GaussianRNG>();
  3420. static_cast<void>(op_);
  3421. return mgb::hash_pair_combine(
  3422. mgb::hash(op_.dyn_typeinfo()),
  3423. mgb::hash_pair_combine(
  3424. mgb::hash(op_.handle),
  3425. mgb::hash_pair_combine(
  3426. mgb::hash(op_.mean),
  3427. mgb::hash_pair_combine(
  3428. mgb::hash(op_.std),
  3429. mgb::hash(op_.dtype.enumv())
  3430. )
  3431. )
  3432. )
  3433. );
  3434. }
  3435. bool GaussianRNG_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3436. auto &&a_ = lhs_.cast_final_safe<GaussianRNG>(),
  3437. &&b_ = rhs_.cast_final_safe<GaussianRNG>();
  3438. static_cast<void>(a_);
  3439. static_cast<void>(b_);
  3440. return a_.handle == b_.handle && a_.mean == b_.mean && a_.std == b_.std && a_.dtype == b_.dtype;}
  3441. std::vector<std::pair<const char*, std::string>> GaussianRNG_props_impl(const OpDef& def_) {
  3442. auto&& op_ = def_.cast_final_safe<GaussianRNG>();
  3443. static_cast<void>(op_);
  3444. std::vector<std::pair<const char*, std::string>> props_;
  3445. props_.emplace_back("seed", std::to_string(op_.seed));
  3446. props_.emplace_back("mean", std::to_string(op_.mean));
  3447. props_.emplace_back("std", std::to_string(op_.std));
  3448. props_.emplace_back("dtype", op_.dtype.name());
  3449. props_.emplace_back("handle", std::to_string(op_.handle));
  3450. return props_;
  3451. }
  3452. std::string GaussianRNG_make_name_impl(const OpDef& def_) {
  3453. auto&& op_ = def_.cast_final_safe<GaussianRNG>();
  3454. static_cast<void>(op_);
  3455. return "GaussianRNG";
  3456. }
  3457. } // anonymous namespace
  3458. OP_TRAIT_REG(GaussianRNG, GaussianRNG)
  3459. .hash(GaussianRNG_hash_impl)
  3460. .is_same_st(GaussianRNG_is_same_st_impl)
  3461. .props(GaussianRNG_props_impl)
  3462. .make_name(GaussianRNG_make_name_impl);
  3463. MGB_DYN_TYPE_OBJ_FINAL_IMPL(GetVarShape);
  3464. namespace {
  3465. size_t GetVarShape_hash_impl(const OpDef& def_) {
  3466. auto&& op_ = def_.cast_final_safe<GetVarShape>();
  3467. static_cast<void>(op_);
  3468. size_t val = mgb::hash(op_.dyn_typeinfo());
  3469. val = mgb::hash_pair_combine(val, mgb::hash(op_.axis));
  3470. return val;
  3471. }
  3472. bool GetVarShape_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3473. auto &&a_ = lhs_.cast_final_safe<GetVarShape>(),
  3474. &&b_ = rhs_.cast_final_safe<GetVarShape>();
  3475. static_cast<void>(a_);
  3476. static_cast<void>(b_);
  3477. if (a_.axis != b_.axis) return false;
  3478. return true;
  3479. }
  3480. std::vector<std::pair<const char*, std::string>> GetVarShape_props_impl(const OpDef& def_) {
  3481. auto&& op_ = def_.cast_final_safe<GetVarShape>();
  3482. static_cast<void>(op_);
  3483. std::vector<std::pair<const char*, std::string>> props_;
  3484. props_.emplace_back("axis", std::to_string(op_.axis));
  3485. return props_;
  3486. }
  3487. std::string GetVarShape_make_name_impl(const OpDef& def_) {
  3488. auto&& op_ = def_.cast_final_safe<GetVarShape>();
  3489. static_cast<void>(op_);
  3490. return "GetVarShape";
  3491. }
  3492. } // anonymous namespace
  3493. OP_TRAIT_REG(GetVarShape, GetVarShape)
  3494. .hash(GetVarShape_hash_impl)
  3495. .is_same_st(GetVarShape_is_same_st_impl)
  3496. .props(GetVarShape_props_impl)
  3497. .make_name(GetVarShape_make_name_impl);
  3498. MGB_DYN_TYPE_OBJ_FINAL_IMPL(GroupLocal);
  3499. namespace {
  3500. size_t GroupLocal_hash_impl(const OpDef& def_) {
  3501. auto&& op_ = def_.cast_final_safe<GroupLocal>();
  3502. static_cast<void>(op_);
  3503. size_t val = mgb::hash(op_.dyn_typeinfo());
  3504. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode));
  3505. val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_h));
  3506. val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_w));
  3507. val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_h));
  3508. val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_w));
  3509. val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_h));
  3510. val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_w));
  3511. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.sparse));
  3512. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format));
  3513. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.compute_mode));
  3514. return val;
  3515. }
  3516. bool GroupLocal_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3517. auto &&a_ = lhs_.cast_final_safe<GroupLocal>(),
  3518. &&b_ = rhs_.cast_final_safe<GroupLocal>();
  3519. static_cast<void>(a_);
  3520. static_cast<void>(b_);
  3521. if (a_.mode != b_.mode) return false;
  3522. if (a_.pad_h != b_.pad_h) return false;
  3523. if (a_.pad_w != b_.pad_w) return false;
  3524. if (a_.stride_h != b_.stride_h) return false;
  3525. if (a_.stride_w != b_.stride_w) return false;
  3526. if (a_.dilate_h != b_.dilate_h) return false;
  3527. if (a_.dilate_w != b_.dilate_w) return false;
  3528. if (a_.sparse != b_.sparse) return false;
  3529. if (a_.format != b_.format) return false;
  3530. if (a_.compute_mode != b_.compute_mode) return false;
  3531. return true;
  3532. }
  3533. std::vector<std::pair<const char*, std::string>> GroupLocal_props_impl(const OpDef& def_) {
  3534. auto&& op_ = def_.cast_final_safe<GroupLocal>();
  3535. static_cast<void>(op_);
  3536. std::vector<std::pair<const char*, std::string>> props_;
  3537. switch (op_.mode){
  3538. case GroupLocal::Mode::CROSS_CORRELATION:
  3539. props_.emplace_back("mode", "CROSS_CORRELATION");
  3540. break;
  3541. case GroupLocal::Mode::CONVOLUTION:
  3542. props_.emplace_back("mode", "CONVOLUTION");
  3543. break;
  3544. default:
  3545. props_.emplace_back("mode", "INVALID");
  3546. break;
  3547. }
  3548. props_.emplace_back("pad_h", std::to_string(op_.pad_h));
  3549. props_.emplace_back("pad_w", std::to_string(op_.pad_w));
  3550. props_.emplace_back("stride_h", std::to_string(op_.stride_h));
  3551. props_.emplace_back("stride_w", std::to_string(op_.stride_w));
  3552. props_.emplace_back("dilate_h", std::to_string(op_.dilate_h));
  3553. props_.emplace_back("dilate_w", std::to_string(op_.dilate_w));
  3554. switch (op_.sparse){
  3555. case GroupLocal::Sparse::DENSE:
  3556. props_.emplace_back("sparse", "DENSE");
  3557. break;
  3558. case GroupLocal::Sparse::GROUP:
  3559. props_.emplace_back("sparse", "GROUP");
  3560. break;
  3561. default:
  3562. props_.emplace_back("sparse", "INVALID");
  3563. break;
  3564. }
  3565. switch (op_.format){
  3566. case GroupLocal::Format::NCHW:
  3567. props_.emplace_back("format", "NCHW");
  3568. break;
  3569. case GroupLocal::Format::NHWC:
  3570. props_.emplace_back("format", "NHWC");
  3571. break;
  3572. case GroupLocal::Format::NHWCD4:
  3573. props_.emplace_back("format", "NHWCD4");
  3574. break;
  3575. case GroupLocal::Format::NCHW4:
  3576. props_.emplace_back("format", "NCHW4");
  3577. break;
  3578. case GroupLocal::Format::NCHW8:
  3579. props_.emplace_back("format", "NCHW8");
  3580. break;
  3581. case GroupLocal::Format::NCHW32:
  3582. props_.emplace_back("format", "NCHW32");
  3583. break;
  3584. case GroupLocal::Format::NCHW88:
  3585. props_.emplace_back("format", "NCHW88");
  3586. break;
  3587. case GroupLocal::Format::NCHW44:
  3588. props_.emplace_back("format", "NCHW44");
  3589. break;
  3590. case GroupLocal::Format::NCHW44_DOT:
  3591. props_.emplace_back("format", "NCHW44_DOT");
  3592. break;
  3593. case GroupLocal::Format::NCHW4_NCHW32:
  3594. props_.emplace_back("format", "NCHW4_NCHW32");
  3595. break;
  3596. case GroupLocal::Format::NCHW32_NCHW4:
  3597. props_.emplace_back("format", "NCHW32_NCHW4");
  3598. break;
  3599. case GroupLocal::Format::NCHW4_NCHW:
  3600. props_.emplace_back("format", "NCHW4_NCHW");
  3601. break;
  3602. case GroupLocal::Format::NHWC_NCHW:
  3603. props_.emplace_back("format", "NHWC_NCHW");
  3604. break;
  3605. case GroupLocal::Format::NHWC_NCHW4_IC_SMALL:
  3606. props_.emplace_back("format", "NHWC_NCHW4_IC_SMALL");
  3607. break;
  3608. case GroupLocal::Format::NCHW_NCHW4_IC_SMALL:
  3609. props_.emplace_back("format", "NCHW_NCHW4_IC_SMALL");
  3610. break;
  3611. case GroupLocal::Format::CHWN4:
  3612. props_.emplace_back("format", "CHWN4");
  3613. break;
  3614. case GroupLocal::Format::NCHW64:
  3615. props_.emplace_back("format", "NCHW64");
  3616. break;
  3617. case GroupLocal::Format::NCHW4_NHWC:
  3618. props_.emplace_back("format", "NCHW4_NHWC");
  3619. break;
  3620. default:
  3621. props_.emplace_back("format", "INVALID");
  3622. break;
  3623. }
  3624. switch (op_.compute_mode){
  3625. case GroupLocal::ComputeMode::DEFAULT:
  3626. props_.emplace_back("compute_mode", "DEFAULT");
  3627. break;
  3628. case GroupLocal::ComputeMode::FLOAT32:
  3629. props_.emplace_back("compute_mode", "FLOAT32");
  3630. break;
  3631. default:
  3632. props_.emplace_back("compute_mode", "INVALID");
  3633. break;
  3634. }
  3635. return props_;
  3636. }
  3637. std::string GroupLocal_make_name_impl(const OpDef& def_) {
  3638. auto&& op_ = def_.cast_final_safe<GroupLocal>();
  3639. static_cast<void>(op_);
  3640. return "GroupLocal";
  3641. }
  3642. } // anonymous namespace
  3643. OP_TRAIT_REG(GroupLocal, GroupLocal)
  3644. .hash(GroupLocal_hash_impl)
  3645. .is_same_st(GroupLocal_is_same_st_impl)
  3646. .props(GroupLocal_props_impl)
  3647. .make_name(GroupLocal_make_name_impl);
  3648. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Identity);
  3649. namespace {
  3650. size_t Identity_hash_impl(const OpDef& def_) {
  3651. auto&& op_ = def_.cast_final_safe<Identity>();
  3652. static_cast<void>(op_);
  3653. size_t val = mgb::hash(op_.dyn_typeinfo());
  3654. return val;
  3655. }
  3656. bool Identity_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3657. auto &&a_ = lhs_.cast_final_safe<Identity>(),
  3658. &&b_ = rhs_.cast_final_safe<Identity>();
  3659. static_cast<void>(a_);
  3660. static_cast<void>(b_);
  3661. return true;
  3662. }
  3663. std::vector<std::pair<const char*, std::string>> Identity_props_impl(const OpDef& def_) {
  3664. auto&& op_ = def_.cast_final_safe<Identity>();
  3665. static_cast<void>(op_);
  3666. std::vector<std::pair<const char*, std::string>> props_;
  3667. return props_;
  3668. }
  3669. std::string Identity_make_name_impl(const OpDef& def_) {
  3670. auto&& op_ = def_.cast_final_safe<Identity>();
  3671. static_cast<void>(op_);
  3672. return "Identity";
  3673. }
  3674. } // anonymous namespace
  3675. OP_TRAIT_REG(Identity, Identity)
  3676. .hash(Identity_hash_impl)
  3677. .is_same_st(Identity_is_same_st_impl)
  3678. .props(Identity_props_impl)
  3679. .make_name(Identity_make_name_impl);
  3680. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Images2Neibs);
  3681. namespace {
  3682. size_t Images2Neibs_hash_impl(const OpDef& def_) {
  3683. auto&& op_ = def_.cast_final_safe<Images2Neibs>();
  3684. static_cast<void>(op_);
  3685. size_t val = mgb::hash(op_.dyn_typeinfo());
  3686. val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_h));
  3687. val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_w));
  3688. val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_h));
  3689. val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_w));
  3690. val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_h));
  3691. val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_w));
  3692. val = mgb::hash_pair_combine(val, mgb::hash(op_.window_h));
  3693. val = mgb::hash_pair_combine(val, mgb::hash(op_.window_w));
  3694. return val;
  3695. }
  3696. bool Images2Neibs_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3697. auto &&a_ = lhs_.cast_final_safe<Images2Neibs>(),
  3698. &&b_ = rhs_.cast_final_safe<Images2Neibs>();
  3699. static_cast<void>(a_);
  3700. static_cast<void>(b_);
  3701. if (a_.pad_h != b_.pad_h) return false;
  3702. if (a_.pad_w != b_.pad_w) return false;
  3703. if (a_.stride_h != b_.stride_h) return false;
  3704. if (a_.stride_w != b_.stride_w) return false;
  3705. if (a_.dilate_h != b_.dilate_h) return false;
  3706. if (a_.dilate_w != b_.dilate_w) return false;
  3707. if (a_.window_h != b_.window_h) return false;
  3708. if (a_.window_w != b_.window_w) return false;
  3709. return true;
  3710. }
  3711. std::vector<std::pair<const char*, std::string>> Images2Neibs_props_impl(const OpDef& def_) {
  3712. auto&& op_ = def_.cast_final_safe<Images2Neibs>();
  3713. static_cast<void>(op_);
  3714. std::vector<std::pair<const char*, std::string>> props_;
  3715. props_.emplace_back("pad_h", std::to_string(op_.pad_h));
  3716. props_.emplace_back("pad_w", std::to_string(op_.pad_w));
  3717. props_.emplace_back("stride_h", std::to_string(op_.stride_h));
  3718. props_.emplace_back("stride_w", std::to_string(op_.stride_w));
  3719. props_.emplace_back("dilate_h", std::to_string(op_.dilate_h));
  3720. props_.emplace_back("dilate_w", std::to_string(op_.dilate_w));
  3721. props_.emplace_back("window_h", std::to_string(op_.window_h));
  3722. props_.emplace_back("window_w", std::to_string(op_.window_w));
  3723. return props_;
  3724. }
  3725. std::string Images2Neibs_make_name_impl(const OpDef& def_) {
  3726. auto&& op_ = def_.cast_final_safe<Images2Neibs>();
  3727. static_cast<void>(op_);
  3728. return "Images2Neibs";
  3729. }
  3730. } // anonymous namespace
  3731. OP_TRAIT_REG(Images2Neibs, Images2Neibs)
  3732. .hash(Images2Neibs_hash_impl)
  3733. .is_same_st(Images2Neibs_is_same_st_impl)
  3734. .props(Images2Neibs_props_impl)
  3735. .make_name(Images2Neibs_make_name_impl);
  3736. MGB_DYN_TYPE_OBJ_FINAL_IMPL(IncrMeshIndexing);
  3737. namespace {
  3738. size_t IncrMeshIndexing_hash_impl(const OpDef& def_) {
  3739. auto&& op_ = def_.cast_final_safe<IncrMeshIndexing>();
  3740. static_cast<void>(op_);
  3741. size_t val = mgb::hash(op_.dyn_typeinfo());
  3742. val = mgb::hash_pair_combine(val, mgb::hash(op_.items));
  3743. return val;
  3744. }
  3745. bool IncrMeshIndexing_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3746. auto &&a_ = lhs_.cast_final_safe<IncrMeshIndexing>(),
  3747. &&b_ = rhs_.cast_final_safe<IncrMeshIndexing>();
  3748. static_cast<void>(a_);
  3749. static_cast<void>(b_);
  3750. if (a_.items != b_.items) return false;
  3751. return true;
  3752. }
  3753. std::vector<std::pair<const char*, std::string>> IncrMeshIndexing_props_impl(const OpDef& def_) {
  3754. auto&& op_ = def_.cast_final_safe<IncrMeshIndexing>();
  3755. static_cast<void>(op_);
  3756. std::vector<std::pair<const char*, std::string>> props_;
  3757. props_.emplace_back("items", "{std::vector}");
  3758. return props_;
  3759. }
  3760. std::string IncrMeshIndexing_make_name_impl(const OpDef& def_) {
  3761. auto&& op_ = def_.cast_final_safe<IncrMeshIndexing>();
  3762. static_cast<void>(op_);
  3763. return "IncrMeshIndexing";
  3764. }
  3765. } // anonymous namespace
  3766. OP_TRAIT_REG(IncrMeshIndexing, IncrMeshIndexing)
  3767. .hash(IncrMeshIndexing_hash_impl)
  3768. .is_same_st(IncrMeshIndexing_is_same_st_impl)
  3769. .props(IncrMeshIndexing_props_impl)
  3770. .make_name(IncrMeshIndexing_make_name_impl);
  3771. MGB_DYN_TYPE_OBJ_FINAL_IMPL(IncrSubtensor);
  3772. namespace {
  3773. size_t IncrSubtensor_hash_impl(const OpDef& def_) {
  3774. auto&& op_ = def_.cast_final_safe<IncrSubtensor>();
  3775. static_cast<void>(op_);
  3776. size_t val = mgb::hash(op_.dyn_typeinfo());
  3777. val = mgb::hash_pair_combine(val, mgb::hash(op_.items));
  3778. return val;
  3779. }
  3780. bool IncrSubtensor_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3781. auto &&a_ = lhs_.cast_final_safe<IncrSubtensor>(),
  3782. &&b_ = rhs_.cast_final_safe<IncrSubtensor>();
  3783. static_cast<void>(a_);
  3784. static_cast<void>(b_);
  3785. if (a_.items != b_.items) return false;
  3786. return true;
  3787. }
  3788. std::vector<std::pair<const char*, std::string>> IncrSubtensor_props_impl(const OpDef& def_) {
  3789. auto&& op_ = def_.cast_final_safe<IncrSubtensor>();
  3790. static_cast<void>(op_);
  3791. std::vector<std::pair<const char*, std::string>> props_;
  3792. props_.emplace_back("items", "{std::vector}");
  3793. return props_;
  3794. }
  3795. std::string IncrSubtensor_make_name_impl(const OpDef& def_) {
  3796. auto&& op_ = def_.cast_final_safe<IncrSubtensor>();
  3797. static_cast<void>(op_);
  3798. return "IncrSubtensor";
  3799. }
  3800. } // anonymous namespace
  3801. OP_TRAIT_REG(IncrSubtensor, IncrSubtensor)
  3802. .hash(IncrSubtensor_hash_impl)
  3803. .is_same_st(IncrSubtensor_is_same_st_impl)
  3804. .props(IncrSubtensor_props_impl)
  3805. .make_name(IncrSubtensor_make_name_impl);
  3806. MGB_DYN_TYPE_OBJ_FINAL_IMPL(IndexingIncrMultiAxisVec);
  3807. namespace {
  3808. size_t IndexingIncrMultiAxisVec_hash_impl(const OpDef& def_) {
  3809. auto&& op_ = def_.cast_final_safe<IndexingIncrMultiAxisVec>();
  3810. static_cast<void>(op_);
  3811. size_t val = mgb::hash(op_.dyn_typeinfo());
  3812. val = mgb::hash_pair_combine(val, mgb::hash(op_.items));
  3813. return val;
  3814. }
  3815. bool IndexingIncrMultiAxisVec_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3816. auto &&a_ = lhs_.cast_final_safe<IndexingIncrMultiAxisVec>(),
  3817. &&b_ = rhs_.cast_final_safe<IndexingIncrMultiAxisVec>();
  3818. static_cast<void>(a_);
  3819. static_cast<void>(b_);
  3820. if (a_.items != b_.items) return false;
  3821. return true;
  3822. }
  3823. std::vector<std::pair<const char*, std::string>> IndexingIncrMultiAxisVec_props_impl(const OpDef& def_) {
  3824. auto&& op_ = def_.cast_final_safe<IndexingIncrMultiAxisVec>();
  3825. static_cast<void>(op_);
  3826. std::vector<std::pair<const char*, std::string>> props_;
  3827. props_.emplace_back("items", "{std::vector}");
  3828. return props_;
  3829. }
  3830. std::string IndexingIncrMultiAxisVec_make_name_impl(const OpDef& def_) {
  3831. auto&& op_ = def_.cast_final_safe<IndexingIncrMultiAxisVec>();
  3832. static_cast<void>(op_);
  3833. return "IndexingIncrMultiAxisVec";
  3834. }
  3835. } // anonymous namespace
  3836. OP_TRAIT_REG(IndexingIncrMultiAxisVec, IndexingIncrMultiAxisVec)
  3837. .hash(IndexingIncrMultiAxisVec_hash_impl)
  3838. .is_same_st(IndexingIncrMultiAxisVec_is_same_st_impl)
  3839. .props(IndexingIncrMultiAxisVec_props_impl)
  3840. .make_name(IndexingIncrMultiAxisVec_make_name_impl);
  3841. MGB_DYN_TYPE_OBJ_FINAL_IMPL(IndexingMultiAxisVec);
  3842. namespace {
  3843. size_t IndexingMultiAxisVec_hash_impl(const OpDef& def_) {
  3844. auto&& op_ = def_.cast_final_safe<IndexingMultiAxisVec>();
  3845. static_cast<void>(op_);
  3846. size_t val = mgb::hash(op_.dyn_typeinfo());
  3847. val = mgb::hash_pair_combine(val, mgb::hash(op_.items));
  3848. return val;
  3849. }
  3850. bool IndexingMultiAxisVec_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3851. auto &&a_ = lhs_.cast_final_safe<IndexingMultiAxisVec>(),
  3852. &&b_ = rhs_.cast_final_safe<IndexingMultiAxisVec>();
  3853. static_cast<void>(a_);
  3854. static_cast<void>(b_);
  3855. if (a_.items != b_.items) return false;
  3856. return true;
  3857. }
  3858. std::vector<std::pair<const char*, std::string>> IndexingMultiAxisVec_props_impl(const OpDef& def_) {
  3859. auto&& op_ = def_.cast_final_safe<IndexingMultiAxisVec>();
  3860. static_cast<void>(op_);
  3861. std::vector<std::pair<const char*, std::string>> props_;
  3862. props_.emplace_back("items", "{std::vector}");
  3863. return props_;
  3864. }
  3865. std::string IndexingMultiAxisVec_make_name_impl(const OpDef& def_) {
  3866. auto&& op_ = def_.cast_final_safe<IndexingMultiAxisVec>();
  3867. static_cast<void>(op_);
  3868. return "IndexingMultiAxisVec";
  3869. }
  3870. } // anonymous namespace
  3871. OP_TRAIT_REG(IndexingMultiAxisVec, IndexingMultiAxisVec)
  3872. .hash(IndexingMultiAxisVec_hash_impl)
  3873. .is_same_st(IndexingMultiAxisVec_is_same_st_impl)
  3874. .props(IndexingMultiAxisVec_props_impl)
  3875. .make_name(IndexingMultiAxisVec_make_name_impl);
  3876. MGB_DYN_TYPE_OBJ_FINAL_IMPL(IndexingOneHot);
  3877. namespace {
  3878. size_t IndexingOneHot_hash_impl(const OpDef& def_) {
  3879. auto&& op_ = def_.cast_final_safe<IndexingOneHot>();
  3880. static_cast<void>(op_);
  3881. size_t val = mgb::hash(op_.dyn_typeinfo());
  3882. val = mgb::hash_pair_combine(val, mgb::hash(op_.axis));
  3883. val = mgb::hash_pair_combine(val, mgb::hash(op_.ndim));
  3884. return val;
  3885. }
  3886. bool IndexingOneHot_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3887. auto &&a_ = lhs_.cast_final_safe<IndexingOneHot>(),
  3888. &&b_ = rhs_.cast_final_safe<IndexingOneHot>();
  3889. static_cast<void>(a_);
  3890. static_cast<void>(b_);
  3891. if (a_.axis != b_.axis) return false;
  3892. if (a_.ndim != b_.ndim) return false;
  3893. return true;
  3894. }
  3895. std::vector<std::pair<const char*, std::string>> IndexingOneHot_props_impl(const OpDef& def_) {
  3896. auto&& op_ = def_.cast_final_safe<IndexingOneHot>();
  3897. static_cast<void>(op_);
  3898. std::vector<std::pair<const char*, std::string>> props_;
  3899. props_.emplace_back("axis", std::to_string(op_.axis));
  3900. props_.emplace_back("ndim", std::to_string(op_.ndim));
  3901. return props_;
  3902. }
  3903. std::string IndexingOneHot_make_name_impl(const OpDef& def_) {
  3904. auto&& op_ = def_.cast_final_safe<IndexingOneHot>();
  3905. static_cast<void>(op_);
  3906. return "IndexingOneHot";
  3907. }
  3908. } // anonymous namespace
  3909. OP_TRAIT_REG(IndexingOneHot, IndexingOneHot)
  3910. .hash(IndexingOneHot_hash_impl)
  3911. .is_same_st(IndexingOneHot_is_same_st_impl)
  3912. .props(IndexingOneHot_props_impl)
  3913. .make_name(IndexingOneHot_make_name_impl);
  3914. MGB_DYN_TYPE_OBJ_FINAL_IMPL(IndexingSetMultiAxisVec);
  3915. namespace {
  3916. size_t IndexingSetMultiAxisVec_hash_impl(const OpDef& def_) {
  3917. auto&& op_ = def_.cast_final_safe<IndexingSetMultiAxisVec>();
  3918. static_cast<void>(op_);
  3919. size_t val = mgb::hash(op_.dyn_typeinfo());
  3920. val = mgb::hash_pair_combine(val, mgb::hash(op_.items));
  3921. return val;
  3922. }
  3923. bool IndexingSetMultiAxisVec_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3924. auto &&a_ = lhs_.cast_final_safe<IndexingSetMultiAxisVec>(),
  3925. &&b_ = rhs_.cast_final_safe<IndexingSetMultiAxisVec>();
  3926. static_cast<void>(a_);
  3927. static_cast<void>(b_);
  3928. if (a_.items != b_.items) return false;
  3929. return true;
  3930. }
  3931. std::vector<std::pair<const char*, std::string>> IndexingSetMultiAxisVec_props_impl(const OpDef& def_) {
  3932. auto&& op_ = def_.cast_final_safe<IndexingSetMultiAxisVec>();
  3933. static_cast<void>(op_);
  3934. std::vector<std::pair<const char*, std::string>> props_;
  3935. props_.emplace_back("items", "{std::vector}");
  3936. return props_;
  3937. }
  3938. std::string IndexingSetMultiAxisVec_make_name_impl(const OpDef& def_) {
  3939. auto&& op_ = def_.cast_final_safe<IndexingSetMultiAxisVec>();
  3940. static_cast<void>(op_);
  3941. return "IndexingSetMultiAxisVec";
  3942. }
  3943. } // anonymous namespace
  3944. OP_TRAIT_REG(IndexingSetMultiAxisVec, IndexingSetMultiAxisVec)
  3945. .hash(IndexingSetMultiAxisVec_hash_impl)
  3946. .is_same_st(IndexingSetMultiAxisVec_is_same_st_impl)
  3947. .props(IndexingSetMultiAxisVec_props_impl)
  3948. .make_name(IndexingSetMultiAxisVec_make_name_impl);
  3949. MGB_DYN_TYPE_OBJ_FINAL_IMPL(IndexingSetOneHot);
  3950. namespace {
  3951. size_t IndexingSetOneHot_hash_impl(const OpDef& def_) {
  3952. auto&& op_ = def_.cast_final_safe<IndexingSetOneHot>();
  3953. static_cast<void>(op_);
  3954. size_t val = mgb::hash(op_.dyn_typeinfo());
  3955. val = mgb::hash_pair_combine(val, mgb::hash(op_.axis));
  3956. val = mgb::hash_pair_combine(val, mgb::hash(op_.ndim));
  3957. return val;
  3958. }
  3959. bool IndexingSetOneHot_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3960. auto &&a_ = lhs_.cast_final_safe<IndexingSetOneHot>(),
  3961. &&b_ = rhs_.cast_final_safe<IndexingSetOneHot>();
  3962. static_cast<void>(a_);
  3963. static_cast<void>(b_);
  3964. if (a_.axis != b_.axis) return false;
  3965. if (a_.ndim != b_.ndim) return false;
  3966. return true;
  3967. }
  3968. std::vector<std::pair<const char*, std::string>> IndexingSetOneHot_props_impl(const OpDef& def_) {
  3969. auto&& op_ = def_.cast_final_safe<IndexingSetOneHot>();
  3970. static_cast<void>(op_);
  3971. std::vector<std::pair<const char*, std::string>> props_;
  3972. props_.emplace_back("axis", std::to_string(op_.axis));
  3973. props_.emplace_back("ndim", std::to_string(op_.ndim));
  3974. return props_;
  3975. }
  3976. std::string IndexingSetOneHot_make_name_impl(const OpDef& def_) {
  3977. auto&& op_ = def_.cast_final_safe<IndexingSetOneHot>();
  3978. static_cast<void>(op_);
  3979. return "IndexingSetOneHot";
  3980. }
  3981. } // anonymous namespace
  3982. OP_TRAIT_REG(IndexingSetOneHot, IndexingSetOneHot)
  3983. .hash(IndexingSetOneHot_hash_impl)
  3984. .is_same_st(IndexingSetOneHot_is_same_st_impl)
  3985. .props(IndexingSetOneHot_props_impl)
  3986. .make_name(IndexingSetOneHot_make_name_impl);
  3987. MGB_DYN_TYPE_OBJ_FINAL_IMPL(InplaceAdd);
  3988. namespace {
  3989. size_t InplaceAdd_hash_impl(const OpDef& def_) {
  3990. auto&& op_ = def_.cast_final_safe<InplaceAdd>();
  3991. static_cast<void>(op_);
  3992. size_t val = mgb::hash(op_.dyn_typeinfo());
  3993. return val;
  3994. }
  3995. bool InplaceAdd_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  3996. auto &&a_ = lhs_.cast_final_safe<InplaceAdd>(),
  3997. &&b_ = rhs_.cast_final_safe<InplaceAdd>();
  3998. static_cast<void>(a_);
  3999. static_cast<void>(b_);
  4000. return true;
  4001. }
  4002. std::vector<std::pair<const char*, std::string>> InplaceAdd_props_impl(const OpDef& def_) {
  4003. auto&& op_ = def_.cast_final_safe<InplaceAdd>();
  4004. static_cast<void>(op_);
  4005. std::vector<std::pair<const char*, std::string>> props_;
  4006. return props_;
  4007. }
  4008. std::string InplaceAdd_make_name_impl(const OpDef& def_) {
  4009. auto&& op_ = def_.cast_final_safe<InplaceAdd>();
  4010. static_cast<void>(op_);
  4011. return "InplaceAdd";
  4012. }
  4013. } // anonymous namespace
  4014. OP_TRAIT_REG(InplaceAdd, InplaceAdd)
  4015. .hash(InplaceAdd_hash_impl)
  4016. .is_same_st(InplaceAdd_is_same_st_impl)
  4017. .props(InplaceAdd_props_impl)
  4018. .make_name(InplaceAdd_make_name_impl);
  4019. MGB_DYN_TYPE_OBJ_FINAL_IMPL(LAMBUpdate);
  4020. namespace {
  4021. size_t LAMBUpdate_hash_impl(const OpDef& def_) {
  4022. auto&& op_ = def_.cast_final_safe<LAMBUpdate>();
  4023. static_cast<void>(op_);
  4024. size_t val = mgb::hash(op_.dyn_typeinfo());
  4025. val = mgb::hash_pair_combine(val, mgb::hash(op_.beta_1));
  4026. val = mgb::hash_pair_combine(val, mgb::hash(op_.beta_2));
  4027. val = mgb::hash_pair_combine(val, mgb::hash(op_.step));
  4028. val = mgb::hash_pair_combine(val, mgb::hash(op_.lr));
  4029. val = mgb::hash_pair_combine(val, mgb::hash(op_.weight_decay));
  4030. val = mgb::hash_pair_combine(val, mgb::hash(op_.eps));
  4031. val = mgb::hash_pair_combine(val, mgb::hash(op_.bias_correction));
  4032. val = mgb::hash_pair_combine(val, mgb::hash(op_.always_adapt));
  4033. return val;
  4034. }
  4035. bool LAMBUpdate_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4036. auto &&a_ = lhs_.cast_final_safe<LAMBUpdate>(),
  4037. &&b_ = rhs_.cast_final_safe<LAMBUpdate>();
  4038. static_cast<void>(a_);
  4039. static_cast<void>(b_);
  4040. if (a_.beta_1 != b_.beta_1) return false;
  4041. if (a_.beta_2 != b_.beta_2) return false;
  4042. if (a_.step != b_.step) return false;
  4043. if (a_.lr != b_.lr) return false;
  4044. if (a_.weight_decay != b_.weight_decay) return false;
  4045. if (a_.eps != b_.eps) return false;
  4046. if (a_.bias_correction != b_.bias_correction) return false;
  4047. if (a_.always_adapt != b_.always_adapt) return false;
  4048. return true;
  4049. }
  4050. std::vector<std::pair<const char*, std::string>> LAMBUpdate_props_impl(const OpDef& def_) {
  4051. auto&& op_ = def_.cast_final_safe<LAMBUpdate>();
  4052. static_cast<void>(op_);
  4053. std::vector<std::pair<const char*, std::string>> props_;
  4054. props_.emplace_back("beta_1", std::to_string(op_.beta_1));
  4055. props_.emplace_back("beta_2", std::to_string(op_.beta_2));
  4056. props_.emplace_back("step", std::to_string(op_.step));
  4057. props_.emplace_back("lr", std::to_string(op_.lr));
  4058. props_.emplace_back("weight_decay", std::to_string(op_.weight_decay));
  4059. props_.emplace_back("eps", std::to_string(op_.eps));
  4060. props_.emplace_back("bias_correction", std::to_string(op_.bias_correction));
  4061. props_.emplace_back("always_adapt", std::to_string(op_.always_adapt));
  4062. return props_;
  4063. }
  4064. std::string LAMBUpdate_make_name_impl(const OpDef& def_) {
  4065. auto&& op_ = def_.cast_final_safe<LAMBUpdate>();
  4066. static_cast<void>(op_);
  4067. return "LAMBUpdate";
  4068. }
  4069. } // anonymous namespace
  4070. OP_TRAIT_REG(LAMBUpdate, LAMBUpdate)
  4071. .hash(LAMBUpdate_hash_impl)
  4072. .is_same_st(LAMBUpdate_is_same_st_impl)
  4073. .props(LAMBUpdate_props_impl)
  4074. .make_name(LAMBUpdate_make_name_impl);
  4075. MGB_DYN_TYPE_OBJ_FINAL_IMPL(LRN);
  4076. namespace {
  4077. size_t LRN_hash_impl(const OpDef& def_) {
  4078. auto&& op_ = def_.cast_final_safe<LRN>();
  4079. static_cast<void>(op_);
  4080. size_t val = mgb::hash(op_.dyn_typeinfo());
  4081. val = mgb::hash_pair_combine(val, mgb::hash(op_.n));
  4082. val = mgb::hash_pair_combine(val, mgb::hash(op_.k));
  4083. val = mgb::hash_pair_combine(val, mgb::hash(op_.alpha));
  4084. val = mgb::hash_pair_combine(val, mgb::hash(op_.beta));
  4085. return val;
  4086. }
  4087. bool LRN_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4088. auto &&a_ = lhs_.cast_final_safe<LRN>(),
  4089. &&b_ = rhs_.cast_final_safe<LRN>();
  4090. static_cast<void>(a_);
  4091. static_cast<void>(b_);
  4092. if (a_.n != b_.n) return false;
  4093. if (a_.k != b_.k) return false;
  4094. if (a_.alpha != b_.alpha) return false;
  4095. if (a_.beta != b_.beta) return false;
  4096. return true;
  4097. }
  4098. std::vector<std::pair<const char*, std::string>> LRN_props_impl(const OpDef& def_) {
  4099. auto&& op_ = def_.cast_final_safe<LRN>();
  4100. static_cast<void>(op_);
  4101. std::vector<std::pair<const char*, std::string>> props_;
  4102. props_.emplace_back("n", std::to_string(op_.n));
  4103. props_.emplace_back("k", std::to_string(op_.k));
  4104. props_.emplace_back("alpha", std::to_string(op_.alpha));
  4105. props_.emplace_back("beta", std::to_string(op_.beta));
  4106. return props_;
  4107. }
  4108. std::string LRN_make_name_impl(const OpDef& def_) {
  4109. auto&& op_ = def_.cast_final_safe<LRN>();
  4110. static_cast<void>(op_);
  4111. return "LRN";
  4112. }
  4113. } // anonymous namespace
  4114. OP_TRAIT_REG(LRN, LRN)
  4115. .hash(LRN_hash_impl)
  4116. .is_same_st(LRN_is_same_st_impl)
  4117. .props(LRN_props_impl)
  4118. .make_name(LRN_make_name_impl);
  4119. MGB_DYN_TYPE_OBJ_FINAL_IMPL(LSQ);
  4120. namespace {
  4121. size_t LSQ_hash_impl(const OpDef& def_) {
  4122. auto&& op_ = def_.cast_final_safe<LSQ>();
  4123. static_cast<void>(op_);
  4124. size_t val = mgb::hash(op_.dyn_typeinfo());
  4125. val = mgb::hash_pair_combine(val, mgb::hash(op_.qmin));
  4126. val = mgb::hash_pair_combine(val, mgb::hash(op_.qmax));
  4127. return val;
  4128. }
  4129. bool LSQ_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4130. auto &&a_ = lhs_.cast_final_safe<LSQ>(),
  4131. &&b_ = rhs_.cast_final_safe<LSQ>();
  4132. static_cast<void>(a_);
  4133. static_cast<void>(b_);
  4134. if (a_.qmin != b_.qmin) return false;
  4135. if (a_.qmax != b_.qmax) return false;
  4136. return true;
  4137. }
  4138. std::vector<std::pair<const char*, std::string>> LSQ_props_impl(const OpDef& def_) {
  4139. auto&& op_ = def_.cast_final_safe<LSQ>();
  4140. static_cast<void>(op_);
  4141. std::vector<std::pair<const char*, std::string>> props_;
  4142. props_.emplace_back("qmin", std::to_string(op_.qmin));
  4143. props_.emplace_back("qmax", std::to_string(op_.qmax));
  4144. return props_;
  4145. }
  4146. std::string LSQ_make_name_impl(const OpDef& def_) {
  4147. auto&& op_ = def_.cast_final_safe<LSQ>();
  4148. static_cast<void>(op_);
  4149. return "LSQ";
  4150. }
  4151. } // anonymous namespace
  4152. OP_TRAIT_REG(LSQ, LSQ)
  4153. .hash(LSQ_hash_impl)
  4154. .is_same_st(LSQ_is_same_st_impl)
  4155. .props(LSQ_props_impl)
  4156. .make_name(LSQ_make_name_impl);
  4157. MGB_DYN_TYPE_OBJ_FINAL_IMPL(LSTM);
  4158. namespace {
  4159. size_t LSTM_hash_impl(const OpDef& def_) {
  4160. auto&& op_ = def_.cast_final_safe<LSTM>();
  4161. static_cast<void>(op_);
  4162. size_t val = mgb::hash(op_.dyn_typeinfo());
  4163. val = mgb::hash_pair_combine(val, mgb::hash(op_.num_layers));
  4164. val = mgb::hash_pair_combine(val, mgb::hash(op_.bidirectional));
  4165. val = mgb::hash_pair_combine(val, mgb::hash(op_.bias));
  4166. val = mgb::hash_pair_combine(val, mgb::hash(op_.hidden_size));
  4167. val = mgb::hash_pair_combine(val, mgb::hash(op_.proj_size));
  4168. val = mgb::hash_pair_combine(val, mgb::hash(op_.dropout));
  4169. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.fwd_mode));
  4170. return val;
  4171. }
  4172. bool LSTM_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4173. auto &&a_ = lhs_.cast_final_safe<LSTM>(),
  4174. &&b_ = rhs_.cast_final_safe<LSTM>();
  4175. static_cast<void>(a_);
  4176. static_cast<void>(b_);
  4177. if (a_.num_layers != b_.num_layers) return false;
  4178. if (a_.bidirectional != b_.bidirectional) return false;
  4179. if (a_.bias != b_.bias) return false;
  4180. if (a_.hidden_size != b_.hidden_size) return false;
  4181. if (a_.proj_size != b_.proj_size) return false;
  4182. if (a_.dropout != b_.dropout) return false;
  4183. if (a_.fwd_mode != b_.fwd_mode) return false;
  4184. return true;
  4185. }
  4186. std::vector<std::pair<const char*, std::string>> LSTM_props_impl(const OpDef& def_) {
  4187. auto&& op_ = def_.cast_final_safe<LSTM>();
  4188. static_cast<void>(op_);
  4189. std::vector<std::pair<const char*, std::string>> props_;
  4190. props_.emplace_back("num_layers", std::to_string(op_.num_layers));
  4191. props_.emplace_back("bidirectional", std::to_string(op_.bidirectional));
  4192. props_.emplace_back("bias", std::to_string(op_.bias));
  4193. props_.emplace_back("hidden_size", std::to_string(op_.hidden_size));
  4194. props_.emplace_back("proj_size", std::to_string(op_.proj_size));
  4195. props_.emplace_back("dropout", std::to_string(op_.dropout));
  4196. switch (op_.fwd_mode){
  4197. case LSTM::FwdMode::TRAINING:
  4198. props_.emplace_back("fwd_mode", "TRAINING");
  4199. break;
  4200. case LSTM::FwdMode::INFERENCE:
  4201. props_.emplace_back("fwd_mode", "INFERENCE");
  4202. break;
  4203. default:
  4204. props_.emplace_back("fwd_mode", "INVALID");
  4205. break;
  4206. }
  4207. return props_;
  4208. }
  4209. std::string LSTM_make_name_impl(const OpDef& def_) {
  4210. auto&& op_ = def_.cast_final_safe<LSTM>();
  4211. static_cast<void>(op_);
  4212. return "LSTM";
  4213. }
  4214. } // anonymous namespace
  4215. OP_TRAIT_REG(LSTM, LSTM)
  4216. .hash(LSTM_hash_impl)
  4217. .is_same_st(LSTM_is_same_st_impl)
  4218. .props(LSTM_props_impl)
  4219. .make_name(LSTM_make_name_impl);
  4220. MGB_DYN_TYPE_OBJ_FINAL_IMPL(LSTMCell);
  4221. namespace {
  4222. size_t LSTMCell_hash_impl(const OpDef& def_) {
  4223. auto&& op_ = def_.cast_final_safe<LSTMCell>();
  4224. static_cast<void>(op_);
  4225. size_t val = mgb::hash(op_.dyn_typeinfo());
  4226. return val;
  4227. }
  4228. bool LSTMCell_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4229. auto &&a_ = lhs_.cast_final_safe<LSTMCell>(),
  4230. &&b_ = rhs_.cast_final_safe<LSTMCell>();
  4231. static_cast<void>(a_);
  4232. static_cast<void>(b_);
  4233. return true;
  4234. }
  4235. std::vector<std::pair<const char*, std::string>> LSTMCell_props_impl(const OpDef& def_) {
  4236. auto&& op_ = def_.cast_final_safe<LSTMCell>();
  4237. static_cast<void>(op_);
  4238. std::vector<std::pair<const char*, std::string>> props_;
  4239. return props_;
  4240. }
  4241. std::string LSTMCell_make_name_impl(const OpDef& def_) {
  4242. auto&& op_ = def_.cast_final_safe<LSTMCell>();
  4243. static_cast<void>(op_);
  4244. return "LSTMCell";
  4245. }
  4246. } // anonymous namespace
  4247. OP_TRAIT_REG(LSTMCell, LSTMCell)
  4248. .hash(LSTMCell_hash_impl)
  4249. .is_same_st(LSTMCell_is_same_st_impl)
  4250. .props(LSTMCell_props_impl)
  4251. .make_name(LSTMCell_make_name_impl);
  4252. MGB_DYN_TYPE_OBJ_FINAL_IMPL(LayerNorm);
  4253. namespace {
  4254. size_t LayerNorm_hash_impl(const OpDef& def_) {
  4255. auto&& op_ = def_.cast_final_safe<LayerNorm>();
  4256. static_cast<void>(op_);
  4257. size_t val = mgb::hash(op_.dyn_typeinfo());
  4258. val = mgb::hash_pair_combine(val, mgb::hash(op_.affine));
  4259. val = mgb::hash_pair_combine(val, mgb::hash(op_.eps));
  4260. val = mgb::hash_pair_combine(val, mgb::hash(op_.normalized_dim));
  4261. val = mgb::hash_pair_combine(val, mgb::hash(op_.normalized_size));
  4262. return val;
  4263. }
  4264. bool LayerNorm_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4265. auto &&a_ = lhs_.cast_final_safe<LayerNorm>(),
  4266. &&b_ = rhs_.cast_final_safe<LayerNorm>();
  4267. static_cast<void>(a_);
  4268. static_cast<void>(b_);
  4269. if (a_.affine != b_.affine) return false;
  4270. if (a_.eps != b_.eps) return false;
  4271. if (a_.normalized_dim != b_.normalized_dim) return false;
  4272. if (a_.normalized_size != b_.normalized_size) return false;
  4273. return true;
  4274. }
  4275. std::vector<std::pair<const char*, std::string>> LayerNorm_props_impl(const OpDef& def_) {
  4276. auto&& op_ = def_.cast_final_safe<LayerNorm>();
  4277. static_cast<void>(op_);
  4278. std::vector<std::pair<const char*, std::string>> props_;
  4279. props_.emplace_back("affine", std::to_string(op_.affine));
  4280. props_.emplace_back("eps", std::to_string(op_.eps));
  4281. props_.emplace_back("normalized_dim", std::to_string(op_.normalized_dim));
  4282. props_.emplace_back("normalized_size", std::to_string(op_.normalized_size));
  4283. return props_;
  4284. }
  4285. std::string LayerNorm_make_name_impl(const OpDef& def_) {
  4286. auto&& op_ = def_.cast_final_safe<LayerNorm>();
  4287. static_cast<void>(op_);
  4288. return "LayerNorm";
  4289. }
  4290. } // anonymous namespace
  4291. OP_TRAIT_REG(LayerNorm, LayerNorm)
  4292. .hash(LayerNorm_hash_impl)
  4293. .is_same_st(LayerNorm_is_same_st_impl)
  4294. .props(LayerNorm_props_impl)
  4295. .make_name(LayerNorm_make_name_impl);
  4296. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Linspace);
  4297. namespace {
  4298. size_t Linspace_hash_impl(const OpDef& def_) {
  4299. auto&& op_ = def_.cast_final_safe<Linspace>();
  4300. static_cast<void>(op_);
  4301. size_t val = mgb::hash(op_.dyn_typeinfo());
  4302. val = mgb::hash_pair_combine(val, mgb::hash(op_.endpoint));
  4303. val = mgb::hash_pair_combine(val, mgb::hash(op_.comp_node));
  4304. return val;
  4305. }
  4306. bool Linspace_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4307. auto &&a_ = lhs_.cast_final_safe<Linspace>(),
  4308. &&b_ = rhs_.cast_final_safe<Linspace>();
  4309. static_cast<void>(a_);
  4310. static_cast<void>(b_);
  4311. if (a_.endpoint != b_.endpoint) return false;
  4312. if (a_.comp_node != b_.comp_node) return false;
  4313. return true;
  4314. }
  4315. std::vector<std::pair<const char*, std::string>> Linspace_props_impl(const OpDef& def_) {
  4316. auto&& op_ = def_.cast_final_safe<Linspace>();
  4317. static_cast<void>(op_);
  4318. std::vector<std::pair<const char*, std::string>> props_;
  4319. props_.emplace_back("endpoint", std::to_string(op_.endpoint));
  4320. props_.emplace_back("comp_node", op_.comp_node.to_string());
  4321. return props_;
  4322. }
  4323. std::string Linspace_make_name_impl(const OpDef& def_) {
  4324. auto&& op_ = def_.cast_final_safe<Linspace>();
  4325. static_cast<void>(op_);
  4326. return "Linspace";
  4327. }
  4328. } // anonymous namespace
  4329. OP_TRAIT_REG(Linspace, Linspace)
  4330. .hash(Linspace_hash_impl)
  4331. .is_same_st(Linspace_is_same_st_impl)
  4332. .props(Linspace_props_impl)
  4333. .make_name(Linspace_make_name_impl);
  4334. MGB_DYN_TYPE_OBJ_FINAL_IMPL(MagicMindRuntime);
  4335. namespace {
  4336. size_t MagicMindRuntime_hash_impl(const OpDef& def_) {
  4337. auto&& op_ = def_.cast_final_safe<MagicMindRuntime>();
  4338. static_cast<void>(op_);
  4339. size_t val = mgb::hash(op_.dyn_typeinfo());
  4340. val = mgb::hash_pair_combine(val, mgb::hash(op_.buf));
  4341. val = mgb::hash_pair_combine(val, mgb::hash(op_.buf_size));
  4342. return val;
  4343. }
  4344. bool MagicMindRuntime_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4345. auto &&a_ = lhs_.cast_final_safe<MagicMindRuntime>(),
  4346. &&b_ = rhs_.cast_final_safe<MagicMindRuntime>();
  4347. static_cast<void>(a_);
  4348. static_cast<void>(b_);
  4349. if (a_.buf != b_.buf) return false;
  4350. if (a_.buf_size != b_.buf_size) return false;
  4351. return true;
  4352. }
  4353. std::vector<std::pair<const char*, std::string>> MagicMindRuntime_props_impl(const OpDef& def_) {
  4354. auto&& op_ = def_.cast_final_safe<MagicMindRuntime>();
  4355. static_cast<void>(op_);
  4356. std::vector<std::pair<const char*, std::string>> props_;
  4357. props_.emplace_back("buf", op_.buf);
  4358. props_.emplace_back("buf_size", std::to_string(op_.buf_size));
  4359. return props_;
  4360. }
  4361. std::string MagicMindRuntime_make_name_impl(const OpDef& def_) {
  4362. auto&& op_ = def_.cast_final_safe<MagicMindRuntime>();
  4363. static_cast<void>(op_);
  4364. return "MagicMindRuntime";
  4365. }
  4366. } // anonymous namespace
  4367. OP_TRAIT_REG(MagicMindRuntime, MagicMindRuntime)
  4368. .hash(MagicMindRuntime_hash_impl)
  4369. .is_same_st(MagicMindRuntime_is_same_st_impl)
  4370. .props(MagicMindRuntime_props_impl)
  4371. .make_name(MagicMindRuntime_make_name_impl);
  4372. MGB_DYN_TYPE_OBJ_FINAL_IMPL(MatrixInverse);
  4373. namespace {
  4374. size_t MatrixInverse_hash_impl(const OpDef& def_) {
  4375. auto&& op_ = def_.cast_final_safe<MatrixInverse>();
  4376. static_cast<void>(op_);
  4377. size_t val = mgb::hash(op_.dyn_typeinfo());
  4378. return val;
  4379. }
  4380. bool MatrixInverse_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4381. auto &&a_ = lhs_.cast_final_safe<MatrixInverse>(),
  4382. &&b_ = rhs_.cast_final_safe<MatrixInverse>();
  4383. static_cast<void>(a_);
  4384. static_cast<void>(b_);
  4385. return true;
  4386. }
  4387. std::vector<std::pair<const char*, std::string>> MatrixInverse_props_impl(const OpDef& def_) {
  4388. auto&& op_ = def_.cast_final_safe<MatrixInverse>();
  4389. static_cast<void>(op_);
  4390. std::vector<std::pair<const char*, std::string>> props_;
  4391. return props_;
  4392. }
  4393. std::string MatrixInverse_make_name_impl(const OpDef& def_) {
  4394. auto&& op_ = def_.cast_final_safe<MatrixInverse>();
  4395. static_cast<void>(op_);
  4396. return "MatrixInverse";
  4397. }
  4398. } // anonymous namespace
  4399. OP_TRAIT_REG(MatrixInverse, MatrixInverse)
  4400. .hash(MatrixInverse_hash_impl)
  4401. .is_same_st(MatrixInverse_is_same_st_impl)
  4402. .props(MatrixInverse_props_impl)
  4403. .make_name(MatrixInverse_make_name_impl);
  4404. MGB_DYN_TYPE_OBJ_FINAL_IMPL(MatrixMul);
  4405. namespace {
  4406. size_t MatrixMul_hash_impl(const OpDef& def_) {
  4407. auto&& op_ = def_.cast_final_safe<MatrixMul>();
  4408. static_cast<void>(op_);
  4409. size_t val = mgb::hash(op_.dyn_typeinfo());
  4410. val = mgb::hash_pair_combine(val, mgb::hash(op_.transposeA));
  4411. val = mgb::hash_pair_combine(val, mgb::hash(op_.transposeB));
  4412. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.compute_mode));
  4413. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format));
  4414. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.strategy));
  4415. val = mgb::hash_pair_combine(val, mgb::hash(op_.workspace_limit));
  4416. val = mgb::hash_pair_combine(val, mgb::hash(op_.dimA));
  4417. val = mgb::hash_pair_combine(val, mgb::hash(op_.dimB));
  4418. return val;
  4419. }
  4420. bool MatrixMul_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4421. auto &&a_ = lhs_.cast_final_safe<MatrixMul>(),
  4422. &&b_ = rhs_.cast_final_safe<MatrixMul>();
  4423. static_cast<void>(a_);
  4424. static_cast<void>(b_);
  4425. if (a_.transposeA != b_.transposeA) return false;
  4426. if (a_.transposeB != b_.transposeB) return false;
  4427. if (a_.compute_mode != b_.compute_mode) return false;
  4428. if (a_.format != b_.format) return false;
  4429. if (a_.strategy != b_.strategy) return false;
  4430. if (a_.workspace_limit != b_.workspace_limit) return false;
  4431. if (a_.dimA != b_.dimA) return false;
  4432. if (a_.dimB != b_.dimB) return false;
  4433. return true;
  4434. }
  4435. std::vector<std::pair<const char*, std::string>> MatrixMul_props_impl(const OpDef& def_) {
  4436. auto&& op_ = def_.cast_final_safe<MatrixMul>();
  4437. static_cast<void>(op_);
  4438. std::vector<std::pair<const char*, std::string>> props_;
  4439. props_.emplace_back("transposeA", std::to_string(op_.transposeA));
  4440. props_.emplace_back("transposeB", std::to_string(op_.transposeB));
  4441. switch (op_.compute_mode){
  4442. case MatrixMul::ComputeMode::DEFAULT:
  4443. props_.emplace_back("compute_mode", "DEFAULT");
  4444. break;
  4445. case MatrixMul::ComputeMode::FLOAT32:
  4446. props_.emplace_back("compute_mode", "FLOAT32");
  4447. break;
  4448. default:
  4449. props_.emplace_back("compute_mode", "INVALID");
  4450. break;
  4451. }
  4452. switch (op_.format){
  4453. case MatrixMul::Format::DEFAULT:
  4454. props_.emplace_back("format", "DEFAULT");
  4455. break;
  4456. case MatrixMul::Format::MK4:
  4457. props_.emplace_back("format", "MK4");
  4458. break;
  4459. case MatrixMul::Format::MK8:
  4460. props_.emplace_back("format", "MK8");
  4461. break;
  4462. case MatrixMul::Format::MK4_DOT:
  4463. props_.emplace_back("format", "MK4_DOT");
  4464. break;
  4465. case MatrixMul::Format::N32K4_DOT:
  4466. props_.emplace_back("format", "N32K4_DOT");
  4467. break;
  4468. default:
  4469. props_.emplace_back("format", "INVALID");
  4470. break;
  4471. }
  4472. switch (op_.strategy){
  4473. case MatrixMul::Strategy::HEURISTIC:
  4474. props_.emplace_back("strategy", "HEURISTIC");
  4475. break;
  4476. case MatrixMul::Strategy::PROFILE:
  4477. props_.emplace_back("strategy", "PROFILE");
  4478. break;
  4479. case MatrixMul::Strategy::REPRODUCIBLE:
  4480. props_.emplace_back("strategy", "REPRODUCIBLE");
  4481. break;
  4482. case MatrixMul::Strategy::OPTIMIZED:
  4483. props_.emplace_back("strategy", "OPTIMIZED");
  4484. break;
  4485. default:
  4486. props_.emplace_back("strategy", "INVALID");
  4487. break;
  4488. }
  4489. props_.emplace_back("workspace_limit", std::to_string(op_.workspace_limit));
  4490. props_.emplace_back("dimA", std::to_string(op_.dimA));
  4491. props_.emplace_back("dimB", std::to_string(op_.dimB));
  4492. return props_;
  4493. }
  4494. std::string MatrixMul_make_name_impl(const OpDef& def_) {
  4495. auto&& op_ = def_.cast_final_safe<MatrixMul>();
  4496. static_cast<void>(op_);
  4497. return "MatrixMul";
  4498. }
  4499. } // anonymous namespace
  4500. OP_TRAIT_REG(MatrixMul, MatrixMul)
  4501. .hash(MatrixMul_hash_impl)
  4502. .is_same_st(MatrixMul_is_same_st_impl)
  4503. .props(MatrixMul_props_impl)
  4504. .make_name(MatrixMul_make_name_impl);
  4505. MGB_DYN_TYPE_OBJ_FINAL_IMPL(MeshIndexing);
  4506. namespace {
  4507. size_t MeshIndexing_hash_impl(const OpDef& def_) {
  4508. auto&& op_ = def_.cast_final_safe<MeshIndexing>();
  4509. static_cast<void>(op_);
  4510. size_t val = mgb::hash(op_.dyn_typeinfo());
  4511. val = mgb::hash_pair_combine(val, mgb::hash(op_.items));
  4512. return val;
  4513. }
  4514. bool MeshIndexing_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4515. auto &&a_ = lhs_.cast_final_safe<MeshIndexing>(),
  4516. &&b_ = rhs_.cast_final_safe<MeshIndexing>();
  4517. static_cast<void>(a_);
  4518. static_cast<void>(b_);
  4519. if (a_.items != b_.items) return false;
  4520. return true;
  4521. }
  4522. std::vector<std::pair<const char*, std::string>> MeshIndexing_props_impl(const OpDef& def_) {
  4523. auto&& op_ = def_.cast_final_safe<MeshIndexing>();
  4524. static_cast<void>(op_);
  4525. std::vector<std::pair<const char*, std::string>> props_;
  4526. props_.emplace_back("items", "{std::vector}");
  4527. return props_;
  4528. }
  4529. std::string MeshIndexing_make_name_impl(const OpDef& def_) {
  4530. auto&& op_ = def_.cast_final_safe<MeshIndexing>();
  4531. static_cast<void>(op_);
  4532. return "MeshIndexing";
  4533. }
  4534. } // anonymous namespace
  4535. OP_TRAIT_REG(MeshIndexing, MeshIndexing)
  4536. .hash(MeshIndexing_hash_impl)
  4537. .is_same_st(MeshIndexing_is_same_st_impl)
  4538. .props(MeshIndexing_props_impl)
  4539. .make_name(MeshIndexing_make_name_impl);
  4540. MGB_DYN_TYPE_OBJ_FINAL_IMPL(NMSKeep);
  4541. namespace {
  4542. size_t NMSKeep_hash_impl(const OpDef& def_) {
  4543. auto&& op_ = def_.cast_final_safe<NMSKeep>();
  4544. static_cast<void>(op_);
  4545. size_t val = mgb::hash(op_.dyn_typeinfo());
  4546. val = mgb::hash_pair_combine(val, mgb::hash(op_.iou_thresh));
  4547. val = mgb::hash_pair_combine(val, mgb::hash(op_.max_output));
  4548. return val;
  4549. }
  4550. bool NMSKeep_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4551. auto &&a_ = lhs_.cast_final_safe<NMSKeep>(),
  4552. &&b_ = rhs_.cast_final_safe<NMSKeep>();
  4553. static_cast<void>(a_);
  4554. static_cast<void>(b_);
  4555. if (a_.iou_thresh != b_.iou_thresh) return false;
  4556. if (a_.max_output != b_.max_output) return false;
  4557. return true;
  4558. }
  4559. std::vector<std::pair<const char*, std::string>> NMSKeep_props_impl(const OpDef& def_) {
  4560. auto&& op_ = def_.cast_final_safe<NMSKeep>();
  4561. static_cast<void>(op_);
  4562. std::vector<std::pair<const char*, std::string>> props_;
  4563. props_.emplace_back("iou_thresh", std::to_string(op_.iou_thresh));
  4564. props_.emplace_back("max_output", std::to_string(op_.max_output));
  4565. return props_;
  4566. }
  4567. std::string NMSKeep_make_name_impl(const OpDef& def_) {
  4568. auto&& op_ = def_.cast_final_safe<NMSKeep>();
  4569. static_cast<void>(op_);
  4570. return "NMSKeep";
  4571. }
  4572. } // anonymous namespace
  4573. OP_TRAIT_REG(NMSKeep, NMSKeep)
  4574. .hash(NMSKeep_hash_impl)
  4575. .is_same_st(NMSKeep_is_same_st_impl)
  4576. .props(NMSKeep_props_impl)
  4577. .make_name(NMSKeep_make_name_impl);
  4578. MGB_DYN_TYPE_OBJ_FINAL_IMPL(NvOf);
  4579. namespace {
  4580. size_t NvOf_hash_impl(const OpDef& def_) {
  4581. auto&& op_ = def_.cast_final_safe<NvOf>();
  4582. static_cast<void>(op_);
  4583. size_t val = mgb::hash(op_.dyn_typeinfo());
  4584. val = mgb::hash_pair_combine(val, mgb::hash(op_.precision));
  4585. return val;
  4586. }
  4587. bool NvOf_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4588. auto &&a_ = lhs_.cast_final_safe<NvOf>(),
  4589. &&b_ = rhs_.cast_final_safe<NvOf>();
  4590. static_cast<void>(a_);
  4591. static_cast<void>(b_);
  4592. if (a_.precision != b_.precision) return false;
  4593. return true;
  4594. }
  4595. std::vector<std::pair<const char*, std::string>> NvOf_props_impl(const OpDef& def_) {
  4596. auto&& op_ = def_.cast_final_safe<NvOf>();
  4597. static_cast<void>(op_);
  4598. std::vector<std::pair<const char*, std::string>> props_;
  4599. props_.emplace_back("precision", std::to_string(op_.precision));
  4600. return props_;
  4601. }
  4602. std::string NvOf_make_name_impl(const OpDef& def_) {
  4603. auto&& op_ = def_.cast_final_safe<NvOf>();
  4604. static_cast<void>(op_);
  4605. return "NvOf";
  4606. }
  4607. } // anonymous namespace
  4608. OP_TRAIT_REG(NvOf, NvOf)
  4609. .hash(NvOf_hash_impl)
  4610. .is_same_st(NvOf_is_same_st_impl)
  4611. .props(NvOf_props_impl)
  4612. .make_name(NvOf_make_name_impl);
  4613. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Padding);
  4614. namespace {
  4615. size_t Padding_hash_impl(const OpDef& def_) {
  4616. auto&& op_ = def_.cast_final_safe<Padding>();
  4617. static_cast<void>(op_);
  4618. size_t val = mgb::hash(op_.dyn_typeinfo());
  4619. val = mgb::hash_pair_combine(val, mgb::hash(op_.front_offset_dim0));
  4620. val = mgb::hash_pair_combine(val, mgb::hash(op_.front_offset_dim1));
  4621. val = mgb::hash_pair_combine(val, mgb::hash(op_.front_offset_dim2));
  4622. val = mgb::hash_pair_combine(val, mgb::hash(op_.front_offset_dim3));
  4623. val = mgb::hash_pair_combine(val, mgb::hash(op_.front_offset_dim4));
  4624. val = mgb::hash_pair_combine(val, mgb::hash(op_.front_offset_dim5));
  4625. val = mgb::hash_pair_combine(val, mgb::hash(op_.front_offset_dim6));
  4626. val = mgb::hash_pair_combine(val, mgb::hash(op_.back_offset_dim0));
  4627. val = mgb::hash_pair_combine(val, mgb::hash(op_.back_offset_dim1));
  4628. val = mgb::hash_pair_combine(val, mgb::hash(op_.back_offset_dim2));
  4629. val = mgb::hash_pair_combine(val, mgb::hash(op_.back_offset_dim3));
  4630. val = mgb::hash_pair_combine(val, mgb::hash(op_.back_offset_dim4));
  4631. val = mgb::hash_pair_combine(val, mgb::hash(op_.back_offset_dim5));
  4632. val = mgb::hash_pair_combine(val, mgb::hash(op_.back_offset_dim6));
  4633. val = mgb::hash_pair_combine(val, mgb::hash(op_.padding_val));
  4634. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.padding_mode));
  4635. return val;
  4636. }
  4637. bool Padding_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4638. auto &&a_ = lhs_.cast_final_safe<Padding>(),
  4639. &&b_ = rhs_.cast_final_safe<Padding>();
  4640. static_cast<void>(a_);
  4641. static_cast<void>(b_);
  4642. if (a_.front_offset_dim0 != b_.front_offset_dim0) return false;
  4643. if (a_.front_offset_dim1 != b_.front_offset_dim1) return false;
  4644. if (a_.front_offset_dim2 != b_.front_offset_dim2) return false;
  4645. if (a_.front_offset_dim3 != b_.front_offset_dim3) return false;
  4646. if (a_.front_offset_dim4 != b_.front_offset_dim4) return false;
  4647. if (a_.front_offset_dim5 != b_.front_offset_dim5) return false;
  4648. if (a_.front_offset_dim6 != b_.front_offset_dim6) return false;
  4649. if (a_.back_offset_dim0 != b_.back_offset_dim0) return false;
  4650. if (a_.back_offset_dim1 != b_.back_offset_dim1) return false;
  4651. if (a_.back_offset_dim2 != b_.back_offset_dim2) return false;
  4652. if (a_.back_offset_dim3 != b_.back_offset_dim3) return false;
  4653. if (a_.back_offset_dim4 != b_.back_offset_dim4) return false;
  4654. if (a_.back_offset_dim5 != b_.back_offset_dim5) return false;
  4655. if (a_.back_offset_dim6 != b_.back_offset_dim6) return false;
  4656. if (a_.padding_val != b_.padding_val) return false;
  4657. if (a_.padding_mode != b_.padding_mode) return false;
  4658. return true;
  4659. }
  4660. std::vector<std::pair<const char*, std::string>> Padding_props_impl(const OpDef& def_) {
  4661. auto&& op_ = def_.cast_final_safe<Padding>();
  4662. static_cast<void>(op_);
  4663. std::vector<std::pair<const char*, std::string>> props_;
  4664. props_.emplace_back("front_offset_dim0", std::to_string(op_.front_offset_dim0));
  4665. props_.emplace_back("front_offset_dim1", std::to_string(op_.front_offset_dim1));
  4666. props_.emplace_back("front_offset_dim2", std::to_string(op_.front_offset_dim2));
  4667. props_.emplace_back("front_offset_dim3", std::to_string(op_.front_offset_dim3));
  4668. props_.emplace_back("front_offset_dim4", std::to_string(op_.front_offset_dim4));
  4669. props_.emplace_back("front_offset_dim5", std::to_string(op_.front_offset_dim5));
  4670. props_.emplace_back("front_offset_dim6", std::to_string(op_.front_offset_dim6));
  4671. props_.emplace_back("back_offset_dim0", std::to_string(op_.back_offset_dim0));
  4672. props_.emplace_back("back_offset_dim1", std::to_string(op_.back_offset_dim1));
  4673. props_.emplace_back("back_offset_dim2", std::to_string(op_.back_offset_dim2));
  4674. props_.emplace_back("back_offset_dim3", std::to_string(op_.back_offset_dim3));
  4675. props_.emplace_back("back_offset_dim4", std::to_string(op_.back_offset_dim4));
  4676. props_.emplace_back("back_offset_dim5", std::to_string(op_.back_offset_dim5));
  4677. props_.emplace_back("back_offset_dim6", std::to_string(op_.back_offset_dim6));
  4678. props_.emplace_back("padding_val", std::to_string(op_.padding_val));
  4679. switch (op_.padding_mode){
  4680. case Padding::PaddingMode::REPLICATE:
  4681. props_.emplace_back("padding_mode", "REPLICATE");
  4682. break;
  4683. case Padding::PaddingMode::REFLECT:
  4684. props_.emplace_back("padding_mode", "REFLECT");
  4685. break;
  4686. case Padding::PaddingMode::CONSTANT:
  4687. props_.emplace_back("padding_mode", "CONSTANT");
  4688. break;
  4689. default:
  4690. props_.emplace_back("padding_mode", "INVALID");
  4691. break;
  4692. }
  4693. return props_;
  4694. }
  4695. std::string Padding_make_name_impl(const OpDef& def_) {
  4696. auto&& op_ = def_.cast_final_safe<Padding>();
  4697. static_cast<void>(op_);
  4698. return "Padding";
  4699. }
  4700. } // anonymous namespace
  4701. OP_TRAIT_REG(Padding, Padding)
  4702. .hash(Padding_hash_impl)
  4703. .is_same_st(Padding_is_same_st_impl)
  4704. .props(Padding_props_impl)
  4705. .make_name(Padding_make_name_impl);
  4706. MGB_DYN_TYPE_OBJ_FINAL_IMPL(ParamPackConcat);
  4707. namespace {
  4708. size_t ParamPackConcat_hash_impl(const OpDef& def_) {
  4709. auto&& op_ = def_.cast_final_safe<ParamPackConcat>();
  4710. static_cast<void>(op_);
  4711. size_t val = mgb::hash(op_.dyn_typeinfo());
  4712. val = mgb::hash_pair_combine(val, mgb::hash(op_.offsets));
  4713. return val;
  4714. }
  4715. bool ParamPackConcat_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4716. auto &&a_ = lhs_.cast_final_safe<ParamPackConcat>(),
  4717. &&b_ = rhs_.cast_final_safe<ParamPackConcat>();
  4718. static_cast<void>(a_);
  4719. static_cast<void>(b_);
  4720. if (a_.offsets != b_.offsets) return false;
  4721. return true;
  4722. }
  4723. std::vector<std::pair<const char*, std::string>> ParamPackConcat_props_impl(const OpDef& def_) {
  4724. auto&& op_ = def_.cast_final_safe<ParamPackConcat>();
  4725. static_cast<void>(op_);
  4726. std::vector<std::pair<const char*, std::string>> props_;
  4727. props_.emplace_back("offsets", "{std::vector}");
  4728. return props_;
  4729. }
  4730. std::string ParamPackConcat_make_name_impl(const OpDef& def_) {
  4731. auto&& op_ = def_.cast_final_safe<ParamPackConcat>();
  4732. static_cast<void>(op_);
  4733. return "ParamPackConcat";
  4734. }
  4735. } // anonymous namespace
  4736. OP_TRAIT_REG(ParamPackConcat, ParamPackConcat)
  4737. .hash(ParamPackConcat_hash_impl)
  4738. .is_same_st(ParamPackConcat_is_same_st_impl)
  4739. .props(ParamPackConcat_props_impl)
  4740. .make_name(ParamPackConcat_make_name_impl);
  4741. MGB_DYN_TYPE_OBJ_FINAL_IMPL(ParamPackSplit);
  4742. namespace {
  4743. size_t ParamPackSplit_hash_impl(const OpDef& def_) {
  4744. auto&& op_ = def_.cast_final_safe<ParamPackSplit>();
  4745. static_cast<void>(op_);
  4746. size_t val = mgb::hash(op_.dyn_typeinfo());
  4747. val = mgb::hash_pair_combine(val, mgb::hash(op_.offsets));
  4748. val = mgb::hash_pair_combine(val, mgb::hash(op_.shapes));
  4749. return val;
  4750. }
  4751. bool ParamPackSplit_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4752. auto &&a_ = lhs_.cast_final_safe<ParamPackSplit>(),
  4753. &&b_ = rhs_.cast_final_safe<ParamPackSplit>();
  4754. static_cast<void>(a_);
  4755. static_cast<void>(b_);
  4756. if (a_.offsets != b_.offsets) return false;
  4757. if (a_.shapes != b_.shapes) return false;
  4758. return true;
  4759. }
  4760. std::vector<std::pair<const char*, std::string>> ParamPackSplit_props_impl(const OpDef& def_) {
  4761. auto&& op_ = def_.cast_final_safe<ParamPackSplit>();
  4762. static_cast<void>(op_);
  4763. std::vector<std::pair<const char*, std::string>> props_;
  4764. props_.emplace_back("offsets", "{std::vector}");
  4765. props_.emplace_back("shapes", "{std::vector}");
  4766. return props_;
  4767. }
  4768. std::string ParamPackSplit_make_name_impl(const OpDef& def_) {
  4769. auto&& op_ = def_.cast_final_safe<ParamPackSplit>();
  4770. static_cast<void>(op_);
  4771. return "ParamPackSplit";
  4772. }
  4773. } // anonymous namespace
  4774. OP_TRAIT_REG(ParamPackSplit, ParamPackSplit)
  4775. .hash(ParamPackSplit_hash_impl)
  4776. .is_same_st(ParamPackSplit_is_same_st_impl)
  4777. .props(ParamPackSplit_props_impl)
  4778. .make_name(ParamPackSplit_make_name_impl);
  4779. MGB_DYN_TYPE_OBJ_FINAL_IMPL(PermutationRNG);
  4780. namespace {
  4781. size_t PermutationRNG_hash_impl(const OpDef& def_) {
  4782. auto&& op_ = def_.cast_final_safe<PermutationRNG>();
  4783. static_cast<void>(op_);
  4784. return mgb::hash_pair_combine(
  4785. mgb::hash(op_.dyn_typeinfo()),
  4786. mgb::hash_pair_combine(
  4787. mgb::hash(op_.handle),
  4788. mgb::hash(op_.dtype.enumv())
  4789. )
  4790. );
  4791. }
  4792. bool PermutationRNG_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4793. auto &&a_ = lhs_.cast_final_safe<PermutationRNG>(),
  4794. &&b_ = rhs_.cast_final_safe<PermutationRNG>();
  4795. static_cast<void>(a_);
  4796. static_cast<void>(b_);
  4797. return a_.handle == b_.handle && a_.dtype == b_.dtype;}
  4798. std::vector<std::pair<const char*, std::string>> PermutationRNG_props_impl(const OpDef& def_) {
  4799. auto&& op_ = def_.cast_final_safe<PermutationRNG>();
  4800. static_cast<void>(op_);
  4801. std::vector<std::pair<const char*, std::string>> props_;
  4802. props_.emplace_back("seed", std::to_string(op_.seed));
  4803. props_.emplace_back("dtype", op_.dtype.name());
  4804. props_.emplace_back("handle", std::to_string(op_.handle));
  4805. return props_;
  4806. }
  4807. std::string PermutationRNG_make_name_impl(const OpDef& def_) {
  4808. auto&& op_ = def_.cast_final_safe<PermutationRNG>();
  4809. static_cast<void>(op_);
  4810. return "PermutationRNG";
  4811. }
  4812. } // anonymous namespace
  4813. OP_TRAIT_REG(PermutationRNG, PermutationRNG)
  4814. .hash(PermutationRNG_hash_impl)
  4815. .is_same_st(PermutationRNG_is_same_st_impl)
  4816. .props(PermutationRNG_props_impl)
  4817. .make_name(PermutationRNG_make_name_impl);
  4818. MGB_DYN_TYPE_OBJ_FINAL_IMPL(PixelShuffle);
  4819. namespace {
  4820. size_t PixelShuffle_hash_impl(const OpDef& def_) {
  4821. auto&& op_ = def_.cast_final_safe<PixelShuffle>();
  4822. static_cast<void>(op_);
  4823. size_t val = mgb::hash(op_.dyn_typeinfo());
  4824. val = mgb::hash_pair_combine(val, mgb::hash(op_.factor));
  4825. return val;
  4826. }
  4827. bool PixelShuffle_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4828. auto &&a_ = lhs_.cast_final_safe<PixelShuffle>(),
  4829. &&b_ = rhs_.cast_final_safe<PixelShuffle>();
  4830. static_cast<void>(a_);
  4831. static_cast<void>(b_);
  4832. if (a_.factor != b_.factor) return false;
  4833. return true;
  4834. }
  4835. std::vector<std::pair<const char*, std::string>> PixelShuffle_props_impl(const OpDef& def_) {
  4836. auto&& op_ = def_.cast_final_safe<PixelShuffle>();
  4837. static_cast<void>(op_);
  4838. std::vector<std::pair<const char*, std::string>> props_;
  4839. props_.emplace_back("factor", std::to_string(op_.factor));
  4840. return props_;
  4841. }
  4842. std::string PixelShuffle_make_name_impl(const OpDef& def_) {
  4843. auto&& op_ = def_.cast_final_safe<PixelShuffle>();
  4844. static_cast<void>(op_);
  4845. return "PixelShuffle";
  4846. }
  4847. } // anonymous namespace
  4848. OP_TRAIT_REG(PixelShuffle, PixelShuffle)
  4849. .hash(PixelShuffle_hash_impl)
  4850. .is_same_st(PixelShuffle_is_same_st_impl)
  4851. .props(PixelShuffle_props_impl)
  4852. .make_name(PixelShuffle_make_name_impl);
  4853. MGB_DYN_TYPE_OBJ_FINAL_IMPL(PixelShuffleBackward);
  4854. namespace {
  4855. size_t PixelShuffleBackward_hash_impl(const OpDef& def_) {
  4856. auto&& op_ = def_.cast_final_safe<PixelShuffleBackward>();
  4857. static_cast<void>(op_);
  4858. size_t val = mgb::hash(op_.dyn_typeinfo());
  4859. val = mgb::hash_pair_combine(val, mgb::hash(op_.factor));
  4860. return val;
  4861. }
  4862. bool PixelShuffleBackward_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4863. auto &&a_ = lhs_.cast_final_safe<PixelShuffleBackward>(),
  4864. &&b_ = rhs_.cast_final_safe<PixelShuffleBackward>();
  4865. static_cast<void>(a_);
  4866. static_cast<void>(b_);
  4867. if (a_.factor != b_.factor) return false;
  4868. return true;
  4869. }
  4870. std::vector<std::pair<const char*, std::string>> PixelShuffleBackward_props_impl(const OpDef& def_) {
  4871. auto&& op_ = def_.cast_final_safe<PixelShuffleBackward>();
  4872. static_cast<void>(op_);
  4873. std::vector<std::pair<const char*, std::string>> props_;
  4874. props_.emplace_back("factor", std::to_string(op_.factor));
  4875. return props_;
  4876. }
  4877. std::string PixelShuffleBackward_make_name_impl(const OpDef& def_) {
  4878. auto&& op_ = def_.cast_final_safe<PixelShuffleBackward>();
  4879. static_cast<void>(op_);
  4880. return "PixelShuffleBackward";
  4881. }
  4882. } // anonymous namespace
  4883. OP_TRAIT_REG(PixelShuffleBackward, PixelShuffleBackward)
  4884. .hash(PixelShuffleBackward_hash_impl)
  4885. .is_same_st(PixelShuffleBackward_is_same_st_impl)
  4886. .props(PixelShuffleBackward_props_impl)
  4887. .make_name(PixelShuffleBackward_make_name_impl);
  4888. MGB_DYN_TYPE_OBJ_FINAL_IMPL(PoissonRNG);
  4889. namespace {
  4890. size_t PoissonRNG_hash_impl(const OpDef& def_) {
  4891. auto&& op_ = def_.cast_final_safe<PoissonRNG>();
  4892. static_cast<void>(op_);
  4893. return mgb::hash_pair_combine(
  4894. mgb::hash(op_.dyn_typeinfo()),
  4895. mgb::hash(op_.handle)
  4896. );
  4897. }
  4898. bool PoissonRNG_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4899. auto &&a_ = lhs_.cast_final_safe<PoissonRNG>(),
  4900. &&b_ = rhs_.cast_final_safe<PoissonRNG>();
  4901. static_cast<void>(a_);
  4902. static_cast<void>(b_);
  4903. return a_.handle == b_.handle;}
  4904. std::vector<std::pair<const char*, std::string>> PoissonRNG_props_impl(const OpDef& def_) {
  4905. auto&& op_ = def_.cast_final_safe<PoissonRNG>();
  4906. static_cast<void>(op_);
  4907. std::vector<std::pair<const char*, std::string>> props_;
  4908. props_.emplace_back("seed", std::to_string(op_.seed));
  4909. props_.emplace_back("handle", std::to_string(op_.handle));
  4910. return props_;
  4911. }
  4912. std::string PoissonRNG_make_name_impl(const OpDef& def_) {
  4913. auto&& op_ = def_.cast_final_safe<PoissonRNG>();
  4914. static_cast<void>(op_);
  4915. return "PoissonRNG";
  4916. }
  4917. } // anonymous namespace
  4918. OP_TRAIT_REG(PoissonRNG, PoissonRNG)
  4919. .hash(PoissonRNG_hash_impl)
  4920. .is_same_st(PoissonRNG_is_same_st_impl)
  4921. .props(PoissonRNG_props_impl)
  4922. .make_name(PoissonRNG_make_name_impl);
  4923. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Pooling);
  4924. namespace {
  4925. size_t Pooling_hash_impl(const OpDef& def_) {
  4926. auto&& op_ = def_.cast_final_safe<Pooling>();
  4927. static_cast<void>(op_);
  4928. size_t val = mgb::hash(op_.dyn_typeinfo());
  4929. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode));
  4930. val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_h));
  4931. val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_w));
  4932. val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_h));
  4933. val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_w));
  4934. val = mgb::hash_pair_combine(val, mgb::hash(op_.window_h));
  4935. val = mgb::hash_pair_combine(val, mgb::hash(op_.window_w));
  4936. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format));
  4937. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.strategy));
  4938. val = mgb::hash_pair_combine(val, mgb::hash(op_.workspace_limit));
  4939. return val;
  4940. }
  4941. bool Pooling_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  4942. auto &&a_ = lhs_.cast_final_safe<Pooling>(),
  4943. &&b_ = rhs_.cast_final_safe<Pooling>();
  4944. static_cast<void>(a_);
  4945. static_cast<void>(b_);
  4946. if (a_.mode != b_.mode) return false;
  4947. if (a_.pad_h != b_.pad_h) return false;
  4948. if (a_.pad_w != b_.pad_w) return false;
  4949. if (a_.stride_h != b_.stride_h) return false;
  4950. if (a_.stride_w != b_.stride_w) return false;
  4951. if (a_.window_h != b_.window_h) return false;
  4952. if (a_.window_w != b_.window_w) return false;
  4953. if (a_.format != b_.format) return false;
  4954. if (a_.strategy != b_.strategy) return false;
  4955. if (a_.workspace_limit != b_.workspace_limit) return false;
  4956. return true;
  4957. }
  4958. std::vector<std::pair<const char*, std::string>> Pooling_props_impl(const OpDef& def_) {
  4959. auto&& op_ = def_.cast_final_safe<Pooling>();
  4960. static_cast<void>(op_);
  4961. std::vector<std::pair<const char*, std::string>> props_;
  4962. switch (op_.mode){
  4963. case Pooling::Mode::MAX:
  4964. props_.emplace_back("mode", "MAX");
  4965. break;
  4966. case Pooling::Mode::AVERAGE:
  4967. props_.emplace_back("mode", "AVERAGE");
  4968. break;
  4969. case Pooling::Mode::AVERAGE_COUNT_EXCLUDE_PADDING:
  4970. props_.emplace_back("mode", "AVERAGE_COUNT_EXCLUDE_PADDING");
  4971. break;
  4972. default:
  4973. props_.emplace_back("mode", "INVALID");
  4974. break;
  4975. }
  4976. props_.emplace_back("pad_h", std::to_string(op_.pad_h));
  4977. props_.emplace_back("pad_w", std::to_string(op_.pad_w));
  4978. props_.emplace_back("stride_h", std::to_string(op_.stride_h));
  4979. props_.emplace_back("stride_w", std::to_string(op_.stride_w));
  4980. props_.emplace_back("window_h", std::to_string(op_.window_h));
  4981. props_.emplace_back("window_w", std::to_string(op_.window_w));
  4982. switch (op_.format){
  4983. case Pooling::Format::NCHW:
  4984. props_.emplace_back("format", "NCHW");
  4985. break;
  4986. case Pooling::Format::NHWC:
  4987. props_.emplace_back("format", "NHWC");
  4988. break;
  4989. case Pooling::Format::NHWCD4:
  4990. props_.emplace_back("format", "NHWCD4");
  4991. break;
  4992. case Pooling::Format::NCHW4:
  4993. props_.emplace_back("format", "NCHW4");
  4994. break;
  4995. case Pooling::Format::NCHW8:
  4996. props_.emplace_back("format", "NCHW8");
  4997. break;
  4998. case Pooling::Format::NCHW32:
  4999. props_.emplace_back("format", "NCHW32");
  5000. break;
  5001. case Pooling::Format::NCHW88:
  5002. props_.emplace_back("format", "NCHW88");
  5003. break;
  5004. case Pooling::Format::NCHW44:
  5005. props_.emplace_back("format", "NCHW44");
  5006. break;
  5007. case Pooling::Format::NCHW44_DOT:
  5008. props_.emplace_back("format", "NCHW44_DOT");
  5009. break;
  5010. case Pooling::Format::NCHW4_NCHW32:
  5011. props_.emplace_back("format", "NCHW4_NCHW32");
  5012. break;
  5013. case Pooling::Format::NCHW32_NCHW4:
  5014. props_.emplace_back("format", "NCHW32_NCHW4");
  5015. break;
  5016. case Pooling::Format::NCHW4_NCHW:
  5017. props_.emplace_back("format", "NCHW4_NCHW");
  5018. break;
  5019. case Pooling::Format::NHWC_NCHW:
  5020. props_.emplace_back("format", "NHWC_NCHW");
  5021. break;
  5022. case Pooling::Format::NHWC_NCHW4_IC_SMALL:
  5023. props_.emplace_back("format", "NHWC_NCHW4_IC_SMALL");
  5024. break;
  5025. case Pooling::Format::NCHW_NCHW4_IC_SMALL:
  5026. props_.emplace_back("format", "NCHW_NCHW4_IC_SMALL");
  5027. break;
  5028. case Pooling::Format::CHWN4:
  5029. props_.emplace_back("format", "CHWN4");
  5030. break;
  5031. case Pooling::Format::NCHW64:
  5032. props_.emplace_back("format", "NCHW64");
  5033. break;
  5034. case Pooling::Format::NCHW4_NHWC:
  5035. props_.emplace_back("format", "NCHW4_NHWC");
  5036. break;
  5037. default:
  5038. props_.emplace_back("format", "INVALID");
  5039. break;
  5040. }
  5041. switch (op_.strategy){
  5042. case Pooling::Strategy::HEURISTIC:
  5043. props_.emplace_back("strategy", "HEURISTIC");
  5044. break;
  5045. case Pooling::Strategy::PROFILE:
  5046. props_.emplace_back("strategy", "PROFILE");
  5047. break;
  5048. case Pooling::Strategy::REPRODUCIBLE:
  5049. props_.emplace_back("strategy", "REPRODUCIBLE");
  5050. break;
  5051. case Pooling::Strategy::OPTIMIZED:
  5052. props_.emplace_back("strategy", "OPTIMIZED");
  5053. break;
  5054. default:
  5055. props_.emplace_back("strategy", "INVALID");
  5056. break;
  5057. }
  5058. props_.emplace_back("workspace_limit", std::to_string(op_.workspace_limit));
  5059. return props_;
  5060. }
  5061. std::string Pooling_make_name_impl(const OpDef& def_) {
  5062. auto&& op_ = def_.cast_final_safe<Pooling>();
  5063. static_cast<void>(op_);
  5064. return "Pooling";
  5065. }
  5066. } // anonymous namespace
  5067. OP_TRAIT_REG(Pooling, Pooling)
  5068. .hash(Pooling_hash_impl)
  5069. .is_same_st(Pooling_is_same_st_impl)
  5070. .props(Pooling_props_impl)
  5071. .make_name(Pooling_make_name_impl);
  5072. MGB_DYN_TYPE_OBJ_FINAL_IMPL(RNN);
  5073. namespace {
  5074. size_t RNN_hash_impl(const OpDef& def_) {
  5075. auto&& op_ = def_.cast_final_safe<RNN>();
  5076. static_cast<void>(op_);
  5077. size_t val = mgb::hash(op_.dyn_typeinfo());
  5078. val = mgb::hash_pair_combine(val, mgb::hash(op_.num_layers));
  5079. val = mgb::hash_pair_combine(val, mgb::hash(op_.bidirectional));
  5080. val = mgb::hash_pair_combine(val, mgb::hash(op_.bias));
  5081. val = mgb::hash_pair_combine(val, mgb::hash(op_.hidden_size));
  5082. val = mgb::hash_pair_combine(val, mgb::hash(op_.dropout));
  5083. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.nonlineMode));
  5084. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.fwd_mode));
  5085. return val;
  5086. }
  5087. bool RNN_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  5088. auto &&a_ = lhs_.cast_final_safe<RNN>(),
  5089. &&b_ = rhs_.cast_final_safe<RNN>();
  5090. static_cast<void>(a_);
  5091. static_cast<void>(b_);
  5092. if (a_.num_layers != b_.num_layers) return false;
  5093. if (a_.bidirectional != b_.bidirectional) return false;
  5094. if (a_.bias != b_.bias) return false;
  5095. if (a_.hidden_size != b_.hidden_size) return false;
  5096. if (a_.dropout != b_.dropout) return false;
  5097. if (a_.nonlineMode != b_.nonlineMode) return false;
  5098. if (a_.fwd_mode != b_.fwd_mode) return false;
  5099. return true;
  5100. }
  5101. std::vector<std::pair<const char*, std::string>> RNN_props_impl(const OpDef& def_) {
  5102. auto&& op_ = def_.cast_final_safe<RNN>();
  5103. static_cast<void>(op_);
  5104. std::vector<std::pair<const char*, std::string>> props_;
  5105. props_.emplace_back("num_layers", std::to_string(op_.num_layers));
  5106. props_.emplace_back("bidirectional", std::to_string(op_.bidirectional));
  5107. props_.emplace_back("bias", std::to_string(op_.bias));
  5108. props_.emplace_back("hidden_size", std::to_string(op_.hidden_size));
  5109. props_.emplace_back("dropout", std::to_string(op_.dropout));
  5110. switch (op_.nonlineMode){
  5111. case RNN::NonlineMode::IDENTITY:
  5112. props_.emplace_back("nonlineMode", "IDENTITY");
  5113. break;
  5114. case RNN::NonlineMode::RELU:
  5115. props_.emplace_back("nonlineMode", "RELU");
  5116. break;
  5117. case RNN::NonlineMode::TANH:
  5118. props_.emplace_back("nonlineMode", "TANH");
  5119. break;
  5120. default:
  5121. props_.emplace_back("nonlineMode", "INVALID");
  5122. break;
  5123. }
  5124. switch (op_.fwd_mode){
  5125. case RNN::FwdMode::TRAINING:
  5126. props_.emplace_back("fwd_mode", "TRAINING");
  5127. break;
  5128. case RNN::FwdMode::INFERENCE:
  5129. props_.emplace_back("fwd_mode", "INFERENCE");
  5130. break;
  5131. default:
  5132. props_.emplace_back("fwd_mode", "INVALID");
  5133. break;
  5134. }
  5135. return props_;
  5136. }
  5137. std::string RNN_make_name_impl(const OpDef& def_) {
  5138. auto&& op_ = def_.cast_final_safe<RNN>();
  5139. static_cast<void>(op_);
  5140. return "RNN";
  5141. }
  5142. } // anonymous namespace
  5143. OP_TRAIT_REG(RNN, RNN)
  5144. .hash(RNN_hash_impl)
  5145. .is_same_st(RNN_is_same_st_impl)
  5146. .props(RNN_props_impl)
  5147. .make_name(RNN_make_name_impl);
  5148. MGB_DYN_TYPE_OBJ_FINAL_IMPL(RNNCell);
  5149. namespace {
  5150. size_t RNNCell_hash_impl(const OpDef& def_) {
  5151. auto&& op_ = def_.cast_final_safe<RNNCell>();
  5152. static_cast<void>(op_);
  5153. size_t val = mgb::hash(op_.dyn_typeinfo());
  5154. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.nonlineMode));
  5155. return val;
  5156. }
  5157. bool RNNCell_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  5158. auto &&a_ = lhs_.cast_final_safe<RNNCell>(),
  5159. &&b_ = rhs_.cast_final_safe<RNNCell>();
  5160. static_cast<void>(a_);
  5161. static_cast<void>(b_);
  5162. if (a_.nonlineMode != b_.nonlineMode) return false;
  5163. return true;
  5164. }
  5165. std::vector<std::pair<const char*, std::string>> RNNCell_props_impl(const OpDef& def_) {
  5166. auto&& op_ = def_.cast_final_safe<RNNCell>();
  5167. static_cast<void>(op_);
  5168. std::vector<std::pair<const char*, std::string>> props_;
  5169. switch (op_.nonlineMode){
  5170. case RNNCell::NonlineMode::IDENTITY:
  5171. props_.emplace_back("nonlineMode", "IDENTITY");
  5172. break;
  5173. case RNNCell::NonlineMode::RELU:
  5174. props_.emplace_back("nonlineMode", "RELU");
  5175. break;
  5176. case RNNCell::NonlineMode::TANH:
  5177. props_.emplace_back("nonlineMode", "TANH");
  5178. break;
  5179. default:
  5180. props_.emplace_back("nonlineMode", "INVALID");
  5181. break;
  5182. }
  5183. return props_;
  5184. }
  5185. std::string RNNCell_make_name_impl(const OpDef& def_) {
  5186. auto&& op_ = def_.cast_final_safe<RNNCell>();
  5187. static_cast<void>(op_);
  5188. return "RNNCell";
  5189. }
  5190. } // anonymous namespace
  5191. OP_TRAIT_REG(RNNCell, RNNCell)
  5192. .hash(RNNCell_hash_impl)
  5193. .is_same_st(RNNCell_is_same_st_impl)
  5194. .props(RNNCell_props_impl)
  5195. .make_name(RNNCell_make_name_impl);
  5196. MGB_DYN_TYPE_OBJ_FINAL_IMPL(ROIAlign);
  5197. namespace {
  5198. size_t ROIAlign_hash_impl(const OpDef& def_) {
  5199. auto&& op_ = def_.cast_final_safe<ROIAlign>();
  5200. static_cast<void>(op_);
  5201. size_t val = mgb::hash(op_.dyn_typeinfo());
  5202. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode));
  5203. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format));
  5204. val = mgb::hash_pair_combine(val, mgb::hash(op_.spatial_scale));
  5205. val = mgb::hash_pair_combine(val, mgb::hash(op_.offset));
  5206. val = mgb::hash_pair_combine(val, mgb::hash(op_.pooled_height));
  5207. val = mgb::hash_pair_combine(val, mgb::hash(op_.pooled_width));
  5208. val = mgb::hash_pair_combine(val, mgb::hash(op_.sample_height));
  5209. val = mgb::hash_pair_combine(val, mgb::hash(op_.sample_width));
  5210. return val;
  5211. }
  5212. bool ROIAlign_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  5213. auto &&a_ = lhs_.cast_final_safe<ROIAlign>(),
  5214. &&b_ = rhs_.cast_final_safe<ROIAlign>();
  5215. static_cast<void>(a_);
  5216. static_cast<void>(b_);
  5217. if (a_.mode != b_.mode) return false;
  5218. if (a_.format != b_.format) return false;
  5219. if (a_.spatial_scale != b_.spatial_scale) return false;
  5220. if (a_.offset != b_.offset) return false;
  5221. if (a_.pooled_height != b_.pooled_height) return false;
  5222. if (a_.pooled_width != b_.pooled_width) return false;
  5223. if (a_.sample_height != b_.sample_height) return false;
  5224. if (a_.sample_width != b_.sample_width) return false;
  5225. return true;
  5226. }
  5227. std::vector<std::pair<const char*, std::string>> ROIAlign_props_impl(const OpDef& def_) {
  5228. auto&& op_ = def_.cast_final_safe<ROIAlign>();
  5229. static_cast<void>(op_);
  5230. std::vector<std::pair<const char*, std::string>> props_;
  5231. switch (op_.mode){
  5232. case ROIAlign::Mode::MAX:
  5233. props_.emplace_back("mode", "MAX");
  5234. break;
  5235. case ROIAlign::Mode::AVERAGE:
  5236. props_.emplace_back("mode", "AVERAGE");
  5237. break;
  5238. default:
  5239. props_.emplace_back("mode", "INVALID");
  5240. break;
  5241. }
  5242. switch (op_.format){
  5243. case ROIAlign::Format::NCHW:
  5244. props_.emplace_back("format", "NCHW");
  5245. break;
  5246. case ROIAlign::Format::NHWC:
  5247. props_.emplace_back("format", "NHWC");
  5248. break;
  5249. case ROIAlign::Format::NHWCD4:
  5250. props_.emplace_back("format", "NHWCD4");
  5251. break;
  5252. case ROIAlign::Format::NCHW4:
  5253. props_.emplace_back("format", "NCHW4");
  5254. break;
  5255. case ROIAlign::Format::NCHW8:
  5256. props_.emplace_back("format", "NCHW8");
  5257. break;
  5258. case ROIAlign::Format::NCHW32:
  5259. props_.emplace_back("format", "NCHW32");
  5260. break;
  5261. case ROIAlign::Format::NCHW88:
  5262. props_.emplace_back("format", "NCHW88");
  5263. break;
  5264. case ROIAlign::Format::NCHW44:
  5265. props_.emplace_back("format", "NCHW44");
  5266. break;
  5267. case ROIAlign::Format::NCHW44_DOT:
  5268. props_.emplace_back("format", "NCHW44_DOT");
  5269. break;
  5270. case ROIAlign::Format::NCHW4_NCHW32:
  5271. props_.emplace_back("format", "NCHW4_NCHW32");
  5272. break;
  5273. case ROIAlign::Format::NCHW32_NCHW4:
  5274. props_.emplace_back("format", "NCHW32_NCHW4");
  5275. break;
  5276. case ROIAlign::Format::NCHW4_NCHW:
  5277. props_.emplace_back("format", "NCHW4_NCHW");
  5278. break;
  5279. case ROIAlign::Format::NHWC_NCHW:
  5280. props_.emplace_back("format", "NHWC_NCHW");
  5281. break;
  5282. case ROIAlign::Format::NHWC_NCHW4_IC_SMALL:
  5283. props_.emplace_back("format", "NHWC_NCHW4_IC_SMALL");
  5284. break;
  5285. case ROIAlign::Format::NCHW_NCHW4_IC_SMALL:
  5286. props_.emplace_back("format", "NCHW_NCHW4_IC_SMALL");
  5287. break;
  5288. case ROIAlign::Format::CHWN4:
  5289. props_.emplace_back("format", "CHWN4");
  5290. break;
  5291. case ROIAlign::Format::NCHW64:
  5292. props_.emplace_back("format", "NCHW64");
  5293. break;
  5294. case ROIAlign::Format::NCHW4_NHWC:
  5295. props_.emplace_back("format", "NCHW4_NHWC");
  5296. break;
  5297. default:
  5298. props_.emplace_back("format", "INVALID");
  5299. break;
  5300. }
  5301. props_.emplace_back("spatial_scale", std::to_string(op_.spatial_scale));
  5302. props_.emplace_back("offset", std::to_string(op_.offset));
  5303. props_.emplace_back("pooled_height", std::to_string(op_.pooled_height));
  5304. props_.emplace_back("pooled_width", std::to_string(op_.pooled_width));
  5305. props_.emplace_back("sample_height", std::to_string(op_.sample_height));
  5306. props_.emplace_back("sample_width", std::to_string(op_.sample_width));
  5307. return props_;
  5308. }
  5309. std::string ROIAlign_make_name_impl(const OpDef& def_) {
  5310. auto&& op_ = def_.cast_final_safe<ROIAlign>();
  5311. static_cast<void>(op_);
  5312. return "ROIAlign";
  5313. }
  5314. } // anonymous namespace
  5315. OP_TRAIT_REG(ROIAlign, ROIAlign)
  5316. .hash(ROIAlign_hash_impl)
  5317. .is_same_st(ROIAlign_is_same_st_impl)
  5318. .props(ROIAlign_props_impl)
  5319. .make_name(ROIAlign_make_name_impl);
  5320. MGB_DYN_TYPE_OBJ_FINAL_IMPL(ROIPooling);
  5321. namespace {
  5322. size_t ROIPooling_hash_impl(const OpDef& def_) {
  5323. auto&& op_ = def_.cast_final_safe<ROIPooling>();
  5324. static_cast<void>(op_);
  5325. size_t val = mgb::hash(op_.dyn_typeinfo());
  5326. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode));
  5327. val = mgb::hash_pair_combine(val, mgb::hash(op_.scale));
  5328. return val;
  5329. }
  5330. bool ROIPooling_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  5331. auto &&a_ = lhs_.cast_final_safe<ROIPooling>(),
  5332. &&b_ = rhs_.cast_final_safe<ROIPooling>();
  5333. static_cast<void>(a_);
  5334. static_cast<void>(b_);
  5335. if (a_.mode != b_.mode) return false;
  5336. if (a_.scale != b_.scale) return false;
  5337. return true;
  5338. }
  5339. std::vector<std::pair<const char*, std::string>> ROIPooling_props_impl(const OpDef& def_) {
  5340. auto&& op_ = def_.cast_final_safe<ROIPooling>();
  5341. static_cast<void>(op_);
  5342. std::vector<std::pair<const char*, std::string>> props_;
  5343. switch (op_.mode){
  5344. case ROIPooling::Mode::MAX:
  5345. props_.emplace_back("mode", "MAX");
  5346. break;
  5347. case ROIPooling::Mode::AVERAGE:
  5348. props_.emplace_back("mode", "AVERAGE");
  5349. break;
  5350. default:
  5351. props_.emplace_back("mode", "INVALID");
  5352. break;
  5353. }
  5354. props_.emplace_back("scale", std::to_string(op_.scale));
  5355. return props_;
  5356. }
  5357. std::string ROIPooling_make_name_impl(const OpDef& def_) {
  5358. auto&& op_ = def_.cast_final_safe<ROIPooling>();
  5359. static_cast<void>(op_);
  5360. return "ROIPooling";
  5361. }
  5362. } // anonymous namespace
  5363. OP_TRAIT_REG(ROIPooling, ROIPooling)
  5364. .hash(ROIPooling_hash_impl)
  5365. .is_same_st(ROIPooling_is_same_st_impl)
  5366. .props(ROIPooling_props_impl)
  5367. .make_name(ROIPooling_make_name_impl);
  5368. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Reduce);
  5369. namespace {
  5370. size_t Reduce_hash_impl(const OpDef& def_) {
  5371. auto&& op_ = def_.cast_final_safe<Reduce>();
  5372. static_cast<void>(op_);
  5373. size_t val = mgb::hash(op_.dyn_typeinfo());
  5374. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode));
  5375. val = mgb::hash_pair_combine(val, mgb::hash(op_.axis));
  5376. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.data_type));
  5377. val = mgb::hash_pair_combine(val, mgb::hash(op_.keepdim));
  5378. return val;
  5379. }
  5380. bool Reduce_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  5381. auto &&a_ = lhs_.cast_final_safe<Reduce>(),
  5382. &&b_ = rhs_.cast_final_safe<Reduce>();
  5383. static_cast<void>(a_);
  5384. static_cast<void>(b_);
  5385. if (a_.mode != b_.mode) return false;
  5386. if (a_.axis != b_.axis) return false;
  5387. if (a_.data_type != b_.data_type) return false;
  5388. if (a_.keepdim != b_.keepdim) return false;
  5389. return true;
  5390. }
  5391. std::vector<std::pair<const char*, std::string>> Reduce_props_impl(const OpDef& def_) {
  5392. auto&& op_ = def_.cast_final_safe<Reduce>();
  5393. static_cast<void>(op_);
  5394. std::vector<std::pair<const char*, std::string>> props_;
  5395. switch (op_.mode){
  5396. case Reduce::Mode::SUM:
  5397. props_.emplace_back("mode", "SUM");
  5398. break;
  5399. case Reduce::Mode::SUM_SQR:
  5400. props_.emplace_back("mode", "SUM_SQR");
  5401. break;
  5402. case Reduce::Mode::PRODUCT:
  5403. props_.emplace_back("mode", "PRODUCT");
  5404. break;
  5405. case Reduce::Mode::MIN:
  5406. props_.emplace_back("mode", "MIN");
  5407. break;
  5408. case Reduce::Mode::MAX:
  5409. props_.emplace_back("mode", "MAX");
  5410. break;
  5411. case Reduce::Mode::MEAN:
  5412. props_.emplace_back("mode", "MEAN");
  5413. break;
  5414. default:
  5415. props_.emplace_back("mode", "INVALID");
  5416. break;
  5417. }
  5418. props_.emplace_back("axis", std::to_string(op_.axis));
  5419. switch (op_.data_type){
  5420. case Reduce::DataType::DEFAULT:
  5421. props_.emplace_back("data_type", "DEFAULT");
  5422. break;
  5423. case Reduce::DataType::FLOAT_IO16xC32:
  5424. props_.emplace_back("data_type", "FLOAT_IO16xC32");
  5425. break;
  5426. case Reduce::DataType::FLOAT_O32xC32:
  5427. props_.emplace_back("data_type", "FLOAT_O32xC32");
  5428. break;
  5429. case Reduce::DataType::FLOAT_O16xC32:
  5430. props_.emplace_back("data_type", "FLOAT_O16xC32");
  5431. break;
  5432. case Reduce::DataType::QUINT_I8xO32:
  5433. props_.emplace_back("data_type", "QUINT_I8xO32");
  5434. break;
  5435. case Reduce::DataType::QINT_I8xO32:
  5436. props_.emplace_back("data_type", "QINT_I8xO32");
  5437. break;
  5438. default:
  5439. props_.emplace_back("data_type", "INVALID");
  5440. break;
  5441. }
  5442. props_.emplace_back("keepdim", std::to_string(op_.keepdim));
  5443. return props_;
  5444. }
  5445. std::string Reduce_make_name_impl(const OpDef& def_) {
  5446. auto&& op_ = def_.cast_final_safe<Reduce>();
  5447. static_cast<void>(op_);
  5448. return "Reduce";
  5449. }
  5450. } // anonymous namespace
  5451. OP_TRAIT_REG(Reduce, Reduce)
  5452. .hash(Reduce_hash_impl)
  5453. .is_same_st(Reduce_is_same_st_impl)
  5454. .props(Reduce_props_impl)
  5455. .make_name(Reduce_make_name_impl);
  5456. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Remap);
  5457. namespace {
  5458. size_t Remap_hash_impl(const OpDef& def_) {
  5459. auto&& op_ = def_.cast_final_safe<Remap>();
  5460. static_cast<void>(op_);
  5461. size_t val = mgb::hash(op_.dyn_typeinfo());
  5462. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.imode));
  5463. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.border_type));
  5464. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format));
  5465. val = mgb::hash_pair_combine(val, mgb::hash(op_.scalar));
  5466. return val;
  5467. }
  5468. bool Remap_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  5469. auto &&a_ = lhs_.cast_final_safe<Remap>(),
  5470. &&b_ = rhs_.cast_final_safe<Remap>();
  5471. static_cast<void>(a_);
  5472. static_cast<void>(b_);
  5473. if (a_.imode != b_.imode) return false;
  5474. if (a_.border_type != b_.border_type) return false;
  5475. if (a_.format != b_.format) return false;
  5476. if (a_.scalar != b_.scalar) return false;
  5477. return true;
  5478. }
  5479. std::vector<std::pair<const char*, std::string>> Remap_props_impl(const OpDef& def_) {
  5480. auto&& op_ = def_.cast_final_safe<Remap>();
  5481. static_cast<void>(op_);
  5482. std::vector<std::pair<const char*, std::string>> props_;
  5483. switch (op_.imode){
  5484. case Remap::InterpolationMode::NEAREST:
  5485. props_.emplace_back("imode", "NEAREST");
  5486. break;
  5487. case Remap::InterpolationMode::LINEAR:
  5488. props_.emplace_back("imode", "LINEAR");
  5489. break;
  5490. case Remap::InterpolationMode::AREA:
  5491. props_.emplace_back("imode", "AREA");
  5492. break;
  5493. case Remap::InterpolationMode::CUBIC:
  5494. props_.emplace_back("imode", "CUBIC");
  5495. break;
  5496. case Remap::InterpolationMode::LANCZOS4:
  5497. props_.emplace_back("imode", "LANCZOS4");
  5498. break;
  5499. default:
  5500. props_.emplace_back("imode", "INVALID");
  5501. break;
  5502. }
  5503. switch (op_.border_type){
  5504. case Remap::BorderMode::REPLICATE:
  5505. props_.emplace_back("border_type", "REPLICATE");
  5506. break;
  5507. case Remap::BorderMode::REFLECT:
  5508. props_.emplace_back("border_type", "REFLECT");
  5509. break;
  5510. case Remap::BorderMode::REFLECT_101:
  5511. props_.emplace_back("border_type", "REFLECT_101");
  5512. break;
  5513. case Remap::BorderMode::WRAP:
  5514. props_.emplace_back("border_type", "WRAP");
  5515. break;
  5516. case Remap::BorderMode::CONSTANT:
  5517. props_.emplace_back("border_type", "CONSTANT");
  5518. break;
  5519. case Remap::BorderMode::TRANSPARENT:
  5520. props_.emplace_back("border_type", "TRANSPARENT");
  5521. break;
  5522. case Remap::BorderMode::ISOLATED:
  5523. props_.emplace_back("border_type", "ISOLATED");
  5524. break;
  5525. default:
  5526. props_.emplace_back("border_type", "INVALID");
  5527. break;
  5528. }
  5529. switch (op_.format){
  5530. case Remap::Format::NCHW:
  5531. props_.emplace_back("format", "NCHW");
  5532. break;
  5533. case Remap::Format::NHWC:
  5534. props_.emplace_back("format", "NHWC");
  5535. break;
  5536. case Remap::Format::NHWCD4:
  5537. props_.emplace_back("format", "NHWCD4");
  5538. break;
  5539. case Remap::Format::NCHW4:
  5540. props_.emplace_back("format", "NCHW4");
  5541. break;
  5542. case Remap::Format::NCHW8:
  5543. props_.emplace_back("format", "NCHW8");
  5544. break;
  5545. case Remap::Format::NCHW32:
  5546. props_.emplace_back("format", "NCHW32");
  5547. break;
  5548. case Remap::Format::NCHW88:
  5549. props_.emplace_back("format", "NCHW88");
  5550. break;
  5551. case Remap::Format::NCHW44:
  5552. props_.emplace_back("format", "NCHW44");
  5553. break;
  5554. case Remap::Format::NCHW44_DOT:
  5555. props_.emplace_back("format", "NCHW44_DOT");
  5556. break;
  5557. case Remap::Format::NCHW4_NCHW32:
  5558. props_.emplace_back("format", "NCHW4_NCHW32");
  5559. break;
  5560. case Remap::Format::NCHW32_NCHW4:
  5561. props_.emplace_back("format", "NCHW32_NCHW4");
  5562. break;
  5563. case Remap::Format::NCHW4_NCHW:
  5564. props_.emplace_back("format", "NCHW4_NCHW");
  5565. break;
  5566. case Remap::Format::NHWC_NCHW:
  5567. props_.emplace_back("format", "NHWC_NCHW");
  5568. break;
  5569. case Remap::Format::NHWC_NCHW4_IC_SMALL:
  5570. props_.emplace_back("format", "NHWC_NCHW4_IC_SMALL");
  5571. break;
  5572. case Remap::Format::NCHW_NCHW4_IC_SMALL:
  5573. props_.emplace_back("format", "NCHW_NCHW4_IC_SMALL");
  5574. break;
  5575. case Remap::Format::CHWN4:
  5576. props_.emplace_back("format", "CHWN4");
  5577. break;
  5578. case Remap::Format::NCHW64:
  5579. props_.emplace_back("format", "NCHW64");
  5580. break;
  5581. case Remap::Format::NCHW4_NHWC:
  5582. props_.emplace_back("format", "NCHW4_NHWC");
  5583. break;
  5584. default:
  5585. props_.emplace_back("format", "INVALID");
  5586. break;
  5587. }
  5588. props_.emplace_back("scalar", std::to_string(op_.scalar));
  5589. return props_;
  5590. }
  5591. std::string Remap_make_name_impl(const OpDef& def_) {
  5592. auto&& op_ = def_.cast_final_safe<Remap>();
  5593. static_cast<void>(op_);
  5594. return "Remap";
  5595. }
  5596. } // anonymous namespace
  5597. OP_TRAIT_REG(Remap, Remap)
  5598. .hash(Remap_hash_impl)
  5599. .is_same_st(Remap_is_same_st_impl)
  5600. .props(Remap_props_impl)
  5601. .make_name(Remap_make_name_impl);
  5602. MGB_DYN_TYPE_OBJ_FINAL_IMPL(RemoteRecv);
  5603. namespace {
  5604. size_t RemoteRecv_hash_impl(const OpDef& def_) {
  5605. auto&& op_ = def_.cast_final_safe<RemoteRecv>();
  5606. static_cast<void>(op_);
  5607. size_t val = mgb::hash(op_.dyn_typeinfo());
  5608. val = mgb::hash_pair_combine(val, mgb::hash(op_.key));
  5609. val = mgb::hash_pair_combine(val, mgb::hash(op_.addr));
  5610. val = mgb::hash_pair_combine(val, mgb::hash(op_.port));
  5611. val = mgb::hash_pair_combine(val, mgb::hash(op_.rank_from));
  5612. val = mgb::hash_pair_combine(val, mgb::hash(op_.cn));
  5613. val = mgb::hash_pair_combine(val, mgb::hash(op_.shape));
  5614. val = mgb::hash_pair_combine(val, mgb::hash(op_.dtype.handle()));
  5615. val = mgb::hash_pair_combine(val, mgb::hash(op_.backend));
  5616. return val;
  5617. }
  5618. bool RemoteRecv_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  5619. auto &&a_ = lhs_.cast_final_safe<RemoteRecv>(),
  5620. &&b_ = rhs_.cast_final_safe<RemoteRecv>();
  5621. static_cast<void>(a_);
  5622. static_cast<void>(b_);
  5623. if (a_.key != b_.key) return false;
  5624. if (a_.addr != b_.addr) return false;
  5625. if (a_.port != b_.port) return false;
  5626. if (a_.rank_from != b_.rank_from) return false;
  5627. if (a_.cn != b_.cn) return false;
  5628. if (a_.shape != b_.shape) return false;
  5629. if (a_.dtype != b_.dtype) return false;
  5630. if (a_.backend != b_.backend) return false;
  5631. return true;
  5632. }
  5633. std::vector<std::pair<const char*, std::string>> RemoteRecv_props_impl(const OpDef& def_) {
  5634. auto&& op_ = def_.cast_final_safe<RemoteRecv>();
  5635. static_cast<void>(op_);
  5636. std::vector<std::pair<const char*, std::string>> props_;
  5637. props_.emplace_back("key", op_.key);
  5638. props_.emplace_back("addr", op_.addr);
  5639. props_.emplace_back("port", std::to_string(op_.port));
  5640. props_.emplace_back("rank_from", std::to_string(op_.rank_from));
  5641. props_.emplace_back("cn", op_.cn.to_string());
  5642. props_.emplace_back("shape", "{std::vector}");
  5643. props_.emplace_back("dtype", op_.dtype.name());
  5644. props_.emplace_back("backend", op_.backend);
  5645. return props_;
  5646. }
  5647. std::string RemoteRecv_make_name_impl(const OpDef& def_) {
  5648. auto&& op_ = def_.cast_final_safe<RemoteRecv>();
  5649. static_cast<void>(op_);
  5650. return "RemoteRecv";
  5651. }
  5652. } // anonymous namespace
  5653. OP_TRAIT_REG(RemoteRecv, RemoteRecv)
  5654. .hash(RemoteRecv_hash_impl)
  5655. .is_same_st(RemoteRecv_is_same_st_impl)
  5656. .props(RemoteRecv_props_impl)
  5657. .make_name(RemoteRecv_make_name_impl);
  5658. MGB_DYN_TYPE_OBJ_FINAL_IMPL(RemoteSend);
  5659. namespace {
  5660. size_t RemoteSend_hash_impl(const OpDef& def_) {
  5661. auto&& op_ = def_.cast_final_safe<RemoteSend>();
  5662. static_cast<void>(op_);
  5663. size_t val = mgb::hash(op_.dyn_typeinfo());
  5664. val = mgb::hash_pair_combine(val, mgb::hash(op_.key));
  5665. val = mgb::hash_pair_combine(val, mgb::hash(op_.addr));
  5666. val = mgb::hash_pair_combine(val, mgb::hash(op_.port));
  5667. val = mgb::hash_pair_combine(val, mgb::hash(op_.rank_to));
  5668. val = mgb::hash_pair_combine(val, mgb::hash(op_.backend));
  5669. return val;
  5670. }
  5671. bool RemoteSend_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  5672. auto &&a_ = lhs_.cast_final_safe<RemoteSend>(),
  5673. &&b_ = rhs_.cast_final_safe<RemoteSend>();
  5674. static_cast<void>(a_);
  5675. static_cast<void>(b_);
  5676. if (a_.key != b_.key) return false;
  5677. if (a_.addr != b_.addr) return false;
  5678. if (a_.port != b_.port) return false;
  5679. if (a_.rank_to != b_.rank_to) return false;
  5680. if (a_.backend != b_.backend) return false;
  5681. return true;
  5682. }
  5683. std::vector<std::pair<const char*, std::string>> RemoteSend_props_impl(const OpDef& def_) {
  5684. auto&& op_ = def_.cast_final_safe<RemoteSend>();
  5685. static_cast<void>(op_);
  5686. std::vector<std::pair<const char*, std::string>> props_;
  5687. props_.emplace_back("key", op_.key);
  5688. props_.emplace_back("addr", op_.addr);
  5689. props_.emplace_back("port", std::to_string(op_.port));
  5690. props_.emplace_back("rank_to", std::to_string(op_.rank_to));
  5691. props_.emplace_back("backend", op_.backend);
  5692. return props_;
  5693. }
  5694. std::string RemoteSend_make_name_impl(const OpDef& def_) {
  5695. auto&& op_ = def_.cast_final_safe<RemoteSend>();
  5696. static_cast<void>(op_);
  5697. return "RemoteSend";
  5698. }
  5699. } // anonymous namespace
  5700. OP_TRAIT_REG(RemoteSend, RemoteSend)
  5701. .hash(RemoteSend_hash_impl)
  5702. .is_same_st(RemoteSend_is_same_st_impl)
  5703. .props(RemoteSend_props_impl)
  5704. .make_name(RemoteSend_make_name_impl);
  5705. MGB_DYN_TYPE_OBJ_FINAL_IMPL(RemoveAxis);
  5706. namespace {
  5707. size_t RemoveAxis_hash_impl(const OpDef& def_) {
  5708. auto&& op_ = def_.cast_final_safe<RemoveAxis>();
  5709. static_cast<void>(op_);
  5710. size_t val = mgb::hash(op_.dyn_typeinfo());
  5711. val = mgb::hash_pair_combine(val, mgb::hash(op_.axis));
  5712. return val;
  5713. }
  5714. bool RemoveAxis_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  5715. auto &&a_ = lhs_.cast_final_safe<RemoveAxis>(),
  5716. &&b_ = rhs_.cast_final_safe<RemoveAxis>();
  5717. static_cast<void>(a_);
  5718. static_cast<void>(b_);
  5719. if (a_.axis != b_.axis) return false;
  5720. return true;
  5721. }
  5722. std::vector<std::pair<const char*, std::string>> RemoveAxis_props_impl(const OpDef& def_) {
  5723. auto&& op_ = def_.cast_final_safe<RemoveAxis>();
  5724. static_cast<void>(op_);
  5725. std::vector<std::pair<const char*, std::string>> props_;
  5726. props_.emplace_back("axis", "{std::vector}");
  5727. return props_;
  5728. }
  5729. std::string RemoveAxis_make_name_impl(const OpDef& def_) {
  5730. auto&& op_ = def_.cast_final_safe<RemoveAxis>();
  5731. static_cast<void>(op_);
  5732. return "RemoveAxis";
  5733. }
  5734. } // anonymous namespace
  5735. OP_TRAIT_REG(RemoveAxis, RemoveAxis)
  5736. .hash(RemoveAxis_hash_impl)
  5737. .is_same_st(RemoveAxis_is_same_st_impl)
  5738. .props(RemoveAxis_props_impl)
  5739. .make_name(RemoveAxis_make_name_impl);
  5740. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Reshape);
  5741. namespace {
  5742. size_t Reshape_hash_impl(const OpDef& def_) {
  5743. auto&& op_ = def_.cast_final_safe<Reshape>();
  5744. static_cast<void>(op_);
  5745. size_t val = mgb::hash(op_.dyn_typeinfo());
  5746. val = mgb::hash_pair_combine(val, mgb::hash(op_.axis));
  5747. val = mgb::hash_pair_combine(val, mgb::hash(op_.shape));
  5748. return val;
  5749. }
  5750. bool Reshape_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  5751. auto &&a_ = lhs_.cast_final_safe<Reshape>(),
  5752. &&b_ = rhs_.cast_final_safe<Reshape>();
  5753. static_cast<void>(a_);
  5754. static_cast<void>(b_);
  5755. if (a_.axis != b_.axis) return false;
  5756. if (a_.shape != b_.shape) return false;
  5757. return true;
  5758. }
  5759. std::vector<std::pair<const char*, std::string>> Reshape_props_impl(const OpDef& def_) {
  5760. auto&& op_ = def_.cast_final_safe<Reshape>();
  5761. static_cast<void>(op_);
  5762. std::vector<std::pair<const char*, std::string>> props_;
  5763. props_.emplace_back("axis", std::to_string(op_.axis));
  5764. props_.emplace_back("shape", "{std::vector}");
  5765. return props_;
  5766. }
  5767. std::string Reshape_make_name_impl(const OpDef& def_) {
  5768. auto&& op_ = def_.cast_final_safe<Reshape>();
  5769. static_cast<void>(op_);
  5770. return "Reshape";
  5771. }
  5772. } // anonymous namespace
  5773. OP_TRAIT_REG(Reshape, Reshape)
  5774. .hash(Reshape_hash_impl)
  5775. .is_same_st(Reshape_is_same_st_impl)
  5776. .props(Reshape_props_impl)
  5777. .make_name(Reshape_make_name_impl);
  5778. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Resize);
  5779. namespace {
  5780. size_t Resize_hash_impl(const OpDef& def_) {
  5781. auto&& op_ = def_.cast_final_safe<Resize>();
  5782. static_cast<void>(op_);
  5783. size_t val = mgb::hash(op_.dyn_typeinfo());
  5784. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.imode));
  5785. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format));
  5786. return val;
  5787. }
  5788. bool Resize_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  5789. auto &&a_ = lhs_.cast_final_safe<Resize>(),
  5790. &&b_ = rhs_.cast_final_safe<Resize>();
  5791. static_cast<void>(a_);
  5792. static_cast<void>(b_);
  5793. if (a_.imode != b_.imode) return false;
  5794. if (a_.format != b_.format) return false;
  5795. return true;
  5796. }
  5797. std::vector<std::pair<const char*, std::string>> Resize_props_impl(const OpDef& def_) {
  5798. auto&& op_ = def_.cast_final_safe<Resize>();
  5799. static_cast<void>(op_);
  5800. std::vector<std::pair<const char*, std::string>> props_;
  5801. switch (op_.imode){
  5802. case Resize::InterpolationMode::NEAREST:
  5803. props_.emplace_back("imode", "NEAREST");
  5804. break;
  5805. case Resize::InterpolationMode::LINEAR:
  5806. props_.emplace_back("imode", "LINEAR");
  5807. break;
  5808. case Resize::InterpolationMode::AREA:
  5809. props_.emplace_back("imode", "AREA");
  5810. break;
  5811. case Resize::InterpolationMode::CUBIC:
  5812. props_.emplace_back("imode", "CUBIC");
  5813. break;
  5814. case Resize::InterpolationMode::LANCZOS4:
  5815. props_.emplace_back("imode", "LANCZOS4");
  5816. break;
  5817. default:
  5818. props_.emplace_back("imode", "INVALID");
  5819. break;
  5820. }
  5821. switch (op_.format){
  5822. case Resize::Format::NCHW:
  5823. props_.emplace_back("format", "NCHW");
  5824. break;
  5825. case Resize::Format::NHWC:
  5826. props_.emplace_back("format", "NHWC");
  5827. break;
  5828. case Resize::Format::NHWCD4:
  5829. props_.emplace_back("format", "NHWCD4");
  5830. break;
  5831. case Resize::Format::NCHW4:
  5832. props_.emplace_back("format", "NCHW4");
  5833. break;
  5834. case Resize::Format::NCHW8:
  5835. props_.emplace_back("format", "NCHW8");
  5836. break;
  5837. case Resize::Format::NCHW32:
  5838. props_.emplace_back("format", "NCHW32");
  5839. break;
  5840. case Resize::Format::NCHW88:
  5841. props_.emplace_back("format", "NCHW88");
  5842. break;
  5843. case Resize::Format::NCHW44:
  5844. props_.emplace_back("format", "NCHW44");
  5845. break;
  5846. case Resize::Format::NCHW44_DOT:
  5847. props_.emplace_back("format", "NCHW44_DOT");
  5848. break;
  5849. case Resize::Format::NCHW4_NCHW32:
  5850. props_.emplace_back("format", "NCHW4_NCHW32");
  5851. break;
  5852. case Resize::Format::NCHW32_NCHW4:
  5853. props_.emplace_back("format", "NCHW32_NCHW4");
  5854. break;
  5855. case Resize::Format::NCHW4_NCHW:
  5856. props_.emplace_back("format", "NCHW4_NCHW");
  5857. break;
  5858. case Resize::Format::NHWC_NCHW:
  5859. props_.emplace_back("format", "NHWC_NCHW");
  5860. break;
  5861. case Resize::Format::NHWC_NCHW4_IC_SMALL:
  5862. props_.emplace_back("format", "NHWC_NCHW4_IC_SMALL");
  5863. break;
  5864. case Resize::Format::NCHW_NCHW4_IC_SMALL:
  5865. props_.emplace_back("format", "NCHW_NCHW4_IC_SMALL");
  5866. break;
  5867. case Resize::Format::CHWN4:
  5868. props_.emplace_back("format", "CHWN4");
  5869. break;
  5870. case Resize::Format::NCHW64:
  5871. props_.emplace_back("format", "NCHW64");
  5872. break;
  5873. case Resize::Format::NCHW4_NHWC:
  5874. props_.emplace_back("format", "NCHW4_NHWC");
  5875. break;
  5876. default:
  5877. props_.emplace_back("format", "INVALID");
  5878. break;
  5879. }
  5880. return props_;
  5881. }
  5882. std::string Resize_make_name_impl(const OpDef& def_) {
  5883. auto&& op_ = def_.cast_final_safe<Resize>();
  5884. static_cast<void>(op_);
  5885. return "Resize";
  5886. }
  5887. } // anonymous namespace
  5888. OP_TRAIT_REG(Resize, Resize)
  5889. .hash(Resize_hash_impl)
  5890. .is_same_st(Resize_is_same_st_impl)
  5891. .props(Resize_props_impl)
  5892. .make_name(Resize_make_name_impl);
  5893. MGB_DYN_TYPE_OBJ_FINAL_IMPL(SVD);
  5894. namespace {
  5895. size_t SVD_hash_impl(const OpDef& def_) {
  5896. auto&& op_ = def_.cast_final_safe<SVD>();
  5897. static_cast<void>(op_);
  5898. size_t val = mgb::hash(op_.dyn_typeinfo());
  5899. val = mgb::hash_pair_combine(val, mgb::hash(op_.full_matrices));
  5900. val = mgb::hash_pair_combine(val, mgb::hash(op_.compute_uv));
  5901. return val;
  5902. }
  5903. bool SVD_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  5904. auto &&a_ = lhs_.cast_final_safe<SVD>(),
  5905. &&b_ = rhs_.cast_final_safe<SVD>();
  5906. static_cast<void>(a_);
  5907. static_cast<void>(b_);
  5908. if (a_.full_matrices != b_.full_matrices) return false;
  5909. if (a_.compute_uv != b_.compute_uv) return false;
  5910. return true;
  5911. }
  5912. std::vector<std::pair<const char*, std::string>> SVD_props_impl(const OpDef& def_) {
  5913. auto&& op_ = def_.cast_final_safe<SVD>();
  5914. static_cast<void>(op_);
  5915. std::vector<std::pair<const char*, std::string>> props_;
  5916. props_.emplace_back("full_matrices", std::to_string(op_.full_matrices));
  5917. props_.emplace_back("compute_uv", std::to_string(op_.compute_uv));
  5918. return props_;
  5919. }
  5920. std::string SVD_make_name_impl(const OpDef& def_) {
  5921. auto&& op_ = def_.cast_final_safe<SVD>();
  5922. static_cast<void>(op_);
  5923. return "SVD";
  5924. }
  5925. } // anonymous namespace
  5926. OP_TRAIT_REG(SVD, SVD)
  5927. .hash(SVD_hash_impl)
  5928. .is_same_st(SVD_is_same_st_impl)
  5929. .props(SVD_props_impl)
  5930. .make_name(SVD_make_name_impl);
  5931. MGB_DYN_TYPE_OBJ_FINAL_IMPL(SetMeshIndexing);
  5932. namespace {
  5933. size_t SetMeshIndexing_hash_impl(const OpDef& def_) {
  5934. auto&& op_ = def_.cast_final_safe<SetMeshIndexing>();
  5935. static_cast<void>(op_);
  5936. size_t val = mgb::hash(op_.dyn_typeinfo());
  5937. val = mgb::hash_pair_combine(val, mgb::hash(op_.items));
  5938. return val;
  5939. }
  5940. bool SetMeshIndexing_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  5941. auto &&a_ = lhs_.cast_final_safe<SetMeshIndexing>(),
  5942. &&b_ = rhs_.cast_final_safe<SetMeshIndexing>();
  5943. static_cast<void>(a_);
  5944. static_cast<void>(b_);
  5945. if (a_.items != b_.items) return false;
  5946. return true;
  5947. }
  5948. std::vector<std::pair<const char*, std::string>> SetMeshIndexing_props_impl(const OpDef& def_) {
  5949. auto&& op_ = def_.cast_final_safe<SetMeshIndexing>();
  5950. static_cast<void>(op_);
  5951. std::vector<std::pair<const char*, std::string>> props_;
  5952. props_.emplace_back("items", "{std::vector}");
  5953. return props_;
  5954. }
  5955. std::string SetMeshIndexing_make_name_impl(const OpDef& def_) {
  5956. auto&& op_ = def_.cast_final_safe<SetMeshIndexing>();
  5957. static_cast<void>(op_);
  5958. return "SetMeshIndexing";
  5959. }
  5960. } // anonymous namespace
  5961. OP_TRAIT_REG(SetMeshIndexing, SetMeshIndexing)
  5962. .hash(SetMeshIndexing_hash_impl)
  5963. .is_same_st(SetMeshIndexing_is_same_st_impl)
  5964. .props(SetMeshIndexing_props_impl)
  5965. .make_name(SetMeshIndexing_make_name_impl);
  5966. MGB_DYN_TYPE_OBJ_FINAL_IMPL(SetSubtensor);
  5967. namespace {
  5968. size_t SetSubtensor_hash_impl(const OpDef& def_) {
  5969. auto&& op_ = def_.cast_final_safe<SetSubtensor>();
  5970. static_cast<void>(op_);
  5971. size_t val = mgb::hash(op_.dyn_typeinfo());
  5972. val = mgb::hash_pair_combine(val, mgb::hash(op_.items));
  5973. return val;
  5974. }
  5975. bool SetSubtensor_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  5976. auto &&a_ = lhs_.cast_final_safe<SetSubtensor>(),
  5977. &&b_ = rhs_.cast_final_safe<SetSubtensor>();
  5978. static_cast<void>(a_);
  5979. static_cast<void>(b_);
  5980. if (a_.items != b_.items) return false;
  5981. return true;
  5982. }
  5983. std::vector<std::pair<const char*, std::string>> SetSubtensor_props_impl(const OpDef& def_) {
  5984. auto&& op_ = def_.cast_final_safe<SetSubtensor>();
  5985. static_cast<void>(op_);
  5986. std::vector<std::pair<const char*, std::string>> props_;
  5987. props_.emplace_back("items", "{std::vector}");
  5988. return props_;
  5989. }
  5990. std::string SetSubtensor_make_name_impl(const OpDef& def_) {
  5991. auto&& op_ = def_.cast_final_safe<SetSubtensor>();
  5992. static_cast<void>(op_);
  5993. return "SetSubtensor";
  5994. }
  5995. } // anonymous namespace
  5996. OP_TRAIT_REG(SetSubtensor, SetSubtensor)
  5997. .hash(SetSubtensor_hash_impl)
  5998. .is_same_st(SetSubtensor_is_same_st_impl)
  5999. .props(SetSubtensor_props_impl)
  6000. .make_name(SetSubtensor_make_name_impl);
  6001. MGB_DYN_TYPE_OBJ_FINAL_IMPL(ShuffleRNG);
  6002. namespace {
  6003. size_t ShuffleRNG_hash_impl(const OpDef& def_) {
  6004. auto&& op_ = def_.cast_final_safe<ShuffleRNG>();
  6005. static_cast<void>(op_);
  6006. return mgb::hash_pair_combine(
  6007. mgb::hash(op_.dyn_typeinfo()),
  6008. mgb::hash(op_.handle)
  6009. );
  6010. }
  6011. bool ShuffleRNG_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  6012. auto &&a_ = lhs_.cast_final_safe<ShuffleRNG>(),
  6013. &&b_ = rhs_.cast_final_safe<ShuffleRNG>();
  6014. static_cast<void>(a_);
  6015. static_cast<void>(b_);
  6016. return a_.handle == b_.handle;}
  6017. std::vector<std::pair<const char*, std::string>> ShuffleRNG_props_impl(const OpDef& def_) {
  6018. auto&& op_ = def_.cast_final_safe<ShuffleRNG>();
  6019. static_cast<void>(op_);
  6020. std::vector<std::pair<const char*, std::string>> props_;
  6021. props_.emplace_back("seed", std::to_string(op_.seed));
  6022. props_.emplace_back("handle", std::to_string(op_.handle));
  6023. return props_;
  6024. }
  6025. std::string ShuffleRNG_make_name_impl(const OpDef& def_) {
  6026. auto&& op_ = def_.cast_final_safe<ShuffleRNG>();
  6027. static_cast<void>(op_);
  6028. return "ShuffleRNG";
  6029. }
  6030. } // anonymous namespace
  6031. OP_TRAIT_REG(ShuffleRNG, ShuffleRNG)
  6032. .hash(ShuffleRNG_hash_impl)
  6033. .is_same_st(ShuffleRNG_is_same_st_impl)
  6034. .props(ShuffleRNG_props_impl)
  6035. .make_name(ShuffleRNG_make_name_impl);
  6036. MGB_DYN_TYPE_OBJ_FINAL_IMPL(SlidingWindowTranspose);
  6037. namespace {
  6038. size_t SlidingWindowTranspose_hash_impl(const OpDef& def_) {
  6039. auto&& op_ = def_.cast_final_safe<SlidingWindowTranspose>();
  6040. static_cast<void>(op_);
  6041. size_t val = mgb::hash(op_.dyn_typeinfo());
  6042. val = mgb::hash_pair_combine(val, mgb::hash(op_.out_h));
  6043. val = mgb::hash_pair_combine(val, mgb::hash(op_.out_w));
  6044. val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_h));
  6045. val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_w));
  6046. val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_h));
  6047. val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_w));
  6048. val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_h));
  6049. val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_w));
  6050. val = mgb::hash_pair_combine(val, mgb::hash(op_.window_h));
  6051. val = mgb::hash_pair_combine(val, mgb::hash(op_.window_w));
  6052. return val;
  6053. }
  6054. bool SlidingWindowTranspose_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  6055. auto &&a_ = lhs_.cast_final_safe<SlidingWindowTranspose>(),
  6056. &&b_ = rhs_.cast_final_safe<SlidingWindowTranspose>();
  6057. static_cast<void>(a_);
  6058. static_cast<void>(b_);
  6059. if (a_.out_h != b_.out_h) return false;
  6060. if (a_.out_w != b_.out_w) return false;
  6061. if (a_.pad_h != b_.pad_h) return false;
  6062. if (a_.pad_w != b_.pad_w) return false;
  6063. if (a_.stride_h != b_.stride_h) return false;
  6064. if (a_.stride_w != b_.stride_w) return false;
  6065. if (a_.dilate_h != b_.dilate_h) return false;
  6066. if (a_.dilate_w != b_.dilate_w) return false;
  6067. if (a_.window_h != b_.window_h) return false;
  6068. if (a_.window_w != b_.window_w) return false;
  6069. return true;
  6070. }
  6071. std::vector<std::pair<const char*, std::string>> SlidingWindowTranspose_props_impl(const OpDef& def_) {
  6072. auto&& op_ = def_.cast_final_safe<SlidingWindowTranspose>();
  6073. static_cast<void>(op_);
  6074. std::vector<std::pair<const char*, std::string>> props_;
  6075. props_.emplace_back("out_h", std::to_string(op_.out_h));
  6076. props_.emplace_back("out_w", std::to_string(op_.out_w));
  6077. props_.emplace_back("pad_h", std::to_string(op_.pad_h));
  6078. props_.emplace_back("pad_w", std::to_string(op_.pad_w));
  6079. props_.emplace_back("stride_h", std::to_string(op_.stride_h));
  6080. props_.emplace_back("stride_w", std::to_string(op_.stride_w));
  6081. props_.emplace_back("dilate_h", std::to_string(op_.dilate_h));
  6082. props_.emplace_back("dilate_w", std::to_string(op_.dilate_w));
  6083. props_.emplace_back("window_h", std::to_string(op_.window_h));
  6084. props_.emplace_back("window_w", std::to_string(op_.window_w));
  6085. return props_;
  6086. }
  6087. std::string SlidingWindowTranspose_make_name_impl(const OpDef& def_) {
  6088. auto&& op_ = def_.cast_final_safe<SlidingWindowTranspose>();
  6089. static_cast<void>(op_);
  6090. return "SlidingWindowTranspose";
  6091. }
  6092. } // anonymous namespace
  6093. OP_TRAIT_REG(SlidingWindowTranspose, SlidingWindowTranspose)
  6094. .hash(SlidingWindowTranspose_hash_impl)
  6095. .is_same_st(SlidingWindowTranspose_is_same_st_impl)
  6096. .props(SlidingWindowTranspose_props_impl)
  6097. .make_name(SlidingWindowTranspose_make_name_impl);
  6098. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Softmax);
  6099. namespace {
  6100. size_t Softmax_hash_impl(const OpDef& def_) {
  6101. auto&& op_ = def_.cast_final_safe<Softmax>();
  6102. static_cast<void>(op_);
  6103. size_t val = mgb::hash(op_.dyn_typeinfo());
  6104. val = mgb::hash_pair_combine(val, mgb::hash(op_.axis));
  6105. return val;
  6106. }
  6107. bool Softmax_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  6108. auto &&a_ = lhs_.cast_final_safe<Softmax>(),
  6109. &&b_ = rhs_.cast_final_safe<Softmax>();
  6110. static_cast<void>(a_);
  6111. static_cast<void>(b_);
  6112. if (a_.axis != b_.axis) return false;
  6113. return true;
  6114. }
  6115. std::vector<std::pair<const char*, std::string>> Softmax_props_impl(const OpDef& def_) {
  6116. auto&& op_ = def_.cast_final_safe<Softmax>();
  6117. static_cast<void>(op_);
  6118. std::vector<std::pair<const char*, std::string>> props_;
  6119. props_.emplace_back("axis", std::to_string(op_.axis));
  6120. return props_;
  6121. }
  6122. std::string Softmax_make_name_impl(const OpDef& def_) {
  6123. auto&& op_ = def_.cast_final_safe<Softmax>();
  6124. static_cast<void>(op_);
  6125. return "Softmax";
  6126. }
  6127. } // anonymous namespace
  6128. OP_TRAIT_REG(Softmax, Softmax)
  6129. .hash(Softmax_hash_impl)
  6130. .is_same_st(Softmax_is_same_st_impl)
  6131. .props(Softmax_props_impl)
  6132. .make_name(Softmax_make_name_impl);
  6133. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Split);
  6134. namespace {
  6135. size_t Split_hash_impl(const OpDef& def_) {
  6136. auto&& op_ = def_.cast_final_safe<Split>();
  6137. static_cast<void>(op_);
  6138. size_t val = mgb::hash(op_.dyn_typeinfo());
  6139. val = mgb::hash_pair_combine(val, mgb::hash(op_.axis));
  6140. val = mgb::hash_pair_combine(val, mgb::hash(op_.nsections));
  6141. return val;
  6142. }
  6143. bool Split_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  6144. auto &&a_ = lhs_.cast_final_safe<Split>(),
  6145. &&b_ = rhs_.cast_final_safe<Split>();
  6146. static_cast<void>(a_);
  6147. static_cast<void>(b_);
  6148. if (a_.axis != b_.axis) return false;
  6149. if (a_.nsections != b_.nsections) return false;
  6150. return true;
  6151. }
  6152. std::vector<std::pair<const char*, std::string>> Split_props_impl(const OpDef& def_) {
  6153. auto&& op_ = def_.cast_final_safe<Split>();
  6154. static_cast<void>(op_);
  6155. std::vector<std::pair<const char*, std::string>> props_;
  6156. props_.emplace_back("axis", std::to_string(op_.axis));
  6157. props_.emplace_back("nsections", std::to_string(op_.nsections));
  6158. return props_;
  6159. }
  6160. std::string Split_make_name_impl(const OpDef& def_) {
  6161. auto&& op_ = def_.cast_final_safe<Split>();
  6162. static_cast<void>(op_);
  6163. return "Split";
  6164. }
  6165. } // anonymous namespace
  6166. OP_TRAIT_REG(Split, Split)
  6167. .hash(Split_hash_impl)
  6168. .is_same_st(Split_is_same_st_impl)
  6169. .props(Split_props_impl)
  6170. .make_name(Split_make_name_impl);
  6171. MGB_DYN_TYPE_OBJ_FINAL_IMPL(Subtensor);
  6172. namespace {
  6173. size_t Subtensor_hash_impl(const OpDef& def_) {
  6174. auto&& op_ = def_.cast_final_safe<Subtensor>();
  6175. static_cast<void>(op_);
  6176. size_t val = mgb::hash(op_.dyn_typeinfo());
  6177. val = mgb::hash_pair_combine(val, mgb::hash(op_.items));
  6178. return val;
  6179. }
  6180. bool Subtensor_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  6181. auto &&a_ = lhs_.cast_final_safe<Subtensor>(),
  6182. &&b_ = rhs_.cast_final_safe<Subtensor>();
  6183. static_cast<void>(a_);
  6184. static_cast<void>(b_);
  6185. if (a_.items != b_.items) return false;
  6186. return true;
  6187. }
  6188. std::vector<std::pair<const char*, std::string>> Subtensor_props_impl(const OpDef& def_) {
  6189. auto&& op_ = def_.cast_final_safe<Subtensor>();
  6190. static_cast<void>(op_);
  6191. std::vector<std::pair<const char*, std::string>> props_;
  6192. props_.emplace_back("items", "{std::vector}");
  6193. return props_;
  6194. }
  6195. std::string Subtensor_make_name_impl(const OpDef& def_) {
  6196. auto&& op_ = def_.cast_final_safe<Subtensor>();
  6197. static_cast<void>(op_);
  6198. return "Subtensor";
  6199. }
  6200. } // anonymous namespace
  6201. OP_TRAIT_REG(Subtensor, Subtensor)
  6202. .hash(Subtensor_hash_impl)
  6203. .is_same_st(Subtensor_is_same_st_impl)
  6204. .props(Subtensor_props_impl)
  6205. .make_name(Subtensor_make_name_impl);
  6206. MGB_DYN_TYPE_OBJ_FINAL_IMPL(TQT);
  6207. namespace {
  6208. size_t TQT_hash_impl(const OpDef& def_) {
  6209. auto&& op_ = def_.cast_final_safe<TQT>();
  6210. static_cast<void>(op_);
  6211. size_t val = mgb::hash(op_.dyn_typeinfo());
  6212. val = mgb::hash_pair_combine(val, mgb::hash(op_.qmin));
  6213. val = mgb::hash_pair_combine(val, mgb::hash(op_.qmax));
  6214. return val;
  6215. }
  6216. bool TQT_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  6217. auto &&a_ = lhs_.cast_final_safe<TQT>(),
  6218. &&b_ = rhs_.cast_final_safe<TQT>();
  6219. static_cast<void>(a_);
  6220. static_cast<void>(b_);
  6221. if (a_.qmin != b_.qmin) return false;
  6222. if (a_.qmax != b_.qmax) return false;
  6223. return true;
  6224. }
  6225. std::vector<std::pair<const char*, std::string>> TQT_props_impl(const OpDef& def_) {
  6226. auto&& op_ = def_.cast_final_safe<TQT>();
  6227. static_cast<void>(op_);
  6228. std::vector<std::pair<const char*, std::string>> props_;
  6229. props_.emplace_back("qmin", std::to_string(op_.qmin));
  6230. props_.emplace_back("qmax", std::to_string(op_.qmax));
  6231. return props_;
  6232. }
  6233. std::string TQT_make_name_impl(const OpDef& def_) {
  6234. auto&& op_ = def_.cast_final_safe<TQT>();
  6235. static_cast<void>(op_);
  6236. return "TQT";
  6237. }
  6238. } // anonymous namespace
  6239. OP_TRAIT_REG(TQT, TQT)
  6240. .hash(TQT_hash_impl)
  6241. .is_same_st(TQT_is_same_st_impl)
  6242. .props(TQT_props_impl)
  6243. .make_name(TQT_make_name_impl);
  6244. MGB_DYN_TYPE_OBJ_FINAL_IMPL(TensorRTRuntime);
  6245. namespace {
  6246. size_t TensorRTRuntime_hash_impl(const OpDef& def_) {
  6247. auto&& op_ = def_.cast_final_safe<TensorRTRuntime>();
  6248. static_cast<void>(op_);
  6249. size_t val = mgb::hash(op_.dyn_typeinfo());
  6250. val = mgb::hash_pair_combine(val, mgb::hash(op_.buf));
  6251. val = mgb::hash_pair_combine(val, mgb::hash(op_.buf_size));
  6252. return val;
  6253. }
  6254. bool TensorRTRuntime_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  6255. auto &&a_ = lhs_.cast_final_safe<TensorRTRuntime>(),
  6256. &&b_ = rhs_.cast_final_safe<TensorRTRuntime>();
  6257. static_cast<void>(a_);
  6258. static_cast<void>(b_);
  6259. if (a_.buf != b_.buf) return false;
  6260. if (a_.buf_size != b_.buf_size) return false;
  6261. return true;
  6262. }
  6263. std::vector<std::pair<const char*, std::string>> TensorRTRuntime_props_impl(const OpDef& def_) {
  6264. auto&& op_ = def_.cast_final_safe<TensorRTRuntime>();
  6265. static_cast<void>(op_);
  6266. std::vector<std::pair<const char*, std::string>> props_;
  6267. props_.emplace_back("buf", op_.buf);
  6268. props_.emplace_back("buf_size", std::to_string(op_.buf_size));
  6269. return props_;
  6270. }
  6271. std::string TensorRTRuntime_make_name_impl(const OpDef& def_) {
  6272. auto&& op_ = def_.cast_final_safe<TensorRTRuntime>();
  6273. static_cast<void>(op_);
  6274. return "TensorRTRuntime";
  6275. }
  6276. } // anonymous namespace
  6277. OP_TRAIT_REG(TensorRTRuntime, TensorRTRuntime)
  6278. .hash(TensorRTRuntime_hash_impl)
  6279. .is_same_st(TensorRTRuntime_is_same_st_impl)
  6280. .props(TensorRTRuntime_props_impl)
  6281. .make_name(TensorRTRuntime_make_name_impl);
  6282. MGB_DYN_TYPE_OBJ_FINAL_IMPL(TopK);
  6283. namespace {
  6284. size_t TopK_hash_impl(const OpDef& def_) {
  6285. auto&& op_ = def_.cast_final_safe<TopK>();
  6286. static_cast<void>(op_);
  6287. size_t val = mgb::hash(op_.dyn_typeinfo());
  6288. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode));
  6289. return val;
  6290. }
  6291. bool TopK_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  6292. auto &&a_ = lhs_.cast_final_safe<TopK>(),
  6293. &&b_ = rhs_.cast_final_safe<TopK>();
  6294. static_cast<void>(a_);
  6295. static_cast<void>(b_);
  6296. if (a_.mode != b_.mode) return false;
  6297. return true;
  6298. }
  6299. std::vector<std::pair<const char*, std::string>> TopK_props_impl(const OpDef& def_) {
  6300. auto&& op_ = def_.cast_final_safe<TopK>();
  6301. static_cast<void>(op_);
  6302. std::vector<std::pair<const char*, std::string>> props_;
  6303. switch (op_.mode){
  6304. case TopK::Mode::KTH_ONLY:
  6305. props_.emplace_back("mode", "KTH_ONLY");
  6306. break;
  6307. case TopK::Mode::VALUE_IDX_NOSORT:
  6308. props_.emplace_back("mode", "VALUE_IDX_NOSORT");
  6309. break;
  6310. case TopK::Mode::VALUE_IDX_SORTED:
  6311. props_.emplace_back("mode", "VALUE_IDX_SORTED");
  6312. break;
  6313. default:
  6314. props_.emplace_back("mode", "INVALID");
  6315. break;
  6316. }
  6317. return props_;
  6318. }
  6319. std::string TopK_make_name_impl(const OpDef& def_) {
  6320. auto&& op_ = def_.cast_final_safe<TopK>();
  6321. static_cast<void>(op_);
  6322. return "TopK";
  6323. }
  6324. } // anonymous namespace
  6325. OP_TRAIT_REG(TopK, TopK)
  6326. .hash(TopK_hash_impl)
  6327. .is_same_st(TopK_is_same_st_impl)
  6328. .props(TopK_props_impl)
  6329. .make_name(TopK_make_name_impl);
  6330. MGB_DYN_TYPE_OBJ_FINAL_IMPL(TypeCvt);
  6331. namespace {
  6332. size_t TypeCvt_hash_impl(const OpDef& def_) {
  6333. auto&& op_ = def_.cast_final_safe<TypeCvt>();
  6334. static_cast<void>(op_);
  6335. size_t val = mgb::hash(op_.dyn_typeinfo());
  6336. val = mgb::hash_pair_combine(val, mgb::hash(op_.dtype.handle()));
  6337. return val;
  6338. }
  6339. bool TypeCvt_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  6340. auto &&a_ = lhs_.cast_final_safe<TypeCvt>(),
  6341. &&b_ = rhs_.cast_final_safe<TypeCvt>();
  6342. static_cast<void>(a_);
  6343. static_cast<void>(b_);
  6344. if (a_.dtype != b_.dtype) return false;
  6345. return true;
  6346. }
  6347. std::vector<std::pair<const char*, std::string>> TypeCvt_props_impl(const OpDef& def_) {
  6348. auto&& op_ = def_.cast_final_safe<TypeCvt>();
  6349. static_cast<void>(op_);
  6350. std::vector<std::pair<const char*, std::string>> props_;
  6351. props_.emplace_back("dtype", op_.dtype.name());
  6352. return props_;
  6353. }
  6354. std::string TypeCvt_make_name_impl(const OpDef& def_) {
  6355. auto&& op_ = def_.cast_final_safe<TypeCvt>();
  6356. static_cast<void>(op_);
  6357. return "TypeCvt";
  6358. }
  6359. } // anonymous namespace
  6360. OP_TRAIT_REG(TypeCvt, TypeCvt)
  6361. .hash(TypeCvt_hash_impl)
  6362. .is_same_st(TypeCvt_is_same_st_impl)
  6363. .props(TypeCvt_props_impl)
  6364. .make_name(TypeCvt_make_name_impl);
  6365. MGB_DYN_TYPE_OBJ_FINAL_IMPL(UniformRNG);
  6366. namespace {
  6367. size_t UniformRNG_hash_impl(const OpDef& def_) {
  6368. auto&& op_ = def_.cast_final_safe<UniformRNG>();
  6369. static_cast<void>(op_);
  6370. return mgb::hash_pair_combine(
  6371. mgb::hash(op_.dyn_typeinfo()),
  6372. mgb::hash_pair_combine(
  6373. mgb::hash(op_.handle),
  6374. mgb::hash(op_.dtype.enumv())
  6375. )
  6376. );
  6377. }
  6378. bool UniformRNG_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  6379. auto &&a_ = lhs_.cast_final_safe<UniformRNG>(),
  6380. &&b_ = rhs_.cast_final_safe<UniformRNG>();
  6381. static_cast<void>(a_);
  6382. static_cast<void>(b_);
  6383. return a_.handle == b_.handle && a_.dtype == b_.dtype;}
  6384. std::vector<std::pair<const char*, std::string>> UniformRNG_props_impl(const OpDef& def_) {
  6385. auto&& op_ = def_.cast_final_safe<UniformRNG>();
  6386. static_cast<void>(op_);
  6387. std::vector<std::pair<const char*, std::string>> props_;
  6388. props_.emplace_back("seed", std::to_string(op_.seed));
  6389. props_.emplace_back("dtype", op_.dtype.name());
  6390. props_.emplace_back("handle", std::to_string(op_.handle));
  6391. return props_;
  6392. }
  6393. std::string UniformRNG_make_name_impl(const OpDef& def_) {
  6394. auto&& op_ = def_.cast_final_safe<UniformRNG>();
  6395. static_cast<void>(op_);
  6396. return "UniformRNG";
  6397. }
  6398. } // anonymous namespace
  6399. OP_TRAIT_REG(UniformRNG, UniformRNG)
  6400. .hash(UniformRNG_hash_impl)
  6401. .is_same_st(UniformRNG_is_same_st_impl)
  6402. .props(UniformRNG_props_impl)
  6403. .make_name(UniformRNG_make_name_impl);
  6404. MGB_DYN_TYPE_OBJ_FINAL_IMPL(WarpAffine);
  6405. namespace {
  6406. size_t WarpAffine_hash_impl(const OpDef& def_) {
  6407. auto&& op_ = def_.cast_final_safe<WarpAffine>();
  6408. static_cast<void>(op_);
  6409. size_t val = mgb::hash(op_.dyn_typeinfo());
  6410. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.imode));
  6411. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.border_mode));
  6412. val = mgb::hash_pair_combine(val, mgb::hash(op_.border_val));
  6413. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format));
  6414. return val;
  6415. }
  6416. bool WarpAffine_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  6417. auto &&a_ = lhs_.cast_final_safe<WarpAffine>(),
  6418. &&b_ = rhs_.cast_final_safe<WarpAffine>();
  6419. static_cast<void>(a_);
  6420. static_cast<void>(b_);
  6421. if (a_.imode != b_.imode) return false;
  6422. if (a_.border_mode != b_.border_mode) return false;
  6423. if (a_.border_val != b_.border_val) return false;
  6424. if (a_.format != b_.format) return false;
  6425. return true;
  6426. }
  6427. std::vector<std::pair<const char*, std::string>> WarpAffine_props_impl(const OpDef& def_) {
  6428. auto&& op_ = def_.cast_final_safe<WarpAffine>();
  6429. static_cast<void>(op_);
  6430. std::vector<std::pair<const char*, std::string>> props_;
  6431. switch (op_.imode){
  6432. case WarpAffine::InterpolationMode::NEAREST:
  6433. props_.emplace_back("imode", "NEAREST");
  6434. break;
  6435. case WarpAffine::InterpolationMode::LINEAR:
  6436. props_.emplace_back("imode", "LINEAR");
  6437. break;
  6438. case WarpAffine::InterpolationMode::AREA:
  6439. props_.emplace_back("imode", "AREA");
  6440. break;
  6441. case WarpAffine::InterpolationMode::CUBIC:
  6442. props_.emplace_back("imode", "CUBIC");
  6443. break;
  6444. case WarpAffine::InterpolationMode::LANCZOS4:
  6445. props_.emplace_back("imode", "LANCZOS4");
  6446. break;
  6447. default:
  6448. props_.emplace_back("imode", "INVALID");
  6449. break;
  6450. }
  6451. switch (op_.border_mode){
  6452. case WarpAffine::BorderMode::REPLICATE:
  6453. props_.emplace_back("border_mode", "REPLICATE");
  6454. break;
  6455. case WarpAffine::BorderMode::REFLECT:
  6456. props_.emplace_back("border_mode", "REFLECT");
  6457. break;
  6458. case WarpAffine::BorderMode::REFLECT_101:
  6459. props_.emplace_back("border_mode", "REFLECT_101");
  6460. break;
  6461. case WarpAffine::BorderMode::WRAP:
  6462. props_.emplace_back("border_mode", "WRAP");
  6463. break;
  6464. case WarpAffine::BorderMode::CONSTANT:
  6465. props_.emplace_back("border_mode", "CONSTANT");
  6466. break;
  6467. case WarpAffine::BorderMode::TRANSPARENT:
  6468. props_.emplace_back("border_mode", "TRANSPARENT");
  6469. break;
  6470. case WarpAffine::BorderMode::ISOLATED:
  6471. props_.emplace_back("border_mode", "ISOLATED");
  6472. break;
  6473. default:
  6474. props_.emplace_back("border_mode", "INVALID");
  6475. break;
  6476. }
  6477. props_.emplace_back("border_val", std::to_string(op_.border_val));
  6478. switch (op_.format){
  6479. case WarpAffine::Format::NCHW:
  6480. props_.emplace_back("format", "NCHW");
  6481. break;
  6482. case WarpAffine::Format::NHWC:
  6483. props_.emplace_back("format", "NHWC");
  6484. break;
  6485. case WarpAffine::Format::NHWCD4:
  6486. props_.emplace_back("format", "NHWCD4");
  6487. break;
  6488. case WarpAffine::Format::NCHW4:
  6489. props_.emplace_back("format", "NCHW4");
  6490. break;
  6491. case WarpAffine::Format::NCHW8:
  6492. props_.emplace_back("format", "NCHW8");
  6493. break;
  6494. case WarpAffine::Format::NCHW32:
  6495. props_.emplace_back("format", "NCHW32");
  6496. break;
  6497. case WarpAffine::Format::NCHW88:
  6498. props_.emplace_back("format", "NCHW88");
  6499. break;
  6500. case WarpAffine::Format::NCHW44:
  6501. props_.emplace_back("format", "NCHW44");
  6502. break;
  6503. case WarpAffine::Format::NCHW44_DOT:
  6504. props_.emplace_back("format", "NCHW44_DOT");
  6505. break;
  6506. case WarpAffine::Format::NCHW4_NCHW32:
  6507. props_.emplace_back("format", "NCHW4_NCHW32");
  6508. break;
  6509. case WarpAffine::Format::NCHW32_NCHW4:
  6510. props_.emplace_back("format", "NCHW32_NCHW4");
  6511. break;
  6512. case WarpAffine::Format::NCHW4_NCHW:
  6513. props_.emplace_back("format", "NCHW4_NCHW");
  6514. break;
  6515. case WarpAffine::Format::NHWC_NCHW:
  6516. props_.emplace_back("format", "NHWC_NCHW");
  6517. break;
  6518. case WarpAffine::Format::NHWC_NCHW4_IC_SMALL:
  6519. props_.emplace_back("format", "NHWC_NCHW4_IC_SMALL");
  6520. break;
  6521. case WarpAffine::Format::NCHW_NCHW4_IC_SMALL:
  6522. props_.emplace_back("format", "NCHW_NCHW4_IC_SMALL");
  6523. break;
  6524. case WarpAffine::Format::CHWN4:
  6525. props_.emplace_back("format", "CHWN4");
  6526. break;
  6527. case WarpAffine::Format::NCHW64:
  6528. props_.emplace_back("format", "NCHW64");
  6529. break;
  6530. case WarpAffine::Format::NCHW4_NHWC:
  6531. props_.emplace_back("format", "NCHW4_NHWC");
  6532. break;
  6533. default:
  6534. props_.emplace_back("format", "INVALID");
  6535. break;
  6536. }
  6537. return props_;
  6538. }
  6539. std::string WarpAffine_make_name_impl(const OpDef& def_) {
  6540. auto&& op_ = def_.cast_final_safe<WarpAffine>();
  6541. static_cast<void>(op_);
  6542. return "WarpAffine";
  6543. }
  6544. } // anonymous namespace
  6545. OP_TRAIT_REG(WarpAffine, WarpAffine)
  6546. .hash(WarpAffine_hash_impl)
  6547. .is_same_st(WarpAffine_is_same_st_impl)
  6548. .props(WarpAffine_props_impl)
  6549. .make_name(WarpAffine_make_name_impl);
  6550. MGB_DYN_TYPE_OBJ_FINAL_IMPL(WarpPerspective);
  6551. namespace {
  6552. size_t WarpPerspective_hash_impl(const OpDef& def_) {
  6553. auto&& op_ = def_.cast_final_safe<WarpPerspective>();
  6554. static_cast<void>(op_);
  6555. size_t val = mgb::hash(op_.dyn_typeinfo());
  6556. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.imode));
  6557. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.bmode));
  6558. val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format));
  6559. val = mgb::hash_pair_combine(val, mgb::hash(op_.border_val));
  6560. return val;
  6561. }
  6562. bool WarpPerspective_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) {
  6563. auto &&a_ = lhs_.cast_final_safe<WarpPerspective>(),
  6564. &&b_ = rhs_.cast_final_safe<WarpPerspective>();
  6565. static_cast<void>(a_);
  6566. static_cast<void>(b_);
  6567. if (a_.imode != b_.imode) return false;
  6568. if (a_.bmode != b_.bmode) return false;
  6569. if (a_.format != b_.format) return false;
  6570. if (a_.border_val != b_.border_val) return false;
  6571. return true;
  6572. }
  6573. std::vector<std::pair<const char*, std::string>> WarpPerspective_props_impl(const OpDef& def_) {
  6574. auto&& op_ = def_.cast_final_safe<WarpPerspective>();
  6575. static_cast<void>(op_);
  6576. std::vector<std::pair<const char*, std::string>> props_;
  6577. switch (op_.imode){
  6578. case WarpPerspective::InterpolationMode::NEAREST:
  6579. props_.emplace_back("imode", "NEAREST");
  6580. break;
  6581. case WarpPerspective::InterpolationMode::LINEAR:
  6582. props_.emplace_back("imode", "LINEAR");
  6583. break;
  6584. case WarpPerspective::InterpolationMode::AREA:
  6585. props_.emplace_back("imode", "AREA");
  6586. break;
  6587. case WarpPerspective::InterpolationMode::CUBIC:
  6588. props_.emplace_back("imode", "CUBIC");
  6589. break;
  6590. case WarpPerspective::InterpolationMode::LANCZOS4:
  6591. props_.emplace_back("imode", "LANCZOS4");
  6592. break;
  6593. default:
  6594. props_.emplace_back("imode", "INVALID");
  6595. break;
  6596. }
  6597. switch (op_.bmode){
  6598. case WarpPerspective::BorderMode::REPLICATE:
  6599. props_.emplace_back("bmode", "REPLICATE");
  6600. break;
  6601. case WarpPerspective::BorderMode::REFLECT:
  6602. props_.emplace_back("bmode", "REFLECT");
  6603. break;
  6604. case WarpPerspective::BorderMode::REFLECT_101:
  6605. props_.emplace_back("bmode", "REFLECT_101");
  6606. break;
  6607. case WarpPerspective::BorderMode::WRAP:
  6608. props_.emplace_back("bmode", "WRAP");
  6609. break;
  6610. case WarpPerspective::BorderMode::CONSTANT:
  6611. props_.emplace_back("bmode", "CONSTANT");
  6612. break;
  6613. case WarpPerspective::BorderMode::TRANSPARENT:
  6614. props_.emplace_back("bmode", "TRANSPARENT");
  6615. break;
  6616. case WarpPerspective::BorderMode::ISOLATED:
  6617. props_.emplace_back("bmode", "ISOLATED");
  6618. break;
  6619. default:
  6620. props_.emplace_back("bmode", "INVALID");
  6621. break;
  6622. }
  6623. switch (op_.format){
  6624. case WarpPerspective::Format::NCHW:
  6625. props_.emplace_back("format", "NCHW");
  6626. break;
  6627. case WarpPerspective::Format::NHWC:
  6628. props_.emplace_back("format", "NHWC");
  6629. break;
  6630. case WarpPerspective::Format::NHWCD4:
  6631. props_.emplace_back("format", "NHWCD4");
  6632. break;
  6633. case WarpPerspective::Format::NCHW4:
  6634. props_.emplace_back("format", "NCHW4");
  6635. break;
  6636. case WarpPerspective::Format::NCHW8:
  6637. props_.emplace_back("format", "NCHW8");
  6638. break;
  6639. case WarpPerspective::Format::NCHW32:
  6640. props_.emplace_back("format", "NCHW32");
  6641. break;
  6642. case WarpPerspective::Format::NCHW88:
  6643. props_.emplace_back("format", "NCHW88");
  6644. break;
  6645. case WarpPerspective::Format::NCHW44:
  6646. props_.emplace_back("format", "NCHW44");
  6647. break;
  6648. case WarpPerspective::Format::NCHW44_DOT:
  6649. props_.emplace_back("format", "NCHW44_DOT");
  6650. break;
  6651. case WarpPerspective::Format::NCHW4_NCHW32:
  6652. props_.emplace_back("format", "NCHW4_NCHW32");
  6653. break;
  6654. case WarpPerspective::Format::NCHW32_NCHW4:
  6655. props_.emplace_back("format", "NCHW32_NCHW4");
  6656. break;
  6657. case WarpPerspective::Format::NCHW4_NCHW:
  6658. props_.emplace_back("format", "NCHW4_NCHW");
  6659. break;
  6660. case WarpPerspective::Format::NHWC_NCHW:
  6661. props_.emplace_back("format", "NHWC_NCHW");
  6662. break;
  6663. case WarpPerspective::Format::NHWC_NCHW4_IC_SMALL:
  6664. props_.emplace_back("format", "NHWC_NCHW4_IC_SMALL");
  6665. break;
  6666. case WarpPerspective::Format::NCHW_NCHW4_IC_SMALL:
  6667. props_.emplace_back("format", "NCHW_NCHW4_IC_SMALL");
  6668. break;
  6669. case WarpPerspective::Format::CHWN4:
  6670. props_.emplace_back("format", "CHWN4");
  6671. break;
  6672. case WarpPerspective::Format::NCHW64:
  6673. props_.emplace_back("format", "NCHW64");
  6674. break;
  6675. case WarpPerspective::Format::NCHW4_NHWC:
  6676. props_.emplace_back("format", "NCHW4_NHWC");
  6677. break;
  6678. default:
  6679. props_.emplace_back("format", "INVALID");
  6680. break;
  6681. }
  6682. props_.emplace_back("border_val", std::to_string(op_.border_val));
  6683. return props_;
  6684. }
  6685. std::string WarpPerspective_make_name_impl(const OpDef& def_) {
  6686. auto&& op_ = def_.cast_final_safe<WarpPerspective>();
  6687. static_cast<void>(op_);
  6688. return "WarpPerspective";
  6689. }
  6690. } // anonymous namespace
  6691. OP_TRAIT_REG(WarpPerspective, WarpPerspective)
  6692. .hash(WarpPerspective_hash_impl)
  6693. .is_same_st(WarpPerspective_is_same_st_impl)
  6694. .props(WarpPerspective_props_impl)
  6695. .make_name(WarpPerspective_make_name_impl);
  6696. // clang-format on