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

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