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

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